From: Joshua Wise Date: Thu, 25 Sep 2008 21:55:27 +0000 (-0400) Subject: Move dolog to output X-Git-Url: http://git.joshuawise.com/netwatch.git/commitdiff_plain/efea5b4edd5cc94b4ed0917ebca0efb6bb6a2f82?ds=sidebyside;hp=-c Move dolog to output --- efea5b4edd5cc94b4ed0917ebca0efb6bb6a2f82 diff --git a/aseg/vga-overlay.c b/aseg/vga-overlay.c index d205656..ca0e8a5 100644 --- a/aseg/vga-overlay.c +++ b/aseg/vga-overlay.c @@ -3,6 +3,7 @@ #include #include #include +#include static char logents[4][41] = {{0}}; @@ -66,13 +67,14 @@ void outlog() strblit(logents[y], y, 40); } -void dolog(char *s) +void dolog(const char *s) { memmove(logents[0], logents[1], sizeof(logents[0])*3); strcpy(logents[3], s); } +void (*output)(const char *s) = dolog; -void dologf(char *fmt, ...) +void dologf(const char *fmt, ...) { va_list va; @@ -81,3 +83,4 @@ void dologf(char *fmt, ...) vsnprintf(logents[3], 40, fmt, va); va_end(va); } +void (*outputf)(const char *s, ...) = dologf; diff --git a/grubload/Makefile b/grubload/Makefile index ae3b7a2..0ff596a 100644 --- a/grubload/Makefile +++ b/grubload/Makefile @@ -1,4 +1,4 @@ -OBJS=multiboot_c.o multiboot_asm.o realmode.o loader.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o ../ich2/smram-ich2.o ../ich2/smi.o +OBJS=multiboot_c.o multiboot_asm.o realmode.o loader.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o ../ich2/smram-ich2.o ../ich2/smi.o output.o ../lib/sprintf.o ../lib/doprnt.o CC=gcc CFLAGS=-nostdlib -I../include -I../include/raw -I. -D__RAW__ -fno-builtin -nostdinc -Wall -Werror -pedantic -std=gnu99 diff --git a/grubload/loader.c b/grubload/loader.c index ee9fc00..a754a49 100644 --- a/grubload/loader.c +++ b/grubload/loader.c @@ -1,4 +1,6 @@ #include +#include +#include static const unsigned char elf_ident[4] = { 0x7F, 'E', 'L', 'F' }; @@ -8,7 +10,7 @@ int load_elf (char * buf, int size) { Elf32_Shdr * elf_sec_hdrs = (Elf32_Shdr *) (buf + elf_hdr->e_shoff); /* Sanity check on ELF file */ - if (memcmp(elf_hdr->e_ident, elf_ident, sizeof(elf_ident))) return -1; + if (memcmp((void *)elf_hdr->e_ident, (void *)elf_ident, sizeof(elf_ident))) return -1; if (elf_hdr->e_type != ET_EXEC) return -1; if (elf_hdr->e_machine != EM_386) return -1; if (elf_hdr->e_version != EV_CURRENT) return -1; @@ -29,17 +31,13 @@ int load_elf (char * buf, int size) { char * section_name = string_table + elf_sec_hdrs[i].sh_name; if ((elf_sec_hdrs[i].sh_type != SHT_PROGBITS) || !(elf_sec_hdrs[i].sh_flags & SHF_ALLOC)) { - puts("Skipping "); - puts(section_name); - puts("\n"); + outputf("Skipping %s", section_name); continue; } - puts("Loading "); - puts(section_name); - puts("\n"); + outputf("Loading %s at %08x", section_name, elf_sec_hdrs[i].sh_addr); - memcpy(elf_sec_hdrs[i].sh_addr, + memcpy((void *)elf_sec_hdrs[i].sh_addr, buf + elf_sec_hdrs[i].sh_offset, elf_sec_hdrs[i].sh_size); } diff --git a/grubload/multiboot_c.c b/grubload/multiboot_c.c index 55f3a4f..04f9b2f 100644 --- a/grubload/multiboot_c.c +++ b/grubload/multiboot_c.c @@ -1,6 +1,6 @@ #include "console.h" #include "loader.h" - +#include #include #include #include @@ -21,18 +21,10 @@ struct info_section void panic(const char *msg) { - puts("PANIC: "); - puts(msg); - puts("\nSystem halted\n"); + outputf("PANIC: %s\nSystem halted\n", msg); while(1) { __asm__("hlt"); } } -void dolog(char *s) -{ - /* little shim -- need to unify logging */ - puts(s); -} - void c_start(unsigned int magic, struct mb_info *mbinfo) { struct mod_info *mods = mbinfo->mods; @@ -43,25 +35,25 @@ void c_start(unsigned int magic, struct mb_info *mbinfo) void (*realmode)() = (void (*)()) 0x4000; show_cursor(); - puts("NetWatch loader\n"); + outputf("NetWatch loader"); if (magic != MULTIBOOT_LOADER_MAGIC) panic("Bootloader was not multiboot compliant; cannot continue."); for (i = 0; i < mbinfo->mod_cnt; i++) { - puts("Module found:\n"); - puts(" Start: "); puthex((unsigned long) mods[i].mod_start); puts("\n"); - puts(" Size: "); puthex((unsigned long)mods[i].mod_end - (unsigned long)mods[i].mod_start); puts("\n"); - puts(" Name: "); puts(mods[i].mod_string); puts("\n"); + outputf("Module found:"); + outputf(" Start: %08x", (unsigned long) mods[i].mod_start); + outputf(" Size: %08x", (unsigned long)mods[i].mod_end - (unsigned long)mods[i].mod_start); + outputf(" Name: %s", mods[i].mod_string); } if (mbinfo->mod_cnt != 1) panic("Expected exactly one module; cannot continue."); - 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"); + outputf("Current USB state is: %04x %04x", pci_read16(0, 31, 2, 0xC0), pci_read16(0, 31, 4, 0xC0)); + outputf("Current SMI state is: %08x", inl(0x830)); + outputf("Current SMRAMC state is: %02x", pci_read8(0, 0, 0, 0x70)); smi_disable(); @@ -98,7 +90,7 @@ void c_start(unsigned int magic, struct mb_info *mbinfo) } puts("\n"); - puts("Now returning to real mode.\n"); + outputf("Now returning to real mode."); memcpy((void *)0x4000, _binary_realmode_bin_start, (int)&_binary_realmode_bin_size); realmode(); // goodbye! } diff --git a/grubload/output.c b/grubload/output.c new file mode 100644 index 0000000..6a6ffab --- /dev/null +++ b/grubload/output.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#include + +#define OUTBLEN 160 + +static void safeputs(const char *s) +{ + unsigned long old = smram_save_state(); + smram_aseg_set_state(SMRAM_ASEG_SMMONLY); + puts(s); + smram_restore_state(old); +} +void (*output)(const char *s) = safeputs; + +static void miniprintf(const char *fmt, ...) +{ + va_list va; + char b[OUTBLEN+1]; + + va_start(va, fmt); + vsnprintf(b, OUTBLEN, fmt, va); + va_end(va); + + output(b); + putbyte('\n'); +} + +void (*outputf)(const char *s, ...) = miniprintf; diff --git a/ich2/smi.c b/ich2/smi.c index 41bc4a1..adba74f 100644 --- a/ich2/smi.c +++ b/ich2/smi.c @@ -4,6 +4,7 @@ #include #include #include +#include static uint16_t _get_PMBASE() { @@ -39,25 +40,25 @@ void smi_poll() if (sts & ICH2_SMI_STS_BIOS_STS) { - dolog("Unhandled: BIOS_STS"); + output("Unhandled: BIOS_STS"); outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_BIOS_STS); } if (sts & ICH2_SMI_STS_LEGACY_USB_STS) { - dolog("Unhandled: LEGACY_USB_STS"); + output("Unhandled: LEGACY_USB_STS"); outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_LEGACY_USB_STS); } if (sts & ICH2_SMI_STS_SLP_SMI_STS) { - dolog("Unhandled: SLP_SMI_STS"); + output("Unhandled: SLP_SMI_STS"); outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_SLP_SMI_STS); } if (sts & ICH2_SMI_STS_APM_STS) { - dolog("Unhandled: APM_STS"); + output("Unhandled: APM_STS"); outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_APM_STS); } @@ -78,25 +79,25 @@ void smi_poll() pm1_sts &= pm1_en; if (pm1_sts & ICH2_PM1_STS_RTC_STS) { - dolog("Unhandled: PM1_STS: RTC_STS"); + output("Unhandled: PM1_STS: RTC_STS"); outw(_get_PMBASE() + ICH2_PMBASE_PM1_STS, ICH2_PM1_STS_RTC_STS); } if (pm1_sts & ICH2_PM1_STS_PWRBTN_STS) { - dolog("Unhandled: PM1_STS: PWRBTN_STS"); + output("Unhandled: PM1_STS: PWRBTN_STS"); outw(_get_PMBASE() + ICH2_PMBASE_PM1_STS, ICH2_PM1_STS_PWRBTN_STS); } if (pm1_sts & ICH2_PM1_STS_GBL_STS) { - dolog("Unhandled: PM1_STS: GBL_STS"); + output("Unhandled: PM1_STS: GBL_STS"); outw(_get_PMBASE() + ICH2_PMBASE_PM1_STS, ICH2_PM1_STS_GBL_STS); } if (pm1_sts & ICH2_PM1_STS_TMROF_STS) { - dolog("Unhandled: PM1_STS: TMROF_STS"); + output("Unhandled: PM1_STS: TMROF_STS"); outw(_get_PMBASE() + ICH2_PMBASE_PM1_STS, ICH2_PM1_STS_TMROF_STS); } @@ -106,18 +107,18 @@ void smi_poll() if (sts & ICH2_SMI_STS_GPE0_STS) { /* XXX -- trawl through GPE0_STS to see what happened */ - dolog("XXX Unhandled: GPE0_STS (expect lockup)"); + output("XXX Unhandled: GPE0_STS (expect lockup)"); } if (sts & ICH2_SMI_STS_GPE1_STS) { /* XXX -- trawl through GPE1_STS to see what happened */ - dolog("XXX Unhandled: GPE1_STS (expect lockup)"); + output("XXX Unhandled: GPE1_STS (expect lockup)"); } if (sts & ICH2_SMI_STS_MCSMI_STS) { - dolog("Unhandled: MCSMI_STS"); + output("Unhandled: MCSMI_STS"); outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_MCSMI_STS); } @@ -127,37 +128,37 @@ void smi_poll() unsigned long devact_sts = inl(_get_PMBASE() + ICH2_PMBASE_DEVACT_STS); unsigned long devtrap_en = inl(_get_PMBASE() + ICH2_PMBASE_DEVTRAP_EN); if (((mon_smi & 0x0F00) >> 8) & ((mon_smi & 0xF000) >> 12)) - dologf("Unhandled: MON_SMI (%04x)", mon_smi); + outputf("Unhandled: MON_SMI (%04x)", mon_smi); if (devact_sts & devtrap_en) - dologf("Unhandled: DEVTRAP (%08x)", devact_sts & devtrap_en); + outputf("Unhandled: DEVTRAP (%08x)", devact_sts & devtrap_en); } if (sts & ICH2_SMI_STS_TCO_STS) { - dolog("Unhandled: TCO_STS"); + output("Unhandled: TCO_STS"); outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_TCO_STS); } if (sts & ICH2_SMI_STS_PERIODIC_STS) { - dolog("Unhandled: PERIODIC_STS"); + output("Unhandled: PERIODIC_STS"); outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_PERIODIC_STS); } if (sts & ICH2_SMI_STS_SERIRQ_SMI_STS) { - dolog("Unhandled: SERIRQ_SMI_STS"); + output("Unhandled: SERIRQ_SMI_STS"); outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_SERIRQ_SMI_STS); } if (sts & ICH2_SMI_STS_SMBUS_SMI_STS) { - dolog("Unhandled: SMBUS_SMI_STS"); + output("Unhandled: SMBUS_SMI_STS"); outl(_get_PMBASE() + ICH2_PMBASE_SMI_STS, ICH2_SMI_STS_SMBUS_SMI_STS); } if (smi_status() & ~ICH2_SMI_STS_PM1_STS_REG) /* Either the chipset is buggy, or we are. */ - dologf("WARN: couldn't clear SMI_STS! (%08x)", smi_status()); + outputf("WARN: couldn't clear SMI_STS! (%08x)", smi_status()); outl(_get_PMBASE() + ICH2_PMBASE_SMI_EN, inl(_get_PMBASE() + ICH2_PMBASE_SMI_EN) | diff --git a/include/output.h b/include/output.h new file mode 100644 index 0000000..f49ef59 --- /dev/null +++ b/include/output.h @@ -0,0 +1,7 @@ +#ifndef __OUTPUT_H +#define __OUTPUT_H + +extern void (*output)(const char *s); +extern void (*outputf)(const char *s, ...); + +#endif