Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 2 | |
Hannah Williams | d3c0c0c | 2018-04-27 09:09:04 -0700 | [diff] [blame] | 3 | .code32 |
Kyösti Mälkki | 7522a8f | 2020-11-20 16:47:38 +0200 | [diff] [blame] | 4 | |
| 5 | .section .init, "ax", @progbits |
| 6 | |
| 7 | .section .init._gdt_, "ax", @progbits |
Hannah Williams | d3c0c0c | 2018-04-27 09:09:04 -0700 | [diff] [blame] | 8 | |
| 9 | .globl gdt_init |
| 10 | gdt_init: |
| 11 | lgdt %cs:gdtptr |
| 12 | ret |
| 13 | |
| 14 | .previous |
| 15 | .align 4 |
| 16 | .globl gdtptr |
Hannah Williams | d3c0c0c | 2018-04-27 09:09:04 -0700 | [diff] [blame] | 17 | gdtptr: |
| 18 | .word gdt_end - gdt -1 /* compute the table limit */ |
| 19 | .long gdt /* we know the offset */ |
Patrick Rudolph | 4e8dee5 | 2019-03-03 17:58:54 +0100 | [diff] [blame] | 20 | |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 21 | #if ENV_X86_64 |
Patrick Rudolph | 8daa12f | 2018-12-26 15:12:32 +0100 | [diff] [blame] | 22 | .code64 |
Kyösti Mälkki | 7522a8f | 2020-11-20 16:47:38 +0200 | [diff] [blame] | 23 | .section .init._gdt64_, "ax", @progbits |
Patrick Rudolph | 8daa12f | 2018-12-26 15:12:32 +0100 | [diff] [blame] | 24 | .globl gdt_init64 |
| 25 | gdt_init64: |
Patrick Rudolph | 29ed4f5 | 2020-07-05 08:46:55 +0200 | [diff] [blame] | 26 | movabs $gdtptr64, %rax |
| 27 | lgdt (%rax) |
Patrick Rudolph | 8daa12f | 2018-12-26 15:12:32 +0100 | [diff] [blame] | 28 | ret |
| 29 | |
| 30 | .previous |
| 31 | .align 4 |
| 32 | .globl gdtptr64 |
| 33 | gdtptr64: |
| 34 | .word gdt_end - gdt -1 /* compute the table limit */ |
| 35 | .quad gdt /* we know the offset */ |
| 36 | #endif |
| 37 | |
Patrick Rudolph | 4e8dee5 | 2019-03-03 17:58:54 +0100 | [diff] [blame] | 38 | .align 4 |
| 39 | gdt: |
| 40 | /* selgdt 0, unused */ |
| 41 | .word 0x0000, 0x0000 /* dummy */ |
| 42 | .byte 0x00, 0x00, 0x00, 0x00 |
Hannah Williams | d3c0c0c | 2018-04-27 09:09:04 -0700 | [diff] [blame] | 43 | |
| 44 | /* selgdt 0x08, flat code segment */ |
| 45 | .word 0xffff, 0x0000 |
| 46 | .byte 0x00, 0x9b, 0xcf, 0x00 /* G=1 and 0x0f, So we get 4Gbytes |
| 47 | for limit */ |
| 48 | |
| 49 | /* selgdt 0x10,flat data segment */ |
| 50 | .word 0xffff, 0x0000 |
| 51 | .byte 0x00, 0x93, 0xcf, 0x00 |
| 52 | |
| 53 | /* selgdt 0x18, flat code segment (64-bit) */ |
| 54 | .word 0xffff, 0x0000 |
| 55 | .byte 0x00, 0x9b, 0xaf, 0x00 |
| 56 | |
| 57 | gdt_end: |