[BOOT] Multiboot compliant kernel which runs 64 bit code

This commit is contained in:
2016-07-24 00:45:20 +02:00
parent 1f8d5b3482
commit df86be2973
13 changed files with 433 additions and 4 deletions

12
kernel/include/gdt.h Normal file
View File

@@ -0,0 +1,12 @@
#pragma once
#define GDT_WRITE (1<<41)
#define GDT_EXECUTE (1<<43)
#define GDT_CODEDATA (1<<44)
#define GDT_PRESENT (1<<47)
#define GDT_64BIT (1<<53)
#ifndef __ASSEMBLER__
#include <stdint.h>
extern uint64_t BootGDT;
#endif

27
kernel/include/mem.h Normal file
View File

@@ -0,0 +1,27 @@
#pragma once
#define KERNEL_OFFSET 0xFFFFFF8000000000
#ifdef __ASSEMBLER__
#define V2P(a) ((a) - KERNEL_OFFSET)
#define P2V(a) ((a) + KERNEL_OFFSET)
#define P1_OFFSET(p) (((p) >> 12) & 0x1FF)
#define P2_OFFSET(p) (((p) >> 21) & 0x1FF)
#define P3_OFFSET(p) (((p) >> 30) & 0x1FF)
#define P4_OFFSET(p) (((p) >> 39) & 0x1FF)
#else
#include <stdint.h>
#define V2P(a) ((uintptr_t)(a) - KERNEL_OFFSET)
#define P2V(a) ((void *)((uintptr_t)(a) + KERNEL_OFFSET))
#endif
// Paging
#define PAGE_PRESENT 0x001
#define PAGE_WRITE 0x002
#define PAGE_USER 0x004
#define PAGE_WRITETHROUGH 0x008
#define PAGE_NOCACHE 0x010
#define PAGE_ACCESSED 0x020
#define PAGE_DIRTY 0x040
#define PAGE_HUGE 0x080
#define PAGE_GLOBAL 0x100

View File

@@ -0,0 +1,14 @@
#pragma once
#define MBOOT1_MAGIC 0x1BADB002
#define MBOOT1_MAGIC2 0x2BADB002
#define MBOOT1_FLAG_PAGE_ALIGN 0x01
#define MBOOT1_FLAG_MEM_INFO 0x02
#define MBOOT1_HEADER_FLAGS (MBOOT1_FLAG_PAGE_ALIGN | MBOOT1_FLAG_MEM_INFO)
#define MBOOT1_HEADER_CHECKSUM -(MBOOT1_HEADER_FLAGS + MBOOT1_MAGIC)
#define MBOOT2_MAGIC 0xE85250D6
#define MBOOT2_MAGIC2 0x36D76289
#define MBOOT2_ARCH 0
#define MBOOT2_LENGTH (MultiBootHeaderEnd - MultiBootHeader)
#define MBOOT2_CHECKSUM -(MBOOT2_MAGIC + MBOOT2_ARCH + MBOOT2_LENGTH)