From: Jacob Potter Date: Fri, 19 Sep 2008 19:44:09 +0000 (-0400) Subject: cleanup; add -Wkesden X-Git-Url: http://git.joshuawise.com/netwatch.git/commitdiff_plain/36ce375d87e8dd0fdee14de4fbc35c1aef56d7e9 cleanup; add -Wkesden --- diff --git a/aseg/Makefile b/aseg/Makefile index 5033a55..1c2867d 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__ -OBJS=counter.o firstrun.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o +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 all: aseg.elf diff --git a/aseg/counter.c b/aseg/counter.c index e4b5eae..ccfff72 100644 --- a/aseg/counter.c +++ b/aseg/counter.c @@ -1,51 +1,72 @@ #include +#include +#include +#include unsigned int counter = 0; unsigned long pcisave; unsigned char vgasave; -unsigned char thestr[512]; -unsigned char logents[4][41] = {0}; +char thestr[512]; +char logents[4][41] = {{0}}; -unsigned char vgaread(unsigned char idx) +#define VRAM_BASE 0xA0000UL +#define TEXT_CONSOLE_OFFSET 0x18000UL + +#define TEXT_CONSOLE_BASE (VRAM_BASE + TEXT_CONSOLE_OFFSET) + +#define COLOR 0x1F + +unsigned char vga_read(unsigned char idx) +{ + outb(CRTC_IDX_REG, idx); + return inb(CRTC_DATA_REG); +} + +char * vga_base() { - outb(0x3D4, idx); - inb(0x3D5); + 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) + ); } -void strblit(char *src, int r, int c) +void strblit(char *src, int row, int col) { - char *destp = (char*)(0xB8000UL | (((unsigned int)vgaread(0xC)) << 9) | (((unsigned int)vgaread(0xD)) << 1)) + r*80*2 + c*2; - unsigned char smramc; + char *destp = vga_base() + row * 80 * 2 + col * 2; + smram_state_t old_state = smram_save_state(); + + smram_aseg_set_state(SMRAM_ASEG_SMMCODE); - smramc = pci_read8(0, 0, 0, 0x70); - pci_write8(0, 0, 0, 0x70, (smramc & 0xF3) | 0x08); while (*src) { *(destp++) = *(src++); - *(destp++) = 0x1F; + *(destp++) = COLOR; } - pci_write8(0, 0, 0, 0x70, smramc); + + smram_restore_state(old_state); } void outlog() { int y, x; - unsigned char smramc; - unsigned char *basep = (char*)(0xB8000UL | (((unsigned int)vgaread(0xC)) << 9) | (((unsigned int)vgaread(0xD)) << 1)); - - smramc = pci_read8(0, 0, 0, 0x70); - pci_write8(0, 0, 0, 0x70, (smramc & 0xF3) | 0x08); + char *basep = vga_base(); + + smram_state_t old_state = smram_save_state(); + + smram_aseg_set_state(SMRAM_ASEG_SMMCODE); + for (y = 0; y < 4; y++) for (x = 40; x < 80; x++) { basep[y*80*2+x*2] = ' '; basep[y*80*2+x*2+1] = 0x1F; } - pci_write8(0, 0, 0, 0x70, smramc); - + + smram_restore_state(old_state); + for (y = 0; y < 4; y++) strblit(logents[y], y, 40); - } void dolog(char *s) @@ -55,7 +76,7 @@ void dolog(char *s) } void pci_dump() { - unsigned char s[40]; + char s[40]; unsigned long cts; static int curdev = 0; /* 0 if kbd, 1 if mouse */ @@ -99,7 +120,6 @@ void pci_dump() { void __start (void) { - unsigned char smramc; static int first = 1; pcisave = inl(0xCF8); @@ -141,7 +161,7 @@ void __start (void) } if (inl(0x834) & ~(0x4160)) { - unsigned char s[40]; + char s[40]; strcpy(s, "Unknown: xxxxxxxx"); tohex(s + 9, inl(0x834) & ~(0x140)); dolog(s); diff --git a/aseg/firstrun.c b/aseg/firstrun.c index ace70c6..355fb9a 100644 --- a/aseg/firstrun.c +++ b/aseg/firstrun.c @@ -1,4 +1,5 @@ #include +#include void __firstrun_start() { /* diff --git a/ich2/smram-ich2.c b/ich2/smram-ich2.c index 36a191b..d274c85 100644 --- a/ich2/smram-ich2.c +++ b/ich2/smram-ich2.c @@ -94,7 +94,7 @@ smram_state_t smram_save_state() void smram_restore_state(smram_state_t state) { - return pci_write8(0, 0, 0, SMRAMC, state); + pci_write8(0, 0, 0, SMRAMC, state); } int smram_aseg_set_state (int open) { diff --git a/include/minilib.h b/include/minilib.h index e0fc16b..747b2aa 100644 --- a/include/minilib.h +++ b/include/minilib.h @@ -1,33 +1,9 @@ -#ifndef __MINILIB_H -#define __MINILIB_H +#ifndef MINILIB_H +#define MINILIB_H -#define MINILIB 1 - -#ifndef __int8_t_defined -# define __int8_t_defined -typedef signed char int8_t; -typedef short int int16_t; -typedef int int32_t; -# if __WORDSIZE == 64 -typedef long int int64_t; -# else -__extension__ -typedef long long int int64_t; -# endif -#endif - -/* Unsigned. */ -typedef unsigned char uint8_t; -typedef unsigned short int uint16_t; -#ifndef __uint32_t_defined -typedef unsigned int uint32_t; -# define __uint32_t_defined -#endif -#if __WORDSIZE == 64 -typedef unsigned long int uint64_t; -#else -__extension__ -typedef unsigned long long int uint64_t; -#endif +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); #endif diff --git a/include/raw/io.h b/include/raw/io.h index 5fd0b19..f04f44c 100644 --- a/include/raw/io.h +++ b/include/raw/io.h @@ -1,11 +1,11 @@ #ifndef __IO_H #define __IO_H -#define inb(port) ({ unsigned char val; asm volatile("inb %%dx, %0" : "=a" ((unsigned char)(val)) : "d" ((unsigned short)(port))); val; }) -#define inw(port) ({ unsigned short val; asm volatile("inw %%dx, %0" : "=a" ((unsigned short)(val)) : "d" ((unsigned short)(port))); val; }) -#define inl(port) ({ unsigned long val; asm volatile("inl %%dx, %0" : "=a" ((unsigned long)(val)) : "d" ((unsigned short)(port))); val; }) -#define outb(port, val) ({ asm volatile("outb %0, %%dx" : : "a" ((unsigned char)(val)) , "d" ((unsigned short)(port))); }) -#define outw(port, val) ({ asm volatile("outw %0, %%dx" : : "a" ((unsigned short)(val)) , "d" ((unsigned short)(port))); }) -#define outl(port, val) ({ asm volatile("outl %0, %%dx" : : "a" ((unsigned long)(val)) , "d" ((unsigned short)(port))); }) +#define inb(port) __extension__ ({ unsigned char val; asm volatile("inb %%dx, %0" : "=a" ((unsigned char)(val)) : "d" ((unsigned short)(port))); val; }) +#define inw(port) __extension__ ({ unsigned short val; asm volatile("inw %%dx, %0" : "=a" ((unsigned short)(val)) : "d" ((unsigned short)(port))); val; }) +#define inl(port) __extension__ ({ unsigned long val; asm volatile("inl %%dx, %0" : "=a" ((unsigned long)(val)) : "d" ((unsigned short)(port))); val; }) +#define outb(port, val) __extension__ ({ asm volatile("outb %0, %%dx" : : "a" ((unsigned char)(val)) , "d" ((unsigned short)(port))); }) +#define outw(port, val) __extension__ ({ asm volatile("outw %0, %%dx" : : "a" ((unsigned short)(val)) , "d" ((unsigned short)(port))); }) +#define outl(port, val) __extension__ ({ asm volatile("outl %0, %%dx" : : "a" ((unsigned long)(val)) , "d" ((unsigned short)(port))); }) #endif diff --git a/include/video_defines.h b/include/video_defines.h index ca202ef..8c3b9fe 100644 --- a/include/video_defines.h +++ b/include/video_defines.h @@ -46,9 +46,13 @@ #define BLINK 0x80 /* Annoying. */ /* --- CRTC Register Manipulation --- */ + #define CRTC_IDX_REG 0x3d4 #define CRTC_DATA_REG 0x3d5 -#define CRTC_CURSOR_LSB_IDX 15 -#define CRTC_CURSOR_MSB_IDX 14 + +#define CRTC_START_ADDR_MSB_IDX 0xC +#define CRTC_START_ADDR_LSB_IDX 0xD +#define CRTC_CURSOR_MSB_IDX 0xE +#define CRTC_CURSOR_LSB_IDX 0xF #endif diff --git a/lib/console.c b/lib/console.c index 27880ba..66cfbaf 100644 --- a/lib/console.c +++ b/lib/console.c @@ -7,6 +7,7 @@ #include #include "console-ext.h" +#include #include #define POS_IS_VALID(row, col) ((row) >= 0 && (row) < CONSOLE_HEIGHT && (col) >= 0 && (col) < CONSOLE_WIDTH) diff --git a/lib/minilib.c b/lib/minilib.c index f64f3b1..232878b 100644 --- a/lib/minilib.c +++ b/lib/minilib.c @@ -1,26 +1,31 @@ #include "console.h" +#include -void memcpy(unsigned char *a2, unsigned char *a1, int bytes) +void memcpy(void *dest, void *src, int bytes) { + char * cdest = dest; + char * csrc = src; while (bytes--) - *(a2++) = *(a1++); + *(cdest++) = *(csrc++); } -void memmove(unsigned char *dest, unsigned char *src, int bytes) +void memmove(void *dest, void *src, int bytes) { - if ((dest > src) && (dest <= (src + bytes))) + char * cdest = dest; + char * csrc = src; + if ((cdest > csrc) && (cdest <= (csrc + bytes))) { /* do it backwards! */ - dest += bytes; - src += bytes; + cdest += bytes; + csrc += bytes; while (bytes--) - *(--dest) = *(--src); + *(--cdest) = *(--csrc); } else while (bytes--) - *(dest++) = *(src++); + *(cdest++) = *(csrc++); } -int memcmp (unsigned char *a2, unsigned char *a1, int bytes) { +int memcmp (const char *a2, const char *a1, int bytes) { while (bytes--) { if (*(a2++) != *(a1++)) @@ -29,7 +34,7 @@ int memcmp (unsigned char *a2, unsigned char *a1, int bytes) { return 0; } -int strcmp (unsigned char *a2, unsigned char *a1) { +int strcmp (const char *a2, const char *a1) { while (1) { if (*a2 != *a1) return 1; if (*a2 == 0) return 0; @@ -46,7 +51,7 @@ int strlen(char *c) return l; } -void strcpy(unsigned char *a2, unsigned char *a1) +void strcpy(char *a2, const char *a1) { do { *(a2++) = *a1; @@ -59,7 +64,7 @@ void puts(char *c) } static char hexarr[] = "0123456789ABCDEF"; -void tohex(unsigned char *s, unsigned long l) +void tohex(char *s, unsigned long l) { int i; for (i = 0; i < 8; i++) @@ -71,7 +76,7 @@ void tohex(unsigned char *s, unsigned long l) void puthex(unsigned long l) { - unsigned char d[9]; + char d[9]; d[8] = 0; tohex(d, l); puts(d);