* 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:
-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
OBJS=counter.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o
all: aseg.elf
OBJS=multiboot_c.o multiboot_asm.o realmode.o loader.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o
CC=gcc
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
void (*realmode)() = (void (*)()) 0x4000;
void (*realmode)() = (void (*)()) 0x4000;
- puts("Magic is: ");
- puthex(magic);
- puts("\nMultiboot header is: ");
- puthex(wee);
- puts("\n");
+ 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++)
{
for (i = 0; i < wee->mod_cnt; i++)
{
+ 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");
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");
puts("Current SMI state is: "); puthex(inl(0x830)); puts("\n");
puts("Current SMRAMC state is: "); puthex(pci_read8(0, 0, 0, 0x70)); puts("\n");
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));
/* Try really hard to shut up USB_LEGKEY. */
pci_write16(0, 31, 2, 0xC0, pci_read16(0, 31, 2, 0xC0));
+#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
0, // 0
32*1024*1024, // 1
32*1024*1024, // 2
void smram_aseg_dump(void) {
unsigned char smramc, drp, drp2;
void smram_aseg_dump(void) {
unsigned char smramc, drp, drp2;
+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;
int smram_aseg_set_state (int open) {
unsigned char smramc;
+
+ if (smram_locked())
+ return -1;
+
smramc = pci_read8(0, 0, 0, SMRAMC);
smramc = pci_read8(0, 0, 0, SMRAMC);
- if (smramc & SMRAMC_LOCK)
- /* 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;
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;
smramc = (smramc & 0xF0) | 0x0C;
+ break;
+ default:
+ return -1;
- pci_write8(0, 0, 0, SMRAMC);
+ pci_write8(0, 0, 0, SMRAMC, smramc);
--- /dev/null
+#ifndef __SMRAM_ICH2_H
+#define __SMRAM_ICH2_H
+
+typedef unsigned char smram_state_t;
+
+#endif
#ifndef PCI_H
#define PCI_H
#ifndef PCI_H
#define PCI_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.
/* 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.
--- /dev/null
+#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
#include <stdio.h>
#include <inttypes.h>
#include <stdio.h>
#include <inttypes.h>
+#include "../include/pci.h"
static int _open(int bus, int slot, int fn)
{
static int _open(int bus, int slot, int fn)
{
#include <io.h>
#include <stdint.h>
#include <io.h>
#include <stdint.h>
static void __pci_config(int bus, int slot, int fn, int addr)
{
static void __pci_config(int bus, int slot, int fn, int addr)
{
-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)
#include <getopt.h>
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include <stdio.h>
static struct option longopts[] = {
{ "open", no_argument, NULL, 'o' },
static struct option longopts[] = {
{ "open", no_argument, NULL, 'o' },
- printf("This program must be run as root, dumbass.\n");
+ printf("%s: This program must be run as root.\n", argv[0]);
- smram_aseg_set_state(do_open);
+ smram_aseg_set_state(do_open ? SMRAM_ASEG_OPEN : SMRAM_ASEG_SMMONLY);