18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Written 2000 by Andi Kleen */ 38c2ecf20Sopenharmony_ci#ifndef _ASM_X86_DESC_DEFS_H 48c2ecf20Sopenharmony_ci#define _ASM_X86_DESC_DEFS_H 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci/* 78c2ecf20Sopenharmony_ci * Segment descriptor structure definitions, usable from both x86_64 and i386 88c2ecf20Sopenharmony_ci * archs. 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/types.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* 8 byte segment descriptor */ 168c2ecf20Sopenharmony_cistruct desc_struct { 178c2ecf20Sopenharmony_ci u16 limit0; 188c2ecf20Sopenharmony_ci u16 base0; 198c2ecf20Sopenharmony_ci u16 base1: 8, type: 4, s: 1, dpl: 2, p: 1; 208c2ecf20Sopenharmony_ci u16 limit1: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8; 218c2ecf20Sopenharmony_ci} __attribute__((packed)); 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define GDT_ENTRY_INIT(flags, base, limit) \ 248c2ecf20Sopenharmony_ci { \ 258c2ecf20Sopenharmony_ci .limit0 = (u16) (limit), \ 268c2ecf20Sopenharmony_ci .limit1 = ((limit) >> 16) & 0x0F, \ 278c2ecf20Sopenharmony_ci .base0 = (u16) (base), \ 288c2ecf20Sopenharmony_ci .base1 = ((base) >> 16) & 0xFF, \ 298c2ecf20Sopenharmony_ci .base2 = ((base) >> 24) & 0xFF, \ 308c2ecf20Sopenharmony_ci .type = (flags & 0x0f), \ 318c2ecf20Sopenharmony_ci .s = (flags >> 4) & 0x01, \ 328c2ecf20Sopenharmony_ci .dpl = (flags >> 5) & 0x03, \ 338c2ecf20Sopenharmony_ci .p = (flags >> 7) & 0x01, \ 348c2ecf20Sopenharmony_ci .avl = (flags >> 12) & 0x01, \ 358c2ecf20Sopenharmony_ci .l = (flags >> 13) & 0x01, \ 368c2ecf20Sopenharmony_ci .d = (flags >> 14) & 0x01, \ 378c2ecf20Sopenharmony_ci .g = (flags >> 15) & 0x01, \ 388c2ecf20Sopenharmony_ci } 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cienum { 418c2ecf20Sopenharmony_ci GATE_INTERRUPT = 0xE, 428c2ecf20Sopenharmony_ci GATE_TRAP = 0xF, 438c2ecf20Sopenharmony_ci GATE_CALL = 0xC, 448c2ecf20Sopenharmony_ci GATE_TASK = 0x5, 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cienum { 488c2ecf20Sopenharmony_ci DESC_TSS = 0x9, 498c2ecf20Sopenharmony_ci DESC_LDT = 0x2, 508c2ecf20Sopenharmony_ci DESCTYPE_S = 0x10, /* !system */ 518c2ecf20Sopenharmony_ci}; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/* LDT or TSS descriptor in the GDT. */ 548c2ecf20Sopenharmony_cistruct ldttss_desc { 558c2ecf20Sopenharmony_ci u16 limit0; 568c2ecf20Sopenharmony_ci u16 base0; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci u16 base1 : 8, type : 5, dpl : 2, p : 1; 598c2ecf20Sopenharmony_ci u16 limit1 : 4, zero0 : 3, g : 1, base2 : 8; 608c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_64 618c2ecf20Sopenharmony_ci u32 base3; 628c2ecf20Sopenharmony_ci u32 zero1; 638c2ecf20Sopenharmony_ci#endif 648c2ecf20Sopenharmony_ci} __attribute__((packed)); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_citypedef struct ldttss_desc ldt_desc; 678c2ecf20Sopenharmony_citypedef struct ldttss_desc tss_desc; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistruct idt_bits { 708c2ecf20Sopenharmony_ci u16 ist : 3, 718c2ecf20Sopenharmony_ci zero : 5, 728c2ecf20Sopenharmony_ci type : 5, 738c2ecf20Sopenharmony_ci dpl : 2, 748c2ecf20Sopenharmony_ci p : 1; 758c2ecf20Sopenharmony_ci} __attribute__((packed)); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistruct idt_data { 788c2ecf20Sopenharmony_ci unsigned int vector; 798c2ecf20Sopenharmony_ci unsigned int segment; 808c2ecf20Sopenharmony_ci struct idt_bits bits; 818c2ecf20Sopenharmony_ci const void *addr; 828c2ecf20Sopenharmony_ci}; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistruct gate_struct { 858c2ecf20Sopenharmony_ci u16 offset_low; 868c2ecf20Sopenharmony_ci u16 segment; 878c2ecf20Sopenharmony_ci struct idt_bits bits; 888c2ecf20Sopenharmony_ci u16 offset_middle; 898c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_64 908c2ecf20Sopenharmony_ci u32 offset_high; 918c2ecf20Sopenharmony_ci u32 reserved; 928c2ecf20Sopenharmony_ci#endif 938c2ecf20Sopenharmony_ci} __attribute__((packed)); 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_citypedef struct gate_struct gate_desc; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic inline unsigned long gate_offset(const gate_desc *g) 988c2ecf20Sopenharmony_ci{ 998c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_64 1008c2ecf20Sopenharmony_ci return g->offset_low | ((unsigned long)g->offset_middle << 16) | 1018c2ecf20Sopenharmony_ci ((unsigned long) g->offset_high << 32); 1028c2ecf20Sopenharmony_ci#else 1038c2ecf20Sopenharmony_ci return g->offset_low | ((unsigned long)g->offset_middle << 16); 1048c2ecf20Sopenharmony_ci#endif 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic inline unsigned long gate_segment(const gate_desc *g) 1088c2ecf20Sopenharmony_ci{ 1098c2ecf20Sopenharmony_ci return g->segment; 1108c2ecf20Sopenharmony_ci} 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_cistruct desc_ptr { 1138c2ecf20Sopenharmony_ci unsigned short size; 1148c2ecf20Sopenharmony_ci unsigned long address; 1158c2ecf20Sopenharmony_ci} __attribute__((packed)) ; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */ 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci/* Boot IDT definitions */ 1208c2ecf20Sopenharmony_ci#define BOOT_IDT_ENTRIES 32 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/* Access rights as returned by LAR */ 1238c2ecf20Sopenharmony_ci#define AR_TYPE_RODATA (0 * (1 << 9)) 1248c2ecf20Sopenharmony_ci#define AR_TYPE_RWDATA (1 * (1 << 9)) 1258c2ecf20Sopenharmony_ci#define AR_TYPE_RODATA_EXPDOWN (2 * (1 << 9)) 1268c2ecf20Sopenharmony_ci#define AR_TYPE_RWDATA_EXPDOWN (3 * (1 << 9)) 1278c2ecf20Sopenharmony_ci#define AR_TYPE_XOCODE (4 * (1 << 9)) 1288c2ecf20Sopenharmony_ci#define AR_TYPE_XRCODE (5 * (1 << 9)) 1298c2ecf20Sopenharmony_ci#define AR_TYPE_XOCODE_CONF (6 * (1 << 9)) 1308c2ecf20Sopenharmony_ci#define AR_TYPE_XRCODE_CONF (7 * (1 << 9)) 1318c2ecf20Sopenharmony_ci#define AR_TYPE_MASK (7 * (1 << 9)) 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#define AR_DPL0 (0 * (1 << 13)) 1348c2ecf20Sopenharmony_ci#define AR_DPL3 (3 * (1 << 13)) 1358c2ecf20Sopenharmony_ci#define AR_DPL_MASK (3 * (1 << 13)) 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci#define AR_A (1 << 8) /* "Accessed" */ 1388c2ecf20Sopenharmony_ci#define AR_S (1 << 12) /* If clear, "System" segment */ 1398c2ecf20Sopenharmony_ci#define AR_P (1 << 15) /* "Present" */ 1408c2ecf20Sopenharmony_ci#define AR_AVL (1 << 20) /* "AVaiLable" (no HW effect) */ 1418c2ecf20Sopenharmony_ci#define AR_L (1 << 21) /* "Long mode" for code segments */ 1428c2ecf20Sopenharmony_ci#define AR_DB (1 << 22) /* D/B, effect depends on type */ 1438c2ecf20Sopenharmony_ci#define AR_G (1 << 23) /* "Granularity" (limit in pages) */ 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci#endif /* _ASM_X86_DESC_DEFS_H */ 146