From 35284962d181ed99f38d8201472d65e3aed96e19 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 24 Jul 2009 21:49:26 -0400 Subject: [PATCH] When enabling write access to 0xf0000, just copy from 0xffff0000. Instead of copying the bios to temp space and then copying back to 0xf0000, just copy from the permanent location at 0xffff0000. This should make startup slightly faster. --- TODO | 3 +-- src/config.h | 2 -- src/shadow.c | 32 ++++++++++++++++---------------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/TODO b/TODO index 0fa1663..45ffe1d 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,5 @@ Enhance shadow support: Write-enable c, d, e segments; write protect -option roms before boot. When copying bios - just copy from high -memory. +option roms before boot. Replace hand-rolled memory allocation code with new malloc_fseg() and malloc_high() functions. diff --git a/src/config.h b/src/config.h index a77fe0c..cba7ac4 100644 --- a/src/config.h +++ b/src/config.h @@ -114,8 +114,6 @@ #define BUILD_AP_BOOT_ADDR 0x10000 #define BUILD_BIOS_ADDR 0xf0000 #define BUILD_BIOS_SIZE 0x10000 -// 64 KB used to copy the BIOS to shadow RAM -#define BUILD_BIOS_TMP_ADDR 0x30000 #define BUILD_APIC_ADDR 0xfee00000 #define BUILD_IOAPIC_ADDR 0xfec00000 diff --git a/src/shadow.c b/src/shadow.c index 264656d..1c389f4 100644 --- a/src/shadow.c +++ b/src/shadow.c @@ -18,15 +18,15 @@ (__addr - __start < __size); \ }) +// On the emulators, the bios at 0xf0000 is also at 0xffff0000 +#define BIOS_SRC_ADDR 0xffff0000 + // Enable shadowing and copy bios. static void -copy_bios(u16 bdf) +copy_bios(u16 bdf, int reg) { - int v = pci_config_readb(bdf, 0x59); - v |= 0x30; - pci_config_writeb(bdf, 0x59, v); - memcpy((void *)BUILD_BIOS_ADDR, (void *)BUILD_BIOS_TMP_ADDR - , BUILD_BIOS_SIZE); + pci_config_writeb(bdf, 0x59, reg | 0x30); + memcpy((void*)BUILD_BIOS_ADDR, (void*)BIOS_SRC_ADDR, BUILD_BIOS_SIZE); } // Make the BIOS code segment area (0xf0000) writable. @@ -45,24 +45,24 @@ make_bios_writable() return; } - // Copy the bios to a temporary area. - memcpy((void *)BUILD_BIOS_TMP_ADDR, (void *)BUILD_BIOS_ADDR - , BUILD_BIOS_SIZE); + int reg = pci_config_readb(bdf, 0x59); + if (reg & 0x30) { + // Ram already present - just enable writes + pci_config_writeb(bdf, 0x59, reg | 0x30); + return; + } // Enable shadowing and copy bios. if (IN_RANGE((u32)copy_bios, BUILD_BIOS_ADDR, BUILD_BIOS_SIZE)) { // Jump to shadow enable function - use the copy in the // temporary storage area so that memory does not change under // the executing code. - u32 pos = (u32)copy_bios - BUILD_BIOS_ADDR + BUILD_BIOS_TMP_ADDR; - void (*func)(u16 bdf) = (void*)pos; - func(bdf); + u32 pos = (u32)copy_bios - BUILD_BIOS_ADDR + BIOS_SRC_ADDR; + void (*func)(u16 bdf, int reg) = (void*)pos; + func(bdf, reg); } else { - copy_bios(bdf); + copy_bios(bdf, reg); } - - // Clear the temporary area. - memset((void *)BUILD_BIOS_TMP_ADDR, 0, BUILD_BIOS_SIZE); } // Make the BIOS code segment area (0xf0000) read-only. -- 2.25.1