Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | #include <arch/asm.h> |
| 2 | #include <arch/intel.h> |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 3 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 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 | |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 18 | intel_chip_post_macro(0x13) /* post 13 */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 19 | |
| 20 | /** clear stack */ |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 21 | cld |
Eric Biederman | ae948f7 | 2003-07-14 20:40:38 +0000 | [diff] [blame] | 22 | leal _stack, %edi |
| 23 | movl $_estack, %ecx |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 24 | subl %edi, %ecx |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 25 | shrl $2, %ecx /* it is 32 bit align, right? */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 26 | xorl %eax, %eax |
| 27 | rep |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 28 | stosl |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 29 | |
| 30 | /** clear bss */ |
Eric Biederman | ae948f7 | 2003-07-14 20:40:38 +0000 | [diff] [blame] | 31 | leal _bss, %edi |
| 32 | movl $_ebss, %ecx |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 33 | subl %edi, %ecx |
| 34 | jz .Lnobss |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 35 | shrl $2, %ecx /* it is 32 bit align, right? */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 36 | xorl %eax, %eax |
| 37 | rep |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 38 | stosl |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 39 | .Lnobss: |
| 40 | |
| 41 | /* set new stack */ |
| 42 | movl $_estack, %esp |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 43 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 44 | /* Push the cpu index and struct cpu */ |
| 45 | pushl $0 |
| 46 | pushl $0 |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 47 | |
| 48 | /* push the boot_complete flag */ |
| 49 | pushl %ebp |
| 50 | |
| 51 | /* Save the stack location */ |
| 52 | movl %esp, %ebp |
| 53 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 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 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 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 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 79 | /* Restore the stack location */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 80 | movl %ebp, %esp |
| 81 | |
| 82 | /* The boot_complete flag has already been pushed */ |
Eric Biederman | ae948f7 | 2003-07-14 20:40:38 +0000 | [diff] [blame] | 83 | call hardwaremain |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 84 | /*NOTREACHED*/ |
| 85 | .Lhlt: |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 86 | intel_chip_post_macro(0xee) /* post ee */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 87 | hlt |
| 88 | jmp .Lhlt |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 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 |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 213 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 214 | pushl %esp /* Pointer to structure on the stack */ |
| 215 | call x86_exception |
| 216 | pop %eax /* Drop the pointer */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 217 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 218 | popl %eax |
| 219 | popl %ecx |
| 220 | popl %edx |
| 221 | popl %ebx |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 222 | popl %ebp /* Ignore saved %esp value */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 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 |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 246 | |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 247 | gdt_limit = gdt_end - gdt - 1 /* compute the table limit */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 248 | gdtaddr: |
| 249 | .word gdt_limit |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 250 | .long gdt /* we know the offset */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 251 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 252 | .data |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 253 | |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 254 | /* This is the gdt for GCC part of coreboot. |
| 255 | * It is different from the gdt in ROMCC/ASM part of coreboot |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 256 | * which is defined in entry32.inc */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 257 | gdt: |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 258 | /* selgdt 0, unused */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 259 | .word 0x0000, 0x0000 /* dummy */ |
| 260 | .byte 0x00, 0x00, 0x00, 0x00 |
| 261 | |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 262 | /* selgdt 8, unused */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 263 | .word 0x0000, 0x0000 /* dummy */ |
| 264 | .byte 0x00, 0x00, 0x00, 0x00 |
| 265 | |
Yinghai Lu | 30b4abe | 2007-04-06 19:57:42 +0000 | [diff] [blame] | 266 | /* selgdt 0x10, flat code segment */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 267 | .word 0xffff, 0x0000 |
Yinghai Lu | 30b4abe | 2007-04-06 19:57:42 +0000 | [diff] [blame] | 268 | .byte 0x00, 0x9b, 0xcf, 0x00 /* G=1 and 0x0f, So we get 4Gbytes for limit */ |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 269 | |
| 270 | /* selgdt 0x18, flat data segment */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 271 | .word 0xffff, 0x0000 |
| 272 | .byte 0x00, 0x93, 0xcf, 0x00 |
| 273 | |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 274 | /* selgdt 0x20, unused */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 275 | .word 0x0000, 0x0000 /* dummy */ |
| 276 | .byte 0x00, 0x00, 0x00, 0x00 |
| 277 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 278 | gdt_end: |
| 279 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 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 |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 289 | .code32 |