From: Jacob Potter Date: Sat, 13 Sep 2008 22:34:27 +0000 (-0400) Subject: more aseg/grubload rearrangements X-Git-Url: http://git.joshuawise.com/netwatch.git/commitdiff_plain/e5d94488b04d37328aef0420beafed4afe42cef5 more aseg/grubload rearrangements --- diff --git a/aseg/Makefile b/aseg/Makefile index fd1efa9..5033a55 100644 --- a/aseg/Makefile +++ b/aseg/Makefile @@ -1,17 +1,17 @@ CC=gcc CFLAGS=-I../include -I../include/raw -nostdlib -nostdinc -fno-builtin -D__RAW__ -OBJS=counter.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o +OBJS=counter.o firstrun.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o all: aseg.elf -aseg.bin: aseg.asm - nasm -o aseg.bin aseg.asm - -aseg.o: aseg.bin - objcopy -I binary -B i386 -O elf32-i386 aseg.bin aseg.o - aseg.elf: aseg.lds aseg.o $(OBJS) ld -o aseg.elf -T aseg.lds $(OBJS) clean: rm -f $(OBJS) aseg.elf aseg.bin aseg.o + + +%.o: %.asm + nasm -o $@.bin $< + objcopy -I binary -B i386 -O elf32-i386 $@.bin $@ + rm -f $@.bin diff --git a/aseg/aseg.lds b/aseg/aseg.lds index a3a8ece..2905027 100644 --- a/aseg/aseg.lds +++ b/aseg/aseg.lds @@ -26,4 +26,11 @@ SECTIONS . = ALIGN(0x10); _stacktop = .; } + + . = 0x10000; + .info : { + _start = .; + LONG(0x5754454E); + LONG(__firstrun_start); + } } diff --git a/aseg/firstrun.c b/aseg/firstrun.c new file mode 100644 index 0000000..ace70c6 --- /dev/null +++ b/aseg/firstrun.c @@ -0,0 +1,27 @@ +#include + +void __firstrun_start() { +/* + puts("Current USB state is: "); + puthex(pci_read16(0, 31, 2, 0xC0)); + puts(" "); + puthex(pci_read16(0, 31, 4, 0xC0)); + puts("\n"); + puts("Current SMI state is: "); + puthex(inl(0x830)); + puts("\n"); + puts("Current SMRAMC state is: "); + puthex(pci_read8(0, 0, 0, 0x70)); + puts("\n"); +*/ + + /* Try really hard to shut up USB_LEGKEY. */ + pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0)); + pci_write16(0, 31, 2, 0xC0, 0); + pci_write16(0, 31, 4, 0xC0, pci_read16(0, 31, 4, 0xC0)); + pci_write16(0, 31, 4, 0xC0, 0); + + /* Turn on the SMIs we want */ + outb(0x830, inb(0x830) | 0x41); +} + diff --git a/grubload/multiboot_c.c b/grubload/multiboot_c.c index c75e830..50aca06 100644 --- a/grubload/multiboot_c.c +++ b/grubload/multiboot_c.c @@ -2,6 +2,8 @@ #include #include +#define INFO_SIGNATURE 0x5754454E + extern char _binary_realmode_bin_start[]; extern int _binary_realmode_bin_size; @@ -23,9 +25,15 @@ struct mod_info void *reserved; }; +struct info_section +{ + unsigned int signature; + void (*firstrun)(); +}; + void c_start(unsigned int magic, struct mb_info *info) { - struct mod_info *mods = mods; + struct mod_info *mods = info->mods; unsigned short *grubptr = (unsigned short *)0x7CFE; unsigned char smramc; int i; @@ -78,11 +86,19 @@ void c_start(unsigned int magic, struct mb_info *info) else { load_elf(mods[0].mod_start, mods[0].mod_end - mods[0].mod_start); - smram_restore_state(old_smramc); + + struct info_section * info = (struct info_section *)0x10000; + if (info->signature != INFO_SIGNATURE) + { + smram_restore_state(old_smramc); + puts("Info section signature mismatch.\n"); + } + else { + info->firstrun(); + smram_restore_state(old_smramc); + } } - outb(0x830, inb(0x830) | 0x41); /* turn on the SMIs we want */ - puts("Waiting for a bit before returning to real mode..."); for (i=0; i<0x500000; i++) {