blob: 3145931e51a1920f3b1200f7c478bc3ba3781873 [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001#include <arch/asm.h>
2#include <arch/intel.h>
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +00003
Eric Biederman8ca8d762003-04-22 19:02:15 +00004 .section ".text"
5 .code32
6 .globl _start
7_start:
8 cli
9 lgdt %cs:gdtaddr
10 ljmp $0x10, $1f
111: movl $0x18, %eax
12 movl %eax, %ds
13 movl %eax, %es
14 movl %eax, %ss
15 movl %eax, %fs
16 movl %eax, %gs
17
arch import user (historical)6ca76362005-07-06 17:17:25 +000018 intel_chip_post_macro(0x13) /* post 13 */
Eric Biederman8ca8d762003-04-22 19:02:15 +000019
20 /** clear stack */
arch import user (historical)6ca76362005-07-06 17:17:25 +000021 cld
Eric Biedermanae948f72003-07-14 20:40:38 +000022 leal _stack, %edi
23 movl $_estack, %ecx
Eric Biederman8ca8d762003-04-22 19:02:15 +000024 subl %edi, %ecx
Stefan Reinauer7ce8c542005-12-02 21:52:30 +000025 shrl $2, %ecx /* it is 32 bit align, right? */
Eric Biederman8ca8d762003-04-22 19:02:15 +000026 xorl %eax, %eax
27 rep
Stefan Reinauer7ce8c542005-12-02 21:52:30 +000028 stosl
Eric Biederman8ca8d762003-04-22 19:02:15 +000029
30 /** clear bss */
Eric Biedermanae948f72003-07-14 20:40:38 +000031 leal _bss, %edi
32 movl $_ebss, %ecx
Eric Biederman8ca8d762003-04-22 19:02:15 +000033 subl %edi, %ecx
34 jz .Lnobss
Stefan Reinauer7ce8c542005-12-02 21:52:30 +000035 shrl $2, %ecx /* it is 32 bit align, right? */
Eric Biederman8ca8d762003-04-22 19:02:15 +000036 xorl %eax, %eax
37 rep
Stefan Reinauer7ce8c542005-12-02 21:52:30 +000038 stosl
Eric Biederman8ca8d762003-04-22 19:02:15 +000039.Lnobss:
40
41 /* set new stack */
42 movl $_estack, %esp
Eric Biederman8ca8d762003-04-22 19:02:15 +000043
Eric Biedermanb78c1972004-10-14 20:54:17 +000044 /* Push the cpu index and struct cpu */
45 pushl $0
46 pushl $0
Eric Biederman8ca8d762003-04-22 19:02:15 +000047
48 /* push the boot_complete flag */
49 pushl %ebp
50
51 /* Save the stack location */
52 movl %esp, %ebp
53
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +000054 /* Initialize the Interrupt Descriptor table */
55 leal _idt, %edi
56 leal vec0, %ebx
57 movl $(0x10 << 16), %eax /* cs selector */
58
591: movw %bx, %ax
60 movl %ebx, %edx
61 movw $0x8E00, %dx /* Interrupt gate - dpl=0, present */
62 movl %eax, 0(%edi)
63 movl %edx, 4(%edi)
64 addl $6, %ebx
65 addl $8, %edi
66 cmpl $_idt_end, %edi
67 jne 1b
68
69 /* Load the Interrupt descriptor table */
70 lidt idtarg
71
Eric Biederman8ca8d762003-04-22 19:02:15 +000072 /*
73 * Now we are finished. Memory is up, data is copied and
74 * bss is cleared. Now we call the main routine and
75 * let it do the rest.
76 */
77 intel_chip_post_macro(0xfe) /* post fe */
78
Eric Biedermanb78c1972004-10-14 20:54:17 +000079 /* Restore the stack location */
Eric Biederman8ca8d762003-04-22 19:02:15 +000080 movl %ebp, %esp
81
82 /* The boot_complete flag has already been pushed */
Eric Biedermanae948f72003-07-14 20:40:38 +000083 call hardwaremain
Eric Biederman8ca8d762003-04-22 19:02:15 +000084 /*NOTREACHED*/
85.Lhlt:
arch import user (historical)6ca76362005-07-06 17:17:25 +000086 intel_chip_post_macro(0xee) /* post ee */
Eric Biederman8ca8d762003-04-22 19:02:15 +000087 hlt
88 jmp .Lhlt
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +000089
90vec0:
91 pushl $0 /* error code */
92 pushl $0 /* vector */
93 jmp int_hand
94vec1:
95 pushl $0 /* error code */
96 pushl $1 /* vector */
97 jmp int_hand
98
99vec2:
100 pushl $0 /* error code */
101 pushl $2 /* vector */
102 jmp int_hand
103
104vec3:
105 pushl $0 /* error code */
106 pushl $3 /* vector */
107 jmp int_hand
108
109vec4:
110 pushl $0 /* error code */
111 pushl $4 /* vector */
112 jmp int_hand
113
114vec5:
115 pushl $0 /* error code */
116 pushl $5 /* vector */
117 jmp int_hand
118
119vec6:
120 pushl $0 /* error code */
121 pushl $6 /* vector */
122 jmp int_hand
123
124vec7:
125 pushl $0 /* error code */
126 pushl $7 /* vector */
127 jmp int_hand
128
129vec8:
130 /* error code */
131 pushl $8 /* vector */
132 jmp int_hand
133 .word 0x9090
134
135vec9:
136 pushl $0 /* error code */
137 pushl $9 /* vector */
138 jmp int_hand
139
140vec10:
141 /* error code */
142 pushl $10 /* vector */
143 jmp int_hand
144 .word 0x9090
145
146vec11:
147 /* error code */
148 pushl $11 /* vector */
149 jmp int_hand
150 .word 0x9090
151
152vec12:
153 /* error code */
154 pushl $12 /* vector */
155 jmp int_hand
156 .word 0x9090
157
158vec13:
159 /* error code */
160 pushl $13 /* vector */
161 jmp int_hand
162 .word 0x9090
163
164vec14:
165 /* error code */
166 pushl $14 /* vector */
167 jmp int_hand
168 .word 0x9090
169
170vec15:
171 pushl $0 /* error code */
172 pushl $15 /* vector */
173 jmp int_hand
174
175vec16:
176 pushl $0 /* error code */
177 pushl $16 /* vector */
178 jmp int_hand
179
180vec17:
181 /* error code */
182 pushl $17 /* vector */
183 jmp int_hand
184 .word 0x9090
185
186vec18:
187 pushl $0 /* error code */
188 pushl $18 /* vector */
189 jmp int_hand
190
191vec19:
192 pushl $0 /* error code */
193 pushl $19 /* vector */
194 jmp int_hand
195int_hand:
196 /* At this point on the stack there is:
197 * 0(%esp) vector
198 * 4(%esp) error code
199 * 8(%esp) eip
200 * 12(%esp) cs
201 * 16(%esp) eflags
202 */
203 pushl %edi
204 pushl %esi
205 pushl %ebp
206 /* Original stack pointer */
207 leal 32(%esp), %ebp
208 pushl %ebp
209 pushl %ebx
210 pushl %edx
211 pushl %ecx
212 pushl %eax
Eric Biederman8ca8d762003-04-22 19:02:15 +0000213
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000214 pushl %esp /* Pointer to structure on the stack */
215 call x86_exception
216 pop %eax /* Drop the pointer */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000217
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000218 popl %eax
219 popl %ecx
220 popl %edx
221 popl %ebx
Li-Ta Lof84926e2004-11-04 18:36:06 +0000222 popl %ebp /* Ignore saved %esp value */
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000223 popl %ebp
224 popl %esi
225 popl %edi
226
227 addl $8, %esp /* pop of the vector and error code */
228
229 iret
230
231#if CONFIG_GDB_STUB == 1
232
233 .globl gdb_stub_breakpoint
234gdb_stub_breakpoint:
235 popl %eax /* Return address */
236 pushfl
237 pushl %cs
238 pushl %eax /* Return address */
239 pushl $0 /* No error code */
240 pushl $32 /* vector 32 is user defined */
241 jmp int_hand
242
243#endif
244
245 .globl gdt, gdt_end, gdt_limit, idtarg
Eric Biederman8ca8d762003-04-22 19:02:15 +0000246
Li-Ta Lof84926e2004-11-04 18:36:06 +0000247gdt_limit = gdt_end - gdt - 1 /* compute the table limit */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000248gdtaddr:
249 .word gdt_limit
Li-Ta Lof84926e2004-11-04 18:36:06 +0000250 .long gdt /* we know the offset */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000251
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000252 .data
Li-Ta Lof84926e2004-11-04 18:36:06 +0000253
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000254 /* This is the gdt for GCC part of coreboot.
255 * It is different from the gdt in ROMCC/ASM part of coreboot
Li-Ta Lof84926e2004-11-04 18:36:06 +0000256 * which is defined in entry32.inc */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000257gdt:
Li-Ta Lof84926e2004-11-04 18:36:06 +0000258 /* selgdt 0, unused */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000259 .word 0x0000, 0x0000 /* dummy */
260 .byte 0x00, 0x00, 0x00, 0x00
261
Li-Ta Lof84926e2004-11-04 18:36:06 +0000262 /* selgdt 8, unused */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000263 .word 0x0000, 0x0000 /* dummy */
264 .byte 0x00, 0x00, 0x00, 0x00
265
Yinghai Lu30b4abe2007-04-06 19:57:42 +0000266 /* selgdt 0x10, flat code segment */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000267 .word 0xffff, 0x0000
Yinghai Lu30b4abe2007-04-06 19:57:42 +0000268 .byte 0x00, 0x9b, 0xcf, 0x00 /* G=1 and 0x0f, So we get 4Gbytes for limit */
Li-Ta Lof84926e2004-11-04 18:36:06 +0000269
270 /* selgdt 0x18, flat data segment */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000271 .word 0xffff, 0x0000
272 .byte 0x00, 0x93, 0xcf, 0x00
273
Li-Ta Lof84926e2004-11-04 18:36:06 +0000274 /* selgdt 0x20, unused */
Eric Biederman8ca8d762003-04-22 19:02:15 +0000275 .word 0x0000, 0x0000 /* dummy */
276 .byte 0x00, 0x00, 0x00, 0x00
277
Eric Biederman8ca8d762003-04-22 19:02:15 +0000278gdt_end:
279
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000280idtarg:
281 .word _idt_end - _idt - 1 /* limit */
282 .long _idt
283 .word 0
284_idt:
285 .fill 20, 8, 0 # idt is unitiailzed
286_idt_end:
287
288 .previous
Eric Biederman8ca8d762003-04-22 19:02:15 +0000289.code32