5 extern char _binary_realmode_bin_start[];
6 extern int _binary_realmode_bin_size;
11 unsigned long mem_lower, mem_upper;
12 unsigned long boot_dev;
14 unsigned long mod_cnt;
15 struct mod_info *mods;
26 void c_start(unsigned int magic, struct mb_info *info)
28 struct mod_info *mods = mods;
29 unsigned short *grubptr = (unsigned short *)0x7CFE;
33 void (*realmode)() = (void (*)()) 0x4000;
36 puts("NetWatch loader\n");
38 if (magic != 0x2BADB002)
40 puts("Bootloader was not multiboot compliant; cannot continue.\n");
44 for (i = 0; i < info->mod_cnt; i++)
46 puts("Module found:\n");
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");
52 if (info->mod_cnt != 1)
54 puts("Expected exactly one module; cannot continue.\n");
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");
62 outl(0x830, inl(0x830) & ~0x1); /* turn off SMIs */
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);
71 /* Open the SMRAM aperture and load our ELF. */
72 smram_state_t old_smramc = smram_save_state();
74 if (smram_aseg_set_state(SMRAM_ASEG_OPEN) != 0)
76 puts("Opening SMRAM failed; cannot load ELF.\n");
80 load_elf(mods[0].mod_start, mods[0].mod_end - mods[0].mod_start);
81 smram_restore_state(old_smramc);
84 outb(0x830, inb(0x830) | 0x41); /* turn on the SMIs we want */
86 puts("Waiting for a bit before returning to real mode...");
87 for (i=0; i<0x500000; i++)
89 if ((i % 0x100000) == 0)
95 puts("Now returning to real mode.\n");
96 memcpy(0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size);
97 realmode(); // goodbye!