Changeset 99d6fd0 in mainline
- Timestamp:
- 2009-03-13T12:57:15Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 421c833
- Parents:
- 0160b1c8
- Location:
- kernel/arch
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/include/asm.h
r0160b1c8 r99d6fd0 343 343 * 344 344 */ 345 static inline void gdtr_load( struct ptr_16_64*gdtr_reg)345 static inline void gdtr_load(ptr_16_64_t *gdtr_reg) 346 346 { 347 347 asm volatile ( … … 356 356 * 357 357 */ 358 static inline void gdtr_store( struct ptr_16_64*gdtr_reg)358 static inline void gdtr_store(ptr_16_64_t *gdtr_reg) 359 359 { 360 360 asm volatile ( … … 369 369 * 370 370 */ 371 static inline void idtr_load( struct ptr_16_64*idtr_reg)371 static inline void idtr_load(ptr_16_64_t *idtr_reg) 372 372 { 373 373 asm volatile ( -
kernel/arch/amd64/include/cpu.h
r0160b1c8 r99d6fd0 36 36 #define KERN_amd64_CPU_H_ 37 37 38 #define RFLAGS_IF 39 #define RFLAGS_DF 40 #define RFLAGS_RF 38 #define RFLAGS_IF (1 << 9) 39 #define RFLAGS_DF (1 << 10) 40 #define RFLAGS_RF (1 << 16) 41 41 42 42 #define EFER_MSR_NUM 0xc0000080 … … 63 63 int model; 64 64 int stepping; 65 struct tss*tss;65 tss_t *tss; 66 66 67 count_t iomapver_copy; 67 count_t iomapver_copy; /** Copy of TASK's I/O Permission bitmap generation count. */ 68 68 } cpu_arch_t; 69 69 70 70 struct star_msr { 71 72 71 }; 73 72 74 73 struct lstar_msr { 75 76 74 }; 77 75 -
kernel/arch/amd64/include/pm.h
r0160b1c8 r99d6fd0 27 27 */ 28 28 29 /** @addtogroup amd64 29 /** @addtogroup amd64 30 30 * @{ 31 31 */ … … 37 37 38 38 #ifndef __ASM__ 39 #include <arch/types.h>40 #include <arch/context.h>39 #include <arch/types.h> 40 #include <arch/context.h> 41 41 #endif 42 42 43 #define IDT_ITEMS 6444 #define GDT_ITEMS 843 #define IDT_ITEMS 64 44 #define GDT_ITEMS 8 45 45 46 46 47 #define NULL_DES 0 48 /* Warning: Do not reorder next 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 /* EndOfWarning */ 55 #define TSS_DES 6 56 57 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 58 56 59 57 #ifdef CONFIG_FB 60 58 61 #define VESA_INIT_DES 8 62 #define VESA_INIT_SEGMENT 0x8000 63 #undef GDT_ITEMS 64 #define GDT_ITEMS 9 59 #define VESA_INIT_DES 8 60 #define VESA_INIT_SEGMENT 0x8000 65 61 66 #endif /*CONFIG_FB*/ 62 #undef GDT_ITEMS 63 #define GDT_ITEMS 9 67 64 65 #endif /* CONFIG_FB */ 68 66 67 #define gdtselector(des) ((des) << 3) 68 #define idtselector(des) ((des) << 4) 69 69 70 #define gdtselector(des) ((des) << 3)71 #define idtselector(des) ((des) << 4)70 #define PL_KERNEL 0 71 #define PL_USER 3 72 72 73 #define PL_KERNEL 0 74 #define PL_USER 3 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) 75 81 76 #define AR_PRESENT (1<<7) 77 #define AR_DATA (2<<3) 78 #define AR_CODE (3<<3) 79 #define AR_WRITABLE (1<<1) 80 #define AR_READABLE (1<<1) 81 #define AR_TSS (0x9) 82 #define AR_INTERRUPT (0xe) 83 #define AR_TRAP (0xf) 82 #define DPL_KERNEL (PL_KERNEL << 5) 83 #define DPL_USER (PL_USER << 5) 84 84 85 #define DPL_KERNEL (PL_KERNEL<<5)86 #define DPL_USER (PL_USER<<5)85 #define TSS_BASIC_SIZE 104 86 #define TSS_IOMAP_SIZE (16 * 1024 + 1) /* 16K for bitmap + 1 terminating byte for convenience */ 87 87 88 #define TSS_BASIC_SIZE 104 89 #define TSS_IOMAP_SIZE (16*1024+1) /* 16K for bitmap + 1 terminating byte for convenience */ 90 91 #define IO_PORTS (64*1024) 88 #define IO_PORTS (64 * 1024) 92 89 93 90 #ifndef __ASM__ 94 91 95 struct descriptor{92 typedef struct { 96 93 unsigned limit_0_15: 16; 97 94 unsigned base_0_15: 16; … … 104 101 unsigned granularity : 1; 105 102 unsigned base_24_31: 8; 106 } __attribute__ ((packed)); 107 typedef struct descriptor descriptor_t; 103 } __attribute__ ((packed)) descriptor_t; 108 104 109 struct tss_descriptor{105 typedef struct { 110 106 unsigned limit_0_15: 16; 111 107 unsigned base_0_15: 16; … … 122 118 unsigned base_32_63 : 32; 123 119 unsigned : 32; 124 } __attribute__ ((packed)); 125 typedef struct tss_descriptor tss_descriptor_t; 120 } __attribute__ ((packed)) tss_descriptor_t; 126 121 127 struct idescriptor{122 typedef struct { 128 123 unsigned offset_0_15: 16; 129 124 unsigned selector: 16; … … 136 131 unsigned offset_32_63: 32; 137 132 unsigned : 32; 138 } __attribute__ ((packed)); 139 typedef struct idescriptor idescriptor_t; 133 } __attribute__ ((packed)) idescriptor_t; 140 134 141 struct ptr_16_64{135 typedef struct { 142 136 uint16_t limit; 143 137 uint64_t base; 144 } __attribute__ ((packed)); 145 typedef struct ptr_16_64 ptr_16_64_t; 138 } __attribute__ ((packed)) ptr_16_64_t; 146 139 147 struct ptr_16_32{140 typedef struct { 148 141 uint16_t limit; 149 142 uint32_t base; 150 } __attribute__ ((packed)); 151 typedef struct ptr_16_32 ptr_16_32_t; 143 } __attribute__ ((packed)) ptr_16_32_t; 152 144 153 struct tss{145 typedef struct { 154 146 uint32_t reserve1; 155 147 uint64_t rsp0; … … 168 160 uint16_t iomap_base; 169 161 uint8_t iomap[TSS_IOMAP_SIZE]; 170 } __attribute__ ((packed)); 171 typedef struct tss tss_t; 162 } __attribute__ ((packed)) tss_t; 172 163 173 164 extern tss_t *tss_p; -
kernel/arch/amd64/src/ddi/ddi.c
r0160b1c8 r99d6fd0 58 58 { 59 59 count_t bits; 60 60 61 61 bits = ioaddr + size; 62 62 if (bits > IO_PORTS) 63 63 return ENOENT; 64 64 65 65 if (task->arch.iomap.bits < bits) { 66 66 bitmap_t oldiomap; 67 67 uint8_t *newmap; 68 68 69 69 /* 70 70 * The I/O permission bitmap is too small and needs to be grown. … … 78 78 task->arch.iomap.bits); 79 79 bitmap_initialize(&task->arch.iomap, newmap, bits); 80 80 81 81 /* 82 82 * Mark the new range inaccessible. … … 84 84 bitmap_set_range(&task->arch.iomap, oldiomap.bits, 85 85 bits - oldiomap.bits); 86 86 87 87 /* 88 88 * In case there really existed smaller iomap, 89 89 * copy its contents and deallocate it. 90 */ 90 */ 91 91 if (oldiomap.bits) { 92 92 bitmap_copy(&task->arch.iomap, &oldiomap, … … 95 95 } 96 96 } 97 97 98 98 /* 99 99 * Enable the range and we are done. 100 100 */ 101 101 bitmap_clear_range(&task->arch.iomap, (index_t) ioaddr, (count_t) size); 102 102 103 103 /* 104 104 * Increment I/O Permission bitmap generation counter. 105 105 */ 106 106 task->arch.iomapver++; 107 107 108 108 return 0; 109 109 } … … 123 123 tss_descriptor_t *tss_desc; 124 124 count_t ver; 125 125 126 126 /* First, copy the I/O Permission Bitmap. */ 127 127 spinlock_lock(&TASK->lock); … … 141 141 } 142 142 spinlock_unlock(&TASK->lock); 143 143 144 144 /* 145 145 * Second, adjust TSS segment limit. … … 152 152 153 153 /* 154 155 156 157 tss_desc = (tss_descriptor_t *) 154 * Before we load new TSS limit, the current TSS descriptor 155 * type must be changed to describe inactive TSS. 156 */ 157 tss_desc = (tss_descriptor_t *) &gdt_p[TSS_DES]; 158 158 tss_desc->type = AR_TSS; 159 159 tr_load(gdtselector(TSS_DES)); -
kernel/arch/amd64/src/pm.c
r0160b1c8 r99d6fd0 138 138 void gdt_tss_setlimit(descriptor_t *d, uint32_t limit) 139 139 { 140 struct tss_descriptor*td = (tss_descriptor_t *) d;141 140 tss_descriptor_t *td = (tss_descriptor_t *) d; 141 142 142 td->limit_0_15 = limit & 0xffff; 143 143 td->limit_16_19 = (limit >> 16) & 0xf; … … 186 186 void pm_init(void) 187 187 { 188 descriptor_t *gdt_p = ( struct descriptor*) gdtr.base;188 descriptor_t *gdt_p = (descriptor_t *) gdtr.base; 189 189 tss_descriptor_t *tss_desc; 190 190 191 191 /* 192 192 * Each CPU has its private GDT and TSS. 193 193 * All CPUs share one IDT. 194 194 */ 195 195 196 196 if (config.cpu_active == 1) { 197 197 idt_init(); … … 201 201 */ 202 202 tss_p = &tss; 203 } 204 else { 203 } else { 205 204 /* We are going to use malloc, which may return 206 205 * non boot-mapped pointer, initialize the CR3 register 207 206 * ahead of page_init */ 208 207 write_cr3((uintptr_t) AS_KERNEL->genarch.page_table); 209 210 tss_p = ( struct tss*) malloc(sizeof(tss_t), FRAME_ATOMIC);208 209 tss_p = (tss_t *) malloc(sizeof(tss_t), FRAME_ATOMIC); 211 210 if (!tss_p) 212 211 panic("Cannot allocate TSS."); 213 212 } 214 213 215 214 tss_initialize(tss_p); 216 215 217 216 tss_desc = (tss_descriptor_t *) (&gdt_p[TSS_DES]); 218 217 tss_desc->present = 1; … … 222 221 gdt_tss_setbase(&gdt_p[TSS_DES], (uintptr_t) tss_p); 223 222 gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE - 1); 224 223 225 224 gdtr_load(&gdtr); 226 225 idtr_load(&idtr); -
kernel/arch/ia32/include/cpu.h
r0160b1c8 r99d6fd0 56 56 unsigned int model; 57 57 unsigned int stepping; 58 struct tss*tss;58 tss_t *tss; 59 59 60 60 count_t iomapver_copy; /** Copy of TASK's I/O Permission bitmap generation count. */ -
kernel/arch/ia32/include/pm.h
r0160b1c8 r99d6fd0 27 27 */ 28 28 29 /** @addtogroup ia32 29 /** @addtogroup ia32 30 30 * @{ 31 31 */ … … 36 36 #define KERN_ia32_PM_H_ 37 37 38 #define IDT_ITEMS 6439 #define GDT_ITEMS 38 #define IDT_ITEMS 64 39 #define GDT_ITEMS 7 40 40 41 #define VESA_INIT_SEGMENT 0x8000 42 43 #define NULL_DES 0 44 #define KTEXT_DES 1 45 #define KDATA_DES 2 46 #define UTEXT_DES 3 47 #define UDATA_DES 4 48 #define TSS_DES 5 49 #define TLS_DES 6 /* Pointer to Thread-Local-Storage data */ 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 TSS_DES 5 47 #define TLS_DES 6 /* Pointer to Thread-Local-Storage data */ 50 48 51 49 #ifdef CONFIG_FB 52 50 53 #define VESA_INIT_SEGMENT 0x8000 54 #define VESA_INIT_DES 7 51 #define VESA_INIT_SEGMENT 0x8000 52 #define VESA_INIT_DES 7 53 #define KTEXT32_DES KTEXT_DES 54 55 55 #undef GDT_ITEMS 56 #define GDT_ITEMS 856 #define GDT_ITEMS 8 57 57 58 58 #endif /* CONFIG_FB */ 59 59 60 #define gdtselector(des) ((des) << 3) 60 61 61 #define gdtselector(des) ((des) << 3) 62 #define PL_KERNEL 0 63 #define PL_USER 3 62 64 63 #define PL_KERNEL 0 64 #define PL_USER 3 65 #define AR_PRESENT (1 << 7) 66 #define AR_DATA (2 << 3) 67 #define AR_CODE (3 << 3) 68 #define AR_WRITABLE (1 << 1) 69 #define AR_INTERRUPT (0x0e) 70 #define AR_TSS (0x09) 65 71 66 #define AR_PRESENT (1 << 7) 67 #define AR_DATA (2 << 3) 68 #define AR_CODE (3 << 3) 69 #define AR_WRITABLE (1 << 1) 70 #define AR_INTERRUPT (0xe) 71 #define AR_TSS (0x9) 72 #define DPL_KERNEL (PL_KERNEL << 5) 73 #define DPL_USER (PL_USER << 5) 72 74 73 #define DPL_KERNEL (PL_KERNEL << 5)74 #define DPL_USER (PL_USER << 5)75 #define TSS_BASIC_SIZE 104 76 #define TSS_IOMAP_SIZE (16 * 1024 + 1) /* 16K for bitmap + 1 terminating byte for convenience */ 75 77 76 #define TSS_BASIC_SIZE 104 77 #define TSS_IOMAP_SIZE (16 * 1024 + 1) /* 16K for bitmap + 1 terminating byte for convenience */ 78 79 #define IO_PORTS (64 * 1024) 78 #define IO_PORTS (64 * 1024) 80 79 81 80 #ifndef __ASM__ … … 84 83 #include <arch/context.h> 85 84 86 struct ptr_16_32{85 typedef struct { 87 86 uint16_t limit; 88 87 uint32_t base; 89 } __attribute__ ((packed)); 90 typedef struct ptr_16_32 ptr_16_32_t; 88 } __attribute__ ((packed)) ptr_16_32_t; 91 89 92 struct descriptor{90 typedef struct { 93 91 unsigned limit_0_15: 16; 94 92 unsigned base_0_15: 16; … … 101 99 unsigned granularity : 1; 102 100 unsigned base_24_31: 8; 103 } __attribute__ ((packed)); 104 typedef struct descriptor descriptor_t; 101 } __attribute__ ((packed)) descriptor_t; 105 102 106 struct idescriptor{103 typedef struct { 107 104 unsigned offset_0_15: 16; 108 105 unsigned selector: 16; … … 110 107 unsigned access: 8; 111 108 unsigned offset_16_31: 16; 112 } __attribute__ ((packed)); 113 typedef struct idescriptor idescriptor_t; 109 } __attribute__ ((packed)) idescriptor_t; 114 110 115 struct tss{111 typedef struct { 116 112 uint16_t link; 117 113 unsigned : 16; … … 153 149 uint16_t iomap_base; 154 150 uint8_t iomap[TSS_IOMAP_SIZE]; 155 } __attribute__ ((packed)); 156 typedef struct tss tss_t; 151 } __attribute__ ((packed)) tss_t; 157 152 158 153 extern ptr_16_32_t gdtr; 159 154 extern ptr_16_32_t bootstrap_gdtr; 160 155 extern ptr_16_32_t protected_ap_gdtr; 161 extern struct tss*tss_p;156 extern tss_t *tss_p; 162 157 163 158 extern descriptor_t gdt[]; -
kernel/arch/ia32/src/pm.c
r0160b1c8 r99d6fd0 113 113 void tss_initialize(tss_t *t) 114 114 { 115 memsetb(t, sizeof( struct tss), 0);115 memsetb(t, sizeof(tss_t), 0); 116 116 } 117 117 -
kernel/arch/ia32/src/proc/scheduler.c
r0160b1c8 r99d6fd0 60 60 uintptr_t kstk = (uintptr_t) &THREAD->kstack[THREAD_STACK_SIZE - 61 61 SP_DELTA]; 62 62 63 63 /* Set kernel stack for CP3 -> CPL0 switch via SYSENTER */ 64 64 write_msr(IA32_MSR_SYSENTER_ESP, kstk); 65 65 66 66 /* Set kernel stack for CPL3 -> CPL0 switch via interrupt */ 67 67 CPU->arch.tss->esp0 = kstk; 68 68 CPU->arch.tss->ss0 = gdtselector(KDATA_DES); 69 69 70 70 /* Set up TLS in GS register */ 71 71 set_tls_desc(THREAD->arch.tls); -
kernel/arch/ia32/src/smp/smp.c
r0160b1c8 r99d6fd0 27 27 */ 28 28 29 /** @addtogroup ia32 29 /** @addtogroup ia32 30 30 * @{ 31 31 */ … … 132 132 133 133 for (i = 0; i < ops->cpu_count(); i++) { 134 struct descriptor*gdt_new;135 134 descriptor_t *gdt_new; 135 136 136 /* 137 137 * Skip processors marked unusable. … … 160 160 * the memory subsystem 161 161 */ 162 gdt_new = ( struct descriptor*) malloc(GDT_ITEMS *163 sizeof( struct descriptor), FRAME_ATOMIC);162 gdt_new = (descriptor_t *) malloc(GDT_ITEMS * 163 sizeof(descriptor_t), FRAME_ATOMIC); 164 164 if (!gdt_new) 165 165 panic("Cannot allocate memory for GDT."); 166 166 167 memcpy(gdt_new, gdt, GDT_ITEMS * sizeof( struct descriptor));168 memsetb(&gdt_new[TSS_DES], sizeof( struct descriptor), 0);169 protected_ap_gdtr.limit = GDT_ITEMS * sizeof( struct descriptor);167 memcpy(gdt_new, gdt, GDT_ITEMS * sizeof(descriptor_t)); 168 memsetb(&gdt_new[TSS_DES], sizeof(descriptor_t), 0); 169 protected_ap_gdtr.limit = GDT_ITEMS * sizeof(descriptor_t); 170 170 protected_ap_gdtr.base = KA2PA((uintptr_t) gdt_new); 171 171 gdtr.base = (uintptr_t) gdt_new;
Note:
See TracChangeset
for help on using the changeset viewer.