source: mainline/arch/amd64/include/pm.h@ 379d73f3

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 379d73f3 was 8fc0d455, checked in by Ondrej Palkovsky <ondrap@…>, 20 years ago

Code cleanup.

  • Property mode set to 100644
File size: 3.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#ifndef __amd64_PM_H__
30#define __amd64_PM_H__
31
32#ifndef __ASM__
33# include <arch/types.h>
34# include <typedefs.h>
35# include <arch/context.h>
36#endif
37
38#define IDT_ITEMS 64
39#define GDT_ITEMS 7
40
41#define NULL_DES 0
42#define KTEXT_DES 1
43#define KDATA_DES 2
44#define UTEXT_DES 3
45#define UDATA_DES 4
46#define KTEXT32_DES 5
47#define TSS_DES 6
48
49#define selector(des) ((des)<<3)
50
51#define PL_KERNEL 0
52#define PL_USER 3
53
54#define AR_PRESENT (1<<7)
55#define AR_DATA (2<<3)
56#define AR_CODE (3<<3)
57#define AR_WRITABLE (1<<1)
58#define AR_READABLE (1<<1)
59#define AR_INTERRUPT (0xe)
60#define AR_TSS (0x9)
61
62#define DPL_KERNEL (PL_KERNEL<<5)
63#define DPL_USER (PL_USER<<5)
64
65#define IO_MAP_BASE (104)
66
67#ifndef __ASM__
68
69struct ptr_16_32 {
70 __u16 limit;
71 __u32 base;
72} __attribute__ ((packed));
73
74struct descriptor {
75 unsigned limit_0_15: 16;
76 unsigned base_0_15: 16;
77 unsigned base_16_23: 8;
78 unsigned access: 8;
79 unsigned limit_16_19: 4;
80 unsigned available: 1;
81 unsigned longmode: 1;
82 unsigned special: 1;
83 unsigned granularity : 1;
84 unsigned base_24_31: 8;
85} __attribute__ ((packed));
86
87struct idescriptor {
88 unsigned offset_0_15: 16;
89 unsigned selector: 16;
90 unsigned unused: 8;
91 unsigned access: 8;
92 unsigned offset_16_31: 16;
93} __attribute__ ((packed));
94
95
96struct tss {
97 __u16 link;
98 unsigned : 16;
99 __u32 esp0;
100 __u16 ss0;
101 unsigned : 16;
102 __u32 esp1;
103 __u16 ss1;
104 unsigned : 16;
105 __u32 esp2;
106 __u16 ss2;
107 unsigned : 16;
108 __u32 cr3;
109 __u32 eip;
110 __u32 eflags;
111 __u32 eax;
112 __u32 ecx;
113 __u32 edx;
114 __u32 ebx;
115 __u32 esp;
116 __u32 ebp;
117 __u32 esi;
118 __u32 edi;
119 __u16 es;
120 unsigned : 16;
121 __u16 cs;
122 unsigned : 16;
123 __u16 ss;
124 unsigned : 16;
125 __u16 ds;
126 unsigned : 16;
127 __u16 fs;
128 unsigned : 16;
129 __u16 gs;
130 unsigned : 16;
131 __u16 ldtr;
132 unsigned : 16;
133 unsigned : 16;
134 __u16 io_map_base;
135} __attribute__ ((packed));
136
137extern struct ptr_16_32 gdtr;
138extern struct tss *tss_p;
139
140extern struct descriptor gdt[];
141extern struct idescriptor idt[];
142
143extern void pm_init(void);
144
145extern void gdt_setbase(struct descriptor *d, __address base);
146extern void gdt_setlimit(struct descriptor *d, __u32 limit);
147
148extern void idt_init(void);
149extern void idt_setoffset(struct idescriptor *d, __address offset);
150
151extern void tss_initialize(struct tss *t);
152
153#endif /* __ASM__ */
154
155#endif
Note: See TracBrowser for help on using the repository browser.