]> Joshua Wise's Git repositories - netwatch.git/blame - grubload/multiboot_c.c
cleanup
[netwatch.git] / grubload / multiboot_c.c
CommitLineData
9b8c947b 1#include "console.h"
60a917ef 2#include <io.h>
9b8c947b 3
c4a16564
JW
4extern char _binary_realmode_bin_start[];
5extern int _binary_realmode_bin_size;
6
9b8c947b 7struct mb_info
56553b73 8{
9b8c947b
JW
9 unsigned long flags;
10 unsigned long mem_lower, mem_upper;
11 unsigned long boot_dev;
12 char *cmdline;
13 unsigned long mod_cnt;
14 struct mod_info *mods;
15};
16
17struct mod_info
18{
19 void *mod_start;
20 void *mod_end;
21 char *mod_string;
22 void *reserved;
23};
24
25void c_start(unsigned int magic, struct mb_info *wee)
26{
7e16b8e6 27 unsigned short *grubptr = (unsigned short *)0x7CFE;
60a917ef 28 unsigned char smramc;
9b8c947b
JW
29 int i;
30
7e16b8e6 31 void (*realmode)() = (void (*)()) 0x4000;
c4a16564 32
9b8c947b
JW
33 puts("Magic is: ");
34 puthex(magic);
35 puts("\nMultiboot header is: ");
36 puthex(wee);
37 puts("\n");
38 show_cursor();
39
40 puts("Grubptr is: ");
41 puthex(*grubptr);
42 puts("\n");
d56898ee 43
44
9b8c947b
JW
45 for (i = 0; i < wee->mod_cnt; i++)
46 {
47 puts("Module:\n");
48 puts(" Start: "); puthex(wee->mods[i].mod_start); puts("\n");
49 puts(" Size: "); puthex(wee->mods[i].mod_end - wee->mods[i].mod_start); puts("\n");
50 puts(" Name: "); puts(wee->mods[i].mod_string); puts("\n");
51 }
c4a16564 52
60a917ef 53 if (wee->mod_cnt != 1)
d56898ee 54 {
60a917ef 55 puts("Expected exactly one module; cannot continue.\n");
d56898ee 56 while(1) asm("hlt");
57 }
58
60a917ef
JW
59 puts("Current USB state is: "); puthex(pci_read16(0, 31, 2, 0xC0)); puts(" "); puthex(pci_read16(0, 31, 4, 0xC0)); puts("\n");
60 puts("Current SMI state is: "); puthex(inl(0x830)); puts("\n");
61 puts("Current SMRAMC state is: "); puthex(pci_read8(0, 0, 0, 0x70)); puts("\n");
62
63 outl(0x830, inl(0x830) & ~0x2001); /* turn off SMIs */
64
65 /* Try really hard to shut up USB_LEGKEY. */
66 pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0));
67 pci_write16(0, 31, 2, 0xC0, 0);
68 pci_write16(0, 31, 4, 0xC0, pci_read16(0, 31, 4, 0xC0));
69 pci_write16(0, 31, 4, 0xC0, 0);
70 smramc = pci_read8(0, 0, 0, 0x70);
71 pci_write8(0, 0, 0, 0x70, (smramc & 0xF0) | 0x04);
d56898ee 72 load_elf(wee->mods[0].mod_start, wee->mods[0].mod_end - wee->mods[0].mod_start);
60a917ef
JW
73 pci_write8(0, 0, 0, 0x70, smramc);
74 outb(0x830, inb(0x830) | 0x41); /* turn on the SMIs we want */
75
76 puts("Waiting for a bit before returning to real mode...");
77 for (i=0; i<0x500000; i++)
78 {
79 if ((i % 0x100000) == 0)
80 puts(".");
81 inb(0x80);
82 }
83 puts("\n");
d56898ee 84
c4a16564
JW
85 puts("Now returning to real mode.\n");
86 memcpy(0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size);
86c89e89 87 realmode(); // goodbye!
56553b73 88}
This page took 0.036374 seconds and 4 git commands to generate.