]> Joshua Wise's Git repositories - netwatch.git/blame - grubload/multiboot_c.c
Fix vga-overlay so that it doesn't cause disasters when it does an immediate-flush...
[netwatch.git] / grubload / multiboot_c.c
CommitLineData
9b8c947b 1#include "console.h"
f2da2cd3 2#include "loader.h"
efea5b4e 3#include <output.h>
85bc8ca6 4#include <minilib.h>
60a917ef 5#include <io.h>
c34aba05 6#include <smram.h>
94d78d15 7#include <multiboot.h>
85bc8ca6 8#include <smi.h>
f2da2cd3 9#include <pci.h>
9b8c947b 10
e5d94488
JP
11#define INFO_SIGNATURE 0x5754454E
12
c4a16564
JW
13extern char _binary_realmode_bin_start[];
14extern int _binary_realmode_bin_size;
15
e5d94488
JP
16struct info_section
17{
18 unsigned int signature;
19 void (*firstrun)();
20};
21
e997a89b 22void panic(const char *msg)
9b8c947b 23{
efea5b4e 24 outputf("PANIC: %s\nSystem halted\n", msg);
f2da2cd3 25 while(1) { __asm__("hlt"); }
e997a89b
JW
26}
27
28void c_start(unsigned int magic, struct mb_info *mbinfo)
29{
30 struct mod_info *mods = mbinfo->mods;
f2da2cd3
JP
31 smram_state_t old_smramc;
32 struct info_section * info;
9b8c947b
JW
33 int i;
34
7e16b8e6 35 void (*realmode)() = (void (*)()) 0x4000;
c4a16564 36
9b8c947b 37 show_cursor();
efea5b4e 38 outputf("NetWatch loader");
81148fa1 39
94d78d15 40 if (magic != MULTIBOOT_LOADER_MAGIC)
e997a89b 41 panic("Bootloader was not multiboot compliant; cannot continue.");
9b8c947b 42
e997a89b 43 for (i = 0; i < mbinfo->mod_cnt; i++)
9b8c947b 44 {
efea5b4e
JW
45 outputf("Module found:");
46 outputf(" Start: %08x", (unsigned long) mods[i].mod_start);
47 outputf(" Size: %08x", (unsigned long)mods[i].mod_end - (unsigned long)mods[i].mod_start);
48 outputf(" Name: %s", mods[i].mod_string);
9b8c947b 49 }
c4a16564 50
e997a89b
JW
51 if (mbinfo->mod_cnt != 1)
52 panic("Expected exactly one module; cannot continue.");
f2b87dd6 53 outputf("Current SMRAMC state is: %02x", pci_read8(0, 0, 0, 0x70));
efea5b4e
JW
54 outputf("Current USB state is: %04x %04x", pci_read16(0, 31, 2, 0xC0), pci_read16(0, 31, 4, 0xC0));
55 outputf("Current SMI state is: %08x", inl(0x830));
f2b87dd6 56
85bc8ca6 57 smi_disable();
60a917ef
JW
58
59 /* Try really hard to shut up USB_LEGKEY. */
60 pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0));
61 pci_write16(0, 31, 2, 0xC0, 0);
62 pci_write16(0, 31, 4, 0xC0, pci_read16(0, 31, 4, 0xC0));
63 pci_write16(0, 31, 4, 0xC0, 0);
83a02556
JW
64
65 pci_bus_enum();
c34aba05 66
c34aba05 67 /* Open the SMRAM aperture and load our ELF. */
f2da2cd3 68 old_smramc = smram_save_state();
c34aba05
JP
69
70 if (smram_aseg_set_state(SMRAM_ASEG_OPEN) != 0)
e997a89b
JW
71 panic("Opening SMRAM failed; cannot load ELF.");
72
f2da2cd3 73 load_elf(mods[0].mod_start, (unsigned long)mods[0].mod_end - (unsigned long)mods[0].mod_start);
e997a89b 74
f2da2cd3 75 info = (struct info_section *)0x10000;
e997a89b 76 if (info->signature != INFO_SIGNATURE)
c34aba05 77 {
e997a89b
JW
78 smram_restore_state(old_smramc); /* Restore so that video ram is touchable again. */
79 panic("Info section signature mismatch.");
c34aba05
JP
80 }
81
e997a89b
JW
82 info->firstrun();
83 smram_restore_state(old_smramc);
f2b87dd6
JW
84
85 outputf("New SMRAMC state is: %02x", pci_read8(0, 0, 0, 0x70));
e997a89b 86
60a917ef
JW
87 puts("Waiting for a bit before returning to real mode...");
88 for (i=0; i<0x500000; i++)
89 {
90 if ((i % 0x100000) == 0)
91 puts(".");
92 inb(0x80);
93 }
94 puts("\n");
d56898ee 95
efea5b4e 96 outputf("Now returning to real mode.");
f2da2cd3 97 memcpy((void *)0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size);
86c89e89 98 realmode(); // goodbye!
56553b73 99}
This page took 0.039003 seconds and 4 git commands to generate.