11 #define INFO_SIGNATURE 0x5754454E
13 extern char _binary_realmode_bin_start[];
14 extern int _binary_realmode_bin_size;
18 unsigned int signature;
22 void panic(const char *msg)
26 puts("\nSystem halted\n");
27 while(1) { __asm__("hlt"); }
32 /* little shim -- need to unify logging */
36 void c_start(unsigned int magic, struct mb_info *mbinfo)
38 struct mod_info *mods = mbinfo->mods;
39 smram_state_t old_smramc;
40 struct info_section * info;
43 void (*realmode)() = (void (*)()) 0x4000;
46 puts("NetWatch loader\n");
48 if (magic != MULTIBOOT_LOADER_MAGIC)
49 panic("Bootloader was not multiboot compliant; cannot continue.");
51 for (i = 0; i < mbinfo->mod_cnt; i++)
53 puts("Module found:\n");
54 puts(" Start: "); puthex((unsigned long) mods[i].mod_start); puts("\n");
55 puts(" Size: "); puthex((unsigned long)mods[i].mod_end - (unsigned long)mods[i].mod_start); puts("\n");
56 puts(" Name: "); puts(mods[i].mod_string); puts("\n");
59 if (mbinfo->mod_cnt != 1)
60 panic("Expected exactly one module; cannot continue.");
62 puts("Current USB state is: "); puthex(pci_read16(0, 31, 2, 0xC0)); puts(" "); puthex(pci_read16(0, 31, 4, 0xC0)); puts("\n");
63 puts("Current SMI state is: "); puthex(inl(0x830)); puts("\n");
64 puts("Current SMRAMC state is: "); puthex(pci_read8(0, 0, 0, 0x70)); puts("\n");
68 /* Try really hard to shut up USB_LEGKEY. */
69 pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0));
70 pci_write16(0, 31, 2, 0xC0, 0);
71 pci_write16(0, 31, 4, 0xC0, pci_read16(0, 31, 4, 0xC0));
72 pci_write16(0, 31, 4, 0xC0, 0);
74 /* Open the SMRAM aperture and load our ELF. */
75 old_smramc = smram_save_state();
77 if (smram_aseg_set_state(SMRAM_ASEG_OPEN) != 0)
78 panic("Opening SMRAM failed; cannot load ELF.");
80 load_elf(mods[0].mod_start, (unsigned long)mods[0].mod_end - (unsigned long)mods[0].mod_start);
82 info = (struct info_section *)0x10000;
83 if (info->signature != INFO_SIGNATURE)
85 smram_restore_state(old_smramc); /* Restore so that video ram is touchable again. */
86 panic("Info section signature mismatch.");
90 smram_restore_state(old_smramc);
92 puts("Waiting for a bit before returning to real mode...");
93 for (i=0; i<0x500000; i++)
95 if ((i % 0x100000) == 0)
101 puts("Now returning to real mode.\n");
102 memcpy((void *)0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size);
103 realmode(); // goodbye!