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