1/* 2 * Copyright (c) 2009 Corey Tabaka 3 * Copyright (c) 2015-2018 Intel Corporation 4 * Copyright (c) 2016 Travis Geiselbrecht 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining 7 * a copy of this software and associated documentation files 8 * (the "Software"), to deal in the Software without restriction, 9 * including without limitation the rights to use, copy, modify, merge, 10 * publish, distribute, sublicense, and/or sell copies of the Software, 11 * and to permit persons to whom the Software is furnished to do so, 12 * subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be 15 * included in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 */ 25#include <asm.h> 26#include <arch/x86/descriptor.h> 27 28#define PHYS(x) ((x) - KERNEL_BASE + MEMBASE) 29 30.data 31 32.align 4096 33/* Keep it page alignment since we need to map this page */ 34DATA(_gdtr_phys) 35 .short _gdt_end - _gdt - 1 36#if ARCH_X86_32 37 .int PHYS(_gdt) 38#elif ARCH_X86_64 39 .quad PHYS(_gdt) 40#endif 41 42.align 8 43DATA(_gdtr) 44 .short _gdt_end - _gdt - 1 45#if ARCH_X86_32 46 .int _gdt 47#elif ARCH_X86_64 48 .quad _gdt 49#endif 50 51.align 8 52DATA(_gdt) 53 .int 0 54 .int 0 55 56.set codesel_32, . - _gdt 57_code_32_gde: 58 .short 0xffff /* limit 15:00 */ 59 .short 0x0000 /* base 15:00 */ 60 .byte 0x00 /* base 23:16 */ 61 .byte 0b10011010 /* P(1) DPL(00) S(1) 1 C(0) R(1) A(0) */ 62 .byte 0b11001111 /* G(1) D(1) 0 0 limit 19:16 */ 63 .byte 0x0 /* base 31:24 */ 64 65.set datasel, . - _gdt 66_data_gde: 67 .short 0xffff /* limit 15:00 */ 68 .short 0x0000 /* base 15:00 */ 69 .byte 0x00 /* base 23:16 */ 70 .byte 0b10010010 /* P(1) DPL(00) S(1) 0 E(0) W(1) A(0) */ 71 .byte 0b11001111 /* G(1) B(1) 0 0 limit 19:16 */ 72 .byte 0x0 /* base 31:24 */ 73 74.set user_codesel_32, . - _gdt 75_user_code_32_gde: 76 .short 0xffff /* limit 15:00 */ 77 .short 0x0000 /* base 15:00 */ 78 .byte 0x00 /* base 23:16 */ 79 .byte 0b11111010 /* P(1) DPL(11) S(1) 1 C(0) R(1) A(0) */ 80 .byte 0b11001111 /* G(1) D(1) 0 0 limit 19:16 */ 81 .byte 0x0 /* base 31:24 */ 82 83 84.set user_datasel, . - _gdt 85_user_data_32_gde: 86 .short 0xffff /* limit 15:00 */ 87 .short 0x0000 /* base 15:00 */ 88 .byte 0x00 /* base 23:16 */ 89 .byte 0b11110010 /* P(1) DPL(11) S(1) 0 E(0) W(1) A(0) */ 90 .byte 0b11001111 /* G(1) B(1) 0 0 limit 19:16 */ 91 .byte 0x0 /* base 31:24 */ 92 93.set codesel_64, . - _gdt 94_code_64_gde: 95 .short 0xffff /* limit 15:00 */ 96 .short 0x0000 /* base 15:00 */ 97 .byte 0x00 /* base 23:16 */ 98 .byte 0b10011010 /* P(1) DPL(00) S(1) 1 C(0) R(1) A(0) */ 99 .byte 0b10101111 /* G(1) D(0) L(1) AVL(0) limit 19:16 */ 100 .byte 0x0 /* base 31:24 */ 101 102.set datasel_64, . - _gdt 103_data_64_gde: 104 .short 0xffff /* limit 15:00 */ 105 .short 0x0000 /* base 15:00 */ 106 .byte 0x00 /* base 23:16 */ 107 .byte 0b10010010 /* P(1) DPL(00) S(1) 1 E(0) W(1) A(0) */ 108 .byte 0b11001111 /* G(1) B(1) 0 AVL(0) limit 19:16 */ 109 .byte 0x0 /* base 31:24 */ 110 111.set user_codesel_compat, . - _gdt 112_user_code_compat_gde: 113 .short 0xffff /* limit 15:00 */ 114 .short 0x0000 /* base 15:00 */ 115 .byte 0x00 /* base 23:16 */ 116 .byte 0b11111010 /* P(1) DPL(11) S(1) 1 C(0) R(1) A(0) */ 117 .byte 0b11001111 /* G(1) D(1) L(0) AVL(0) limit 19:16 */ 118 .byte 0x0 /* base 31:24 */ 119 120.set user_datasel_compat, . - _gdt 121_user_data_compat_gde: 122 .short 0xffff /* limit 15:00 */ 123 .short 0x0000 /* base 15:00 */ 124 .byte 0x00 /* base 23:16 */ 125 .byte 0b11110010 /* P(1) DPL(11) S(1) 0 E(0) W(1) A(0) */ 126 .byte 0b11001111 /* G(1) B(1) 0 0 limit 19:16 */ 127 .byte 0x0 /* base 31:24 */ 128 129.set user_codesel_64, . - _gdt 130_user_code_64_gde: 131 .short 0xffff /* limit 15:00 */ 132 .short 0x0000 /* base 15:00 */ 133 .byte 0x00 /* base 23:16 */ 134 .byte 0b11111010 /* P(1) DPL(11) S(1) 1 C(0) R(1) A(0) */ 135 .byte 0b10101111 /* G(1) D(0) L(1) AVL(0) limit 19:16 */ 136 .byte 0x0 /* base 31:24 */ 137 138.set user_datasel_64, . - _gdt 139_user_data_64_gde: 140 .short 0xffff /* limit 15:00 */ 141 .short 0x0000 /* base 15:00 */ 142 .byte 0x00 /* base 23:16 */ 143 .byte 0b11110010 /* P(1) DPL(11) S(1) 0 E(0) W(1) A(0) */ 144 .byte 0b11001111 /* G(1) B(1) 0 0 limit 19:16 */ 145 .byte 0x0 /* base 31:24 */ 146 147/* TSS descriptor */ 148.set tsssel, . - _gdt 149_tss_gde: 150 .short 0 /* limit 15:00 */ 151 .short 0 /* base 15:00 */ 152 .byte 0 /* base 23:16 */ 153 .byte 0x89 /* P(1) DPL(0) S(0) TYPE(9) */ 154 .byte 0x80 /* G(1) 0 0 AVL(0) limit 19:16 */ 155 .byte 0 /* base 31:24 */ 156 .quad 0x0000000000000000 157 158DATA(_gdt_end) 159 160