Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Martin Roth | 9df9e939 | 2016-01-12 15:55:28 -0700 | [diff] [blame] | 2 | |
Raul E Rangel | da68c9d | 2021-09-22 10:45:51 -0600 | [diff] [blame] | 3 | #include <cpu/x86/cpu_info.S.inc> |
Stefan Reinauer | 5f5436f | 2010-04-25 20:42:02 +0000 | [diff] [blame] | 4 | #include <cpu/x86/post_code.h> |
Patrick Rudolph | 776da08 | 2019-10-25 08:09:33 +0200 | [diff] [blame] | 5 | #include <arch/ram_segs.h> |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 6 | |
Elyes HAOUAS | f79f775 | 2021-12-12 21:43:13 +0100 | [diff] [blame] | 7 | /* Place the stack in the bss section. It's not necessary to define it in |
Aaron Durbin | 633f112 | 2013-02-06 15:28:40 -0600 | [diff] [blame] | 8 | * the linker script. */ |
| 9 | .section .bss, "aw", @nobits |
| 10 | .global _stack |
| 11 | .global _estack |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 12 | .global _stack_size |
Aaron Durbin | 633f112 | 2013-02-06 15:28:40 -0600 | [diff] [blame] | 13 | |
Kyösti Mälkki | 2fbb677 | 2018-05-15 19:50:20 +0300 | [diff] [blame] | 14 | /* Stack alignment is not enforced with rmodule loader, reserve one |
| 15 | * extra CPU such that alignment can be enforced on entry. */ |
Aaron Durbin | 633f112 | 2013-02-06 15:28:40 -0600 | [diff] [blame] | 16 | .align CONFIG_STACK_SIZE |
| 17 | _stack: |
Kyösti Mälkki | 2fbb677 | 2018-05-15 19:50:20 +0300 | [diff] [blame] | 18 | .space (CONFIG_MAX_CPUS+1)*CONFIG_STACK_SIZE |
Aaron Durbin | 633f112 | 2013-02-06 15:28:40 -0600 | [diff] [blame] | 19 | _estack: |
Julius Werner | 82d16b1 | 2020-12-30 15:51:10 -0800 | [diff] [blame] | 20 | .set _stack_size, _estack - _stack |
Aaron Durbin | 633f112 | 2013-02-06 15:28:40 -0600 | [diff] [blame] | 21 | |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 22 | .section ".text._start", "ax", @progbits |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 23 | #if ENV_X86_64 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 24 | .code64 |
| 25 | #else |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 26 | .code32 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 27 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 28 | .globl _start |
| 29 | _start: |
| 30 | cli |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 31 | #if ENV_X86_64 |
Patrick Rudolph | d023909 | 2021-06-11 21:24:10 +0200 | [diff] [blame] | 32 | movabs $gdtaddr, %rax |
| 33 | lgdt (%rax) |
| 34 | #else |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 35 | lgdt %cs:gdtaddr |
Patrick Rudolph | 776da08 | 2019-10-25 08:09:33 +0200 | [diff] [blame] | 36 | ljmp $RAM_CODE_SEG, $1f |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 37 | #endif |
Patrick Rudolph | 776da08 | 2019-10-25 08:09:33 +0200 | [diff] [blame] | 38 | 1: movl $RAM_DATA_SEG, %eax |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 39 | movl %eax, %ds |
| 40 | movl %eax, %es |
| 41 | movl %eax, %ss |
Raul E Rangel | ea5c311 | 2021-09-21 10:17:24 -0600 | [diff] [blame] | 42 | xor %eax, %eax /* zero out the gs and fs segment index */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 43 | movl %eax, %fs |
Raul E Rangel | ea5c311 | 2021-09-21 10:17:24 -0600 | [diff] [blame] | 44 | movl %eax, %gs /* Will be used for cpu_info */ |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 45 | #if ENV_X86_64 |
Patrick Rudolph | 776da08 | 2019-10-25 08:09:33 +0200 | [diff] [blame] | 46 | mov $RAM_CODE_SEG64, %ecx |
Elyes HAOUAS | 2ea751a | 2018-12-27 09:21:02 +0100 | [diff] [blame] | 47 | call SetCodeSelector |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 48 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 49 | |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 50 | post_code(POST_ENTRY_C_START) /* post 13 */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 51 | |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 52 | cld |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 53 | |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 54 | #if ENV_X86_64 |
Patrick Rudolph | d023909 | 2021-06-11 21:24:10 +0200 | [diff] [blame] | 55 | mov %rdi, %rax |
| 56 | movabs %rax, _cbmem_top_ptr |
| 57 | movabs $_stack, %rdi |
Arthur Heymans | 7c9a0e8 | 2019-10-23 17:02:50 +0200 | [diff] [blame] | 58 | #else |
| 59 | /* The return argument is at 0(%esp), the calling argument at 4(%esp) */ |
| 60 | movl 4(%esp), %eax |
| 61 | movl %eax, _cbmem_top_ptr |
Patrick Rudolph | d023909 | 2021-06-11 21:24:10 +0200 | [diff] [blame] | 62 | leal _stack, %edi |
Arthur Heymans | 7c9a0e8 | 2019-10-23 17:02:50 +0200 | [diff] [blame] | 63 | #endif |
| 64 | |
Aaron Durbin | 633f112 | 2013-02-06 15:28:40 -0600 | [diff] [blame] | 65 | /** poison the stack. Code should not count on the |
| 66 | * stack being full of zeros. This stack poisoning |
| 67 | * recently uncovered a bug in the broadcast SIPI |
| 68 | * code. |
| 69 | */ |
Aaron Durbin | 633f112 | 2013-02-06 15:28:40 -0600 | [diff] [blame] | 70 | movl $_estack, %ecx |
| 71 | subl %edi, %ecx |
| 72 | shrl $2, %ecx /* it is 32 bit aligned, right? */ |
| 73 | movl $0xDEADBEEF, %eax |
| 74 | rep |
| 75 | stosl |
| 76 | |
Kyösti Mälkki | 2fbb677 | 2018-05-15 19:50:20 +0300 | [diff] [blame] | 77 | /* Set new stack with enforced alignment. */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 78 | movl $_estack, %esp |
Kyösti Mälkki | 2fbb677 | 2018-05-15 19:50:20 +0300 | [diff] [blame] | 79 | andl $(~(CONFIG_STACK_SIZE-1)), %esp |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 80 | |
Raul E Rangel | da68c9d | 2021-09-22 10:45:51 -0600 | [diff] [blame] | 81 | push_cpu_info |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 82 | |
Raul E Rangel | b2346a5 | 2021-09-22 14:56:51 -0600 | [diff] [blame] | 83 | #if CONFIG(CPU_INFO_V2) |
| 84 | /* Allocate the per_cpu_segment_data on the stack */ |
| 85 | push_per_cpu_segment_data |
| 86 | |
| 87 | /* |
| 88 | * Update the BSP's per_cpu_segment_descriptor to point to the |
| 89 | * per_cpu_segment_data that was allocated on the stack. |
| 90 | */ |
| 91 | set_segment_descriptor_base $per_cpu_segment_descriptors, %esp |
| 92 | |
Raul E Rangel | 1eae39f | 2021-10-08 13:10:38 -0600 | [diff] [blame] | 93 | mov $per_cpu_segment_selector, %eax |
| 94 | movl (%eax), %eax |
Raul E Rangel | b2346a5 | 2021-09-22 14:56:51 -0600 | [diff] [blame] | 95 | mov %eax, %gs |
| 96 | #endif |
| 97 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 98 | /* |
| 99 | * Now we are finished. Memory is up, data is copied and |
| 100 | * bss is cleared. Now we call the main routine and |
| 101 | * let it do the rest. |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 102 | */ |
Subrata Banik | 38e4a2d | 2021-05-05 19:34:07 +0530 | [diff] [blame] | 103 | post_code(POST_PRE_HARDWAREMAIN) /* post 6e */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 104 | |
Kyösti Mälkki | 4796c32 | 2017-03-15 08:07:22 +0200 | [diff] [blame] | 105 | andl $0xFFFFFFF0, %esp |
| 106 | |
Harshit Sharma | 9c88fb8 | 2020-06-17 20:19:00 -0700 | [diff] [blame] | 107 | #if CONFIG(ASAN_IN_RAMSTAGE) |
| 108 | call asan_init |
| 109 | #endif |
| 110 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 111 | #if CONFIG(GDB_WAIT) |
Kyösti Mälkki | f2f7f03 | 2014-04-04 15:05:28 +0300 | [diff] [blame] | 112 | call gdb_hw_init |
Denis 'GNUtoo' Carikli | e4cece0 | 2012-06-22 15:56:37 +0200 | [diff] [blame] | 113 | call gdb_stub_breakpoint |
| 114 | #endif |
Stefan Reinauer | 6adef08 | 2013-05-09 16:30:06 -0700 | [diff] [blame] | 115 | call main |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 116 | /* NOTREACHED */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 117 | .Lhlt: |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 118 | post_code(POST_DEAD_CODE) /* post ee */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 119 | hlt |
| 120 | jmp .Lhlt |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 121 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 122 | #if CONFIG(GDB_WAIT) |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 123 | |
| 124 | .globl gdb_stub_breakpoint |
| 125 | gdb_stub_breakpoint: |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 126 | #if ENV_X86_64 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 127 | pop %rax /* Return address */ |
| 128 | pushfl |
| 129 | push %cs |
| 130 | push %rax /* Return address */ |
| 131 | push $0 /* No error code */ |
| 132 | push $32 /* vector 32 is user defined */ |
| 133 | #else |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 134 | popl %eax /* Return address */ |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 135 | pushfl |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 136 | pushl %cs |
| 137 | pushl %eax /* Return address */ |
| 138 | pushl $0 /* No error code */ |
| 139 | pushl $32 /* vector 32 is user defined */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 140 | #endif |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 141 | jmp int_hand |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 142 | #endif |
| 143 | |
Aaron Durbin | 4b032e4 | 2018-04-20 01:39:30 -0600 | [diff] [blame] | 144 | .globl gdt, gdt_end |
Raul E Rangel | b2346a5 | 2021-09-22 14:56:51 -0600 | [diff] [blame] | 145 | .global per_cpu_segment_descriptors, per_cpu_segment_selector |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 146 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 147 | gdtaddr: |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 148 | .word gdt_end - gdt - 1 |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 149 | #if ENV_X86_64 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 150 | .quad gdt |
| 151 | #else |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 152 | .long gdt /* we know the offset */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 153 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 154 | |
Raul E Rangel | b2346a5 | 2021-09-22 14:56:51 -0600 | [diff] [blame] | 155 | .data |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 156 | |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 157 | /* This is the gdt for GCC part of coreboot. |
Arthur Heymans | 1cb9cd5 | 2019-11-28 16:05:08 +0100 | [diff] [blame] | 158 | * It is different from the gdt in ASM part of coreboot |
Kyösti Mälkki | 97b76f7 | 2020-11-19 16:41:28 +0200 | [diff] [blame] | 159 | * which is defined in gdt_init.S |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 160 | * |
| 161 | * When the machine is initially started, we use a very simple |
Kyösti Mälkki | 97b76f7 | 2020-11-19 16:41:28 +0200 | [diff] [blame] | 162 | * gdt from ROM (that in gdt_init.S) which only contains those |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 163 | * entries we need for protected mode. |
| 164 | * |
| 165 | * When we're executing code from RAM, we want to do more complex |
Elyes HAOUAS | 777ea89 | 2016-07-29 07:40:41 +0200 | [diff] [blame] | 166 | * stuff, like initializing PCI option ROMs in real mode, or doing |
| 167 | * a resume from a suspend to RAM. |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 168 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 169 | gdt: |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 170 | /* selgdt 0, unused */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 171 | .word 0x0000, 0x0000 /* dummy */ |
| 172 | .byte 0x00, 0x00, 0x00, 0x00 |
| 173 | |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 174 | /* selgdt 8, unused */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 175 | .word 0x0000, 0x0000 /* dummy */ |
| 176 | .byte 0x00, 0x00, 0x00, 0x00 |
| 177 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 178 | /* selgdt 0x10, flat code segment */ |
| 179 | .word 0xffff, 0x0000 |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 180 | .byte 0x00, 0x9b, 0xcf, 0x00 /* G=1 and 0x0f, So we get 4Gbytes for |
| 181 | * limit |
| 182 | */ |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 183 | |
| 184 | /* selgdt 0x18, flat data segment */ |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 185 | .word 0xffff, 0x0000 |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 186 | #if ENV_X86_64 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 187 | .byte 0x00, 0x92, 0xcf, 0x00 |
| 188 | #else |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 189 | .byte 0x00, 0x93, 0xcf, 0x00 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 190 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 191 | |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 192 | /* selgdt 0x20, unused */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 193 | .word 0x0000, 0x0000 /* dummy */ |
| 194 | .byte 0x00, 0x00, 0x00, 0x00 |
| 195 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 196 | /* The next two entries are used for executing VGA option ROMs */ |
| 197 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 198 | /* selgdt 0x28 16 bit 64k code at 0x00000000 */ |
Elyes HAOUAS | 2ea751a | 2018-12-27 09:21:02 +0100 | [diff] [blame] | 199 | .word 0xffff, 0x0000 |
| 200 | .byte 0, 0x9a, 0, 0 |
Stefan Reinauer | f8a5c6e | 2009-05-29 13:08:27 +0000 | [diff] [blame] | 201 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 202 | /* selgdt 0x30 16 bit 64k data at 0x00000000 */ |
Elyes HAOUAS | 2ea751a | 2018-12-27 09:21:02 +0100 | [diff] [blame] | 203 | .word 0xffff, 0x0000 |
| 204 | .byte 0, 0x92, 0, 0 |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 205 | |
| 206 | /* The next two entries are used for ACPI S3 RESUME */ |
| 207 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 208 | /* selgdt 0x38, flat data segment 16 bit */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 209 | .word 0x0000, 0x0000 /* dummy */ |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 210 | .byte 0x00, 0x93, 0x8f, 0x00 /* G=1 and 0x0f, So we get 4Gbytes for |
| 211 | * limit |
| 212 | */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 213 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 214 | /* selgdt 0x40, flat code segment 16 bit */ |
| 215 | .word 0xffff, 0x0000 |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 216 | .byte 0x00, 0x9b, 0x8f, 0x00 /* G=1 and 0x0f, So we get 4Gbytes for |
| 217 | * limit |
| 218 | */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 219 | |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 220 | #if ENV_X86_64 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 221 | /* selgdt 0x48, flat x64 code segment */ |
| 222 | .word 0xffff, 0x0000 |
| 223 | .byte 0x00, 0x9b, 0xaf, 0x00 |
| 224 | #endif |
Raul E Rangel | b2346a5 | 2021-09-22 14:56:51 -0600 | [diff] [blame] | 225 | #if CONFIG(CPU_INFO_V2) |
| 226 | per_cpu_segment_descriptors: |
| 227 | .rept CONFIG_MAX_CPUS |
| 228 | /* flat data segment */ |
| 229 | .word 0xffff, 0x0000 |
| 230 | #if ENV_X86_64 |
| 231 | .byte 0x00, 0x92, 0xcf, 0x00 |
| 232 | #else |
| 233 | .byte 0x00, 0x93, 0xcf, 0x00 |
| 234 | #endif |
| 235 | .endr |
| 236 | #endif /* CPU_INFO_V2 */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 237 | gdt_end: |
| 238 | |
Raul E Rangel | b2346a5 | 2021-09-22 14:56:51 -0600 | [diff] [blame] | 239 | #if CONFIG(CPU_INFO_V2) |
| 240 | /* Segment selector pointing to the first per_cpu_segment_descriptor. */ |
| 241 | per_cpu_segment_selector: |
| 242 | .long per_cpu_segment_descriptors - gdt |
| 243 | #endif /* CPU_INFO_V2 */ |
| 244 | |
Patrick Georgi | 546f29d | 2016-01-22 12:43:43 +0100 | [diff] [blame] | 245 | .section ".text._start", "ax", @progbits |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 246 | #if ENV_X86_64 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 247 | SetCodeSelector: |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 248 | # save rsp because iret will align it to a 16 byte boundary |
Patrick Georgi | 0302b06 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 249 | mov %rsp, %rdx |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 250 | |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 251 | # use iret to jump to a 64-bit offset in a new code segment |
| 252 | # iret will pop cs:rip, flags, then ss:rsp |
Patrick Georgi | 0302b06 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 253 | mov %ss, %ax # need to push ss.. |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 254 | push %rax # push ss instruction not valid in x64 mode, |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 255 | # so use ax |
Patrick Georgi | 0302b06 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 256 | push %rsp |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 257 | pushfq |
Patrick Georgi | 0302b06 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 258 | push %rcx # cx is code segment selector from caller |
Patrick Rudolph | d023909 | 2021-06-11 21:24:10 +0200 | [diff] [blame] | 259 | movabs $setCodeSelectorLongJump, %rax |
Patrick Georgi | 0302b06 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 260 | push %rax |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 261 | |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 262 | # the iret will continue at next instruction, with the new cs value |
| 263 | # loaded |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 264 | iretq |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 265 | |
| 266 | setCodeSelectorLongJump: |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 267 | # restore rsp, it might not have been 16-byte aligned on entry |
Patrick Georgi | 0302b06 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 268 | mov %rdx, %rsp |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 269 | ret |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 270 | #endif |