Compare commits

...

3 Commits

Author SHA1 Message Date
64190b04cb Add initialize_cpu() 2022-11-05 20:27:48 -04:00
d7b12c7896 Run qemu with maximum supported host CPU features 2022-11-05 20:15:30 -04:00
11f922da33 Add write_cr0() 2022-11-05 19:58:10 -04:00
3 changed files with 20 additions and 1 deletions

View File

@ -159,7 +159,7 @@ task "run", desc: "Run HOS in QEMU" do
Dir.mktmpdir do |tmpdir|
img = hello_env.expand("^/HOS.img")
FileUtils.cp(img, tmpdir)
sh %W[qemu-system-x86_64 -bios OVMF.fd -drive file=#{tmpdir}/HOS.img,format=raw -device qemu-xhci -device usb-tablet]
sh %W[qemu-system-x86_64 -cpu max -bios OVMF.fd -drive file=#{tmpdir}/HOS.img,format=raw -device qemu-xhci -device usb-tablet]
end
end

View File

@ -155,6 +155,11 @@ ulong read_cr0()
return __asm!ulong("mov %cr0, %rax", "={rax}");
}
void write_cr0(ulong v)
{
__asm("mov $0, %cr0", "r", v);
}
ulong read_cr2()
{
return __asm!ulong("mov %cr2, %rax", "={rax}");

View File

@ -33,12 +33,26 @@ private __gshared HulkHeader hulk_header = {
HULK_VIRTUAL_FRAMEBUFFER_ADDRESS, /* virt_fb_buffer */
};
private void initialize_cpu()
{
/* 1. Enable SSE. */
/* 1.a. Turn off CR0.EM and turn on CR0.MP. */
write_cr0((read_cr0() & ~CR0_EM) | CR0_MP);
/* 1.b. Set CR4.OSFXSR and CR4.OSXMMEXCPT. */
write_cr4(read_cr4() | CR4_OSFXSR | CR4_OSXMMEXCPT);
/* 2. Enable OSXSAVE. */
// write_cr4(read_cr4() | CR4_OSXSAVE);
/* 3. Enable AVX. */
// xsetbv(0u, xgetbv(0u) | XCR0_X87 | XCR0_SSE | XCR0_AVX);
}
/**
* HULK entry point.
*/
void hulk_start()
{
cli();
initialize_cpu();
gdt.initialize();
idt.initialize();
fb.initialize(cast(uint *)HULK_VIRTUAL_FRAMEBUFFER_ADDRESS, hulk_header.bootinfo.fb.width, hulk_header.bootinfo.fb.height, hulk_header.bootinfo.fb.stride);