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