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