summaryrefslogtreecommitdiff
path: root/src/post.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2010-09-15 21:59:11 -0400
committerKevin O'Connor <kevin@koconnor.net>2010-09-15 21:59:11 -0400
commit025cabd2caa41d567d06a7c43f910621b99e64a4 (patch)
treeeef5f95b114ff82731e54a34973bf6952c541fb8 /src/post.c
parent12fa24aa5bd47a670e50c3a117693e7522d45c4f (diff)
Move init code from _start() to post().
Move the shadow calls from _start() to post() - this ensures all the one time init code is in post(). Also, reorg post so that malloc setup is done before ivt/bda/ebda setup. This is in preparation for relocating the 32bit flat init code.
Diffstat (limited to 'src/post.c')
-rw-r--r--src/post.c91
1 files changed, 60 insertions, 31 deletions
diff --git a/src/post.c b/src/post.c
index f1ab6be..4d99935 100644
--- a/src/post.c
+++ b/src/post.c
@@ -25,6 +25,11 @@
#include "ps2port.h" // ps2port_setup
#include "virtio-blk.h" // virtio_blk_setup
+
+/****************************************************************
+ * BIOS init
+ ****************************************************************/
+
static void
init_ivt(void)
{
@@ -77,13 +82,16 @@ init_bda(void)
int esize = EBDA_SIZE_START;
SET_BDA(mem_size_kb, BUILD_LOWRAM_END/1024 - esize);
- u16 eseg = EBDA_SEGMENT_START;
- SET_BDA(ebda_seg, eseg);
+ u16 ebda_seg = EBDA_SEGMENT_START;
+ SET_BDA(ebda_seg, ebda_seg);
// Init ebda
struct extended_bios_data_area_s *ebda = get_ebda_ptr();
memset(ebda, 0, sizeof(*ebda));
ebda->size = esize;
+
+ add_e820((u32)MAKE_FLATPTR(ebda_seg, 0), GET_EBDA2(ebda_seg, size) * 1024
+ , E820_RESERVED);
}
static void
@@ -120,9 +128,6 @@ ram_probe(void)
add_e820(BUILD_LOWRAM_END, BUILD_BIOS_ADDR-BUILD_LOWRAM_END, E820_HOLE);
// Mark known areas as reserved.
- u16 ebda_seg = get_ebda_seg();
- add_e820((u32)MAKE_FLATPTR(ebda_seg, 0), GET_EBDA2(ebda_seg, size) * 1024
- , E820_RESERVED);
add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
u32 count = qemu_cfg_e820_entries();
@@ -177,20 +182,30 @@ init_hw(void)
virtio_blk_setup();
}
+// Begin the boot process by invoking an int0x19 in 16bit mode.
+static void
+startBoot(void)
+{
+ // Clear low-memory allocations (required by PMM spec).
+ memset((void*)BUILD_STACK_ADDR, 0, BUILD_EBDA_MINIMUM - BUILD_STACK_ADDR);
+
+ dprintf(3, "Jump to int19\n");
+ struct bregs br;
+ memset(&br, 0, sizeof(br));
+ br.flags = F_IF;
+ call16_int(0x19, &br);
+}
+
// Main setup code.
-void VISIBLE32INIT
-post(void)
+static void
+maininit(void)
{
- // Detect and init ram.
+ // Setup ivt/bda/ebda
init_ivt();
init_bda();
- memmap_setup();
- qemu_cfg_port_probe();
- ram_probe();
- malloc_setup();
- thread_setup();
// Init base pc hardware.
+ thread_setup();
pic_setup();
timer_setup();
mathcp_setup();
@@ -242,10 +257,42 @@ post(void)
pmm_finalize();
malloc_finalize();
memmap_finalize();
+
+ // Setup bios checksum.
+ BiosChecksum -= checksum((u8*)BUILD_BIOS_ADDR, BUILD_BIOS_SIZE);
+
+ // Write protect bios memory.
+ make_bios_readonly();
+
+ // Invoke int 19 to start boot process.
+ startBoot();
}
static int HaveRunPost;
+// Start of Power On Self Test (POST) - the BIOS initilization phase.
+void VISIBLE32INIT
+post(void)
+{
+ // Allow writes to modify bios area (0xf0000)
+ make_bios_writable();
+
+ HaveRunPost = 1;
+
+ // Detect ram and setup internal malloc.
+ memmap_setup();
+ qemu_cfg_port_probe();
+ ram_probe();
+ malloc_setup();
+
+ maininit();
+}
+
+
+/****************************************************************
+ * POST entry point
+ ****************************************************************/
+
// Attempt to invoke a hard-reboot.
static void
tryReboot(void)
@@ -284,24 +331,6 @@ _start(void)
// This is a soft reboot - invoke a hard reboot.
tryReboot();
- // Allow writes to modify bios area (0xf0000)
- make_bios_writable();
-
- HaveRunPost = 1;
-
// Perform main setup code.
post();
-
- // Setup bios checksum.
- BiosChecksum -= checksum((u8*)BUILD_BIOS_ADDR, BUILD_BIOS_SIZE);
-
- // Write protect bios memory.
- make_bios_readonly();
-
- // Invoke int 19 to start boot process.
- dprintf(3, "Jump to int19\n");
- struct bregs br;
- memset(&br, 0, sizeof(br));
- br.flags = F_IF;
- call16_int(0x19, &br);
}