misc: Bug fixes

This commit is contained in:
mintsuki 2021-08-20 18:28:51 +02:00
parent 1dbc6e3907
commit f9fe2f96ed
6 changed files with 25 additions and 40 deletions

View File

@ -129,14 +129,13 @@ bool efi_exit_boot_services(void) {
EFI_MEMORY_DESCRIPTOR *entry = (void *)efi_mmap + i * efi_desc_size; EFI_MEMORY_DESCRIPTOR *entry = (void *)efi_mmap + i * efi_desc_size;
uint64_t base = entry->PhysicalStart; uint64_t base = entry->PhysicalStart;
uint64_t length = entry->NumberOfPages * 4096;
// Find for a match in the untouched memory map // Find for a match in the untouched memory map
for (size_t j = 0; j < untouched_memmap_entries; j++) { for (size_t j = 0; j < untouched_memmap_entries; j++) {
if (untouched_memmap[j].type != MEMMAP_USABLE) if (untouched_memmap[j].type != MEMMAP_USABLE)
continue; continue;
if (untouched_memmap[j].base == base && untouched_memmap[j].length == length) { if (untouched_memmap[j].base == base) {
// It's a match! // It's a match!
entry->Type = EfiConventionalMemory; entry->Type = EfiConventionalMemory;
break; break;

View File

@ -121,11 +121,11 @@ void vprint(const char *fmt, va_list args) {
// Init com1 // Init com1
outb(0x3F8 + 1, 0x00); outb(0x3F8 + 1, 0x00);
outb(0x3F8 + 3, 0x80); outb(0x3F8 + 3, 0x80);
outb(0x3F8 + 0, 0x01); outb(0x3F8 + 0, 0x0c); // 9600 baud
outb(0x3F8 + 1, 0x00); outb(0x3F8 + 1, 0x00);
outb(0x3F8 + 3, 0x03); outb(0x3F8 + 3, 0x03);
outb(0x3F8 + 2, 0xC7); outb(0x3F8 + 2, 0xc7);
outb(0x3F8 + 4, 0x0B); outb(0x3F8 + 4, 0x0b);
com_initialised = true; com_initialised = true;
} }
@ -191,8 +191,11 @@ out:
outb(0xe9, print_buf[i]); outb(0xe9, print_buf[i]);
} }
if (COM_OUTPUT) { if (COM_OUTPUT) {
if (print_buf[i] == '\n') if (print_buf[i] == '\n') {
while ((inb(0x3f8 + 5) & 0x20) == 0);
outb(0x3f8, '\r'); outb(0x3f8, '\r');
}
while ((inb(0x3f8 + 5) & 0x20) == 0);
outb(0x3f8, print_buf[i]); outb(0x3f8, print_buf[i]);
} }
} }

View File

