Remove magic numbers. Also, no code segment - not needed.

This commit is contained in:
Thomas Lovén 2017-11-14 16:26:11 +01:00
parent dd7636e906
commit 5ddf0173c2
6 changed files with 60 additions and 39 deletions

View File

@ -1,8 +1,9 @@
#include <x86_64/memory.h>
.intel_syntax noprefix .intel_syntax noprefix
.section .bss .section .bss
.align 0x1000 .align PAGE_SIZE
.skip 0x1000 .skip PAGE_SIZE
BootStack: BootStack:
.byte 0 .byte 0
@ -71,10 +72,6 @@ mov cr0, eax
lgdt [BootGDTp] lgdt [BootGDTp]
mov eax, 0x10
mov ss, eax
mov ds, eax
mov es, eax
.extern long_mode_start .extern long_mode_start
jmp 0x8:long_mode_start jmp 0x8:long_mode_start
@ -82,4 +79,11 @@ mov es, eax
.code64 .code64
long_mode_start: long_mode_start:
mov eax, 0x0
mov ss, eax
mov ds, eax
mov es, eax
mov fs, eax
mov gs, eax
jmp $ jmp $

View File

@ -0,0 +1,14 @@
#include <x86_64/gdt.h>
#include <x86_64/memory.h>
.intel_syntax noprefix
.section .rodata
.align PAGE_SIZE
.global BootGDT
.global BootGDTp
BootGDT:
.long 0, 0
.long 0, (GDT_PRESENT | GDT_DPL(0) | GDT_CODE | GDT_LONG)
BootGDTp:
.short 2*8-1
.quad offset BootGDT

22
src/kernel/boot/boot_PT.S Normal file
View File

@ -0,0 +1,22 @@
#include <x86_64/memory.h>
.intel_syntax noprefix
.section .data
.align PAGE_SIZE
.global BootP4
BootP4:
.quad offset BootP3 + (PAGE_PRESENT | PAGE_WRITE)
.rept ENTRIES_PER_PT - 1
.quad 0x0
.endr
BootP3:
.quad offset BootP2 + (PAGE_PRESENT | PAGE_WRITE)
.rept ENTRIES_PER_PT - 1
.quad 0x0
.endr
BootP2:
.set i, 0
.rept ENTRIES_PER_PT
.quad (i << 21 ) + (PAGE_PRESENT | PAGE_WRITE | PAGE_HUGE)
.set i, (i+1)
.endr

View File

@ -1,33 +0,0 @@
.intel_syntax noprefix
.section .data
.align 0x1000
.global BootP4
BootP4:
.quad offset BootP3 + 0x3
.rept 511
.quad 0x0
.endr
BootP3:
.quad offset BootP2 + 0x3
.rept 511
.quad 0x0
.endr
BootP2:
.set i, 0
.rept 512
.quad (i << 21 ) + 0x83
.set i, (i+1)
.endr
.section .rodata
.align 0x1000
.global BootGDT
.global BootGDTp
BootGDT:
.quad 0
.quad ((1<<47) + (1<<44) + (1<<41) + (1<<43) + (1<<53))
.quad ((1<<47) + (1<<44) + (1<<41))
BootGDTp:
.short 3*8-1
.quad offset BootGDT

View File

@ -0,0 +1,6 @@
#pragma once
#define GDT_CODE (3<<11)
#define GDT_DPL(lvl) ((lvl)<<13)
#define GDT_PRESENT (1<<15)
#define GDT_LONG (1<<21)

View File

@ -0,0 +1,8 @@
#pragma once
#define PAGE_PRESENT 0x001
#define PAGE_WRITE 0x002
#define PAGE_HUGE 0x080
#define PAGE_SIZE 0x1000
#define ENTRIES_PER_PT 512