Martin Roth | 9df9e939 | 2016-01-12 15:55:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
Stefan Reinauer | 5f5436f | 2010-04-25 20:42:02 +0000 | [diff] [blame] | 14 | #include <cpu/x86/post_code.h> |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 15 | |
Aaron Durbin | 633f112 | 2013-02-06 15:28:40 -0600 | [diff] [blame] | 16 | /* Place the stack in the bss section. It's not necessary to define it in the |
| 17 | * the linker script. */ |
| 18 | .section .bss, "aw", @nobits |
| 19 | .global _stack |
| 20 | .global _estack |
| 21 | |
| 22 | .align CONFIG_STACK_SIZE |
| 23 | _stack: |
| 24 | .space CONFIG_MAX_CPUS*CONFIG_STACK_SIZE |
| 25 | _estack: |
Aaron Durbin | 38c326d | 2013-05-06 12:22:23 -0500 | [diff] [blame] | 26 | #if CONFIG_COOP_MULTITASKING |
| 27 | .global thread_stacks |
| 28 | thread_stacks: |
| 29 | .space CONFIG_STACK_SIZE*CONFIG_NUM_THREADS |
| 30 | #endif |
Aaron Durbin | 633f112 | 2013-02-06 15:28:40 -0600 | [diff] [blame] | 31 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 32 | .section ".text._start", "ax", @progbits |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 33 | #ifdef __x86_64__ |
| 34 | .code64 |
| 35 | #else |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 36 | .code32 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 37 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 38 | .globl _start |
| 39 | _start: |
| 40 | cli |
| 41 | lgdt %cs:gdtaddr |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 42 | #ifndef __x86_64__ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 43 | ljmp $0x10, $1f |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 44 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 45 | 1: movl $0x18, %eax |
| 46 | movl %eax, %ds |
| 47 | movl %eax, %es |
| 48 | movl %eax, %ss |
| 49 | movl %eax, %fs |
| 50 | movl %eax, %gs |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 51 | #ifdef __x86_64__ |
| 52 | mov $0x48, %ecx |
| 53 | call SetCodeSelector |
| 54 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 55 | |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 56 | post_code(POST_ENTRY_C_START) /* post 13 */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 57 | |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 58 | cld |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 59 | |
Aaron Durbin | 633f112 | 2013-02-06 15:28:40 -0600 | [diff] [blame] | 60 | /** poison the stack. Code should not count on the |
| 61 | * stack being full of zeros. This stack poisoning |
| 62 | * recently uncovered a bug in the broadcast SIPI |
| 63 | * code. |
| 64 | */ |
| 65 | leal _stack, %edi |
| 66 | movl $_estack, %ecx |
| 67 | subl %edi, %ecx |
| 68 | shrl $2, %ecx /* it is 32 bit aligned, right? */ |
| 69 | movl $0xDEADBEEF, %eax |
| 70 | rep |
| 71 | stosl |
| 72 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 73 | /* set new stack */ |
| 74 | movl $_estack, %esp |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 75 | |
Aaron Durbin | 38c326d | 2013-05-06 12:22:23 -0500 | [diff] [blame] | 76 | #if CONFIG_COOP_MULTITASKING |
| 77 | /* Push the thread pointer. */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 78 | push $0 |
Aaron Durbin | 38c326d | 2013-05-06 12:22:23 -0500 | [diff] [blame] | 79 | #endif |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 80 | /* Push the cpu index and struct cpu */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 81 | push $0 |
| 82 | push $0 |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 83 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 84 | /* Initialize the Interrupt Descriptor table */ |
| 85 | leal _idt, %edi |
| 86 | leal vec0, %ebx |
| 87 | movl $(0x10 << 16), %eax /* cs selector */ |
| 88 | |
| 89 | 1: movw %bx, %ax |
| 90 | movl %ebx, %edx |
| 91 | movw $0x8E00, %dx /* Interrupt gate - dpl=0, present */ |
| 92 | movl %eax, 0(%edi) |
| 93 | movl %edx, 4(%edi) |
| 94 | addl $6, %ebx |
| 95 | addl $8, %edi |
| 96 | cmpl $_idt_end, %edi |
| 97 | jne 1b |
| 98 | |
| 99 | /* Load the Interrupt descriptor table */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 100 | #ifndef __x86_64__ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 101 | lidt idtarg |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 102 | #else |
| 103 | // FIXME port table to x64 - lidt idtarg |
| 104 | #endif |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 105 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 106 | /* |
| 107 | * Now we are finished. Memory is up, data is copied and |
| 108 | * bss is cleared. Now we call the main routine and |
| 109 | * let it do the rest. |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 110 | */ |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 111 | post_code(POST_PRE_HARDWAREMAIN) /* post fe */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 112 | |
Stefan Reinauer | 8ada152 | 2012-11-16 13:34:48 -0800 | [diff] [blame] | 113 | #if CONFIG_GDB_WAIT |
Kyösti Mälkki | f2f7f03 | 2014-04-04 15:05:28 +0300 | [diff] [blame] | 114 | call gdb_hw_init |
Denis 'GNUtoo' Carikli | e4cece0 | 2012-06-22 15:56:37 +0200 | [diff] [blame] | 115 | call gdb_stub_breakpoint |
| 116 | #endif |
Stefan Reinauer | 6adef08 | 2013-05-09 16:30:06 -0700 | [diff] [blame] | 117 | call main |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 118 | /* NOTREACHED */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 119 | .Lhlt: |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 120 | post_code(POST_DEAD_CODE) /* post ee */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 121 | hlt |
| 122 | jmp .Lhlt |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 123 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 124 | vec0: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 125 | push $0 /* error code */ |
| 126 | push $0 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 127 | jmp int_hand |
| 128 | vec1: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 129 | push $0 /* error code */ |
| 130 | push $1 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 131 | jmp int_hand |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 132 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 133 | vec2: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 134 | push $0 /* error code */ |
| 135 | push $2 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 136 | jmp int_hand |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 137 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 138 | vec3: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 139 | push $0 /* error code */ |
| 140 | push $3 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 141 | jmp int_hand |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 142 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 143 | vec4: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 144 | push $0 /* error code */ |
| 145 | push $4 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 146 | jmp int_hand |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 147 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 148 | vec5: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 149 | push $0 /* error code */ |
| 150 | push $5 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 151 | jmp int_hand |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 152 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 153 | vec6: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 154 | push $0 /* error code */ |
| 155 | push $6 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 156 | jmp int_hand |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 157 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 158 | vec7: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 159 | push $0 /* error code */ |
| 160 | push $7 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 161 | jmp int_hand |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 162 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 163 | vec8: |
| 164 | /* error code */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 165 | push $8 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 166 | jmp int_hand |
| 167 | .word 0x9090 |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 168 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 169 | vec9: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 170 | push $0 /* error code */ |
| 171 | push $9 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 172 | jmp int_hand |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 173 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 174 | vec10: |
| 175 | /* error code */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 176 | push $10 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 177 | jmp int_hand |
| 178 | .word 0x9090 |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 179 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 180 | vec11: |
| 181 | /* error code */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 182 | push $11 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 183 | jmp int_hand |
| 184 | .word 0x9090 |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 185 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 186 | vec12: |
| 187 | /* error code */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 188 | push $12 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 189 | jmp int_hand |
| 190 | .word 0x9090 |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 191 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 192 | vec13: |
| 193 | /* error code */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 194 | push $13 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 195 | jmp int_hand |
| 196 | .word 0x9090 |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 197 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 198 | vec14: |
| 199 | /* error code */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 200 | push $14 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 201 | jmp int_hand |
| 202 | .word 0x9090 |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 203 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 204 | vec15: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 205 | push $0 /* error code */ |
| 206 | push $15 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 207 | jmp int_hand |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 208 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 209 | vec16: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 210 | push $0 /* error code */ |
| 211 | push $16 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 212 | jmp int_hand |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 213 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 214 | vec17: |
| 215 | /* error code */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 216 | push $17 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 217 | jmp int_hand |
| 218 | .word 0x9090 |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 219 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 220 | vec18: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 221 | push $0 /* error code */ |
| 222 | push $18 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 223 | jmp int_hand |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 224 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 225 | vec19: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 226 | push $0 /* error code */ |
| 227 | push $19 /* vector */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 228 | jmp int_hand |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 229 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 230 | int_hand: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 231 | /* At this point, on x86-32, on the stack there is: |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 232 | * 0(%esp) vector |
| 233 | * 4(%esp) error code |
| 234 | * 8(%esp) eip |
| 235 | * 12(%esp) cs |
| 236 | * 16(%esp) eflags |
| 237 | */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 238 | #ifdef __x86_64__ |
| 239 | push %rdi |
| 240 | push %rsi |
| 241 | push %rbp |
| 242 | /* Original stack pointer */ |
| 243 | lea 32(%rsp), %rbp |
| 244 | push %rbp |
| 245 | push %rbx |
| 246 | push %rdx |
| 247 | push %rcx |
| 248 | push %rax |
| 249 | |
| 250 | push %rsp /* Pointer to structure on the stack */ |
| 251 | call x86_exception |
| 252 | pop %rax /* Drop the pointer */ |
| 253 | |
| 254 | pop %rax |
| 255 | pop %rcx |
| 256 | pop %rdx |
| 257 | pop %rbx |
| 258 | pop %rbp /* Ignore saved %rsp value */ |
| 259 | pop %rbp |
| 260 | pop %rsi |
| 261 | pop %rdi |
| 262 | |
| 263 | add $8, %rsp /* pop of the vector and error code */ |
| 264 | #else |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 265 | pushl %edi |
| 266 | pushl %esi |
| 267 | pushl %ebp |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 268 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 269 | /* Original stack pointer */ |
| 270 | leal 32(%esp), %ebp |
| 271 | pushl %ebp |
| 272 | pushl %ebx |
| 273 | pushl %edx |
| 274 | pushl %ecx |
| 275 | pushl %eax |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 276 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 277 | pushl %esp /* Pointer to structure on the stack */ |
| 278 | call x86_exception |
| 279 | pop %eax /* Drop the pointer */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 280 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 281 | popl %eax |
| 282 | popl %ecx |
| 283 | popl %edx |
| 284 | popl %ebx |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 285 | popl %ebp /* Ignore saved %esp value */ |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 286 | popl %ebp |
| 287 | popl %esi |
| 288 | popl %edi |
| 289 | |
| 290 | addl $8, %esp /* pop of the vector and error code */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 291 | #endif |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 292 | |
| 293 | iret |
| 294 | |
Stefan Reinauer | 8ada152 | 2012-11-16 13:34:48 -0800 | [diff] [blame] | 295 | #if CONFIG_GDB_WAIT |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 296 | |
| 297 | .globl gdb_stub_breakpoint |
| 298 | gdb_stub_breakpoint: |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 299 | #ifdef __x86_64__ |
| 300 | pop %rax /* Return address */ |
| 301 | pushfl |
| 302 | push %cs |
| 303 | push %rax /* Return address */ |
| 304 | push $0 /* No error code */ |
| 305 | push $32 /* vector 32 is user defined */ |
| 306 | #else |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 307 | popl %eax /* Return address */ |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 308 | pushfl |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 309 | pushl %cs |
| 310 | pushl %eax /* Return address */ |
| 311 | pushl $0 /* No error code */ |
| 312 | pushl $32 /* vector 32 is user defined */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 313 | #endif |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 314 | jmp int_hand |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 315 | #endif |
| 316 | |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 317 | .globl gdt, gdt_end, idtarg |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 318 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 319 | gdtaddr: |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 320 | .word gdt_end - gdt - 1 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 321 | #ifdef __x86_64__ |
| 322 | .quad gdt |
| 323 | #else |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 324 | .long gdt /* we know the offset */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 325 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 326 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 327 | .data |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 328 | |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 329 | /* This is the gdt for GCC part of coreboot. |
| 330 | * It is different from the gdt in ROMCC/ASM part of coreboot |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 331 | * which is defined in entry32.inc |
| 332 | * |
| 333 | * When the machine is initially started, we use a very simple |
| 334 | * gdt from rom (that in entry32.inc) which only contains those |
| 335 | * entries we need for protected mode. |
| 336 | * |
| 337 | * When we're executing code from RAM, we want to do more complex |
| 338 | * stuff, like initializing PCI option roms in real mode, or doing |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 339 | * a resume from a suspend to ram. |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 340 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 341 | gdt: |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 342 | /* selgdt 0, unused */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 343 | .word 0x0000, 0x0000 /* dummy */ |
| 344 | .byte 0x00, 0x00, 0x00, 0x00 |
| 345 | |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 346 | /* selgdt 8, unused */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 347 | .word 0x0000, 0x0000 /* dummy */ |
| 348 | .byte 0x00, 0x00, 0x00, 0x00 |
| 349 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 350 | /* selgdt 0x10, flat code segment */ |
| 351 | .word 0xffff, 0x0000 |
| 352 | .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] | 353 | |
| 354 | /* selgdt 0x18, flat data segment */ |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 355 | .word 0xffff, 0x0000 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 356 | #ifdef __x86_64__ |
| 357 | .byte 0x00, 0x92, 0xcf, 0x00 |
| 358 | #else |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 359 | .byte 0x00, 0x93, 0xcf, 0x00 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 360 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 361 | |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 362 | /* selgdt 0x20, unused */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 363 | .word 0x0000, 0x0000 /* dummy */ |
| 364 | .byte 0x00, 0x00, 0x00, 0x00 |
| 365 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 366 | /* The next two entries are used for executing VGA option ROMs */ |
| 367 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 368 | /* selgdt 0x28 16 bit 64k code at 0x00000000 */ |
Stefan Reinauer | f8a5c6e | 2009-05-29 13:08:27 +0000 | [diff] [blame] | 369 | .word 0xffff, 0x0000 |
| 370 | .byte 0, 0x9a, 0, 0 |
| 371 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 372 | /* selgdt 0x30 16 bit 64k data at 0x00000000 */ |
Stefan Reinauer | f8a5c6e | 2009-05-29 13:08:27 +0000 | [diff] [blame] | 373 | .word 0xffff, 0x0000 |
| 374 | .byte 0, 0x92, 0, 0 |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 375 | |
| 376 | /* The next two entries are used for ACPI S3 RESUME */ |
| 377 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 378 | /* selgdt 0x38, flat data segment 16 bit */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 379 | .word 0x0000, 0x0000 /* dummy */ |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 380 | .byte 0x00, 0x93, 0x8f, 0x00 /* G=1 and 0x0f, So we get 4Gbytes for limit */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 381 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 382 | /* selgdt 0x40, flat code segment 16 bit */ |
| 383 | .word 0xffff, 0x0000 |
| 384 | .byte 0x00, 0x9b, 0x8f, 0x00 /* G=1 and 0x0f, So we get 4Gbytes for limit */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 385 | |
| 386 | #ifdef __x86_64__ |
| 387 | /* selgdt 0x48, flat x64 code segment */ |
| 388 | .word 0xffff, 0x0000 |
| 389 | .byte 0x00, 0x9b, 0xaf, 0x00 |
| 390 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 391 | gdt_end: |
| 392 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 393 | idtarg: |
| 394 | .word _idt_end - _idt - 1 /* limit */ |
| 395 | .long _idt |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 396 | .word 0 |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 397 | _idt: |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 398 | .fill 20, 8, 0 # idt is uninitialized |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 399 | _idt_end: |
| 400 | |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 401 | #ifdef __x86_64__ |
| 402 | SetCodeSelector: |
| 403 | .intel_syntax noprefix |
| 404 | |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame^] | 405 | # save rsp because iret will align it to a 16 byte boundary |
| 406 | mov rdx, rsp |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 407 | |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame^] | 408 | # use iret to jump to a 64-bit offset in a new code segment |
| 409 | # iret will pop cs:rip, flags, then ss:rsp |
| 410 | mov ax, ss # need to push ss.. |
| 411 | push rax # push ss instuction not valid in x64 mode, so use ax |
| 412 | push rsp |
| 413 | pushfq |
| 414 | push rcx # cx is code segment selector from caller |
| 415 | mov rax, offset setCodeSelectorLongJump |
| 416 | push rax |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 417 | |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame^] | 418 | # the iret will continue at next instruction, with the new cs value loaded |
| 419 | iretq |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 420 | |
| 421 | setCodeSelectorLongJump: |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame^] | 422 | # restore rsp, it might not have been 16-byte aligned on entry |
| 423 | mov rsp, rdx |
| 424 | ret |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 425 | .att_syntax prefix |
| 426 | |
| 427 | .previous |
| 428 | .code64 |
| 429 | #else |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 430 | .previous |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 431 | .code32 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 432 | #endif |