source: mainline/kernel/arch/amd64/include/pm.h@ 86018c1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 86018c1 was 99d6fd0, checked in by Martin Decky <martin@…>, 16 years ago

cleanup pm.h and related stuff (no change in functionality)

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Copyright (c) 2001-2004 Jakub Jermar
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
29/** @addtogroup amd64
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_amd64_PM_H_
36#define KERN_amd64_PM_H_
37
38#ifndef __ASM__
39 #include <arch/types.h>
40 #include <arch/context.h>
41#endif
42
43#define IDT_ITEMS 64
44#define GDT_ITEMS 8
45
46
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
56
57#ifdef CONFIG_FB
58
59#define VESA_INIT_DES 8
60#define VESA_INIT_SEGMENT 0x8000
61
62#undef GDT_ITEMS
63#define GDT_ITEMS 9
64
65#endif /* CONFIG_FB */
66
67#define gdtselector(des) ((des) << 3)
68#define idtselector(des) ((des) << 4)
69
70#define PL_KERNEL 0
71#define PL_USER 3
72
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)
81
82#define DPL_KERNEL (PL_KERNEL << 5)
83#define DPL_USER (PL_USER << 5)
84
85#define TSS_BASIC_SIZE 104
86#define TSS_IOMAP_SIZE (16 * 1024 + 1) /* 16K for bitmap + 1 terminating byte for convenience */
87
88#define IO_PORTS (64 * 1024)
89
90#ifndef __ASM__
91
92typedef struct {
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;
103} __attribute__ ((packed)) descriptor_t;
104
105typedef struct {
106 unsigned limit_0_15: 16;
107 unsigned base_0_15: 16;
108 unsigned base_16_23: 8;
109 unsigned type: 4;
110 unsigned : 1;
111 unsigned dpl : 2;
112 unsigned present : 1;
113 unsigned limit_16_19: 4;
114 unsigned available: 1;
115 unsigned : 2;
116 unsigned granularity : 1;
117 unsigned base_24_31: 8;
118 unsigned base_32_63 : 32;
119 unsigned : 32;
120} __attribute__ ((packed)) tss_descriptor_t;
121
122typedef struct {
123 unsigned offset_0_15: 16;
124 unsigned selector: 16;
125 unsigned ist:3;
126 unsigned unused: 5;
127 unsigned type: 5;
128 unsigned dpl: 2;
129 unsigned present : 1;
130 unsigned offset_16_31: 16;
131 unsigned offset_32_63: 32;
132 unsigned : 32;
133} __attribute__ ((packed)) idescriptor_t;
134
135typedef struct {
136 uint16_t limit;
137 uint64_t base;
138} __attribute__ ((packed)) ptr_16_64_t;
139
140typedef struct {
141 uint16_t limit;
142 uint32_t base;
143} __attribute__ ((packed)) ptr_16_32_t;
144
145typedef struct {
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];
162} __attribute__ ((packed)) tss_t;
163
164extern tss_t *tss_p;
165
166extern descriptor_t gdt[];
167extern idescriptor_t idt[];
168
169extern ptr_16_64_t gdtr;
170extern ptr_16_32_t bootstrap_gdtr;
171extern ptr_16_32_t protected_ap_gdtr;
172
173extern void pm_init(void);
174
175extern void gdt_tss_setbase(descriptor_t *d, uintptr_t base);
176extern void gdt_tss_setlimit(descriptor_t *d, uint32_t limit);
177
178extern void idt_init(void);
179extern void idt_setoffset(idescriptor_t *d, uintptr_t offset);
180
181extern void tss_initialize(tss_t *t);
182
183#endif /* __ASM__ */
184
185#endif
186
187/** @}
188 */
Note: See TracBrowser for help on using the repository browser.