ia64/xen-unstable
changeset 1739:84c0e1e3773f
bitkeeper revision 1.1062.2.1 (40f14d93VNnMM_iUKi37Qk5Dj84vwA)
More x86-64 fixes. We now boot to C code.
More x86-64 fixes. We now boot to C code.
author | kaf24@scramble.cl.cam.ac.uk |
---|---|
date | Sun Jul 11 14:24:19 2004 +0000 (2004-07-11) |
parents | cafda17c0350 |
children | a503a822a023 |
files | xen/arch/x86/boot/x86_64.S xen/include/asm-x86/msr.h xen/include/xen/multiboot.h |
line diff
1.1 --- a/xen/arch/x86/boot/x86_64.S Sat Jul 10 14:55:46 2004 +0000 1.2 +++ b/xen/arch/x86/boot/x86_64.S Sun Jul 11 14:24:19 2004 +0000 1.3 @@ -1,10 +1,11 @@ 1.4 #include <xen/config.h> 1.5 #include <hypervisor-ifs/hypervisor-if.h> 1.6 #include <asm/page.h> 1.7 +#include <asm/msr.h> 1.8 1.9 #define SECONDARY_CPU_FLAG 0xA5A5A5A5 1.10 1.11 - .text 1.12 + .text 1.13 .code32 1.14 1.15 ENTRY(start) 1.16 @@ -13,11 +14,11 @@ ENTRY(start) 1.17 .org 0x004 1.18 /*** MULTIBOOT HEADER ****/ 1.19 /* Magic number indicating a Multiboot header. */ 1.20 - .long 0x1BADB002 1.21 - /* Flags to bootloader (see Multiboot spec). */ 1.22 - .long 0x00000002 1.23 - /* Checksum: must be the negated sum of the first two fields. */ 1.24 - .long -0x1BADB004 1.25 + .long 0x1BADB002 1.26 + /* Flags to bootloader (see Multiboot spec). */ 1.27 + .long 0x00000002 1.28 + /* Checksum: must be the negated sum of the first two fields. */ 1.29 + .long -0x1BADB004 1.30 1.31 .org 0x010 1.32 .asciz "Bad CPU: does not support 64-bit (long) mode." 1.33 @@ -66,38 +67,30 @@ 3: in %dx,%al 1.34 mov $0x20,%ecx # X86_CR4_PAE 1.35 mov %ecx,%cr4 1.36 1.37 - cmp $(SECONDARY_CPU_FLAG),%ebx 1.38 - je start_paging 1.39 - 1.40 mov %ebx,0x1001e0 /* Multiboot info struct */ 1.41 mov %eax,0x1001e4 /* Multiboot magic value */ 1.42 1.43 - /* Initialize mappings of 1GB of memory. */ 1.44 - mov $0x103000,%edi /* idle_pg_table_l2 */ 1.45 - mov $0x1e3,%eax /* PRESENT+RW+A+D+PSE+GLOBAL */ 1.46 - mov $512,%ecx 1.47 -1: stosl 1.48 - add $0x200000,%eax 1.49 - loop 1b 1.50 - 1.51 -start_paging: 1.52 + /* Load pagetable base register. */ 1.53 mov $0x101000,%eax /* idle_pg_table */ 1.54 mov %eax,%cr3 1.55 + 1.56 + /* Set up EFER (Extended Feature Enable Register). */ 1.57 + movl $MSR_EFER, %ecx 1.58 + rdmsr 1.59 + /* Long Mode, SYSCALL/SYSRET, No-Execute */ 1.60 + movl $(EFER_LME|EFER_SCE|EFER_NX),%eax 1.61 + wrmsr 1.62 + 1.63 mov $0x80050033,%eax /* hi-to-lo: PG,AM,WP,NE,ET,MP,PE */ 1.64 mov %eax,%cr0 1.65 jmp 1f 1.66 -1: /* Now in compatibility mode. Long-jump into 64-bit mode. */ 1.67 - ljmp $(__HYPERVISOR_CS64),$0x1000e0 1.68 - 1.69 - .code64 1.70 - .org 0x00e0 1.71 1.72 - /* Jump to high mappings. */ 1.73 - mov high_start(%rip),%rax 1.74 - push %rax 1.75 - ret 1.76 -__high_start: 1.77 +1: /* Now in compatibility mode. Long-jump into 64-bit mode. */ 1.78 + ljmp $(__HYPERVISOR_CS64),$0x100100 1.79 1.80 + .code64 1.81 + .org 0x0100 1.82 + 1.83 /* Install relocated selectors (FS/GS unused). */ 1.84 lgdt gdt_descr(%rip) 1.85 mov $(__HYPERVISOR_DS),%ecx 1.86 @@ -112,9 +105,15 @@ 1: /* Now in compatibility mode. Lo 1.87 mov stack_start(%rip),%rsp 1.88 1.89 /* Reset EFLAGS (subsumes CLI and CLD). */ 1.90 - pushq $0 1.91 - popf 1.92 + pushq $0 1.93 + popf 1.94 1.95 + /* Jump to high mappings. */ 1.96 + mov high_start(%rip),%rax 1.97 + push %rax 1.98 + ret 1.99 +__high_start: 1.100 + 1.101 lidt idt_descr(%rip) 1.102 1.103 cmp $(SECONDARY_CPU_FLAG),%ebx 1.104 @@ -139,19 +138,15 @@ 1: mov %eax,(%rdi) 1.105 add $8,%rdi 1.106 loop 1b 1.107 1.108 - xor %rax,%rax 1.109 mov 0x1001e0,%eax /* Multiboot info struct */ 1.110 lea start(%rip),%rbx 1.111 sub $0x100000,%rbx 1.112 add %rbx,%rax 1.113 push %rax 1.114 - xor %rax,%rax 1.115 mov 0x1001e4,%eax /* Multiboot magic value */ 1.116 push %rax 1.117 1.118 - /* Call into main C routine. This should never return.*/ 1.119 - call cmain 1.120 - ud2 /* Force a panic (invalid opcode). */ 1.121 + call cmain 1.122 1.123 /* This is the default interrupt handler. */ 1.124 int_msg: 1.125 @@ -167,7 +162,9 @@ ignore_int: 1.126 1: jmp 1b 1.127 1.128 .code32 1.129 - 1.130 + 1.131 + .org 0x1e0 1.132 + 1.133 /*** DESCRIPTOR TABLES ***/ 1.134 1.135 .globl SYMBOL_NAME(idt) 1.136 @@ -192,35 +189,51 @@ ENTRY(gdt_table) 1.137 1.138 .word 0 1.139 gdt_descr: 1.140 - .word (LAST_RESERVED_GDT_ENTRY*8)+7 1.141 + .word (LAST_RESERVED_GDT_ENTRY*8)+7 1.142 SYMBOL_NAME(gdt): 1.143 .quad SYMBOL_NAME(gdt_table) 1.144 1.145 .word 0 1.146 idt_descr: 1.147 - .word 256*8-1 1.148 + .word 256*8-1 1.149 SYMBOL_NAME(idt): 1.150 - .quad SYMBOL_NAME(idt_table) 1.151 + .quad SYMBOL_NAME(idt_table) 1.152 1.153 ENTRY(stack_start) 1.154 - .quad SYMBOL_NAME(cpu0_stack) + 8100 - __PAGE_OFFSET 1.155 + .quad SYMBOL_NAME(cpu0_stack) + 8100 1.156 1.157 high_start: 1.158 .quad __high_start 1.159 1.160 +/* Initial PML4 -- level-4 page table */ 1.161 .org 0x1000 1.162 ENTRY(idle_pg_table) 1.163 ENTRY(idle_pg_table_4) 1.164 .quad 0x0000000000102007 # PML4[0] 1.165 .fill 261,8,0 1.166 .quad 0x0000000000102007 # PML4[262] 1.167 + 1.168 +/* Initial PDP -- level-3 page table */ 1.169 .org 0x2000 1.170 ENTRY(idle_pg_table_l3) 1.171 .quad 0x0000000000103007 1.172 + 1.173 +/* Initial PDE -- level-2 page table. */ 1.174 .org 0x3000 1.175 ENTRY(idle_pg_table_l2) 1.176 + .macro identmap from=0, count=512 1.177 + .if \count-1 1.178 + identmap "(\from+0)","(\count/2)" 1.179 + identmap "(\from+(0x200000*(\count/2)))","(\count/2)" 1.180 + .else 1.181 + .quad 0x00000000000001e3 + \from 1.182 + .endif 1.183 + .endm 1.184 + identmap /* Too orangey for crows :-) */ 1.185 + 1.186 .org 0x4000 1.187 ENTRY(cpu0_stack) # Initial stack is 8kB 1.188 + 1.189 .org 0x6000 1.190 ENTRY(stext) 1.191 ENTRY(_stext)
2.1 --- a/xen/include/asm-x86/msr.h Sat Jul 10 14:55:46 2004 +0000 2.2 +++ b/xen/include/asm-x86/msr.h Sun Jul 11 14:24:19 2004 +0000 2.3 @@ -71,8 +71,8 @@ 2.4 #define _EFER_NX 11 /* No execute enable */ 2.5 2.6 #define EFER_SCE (1<<_EFER_SCE) 2.7 -#define EFER_LME (1<<EFER_LME) 2.8 -#define EFER_LMA (1<<EFER_LMA) 2.9 +#define EFER_LME (1<<_EFER_LME) 2.10 +#define EFER_LMA (1<<_EFER_LMA) 2.11 #define EFER_NX (1<<_EFER_NX) 2.12 2.13 /* Intel MSRs. Some also available on other CPUs */
3.1 --- a/xen/include/xen/multiboot.h Sat Jul 10 14:55:46 2004 +0000 3.2 +++ b/xen/include/xen/multiboot.h Sun Jul 11 14:24:19 2004 +0000 3.3 @@ -18,69 +18,59 @@ 3.4 #ifndef __MULTIBOOT_H__ 3.5 #define __MULTIBOOT_H__ 3.6 3.7 -#ifndef __ELF__ 3.8 -#error "Build on a 32-bit ELF system" 3.9 -#endif 3.10 - 3.11 /* The magic number passed by a Multiboot-compliant boot loader. */ 3.12 -#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 3.13 +#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 3.14 3.15 /* The symbol table for a.out. */ 3.16 -typedef struct 3.17 -{ 3.18 - unsigned long tabsize; 3.19 - unsigned long strsize; 3.20 - unsigned long addr; 3.21 - unsigned long reserved; 3.22 +typedef struct { 3.23 + u32 tabsize; 3.24 + u32 strsize; 3.25 + u32 addr; 3.26 + u32 reserved; 3.27 } aout_symbol_table_t; 3.28 3.29 /* The section header table for ELF. */ 3.30 -typedef struct 3.31 -{ 3.32 - unsigned long num; 3.33 - unsigned long size; 3.34 - unsigned long addr; 3.35 - unsigned long shndx; 3.36 +typedef struct { 3.37 + u32 num; 3.38 + u32 size; 3.39 + u32 addr; 3.40 + u32 shndx; 3.41 } elf_section_header_table_t; 3.42 3.43 /* The Multiboot information. */ 3.44 -typedef struct 3.45 -{ 3.46 - unsigned long flags; 3.47 - unsigned long mem_lower; 3.48 - unsigned long mem_upper; 3.49 - unsigned long boot_device; 3.50 - unsigned long cmdline; 3.51 - unsigned long mods_count; 3.52 - unsigned long mods_addr; 3.53 - union 3.54 - { 3.55 - aout_symbol_table_t aout_sym; 3.56 - elf_section_header_table_t elf_sec; 3.57 - } u; 3.58 - unsigned long mmap_length; 3.59 - unsigned long mmap_addr; 3.60 +typedef struct { 3.61 + u32 flags; 3.62 + u32 mem_lower; 3.63 + u32 mem_upper; 3.64 + u32 boot_device; 3.65 + u32 cmdline; 3.66 + u32 mods_count; 3.67 + u32 mods_addr; 3.68 + union { 3.69 + aout_symbol_table_t aout_sym; 3.70 + elf_section_header_table_t elf_sec; 3.71 + } u; 3.72 + u32 mmap_length; 3.73 + u32 mmap_addr; 3.74 } multiboot_info_t; 3.75 3.76 /* The module structure. */ 3.77 -typedef struct 3.78 -{ 3.79 - unsigned long mod_start; 3.80 - unsigned long mod_end; 3.81 - unsigned long string; 3.82 - unsigned long reserved; 3.83 +typedef struct { 3.84 + u32 mod_start; 3.85 + u32 mod_end; 3.86 + u32 string; 3.87 + u32 reserved; 3.88 } module_t; 3.89 3.90 /* The memory map. Be careful that the offset 0 is base_addr_low 3.91 but no size. */ 3.92 -typedef struct 3.93 -{ 3.94 - unsigned long size; 3.95 - unsigned long base_addr_low; 3.96 - unsigned long base_addr_high; 3.97 - unsigned long length_low; 3.98 - unsigned long length_high; 3.99 - unsigned long type; 3.100 +typedef struct { 3.101 + u32 size; 3.102 + u32 base_addr_low; 3.103 + u32 base_addr_high; 3.104 + u32 length_low; 3.105 + u32 length_high; 3.106 + u32 type; 3.107 } memory_map_t; 3.108 3.109 #endif /* __MULTIBOOT_H__ */