]> Joshua Wise's Git repositories - netwatch.git/commitdiff
SMRAM interface changes, and a few misc. header changes.
authorJoshua Wise <joshua@rebirth.joshuawise.com>
Sat, 13 Sep 2008 03:20:12 +0000 (23:20 -0400)
committerJoshua Wise <joshua@rebirth.joshuawise.com>
Sat, 13 Sep 2008 03:20:12 +0000 (23:20 -0400)
  * 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.

13 files changed:
aseg/Makefile
grubload/Makefile
grubload/multiboot_c.c
ich2/smram-ich2.c
ich2/smram-ich2.h [new file with mode: 0644]
include/pci.h [moved from pci/pci.h with 96% similarity]
include/raw/io.h [moved from include/io.h with 100% similarity]
include/raw/stdint.h [moved from include/stdint.h with 100% similarity]
include/smram.h [new file with mode: 0644]
pci/pci-linux.c
pci/pci-raw.c
tools/Makefile
tools/smram-linux-tool.c

index 079c3a500537d71fb20b141e177109404df3203b..73939670e246de0b97dca8028aa074de2b7fdc91 100644 (file)
@@ -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
index e9fa1dfd07e74877623356a826c1254637088d24..f4f50e13a59a534d6923415d7434285acd461fea 100644 (file)
@@ -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
 
index 572c3fd3ee6d80cb86ad3b8764b64badf6df601e..990ffc65aecc045c0e45bab077da799b862d5812 100644 (file)
@@ -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));
index 1052f3b23f1b2f267bdf26dfb5e13327a5c19dea..20c2b8ac6b301b49a8ccd6cb3569996112c54490 100644 (file)
@@ -1,6 +1,10 @@
 #include "reg-82815.h"
+#include <pci.h>
+#include <smram.h>
 
-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 (file)
index 0000000..cd645c9
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __SMRAM_ICH2_H
+#define __SMRAM_ICH2_H
+
+typedef unsigned char smram_state_t;
+
+#endif
similarity index 96%
rename from pci/pci.h
rename to include/pci.h
index 729f9c0bc9f49aa1997589ef993bd0b5df1d4711..60b665f132f59480d1d99c47e14075ec39788b98 100644 (file)
--- a/pci/pci.h
@@ -1,6 +1,8 @@
 #ifndef PCI_H
 #define PCI_H
 
+#include <stdint.h>
+
 /* 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.
similarity index 100%
rename from include/io.h
rename to include/raw/io.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 (file)
index 0000000..6c4ac69
--- /dev/null
@@ -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
index 8880069f7e26cf2e112256cb205d2603949ab850..c957bd088a2f3dd886f7f2bccac406070d819b5c 100644 (file)
@@ -4,7 +4,7 @@
 #include <stdio.h>
 #include <inttypes.h>
 
-#include "pci.h"
+#include "../include/pci.h"
 
 static int _open(int bus, int slot, int fn)
 {
index 4747ffdffe82853283af3fe807cce528559a7ac5..1d59208981e263cadc22345f3b22b5e4b2f100c3 100644 (file)
@@ -1,6 +1,6 @@
 #include <io.h>
 #include <stdint.h>
-#include "pci.h"
+#include <pci.h>
 
 static void __pci_config(int bus, int slot, int fn, int addr)
 {
index 35f37d45eac03b2bdb1f9f43ac0fea3783de7431..df153409b352bdbe4a4ade9bb3c7249b34f197fc 100644 (file)
@@ -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)
index 0d47bb4b63a0b477a1a34daf1473e2fd151e7ef0..0511f6be493fcef6733b6ae104d33d96c518f5bb 100644 (file)
@@ -2,6 +2,7 @@
 #include <getopt.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <smram.h>
 
 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;
This page took 0.043856 seconds and 4 git commands to generate.