]> Joshua Wise's Git repositories - netwatch.git/blame - grubload/multiboot_c.c
Fix the poller.
[netwatch.git] / grubload / multiboot_c.c
CommitLineData
9b8c947b 1#include "console.h"
f2da2cd3
JP
2#include "loader.h"
3
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{
e997a89b
JW
24 puts("PANIC: ");
25 puts(msg);
26 puts("\nSystem halted\n");
f2da2cd3 27 while(1) { __asm__("hlt"); }
e997a89b
JW
28}
29
ddf5629e
JW
30void dolog(char *s)
31{
32 /* little shim -- need to unify logging */
33 puts(s);
34}
35
e997a89b
JW
36void c_start(unsigned int magic, struct mb_info *mbinfo)
37{
38 struct mod_info *mods = mbinfo->mods;
f2da2cd3
JP
39 smram_state_t old_smramc;
40 struct info_section * info;
9b8c947b
JW
41 int i;
42
7e16b8e6 43 void (*realmode)() = (void (*)()) 0x4000;
c4a16564 44
9b8c947b 45 show_cursor();
81148fa1
JW
46 puts("NetWatch loader\n");
47
94d78d15 48 if (magic != MULTIBOOT_LOADER_MAGIC)
e997a89b 49 panic("Bootloader was not multiboot compliant; cannot continue.");
9b8c947b 50
e997a89b 51 for (i = 0; i < mbinfo->mod_cnt; i++)
9b8c947b 52 {
81148fa1 53 puts("Module found:\n");
f2da2cd3
JP
54 puts(" Start: "); puthex((unsigned long) mods[i].mod_start); puts("\n");
55 puts(" Size: "); puthex((unsigned long)mods[i].mod_end - (unsigned long)mods[i].mod_start); puts("\n");
c34aba05 56 puts(" Name: "); puts(mods[i].mod_string); puts("\n");
9b8c947b 57 }
c4a16564 58
e997a89b
JW
59 if (mbinfo->mod_cnt != 1)
60 panic("Expected exactly one module; cannot continue.");
d56898ee 61
60a917ef
JW
62 puts("Current USB state is: "); puthex(pci_read16(0, 31, 2, 0xC0)); puts(" "); puthex(pci_read16(0, 31, 4, 0xC0)); puts("\n");
63 puts("Current SMI state is: "); puthex(inl(0x830)); puts("\n");
64 puts("Current SMRAMC state is: "); puthex(pci_read8(0, 0, 0, 0x70)); puts("\n");
65
85bc8ca6 66 smi_disable();
60a917ef
JW
67
68 /* Try really hard to shut up USB_LEGKEY. */
69 pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0));
70 pci_write16(0, 31, 2, 0xC0, 0);
71 pci_write16(0, 31, 4, 0xC0, pci_read16(0, 31, 4, 0xC0));
72 pci_write16(0, 31, 4, 0xC0, 0);
c34aba05 73
c34aba05 74 /* Open the SMRAM aperture and load our ELF. */
f2da2cd3 75 old_smramc = smram_save_state();
c34aba05
JP
76
77 if (smram_aseg_set_state(SMRAM_ASEG_OPEN) != 0)
e997a89b
JW
78 panic("Opening SMRAM failed; cannot load ELF.");
79
f2da2cd3 80 load_elf(mods[0].mod_start, (unsigned long)mods[0].mod_end - (unsigned long)mods[0].mod_start);
e997a89b 81
f2da2cd3 82 info = (struct info_section *)0x10000;
e997a89b 83 if (info->signature != INFO_SIGNATURE)
c34aba05 84 {
e997a89b
JW
85 smram_restore_state(old_smramc); /* Restore so that video ram is touchable again. */
86 panic("Info section signature mismatch.");
c34aba05
JP
87 }
88
e997a89b
JW
89 info->firstrun();
90 smram_restore_state(old_smramc);
91
60a917ef
JW
92 puts("Waiting for a bit before returning to real mode...");
93 for (i=0; i<0x500000; i++)
94 {
95 if ((i % 0x100000) == 0)
96 puts(".");
97 inb(0x80);
98 }
99 puts("\n");
d56898ee 100
c4a16564 101 puts("Now returning to real mode.\n");
f2da2cd3 102 memcpy((void *)0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size);
86c89e89 103 realmode(); // goodbye!
56553b73 104}
This page took 0.035275 seconds and 4 git commands to generate.