]> Joshua Wise's Git repositories - netwatch.git/commitdiff
Move dolog to output
authorJoshua Wise <joshua@rebirth.joshuawise.com>
Thu, 25 Sep 2008 21:55:27 +0000 (17:55 -0400)
committerJoshua Wise <joshua@rebirth.joshuawise.com>
Thu, 25 Sep 2008 21:55:27 +0000 (17:55 -0400)
aseg/vga-overlay.c
grubload/Makefile
grubload/loader.c
grubload/multiboot_c.c
grubload/output.c [new file with mode: 0644]
ich2/smi.c
include/output.h [new file with mode: 0644]

index d205656f65eb72cf079711f5cc4025f47daa41fc..ca0e8a53e0abae52efdfbb55ac302872fce13301 100644 (file)
@@ -3,6 +3,7 @@
 #include <video_defines.h>
 #include <minilib.h>
 #include <stdarg.h>
+#include <output.h>
 
 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;
index ae3b7a2aa2877f7166c73ca944002ce5a78f312e..0ff596ac8abc3d301de55bc87ecf77fa64b76b4a 100644 (file)
@@ -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
 
index ee9fc00729ea16d066215960baf4cfb00ec43da7..a754a49faeab3e5d917127181f406e3ad28b69c5 100644 (file)
@@ -1,4 +1,6 @@
 #include <elf.h>
+#include <output.h>
+#include <minilib.h>
 
 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);
        }
index 55f3a4fd8c253bfdf368153f00261c0e226d13d8..04f9b2f4f3bb3a901f9ba278b438753ac536dde9 100644 (file)
@@ -1,6 +1,6 @@
 #include "console.h"
 #include "loader.h"
-
+#include <output.h>
 #include <minilib.h>
 #include <io.h>
 #include <smram.h>
@@ -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 (file)
index 0000000..6a6ffab
--- /dev/null
@@ -0,0 +1,31 @@
+#include <stdarg.h>
+#include <minilib.h>
+#include <console.h>
+#include <output.h>
+#include <smram.h>
+
+#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;
index 41bc4a1fea6f4299bb5881466134a9e8243c2acb..adba74f4b285c2ef046761d9896d4d3eabbad714 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdint.h>
 #include <vga-overlay.h>
 #include <reg-82801b.h>
+#include <output.h>
 
 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 (file)
index 0000000..f49ef59
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef __OUTPUT_H
+#define __OUTPUT_H
+
+extern void (*output)(const char *s);
+extern void (*outputf)(const char *s, ...);
+
+#endif
This page took 0.044017 seconds and 4 git commands to generate.