From 1499c9eb8aa167dff5354a25c5a5bd2d00672a54 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 27 May 2010 19:38:59 +0800 Subject: [PATCH] x86_64 now compiles and builds :) :) --- Kernel/Makefile | 6 ++-- Kernel/Makefile.BuildNum | 2 +- Kernel/arch/x86/start.asm | 36 +++++++++++----------- Kernel/arch/x86_64/Makefile | 4 ++- Kernel/arch/x86_64/kernelpanic.c | 16 ++++++++++ Kernel/arch/x86_64/lib.c | 6 ++++ Kernel/arch/x86_64/link.ld | 11 ++++--- Kernel/arch/x86_64/main.c | 22 ++++++++++++++ Kernel/arch/x86_64/mm_virt.c | 15 +++++++++ Kernel/arch/x86_64/start32.asm | 52 +++++++++++++++++++++++++++++--- Kernel/arch/x86_64/start64.asm | 20 ++++++++++++ Kernel/arch/x86_64/vm8086.c | 4 +-- Makefile.x86_64.cfg | 2 +- Modules/Makefile.tpl | 5 ++- 14 files changed, 167 insertions(+), 34 deletions(-) create mode 100644 Kernel/arch/x86_64/kernelpanic.c diff --git a/Kernel/Makefile b/Kernel/Makefile index 6be6a135..5d48945f 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -37,6 +37,7 @@ OBJ += $(addprefix drv/, $(addsuffix .o,$(DRIVERS))) OBJ := $(addsuffix .$(ARCH), $(OBJ)) MODS += $(addprefix ../Modules/, $(addsuffix .xo.$(ARCH),$(MODULES))) BIN = ../Acess2.$(ARCH).bin +GZBIN = ../Acess2.$(ARCH).gz DEPFILES = $(filter %.o.$(ARCH),$(OBJ)) DEPFILES := $(DEPFILES:%.o.$(ARCH)=%.d.$(ARCH)) @@ -49,10 +50,11 @@ SRCFILES := $(SRCFILES:%.ao.$(ARCH)=%.asm) all: $(BIN) clean: - @$(RM) $(BIN) $(BIN).dsm ../Map.$(ARCH).txt LineCounts.$(ARCH).txt $(OBJ) $(DEPFILES) + @$(RM) $(BIN) ../Acess2.$(ARCH).gz $(BIN).dsm ../Map.$(ARCH).txt LineCounts.$(ARCH).txt $(OBJ) $(DEPFILES) install: $(BIN) - $(xCP) $(BIN) $(DISTROOT) + gzip -c $(BIN) > ../Acess2.$(ARCH).gz + $(xCP) ../Acess2.$(ARCH).gz $(DISTROOT) apidoc: doxygen Doxyfile.api diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 41882050..2e18d025 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 2183 +BUILD_NUM = 2206 diff --git a/Kernel/arch/x86/start.asm b/Kernel/arch/x86/start.asm index b98a0165..8b3e18c5 100644 --- a/Kernel/arch/x86/start.asm +++ b/Kernel/arch/x86/start.asm @@ -10,30 +10,30 @@ KERNEL_BASE equ 0xC0000000 [extern gKernelEnd] [section .multiboot] mboot: - ; Multiboot macros to make a few lines later more readable - MULTIBOOT_PAGE_ALIGN equ 1<<0 - MULTIBOOT_MEMORY_INFO equ 1<<1 - MULTIBOOT_HEADER_MAGIC equ 0x1BADB002 - MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO - MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) + ; Multiboot macros to make a few lines later more readable + MULTIBOOT_PAGE_ALIGN equ 1<<0 + MULTIBOOT_MEMORY_INFO equ 1<<1 + MULTIBOOT_HEADER_MAGIC equ 0x1BADB002 + MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO + MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) - ; This is the GRUB Multiboot header. A boot signature - dd MULTIBOOT_HEADER_MAGIC - dd MULTIBOOT_HEADER_FLAGS - dd MULTIBOOT_CHECKSUM + ; This is the GRUB Multiboot header. A boot signature + dd MULTIBOOT_HEADER_MAGIC + dd MULTIBOOT_HEADER_FLAGS + dd MULTIBOOT_CHECKSUM dd mboot - KERNEL_BASE ;Location of Multiboot Header ; Multiboot 2 Header mboot2: - MULTIBOOT2_HEADER_MAGIC equ 0xE85250D6 - MULTIBOOT2_HEADER_ARCH equ 0 - MULTIBOOT2_HEADER_LENGTH equ (mboot2_end-mboot2) - MULTIBOOT2_CHECKSUM equ -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_HEADER_ARCH + MULTIBOOT2_HEADER_LENGTH) + MULTIBOOT2_HEADER_MAGIC equ 0xE85250D6 + MULTIBOOT2_HEADER_ARCH equ 0 + MULTIBOOT2_HEADER_LENGTH equ (mboot2_end-mboot2) + MULTIBOOT2_CHECKSUM equ -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_HEADER_ARCH + MULTIBOOT2_HEADER_LENGTH) - dd MULTIBOOT2_HEADER_MAGIC - dd MULTIBOOT2_HEADER_ARCH - dd MULTIBOOT2_HEADER_LENGTH - dd MULTIBOOT2_CHECKSUM + dd MULTIBOOT2_HEADER_MAGIC + dd MULTIBOOT2_HEADER_ARCH + dd MULTIBOOT2_HEADER_LENGTH + dd MULTIBOOT2_CHECKSUM ; MBoot2 Address Header dw 2, 0 dd 8 + 16 diff --git a/Kernel/arch/x86_64/Makefile b/Kernel/arch/x86_64/Makefile index e4fe5ad4..2e1b84a9 100644 --- a/Kernel/arch/x86_64/Makefile +++ b/Kernel/arch/x86_64/Makefile @@ -14,6 +14,7 @@ MAX_CPUS := 4 CPPFLAGS := -DMAX_CPUS=$(MAX_CPUS) CFLAGS := $(KERNEL_CFLAGS) ASFLAGS := -f elf64 -D MAX_CPUS=$(MAX_CPUS) +LDFLAGS := -nostdlib -nodefaultlibs ifeq ($(ARCH),amd64) ASFLAGS += -D AMD64=1 @@ -27,4 +28,5 @@ endif A_OBJ = start32.ao start64.ao desctab.ao -A_OBJ += main.o lib.o proc.o mm_virt.o mm_phys.o +A_OBJ += main.o lib.o proc.o mm_virt.o mm_phys.o vm8086.o +A_OBJ += kernelpanic.o diff --git a/Kernel/arch/x86_64/kernelpanic.c b/Kernel/arch/x86_64/kernelpanic.c new file mode 100644 index 00000000..32ea75d8 --- /dev/null +++ b/Kernel/arch/x86_64/kernelpanic.c @@ -0,0 +1,16 @@ +/* + */ + +// === PROTOTYPES === +void KernelPanic_SetMode(void); +void KernelPanic_PutChar(char ch); + + +void KernelPanic_SetMode(void) +{ +} + +void KernelPanic_PutChar(char ch) +{ + +} diff --git a/Kernel/arch/x86_64/lib.c b/Kernel/arch/x86_64/lib.c index ba1a618e..ee32d815 100644 --- a/Kernel/arch/x86_64/lib.c +++ b/Kernel/arch/x86_64/lib.c @@ -150,3 +150,9 @@ void *memset(void *__dest, int __val, size_t __count) return __dest; } +void *memsetd(void *__dest, Uint32 __val, size_t __count) +{ + __asm__ __volatile__ ("rep stosl" : : "D"(__dest),"a"(__val),"c"(__count)); + return __dest; +} + diff --git a/Kernel/arch/x86_64/link.ld b/Kernel/arch/x86_64/link.ld index cab3c5c1..9859c4ec 100644 --- a/Kernel/arch/x86_64/link.ld +++ b/Kernel/arch/x86_64/link.ld @@ -5,12 +5,17 @@ _kernel_base = 0xFFFF800000000000; -//lowStart = start - _kernel_base; +/* +lowStart = start - _kernel_base; ENTRY(start) OUTPUT_FORMAT(elf64-x86-64) +*/ +OUTPUT_FORMAT(elf32-i386) +OUTPUT_ARCH(i386:x86-64) +ENTRY (start) SECTIONS { - . = 0x100000; + . = 0x100000 + SIZEOF_HEADERS; __load_addr = .; .multiboot : AT(ADDR(.multiboot)) { *(.multiboot) @@ -39,8 +44,6 @@ SECTIONS { gKernelSymbols = .; *(KEXPORT) gKernelSymbolsEnd = .; - - } /* .debug_abbrev : { *(.debug_abbrev) } diff --git a/Kernel/arch/x86_64/main.c b/Kernel/arch/x86_64/main.c index e69de29b..60d5cf08 100644 --- a/Kernel/arch/x86_64/main.c +++ b/Kernel/arch/x86_64/main.c @@ -0,0 +1,22 @@ +/* + * Acess2 x86_64 Project + */ +#include + +// === GLOBALS == + +// === CODE === +void kmain(Uint MbMagic, void *MbInfoPtr) +{ + +} + +void Arch_LoadBootModules(void) +{ + +} + +void StartupPrint(char *String) +{ + +} diff --git a/Kernel/arch/x86_64/mm_virt.c b/Kernel/arch/x86_64/mm_virt.c index 19bf72f4..f1a4a800 100644 --- a/Kernel/arch/x86_64/mm_virt.c +++ b/Kernel/arch/x86_64/mm_virt.c @@ -35,6 +35,11 @@ void MM_InitVirt(void) } +void MM_FinishVirtualInit(void) +{ + +} + /** * \brief Map a physical page to a virtual one */ @@ -340,3 +345,13 @@ void MM_ClearUser(void) } } } + +tVAddr MM_NewWorkerStack(void) +{ + return 0; +} + +tVAddr MM_NewKStack(void) +{ + return 0; +} diff --git a/Kernel/arch/x86_64/start32.asm b/Kernel/arch/x86_64/start32.asm index 577607aa..21e7c408 100644 --- a/Kernel/arch/x86_64/start32.asm +++ b/Kernel/arch/x86_64/start32.asm @@ -5,14 +5,39 @@ KERNEL_BASE equ 0xFFFF800000000000 [section .multiboot] mboot: - MULTIBOOT_MAGIC equ 0x1BADB002 - dd MULTIBOOT_MAGIC + ; Multiboot macros to make a few lines later more readable + MULTIBOOT_PAGE_ALIGN equ 1<<0 + MULTIBOOT_MEMORY_INFO equ 1<<1 + MULTIBOOT_AOUT_KLUDGE equ 1<<16 + MULTIBOOT_HEADER_MAGIC equ 0x1BADB002 + MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO; | MULTIBOOT_AOUT_KLUDGE + MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) + + ; This is the GRUB Multiboot header. A boot signature + dd MULTIBOOT_HEADER_MAGIC + dd MULTIBOOT_HEADER_FLAGS + dd MULTIBOOT_CHECKSUM + [extern __load_addr] + [extern __bss_start] + [extern gKernelEnd] + ; a.out kludge + dd mboot ; Location of Multiboot Header + dd __load_addr ; Load address + dd __bss_start - KERNEL_BASE ; End of .data + dd gKernelEnd - KERNEL_BASE ; End of .bss (and kernel) + dd start - KERNEL_BASE ; Entrypoint [extern start64] [section .text] [global start] start: + ; Check for Long Mode support + mov eax, 0x80000001 + cpuid + test edx, 1<<29 + jz .not64bitCapable + ; Enable PAE mov eax, cr4 or eax, 0x80|0x20 @@ -44,6 +69,21 @@ start: jmp 0x08:start64 - KERNEL_BASE +.not64bitCapable: + mov ah, 0x0F + mov edi, 0xB8000 + mov esi, csNot64BitCapable - KERNEL_BASE + +.loop: + lodsb + test al, al + jz .hlt + stosw + jmp .loop + +.hlt: + jmp .hlt + [section .data] [global gGDT] gGDT: @@ -72,14 +112,15 @@ gInitialPML4: ; Covers 256 TiB (Full 48-bit Virtual Address Space) gInitialPDP: ; Covers 512 GiB dd gInitialPD - KERNEL_BASE + 3, 0 - times 511 dq 0 + times 511 dq 0 gInitialPD: ; Covers 1 GiB dd gInitialPT1 - KERNEL_BASE + 3, 0 dd gInitialPT2 - KERNEL_BASE + 3, 0 + times 510 dq 0 gInitialPT1: ; Covers 2 MiB - %assign i 1 + %assign i 0 %rep 512 dq i*4096+3 %assign i i+1 @@ -92,3 +133,6 @@ gInitialPT2: ; 2 MiB %endrep +[section .rodata] +csNot64BitCapable: + db "Not 64-bit Capable",0 diff --git a/Kernel/arch/x86_64/start64.asm b/Kernel/arch/x86_64/start64.asm index 30fc9717..a2ffb19b 100644 --- a/Kernel/arch/x86_64/start64.asm +++ b/Kernel/arch/x86_64/start64.asm @@ -63,6 +63,26 @@ Proc_ReturnToUser: iret +; int CallWithArgArray(void *Ptr, int NArgs, Uint *Args) +; Call a function passing the array as arguments +[global CallWithArgArray] +CallWithArgArray: + push rbp + mov rbp, rsp + mov rcx, [rbp+3*8] ; Get NArgs + mov rdx, [rbp+4*8] + +.top: + mov rax, [rdx+rcx*8-8] + push rax + loop .top + + mov rax, [rbp+2*8] + call rax + lea rsp, [rbp] + pop rbp + ret + [section .usertext] User_Syscall_RetAndExit: mov rdi, rax diff --git a/Kernel/arch/x86_64/vm8086.c b/Kernel/arch/x86_64/vm8086.c index 0feb79e9..68728c1c 100644 --- a/Kernel/arch/x86_64/vm8086.c +++ b/Kernel/arch/x86_64/vm8086.c @@ -39,12 +39,12 @@ void VM8086_Free(tVM8086 *State) void *VM8086_Allocate(tVM8086 *State, int Size, Uint16 *Segment, Uint16 *Offset) { - + return NULL; } void *VM8086_GetPointer(tVM8086 *State, Uint16 Segment, Uint16 Offset) { - + return NULL; } void VM8086_Int(tVM8086 *State, Uint8 Interrupt) diff --git a/Makefile.x86_64.cfg b/Makefile.x86_64.cfg index ac012f62..f40c9003 100644 --- a/Makefile.x86_64.cfg +++ b/Makefile.x86_64.cfg @@ -2,7 +2,7 @@ CC = x86_64-linux-gnu-gcc LD = ld -KERNEL_CFLAGS = -mcmodel=large +KERNEL_CFLAGS = -mcmodel=large -nostdlib ARCHDIR = x86_64 diff --git a/Modules/Makefile.tpl b/Modules/Makefile.tpl index b20a731e..103e8d8a 100644 --- a/Modules/Makefile.tpl +++ b/Modules/Makefile.tpl @@ -40,7 +40,10 @@ clean: $(RM) $(BIN) $(BIN).dsm $(KOBJ) $(OBJ) $(DEPFILES) install: $(BIN) - $(xCP) $(BIN) $(DISTROOT)/Modules/$(NAME).kmd +ifeq ($(BUILDTYPE),dynamic) + $(xCP) $(BIN) $(DISTROOT)/Modules/$(NAME).kmd.$(ARCH) +else +endif ifeq ($(BUILDTYPE),dynamic) $(BIN): %.kmd.$(ARCH): $(OBJ) -- 2.20.1