]> Joshua Wise's Git repositories - netwatch.git/blame_incremental - grubload/multiboot_c.c
cleanup
[netwatch.git] / grubload / multiboot_c.c
... / ...
CommitLineData
1#include "console.h"
2#include <io.h>
3
4extern char _binary_realmode_bin_start[];
5extern int _binary_realmode_bin_size;
6
7struct mb_info
8{
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{
27 unsigned short *grubptr = (unsigned short *)0x7CFE;
28 unsigned char smramc;
29 int i;
30
31 void (*realmode)() = (void (*)()) 0x4000;
32
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");
43
44
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 }
52
53 if (wee->mod_cnt != 1)
54 {
55 puts("Expected exactly one module; cannot continue.\n");
56 while(1) asm("hlt");
57 }
58
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);
72 load_elf(wee->mods[0].mod_start, wee->mods[0].mod_end - wee->mods[0].mod_start);
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");
84
85 puts("Now returning to real mode.\n");
86 memcpy(0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size);
87 realmode(); // goodbye!
88}
This page took 0.026817 seconds and 4 git commands to generate.