2018-09-28 20:35:51 +02:00
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
/* COS2000 - Compatible Operating System - LGPL v3 - Hord<72> Nicolas */
|
|
|
|
|
/* */
|
2007-04-02 14:52:01 +02:00
|
|
|
|
#include "types.h"
|
2007-04-02 15:11:17 +02:00
|
|
|
|
|
2018-12-09 00:40:25 +01:00
|
|
|
|
#ifndef _ASM
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define _ASM
|
2018-12-09 00:40:25 +01:00
|
|
|
|
|
2007-04-02 15:30:47 +02:00
|
|
|
|
/******************************************************************************/
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define halt() asm("hlt"::)
|
2007-04-02 15:30:47 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define sti() asm("sti"::)
|
2007-04-02 15:30:47 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define cli() asm("cli"::)
|
2007-04-02 15:30:47 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define nop() asm("nop"::)
|
2007-04-02 15:30:47 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define pushad() asm("pushal"::)
|
2018-08-17 11:17:24 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define popad() asm("popal"::)
|
2018-08-17 11:17:24 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define pushf() asm("pushf"::)
|
2018-08-17 11:17:24 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define pop(mem) asm("popl %0":"=m" (mem))
|
2018-12-10 19:12:20 +01:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define push(mem) asm("pushl %0"::"m" (mem))
|
2018-12-10 19:12:20 +01:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define popf() asm("popf"::)
|
2018-08-17 11:17:24 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define iret() asm("iret"::)
|
2007-04-02 15:30:47 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define leave() asm("leave"::)
|
2018-12-05 14:00:43 +01:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define irqendmaster() asm("movb $0x20,%al; \
|
2007-04-02 15:30:47 +02:00
|
|
|
|
outb %al,$0x20;")
|
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define irqendslave() asm("movb $0x20,%al; \
|
2007-04-02 15:30:47 +02:00
|
|
|
|
outb %al,$0xA0;")
|
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define lidt(idtr) asm ("lidtl %0"::"m" (*idtr))
|
2018-08-31 02:48:03 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define lgdt(gdtr) asm ("lgdtl %0"::"m" (*gdtr))
|
2018-08-31 02:48:03 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define lldt(ldtr) asm ("lldtl %0"::"m" (*ldtr))
|
2018-08-31 02:48:03 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define ltr(tss) asm volatile ("ltr %%ax":: "a" (tss))
|
2007-04-02 15:30:47 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define sidt(idtr) asm ("sidtl %0"::"m" (*idtr))
|
2018-09-18 14:29:35 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define sgdt(gdtr) asm ("sgdtl %0"::"m" (*gdtr))
|
2018-09-18 14:29:35 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define sldt(ldtr) asm ("sldtl %0"::"m" (*ldtr))
|
2018-09-18 15:11:50 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define str(tss) asm volatile ("str %%ax;\
|
2018-10-03 22:50:54 +02:00
|
|
|
|
mov %%ax,%0":: "m" (tss))
|
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define wrmsr(reg,low,high) asm volatile ("wrmsr" :: "c" (reg), "a" (low), "d" (high))
|
2018-10-04 14:55:41 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define rdmsr(reg,low,high) asm volatile ("rdmsr" :: "=a" (low), "=d" (high) : "c" (reg) )
|
2018-10-03 22:50:54 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define movsb(src,dst,count) \
|
2018-10-13 11:25:55 +02:00
|
|
|
|
asm volatile ("cld;rep movsb"::"S" (src), "D" (dst), "c" (count));
|
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define movsw(src,dst,count) \
|
2018-10-13 11:25:55 +02:00
|
|
|
|
asm volatile ("cld;rep movsw"::"S" (src), "D" (dst), "c" (count));
|
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define movsd(src,dst,count) \
|
2018-10-13 13:23:00 +02:00
|
|
|
|
asm volatile ("cld;rep movsl"::"S" (src), "D" (dst), "c" (count));
|
2018-10-13 11:25:55 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define stosb(pattern,dst,count) \
|
2018-10-13 11:25:55 +02:00
|
|
|
|
asm volatile ("cld;rep stosb"::"c" (count), "D" (dst), "a" (pattern));
|
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define stosw(pattern,dst,count) \
|
2018-10-19 10:13:29 +02:00
|
|
|
|
asm volatile ("cld;rep stosw"::"c" (count), "D" (dst), "a" (pattern));
|
2018-10-13 11:25:55 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define stosd(pattern,dst,count) \
|
2018-10-19 10:13:29 +02:00
|
|
|
|
asm volatile ("cld;rep stosl"::"c" (count), "D" (dst), "a" (pattern));
|
2018-10-13 11:25:55 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define rol(addr) \
|
2018-10-13 13:23:00 +02:00
|
|
|
|
asm volatile ("rolb $0x1,%0":"=m" (addr):);
|
2018-10-13 11:25:55 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define ror(addr) \
|
2018-10-13 13:23:00 +02:00
|
|
|
|
asm volatile ("rorb $0x1,%0":"=m" (addr):);
|
2018-11-29 16:45:40 +01:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define finit() \
|
2018-11-29 16:45:40 +01:00
|
|
|
|
asm volatile ("finit"::);
|
2007-04-02 15:30:47 +02:00
|
|
|
|
/******************************************************************************/
|
2007-04-02 14:52:01 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define outb(port,value) \
|
2007-04-02 14:52:01 +02:00
|
|
|
|
asm volatile ("outb %%al,%%dx"::"d" (port), "a" (value));
|
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define outw(port,value) \
|
2007-04-02 14:55:34 +02:00
|
|
|
|
asm volatile ("outw %%ax,%%dx"::"d" (port), "a" (value));
|
2007-04-02 14:52:01 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define outd(port,value) \
|
2007-04-02 15:30:47 +02:00
|
|
|
|
asm volatile ("outl %%eax,%%dx"::"d" (port), "a" (value));
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
2007-04-02 15:11:17 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define inb(port) ({ \
|
2007-04-02 14:52:01 +02:00
|
|
|
|
u8 _v; \
|
|
|
|
|
asm volatile ("inb %%dx,%%al" : "=a" (_v) : "d" (port)); \
|
|
|
|
|
_v; \
|
|
|
|
|
})
|
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define inw(port) ({ \
|
2007-04-02 14:52:01 +02:00
|
|
|
|
u16 _v; \
|
|
|
|
|
asm volatile ("inw %%dx,%%ax" : "=a" (_v) : "d"(port)); \
|
|
|
|
|
_v; \
|
2018-11-08 22:12:51 +01:00
|
|
|
|
})
|
2007-04-02 15:11:17 +02:00
|
|
|
|
|
2007-04-02 15:30:47 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define ind(port) ({ \
|
2007-04-02 15:11:17 +02:00
|
|
|
|
u32 _v; \
|
2007-04-02 15:30:47 +02:00
|
|
|
|
asm volatile ("inl %%dx,%%eax" : "=a" (_v) : "d"(port)); \
|
2007-04-02 15:11:17 +02:00
|
|
|
|
_v; \
|
2018-11-08 22:12:51 +01:00
|
|
|
|
})
|
2007-04-02 15:11:17 +02:00
|
|
|
|
|
2007-04-02 15:30:47 +02:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
/* pas termin<69> */
|
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
# define rolb(input,rotate) ({ \
|
2007-04-02 15:11:17 +02:00
|
|
|
|
u32 _v; \
|
|
|
|
|
asm volatile ("roll %1,%0" : "=g" (_v) : "cI" (rotate), "0" (input)); \
|
|
|
|
|
_v; \
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-28 20:35:51 +02:00
|
|
|
|
/******************************************************************************/
|
2007-04-02 15:30:47 +02:00
|
|
|
|
|
2018-12-09 00:40:25 +01:00
|
|
|
|
#endif
|