So kernel 64 can set up itself now. (Requires 1GB page size. But just for temporary setup, in the kernel we will still stick to 4KB page.)
This commit is contained in:
parent
57b0f4a8f1
commit
56375a5253
|
@ -19,7 +19,11 @@ ata2: enabled=0
|
|||
ata3: enabled=0
|
||||
pci: enabled=1, chipset=i440fx
|
||||
vga: extension=vbe, update_freq=5
|
||||
cpu: count=1, ips=4000000, model=corei7_sandy_bridge_2600k, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
|
||||
cpu: count=1, ips=4000000, model=bx_generic, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
|
||||
cpuid: level=6, stepping=3, model=3, family=6, vendor_string="GenuineIntel", brand_string=" Intel(R) Pentium(R) 4 CPU "
|
||||
cpuid: mmx=1, apic=xapic, simd=sse2, sse4a=0, misaligned_sse=0, sep=1, movbe=0, adx=0
|
||||
cpuid: aes=0, sha=0, xsave=0, xsaveopt=0, x86_64=1, 1g_pages=1, pcid=0, fsgsbase=1
|
||||
cpuid: smep=0, smap=0, mwait=1, vmx=1
|
||||
print_timestamps: enabled=0
|
||||
port_e9_hack: enabled=0
|
||||
private_colormap: enabled=0
|
||||
|
|
|
@ -5,8 +5,8 @@ display_library: win32, options="gui_debug"
|
|||
memory: host=256, guest=256
|
||||
romimage: file="bochs/BIOS-bochs-latest"
|
||||
vgaromimage: file="bochs/VGABIOS-lgpl-latest"
|
||||
|
||||
boot: cdrom
|
||||
magic_break: enabled=1
|
||||
floppy_bootsig_check: disabled=0
|
||||
# no floppya
|
||||
# no floppyb
|
||||
|
@ -20,12 +20,15 @@ ata2: enabled=0
|
|||
ata3: enabled=0
|
||||
pci: enabled=1, chipset=i440fx
|
||||
vga: extension=vbe, update_freq=5
|
||||
cpu: count=1, ips=4000000, model=corei7_sandy_bridge_2600k, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
|
||||
cpu: count=1, ips=4000000, model=bx_generic, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
|
||||
cpuid: level=6, stepping=3, model=3, family=6, vendor_string="GenuineIntel", brand_string=" Intel(R) Pentium(R) 4 CPU "
|
||||
cpuid: mmx=1, apic=xapic, simd=sse2, sse4a=0, misaligned_sse=0, sep=1, movbe=0, adx=0
|
||||
cpuid: aes=0, sha=0, xsave=0, xsaveopt=0, x86_64=1, 1g_pages=1, pcid=0, fsgsbase=1
|
||||
cpuid: smep=0, smap=0, mwait=1, vmx=1
|
||||
print_timestamps: enabled=0
|
||||
port_e9_hack: enabled=0
|
||||
private_colormap: enabled=0
|
||||
clock: sync=none, time0=local, rtc_sync=0
|
||||
magic_break: enabled=1
|
||||
# no cmosimage
|
||||
# no loader
|
||||
log: -
|
||||
|
|
|
@ -22,25 +22,25 @@ times 512 dq 0 ;reserved the rest for page entries
|
|||
|
||||
|
||||
GDT64: ; Global Descriptor Table (64-bit).
|
||||
.NULL: equ $ - GDT64 ; The null descriptor.
|
||||
; NULL
|
||||
dw 0 ; Limit (low).
|
||||
dw 0 ; Base (low).
|
||||
db 0 ; Base (middle)
|
||||
db 0 ; Access.
|
||||
db 0 ; Granularity.
|
||||
db 0 ; Base (high).
|
||||
.CODE: equ $ - GDT64 ; The code descriptor.
|
||||
SLCT_CODE equ $ - GDT64 ; The code descriptor.
|
||||
dw 0 ; Limit (low).
|
||||
dw 0 ; Base (low).
|
||||
db 0 ; Base (middle)
|
||||
db 10011000b ; Access.
|
||||
db 10011010b ; Access.
|
||||
db 00100000b ; Granularity.
|
||||
db 0 ; Base (high).
|
||||
.DATA: equ $ - GDT64 ; The data descriptor.
|
||||
SLCT_DATA equ $ - GDT64 ; The data descriptor.
|
||||
dw 0 ; Limit (low).
|
||||
dw 0 ; Base (low).
|
||||
db 0 ; Base (middle)
|
||||
db 10010000b ; Access.
|
||||
db 10010010b ; Access.
|
||||
db 00000000b ; Granularity.
|
||||
db 0 ; Base (high).
|
||||
.GDT64_PTR: ; The GDT-pointer.
|
||||
|
@ -54,9 +54,6 @@ mov eax, cr0 ; Set the A-register to control r
|
|||
and eax, 01111111111111111111111111111111b ; Clear the PG-bit, which is bit 31.
|
||||
mov cr0, eax ; Set control register 0 to the A-register.
|
||||
|
||||
;pure magic
|
||||
xchg bx,bx
|
||||
|
||||
; write values for pml4
|
||||
mov eax,PML4_BASE
|
||||
mov dword [eax], PDPT_BASE + 3
|
||||
|
@ -101,14 +98,14 @@ or eax, 1 << 31 ; Set the PG-bit, which is bit 31
|
|||
mov cr0, eax ; Set control register 0 to the A-register.
|
||||
|
||||
; enter x64
|
||||
;lgdt [GDT64.GDT64_PTR]
|
||||
jmp GDT64.CODE:entry
|
||||
lgdt [GDT64.GDT64_PTR]
|
||||
jmp SLCT_CODE:entry
|
||||
|
||||
[SECTION .text]
|
||||
[BITS 64]
|
||||
entry:
|
||||
cli
|
||||
mov ax,GDT64.DATA
|
||||
mov ax,SLCT_DATA
|
||||
mov ds,ax
|
||||
mov es,ax
|
||||
mov fs,ax
|
||||
|
|
|
@ -3,14 +3,31 @@
|
|||
#include "print.h"
|
||||
#include "mem.h"
|
||||
#include "multiboot.h"
|
||||
#include "../../../x86/src/c/print.h"
|
||||
|
||||
uint8_t g_gdt[8*9];
|
||||
gdt_ptr_t g_gdt_ptr;
|
||||
extern uint64_t text_pos;
|
||||
extern void HLT_CPU(void);
|
||||
extern void BOCHS_MAGIC_BREAKPOINT();
|
||||
void HYPKERNEL64 hk_main(void)
|
||||
extern void HYPKERNEL64 HLT_CPU(void);
|
||||
extern void HYPKERNEL64 BOCHS_MAGIC_BREAKPOINT();
|
||||
extern void HYPKERNEL64 hk_flush_gdt(gdt_ptr_t* gdt_ptr, uint64_t code_slct, uint64_t data_slct);
|
||||
void HYPKERNEL64 hk_main(multiboot_info_t* multiboot_info)
|
||||
{
|
||||
hk_clear_screen();
|
||||
hk_printf("Welcome to HYP OS. Kernel is now running in x64 mode.\n");
|
||||
text_pos = 0;
|
||||
hk_printf("Kernel is now running in x64 mode. Multiboot info is located at %X.\n\n", (uint64_t)multiboot_info);
|
||||
hk_printf("*Setting up GDT...");
|
||||
hk_write_segment_descriptor((void*)&g_gdt[0], 0, 0, 0);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[8], 0, 0, SEG_DPL_0 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_CODE_X);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[16], 0, 0, SEG_DPL_0 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_DATA_RW);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[24], 0, 0, SEG_DPL_3 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_CODE_X);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[32], 0, 0, SEG_DPL_3 | SEG_CODE_DATA | SEG_PRESENT | SEG_LONG | SEG_TYPE_DATA_RW);
|
||||
|
||||
hk_write_segment_descriptor((void*)&g_gdt[40], 0, 0xFFFFF, SEG_DPL_0 | SEG_GRANULARITY | SEG_CODE_DATA | SEG_PRESENT | SEG_32_BITS | SEG_TYPE_CODE_X);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[48], 0, 0xFFFFF, SEG_DPL_0 | SEG_GRANULARITY | SEG_CODE_DATA | SEG_PRESENT | SEG_32_BITS | SEG_TYPE_DATA_RW);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[56], 0, 0xFFFFF, SEG_DPL_3 | SEG_GRANULARITY | SEG_CODE_DATA | SEG_PRESENT | SEG_32_BITS | SEG_TYPE_CODE_X);
|
||||
hk_write_segment_descriptor((void*)&g_gdt[64], 0, 0xFFFFF, SEG_DPL_3 | SEG_GRANULARITY | SEG_CODE_DATA | SEG_PRESENT | SEG_32_BITS | SEG_TYPE_DATA_RW);
|
||||
|
||||
g_gdt_ptr.base = (uint64_t)g_gdt;
|
||||
g_gdt_ptr.limit = 8*9-1;
|
||||
hk_flush_gdt(&g_gdt_ptr, SEG_SELECTOR(1, 0), SEG_SELECTOR(2, 0));
|
||||
hk_printf("Done.\n\n");
|
||||
HLT_CPU();
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ hk_init_x64:
|
|||
push ebp
|
||||
mov ebp,esp
|
||||
cli
|
||||
xchg bx,bx
|
||||
mov edi,[ss:ebp+8] ;System V ABI
|
||||
jmp 0x100000 ;hard-coded
|
||||
mov esp,ebp
|
||||
|
|
Loading…
Reference in New Issue