1201_ht_bus0_dev0_fidvid_core.diff
[coreboot.git] / src / arch / i386 / lib / c_start.S
1 #include <arch/asm.h>
2 #include <arch/intel.h>
3
4         .section ".text"
5         .code32
6         .globl _start
7 _start:
8         cli
9         lgdt    %cs:gdtaddr
10         ljmp    $0x10, $1f
11 1:      movl    $0x18, %eax
12         movl    %eax, %ds
13         movl    %eax, %es
14         movl    %eax, %ss
15         movl    %eax, %fs
16         movl    %eax, %gs
17
18         intel_chip_post_macro(0x13)             /* post 13 */
19
20         /** clear stack */
21         cld
22         leal    _stack, %edi
23         movl    $_estack, %ecx
24         subl    %edi, %ecx
25         shrl    $2, %ecx   /* it is 32 bit align, right? */
26         xorl    %eax, %eax
27         rep
28         stosl
29
30         /** clear bss */
31         leal    _bss, %edi
32         movl    $_ebss, %ecx
33         subl    %edi, %ecx
34         jz      .Lnobss
35         shrl    $2, %ecx  /* it is 32 bit align, right? */
36         xorl    %eax, %eax
37         rep
38         stosl
39 .Lnobss:
40
41         /* set new stack */
42         movl    $_estack, %esp
43
44         /* Push the cpu index and struct cpu */
45         pushl   $0
46         pushl   $0
47
48         /* push the boot_complete flag */
49         pushl   %ebp
50
51         /* Save the stack location */
52         movl    %esp, %ebp
53
54         /* Initialize the Interrupt Descriptor table */
55         leal    _idt, %edi
56         leal    vec0, %ebx
57         movl    $(0x10 << 16), %eax     /* cs selector */
58
59 1:      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
72         /*
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
79         /* Restore the stack location */
80         movl    %ebp, %esp
81         
82         /* The boot_complete flag has already been pushed */
83         call    hardwaremain
84         /*NOTREACHED*/
85 .Lhlt:
86         intel_chip_post_macro(0xee)     /* post ee */
87         hlt
88         jmp     .Lhlt
89         
90 vec0:
91         pushl   $0 /* error code */
92         pushl   $0 /* vector */
93         jmp int_hand
94 vec1:
95         pushl   $0 /* error code */
96         pushl   $1 /* vector */
97         jmp int_hand
98         
99 vec2:
100         pushl   $0 /* error code */
101         pushl   $2 /* vector */
102         jmp int_hand
103         
104 vec3:
105         pushl   $0 /* error code */
106         pushl   $3 /* vector */
107         jmp     int_hand
108         
109 vec4:
110         pushl   $0 /* error code */
111         pushl   $4 /* vector */
112         jmp     int_hand
113         
114 vec5:
115         pushl   $0 /* error code */
116         pushl   $5 /* vector */
117         jmp     int_hand
118         
119 vec6:
120         pushl   $0 /* error code */
121         pushl   $6 /* vector */
122         jmp     int_hand
123         
124 vec7:
125         pushl   $0 /* error code */
126         pushl   $7 /* vector */
127         jmp     int_hand
128         
129 vec8:
130         /* error code */
131         pushl   $8 /* vector */
132         jmp     int_hand
133         .word   0x9090
134         
135 vec9:
136         pushl   $0 /* error code */
137         pushl   $9 /* vector */
138         jmp int_hand
139         
140 vec10:
141         /* error code */
142         pushl   $10 /* vector */
143         jmp     int_hand
144         .word   0x9090
145         
146 vec11:
147         /* error code */
148         pushl   $11 /* vector */
149         jmp     int_hand
150         .word   0x9090
151                 
152 vec12:
153         /* error code */
154         pushl   $12 /* vector */
155         jmp     int_hand
156         .word   0x9090
157         
158 vec13:
159         /* error code */
160         pushl   $13 /* vector */
161         jmp     int_hand
162         .word   0x9090
163         
164 vec14:
165         /* error code */
166         pushl   $14 /* vector */
167         jmp     int_hand
168         .word   0x9090
169         
170 vec15:
171         pushl   $0 /* error code */
172         pushl   $15 /* vector */
173         jmp     int_hand
174         
175 vec16:
176         pushl   $0 /* error code */
177         pushl   $16 /* vector */
178         jmp     int_hand
179         
180 vec17:
181         /* error code */
182         pushl   $17 /* vector */
183         jmp     int_hand
184         .word   0x9090
185         
186 vec18:
187         pushl   $0 /* error code */
188         pushl   $18 /* vector */
189         jmp     int_hand
190         
191 vec19:
192         pushl   $0 /* error code */
193         pushl   $19 /* vector */
194         jmp     int_hand
195 int_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
213
214         pushl   %esp    /* Pointer to structure on the stack */
215         call    x86_exception
216         pop     %eax    /* Drop the pointer */
217
218         popl    %eax
219         popl    %ecx
220         popl    %edx
221         popl    %ebx
222         popl    %ebp    /* Ignore saved %esp value */
223         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
234 gdb_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
246
247 gdt_limit = gdt_end - gdt - 1   /* compute the table limit */
248 gdtaddr:
249         .word   gdt_limit
250         .long   gdt             /* we know the offset */
251
252          .data
253
254         /* This is the gdt for GCC part of LinuxBIOS.
255          * It is different from the gdt in ROMCC/ASM part of LinuxBIOS
256          * which is defined in entry32.inc */
257 gdt:
258         /* selgdt 0, unused */
259         .word   0x0000, 0x0000          /* dummy */
260         .byte   0x00, 0x00, 0x00, 0x00
261
262         /* selgdt 8, unused */
263         .word   0x0000, 0x0000          /* dummy */
264         .byte   0x00, 0x00, 0x00, 0x00
265
266         /* selgdt 0x10, flat code segment */
267         .word   0xffff, 0x0000          
268         .byte   0x00, 0x9b, 0xcf, 0x00  
269
270         /* selgdt 0x18, flat data segment */
271         .word   0xffff, 0x0000          
272         .byte   0x00, 0x93, 0xcf, 0x00  
273
274         /* selgdt 0x20, unused */
275         .word   0x0000, 0x0000          /* dummy */
276         .byte   0x00, 0x00, 0x00, 0x00
277
278 gdt_end:
279
280 idtarg:
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
289 .code32