]> Joshua Wise's Git repositories - netwatch.git/blame - grubload/multiboot_c.c
more aseg/grubload rearrangements
[netwatch.git] / grubload / multiboot_c.c
CommitLineData
9b8c947b 1#include "console.h"
60a917ef 2#include <io.h>
c34aba05 3#include <smram.h>
9b8c947b 4
e5d94488
JP
5#define INFO_SIGNATURE 0x5754454E
6
c4a16564
JW
7extern char _binary_realmode_bin_start[];
8extern int _binary_realmode_bin_size;
9
9b8c947b 10struct mb_info
56553b73 11{
9b8c947b
JW
12 unsigned long flags;
13 unsigned long mem_lower, mem_upper;
14 unsigned long boot_dev;
15 char *cmdline;
16 unsigned long mod_cnt;
17 struct mod_info *mods;
18};
19
20struct mod_info
21{
22 void *mod_start;
23 void *mod_end;
24 char *mod_string;
25 void *reserved;
26};
27
e5d94488
JP
28struct info_section
29{
30 unsigned int signature;
31 void (*firstrun)();
32};
33
c34aba05 34void c_start(unsigned int magic, struct mb_info *info)
9b8c947b 35{
e5d94488 36 struct mod_info *mods = info->mods;
7e16b8e6 37 unsigned short *grubptr = (unsigned short *)0x7CFE;
60a917ef 38 unsigned char smramc;
9b8c947b
JW
39 int i;
40
7e16b8e6 41 void (*realmode)() = (void (*)()) 0x4000;
c4a16564 42
9b8c947b 43 show_cursor();
81148fa1
JW
44 puts("NetWatch loader\n");
45
46 if (magic != 0x2BADB002)
47 {
48 puts("Bootloader was not multiboot compliant; cannot continue.\n");
49 while(1) asm("hlt");
50 }
9b8c947b 51
c34aba05 52 for (i = 0; i < info->mod_cnt; i++)
9b8c947b 53 {
81148fa1 54 puts("Module found:\n");
c34aba05
JP
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");
9b8c947b 58 }
c4a16564 59
c34aba05 60 if (info->mod_cnt != 1)
d56898ee 61 {
60a917ef 62 puts("Expected exactly one module; cannot continue.\n");
d56898ee 63 while(1) asm("hlt");
64 }
65
60a917ef
JW
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");
69
81148fa1 70 outl(0x830, inl(0x830) & ~0x1); /* turn off SMIs */
60a917ef
JW
71
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);
c34aba05
JP
77
78
79 /* Open the SMRAM aperture and load our ELF. */
80 smram_state_t old_smramc = smram_save_state();
81
82 if (smram_aseg_set_state(SMRAM_ASEG_OPEN) != 0)
83 {
84 puts("Opening SMRAM failed; cannot load ELF.\n");
85 }
86 else
87 {
88 load_elf(mods[0].mod_start, mods[0].mod_end - mods[0].mod_start);
e5d94488
JP
89
90 struct info_section * info = (struct info_section *)0x10000;
91 if (info->signature != INFO_SIGNATURE)
92 {
93 smram_restore_state(old_smramc);
94 puts("Info section signature mismatch.\n");
95 }
96 else {
97 info->firstrun();
98 smram_restore_state(old_smramc);
99 }
c34aba05
JP
100 }
101
60a917ef
JW
102 puts("Waiting for a bit before returning to real mode...");
103 for (i=0; i<0x500000; i++)
104 {
105 if ((i % 0x100000) == 0)
106 puts(".");
107 inb(0x80);
108 }
109 puts("\n");
d56898ee 110
c4a16564
JW
111 puts("Now returning to real mode.\n");
112 memcpy(0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size);
86c89e89 113 realmode(); // goodbye!
56553b73 114}
This page took 0.033433 seconds and 4 git commands to generate.