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 | |
Aaron Durbin | 633f112 | 2013-02-06 15:28:40 -0600 | [diff] [blame] | 7 | /* Place the stack in the bss section. It's not necessary to define it in the |
| 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 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 83 | /* |
| 84 | * Now we are finished. Memory is up, data is copied and |
| 85 | * bss is cleared. Now we call the main routine and |
| 86 | * let it do the rest. |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 87 | */ |
Subrata Banik | 38e4a2d | 2021-05-05 19:34:07 +0530 | [diff] [blame] | 88 | post_code(POST_PRE_HARDWAREMAIN) /* post 6e */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 89 | |
Kyösti Mälkki | 4796c32 | 2017-03-15 08:07:22 +0200 | [diff] [blame] | 90 | andl $0xFFFFFFF0, %esp |
| 91 | |
Harshit Sharma | 9c88fb8 | 2020-06-17 20:19:00 -0700 | [diff] [blame] | 92 | #if CONFIG(ASAN_IN_RAMSTAGE) |
| 93 | call asan_init |
| 94 | #endif |
| 95 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 96 | #if CONFIG(GDB_WAIT) |
Kyösti Mälkki | f2f7f03 | 2014-04-04 15:05:28 +0300 | [diff] [blame] | 97 | call gdb_hw_init |
Denis 'GNUtoo' Carikli | e4cece0 | 2012-06-22 15:56:37 +0200 | [diff] [blame] | 98 | call gdb_stub_breakpoint |
| 99 | #endif |
Stefan Reinauer | 6adef08 | 2013-05-09 16:30:06 -0700 | [diff] [blame] | 100 | call main |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 101 | /* NOTREACHED */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 102 | .Lhlt: |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 103 | post_code(POST_DEAD_CODE) /* post ee */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 104 | hlt |
| 105 | jmp .Lhlt |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 106 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 107 | #if CONFIG(GDB_WAIT) |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 108 | |
| 109 | .globl gdb_stub_breakpoint |
| 110 | gdb_stub_breakpoint: |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 111 | #if ENV_X86_64 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 112 | pop %rax /* Return address */ |
| 113 | pushfl |
| 114 | push %cs |
| 115 | push %rax /* Return address */ |
| 116 | push $0 /* No error code */ |
| 117 | push $32 /* vector 32 is user defined */ |
| 118 | #else |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 119 | popl %eax /* Return address */ |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 120 | pushfl |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 121 | pushl %cs |
| 122 | pushl %eax /* Return address */ |
| 123 | pushl $0 /* No error code */ |
| 124 | pushl $32 /* vector 32 is user defined */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 125 | #endif |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 126 | jmp int_hand |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 127 | #endif |
| 128 | |
Aaron Durbin | 4b032e4 | 2018-04-20 01:39:30 -0600 | [diff] [blame] | 129 | .globl gdt, gdt_end |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 130 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 131 | gdtaddr: |
Aaron Durbin | a146d58 | 2013-02-08 16:56:51 -0600 | [diff] [blame] | 132 | .word gdt_end - gdt - 1 |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 133 | #if ENV_X86_64 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 134 | .quad gdt |
| 135 | #else |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 136 | .long gdt /* we know the offset */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 137 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 138 | |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 139 | .data |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 140 | |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 141 | /* This is the gdt for GCC part of coreboot. |
Arthur Heymans | 1cb9cd5 | 2019-11-28 16:05:08 +0100 | [diff] [blame] | 142 | * 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] | 143 | * which is defined in gdt_init.S |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 144 | * |
| 145 | * 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] | 146 | * gdt from ROM (that in gdt_init.S) which only contains those |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 147 | * entries we need for protected mode. |
| 148 | * |
| 149 | * 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] | 150 | * stuff, like initializing PCI option ROMs in real mode, or doing |
| 151 | * a resume from a suspend to RAM. |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 152 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 153 | gdt: |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 154 | /* selgdt 0, unused */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 155 | .word 0x0000, 0x0000 /* dummy */ |
| 156 | .byte 0x00, 0x00, 0x00, 0x00 |
| 157 | |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 158 | /* selgdt 8, unused */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 159 | .word 0x0000, 0x0000 /* dummy */ |
| 160 | .byte 0x00, 0x00, 0x00, 0x00 |
| 161 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 162 | /* selgdt 0x10, flat code segment */ |
| 163 | .word 0xffff, 0x0000 |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 164 | .byte 0x00, 0x9b, 0xcf, 0x00 /* G=1 and 0x0f, So we get 4Gbytes for |
| 165 | * limit |
| 166 | */ |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 167 | |
| 168 | /* selgdt 0x18, flat data segment */ |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 169 | .word 0xffff, 0x0000 |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 170 | #if ENV_X86_64 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 171 | .byte 0x00, 0x92, 0xcf, 0x00 |
| 172 | #else |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 173 | .byte 0x00, 0x93, 0xcf, 0x00 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 174 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 175 | |
Li-Ta Lo | f84926e | 2004-11-04 18:36:06 +0000 | [diff] [blame] | 176 | /* selgdt 0x20, unused */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 177 | .word 0x0000, 0x0000 /* dummy */ |
| 178 | .byte 0x00, 0x00, 0x00, 0x00 |
| 179 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 180 | /* The next two entries are used for executing VGA option ROMs */ |
| 181 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 182 | /* selgdt 0x28 16 bit 64k code at 0x00000000 */ |
Elyes HAOUAS | 2ea751a | 2018-12-27 09:21:02 +0100 | [diff] [blame] | 183 | .word 0xffff, 0x0000 |
| 184 | .byte 0, 0x9a, 0, 0 |
Stefan Reinauer | f8a5c6e | 2009-05-29 13:08:27 +0000 | [diff] [blame] | 185 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 186 | /* selgdt 0x30 16 bit 64k data at 0x00000000 */ |
Elyes HAOUAS | 2ea751a | 2018-12-27 09:21:02 +0100 | [diff] [blame] | 187 | .word 0xffff, 0x0000 |
| 188 | .byte 0, 0x92, 0, 0 |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 189 | |
| 190 | /* The next two entries are used for ACPI S3 RESUME */ |
| 191 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 192 | /* selgdt 0x38, flat data segment 16 bit */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 193 | .word 0x0000, 0x0000 /* dummy */ |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 194 | .byte 0x00, 0x93, 0x8f, 0x00 /* G=1 and 0x0f, So we get 4Gbytes for |
| 195 | * limit |
| 196 | */ |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 197 | |
Stefan Reinauer | 607cdf6 | 2010-04-26 12:08:51 +0000 | [diff] [blame] | 198 | /* selgdt 0x40, flat code segment 16 bit */ |
| 199 | .word 0xffff, 0x0000 |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 200 | .byte 0x00, 0x9b, 0x8f, 0x00 /* G=1 and 0x0f, So we get 4Gbytes for |
| 201 | * limit |
| 202 | */ |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 203 | |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 204 | #if ENV_X86_64 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 205 | /* selgdt 0x48, flat x64 code segment */ |
| 206 | .word 0xffff, 0x0000 |
| 207 | .byte 0x00, 0x9b, 0xaf, 0x00 |
| 208 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 209 | gdt_end: |
| 210 | |
Patrick Georgi | 546f29d | 2016-01-22 12:43:43 +0100 | [diff] [blame] | 211 | .section ".text._start", "ax", @progbits |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 212 | #if ENV_X86_64 |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 213 | SetCodeSelector: |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 214 | # save rsp because iret will align it to a 16 byte boundary |
Patrick Georgi | 0302b06 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 215 | mov %rsp, %rdx |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 216 | |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 217 | # use iret to jump to a 64-bit offset in a new code segment |
| 218 | # iret will pop cs:rip, flags, then ss:rsp |
Patrick Georgi | 0302b06 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 219 | mov %ss, %ax # need to push ss.. |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 220 | push %rax # push ss instuction not valid in x64 mode, |
| 221 | # so use ax |
Patrick Georgi | 0302b06 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 222 | push %rsp |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 223 | pushfq |
Patrick Georgi | 0302b06 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 224 | push %rcx # cx is code segment selector from caller |
Patrick Rudolph | d023909 | 2021-06-11 21:24:10 +0200 | [diff] [blame] | 225 | movabs $setCodeSelectorLongJump, %rax |
Patrick Georgi | 0302b06 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 226 | push %rax |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 227 | |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 228 | # the iret will continue at next instruction, with the new cs value |
| 229 | # loaded |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 230 | iretq |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 231 | |
| 232 | setCodeSelectorLongJump: |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 233 | # restore rsp, it might not have been 16-byte aligned on entry |
Patrick Georgi | 0302b06 | 2016-01-22 12:26:52 +0100 | [diff] [blame] | 234 | mov %rdx, %rsp |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 235 | ret |
Stefan Reinauer | 9693885 | 2015-06-18 01:23:48 -0700 | [diff] [blame] | 236 | #endif |