From: Joshua Wise <joshua@rebirth.joshuawise.com>
Date: Fri, 19 Sep 2008 20:52:19 +0000 (-0400)
Subject: add printf/dologf
X-Git-Url: http://git.joshuawise.com/netwatch.git/commitdiff_plain/d24901e6cc51d80d30e074eba9fdb3b64d938dc2

add printf/dologf
---

diff --git a/aseg/Makefile b/aseg/Makefile
index 5806bd1..359759c 100644
--- a/aseg/Makefile
+++ b/aseg/Makefile
@@ -1,6 +1,6 @@
 CC=gcc
 CFLAGS=-I../include -I../include/raw -nostdlib -nostdinc -fno-builtin -D__RAW__ -Wall -Werror -pedantic -ansi -std=gnu99
-OBJS=counter.o firstrun.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o ../ich2/smram-ich2.o ../ich2/smi.o vga-overlay.o
+OBJS=counter.o firstrun.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o ../ich2/smram-ich2.o ../ich2/smi.o vga-overlay.o ../lib/sprintf.o ../lib/doprnt.o
 
 all: aseg.elf
 
diff --git a/aseg/counter.c b/aseg/counter.c
index d523168..104d809 100644
--- a/aseg/counter.c
+++ b/aseg/counter.c
@@ -25,15 +25,12 @@ void pci_dump() {
 	case 0x20000:
 	{
 		unsigned char b;
-		strcpy(s, "READxxxxxxxxxxxxxxxx");
-		tohex(s+4, cts);
 		b = inb(cts & 0xFFFF);
-		tohex(s+12, b);
+		dologf("READ: %08x (%02x)", cts, b);
 		if ((cts & 0xFFFF) == 0x64)
 			curdev = (b & 0x20) ? 1 : 0;
 		if ((curdev == 0) && ((cts & 0xFFFF) == 0x60) && (b == 0x01))
 			outb(0xCF9, 0x4);
-		dolog(s);
 		*(unsigned char*)0xAFFD0 /* EAX */ = b;
 		break;
 	}
@@ -97,13 +94,7 @@ void __start (void)
 		outl(0x840, 0x0100);
 	}
 	if (inl(0x834) & ~(0x4160))
-	{
-		char s[40];
-		strcpy(s, "Unknown: xxxxxxxx");
-		tohex(s + 9, inl(0x834) & ~(0x140));
-		dolog(s);
-	}
-
+		dologf("Unknown: %08x", inl(0x834) & ~(0x140));
 
 	outlog();
 	
diff --git a/aseg/vga-overlay.c b/aseg/vga-overlay.c
index e5414ca..d205656 100644
--- a/aseg/vga-overlay.c
+++ b/aseg/vga-overlay.c
@@ -2,6 +2,7 @@
 #include <smram.h>
 #include <video_defines.h>
 #include <minilib.h>
+#include <stdarg.h>
 
 static char logents[4][41] = {{0}};
 
@@ -22,8 +23,8 @@ static char * vga_base()
 {
 	return (char *) (
 		TEXT_CONSOLE_BASE
-		| (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 9)
-		| (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 1)
+		+ (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9)
+		+ (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1)
 	);
 }
 
@@ -60,7 +61,7 @@ void outlog()
 		}
 
 	smram_restore_state(old_state);
-
+	
 	for (y = 0; y < 4; y++)
 		strblit(logents[y], y, 40);
 }
@@ -70,3 +71,13 @@ void dolog(char *s)
 	memmove(logents[0], logents[1], sizeof(logents[0])*3);
 	strcpy(logents[3], s);
 }
+
+void dologf(char *fmt, ...)
+{
+	va_list va;
+	
+	memmove(logents[0], logents[1], sizeof(logents[0])*3);
+	va_start(va, fmt);
+	vsnprintf(logents[3], 40, fmt, va);
+	va_end(va);
+}
diff --git a/aseg/vga-overlay.h b/aseg/vga-overlay.h
index f79e6da..890f353 100644
--- a/aseg/vga-overlay.h
+++ b/aseg/vga-overlay.h
@@ -4,6 +4,7 @@
 void strblit(char *src, int row, int col);
 
 void dolog(char *s);
+void dologf(char *s, ...);
 void outlog();
 
 #endif
diff --git a/ich2/smi.c b/ich2/smi.c
index 59f14b6..e790e40 100644
--- a/ich2/smi.c
+++ b/ich2/smi.c
@@ -5,7 +5,7 @@
 
 uint16_t _get_PMBASE()
 {
-	return pci_read32(0, 0, 0, 0x40) & 0xFF80;
+	return pci_read32(0, 21, 0, 0x40) & 0xFF80;
 }
 
 void smi_disable()
diff --git a/include/minilib.h b/include/minilib.h
index 747b2aa..0f5edff 100644
--- a/include/minilib.h
+++ b/include/minilib.h
@@ -1,9 +1,20 @@
 #ifndef MINILIB_H
 #define MINILIB_H
 
-void memmove(void *dest, void *src, int bytes);
-int strcmp(const char *a2, const char *a1);
-void strcpy(char *a2, const char *a1);
-void tohex(char *s, unsigned long l);
+#include <stdarg.h>
+
+extern void memcpy(void *dest, void *src, int bytes);
+extern void memmove(void *dest, void *src, int bytes);
+extern int memcmp(const char *a2, const char *a1, int bytes);
+extern int strcmp(const char *a2, const char *a1);
+extern int strlen(char *c);
+extern void strcpy(char *a2, const char *a1);
+extern void puts(char *c);
+extern void tohex(char *s, unsigned long l);
+extern void puthex(unsigned long l);
+extern int vsprintf(char *s, const char *fmt, va_list args);
+extern int vsnprintf(char *s, int size, const char *fmt, va_list args);
+extern int sprintf(char *s, const char *fmt, ...);
+extern int snprintf(char *s, int size, const char *fmt, ...);
 
 #endif
diff --git a/lib/minilib.c b/lib/minilib.c
index 232878b..595341e 100644
--- a/lib/minilib.c
+++ b/lib/minilib.c
@@ -81,5 +81,3 @@ void puthex(unsigned long l)
 	tohex(d, l);
 	puts(d);
 }
-
-