5 #define INFO_SIGNATURE 0x5754454E
7 extern char _binary_realmode_bin_start[];
8 extern int _binary_realmode_bin_size;
13 unsigned long mem_lower, mem_upper;
14 unsigned long boot_dev;
16 unsigned long mod_cnt;
17 struct mod_info *mods;
30 unsigned int signature;
34 void c_start(unsigned int magic, struct mb_info *info)
36 struct mod_info *mods = info->mods;
37 unsigned short *grubptr = (unsigned short *)0x7CFE;
41 void (*realmode)() = (void (*)()) 0x4000;
44 puts("NetWatch loader\n");
46 if (magic != 0x2BADB002)
48 puts("Bootloader was not multiboot compliant; cannot continue.\n");
52 for (i = 0; i < info->mod_cnt; i++)
54 puts("Module found:\n");
55 puts(" Start: "); puthex(mods[i].mod_start); puts("\n");
56 puts(" Size: "); puthex(mods[i].mod_end - mods[i].mod_start); puts("\n");
57 puts(" Name: "); puts(mods[i].mod_string); puts("\n");
60 if (info->mod_cnt != 1)
62 puts("Expected exactly one module; cannot continue.\n");
66 puts("Current USB state is: "); puthex(pci_read16(0, 31, 2, 0xC0)); puts(" "); puthex(pci_read16(0, 31, 4, 0xC0)); puts("\n");
67 puts("Current SMI state is: "); puthex(inl(0x830)); puts("\n");
68 puts("Current SMRAMC state is: "); puthex(pci_read8(0, 0, 0, 0x70)); puts("\n");
70 outl(0x830, inl(0x830) & ~0x1); /* turn off SMIs */
72 /* Try really hard to shut up USB_LEGKEY. */
73 pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0));
74 pci_write16(0, 31, 2, 0xC0, 0);
75 pci_write16(0, 31, 4, 0xC0, pci_read16(0, 31, 4, 0xC0));
76 pci_write16(0, 31, 4, 0xC0, 0);
79 /* Open the SMRAM aperture and load our ELF. */
80 smram_state_t old_smramc = smram_save_state();
82 if (smram_aseg_set_state(SMRAM_ASEG_OPEN) != 0)
84 puts("Opening SMRAM failed; cannot load ELF.\n");
88 load_elf(mods[0].mod_start, mods[0].mod_end - mods[0].mod_start);
90 struct info_section * info = (struct info_section *)0x10000;
91 if (info->signature != INFO_SIGNATURE)
93 smram_restore_state(old_smramc);
94 puts("Info section signature mismatch.\n");
98 smram_restore_state(old_smramc);
102 puts("Waiting for a bit before returning to real mode...");
103 for (i=0; i<0x500000; i++)
105 if ((i % 0x100000) == 0)
111 puts("Now returning to real mode.\n");
112 memcpy(0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size);
113 realmode(); // goodbye!