4 extern char _binary_realmode_bin_start[];
5 extern int _binary_realmode_bin_size;
10 unsigned long mem_lower, mem_upper;
11 unsigned long boot_dev;
13 unsigned long mod_cnt;
14 struct mod_info *mods;
25 void c_start(unsigned int magic, struct mb_info *wee)
27 unsigned short *grubptr = (unsigned short *)0x7CFE;
31 void (*realmode)() = (void (*)()) 0x4000;
34 puts("NetWatch loader\n");
36 if (magic != 0x2BADB002)
38 puts("Bootloader was not multiboot compliant; cannot continue.\n");
42 for (i = 0; i < wee->mod_cnt; i++)
44 puts("Module found:\n");
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");
50 if (wee->mod_cnt != 1)
52 puts("Expected exactly one module; cannot continue.\n");
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");
60 outl(0x830, inl(0x830) & ~0x1); /* turn off SMIs */
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);
69 load_elf(wee->mods[0].mod_start, wee->mods[0].mod_end - wee->mods[0].mod_start);
70 pci_write8(0, 0, 0, 0x70, smramc);
71 outb(0x830, inb(0x830) | 0x41); /* turn on the SMIs we want */
73 puts("Waiting for a bit before returning to real mode...");
74 for (i=0; i<0x500000; i++)
76 if ((i % 0x100000) == 0)
82 puts("Now returning to real mode.\n");
83 memcpy(0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size);
84 realmode(); // goodbye!