summaryrefslogtreecommitdiffstats
path: root/src/include/asm/system.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/asm/system.h')
-rw-r--r--src/include/asm/system.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/include/asm/system.h b/src/include/asm/system.h
new file mode 100644
index 0000000..9bc027a
--- /dev/null
+++ b/src/include/asm/system.h
@@ -0,0 +1,67 @@
1#define move_to_user_mode() \
2__asm__ ("movl %%esp,%%eax\n\t" \
3 "pushl $0x17\n\t" \
4 "pushl %%eax\n\t" \
5 "pushfl\n\t" \
6 "pushl $0x0f\n\t" \
7 "pushl $1f\n\t" \
8 "iret\n" \
9 "1:\tmovl $0x17,%%eax\n\t" \
10 "movw %%ax,%%ds\n\t" \
11 "movw %%ax,%%es\n\t" \
12 "movw %%ax,%%fs\n\t" \
13 "movw %%ax,%%gs" \
14 :::"ax")
15
16#define sti() __asm__ ("sti"::)
17#define cli() __asm__ ("cli"::)
18#define nop() __asm__ ("nop"::)
19
20#define iret() __asm__ ("iret"::)
21
22#define _set_gate(gate_addr,type,dpl,addr) \
23__asm__ ("movw %%dx,%%ax\n\t" \
24 "movw %0,%%dx\n\t" \
25 "movl %%eax,%1\n\t" \
26 "movl %%edx,%2" \
27 : \
28 : "i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
29 "o" (*((char *) (gate_addr))), \
30 "o" (*(4+(char *) (gate_addr))), \
31 "d" ((char *) (addr)),"a" (0x00080000))
32
33#define set_intr_gate(n,addr) \
34 _set_gate(&idt[n],14,0,addr)
35
36#define set_trap_gate(n,addr) \
37 _set_gate(&idt[n],15,0,addr)
38
39#define set_system_gate(n,addr) \
40 _set_gate(&idt[n],15,3,addr)
41
42#define _set_seg_desc(gate_addr,type,dpl,base,limit) {\
43 *(gate_addr) = ((base) & 0xff000000) | \
44 (((base) & 0x00ff0000)>>16) | \
45 ((limit) & 0xf0000) | \
46 ((dpl)<<13) | \
47 (0x00408000) | \
48 ((type)<<8); \
49 *((gate_addr)+1) = (((base) & 0x0000ffff)<<16) | \
50 ((limit) & 0x0ffff); }
51
52#define _set_tssldt_desc(n,addr,type) \
53__asm__ ("movw $104,%1\n\t" \
54 "movw %%ax,%2\n\t" \
55 "rorl $16,%%eax\n\t" \
56 "movb %%al,%3\n\t" \
57 "movb $" type ",%4\n\t" \
58 "movb $0x00,%5\n\t" \
59 "movb %%ah,%6\n\t" \
60 "rorl $16,%%eax" \
61 ::"a" (addr), "m" (*(n)), "m" (*(n+2)), "m" (*(n+4)), \
62 "m" (*(n+5)), "m" (*(n+6)), "m" (*(n+7)) \
63 )
64
65#define set_tss_desc(n,addr) _set_tssldt_desc(((char *) (n)),((int)(addr)),"0x89")
66#define set_ldt_desc(n,addr) _set_tssldt_desc(((char *) (n)),((int)(addr)),"0x82")
67