- Merge from trunk up to r45543
[reactos.git] / boot / freeldr / freeldr / arch / i386 / 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 .text
21 .code16
22
23 #define ASM
24 #include <arch.h>
25
26
27 Int386_REGS:
28
29 Int386_eax:
30 .long 0
31 Int386_ebx:
32 .long 0
33 Int386_ecx:
34 .long 0
35 Int386_edx:
36 .long 0
37
38 Int386_esi:
39 .long 0
40 Int386_edi:
41 .long 0
42
43 Int386_ds:
44 .word 0
45 Int386_es:
46 .word 0
47 Int386_fs:
48 .word 0
49 Int386_gs:
50 .word 0
51
52 Int386_eflags:
53 .long 0
54
55 Int386_vector:
56 .long 0
57 Int386_regsin:
58 .long 0
59 Int386_regsout:
60 .long 0
61
62 /*
63 * int Int386(int ivec, REGS* in, REGS* out);
64 */
65 EXTERN(_Int386)
66 .code32
67
68 /* Get the function parameters */
69 movl 0x04(%esp),%eax
70 movl %eax,Int386_vector
71 movb %al,Int386_vector_opcode
72 movl 0x08(%esp),%eax
73 movl %eax,Int386_regsin
74 movl 0x0c(%esp),%eax
75 movl %eax,Int386_regsout
76
77 /* Save all registers + segment registers */
78 pushw %ds
79 pushw %es
80 pushw %fs
81 pushw %gs
82 pushal
83
84 /* Copy the input regs to our variables */
85 movl $Int386_REGS,%edi
86 movl Int386_regsin,%esi
87 movl $0x24,%ecx
88 rep
89 movsb
90
91 call switch_to_real
92 .code16
93
94 /* Setup the registers */
95 movw %cs:Int386_ds,%ax
96 movw %ax,%ds /* DS register */
97 movw %cs:Int386_es,%ax
98 movw %ax,%es /* ES register */
99 movw %cs:Int386_fs,%ax
100 movw %ax,%fs /* FS register */
101 movw %cs:Int386_gs,%ax
102 movw %ax,%gs /* GS register */
103
104 movl %cs:Int386_eax,%eax /* EAX register */
105 movl %cs:Int386_ebx,%ebx /* EBX register */
106 movl %cs:Int386_ecx,%ecx /* ECX register */
107 movl %cs:Int386_edx,%edx /* EDX register */
108
109 movl %cs:Int386_esi,%esi /* ESI register */
110 movl %cs:Int386_edi,%edi /* EDI register */
111
112 /* Do not set the flags register */
113 /* only return its value in regsout */
114 //pushl Int386_eflags
115 //popfl /* EFLAGS register */
116
117 /* Call the interrupt vector */
118 /*int Int386_vector*/
119 Int386_int_opcode:
120 .byte 0xcd
121 Int386_vector_opcode:
122 .byte 0x00
123
124 /* Save the registers */
125 movl %eax,%cs:Int386_eax /* EAX register */
126 movl %ebx,%cs:Int386_ebx /* EBX register */
127 movl %ecx,%cs:Int386_ecx /* ECX register */
128 movl %edx,%cs:Int386_edx /* EDX register */
129
130 movl %esi,%cs:Int386_esi /* ESI register */
131 movl %edi,%cs:Int386_edi /* EDI register */
132
133 movw %ds,%ax /* DS register */
134 movw %ax,%cs:Int386_ds
135 movw %es,%ax /* ES register */
136 movw %ax,%cs:Int386_es
137 movw %fs,%ax /* FS register */
138 movw %ax,%cs:Int386_fs
139 movw %gs,%ax /* GS register */
140 movw %ax,%cs:Int386_gs
141
142 pushf
143 popw %cs:Int386_eflags /* EFLAGS register */
144
145 call switch_to_prot
146 .code32
147
148 /* Copy the variables to the output regs */
149 movl $Int386_REGS,%esi
150 movl Int386_regsout,%edi
151 movl $0x24,%ecx
152 rep
153 movsb
154
155 /* Restore segment and all other registers */
156
157
158 popal
159 popw %gs
160 popw %fs
161 popw %es
162 popw %ds
163
164 /* Get return value */
165 movl Int386_eax,%eax
166
167 ret