1 /*
2  * Copyright (c) 2009 Corey Tabaka
3  * Copyright (c) 2014-2018 Intel Corporation
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files
7  * (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 /*
27  * System Selectors
28  */
29 #define NULL_SELECTOR       0x00
30 
31 /********* x86 selectors *********/
32 #define CODE_SELECTOR                   0x08
33 #define DATA_SELECTOR                   0x10
34 #define USER_CODE_32_SELECTOR           0x18
35 #define USER_DATA_32_SELECTOR           0x20
36 
37 /******* x86-64 selectors ********/
38 #define CODE_64_SELECTOR                0x28
39 #define STACK_64_SELECTOR               0x30
40 #define USER_CODE_COMPAT_SELECTOR       0x38
41 #define USER_DATA_COMPAT_SELECTOR       0x40
42 #define USER_CODE_64_SELECTOR           0x48
43 #define USER_DATA_64_SELECTOR           0x50
44 
45 #define TSS_SELECTOR                    0x58
46 
47 /*
48  * Descriptor Types
49  */
50 #define SEG_TYPE_TSS        0x9
51 #define SEG_TYPE_TSS_BUSY   0xb
52 #define SEG_TYPE_TASK_GATE  0x5
53 #define SEG_TYPE_INT_GATE   0xe     // 32 bit
54 #define SEG_TYPE_DATA_RW    0x2
55 #define SEG_TYPE_CODE_RW    0xa
56 
57 #define USER_RPL            0x03
58 
59 #ifndef ASSEMBLY
60 
61 #include <arch/x86.h>
62 #include <sys/types.h>
63 
64 typedef uint16_t seg_sel_t;
65 
66 extern tss_t system_tss[SMP_MAX_CPUS];
67 
68 tss_t *get_tss_base(void);
69 
70 void set_global_desc(seg_sel_t sel,
71                         void *base,
72                         uint32_t limit,
73                         uint8_t present,
74                         uint8_t ring,
75                         uint8_t sys,
76                         uint8_t type,
77                         uint8_t gran,
78                         uint8_t bits);
79 
80 #endif
81