]>
Commit | Line | Data |
---|---|---|
9b8c947b | 1 | #include "console.h" |
60a917ef | 2 | #include <io.h> |
c34aba05 | 3 | #include <smram.h> |
9b8c947b | 4 | |
c4a16564 JW |
5 | extern char _binary_realmode_bin_start[]; |
6 | extern int _binary_realmode_bin_size; | |
7 | ||
9b8c947b | 8 | struct mb_info |
56553b73 | 9 | { |
9b8c947b JW |
10 | unsigned long flags; |
11 | unsigned long mem_lower, mem_upper; | |
12 | unsigned long boot_dev; | |
13 | char *cmdline; | |
14 | unsigned long mod_cnt; | |
15 | struct mod_info *mods; | |
16 | }; | |
17 | ||
18 | struct mod_info | |
19 | { | |
20 | void *mod_start; | |
21 | void *mod_end; | |
22 | char *mod_string; | |
23 | void *reserved; | |
24 | }; | |
25 | ||
c34aba05 | 26 | void c_start(unsigned int magic, struct mb_info *info) |
9b8c947b | 27 | { |
c34aba05 | 28 | struct mod_info *mods = mods; |
7e16b8e6 | 29 | unsigned short *grubptr = (unsigned short *)0x7CFE; |
60a917ef | 30 | unsigned char smramc; |
9b8c947b JW |
31 | int i; |
32 | ||
7e16b8e6 | 33 | void (*realmode)() = (void (*)()) 0x4000; |
c4a16564 | 34 | |
9b8c947b | 35 | show_cursor(); |
81148fa1 JW |
36 | puts("NetWatch loader\n"); |
37 | ||
38 | if (magic != 0x2BADB002) | |
39 | { | |
40 | puts("Bootloader was not multiboot compliant; cannot continue.\n"); | |
41 | while(1) asm("hlt"); | |
42 | } | |
9b8c947b | 43 | |
c34aba05 | 44 | for (i = 0; i < info->mod_cnt; i++) |
9b8c947b | 45 | { |
81148fa1 | 46 | puts("Module found:\n"); |
c34aba05 JP |
47 | puts(" Start: "); puthex(mods[i].mod_start); puts("\n"); |
48 | puts(" Size: "); puthex(mods[i].mod_end - mods[i].mod_start); puts("\n"); | |
49 | puts(" Name: "); puts(mods[i].mod_string); puts("\n"); | |
9b8c947b | 50 | } |
c4a16564 | 51 | |
c34aba05 | 52 | if (info->mod_cnt != 1) |
d56898ee | 53 | { |
60a917ef | 54 | puts("Expected exactly one module; cannot continue.\n"); |
d56898ee | 55 | while(1) asm("hlt"); |
56 | } | |
57 | ||
60a917ef JW |
58 | puts("Current USB state is: "); puthex(pci_read16(0, 31, 2, 0xC0)); puts(" "); puthex(pci_read16(0, 31, 4, 0xC0)); puts("\n"); |
59 | puts("Current SMI state is: "); puthex(inl(0x830)); puts("\n"); | |
60 | puts("Current SMRAMC state is: "); puthex(pci_read8(0, 0, 0, 0x70)); puts("\n"); | |
61 | ||
81148fa1 | 62 | outl(0x830, inl(0x830) & ~0x1); /* turn off SMIs */ |
60a917ef JW |
63 | |
64 | /* Try really hard to shut up USB_LEGKEY. */ | |
65 | pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0)); | |
66 | pci_write16(0, 31, 2, 0xC0, 0); | |
67 | pci_write16(0, 31, 4, 0xC0, pci_read16(0, 31, 4, 0xC0)); | |
68 | pci_write16(0, 31, 4, 0xC0, 0); | |
c34aba05 JP |
69 | |
70 | ||
71 | /* Open the SMRAM aperture and load our ELF. */ | |
72 | smram_state_t old_smramc = smram_save_state(); | |
73 | ||
74 | if (smram_aseg_set_state(SMRAM_ASEG_OPEN) != 0) | |
75 | { | |
76 | puts("Opening SMRAM failed; cannot load ELF.\n"); | |
77 | } | |
78 | else | |
79 | { | |
80 | load_elf(mods[0].mod_start, mods[0].mod_end - mods[0].mod_start); | |
81 | smram_restore_state(old_smramc); | |
82 | } | |
83 | ||
60a917ef JW |
84 | outb(0x830, inb(0x830) | 0x41); /* turn on the SMIs we want */ |
85 | ||
86 | puts("Waiting for a bit before returning to real mode..."); | |
87 | for (i=0; i<0x500000; i++) | |
88 | { | |
89 | if ((i % 0x100000) == 0) | |
90 | puts("."); | |
91 | inb(0x80); | |
92 | } | |
93 | puts("\n"); | |
d56898ee | 94 | |
c4a16564 JW |
95 | puts("Now returning to real mode.\n"); |
96 | memcpy(0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size); | |
86c89e89 | 97 | realmode(); // goodbye! |
56553b73 | 98 | } |