[FREELDR]
[reactos.git] / reactos / boot / freeldr / freeldr / arch / amd64 / int386.S
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 .intel_syntax noprefix
21 .text
22 .code16
23
24 #define ASM
25 #include <arch.h>
26
27
28 Int386_REGS:
29
30 Int386_eax:
31 .long 0
32 Int386_ebx:
33 .long 0
34 Int386_ecx:
35 .long 0
36 Int386_edx:
37 .long 0
38
39 Int386_esi:
40 .long 0
41 Int386_edi:
42 .long 0
43
44 Int386_ds:
45 .word 0
46 Int386_es:
47 .word 0
48 Int386_fs:
49 .word 0
50 Int386_gs:
51 .word 0
52
53 Int386_eflags:
54 .long 0
55
56 Int386_vector:
57 .quad 0
58 Int386_regsin:
59 .quad 0
60 Int386_regsout:
61 .quad 0
62
63 /*
64 * int Int386(int ivec, REGS* in, REGS* out);
65 */
66 EXTERN(Int386)
67 .code64
68
69 /* Get the function parameters */
70 mov Int386_vector, rcx
71 mov Int386_vector_opcode, cl
72 mov Int386_regsin, rdx
73 mov Int386_regsout, r8
74
75 /* Save all registers + segment registers */
76 // push ds
77 // push es
78 push fs
79 push gs
80 push rbx
81 push rcx
82 push rdx
83 push rsi
84 push rdi
85
86 /* Copy the input regs to our variables */
87 lea rdi, Int386_REGS
88 mov esi, Int386_regsin
89 mov ecx, 0x24
90 rep movsb
91
92 call x86_64_SwitchToReal
93 .code16
94
95 /* Setup the registers */
96 mov ax, cs:Int386_ds
97 mov ds, ax /* DS register */
98 mov ax, cs:Int386_es
99 mov es, ax /* ES register */
100 mov ax, cs:Int386_fs
101 mov fs, ax /* FS register */
102 mov ax, cs:Int386_gs
103 mov gs, ax /* GS register */
104
105 mov eax, cs:Int386_eax /* EAX register */
106 mov ebx, cs:Int386_ebx /* EBX register */
107 mov ecx, cs:Int386_ecx /* ECX register */
108 mov edx, cs:Int386_edx /* EDX register */
109
110 mov esi, cs:Int386_esi /* ESI register */
111 mov edi, cs:Int386_edi /* EDI register */
112
113 /* Do not set the flags register */
114 /* only return its value in regsout */
115 //pushl Int386_eflags
116 //popfl /* EFLAGS register */
117
118 /* Call the interrupt vector */
119 /*int Int386_vector*/
120 Int386_int_opcode:
121 .byte 0xcd
122 Int386_vector_opcode:
123 .byte 0x00
124
125 /* Save the registers */
126 mov cs:Int386_eax, eax /* EAX register */
127 mov cs:Int386_ebx, ebx /* EBX register */
128 mov cs:Int386_ecx, ecx /* ECX register */
129 mov cs:Int386_edx, edx /* EDX register */
130
131 mov cs:Int386_esi, esi /* ESI register */
132 mov cs:Int386_edi, edi /* EDI register */
133
134 mov ax, ds /* DS register */
135 mov cs:Int386_ds, ax
136 mov ax, es /* ES register */
137 mov cs:Int386_es, ax
138 mov ax, fs /* FS register */
139 mov cs:Int386_fs, ax
140 mov ax, gs /* GS register */
141 mov cs:Int386_gs, ax
142
143 pushf
144 pop cs:Int386_eflags /* EFLAGS register */
145
146 call x86_16_SwitchToLong
147 .code64
148
149 /* Copy the variables to the output regs */
150 lea rsi, Int386_REGS
151 mov rdi, Int386_regsout
152 mov rcx, 0x24
153 rep movsb
154
155 /* Restore segment and all other registers */
156 pop rdi
157 pop rsi
158 pop rdx
159 pop rcx
160 pop rbx
161 pop gs
162 pop fs
163 // pop es
164 // pop ds
165
166 /* Get return value */
167 xor rax, rax
168 mov eax, Int386_eax
169
170 ret