#include <video_defines.h>
#include <minilib.h>
#include <stdarg.h>
+#include <output.h>
static char logents[4][41] = {{0}};
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;
vsnprintf(logents[3], 40, fmt, va);
va_end(va);
}
+void (*outputf)(const char *s, ...) = dologf;
-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
#include <elf.h>
+#include <output.h>
+#include <minilib.h>
static const unsigned char elf_ident[4] = { 0x7F, 'E', 'L', 'F' };
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;
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);
}
#include "console.h"
#include "loader.h"
-
+#include <output.h>
#include <minilib.h>
#include <io.h>
#include <smram.h>
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;
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();
}
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!
}
--- /dev/null
+#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;
#include <stdint.h>
#include <vga-overlay.h>
#include <reg-82801b.h>
+#include <output.h>
static uint16_t _get_PMBASE()
{
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);
}
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);
}
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);
}
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) |
--- /dev/null
+#ifndef __OUTPUT_H
+#define __OUTPUT_H
+
+extern void (*output)(const char *s);
+extern void (*outputf)(const char *s, ...);
+
+#endif