@ -376,33 +376,18 @@ void pmm_reclaim_uefi_mem(void) {
} }
struct e820_entry_t recl; struct e820_entry_t recl;
size_t efi_mmap_recl_begin;
size_t efi_mmap_entry_count = efi_mmap_size / efi_desc_size;
for (size_t i = 0; ; i++) { for (size_t i = 0; ; i++) {
if (memmap[i].type != MEMMAP_EFI_RECLAIMABLE) if (memmap[i].type == MEMMAP_EFI_RECLAIMABLE) {
continue;
recl = memmap[i]; recl = memmap[i];
// Go through EFI memmap and find an entry that starts at our base
for (efi_mmap_recl_begin = 0;
efi_mmap_recl_begin < efi_mmap_entry_count; efi_mmap_recl_begin++) {
EFI_MEMORY_DESCRIPTOR *entry =
(void *)efi_mmap + efi_mmap_recl_begin * efi_desc_size;
if (entry->PhysicalStart != memmap[i].base)
continue;
break; break;
} }
break;
} }
// Punch holes in our EFI reclaimable entry for every EFI area which is // Punch holes in our EFI reclaimable entry for every EFI area which is
// boot services or conventional that fits within // boot services or conventional that fits within
for (size_t i = efi_mmap_recl_begin; i < efi_mmap_entry_count; i++) { size_t efi_mmap_entry_count = efi_mmap_size / efi_desc_size;
for (size_t i = 0; i < efi_mmap_entry_count; i++) {
EFI_MEMORY_DESCRIPTOR *entry = (void *)efi_mmap + i * efi_desc_size; EFI_MEMORY_DESCRIPTOR *entry = (void *)efi_mmap + i * efi_desc_size;
uintptr_t base = recl.base; uintptr_t base = recl.base;
@ -426,14 +411,13 @@ void pmm_reclaim_uefi_mem(void) {
efi_top = top; efi_top = top;
} }
// Sanity check
if (!(efi_base >= base && efi_base < top if (!(efi_base >= base && efi_base < top
&& efi_top > base && efi_top <= top)) && efi_top > base && efi_top <= top))
continue; continue;
uint32_t our_type; uint32_t our_type;
switch (entry->Type) { switch (entry->Type) {
default:
our_type = MEMMAP_RESERVED; break;
case EfiBootServicesCode: case EfiBootServicesCode:
case EfiBootServicesData: case EfiBootServicesData:
case EfiConventionalMemory: case EfiConventionalMemory:
@ -442,6 +426,8 @@ void pmm_reclaim_uefi_mem(void) {
our_type = MEMMAP_ACPI_RECLAIMABLE; break; our_type = MEMMAP_ACPI_RECLAIMABLE; break;
case EfiACPIMemoryNVS: case EfiACPIMemoryNVS:
our_type = MEMMAP_ACPI_NVS; break; our_type = MEMMAP_ACPI_NVS; break;
default:
our_type = MEMMAP_RESERVED; break;
} }
memmap_alloc_range(efi_base, efi_size, our_type, false, true, false, true); memmap_alloc_range(efi_base, efi_size, our_type, false, true, false, true);

View File

@ -33,8 +33,9 @@ __attribute__((noreturn)) void linux_spinup(void *entry, void *boot_params) {
"pushl $0x10\n\t" "pushl $0x10\n\t"
"call 1f\n\t" "call 1f\n\t"
"1:\n\t" "1:\n\t"
"addl $5, (%%esp)\n\t" "addl $2f-1b, (%%esp)\n\t"
"lret\n\t" "lret\n\t"
"2:\n\t"
"movl $0x18, %%eax\n\t" "movl $0x18, %%eax\n\t"
"movl %%eax, %%ds\n\t" "movl %%eax, %%ds\n\t"

View File

@ -498,7 +498,8 @@ void linux_load(char *config, char *cmdline) {
if (!fb_init(&fbinfo, req_width, req_height, req_bpp)) if (!fb_init(&fbinfo, req_width, req_height, req_bpp))
panic("linux: Unable to set video mode"); panic("linux: Unable to set video mode");
screen_info->capabilities = VIDEO_CAPABILITY_64BIT_BASE; screen_info->capabilities = VIDEO_CAPABILITY_64BIT_BASE | VIDEO_CAPABILITY_SKIP_QUIRKS;
screen_info->flags = VIDEO_FLAGS_NOCURSOR;
screen_info->lfb_base = (uint32_t)fbinfo.framebuffer_addr; screen_info->lfb_base = (uint32_t)fbinfo.framebuffer_addr;
screen_info->ext_lfb_base = (uint32_t)(fbinfo.framebuffer_addr >> 32); screen_info->ext_lfb_base = (uint32_t)(fbinfo.framebuffer_addr >> 32);
screen_info->lfb_size = fbinfo.framebuffer_pitch * fbinfo.framebuffer_height; screen_info->lfb_size = fbinfo.framebuffer_pitch * fbinfo.framebuffer_height;
@ -537,15 +538,11 @@ void linux_load(char *config, char *cmdline) {
#if uefi == 1 #if uefi == 1
efi_exit_boot_services(); efi_exit_boot_services();
{
const char *efi_signature;
#if defined (__i386__) #if defined (__i386__)
efi_signature = "EL32"; memcpy(&boot_params->efi_info.efi_loader_signature, "EL32", 4);
#elif defined (__x86_64__) #elif defined (__x86_64__)
efi_signature = "EL64"; memcpy(&boot_params->efi_info.efi_loader_signature, "EL64", 4);
#endif #endif
memcpy(&boot_params->efi_info.efi_loader_signature, efi_signature, 4);
}
boot_params->efi_info.efi_systab = (uint32_t)(uint64_t)(uintptr_t)gST; boot_params->efi_info.efi_systab = (uint32_t)(uint64_t)(uintptr_t)gST;
boot_params->efi_info.efi_systab_hi = (uint32_t)((uint64_t)(uintptr_t)gST >> 32); boot_params->efi_info.efi_systab_hi = (uint32_t)((uint64_t)(uintptr_t)gST >> 32);

View File

@ -8,13 +8,12 @@ __attribute__((noreturn)) void multiboot1_spinup_32(
asm volatile ( asm volatile (
"cld\n\t" "cld\n\t"
"pushfl\n\t"
"pushl $0x18\n\t" "pushl $0x18\n\t"
"pushl %%edi\n\t" "pushl %%edi\n\t"
"movl $0x2BADB002, %%eax\n\t" "movl $0x2BADB002, %%eax\n\t"
"iretl\n\t" "lret\n\t"
: :
: "D" (entry_point), : "D" (entry_point),
"b" (multiboot1_info) "b" (multiboot1_info)