]>
Commit | Line | Data |
---|---|---|
9b8c947b | 1 | #include "console.h" |
60a917ef | 2 | #include <io.h> |
9b8c947b | 3 | |
c4a16564 JW |
4 | extern char _binary_realmode_bin_start[]; |
5 | extern int _binary_realmode_bin_size; | |
6 | ||
9b8c947b | 7 | struct 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 | ||
17 | struct mod_info | |
18 | { | |
19 | void *mod_start; | |
20 | void *mod_end; | |
21 | char *mod_string; | |
22 | void *reserved; | |
23 | }; | |
24 | ||
25 | void 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 | 33 | show_cursor(); |
81148fa1 JW |
34 | puts("NetWatch loader\n"); |
35 | ||
36 | if (magic != 0x2BADB002) | |
37 | { | |
38 | puts("Bootloader was not multiboot compliant; cannot continue.\n"); | |
39 | while(1) asm("hlt"); | |
40 | } | |
9b8c947b | 41 | |
9b8c947b JW |
42 | for (i = 0; i < wee->mod_cnt; i++) |
43 | { | |
81148fa1 | 44 | puts("Module found:\n"); |
9b8c947b JW |
45 | puts(" Start: "); puthex(wee->mods[i].mod_start); puts("\n"); |
46 | puts(" Size: "); puthex(wee->mods[i].mod_end - wee->mods[i].mod_start); puts("\n"); | |
47 | puts(" Name: "); puts(wee->mods[i].mod_string); puts("\n"); | |
48 | } | |
c4a16564 | 49 | |
60a917ef | 50 | if (wee->mod_cnt != 1) |
d56898ee | 51 | { |
60a917ef | 52 | puts("Expected exactly one module; cannot continue.\n"); |
d56898ee | 53 | while(1) asm("hlt"); |
54 | } | |
55 | ||
60a917ef JW |
56 | puts("Current USB state is: "); puthex(pci_read16(0, 31, 2, 0xC0)); puts(" "); puthex(pci_read16(0, 31, 4, 0xC0)); puts("\n"); |
57 | puts("Current SMI state is: "); puthex(inl(0x830)); puts("\n"); | |
58 | puts("Current SMRAMC state is: "); puthex(pci_read8(0, 0, 0, 0x70)); puts("\n"); | |
59 | ||
81148fa1 | 60 | outl(0x830, inl(0x830) & ~0x1); /* turn off SMIs */ |
60a917ef JW |
61 | |
62 | /* Try really hard to shut up USB_LEGKEY. */ | |
63 | pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0)); | |
64 | pci_write16(0, 31, 2, 0xC0, 0); | |
65 | pci_write16(0, 31, 4, 0xC0, pci_read16(0, 31, 4, 0xC0)); | |
66 | pci_write16(0, 31, 4, 0xC0, 0); | |
67 | smramc = pci_read8(0, 0, 0, 0x70); | |
68 | pci_write8(0, 0, 0, 0x70, (smramc & 0xF0) | 0x04); | |
d56898ee | 69 | load_elf(wee->mods[0].mod_start, wee->mods[0].mod_end - wee->mods[0].mod_start); |
60a917ef JW |
70 | pci_write8(0, 0, 0, 0x70, smramc); |
71 | outb(0x830, inb(0x830) | 0x41); /* turn on the SMIs we want */ | |
72 | ||
73 | puts("Waiting for a bit before returning to real mode..."); | |
74 | for (i=0; i<0x500000; i++) | |
75 | { | |
76 | if ((i % 0x100000) == 0) | |
77 | puts("."); | |
78 | inb(0x80); | |
79 | } | |
80 | puts("\n"); | |
d56898ee | 81 | |
c4a16564 JW |
82 | puts("Now returning to real mode.\n"); |
83 | memcpy(0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size); | |
86c89e89 | 84 | realmode(); // goodbye! |
56553b73 | 85 | } |