From 302b755a1a7b1d607774353b908e325e934aacdc Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 11 May 2010 10:10:32 +0800 Subject: [PATCH] Adding start of x86_64 port --- Kernel/arch/x86_64/Makefile | 28 ++++++++++ Kernel/arch/x86_64/include/arch.h | 33 +++++++++++ Kernel/arch/x86_64/include/mm_virt.h | 27 +++++++++ Kernel/arch/x86_64/lib.c | 0 Kernel/arch/x86_64/main.c | 0 Kernel/arch/x86_64/start32.asm | 83 ++++++++++++++++++++++++++++ Kernel/arch/x86_64/start64.asm | 0 7 files changed, 171 insertions(+) create mode 100644 Kernel/arch/x86_64/Makefile create mode 100644 Kernel/arch/x86_64/include/arch.h create mode 100644 Kernel/arch/x86_64/include/mm_virt.h create mode 100644 Kernel/arch/x86_64/lib.c create mode 100644 Kernel/arch/x86_64/main.c create mode 100644 Kernel/arch/x86_64/start32.asm create mode 100644 Kernel/arch/x86_64/start64.asm diff --git a/Kernel/arch/x86_64/Makefile b/Kernel/arch/x86_64/Makefile new file mode 100644 index 00000000..3820a691 --- /dev/null +++ b/Kernel/arch/x86_64/Makefile @@ -0,0 +1,28 @@ +# +# Acess2 Kernel +# i386 Architecture Makefile +# arch/i386/Makefile + +# Assuming build machine is 32-bit ELF +#CC = gcc +#AS = nasm +#LD = ld +#OBJDUMP = objdump + +CPPFLAGS = +CFLAGS = +ASFLAGS = -f elf + +ifeq ($(ARCH),amd64) + ASFLAGS += -D AMD64=1 + CPPFLAGS += -DAMD64=1 +else + ifeq ($(ARCH),ia64) + ASFLAGS += -D AMD64=0 -D IA64=1 + CPPFLAGS += -DAMD64=0 -DIA64=1 + endif +endif + + +A_OBJ = start32.ao start64.ao +A_OBJ += main.o lib.o diff --git a/Kernel/arch/x86_64/include/arch.h b/Kernel/arch/x86_64/include/arch.h new file mode 100644 index 00000000..d812a514 --- /dev/null +++ b/Kernel/arch/x86_64/include/arch.h @@ -0,0 +1,33 @@ +/* + * Acess2 x86-64 Architecure Module + * - By John Hodge (thePowersGang) + */ +#ifndef _ARCH_H_ +#define _ARCH_H_ + +#define KERNEL_BASE 0xFFFF8000##00000000 + +// === Core Types === +typedef signed char Sint8; +typedef unsigned char Uint8; +typedef signed short Sint16; +typedef unsigned short Uint16; +typedef signed long Sint32; +typedef unsigned long Uint32; +typedef signed long long Sint64; +typedef unsigned long long Uint64; + +typedef Uint64 Uint; +typedef Uint64 tPAddr; +typedef Uint64 tVAddr; + +//typedef unsigned int size_t; +typedef Uint64 size_t; + +typedef int tSpinlock; + +#define LOCK(_ptr) +#define RELEASE(_ptr) + +#endif + diff --git a/Kernel/arch/x86_64/include/mm_virt.h b/Kernel/arch/x86_64/include/mm_virt.h new file mode 100644 index 00000000..2dd28dd6 --- /dev/null +++ b/Kernel/arch/x86_64/include/mm_virt.h @@ -0,0 +1,27 @@ +/* + * Acess2 x86_64 Architecture Code + * + * This file is published under the terms of the Acess Licence. + * See the file COPYING for more details + * + * vmem.h - Virtual Memory Functions & Definitions + */ +#ifndef _VMEM_H_ +#define _VMEM_H_ + +// === Memory Location Definitions === +/* + * Userland - Lower Half + * Kernel land - Upper Half + * + * 0xFFFF8000 00000000 - 0xFFFFFFFF FFFFFFFF 2**47 Kernel Range + * 8000 00000000 - 8000 7FFFFFFF 2 GiB Identity Map + * 8000 80000000 - 8001 00000000 2 GiB Kernel Heap + * 9000 00000000 0 9800 00000000 cbf Module Space + */ + +#define KERNEL_BASE 0xFFF8000##00000000 +#define MM_KHEAP_BASE (KERNEL_BASE|0x80000000) +#define MM_KHEAP_MAX (KERNEL_BASE|0x1##00000000) + +#endif diff --git a/Kernel/arch/x86_64/lib.c b/Kernel/arch/x86_64/lib.c new file mode 100644 index 00000000..e69de29b diff --git a/Kernel/arch/x86_64/main.c b/Kernel/arch/x86_64/main.c new file mode 100644 index 00000000..e69de29b diff --git a/Kernel/arch/x86_64/start32.asm b/Kernel/arch/x86_64/start32.asm new file mode 100644 index 00000000..eada7b99 --- /dev/null +++ b/Kernel/arch/x86_64/start32.asm @@ -0,0 +1,83 @@ + +[BITS 32] + +[section .multiboot] +mboot: + MULTIBOOT_MAGIC equ 0x1BADB002 + dd MULTIBOOT_MAGIC + +[extern start64] + +[section .text] +[global start] +start: + ; Enable PAE + mov eax, cr4 + or eax, 0x80|0x20 + mov cr4, eax + + ; Load PDP4 + mov eax, gInitialPML4 + mov cr3, eax + + ; Enable long/compatability mode + mov ecx, 0xC0000080 + rdmsr + or ax, 0x100 + wrmsr + + ; Enable paging + mov eax, cr0 + or eax, 0x80000000 + mov cr0, eax + + ; Load GDT + lgdt [gGDTPtr] + mov ax, 0x10 + mov ss, ax + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + + jmp 0x08:start64 + +[section .data] +gGDT: + dd 0,0 + dd 0x00000000, 0x00209800 ; 64-bit Code + dd 0x00000000, 0x00009000 ; 64-bit Data +gGDTPtr: + dw $-gGDT-1 + dd gGDT + dd 0 + +[section .padata] +gInitialPML4: ; 256 TiB + dd gInitialPDP + 3, 0 ; Identity Map Low 4Mb + times 256-1 dq 0 + dd gInitialPDP + 3, 0 ; Identity Map Low 4Mb to kernel base + times 256-1 dq 0 + +gInitialPDP: ; 512 GiB + dd gInitialPD + 3, 0 + times 511 dq 0 + +gInitialPD: ; 1 GiB + dd gInitialPT1 + 3, 0 + dd gInitialPT2 + 3, 0 + +gInitialPT1: ; 2 MiB + %assign i 1 + %rep 512 + dq i*4096+3 + %assign i i+1 + %endrep +gInitialPT2: ; 2 MiB + %assign i 512 + %rep 512 + dq i*4096+3 + %assign i i+1 + %endrep + + diff --git a/Kernel/arch/x86_64/start64.asm b/Kernel/arch/x86_64/start64.asm new file mode 100644 index 00000000..e69de29b -- 2.20.1