diff options
author | Richard Braun <rbraun@sceen.net> | 2012-10-03 01:23:21 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2012-10-03 01:26:08 +0200 |
commit | a4485f033c4ffa07955a45cad30424aedb89dff4 (patch) | |
tree | 136381bd711a9e6bd54b0c31fb347b35028911d1 | |
parent | 69504fc63720b4bf2677d6074285b82256bc9b83 (diff) |
x86: new architecture
Merge 32-bit IA-32 (i386) and 64-bit AMD64 (amd64) code into one common
architecture. The amd64 variant isn't functional yet.
-rw-r--r-- | INSTALL | 10 | ||||
-rw-r--r-- | Makefrag.am | 2 | ||||
-rw-r--r-- | arch/i386/Makefrag.am | 34 | ||||
-rw-r--r-- | arch/i386/configfrag.ac | 15 | ||||
-rw-r--r-- | arch/x86/Makefrag.am | 43 | ||||
-rw-r--r-- | arch/x86/configfrag.ac | 46 | ||||
-rw-r--r-- | arch/x86/machine/acpimp.c (renamed from arch/i386/machine/acpimp.c) | 0 | ||||
-rw-r--r-- | arch/x86/machine/acpimp.h (renamed from arch/i386/machine/acpimp.h) | 6 | ||||
-rw-r--r-- | arch/x86/machine/asm.h (renamed from arch/i386/machine/asm.h) | 6 | ||||
-rw-r--r-- | arch/x86/machine/biosmem.c (renamed from arch/i386/machine/biosmem.c) | 35 | ||||
-rw-r--r-- | arch/x86/machine/biosmem.h (renamed from arch/i386/machine/biosmem.h) | 6 | ||||
-rw-r--r-- | arch/x86/machine/boot.S (renamed from arch/i386/machine/boot.S) | 19 | ||||
-rw-r--r-- | arch/x86/machine/boot.h (renamed from arch/i386/machine/boot.h) | 30 | ||||
-rw-r--r-- | arch/x86/machine/cpu.c (renamed from arch/i386/machine/cpu.c) | 2 | ||||
-rw-r--r-- | arch/x86/machine/cpu.h (renamed from arch/i386/machine/cpu.h) | 37 | ||||
-rw-r--r-- | arch/x86/machine/cpu_asm.S (renamed from arch/i386/machine/cpu_asm.S) | 4 | ||||
-rw-r--r-- | arch/x86/machine/init.c (renamed from arch/i386/machine/init.c) | 28 | ||||
-rw-r--r-- | arch/x86/machine/init.h (renamed from arch/i386/machine/init.h) | 8 | ||||
-rw-r--r-- | arch/x86/machine/io.h (renamed from arch/i386/machine/io.h) | 6 | ||||
-rw-r--r-- | arch/x86/machine/lapic.c (renamed from arch/i386/machine/lapic.c) | 0 | ||||
-rw-r--r-- | arch/x86/machine/lapic.h (renamed from arch/i386/machine/lapic.h) | 6 | ||||
-rw-r--r-- | arch/x86/machine/mps.c (renamed from arch/i386/machine/mps.c) | 0 | ||||
-rw-r--r-- | arch/x86/machine/mps.h (renamed from arch/i386/machine/mps.h) | 6 | ||||
-rw-r--r-- | arch/x86/machine/multiboot.h (renamed from arch/i386/machine/multiboot.h) | 6 | ||||
-rw-r--r-- | arch/x86/machine/param.h (renamed from arch/i386/machine/param.h) | 6 | ||||
-rw-r--r-- | arch/x86/machine/pit.c (renamed from arch/i386/machine/pit.c) | 0 | ||||
-rw-r--r-- | arch/x86/machine/pit.h (renamed from arch/i386/machine/pit.h) | 6 | ||||
-rw-r--r-- | arch/x86/machine/pmap.c (renamed from arch/i386/machine/pmap.c) | 9 | ||||
-rw-r--r-- | arch/x86/machine/pmap.h (renamed from arch/i386/machine/pmap.h) | 6 | ||||
-rw-r--r-- | arch/x86/machine/trap.h (renamed from arch/i386/machine/trap.h) | 6 | ||||
-rw-r--r-- | arch/x86/machine/types.h (renamed from arch/i386/machine/types.h) | 6 | ||||
-rw-r--r-- | arch/x86/machine/vga.c (renamed from arch/i386/machine/vga.c) | 0 | ||||
-rw-r--r-- | arch/x86/machine/vga.h (renamed from arch/i386/machine/vga.h) | 6 | ||||
-rw-r--r-- | arch/x86/x15.lds.S (renamed from arch/i386/x15.lds.S) | 11 | ||||
-rw-r--r-- | configure.ac | 50 | ||||
-rw-r--r-- | lib/stdint.h | 8 | ||||
-rw-r--r-- | vm/vm_map.c | 2 | ||||
-rw-r--r-- | vm/vm_phys.c | 2 |
38 files changed, 265 insertions, 208 deletions
@@ -240,9 +240,15 @@ X15 Options Disable all debugging facilities. By default, debugging is enabled. -i386 options +x86 options ------------ +`--with-i386' + Build for a 32-bit IA-32 machine. + +`--with-amd64' + Build for a 64-bit AMD64 machine. + `--enable-pae' Use the PAE (Physical Address Extension) processor feature to address - physical memory beyond 4 GiB. + physical memory beyond 4 GiB (i386 only). diff --git a/Makefrag.am b/Makefrag.am index dbda2000..b0c1fed8 100644 --- a/Makefrag.am +++ b/Makefrag.am @@ -1,7 +1,7 @@ # # 'arch/xxx' sources # -include arch/i386/Makefrag.am +include arch/x86/Makefrag.am # # 'kern/' sources diff --git a/arch/i386/Makefrag.am b/arch/i386/Makefrag.am deleted file mode 100644 index 2d87b70d..00000000 --- a/arch/i386/Makefrag.am +++ /dev/null @@ -1,34 +0,0 @@ -if I386 - -# Force 32-bits builds. -AM_CPPFLAGS += -m32 -x15_LDFLAGS += -m32 - -x15_SOURCES += \ - arch/i386/machine/acpimp.c \ - arch/i386/machine/acpimp.h \ - arch/i386/machine/biosmem.c \ - arch/i386/machine/biosmem.h \ - arch/i386/machine/boot.h \ - arch/i386/machine/boot.S \ - arch/i386/machine/cpu.c \ - arch/i386/machine/cpu_asm.S \ - arch/i386/machine/cpu.h \ - arch/i386/machine/endian.h \ - arch/i386/machine/init.c \ - arch/i386/machine/init.h \ - arch/i386/machine/io.h \ - arch/i386/machine/lapic.c \ - arch/i386/machine/lapic.h \ - arch/i386/machine/mps.c \ - arch/i386/machine/mps.h \ - arch/i386/machine/multiboot.h \ - arch/i386/machine/param.h \ - arch/i386/machine/pit.c \ - arch/i386/machine/pit.h \ - arch/i386/machine/pmap.c \ - arch/i386/machine/pmap.h \ - arch/i386/machine/vga.c \ - arch/i386/machine/vga.h - -endif I386 diff --git a/arch/i386/configfrag.ac b/arch/i386/configfrag.ac deleted file mode 100644 index 770c625e..00000000 --- a/arch/i386/configfrag.ac +++ /dev/null @@ -1,15 +0,0 @@ -# SYSTYPE -systype=i386 - -# -# Arguments to configure -# -AC_ARG_ENABLE([pae], - [AS_HELP_STRING([--enable-pae], - [enable PAE to address physical memory beyond 4 GiB])]) - -# -# Options -# -AS_IF([test x"$enable_pae" = xyes], - [AC_DEFINE([PAE], [1], [use PAE page tables])]) diff --git a/arch/x86/Makefrag.am b/arch/x86/Makefrag.am new file mode 100644 index 00000000..7a905e54 --- /dev/null +++ b/arch/x86/Makefrag.am @@ -0,0 +1,43 @@ +if X86 + +x15_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 + +if I386 +AM_CPPFLAGS += -m32 +x15_LDFLAGS += -m32 +endif I386 + +if AMD64 +AM_CPPFLAGS += -m64 +AM_CFLAGS += -mcmodel=kernel -mno-red-zone +x15_LDFLAGS += -m64 +endif AMD64 + +x15_SOURCES += \ + arch/x86/machine/acpimp.c \ + arch/x86/machine/acpimp.h \ + arch/x86/machine/biosmem.c \ + arch/x86/machine/biosmem.h \ + arch/x86/machine/boot.h \ + arch/x86/machine/boot.S \ + arch/x86/machine/cpu.c \ + arch/x86/machine/cpu_asm.S \ + arch/x86/machine/cpu.h \ + arch/x86/machine/endian.h \ + arch/x86/machine/init.c \ + arch/x86/machine/init.h \ + arch/x86/machine/io.h \ + arch/x86/machine/lapic.c \ + arch/x86/machine/lapic.h \ + arch/x86/machine/mps.c \ + arch/x86/machine/mps.h \ + arch/x86/machine/multiboot.h \ + arch/x86/machine/param.h \ + arch/x86/machine/pit.c \ + arch/x86/machine/pit.h \ + arch/x86/machine/pmap.c \ + arch/x86/machine/pmap.h \ + arch/x86/machine/vga.c \ + arch/x86/machine/vga.h + +endif X86 diff --git a/arch/x86/configfrag.ac b/arch/x86/configfrag.ac new file mode 100644 index 00000000..fd4edf1e --- /dev/null +++ b/arch/x86/configfrag.ac @@ -0,0 +1,46 @@ +systype=x86 + +# +# Arguments to configure +# +AC_ARG_WITH([i386], + [AS_HELP_STRING([--with-i386], + [build for a 32-bit IA-32 machine])], + [opt_i386=$withval], + [opt_i386=no]) + +AC_ARG_WITH([amd64], + [AS_HELP_STRING([--with-amd64], + [build for a 64-bit AMD64 machine])], + [opt_amd64=$withval], + [opt_amd64=no]) + +AC_ARG_ENABLE([pae], + [AS_HELP_STRING([--enable-pae], + [enable physical address extension (i386 only)])]) + +# +# Options +# +m4_define([i386_ENABLE_PAE], + [AC_DEFINE([PAE], [1], [use PAE page tables]) + AC_MSG_NOTICE([physical address extension enabled])]) + +m4_define([x86_SELECT_I386], + [AC_MSG_NOTICE([build type: i386]) + AS_IF([test x"$enable_pae" = xyes], [i386_ENABLE_PAE])]) + +m4_define([x86_SELECT_AMD64], + [AC_MSG_NOTICE([build type: amd64]) + AS_IF([test x"$enable_pae" = xyes], + [AC_MSG_WARN([pae option available for i386 only, ignoring])])]) + +AS_IF([test x"$opt_i386$opt_amd64" = xyesyes], + [AC_MSG_ERROR([select only one of i386 or amd64])], + [test x"$opt_i386$opt_amd64" = xnono], + [AS_CASE(["$host_cpu"], + [i?86], [opt_i386=yes], + [x86_64], [opt_amd64=yes])]) + +AS_IF([test x"$opt_i386" = xyes], [x86_SELECT_I386], + [test x"$opt_amd64" = xyes], [x86_SELECT_AMD64]) diff --git a/arch/i386/machine/acpimp.c b/arch/x86/machine/acpimp.c index e2fc6eb3..e2fc6eb3 100644 --- a/arch/i386/machine/acpimp.c +++ b/arch/x86/machine/acpimp.c diff --git a/arch/i386/machine/acpimp.h b/arch/x86/machine/acpimp.h index 55c01c91..e66a87ae 100644 --- a/arch/i386/machine/acpimp.h +++ b/arch/x86/machine/acpimp.h @@ -19,8 +19,8 @@ * specification v1.0. */ -#ifndef _I386_ACPIMP_H -#define _I386_ACPIMP_H +#ifndef _X86_ACPIMP_H +#define _X86_ACPIMP_H /* * Load multiprocessor information. @@ -30,4 +30,4 @@ */ int acpimp_setup(void); -#endif /* _I386_ACPIMP_H */ +#endif /* _X86_ACPIMP_H */ diff --git a/arch/i386/machine/asm.h b/arch/x86/machine/asm.h index 32a859b9..e427b51e 100644 --- a/arch/i386/machine/asm.h +++ b/arch/x86/machine/asm.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_ASM_H -#define _I386_ASM_H +#ifndef _X86_ASM_H +#define _X86_ASM_H #ifdef __ASSEMBLY__ @@ -39,4 +39,4 @@ x: #endif /* __ASSEMBLY__ */ -#endif /* _I386_ASM_H */ +#endif /* _X86_ASM_H */ diff --git a/arch/i386/machine/biosmem.c b/arch/x86/machine/biosmem.c index 9d56e21c..1ae2dbd5 100644 --- a/arch/i386/machine/biosmem.c +++ b/arch/x86/machine/biosmem.c @@ -67,19 +67,19 @@ struct biosmem_map_entry { * based on the mem_lower and mem_upper multiboot fields. */ static struct biosmem_map_entry biosmem_map[BIOSMEM_MAX_MAP_SIZE * 2] - __initdata; + __bootdata; /* * Number of valid entries in the BIOS memory map table. */ -static unsigned int biosmem_map_size __initdata; +static unsigned int biosmem_map_size __bootdata; /* * Boundaries of the simple bootstrap heap. */ -static unsigned long biosmem_heap_start __initdata; -static unsigned long biosmem_heap_free __initdata; -static unsigned long biosmem_heap_end __initdata; +static unsigned long biosmem_heap_start __bootdata; +static unsigned long biosmem_heap_free __bootdata; +static unsigned long biosmem_heap_end __bootdata; static void __boot biosmem_map_build(const struct multiboot_info *mbi) @@ -89,7 +89,7 @@ biosmem_map_build(const struct multiboot_info *mbi) mb_entry = mbi->mmap_addr; mb_end = mbi->mmap_addr + mbi->mmap_length; - start = (struct biosmem_map_entry *)BOOT_ADDR_VTOP(biosmem_map); + start = biosmem_map; entry = start; end = entry + BIOSMEM_MAX_MAP_SIZE; @@ -102,7 +102,7 @@ biosmem_map_build(const struct multiboot_info *mbi) entry++; } - BOOT_VTOP(biosmem_map_size) = entry - start; + biosmem_map_size = entry - start; } static void __boot @@ -110,7 +110,7 @@ biosmem_map_build_simple(const struct multiboot_info *mbi) { struct biosmem_map_entry *entry; - entry = (struct biosmem_map_entry *)BOOT_ADDR_VTOP(biosmem_map); + entry = biosmem_map; entry->base_addr = 0; entry->length = mbi->mem_lower << 10; entry->type = BIOSMEM_TYPE_AVAILABLE; @@ -120,7 +120,7 @@ biosmem_map_build_simple(const struct multiboot_info *mbi) entry->length = mbi->mem_upper << 10; entry->type = BIOSMEM_TYPE_AVAILABLE; - BOOT_VTOP(biosmem_map_size) = 2; + biosmem_map_size = 2; } static void __boot @@ -158,7 +158,7 @@ biosmem_find_boot_data(const struct multiboot_info *mbi, unsigned long min, start = max; biosmem_find_boot_data_update(min, &start, &end, &_boot, - (void *)BOOT_ADDR_VTOP(&_end)); + (void *)BOOT_VTOP(&_end)); if ((mbi->flags & MULTIBOOT_LOADER_CMDLINE) && (mbi->cmdline != NULL)) biosmem_find_boot_data_update(min, &start, &end, mbi->cmdline, @@ -222,9 +222,9 @@ biosmem_setup_allocator(struct multiboot_info *mbi) if (max_heap_start >= max_heap_end) init_panic("unable to find memory for the boot allocator"); - BOOT_VTOP(biosmem_heap_start) = max_heap_start; - BOOT_VTOP(biosmem_heap_free) = max_heap_start; - BOOT_VTOP(biosmem_heap_end) = max_heap_end; + biosmem_heap_start = max_heap_start; + biosmem_heap_free = max_heap_start; + biosmem_heap_end = max_heap_end; } static size_t __boot @@ -281,15 +281,14 @@ biosmem_bootalloc(unsigned int nr_pages) if (nr_pages == 0) init_panic("attempt to allocate 0 pages"); - free = BOOT_VTOP(biosmem_heap_free); + free = biosmem_heap_free; page = free; free += PAGE_SIZE * nr_pages; - if ((free <= BOOT_VTOP(biosmem_heap_start)) - || (free > BOOT_VTOP(biosmem_heap_end))) + if ((free <= biosmem_heap_start) || (free > biosmem_heap_end)) init_panic("unable to allocate memory"); - BOOT_VTOP(biosmem_heap_free) = free; + biosmem_heap_free = free; for (ptr = (char *)page; ptr < (char *)free; ptr++) *ptr = '\0'; @@ -600,7 +599,7 @@ biosmem_find_reserved_area(vm_phys_t min, vm_phys_t max, start = max; biosmem_find_reserved_area_update(min, &start, &end, (unsigned long)&_boot, - BOOT_ADDR_VTOP(&_end)); + BOOT_VTOP(&_end)); biosmem_find_reserved_area_update(min, &start, &end, biosmem_heap_start, biosmem_heap_end); diff --git a/arch/i386/machine/biosmem.h b/arch/x86/machine/biosmem.h index d5a01195..fefe2a77 100644 --- a/arch/i386/machine/biosmem.h +++ b/arch/x86/machine/biosmem.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_BIOSMEM_H -#define _I386_BIOSMEM_H +#ifndef _X86_BIOSMEM_H +#define _X86_BIOSMEM_H #include <machine/multiboot.h> @@ -69,4 +69,4 @@ void biosmem_setup(void); */ void biosmem_free_usable(void); -#endif /* _I386_BIOSMEM_H */ +#endif /* _X86_BIOSMEM_H */ diff --git a/arch/i386/machine/boot.S b/arch/x86/machine/boot.S index eec7c585..ece1bb89 100644 --- a/arch/i386/machine/boot.S +++ b/arch/x86/machine/boot.S @@ -45,6 +45,7 @@ END(boot_header) * Entry point. */ ENTRY(_start) + .code32 /* * Set up a simple GDT to conform to the multiboot specification. */ @@ -63,10 +64,16 @@ ENTRY(_start) ljmp $8, $1f 1: + +/* XXX For now */ +#ifdef __LP64__ + hlt +#endif + /* * Set up the init stack. */ - movl $(init_stack + BOOT_STACK_SIZE - KERNEL_OFFSET), %esp + movl $(init_stack + BOOT_STACK_SIZE), %esp movl %esp, %ebp /* @@ -82,10 +89,13 @@ ENTRY(_start) ljmp $8, $1f 1: +#ifdef __LP64__ + hlt +#else /* __LP64__ */ /* * Reset the stack, use high addresses. */ - movl $(init_stack + BOOT_STACK_SIZE), %esp + movl $(init_stack + BOOT_STACK_SIZE + KERNEL_OFFSET), %esp movl %esp, %ebp /* @@ -93,6 +103,7 @@ ENTRY(_start) */ pushl $0 jmp init +#endif /* __LP64__ */ /* * Never reached. @@ -129,7 +140,7 @@ ENTRY(boot_ap_start32) /* * Set up the init stack. */ - movl $(init_ap_stack + BOOT_STACK_SIZE - KERNEL_OFFSET), %esp + movl $(init_ap_stack + BOOT_STACK_SIZE), %esp movl %esp, %ebp /* @@ -146,7 +157,7 @@ ENTRY(boot_ap_start32) /* * Switch to the boot stack preallocated for this AP by the BSP. */ - movl (init_ap_boot_stack - KERNEL_OFFSET), %esp + movl init_ap_boot_stack_addr, %esp addl $BOOT_STACK_SIZE, %esp movl %esp, %ebp diff --git a/arch/i386/machine/boot.h b/arch/x86/machine/boot.h index 11255509..03e934ce 100644 --- a/arch/i386/machine/boot.h +++ b/arch/x86/machine/boot.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_BOOT_H -#define _I386_BOOT_H +#ifndef _X86_BOOT_H +#define _X86_BOOT_H /* * The kernel is physically loaded at BOOT_OFFSET by the boot loader. It @@ -25,7 +25,12 @@ * See the linker script for more information. */ #define BOOT_OFFSET 0x00100000 + +#ifdef __LP64__ +#define KERNEL_OFFSET 0xffffffff80000000 +#else /* __LP64__ */ #define KERNEL_OFFSET 0xc0000000 +#endif /* __LP64__ */ /* * Size of the stack used to bootstrap the kernel. @@ -45,24 +50,17 @@ #include <lib/macros.h> /* - * Access a variable during bootstrap, while still running at physical - * addresses. - */ -#define BOOT_VTOP(var) \ - (*((typeof(var) *)((unsigned long)(&var) - KERNEL_OFFSET))) - -/* - * Address translation macros. + * Virtual to physical address translation macro. */ -#define BOOT_ADDR_VTOP(addr) ((unsigned long)(addr) - KERNEL_OFFSET) -#define BOOT_ADDR_PTOV(addr) ((unsigned long)(addr) + KERNEL_OFFSET) +#define BOOT_VTOP(addr) ((unsigned long)(addr) - KERNEL_OFFSET) /* - * Functions used before paging is enabled must be part of the .boot section - * so that they run at physical addresses. There is no .bootdata section; the - * BOOT_VTOP() macro should be used instead. + * Functions and data used before paging is enabled must be part of the .boot + * and .bootdata sections respectively, so that they use physical addresses. + * Once paging is enabled, their access relies on the kernel identity mapping. */ #define __boot __section(".boot") +#define __bootdata __section(".bootdata") /* * Boundaries of the .boot section. @@ -82,4 +80,4 @@ void boot_ap_start(void); #endif /* __ASSEMBLY__ */ -#endif /* _I386_BOOT_H */ +#endif /* _X86_BOOT_H */ diff --git a/arch/i386/machine/cpu.c b/arch/x86/machine/cpu.c index 2c7a2cd1..0595f76d 100644 --- a/arch/i386/machine/cpu.c +++ b/arch/x86/machine/cpu.c @@ -390,7 +390,7 @@ cpu_mp_start_aps(void) panic("unable to allocate boot stack for cpu%u", i); init_ap_id = i; - init_ap_boot_stack = cpu->boot_stack; + init_ap_boot_stack_addr = cpu->boot_stack; lapic_ipi_init_assert(cpu->apic_id); cpu_delay(200); diff --git a/arch/i386/machine/cpu.h b/arch/x86/machine/cpu.h index 13d72f41..823b9d28 100644 --- a/arch/i386/machine/cpu.h +++ b/arch/x86/machine/cpu.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_CPU_H -#define _I386_CPU_H +#ifndef _X86_CPU_H +#define _X86_CPU_H /* * GDT entry indexes and size. @@ -207,13 +207,13 @@ cpu_tlb_flush_va(unsigned long va) static __always_inline unsigned long cpu_get_flags(void) { - unsigned long eflags; + unsigned long flags; asm volatile("pushf\n" - "popl %0\n" - : "=r" (eflags)); + "pop %0\n" + : "=r" (flags)); - return eflags; + return flags; } /* @@ -238,11 +238,11 @@ cpu_intr_disable(void) * Restore the content of the EFLAGS register, possibly enabling interrupts. */ static __always_inline void -cpu_intr_restore(unsigned long eflags) +cpu_intr_restore(unsigned long flags) { - asm volatile("pushl %0\n" + asm volatile("push %0\n" "popf\n" - : : "r" (eflags)); + : : "r" (flags)); } /* @@ -252,12 +252,12 @@ cpu_intr_restore(unsigned long eflags) static __always_inline unsigned long cpu_intr_save(void) { - unsigned long eflags; + unsigned long flags; - eflags = cpu_get_flags(); + flags = cpu_get_flags(); cpu_intr_disable(); - return eflags; + return flags; } /* @@ -266,10 +266,10 @@ cpu_intr_save(void) static __always_inline int cpu_intr_enabled(void) { - unsigned long eflags; + unsigned long flags; - eflags = cpu_get_flags(); - return (eflags & CPU_EFL_IF) ? 1 : 0; + flags = cpu_get_flags(); + return (flags & CPU_EFL_IF) ? 1 : 0; } /* @@ -307,9 +307,14 @@ cpu_current(void) { struct cpu *cpu; +#ifdef __LP64__ + cpu = NULL; +#else /* __LP64__ */ asm volatile("movl %%fs:%1, %0" : "=r" (cpu) : "m" (*(struct cpu *)offsetof(struct cpu, self))); +#endif /* __LP64__ */ + return cpu; } @@ -403,4 +408,4 @@ void cpu_trap_lapic_spurious_intr(void); #endif /* __ASSEMBLY__ */ -#endif /* _I386_CPU_H */ +#endif /* _X86_CPU_H */ diff --git a/arch/i386/machine/cpu_asm.S b/arch/x86/machine/cpu_asm.S index 373ca8e2..8bba0dc9 100644 --- a/arch/i386/machine/cpu_asm.S +++ b/arch/x86/machine/cpu_asm.S @@ -23,6 +23,9 @@ .text ENTRY(cpu_load_gdt) +#ifdef __LP64__ + ret +#else /* __LP64__ */ movl 4(%esp), %eax lgdt (%eax) @@ -42,6 +45,7 @@ ENTRY(cpu_load_gdt) pushl $(CPU_GDT_SELECTOR(CPU_GDT_CODE_IDX)) pushl %eax lret +#endif /* __LP64__ */ END(cpu_load_gdt) /* diff --git a/arch/i386/machine/init.c b/arch/x86/machine/init.c index 2ee81035..ac1b3474 100644 --- a/arch/i386/machine/init.c +++ b/arch/x86/machine/init.c @@ -43,15 +43,15 @@ #define INIT_VGACHARS (80 * 25) #define INIT_VGACOLOR 0x7 -char init_stack[BOOT_STACK_SIZE] __initdata; -char init_ap_stack[BOOT_STACK_SIZE] __initdata; -unsigned long init_ap_id __initdata; -unsigned long init_ap_boot_stack __initdata; +char init_stack[BOOT_STACK_SIZE] __aligned(8) __bootdata; +char init_ap_stack[BOOT_STACK_SIZE] __aligned(8) __bootdata; +unsigned long init_ap_id __bootdata; +unsigned long init_ap_boot_stack_addr __bootdata; /* * Copy of the multiboot data passed by the boot loader. */ -static struct multiboot_info init_mbi __initdata; +static struct multiboot_info init_mbi __bootdata; void __boot init_panic(const char *msg) @@ -62,12 +62,12 @@ init_panic(const char *msg) ptr = INIT_VGAMEM; end = ptr + INIT_VGACHARS; - s = (const char *)BOOT_ADDR_VTOP("boot panic: "); + s = (const char *)BOOT_VTOP("boot panic: "); while ((ptr < end) && (*s != '\0')) *ptr++ = (INIT_VGACOLOR << 8) | *s++; - s = (const char *)BOOT_ADDR_VTOP(msg); + s = (const char *)BOOT_VTOP(msg); while ((ptr < end) && (*s != '\0')) *ptr++ = (INIT_VGACOLOR << 8) | *s++; @@ -96,8 +96,8 @@ init_paging(uint32_t eax, const struct multiboot_info *mbi) * Save the multiboot data passed by the boot loader and initialize the * bootstrap allocator. */ - BOOT_VTOP(init_mbi) = *mbi; - biosmem_bootstrap(&BOOT_VTOP(init_mbi)); + init_mbi = *mbi; + biosmem_bootstrap(&init_mbi); /* * Create the kernel virtual mapping. Two mappings are actually established, @@ -113,13 +113,13 @@ init_paging(uint32_t eax, const struct multiboot_info *mbi) */ /* Allocate the PTPs */ - kern_end = BOOT_ADDR_VTOP(&_end); + kern_end = BOOT_VTOP(&_end); nr_pages = (kern_end / PAGE_SIZE) + PMAP_RESERVED_PAGES; nr_ptps = P2ROUND(nr_pages, PMAP_PTE_PER_PT) / PMAP_PTE_PER_PT; ptps = biosmem_bootalloc(nr_ptps); /* Insert the PTPs in the page directory */ - pdir = (pmap_pte_t *)BOOT_ADDR_VTOP(pmap_kpdir); + pdir = (pmap_pte_t *)pmap_kpdir; pte = pdir + (KERNEL_OFFSET >> PMAP_PDE_SHIFT); id_pte = pdir; @@ -136,7 +136,7 @@ init_paging(uint32_t eax, const struct multiboot_info *mbi) ptps[vm_page_atop(i)] = i | PMAP_PTE_WRITE | PMAP_PTE_PRESENT; #ifdef PAE - pte = (pmap_pte_t *)BOOT_ADDR_VTOP(pmap_kpdpt); + pte = (pmap_pte_t *)pmap_kpdpt; for (i = 0; i < PMAP_NR_PDT; i++) pte[i] = ((unsigned long)pdir + (i * PAGE_SIZE)) | PMAP_PTE_PRESENT; @@ -154,9 +154,9 @@ init_ap_paging(void) { #ifdef PAE cpu_enable_pae(); - return (pmap_pte_t *)BOOT_ADDR_VTOP(pmap_kpdpt); + return (pmap_pte_t *)pmap_kpdpt; #else /* PAE */ - return (pmap_pte_t *)BOOT_ADDR_VTOP(pmap_kpdir); + return (pmap_pte_t *)pmap_kpdir; #endif /* PAE */ } diff --git a/arch/i386/machine/init.h b/arch/x86/machine/init.h index 8b5d6938..79122c4d 100644 --- a/arch/i386/machine/init.h +++ b/arch/x86/machine/init.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_INIT_H -#define _I386_INIT_H +#ifndef _X86_INIT_H +#define _X86_INIT_H #include <lib/macros.h> #include <lib/stdint.h> @@ -44,7 +44,7 @@ extern unsigned long init_ap_id; * addresses. At this point, it switches to a per-AP preallocated * stack. This variable contains the (virtual) address of that stack. */ -extern unsigned long init_ap_boot_stack; +extern unsigned long init_ap_boot_stack_addr; /* * Print the given message and halt the system immediately. @@ -79,4 +79,4 @@ void init(void); */ void init_ap(void); -#endif /* _I386_INIT_H */ +#endif /* _X86_INIT_H */ diff --git a/arch/i386/machine/io.h b/arch/x86/machine/io.h index 66a53561..d99d180f 100644 --- a/arch/i386/machine/io.h +++ b/arch/x86/machine/io.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_IO_H -#define _I386_IO_H +#ifndef _X86_IO_H +#define _X86_IO_H #include <lib/stdint.h> @@ -41,4 +41,4 @@ io_write_byte(uint16_t port, uint8_t value) asm volatile("outb %%al, %%dx" : : "d" (port), "a" (value)); } -#endif /* _I386_IO_H */ +#endif /* _X86_IO_H */ diff --git a/arch/i386/machine/lapic.c b/arch/x86/machine/lapic.c index 1a1236af..1a1236af 100644 --- a/arch/i386/machine/lapic.c +++ b/arch/x86/machine/lapic.c diff --git a/arch/i386/machine/lapic.h b/arch/x86/machine/lapic.h index 5d5c82aa..ec0b26e4 100644 --- a/arch/i386/machine/lapic.h +++ b/arch/x86/machine/lapic.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_LAPIC_H -#define _I386_LAPIC_H +#ifndef _X86_LAPIC_H +#define _X86_LAPIC_H #include <lib/stdint.h> @@ -42,4 +42,4 @@ void lapic_ipi_startup(uint32_t dest, uint32_t vector); */ void lapic_timer_intr(void); -#endif /* _I386_LAPIC_H */ +#endif /* _X86_LAPIC_H */ diff --git a/arch/i386/machine/mps.c b/arch/x86/machine/mps.c index 8a4a899d..8a4a899d 100644 --- a/arch/i386/machine/mps.c +++ b/arch/x86/machine/mps.c diff --git a/arch/i386/machine/mps.h b/arch/x86/machine/mps.h index 304cec7d..304758a5 100644 --- a/arch/i386/machine/mps.h +++ b/arch/x86/machine/mps.h @@ -19,8 +19,8 @@ * Specification v1.4. */ -#ifndef _I386_MPS_H -#define _I386_MPS_H +#ifndef _X86_MPS_H +#define _X86_MPS_H /* * Load multiprocessor information. @@ -30,4 +30,4 @@ */ int mps_setup(void); -#endif /* _I386_MPS_H */ +#endif /* _X86_MPS_H */ diff --git a/arch/i386/machine/multiboot.h b/arch/x86/machine/multiboot.h index 70e47cd7..c08db166 100644 --- a/arch/i386/machine/multiboot.h +++ b/arch/x86/machine/multiboot.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_MULTIBOOT_H -#define _I386_MULTIBOOT_H +#ifndef _X86_MULTIBOOT_H +#define _X86_MULTIBOOT_H /* * Magic number provided by the OS to the boot loader. @@ -87,4 +87,4 @@ struct multiboot_info { #endif /* __ASSEMBLY__ */ -#endif /* _I386_MULTIBOOT_H */ +#endif /* _X86_MULTIBOOT_H */ diff --git a/arch/i386/machine/param.h b/arch/x86/machine/param.h index caa16912..a03e1050 100644 --- a/arch/i386/machine/param.h +++ b/arch/x86/machine/param.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_PARAM_H -#define _I386_PARAM_H +#ifndef _X86_PARAM_H +#define _X86_PARAM_H #include <machine/boot.h> @@ -105,4 +105,4 @@ */ #define VM_MAP_KENTRY_SIZE 0x800000UL -#endif /* _I386_PARAM_H */ +#endif /* _X86_PARAM_H */ diff --git a/arch/i386/machine/pit.c b/arch/x86/machine/pit.c index e5113ceb..e5113ceb 100644 --- a/arch/i386/machine/pit.c +++ b/arch/x86/machine/pit.c diff --git a/arch/i386/machine/pit.h b/arch/x86/machine/pit.h index 26192e62..3b4da60b 100644 --- a/arch/i386/machine/pit.h +++ b/arch/x86/machine/pit.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_PIT_H -#define _I386_PIT_H +#ifndef _X86_PIT_H +#define _X86_PIT_H /* * Set up the i8253 Programmable Interval Timer. @@ -28,4 +28,4 @@ void pit_setup(void); */ void pit_delay(unsigned long usecs); -#endif /* _I386_PIT_H */ +#endif /* _X86_PIT_H */ diff --git a/arch/i386/machine/pmap.c b/arch/x86/machine/pmap.c index 37c664ab..d5c5224c 100644 --- a/arch/i386/machine/pmap.c +++ b/arch/x86/machine/pmap.c @@ -34,13 +34,14 @@ /* * Kernel page directory. */ -pmap_pte_t pmap_kpdir[PMAP_NR_PDT * PMAP_PTE_PER_PT] __aligned(PAGE_SIZE); +pmap_pte_t pmap_kpdir[PMAP_NR_PDT * PMAP_PTE_PER_PT] __aligned(PAGE_SIZE) + __bootdata; #ifdef PAE /* * Kernel page directory pointer table. */ -pmap_pte_t pmap_kpdpt[PMAP_NR_PDT] __aligned(sizeof(pmap_kpdpt)); +pmap_pte_t pmap_kpdpt[PMAP_NR_PDT] __aligned(sizeof(pmap_kpdpt)) __bootdata; #endif /* PAE */ /* @@ -125,10 +126,10 @@ pmap_bootstrap(void) */ kernel_pmap = &kernel_pmap_store; kernel_pmap->pdir = pmap_kpdir; - kernel_pmap->pdir_pa = BOOT_ADDR_VTOP(pmap_kpdir); + kernel_pmap->pdir_pa = (unsigned long)pmap_kpdir; #ifdef PAE - kernel_pmap->pdpt = (pmap_pte_t *)BOOT_ADDR_VTOP(pmap_kpdpt); + kernel_pmap->pdpt = pmap_kpdpt; #endif /* PAE */ /* diff --git a/arch/i386/machine/pmap.h b/arch/x86/machine/pmap.h index 7053ae7d..89237c14 100644 --- a/arch/i386/machine/pmap.h +++ b/arch/x86/machine/pmap.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_PMAP_H -#define _I386_PMAP_H +#ifndef _X86_PMAP_H +#define _X86_PMAP_H #include <kern/param.h> #include <kern/types.h> @@ -194,4 +194,4 @@ vm_phys_t pmap_kextract(unsigned long va); */ void pmap_zero_page(vm_phys_t pa); -#endif /* _I386_PMAP_H */ +#endif /* _X86_PMAP_H */ diff --git a/arch/i386/machine/trap.h b/arch/x86/machine/trap.h index 8c65b718..796ba007 100644 --- a/arch/i386/machine/trap.h +++ b/arch/x86/machine/trap.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_TRAP_H -#define _I386_TRAP_H +#ifndef _X86_TRAP_H +#define _X86_TRAP_H /* * Trap vectors. @@ -44,4 +44,4 @@ #define T_APIC_ERROR_INTR 254 #define T_APIC_SPURIOUS_INTR 255 -#endif /* _I386_TRAP_H */ +#endif /* _X86_TRAP_H */ diff --git a/arch/i386/machine/types.h b/arch/x86/machine/types.h index 10825624..cc125151 100644 --- a/arch/i386/machine/types.h +++ b/arch/x86/machine/types.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_TYPES_H -#define _I386_TYPES_H +#ifndef _X86_TYPES_H +#define _X86_TYPES_H #ifdef PAE typedef unsigned long long vm_phys_t; @@ -24,4 +24,4 @@ typedef unsigned long long vm_phys_t; typedef unsigned long vm_phys_t; #endif /* PAE */ -#endif /* _I386_TYPES_H */ +#endif /* _X86_TYPES_H */ diff --git a/arch/i386/machine/vga.c b/arch/x86/machine/vga.c index 60911943..60911943 100644 --- a/arch/i386/machine/vga.c +++ b/arch/x86/machine/vga.c diff --git a/arch/i386/machine/vga.h b/arch/x86/machine/vga.h index ff8646c4..f6836cd9 100644 --- a/arch/i386/machine/vga.h +++ b/arch/x86/machine/vga.h @@ -15,8 +15,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _I386_VGA_H -#define _I386_VGA_H +#ifndef _X86_VGA_H +#define _X86_VGA_H #include <lib/stdint.h> @@ -30,4 +30,4 @@ void vga_setup(void); */ void vga_write_byte(uint8_t byte); -#endif /* _I386_VGA_H */ +#endif /* _X86_VGA_H */ diff --git a/arch/i386/x15.lds.S b/arch/x86/x15.lds.S index 363bc919..d5c3bff1 100644 --- a/arch/i386/x15.lds.S +++ b/arch/x86/x15.lds.S @@ -1,10 +1,14 @@ -/* - * Don't replace i386. - */ +/* Don't replace i386 */ #undef i386 +#ifdef __LP64__ +OUTPUT_FORMAT("elf64-x86-64") +OUTPUT_ARCH(i386:x86-64) +#else OUTPUT_FORMAT("elf32-i386") OUTPUT_ARCH(i386) +#endif /* __LP64__ */ + ENTRY(_start) #define __ASSEMBLY__ @@ -29,6 +33,7 @@ SECTIONS _boot = .; *(.boothdr) *(.boot) + *(.bootdata) _eboot = .; } : boot diff --git a/configure.ac b/configure.ac index f4af31ae..33109df9 100644 --- a/configure.ac +++ b/configure.ac @@ -6,21 +6,15 @@ AC_CONFIG_AUX_DIR([build-aux]) AM_INIT_AUTOMAKE([gnu check-news subdir-objects 1.10]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])], - [AC_SUBST([AM_DEFAULT_VERBOSITY], [1])]) + [AC_SUBST([AM_DEFAULT_VERBOSITY], [1])]) AC_PREFIX_DEFAULT([]) - - -# -# Deduce the output variable `systype' from the configuration parameters. -# AC_CANONICAL_HOST - -AS_CASE(["$host_cpu"], - [i?86|x86_64], [m4_include([arch/i386/configfrag.ac])], - [AC_MSG_ERROR([unsuported CPU type])]) - -AC_SUBST([systype]) +AM_PROG_AS +AC_PROG_CC([gcc]) +AC_PROG_CPP +AC_PROG_RANLIB +AM_PROG_CC_C_O # @@ -38,33 +32,35 @@ AC_ARG_WITH([max-cpus], # -# Options +# Deduce the output variable `systype' from the configuration parameters. # -AS_IF([test x"$enable_debug" = xno], - [AC_DEFINE([NDEBUG], [1], [general debugging])]) - -AC_DEFINE([__KERNEL__], [1], [kernel code]) +AS_CASE(["$host_cpu"], + [i?86|x86_64], [m4_include([arch/x86/configfrag.ac])], + [AC_MSG_ERROR([unsuported CPU type])]) -AC_DEFINE_UNQUOTED([ARCH], [$systype], [arch]) -AM_CONDITIONAL([I386], [test "$systype" = i386]) +AC_SUBST([systype]) -AC_DEFINE_UNQUOTED([MAX_CPUS], [$opt_max_cpus], [maximum number of supported processors]) +# XXX Should be in an arch-specific file. +AM_CONDITIONAL([X86], [test "$systype" = x86]) +AM_CONDITIONAL([I386], [test x"$opt_i386" = xyes]) +AM_CONDITIONAL([AMD64], [test x"$opt_amd64" = xyes]) # -# Programs. +# Options # -AM_PROG_AS -AC_PROG_CC([gcc]) -AC_PROG_CPP -AC_PROG_RANLIB +AS_IF([test x"$enable_debug" = xno], + [AC_DEFINE([NDEBUG], [1], [general debugging])]) + +AC_DEFINE([__KERNEL__], [1], [kernel code]) +AC_DEFINE_UNQUOTED([ARCH], [$systype], [arch]) +AC_DEFINE_UNQUOTED([MAX_CPUS], [$opt_max_cpus], + [maximum number of supported processors]) -AM_PROG_CC_C_O # # Output # AC_CONFIG_HEADER([config.h]) AC_CONFIG_FILES([Makefile]) - AC_OUTPUT diff --git a/lib/stdint.h b/lib/stdint.h index ee531db3..17cb9a2b 100644 --- a/lib/stdint.h +++ b/lib/stdint.h @@ -22,17 +22,9 @@ typedef signed char int8_t; typedef unsigned char uint8_t; typedef signed short int16_t; typedef unsigned short uint16_t; - -#ifdef __LP64__ -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef signed long int64_t; -typedef unsigned long uint64_t; -#else /* __LP64__ */ typedef signed int int32_t; typedef unsigned int uint32_t; typedef signed long long int64_t; typedef unsigned long long uint64_t; -#endif /* __LP64__ */ #endif /* _LIB_STDINT_H */ diff --git a/vm/vm_map.c b/vm/vm_map.c index 4030cdc6..f9c6479e 100644 --- a/vm/vm_map.c +++ b/vm/vm_map.c @@ -640,5 +640,5 @@ vm_map_info(struct vm_map *map) entry->flags, type); } - printk("vm_map: total: %uk\n", map->size >> 10); + printk("vm_map: total: %zuk\n", map->size >> 10); } diff --git a/vm/vm_phys.c b/vm/vm_phys.c index 3e8a70f0..2852a034 100644 --- a/vm/vm_phys.c +++ b/vm/vm_phys.c @@ -527,7 +527,7 @@ vm_phys_setup(void) pages += vm_page_atop(vm_phys_seg_size(&vm_phys_segs[i])); map_size = P2ROUND(pages * sizeof(struct vm_page), PAGE_SIZE); - printk("vm_phys: page table size: %u entries (%uk)\n", pages, + printk("vm_phys: page table size: %zu entries (%zuk)\n", pages, map_size >> 10); map = (struct vm_page *)vm_kmem_bootalloc(map_size); |