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 __PM_H__ 00036 #define __PM_H__ 00037 00038 #define IDT_ITEMS 64 00039 #define GDT_ITEMS 7 00040 00041 #define VESA_INIT_SEGMENT 0x8000 00042 00043 #define NULL_DES 0 00044 #define KTEXT_DES 1 00045 #define KDATA_DES 2 00046 #define UTEXT_DES 3 00047 #define UDATA_DES 4 00048 #define TSS_DES 5 00049 #define TLS_DES 6 /* Pointer to Thread-Local-Storage data */ 00050 00051 #ifdef CONFIG_FB 00052 00053 #define VESA_INIT_SEGMENT 0x8000 00054 #define VESA_INIT_DES 7 00055 #undef GDT_ITEMS 00056 #define GDT_ITEMS 8 00057 00058 #endif /* CONFIG_FB */ 00059 00060 00061 #define selector(des) ((des)<<3) 00062 00063 #define PL_KERNEL 0 00064 #define PL_USER 3 00065 00066 #define AR_PRESENT (1<<7) 00067 #define AR_DATA (2<<3) 00068 #define AR_CODE (3<<3) 00069 #define AR_WRITABLE (1<<1) 00070 #define AR_INTERRUPT (0xe) 00071 #define AR_TSS (0x9) 00072 00073 #define DPL_KERNEL (PL_KERNEL<<5) 00074 #define DPL_USER (PL_USER<<5) 00075 00076 #define TSS_BASIC_SIZE 104 00077 #define TSS_IOMAP_SIZE (16*1024+1) /* 16K for bitmap + 1 terminating byte for convenience */ 00078 00079 #define IO_PORTS (64*1024) 00080 00081 #ifndef __ASM__ 00082 00083 #include <arch/types.h> 00084 #include <typedefs.h> 00085 #include <arch/context.h> 00086 00087 struct ptr_16_32 { 00088 __u16 limit; 00089 __u32 base; 00090 } __attribute__ ((packed)); 00091 typedef struct ptr_16_32 ptr_16_32_t; 00092 00093 struct descriptor { 00094 unsigned limit_0_15: 16; 00095 unsigned base_0_15: 16; 00096 unsigned base_16_23: 8; 00097 unsigned access: 8; 00098 unsigned limit_16_19: 4; 00099 unsigned available: 1; 00100 unsigned unused: 1; 00101 unsigned special: 1; 00102 unsigned granularity : 1; 00103 unsigned base_24_31: 8; 00104 } __attribute__ ((packed)); 00105 typedef struct descriptor descriptor_t; 00106 00107 struct idescriptor { 00108 unsigned offset_0_15: 16; 00109 unsigned selector: 16; 00110 unsigned unused: 8; 00111 unsigned access: 8; 00112 unsigned offset_16_31: 16; 00113 } __attribute__ ((packed)); 00114 typedef struct idescriptor idescriptor_t; 00115 00116 struct tss { 00117 __u16 link; 00118 unsigned : 16; 00119 __u32 esp0; 00120 __u16 ss0; 00121 unsigned : 16; 00122 __u32 esp1; 00123 __u16 ss1; 00124 unsigned : 16; 00125 __u32 esp2; 00126 __u16 ss2; 00127 unsigned : 16; 00128 __u32 cr3; 00129 __u32 eip; 00130 __u32 eflags; 00131 __u32 eax; 00132 __u32 ecx; 00133 __u32 edx; 00134 __u32 ebx; 00135 __u32 esp; 00136 __u32 ebp; 00137 __u32 esi; 00138 __u32 edi; 00139 __u16 es; 00140 unsigned : 16; 00141 __u16 cs; 00142 unsigned : 16; 00143 __u16 ss; 00144 unsigned : 16; 00145 __u16 ds; 00146 unsigned : 16; 00147 __u16 fs; 00148 unsigned : 16; 00149 __u16 gs; 00150 unsigned : 16; 00151 __u16 ldtr; 00152 unsigned : 16; 00153 unsigned : 16; 00154 __u16 iomap_base; 00155 __u8 iomap[TSS_IOMAP_SIZE]; 00156 } __attribute__ ((packed)); 00157 typedef struct tss tss_t; 00158 00159 extern ptr_16_32_t gdtr; 00160 extern ptr_16_32_t bootstrap_gdtr; 00161 extern ptr_16_32_t protected_ap_gdtr; 00162 extern struct tss *tss_p; 00163 00164 extern descriptor_t gdt[]; 00165 00166 extern void pm_init(void); 00167 00168 extern void gdt_setbase(descriptor_t *d, __address base); 00169 extern void gdt_setlimit(descriptor_t *d, __u32 limit); 00170 00171 extern void idt_init(void); 00172 extern void idt_setoffset(idescriptor_t *d, __address offset); 00173 00174 extern void tss_initialize(tss_t *t); 00175 extern void set_tls_desc(__address tls); 00176 00177 #endif /* __ASM__ */ 00178 00179 #endif 00180