From: Joshua Wise Date: Sat, 13 Sep 2008 03:20:12 +0000 (-0400) Subject: SMRAM interface changes, and a few misc. header changes. X-Git-Url: http://git.joshuawise.com/netwatch.git/commitdiff_plain/81148fa15713ee68be49610206526d0725a5868f?hp=-c SMRAM interface changes, and a few misc. header changes. * Created a header file that currently hard points to ich2.h. * Allows for saving and restoring of SMRAM state. * Moved PCI to include. * Moved conflicting includes to include/raw, which is only included on non-Linux build targets. * Fixed some messages here and there. --- 81148fa15713ee68be49610206526d0725a5868f diff --git a/aseg/Makefile b/aseg/Makefile index 079c3a5..7393967 100644 --- a/aseg/Makefile +++ b/aseg/Makefile @@ -1,5 +1,5 @@ CC=gcc -CFLAGS=-I../include -nostdlib -nostdinc -fno-builtin +CFLAGS=-I../include -I../include/raw -nostdlib -nostdinc -fno-builtin OBJS=counter.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o all: aseg.elf diff --git a/grubload/Makefile b/grubload/Makefile index e9fa1df..f4f50e1 100644 --- a/grubload/Makefile +++ b/grubload/Makefile @@ -1,6 +1,6 @@ OBJS=multiboot_c.o multiboot_asm.o realmode.o loader.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o CC=gcc -CFLAGS=-nostdlib -I../include -I. -fno-builtin -nostdinc +CFLAGS=-nostdlib -I../include -I../include/raw -I. -fno-builtin -nostdinc all: multiboot diff --git a/grubload/multiboot_c.c b/grubload/multiboot_c.c index 572c3fd..990ffc6 100644 --- a/grubload/multiboot_c.c +++ b/grubload/multiboot_c.c @@ -30,21 +30,18 @@ void c_start(unsigned int magic, struct mb_info *wee) void (*realmode)() = (void (*)()) 0x4000; - puts("Magic is: "); - puthex(magic); - puts("\nMultiboot header is: "); - puthex(wee); - puts("\n"); show_cursor(); + puts("NetWatch loader\n"); + + if (magic != 0x2BADB002) + { + puts("Bootloader was not multiboot compliant; cannot continue.\n"); + while(1) asm("hlt"); + } - puts("Grubptr is: "); - puthex(*grubptr); - puts("\n"); - - for (i = 0; i < wee->mod_cnt; i++) { - puts("Module:\n"); + puts("Module found:\n"); puts(" Start: "); puthex(wee->mods[i].mod_start); puts("\n"); puts(" Size: "); puthex(wee->mods[i].mod_end - wee->mods[i].mod_start); puts("\n"); puts(" Name: "); puts(wee->mods[i].mod_string); puts("\n"); @@ -60,7 +57,7 @@ void c_start(unsigned int magic, struct mb_info *wee) puts("Current SMI state is: "); puthex(inl(0x830)); puts("\n"); puts("Current SMRAMC state is: "); puthex(pci_read8(0, 0, 0, 0x70)); puts("\n"); - outl(0x830, inl(0x830) & ~0x2001); /* turn off SMIs */ + outl(0x830, inl(0x830) & ~0x1); /* turn off SMIs */ /* Try really hard to shut up USB_LEGKEY. */ pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0)); diff --git a/ich2/smram-ich2.c b/ich2/smram-ich2.c index 1052f3b..20c2b8a 100644 --- a/ich2/smram-ich2.c +++ b/ich2/smram-ich2.c @@ -1,6 +1,10 @@ #include "reg-82815.h" +#include +#include -unsigned long memsz[] = { +#ifdef __linux__ + +static unsigned long memsz[] = { 0, // 0 32*1024*1024, // 1 32*1024*1024, // 2 @@ -19,8 +23,6 @@ unsigned long memsz[] = { 512*1024*1024 // F }; -#ifdef __linux__ - void smram_aseg_dump(void) { unsigned char smramc, drp, drp2; @@ -78,25 +80,50 @@ void smram_aseg_dump(void) { } #endif +int smram_locked() +{ + unsigned char smramc = pci_read8(0, 0, 0, SMRAMC); + + return (smramc & SMRAMC_LOCK) ? 1 : 0; +} + +smram_state_t smram_save_state() +{ + return pci_read8(0, 0, 0, SMRAMC); +} + +void smram_restore_state(smram_state_t state) +{ + return pci_write8(0, 0, 0, SMRAMC, state); +} + int smram_aseg_set_state (int open) { unsigned char smramc; + + if (smram_locked()) + return -1; + smramc = pci_read8(0, 0, 0, SMRAMC); - if (smramc & SMRAMC_LOCK) + switch (open) { - /* SMRAM is locked; can't load anything. */ - return 1; - } - - if (open) { - /* Set LSMM to 01 (ABseg = system RAM) */ + case SMRAM_ASEG_CLOSED: + smramc = (smramc & 0xF0) | 0x00; + break; + case SMRAM_ASEG_OPEN: smramc = (smramc & 0xF0) | 0x04; - } else { - /* Set LSMM to 11 (ABseg = SMM RAM) */ + break; + case SMRAM_ASEG_SMMCODE: + smramc = (smramc & 0xF0) | 0x08; + break; + case SMRAM_ASEG_SMMONLY: smramc = (smramc & 0xF0) | 0x0C; + break; + default: + return -1; } - pci_write8(0, 0, 0, SMRAMC); + pci_write8(0, 0, 0, SMRAMC, smramc); return 0; } diff --git a/ich2/smram-ich2.h b/ich2/smram-ich2.h new file mode 100644 index 0000000..cd645c9 --- /dev/null +++ b/ich2/smram-ich2.h @@ -0,0 +1,6 @@ +#ifndef __SMRAM_ICH2_H +#define __SMRAM_ICH2_H + +typedef unsigned char smram_state_t; + +#endif diff --git a/pci/pci.h b/include/pci.h similarity index 96% rename from pci/pci.h rename to include/pci.h index 729f9c0..60b665f 100644 --- a/pci/pci.h +++ b/include/pci.h @@ -1,6 +1,8 @@ #ifndef PCI_H #define PCI_H +#include + /* General PCI functions. This is implemented by pci-linux.c and pci-raw.c; the * former uses Linux's /proc/bus/pci interface for access from userspace, while * the latter accesses the PCI hardware directly. diff --git a/include/io.h b/include/raw/io.h similarity index 100% rename from include/io.h rename to include/raw/io.h diff --git a/include/stdint.h b/include/raw/stdint.h similarity index 100% rename from include/stdint.h rename to include/raw/stdint.h diff --git a/include/smram.h b/include/smram.h new file mode 100644 index 0000000..6c4ac69 --- /dev/null +++ b/include/smram.h @@ -0,0 +1,16 @@ +#ifndef __SMRAM_H +#define __SMRAM_H + +#include "../ich2/smram-ich2.h" + +extern int smram_locked(); +extern smram_state_t smram_save_state(); +extern void smram_restore_state(smram_state_t state); +extern int smram_aseg_set_state (int open); + +#define SMRAM_ASEG_CLOSED 0 /* SMRAM is not readable. */ +#define SMRAM_ASEG_OPEN 1 /* SMRAM is readable by everybody. */ +#define SMRAM_ASEG_SMMCODE 2 /* SMRAM is readable as SMM code only. */ +#define SMRAM_ASEG_SMMONLY 3 /* SMRAM is readable as SMM code and data only. */ + +#endif diff --git a/pci/pci-linux.c b/pci/pci-linux.c index 8880069..c957bd0 100644 --- a/pci/pci-linux.c +++ b/pci/pci-linux.c @@ -4,7 +4,7 @@ #include #include -#include "pci.h" +#include "../include/pci.h" static int _open(int bus, int slot, int fn) { diff --git a/pci/pci-raw.c b/pci/pci-raw.c index 4747ffd..1d59208 100644 --- a/pci/pci-raw.c +++ b/pci/pci-raw.c @@ -1,6 +1,6 @@ #include #include -#include "pci.h" +#include static void __pci_config(int bus, int slot, int fn, int addr) { diff --git a/tools/Makefile b/tools/Makefile index 35f37d4..df15340 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,2 +1,6 @@ -smram-ich2: smram-linux-tool.c ../pci/pci-linux.c ../ich2/smram-ich2.c - gcc -o smram-ich2 smram-linux-tool.c ../pci/pci-linux.c ../ich2/smram-ich2.c +CFLAGS=-I../include +CC=gcc +SMRAM_ICH2_OBJS=smram-linux-tool.o ../pci/pci-linux.o ../ich2/smram-ich2.o + +smram-ich2: $(SMRAM_ICH2_OBJS) + gcc -o smram-ich2 $(SMRAM_ICH2_OBJS) diff --git a/tools/smram-linux-tool.c b/tools/smram-linux-tool.c index 0d47bb4..0511f6b 100644 --- a/tools/smram-linux-tool.c +++ b/tools/smram-linux-tool.c @@ -2,6 +2,7 @@ #include #include #include +#include static struct option longopts[] = { { "open", no_argument, NULL, 'o' }, @@ -24,7 +25,7 @@ int main(int argc, char **argv) { if (geteuid() != 0) { - printf("This program must be run as root, dumbass.\n"); + printf("%s: This program must be run as root.\n", argv[0]); return 1; } @@ -61,7 +62,7 @@ int main(int argc, char **argv) if (op & OP_SET) { - smram_aseg_set_state(do_open); + smram_aseg_set_state(do_open ? SMRAM_ASEG_OPEN : SMRAM_ASEG_SMMONLY); } return 0;