Subversion Repositories HelenOS

Rev

Rev 4126 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
178 palkovsky 1
/*
2071 jermar 2
 * Copyright (c) 2001-2004 Jakub Jermar
178 palkovsky 3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
4126 decky 29
/** @addtogroup amd64
1702 cejka 30
 * @{
31
 */
32
/** @file
33
 */
34
 
1888 jermar 35
#ifndef KERN_amd64_PM_H_
36
#define KERN_amd64_PM_H_
178 palkovsky 37
 
194 palkovsky 38
#ifndef __ASM__
4126 decky 39
    #include <arch/types.h>
40
    #include <arch/context.h>
194 palkovsky 41
#endif
178 palkovsky 42
 
4126 decky 43
#define IDT_ITEMS  64
44
#define GDT_ITEMS  8
178 palkovsky 45
 
1289 vana 46
 
4126 decky 47
#define NULL_DES     0
48
/* Warning: Do not reorder the following items, unless you look into syscall.c! */
49
#define KTEXT_DES    1
50
#define KDATA_DES    2
51
#define UDATA_DES    3
52
#define UTEXT_DES    4
53
#define KTEXT32_DES  5
54
/* End of warning */
55
#define TSS_DES      6
1292 vana 56
 
57
#ifdef CONFIG_FB
58
 
4126 decky 59
#define VESA_INIT_DES      8
60
#define VESA_INIT_SEGMENT  0x8000
178 palkovsky 61
 
4126 decky 62
#undef GDT_ITEMS
63
#define GDT_ITEMS  9
1292 vana 64
 
4126 decky 65
#endif /* CONFIG_FB */
1292 vana 66
 
4126 decky 67
#define gdtselector(des)  ((des) << 3)
68
#define idtselector(des)  ((des) << 4)
1292 vana 69
 
4126 decky 70
#define PL_KERNEL  0
71
#define PL_USER    3
178 palkovsky 72
 
4126 decky 73
#define AR_PRESENT   ( 1 << 7)
74
#define AR_DATA       (2 << 3)
75
#define AR_CODE       (3 << 3)
76
#define AR_WRITABLE   (1 << 1)
77
#define AR_READABLE   (1 << 1)
78
#define AR_TSS        (0x09)
79
#define AR_INTERRUPT  (0x0e)
80
#define AR_TRAP       (0x0f)
178 palkovsky 81
 
4126 decky 82
#define DPL_KERNEL  (PL_KERNEL << 5)
83
#define DPL_USER    (PL_USER << 5)
178 palkovsky 84
 
4126 decky 85
#define TSS_BASIC_SIZE  104
86
#define TSS_IOMAP_SIZE  (16 * 1024 + 1)  /* 16K for bitmap + 1 terminating byte for convenience */
178 palkovsky 87
 
4126 decky 88
#define IO_PORTS  (64 * 1024)
178 palkovsky 89
 
194 palkovsky 90
#ifndef __ASM__
91
 
4126 decky 92
typedef struct {
178 palkovsky 93
    unsigned limit_0_15: 16;
94
    unsigned base_0_15: 16;
95
    unsigned base_16_23: 8;
96
    unsigned access: 8;
97
    unsigned limit_16_19: 4;
98
    unsigned available: 1;
99
    unsigned longmode: 1;
100
    unsigned special: 1;
101
    unsigned granularity : 1;
102
    unsigned base_24_31: 8;
4126 decky 103
} __attribute__ ((packed)) descriptor_t;
178 palkovsky 104
 
4126 decky 105
typedef struct {
206 palkovsky 106
    unsigned limit_0_15: 16;
107
    unsigned base_0_15: 16;
108
    unsigned base_16_23: 8;
109
    unsigned type: 4;
1187 jermar 110
    unsigned : 1;
206 palkovsky 111
    unsigned dpl : 2;
112
    unsigned present : 1;
113
    unsigned limit_16_19: 4;
114
    unsigned available: 1;
224 palkovsky 115
    unsigned : 2;
206 palkovsky 116
    unsigned granularity : 1;
117
    unsigned base_24_31: 8;
118
    unsigned base_32_63 : 32;
224 palkovsky 119
    unsigned  : 32;
4126 decky 120
} __attribute__ ((packed)) tss_descriptor_t;
206 palkovsky 121
 
4126 decky 122
typedef struct {
178 palkovsky 123
    unsigned offset_0_15: 16;
124
    unsigned selector: 16;
206 palkovsky 125
    unsigned ist:3;
126
    unsigned unused: 5;
127
    unsigned type: 5;
128
    unsigned dpl: 2;
129
    unsigned present : 1;
178 palkovsky 130
    unsigned offset_16_31: 16;
224 palkovsky 131
    unsigned offset_32_63: 32;
132
    unsigned  : 32;
4126 decky 133
} __attribute__ ((packed)) idescriptor_t;
178 palkovsky 134
 
4126 decky 135
typedef struct {
1780 jermar 136
    uint16_t limit;
137
    uint64_t base;
4126 decky 138
} __attribute__ ((packed)) ptr_16_64_t;
178 palkovsky 139
 
4126 decky 140
typedef struct {
1780 jermar 141
    uint16_t limit;
142
    uint32_t base;
4126 decky 143
} __attribute__ ((packed)) ptr_16_32_t;
273 palkovsky 144
 
4126 decky 145
typedef struct {
1780 jermar 146
    uint32_t reserve1;
147
    uint64_t rsp0;
148
    uint64_t rsp1;
149
    uint64_t rsp2;
150
    uint64_t reserve2;
151
    uint64_t ist1;
152
    uint64_t ist2;
153
    uint64_t ist3;
154
    uint64_t ist4;
155
    uint64_t ist5;
156
    uint64_t ist6;
157
    uint64_t ist7;
158
    uint64_t reserve3;
159
    uint16_t reserve4;
160
    uint16_t iomap_base;
161
    uint8_t iomap[TSS_IOMAP_SIZE];
4126 decky 162
} __attribute__ ((packed)) tss_t;
178 palkovsky 163
 
1187 jermar 164
extern tss_t *tss_p;
178 palkovsky 165
 
1187 jermar 166
extern descriptor_t gdt[];
167
extern idescriptor_t idt[];
178 palkovsky 168
 
1187 jermar 169
extern ptr_16_64_t gdtr;
170
extern ptr_16_32_t bootstrap_gdtr;
171
extern ptr_16_32_t protected_ap_gdtr;
206 palkovsky 172
 
178 palkovsky 173
extern void pm_init(void);
174
 
1780 jermar 175
extern void gdt_tss_setbase(descriptor_t *d, uintptr_t base);
176
extern void gdt_tss_setlimit(descriptor_t *d, uint32_t limit);
178 palkovsky 177
 
178
extern void idt_init(void);
1780 jermar 179
extern void idt_setoffset(idescriptor_t *d, uintptr_t offset);
178 palkovsky 180
 
1187 jermar 181
extern void tss_initialize(tss_t *t);
178 palkovsky 182
 
194 palkovsky 183
#endif /* __ASM__ */
184
 
178 palkovsky 185
#endif
1702 cejka 186
 
1888 jermar 187
/** @}
1702 cejka 188
 */