[CODE]: s/interupt/interrupt/
[reactos.git] / reactos / boot / freeldr / freeldr / arch / realmode / int386.inc
1
2 #include "../../include/arch/pc/pcbios.h"
3
4 #define EFLAGS_CF HEX(01)
5 #define EFLAGS_ZF HEX(40)
6 #define EFLAGS_SF HEX(80)
7
8 Int386:
9 /* Save all registers + segment registers */
10 push ds
11 push es
12 push fs
13 push gs
14 pushad
15
16 /* Get the interrupt vector and patch the opcode */
17 mov al, byte ptr ds:[BSS_IntVector]
18 mov byte ptr ds:[Int386_vector_opcode], al
19
20 /* Get current EFLAGS and mask CF, ZF and SF */
21 pushf
22 pop cx
23 and cx, not (EFLAGS_CF or EFLAGS_ZF or EFLAGS_SF)
24
25 /* Get flags CF, ZF and SF from the REGS structure */
26 mov ax, word ptr cs:[BSS_RegisterSet + REGS_EFLAGS]
27 and ax, (EFLAGS_CF or EFLAGS_ZF or EFLAGS_SF)
28
29 /* Combine flags and set them */
30 or ax, cx
31 push ax
32 popf
33
34 /* Setup the registers */
35 mov ax, word ptr cs:[BSS_RegisterSet + REGS_DS]
36 mov ds, ax
37 mov ax, word ptr cs:[BSS_RegisterSet + REGS_ES]
38 mov es, ax
39 mov ax, word ptr cs:[BSS_RegisterSet + REGS_FS]
40 mov fs, ax
41 mov ax, word ptr cs:[BSS_RegisterSet + REGS_GS]
42 mov gs, ax
43
44 mov eax, dword ptr cs:[BSS_RegisterSet + REGS_EAX]
45 mov ebx, dword ptr cs:[BSS_RegisterSet + REGS_EBX]
46 mov ecx, dword ptr cs:[BSS_RegisterSet + REGS_ECX]
47 mov edx, dword ptr cs:[BSS_RegisterSet + REGS_EDX]
48 mov esi, dword ptr cs:[BSS_RegisterSet + REGS_ESI]
49 mov edi, dword ptr cs:[BSS_RegisterSet + REGS_EDI]
50 // Don't setup ebp, we only use it as output!
51
52 /* Call the interrupt vector */
53 /*int Int386_vector*/
54 .byte HEX(0cd)
55 Int386_vector_opcode:
56 .byte 00
57
58 /* Save the registers */
59 mov dword ptr cs:[BSS_RegisterSet + REGS_EAX], eax
60 mov dword ptr cs:[BSS_RegisterSet + REGS_EBX], ebx
61 mov dword ptr cs:[BSS_RegisterSet + REGS_ECX], ecx
62 mov dword ptr cs:[BSS_RegisterSet + REGS_EDX], edx
63 mov dword ptr cs:[BSS_RegisterSet + REGS_ESI], esi
64 mov dword ptr cs:[BSS_RegisterSet + REGS_EDI], edi
65 mov dword ptr cs:[BSS_RegisterSet + REGS_EBP], ebp
66
67 mov ax, ds
68 mov word ptr cs:[BSS_RegisterSet + REGS_DS], ax
69 mov ax, es
70 mov word ptr cs:[BSS_RegisterSet + REGS_ES], ax
71 mov ax, fs
72 mov word ptr cs:[BSS_RegisterSet + REGS_FS], ax
73 mov ax, gs
74 mov word ptr cs:[BSS_RegisterSet + REGS_GS], ax
75
76 pushfd
77 pop dword ptr cs:[BSS_RegisterSet + REGS_EFLAGS]
78
79 popad
80 pop gs
81 pop fs
82 pop es
83 pop ds
84
85 ret
86
87
88