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 ../ich2/smi.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 ../ich2/smi.o
all: aseg.elf
#include <io.h>
+#include <smram.h>
+#include <video_defines.h>
+#include <minilib.h>
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)
}
void pci_dump() {
- unsigned char s[40];
+ char s[40];
unsigned long cts;
static int curdev = 0; /* 0 if kbd, 1 if mouse */
void __start (void)
{
- unsigned char smramc;
static int first = 1;
pcisave = inl(0xCF8);
}
if (inl(0x834) & ~(0x4160))
{
- unsigned char s[40];
+ char s[40];
strcpy(s, "Unknown: xxxxxxxx");
tohex(s + 9, inl(0x834) & ~(0x140));
dolog(s);
#include <io.h>
#include <smi.h>
+#include <pci.h>
void __firstrun_start() {
/*
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) {
-#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
#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
#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
#include <console.h>
#include "console-ext.h"
+#include <minilib.h>
#include <io.h>
#define POS_IS_VALID(row, col) ((row) >= 0 && (row) < CONSOLE_HEIGHT && (col) >= 0 && (col) < CONSOLE_WIDTH)
#include "console.h"
+#include <minilib.h>
-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++))
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;
return l;
}
-void strcpy(unsigned char *a2, unsigned char *a1)
+void strcpy(char *a2, const char *a1)
{
do {
*(a2++) = *a1;
}
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++)
void puthex(unsigned long l)
{
- unsigned char d[9];
+ char d[9];
d[8] = 0;
tohex(d, l);
puts(d);