Changeset 0356274 in mainline
- Timestamp:
- 2006-07-17T23:07:09Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f476e76
- Parents:
- 983cd374
- Location:
- kernel/arch/xen32
- Files:
-
- 1 added
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/xen32/Makefile.inc
r983cd374 r0356274 115 115 arch/$(ARCH)/src/atomic.S \ 116 116 arch/$(ARCH)/src/smp/ipi.c \ 117 arch/$(ARCH)/src/ ia32.c \117 arch/$(ARCH)/src/xen32.c \ 118 118 arch/$(ARCH)/src/interrupt.c \ 119 119 arch/$(ARCH)/src/pm.c \ -
kernel/arch/xen32/_link.ld.in
r983cd374 r0356274 3 3 4 4 #define __ASM__ 5 #include <arch/boot/boot.h> 5 6 #include <arch/mm/page.h> 6 7 … … 12 13 } 13 14 14 .image PA2KA( 0): {15 .image PA2KA(BOOT_OFFSET): { 15 16 ktext_start = .; 16 17 *(.text); -
kernel/arch/xen32/include/boot/boot.h
r983cd374 r0356274 36 36 #define __xen32_BOOT_H__ 37 37 38 #define BOOT_STACK_SIZE 0x400 38 #define BOOT_OFFSET 0x0000 39 #define TEMP_STACK_SIZE 0x400 39 40 40 41 #endif -
kernel/arch/xen32/src/boot/boot.S
r983cd374 r0356274 40 40 .byte 0 41 41 42 .section K_TEXT_START, "ax" 43 44 KTEXT=8 45 KDATA=16 42 .text 46 43 47 44 .code32 … … 50 47 51 48 kernel_image_start: 52 lgdt KA2PA(bootstrap_gdtr) # initialize Global Descriptor Table register53 54 movw $KDATA, %cx55 movw %cx, %es56 movw %cx, %fs57 movw %cx, %gs58 movw %cx, %ds # kernel data + stack59 movw %cx, %ss60 61 jmpl $KTEXT, $multiboot_meeting_point62 multiboot_meeting_point:63 64 pushl %ebx # save parameters from GRUB65 pushl %eax66 67 #ifdef CONFIG_FB68 mov $vesa_init, %esi69 mov $VESA_INIT_SEGMENT << 4, %edi70 mov $e_vesa_init - vesa_init, %ecx71 49 cld 72 rep movsb 73 74 mov $VESA_INIT_SEGMENT << 4, %edi 75 jmpl %edi 76 77 vesa_meeting_point: 78 79 mov %esi, KA2PA(vesa_ph_addr) 80 mov %di, KA2PA(vesa_height) 81 shr $16, %edi 82 mov %di, KA2PA(vesa_width) 83 mov %bx, KA2PA(vesa_scanline) 84 shr $16, %ebx 85 mov %bx, KA2PA(vesa_bpp) 86 #endif 87 88 call map_kernel # map kernel and turn paging on 89 90 popl %eax 91 popl %ebx 50 movl $kernel_stack, %esp # initialize stack pointer 92 51 93 52 call main_bsp # never returns … … 96 55 hlt 97 56 98 .global map_kernel 99 map_kernel: 100 # 101 # Here we setup mapping for both the unmapped and mapped sections of the kernel. 102 # For simplicity, we map the entire 4G space. 103 # 104 movl %cr4, %ecx 105 orl $(1<<4), %ecx 106 movl %ecx, %cr4 # turn PSE on 107 108 movl $(page_directory+0), %esi 109 movl $(page_directory+2048), %edi 110 xorl %ecx, %ecx 111 xorl %ebx, %ebx 112 0: 113 movl $((1<<7)|(1<<0)), %eax 114 orl %ebx, %eax 115 movl %eax, (%esi,%ecx,4) # mapping 0x00000000+%ecx*4M => 0x00000000+%ecx*4M 116 movl %eax, (%edi,%ecx,4) # mapping 0x80000000+%ecx*4M => 0x00000000+%ecx*4M 117 addl $(4*1024*1024), %ebx 118 119 incl %ecx 120 cmpl $512, %ecx 121 jl 0b 122 123 movl %esi, %cr3 124 125 # turn paging on 126 movl %cr0, %ebx 127 orl $(1<<31), %ebx 128 movl %ebx, %cr0 129 ret 130 131 #ifdef CONFIG_FB 132 vesa_init: 133 jmp $selector(VESA_INIT_DES), $vesa_init_real - vesa_init 134 135 .code16 136 vesa_init_real: 137 138 mov %cr0, %eax 139 and $~1, %eax 140 mov %eax, %cr0 141 142 jmp $VESA_INIT_SEGMENT, $vesa_init_real2 - vesa_init 143 144 vesa_init_real2: 145 146 mov $VESA_INIT_SEGMENT, %bx 147 148 mov %bx, %es 149 mov %bx, %fs 150 mov %bx, %gs 151 mov %bx, %ds 152 mov %bx, %ss 153 154 movl %esp, %eax 155 movl $0x0000fffc, %esp 156 movl $0x0000fffc, %ebp 157 pushl %eax 158 159 #define VESA_INFO_SIZE 1024 160 161 #define VESA_MODE_LIST_PTR_OFFSET 14 162 #define VESA_MODE_WIDTH_OFFSET 18 163 #define VESA_MODE_HEIGHT_OFFSET 20 164 #define VESA_MODE_BPP_OFFSET 25 165 #define VESA_MODE_SCANLINE_OFFSET 16 166 #define VESA_MODE_PHADDR_OFFSET 40 167 168 #define VESA_END_OF_MODES 0xffff 169 170 #define VESA_OK 0x4f 171 172 #define VESA_GET_INFO 0x4f00 173 #define VESA_GET_MODE_INFO 0x4f01 174 #define VESA_SET_MODE 0x4f02 175 176 #define CONFIG_VESA_BPP_a 255 177 178 #if CONFIG_VESA_BPP == 24 179 #undef CONFIG_VESA_BPP_a 180 #define CONFIG_VESA_BPP_a 32 181 #endif 182 183 mov $VESA_GET_INFO, %ax 184 mov $e_vesa_init - vesa_init, %di 185 push %di 186 int $0x10 187 188 pop %di 189 cmp $VESA_OK, %al 190 jnz 0f 191 192 mov 2 + VESA_MODE_LIST_PTR_OFFSET(%di), %si 193 mov %si, %gs 194 mov VESA_MODE_LIST_PTR_OFFSET(%di), %si 195 196 add $VESA_INFO_SIZE, %di 197 198 1:# Try next mode 199 mov %gs:(%si), %cx 200 cmp $VESA_END_OF_MODES, %cx 201 jz 0f 202 203 inc %si 204 inc %si 205 push %cx 206 push %di 207 push %si 208 mov $VESA_GET_MODE_INFO, %ax 209 int $0x10 210 211 pop %si 212 pop %di 213 pop %cx 214 cmp $VESA_OK, %al 215 jnz 0f 216 217 mov $CONFIG_VESA_WIDTH, %ax 218 cmp VESA_MODE_WIDTH_OFFSET(%di), %ax 219 jnz 1b 220 221 mov $CONFIG_VESA_HEIGHT,%ax 222 cmp VESA_MODE_HEIGHT_OFFSET(%di), %ax 223 jnz 1b 224 225 mov $CONFIG_VESA_BPP, %al 226 cmp VESA_MODE_BPP_OFFSET(%di), %al 227 jz 2f 228 229 mov $CONFIG_VESA_BPP_a, %al 230 cmp VESA_MODE_BPP_OFFSET(%di), %al 231 jnz 1b 232 233 2: 234 235 mov %cx, %bx 236 or $0xc000, %bx 237 push %di 238 mov $VESA_SET_MODE, %ax 239 int $0x10 240 241 pop %di 242 cmp $VESA_OK, %al 243 jnz 0f 244 245 mov VESA_MODE_PHADDR_OFFSET(%di), %esi 246 mov VESA_MODE_WIDTH_OFFSET(%di), %ax 247 shl $16, %eax 248 mov VESA_MODE_HEIGHT_OFFSET(%di), %ax 249 mov VESA_MODE_BPP_OFFSET(%di), %bl 250 xor %bh, %bh 251 shl $16, %ebx 252 mov VESA_MODE_SCANLINE_OFFSET(%di), %bx 253 mov %eax, %edi 254 255 8: 256 257 mov %cr0, %eax 258 or $1, %eax 259 mov %eax, %cr0 260 261 jmp 9f 262 9: 263 264 ljmpl $KTEXT, $(vesa_init_protect - vesa_init + VESA_INIT_SEGMENT << 4) 265 266 0:# No prefered mode found 267 mov $0x111, %cx 268 push %di 269 push %cx 270 mov $VESA_GET_MODE_INFO, %ax 271 int $0x10 272 273 pop %cx 274 pop %di 275 cmp $VESA_OK, %al 276 jnz 1f 277 jz 2b # Force relative jump 278 279 1: 280 mov $0x0003, %ax 281 int $0x10 282 mov $0xffffffff, %edi # EGA text mode used, because of problems with VESA 283 xor %ax, %ax 284 jz 8b # Force relative jump 285 286 287 .code32 288 vesa_init_protect: 289 popl %esp 290 291 movw $KDATA, %cx 292 movw %cx, %es 293 movw %cx, %fs 294 movw %cx, %gs 295 movw %cx, %ds # kernel data + stack 296 movw %cx, %ss 297 298 jmpl $KTEXT, $vesa_meeting_point 299 300 .align 4 301 e_vesa_init: 302 #endif 303 304 .section K_DATA_START, "aw", @progbits 57 .data 305 58 306 59 .align 4096 307 60 page_directory: 308 61 .space 4096, 0 62 63 kernel_stack_bottom: 64 .space TEMP_STACK_SIZE 65 kernel_stack: -
kernel/arch/xen32/src/pm.c
-
Property mode
changed from
120000
to100644
r983cd374 r0356274 1 ../../ia32/src/pm.c 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 /** @addtogroup xen32 30 * @{ 31 */ 32 /** @file 33 */ 34 35 #include <arch/pm.h> 36 #include <config.h> 37 #include <arch/types.h> 38 #include <typedefs.h> 39 #include <arch/interrupt.h> 40 #include <arch/asm.h> 41 #include <arch/context.h> 42 #include <panic.h> 43 #include <arch/mm/page.h> 44 #include <mm/slab.h> 45 #include <memstr.h> 46 #include <arch/boot/boot.h> 47 #include <interrupt.h> 48 49 /* 50 * Early xen32 configuration functions and data structures. 51 */ 52 53 /* 54 * We have no use for segmentation so we set up flat mode. In this 55 * mode, we use, for each privilege level, two segments spanning the 56 * whole memory. One is for code and one is for data. 57 * 58 * One is for GS register which holds pointer to the TLS thread 59 * structure in it's base. 60 */ 61 descriptor_t gdt[GDT_ITEMS] = { 62 /* NULL descriptor */ 63 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 64 /* KTEXT descriptor */ 65 { 0xffff, 0, 0, AR_PRESENT | AR_CODE | DPL_KERNEL, 0xf, 0, 0, 1, 1, 0 }, 66 /* KDATA descriptor */ 67 { 0xffff, 0, 0, AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_KERNEL, 0xf, 0, 0, 1, 1, 0 }, 68 /* UTEXT descriptor */ 69 { 0xffff, 0, 0, AR_PRESENT | AR_CODE | DPL_USER, 0xf, 0, 0, 1, 1, 0 }, 70 /* UDATA descriptor */ 71 { 0xffff, 0, 0, AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_USER, 0xf, 0, 0, 1, 1, 0 }, 72 /* TSS descriptor - set up will be completed later */ 73 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 74 /* TLS descriptor */ 75 { 0xffff, 0, 0, AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_USER, 0xf, 0, 0, 1, 1, 0 }, 76 /* VESA Init descriptor */ 77 #ifdef CONFIG_FB 78 { 0xffff, 0, VESA_INIT_SEGMENT>>12, AR_PRESENT | AR_CODE | DPL_KERNEL, 0xf, 0, 0, 0, 0, 0 } 79 #endif 80 }; 81 82 static idescriptor_t idt[IDT_ITEMS]; 83 84 static tss_t tss; 85 86 tss_t *tss_p = NULL; 87 88 /* gdtr is changed by kmp before next CPU is initialized */ 89 ptr_16_32_t bootstrap_gdtr = { .limit = sizeof(gdt), .base = KA2PA((uintptr_t) gdt) }; 90 ptr_16_32_t gdtr = { .limit = sizeof(gdt), .base = (uintptr_t) gdt }; 91 92 void gdt_setbase(descriptor_t *d, uintptr_t base) 93 { 94 d->base_0_15 = base & 0xffff; 95 d->base_16_23 = ((base) >> 16) & 0xff; 96 d->base_24_31 = ((base) >> 24) & 0xff; 97 } 98 99 void gdt_setlimit(descriptor_t *d, uint32_t limit) 100 { 101 d->limit_0_15 = limit & 0xffff; 102 d->limit_16_19 = (limit >> 16) & 0xf; 103 } 104 105 void idt_setoffset(idescriptor_t *d, uintptr_t offset) 106 { 107 /* 108 * Offset is a linear address. 109 */ 110 d->offset_0_15 = offset & 0xffff; 111 d->offset_16_31 = offset >> 16; 112 } 113 114 void tss_initialize(tss_t *t) 115 { 116 memsetb((uintptr_t) t, sizeof(struct tss), 0); 117 } 118 119 /* 120 * This function takes care of proper setup of IDT and IDTR. 121 */ 122 void idt_init(void) 123 { 124 idescriptor_t *d; 125 int i; 126 127 for (i = 0; i < IDT_ITEMS; i++) { 128 d = &idt[i]; 129 130 d->unused = 0; 131 d->selector = selector(KTEXT_DES); 132 133 d->access = AR_PRESENT | AR_INTERRUPT; /* masking interrupt */ 134 135 if (i == VECTOR_SYSCALL) { 136 /* 137 * The syscall interrupt gate must be calleable from userland. 138 */ 139 d->access |= DPL_USER; 140 } 141 142 idt_setoffset(d, ((uintptr_t) interrupt_handlers) + i*interrupt_handler_size); 143 exc_register(i, "undef", (iroutine) null_interrupt); 144 } 145 exc_register(13, "gp_fault", (iroutine) gp_fault); 146 exc_register( 7, "nm_fault", (iroutine) nm_fault); 147 exc_register(12, "ss_fault", (iroutine) ss_fault); 148 exc_register(19, "simd_fp", (iroutine) simd_fp_exception); 149 } 150 151 152 /* Clean IOPL(12,13) and NT(14) flags in EFLAGS register */ 153 static void clean_IOPL_NT_flags(void) 154 { 155 __asm__ volatile ( 156 "pushfl\n" 157 "pop %%eax\n" 158 "and $0xffff8fff, %%eax\n" 159 "push %%eax\n" 160 "popfl\n" 161 : : : "eax" 162 ); 163 } 164 165 /* Clean AM(18) flag in CR0 register */ 166 static void clean_AM_flag(void) 167 { 168 __asm__ volatile ( 169 "mov %%cr0, %%eax\n" 170 "and $0xfffbffff, %%eax\n" 171 "mov %%eax, %%cr0\n" 172 : : : "eax" 173 ); 174 } 175 176 void pm_init(void) 177 { 178 descriptor_t *gdt_p = (descriptor_t *) gdtr.base; 179 ptr_16_32_t idtr; 180 181 /* 182 * Update addresses in GDT and IDT to their virtual counterparts. 183 */ 184 idtr.limit = sizeof(idt); 185 idtr.base = (uintptr_t) idt; 186 gdtr_load(&gdtr); 187 idtr_load(&idtr); 188 189 /* 190 * Each CPU has its private GDT and TSS. 191 * All CPUs share one IDT. 192 */ 193 194 if (config.cpu_active == 1) { 195 idt_init(); 196 /* 197 * NOTE: bootstrap CPU has statically allocated TSS, because 198 * the heap hasn't been initialized so far. 199 */ 200 tss_p = &tss; 201 } 202 else { 203 tss_p = (tss_t *) malloc(sizeof(tss_t), FRAME_ATOMIC); 204 if (!tss_p) 205 panic("could not allocate TSS\n"); 206 } 207 208 tss_initialize(tss_p); 209 210 gdt_p[TSS_DES].access = AR_PRESENT | AR_TSS | DPL_KERNEL; 211 gdt_p[TSS_DES].special = 1; 212 gdt_p[TSS_DES].granularity = 0; 213 214 gdt_setbase(&gdt_p[TSS_DES], (uintptr_t) tss_p); 215 gdt_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE - 1); 216 217 /* 218 * As of this moment, the current CPU has its own GDT pointing 219 * to its own TSS. We just need to load the TR register. 220 */ 221 tr_load(selector(TSS_DES)); 222 223 clean_IOPL_NT_flags(); /* Disable I/O on nonprivileged levels and clear NT flag. */ 224 clean_AM_flag(); /* Disable alignment check */ 225 } 226 227 void set_tls_desc(uintptr_t tls) 228 { 229 ptr_16_32_t cpugdtr; 230 descriptor_t *gdt_p; 231 232 gdtr_store(&cpugdtr); 233 gdt_p = (descriptor_t *) cpugdtr.base; 234 gdt_setbase(&gdt_p[TLS_DES], tls); 235 /* Reload gdt register to update GS in CPU */ 236 gdtr_load(&cpugdtr); 237 } 238 239 /** @} 240 */ -
Property mode
changed from
Note:
See TracChangeset
for help on using the changeset viewer.