pm.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2004 Jakub Jermar
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef __amd64_PM_H__
00036 #define __amd64_PM_H__
00037 
00038 #ifndef __ASM__
00039 # include <arch/types.h>
00040 # include <typedefs.h>
00041 # include <arch/context.h>
00042 #endif
00043 
00044 #define IDT_ITEMS 64
00045 #define GDT_ITEMS 8
00046 
00047 
00048 #define NULL_DES        0
00049 /* Warning: Do not reorder next items, unless you look into syscall.c!!! */
00050 #define KTEXT_DES       1
00051 #define KDATA_DES       2
00052 #define UDATA_DES       3
00053 #define UTEXT_DES       4
00054 #define KTEXT32_DES     5
00055 /* EndOfWarning */
00056 #define TSS_DES         6
00057 
00058 
00059 
00060 #ifdef CONFIG_FB
00061 
00062 #define VESA_INIT_DES           8
00063 #define VESA_INIT_SEGMENT 0x8000
00064 #undef GDT_ITEMS 
00065 #define GDT_ITEMS 9
00066 
00067 #endif /*CONFIG_FB*/
00068 
00069 
00070 
00071 #define gdtselector(des)        ((des)<<3)
00072 #define idtselector(des)        ((des)<<4)
00073 
00074 #define PL_KERNEL       0
00075 #define PL_USER         3
00076 
00077 #define AR_PRESENT      (1<<7)
00078 #define AR_DATA         (2<<3)
00079 #define AR_CODE         (3<<3)
00080 #define AR_WRITABLE     (1<<1)
00081 #define AR_READABLE     (1<<1)
00082 #define AR_TSS          (0x9)
00083 #define AR_INTERRUPT    (0xe)
00084 #define AR_TRAP         (0xf)
00085 
00086 #define DPL_KERNEL      (PL_KERNEL<<5)
00087 #define DPL_USER        (PL_USER<<5)
00088 
00089 #define TSS_BASIC_SIZE  104
00090 #define TSS_IOMAP_SIZE  (16*1024+1)     /* 16K for bitmap + 1 terminating byte for convenience */
00091 
00092 #define IO_PORTS        (64*1024)
00093 
00094 #ifndef __ASM__
00095 
00096 struct descriptor {
00097         unsigned limit_0_15: 16;
00098         unsigned base_0_15: 16;
00099         unsigned base_16_23: 8;
00100         unsigned access: 8;
00101         unsigned limit_16_19: 4;
00102         unsigned available: 1;
00103         unsigned longmode: 1;
00104         unsigned special: 1;
00105         unsigned granularity : 1;
00106         unsigned base_24_31: 8;
00107 } __attribute__ ((packed));
00108 typedef struct descriptor descriptor_t;
00109 
00110 struct tss_descriptor {
00111         unsigned limit_0_15: 16;
00112         unsigned base_0_15: 16;
00113         unsigned base_16_23: 8;
00114         unsigned type: 4;
00115         unsigned : 1;
00116         unsigned dpl : 2;
00117         unsigned present : 1;
00118         unsigned limit_16_19: 4;
00119         unsigned available: 1;
00120         unsigned : 2;
00121         unsigned granularity : 1;
00122         unsigned base_24_31: 8; 
00123         unsigned base_32_63 : 32;
00124         unsigned  : 32;
00125 } __attribute__ ((packed));
00126 typedef struct tss_descriptor tss_descriptor_t;
00127 
00128 struct idescriptor {
00129         unsigned offset_0_15: 16;
00130         unsigned selector: 16;
00131         unsigned ist:3;
00132         unsigned unused: 5;
00133         unsigned type: 5;
00134         unsigned dpl: 2;
00135         unsigned present : 1;
00136         unsigned offset_16_31: 16;
00137         unsigned offset_32_63: 32;
00138         unsigned  : 32;
00139 } __attribute__ ((packed));
00140 typedef struct idescriptor idescriptor_t;
00141 
00142 struct ptr_16_64 {
00143         __u16 limit;
00144         __u64 base;
00145 } __attribute__ ((packed));
00146 typedef struct ptr_16_64 ptr_16_64_t;
00147 
00148 struct ptr_16_32 {
00149         __u16 limit;
00150         __u32 base;
00151 } __attribute__ ((packed));
00152 typedef struct ptr_16_32 ptr_16_32_t;
00153 
00154 struct tss {
00155         __u32 reserve1;
00156         __u64 rsp0;
00157         __u64 rsp1;
00158         __u64 rsp2;
00159         __u64 reserve2;
00160         __u64 ist1;
00161         __u64 ist2;
00162         __u64 ist3;
00163         __u64 ist4;
00164         __u64 ist5;
00165         __u64 ist6;
00166         __u64 ist7;
00167         __u64 reserve3;
00168         __u16 reserve4;
00169         __u16 iomap_base;
00170         __u8 iomap[TSS_IOMAP_SIZE];
00171 } __attribute__ ((packed));
00172 typedef struct tss tss_t;
00173 
00174 extern tss_t *tss_p;
00175 
00176 extern descriptor_t gdt[];
00177 extern idescriptor_t idt[];
00178 
00179 extern ptr_16_64_t gdtr;
00180 extern ptr_16_32_t bootstrap_gdtr;
00181 extern ptr_16_32_t protected_ap_gdtr;
00182 
00183 extern void pm_init(void);
00184 
00185 extern void gdt_tss_setbase(descriptor_t *d, __address base);
00186 extern void gdt_tss_setlimit(descriptor_t *d, __u32 limit);
00187 
00188 extern void idt_init(void);
00189 extern void idt_setoffset(idescriptor_t *d, __address offset);
00190 
00191 extern void tss_initialize(tss_t *t);
00192 
00193 #endif /* __ASM__ */
00194 
00195 #endif
00196 

Generated on Sun Jun 18 16:26:57 2006 for HelenOS Kernel (amd64) by  doxygen 1.4.6