]> Joshua Wise's Git repositories - netwatch.git/blame_incremental - grubload/multiboot_c.c
slight grubload cleanups; use __RAW__ defined by build scripts instead of __linux__
[netwatch.git] / grubload / multiboot_c.c
... / ...
CommitLineData
1#include "console.h"
2#include <io.h>
3#include <smram.h>
4
5extern char _binary_realmode_bin_start[];
6extern int _binary_realmode_bin_size;
7
8struct mb_info
9{
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
18struct mod_info
19{
20 void *mod_start;
21 void *mod_end;
22 char *mod_string;
23 void *reserved;
24};
25
26void c_start(unsigned int magic, struct mb_info *info)
27{
28 struct mod_info *mods = mods;
29 unsigned short *grubptr = (unsigned short *)0x7CFE;
30 unsigned char smramc;
31 int i;
32
33 void (*realmode)() = (void (*)()) 0x4000;
34
35 show_cursor();
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 }
43
44 for (i = 0; i < info->mod_cnt; i++)
45 {
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");
50 }
51
52 if (info->mod_cnt != 1)
53 {
54 puts("Expected exactly one module; cannot continue.\n");
55 while(1) asm("hlt");
56 }
57
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
62 outl(0x830, inl(0x830) & ~0x1); /* turn off SMIs */
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);
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
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");
94
95 puts("Now returning to real mode.\n");
96 memcpy(0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size);
97 realmode(); // goodbye!
98}
This page took 0.023494 seconds and 4 git commands to generate.