+CFLAGS=-I../include
+
all: aseg.elf
aseg.bin: aseg.asm
aseg.o: aseg.bin
objcopy -I binary -B i386 -O elf32-i386 aseg.bin aseg.o
-aseg.elf: aseg.o aseg.lds counter.o
- ld -o aseg.elf -T aseg.lds counter.o
+aseg.elf: aseg.o aseg.lds counter.o ../pci/pci-smm.o
+ ld -o aseg.elf -T aseg.lds counter.o ../pci/pci-smm.o
mov ss, ax
mov esp, [dataptr]
-; mov al, [cstat]
-; add al, 1
-; out 0x80, al
-; mov [cstat], al
-
- mov dx, 0xCF8 ; save off the old config value
- in dword eax, dx
- mov [esp-4], eax
-
- mov eax, 0x80000070 ; load in smramc
- out dx, eax
- mov dx, 0xCFC
- in byte al, dx
- mov [esp-5], al
- and al, 0xF3 ; Allow graphics access
- or al, 0x08
- out dx, al
-
- xor eax, eax
- mov dx, 0x3D4
- in byte al, dx
- mov [esp-6], al ; save off the old VGA command
- mov al, 0xC
- out dx, al
- inc dx
- in al, dx
- mov ah, al
- dec dx
- mov al, 0xD
- out dx, al
- inc dx
- in al, dx
- shl eax, 1
- add eax, 0xB8000 ; yay
- mov byte [eax+0], '1'
- mov byte [eax+1], 0x1F
- mov byte [eax+2], '5'
- mov byte [eax+3], 0x1F
- mov byte [eax+4], '-'
- mov byte [eax+5], 0x1F
- mov byte [eax+6], '4'
- mov byte [eax+7], 0x1F
- mov byte [eax+8], '1'
- mov byte [eax+9], 0x1F
- mov byte [eax+10], '2'
- mov byte [eax+11], 0x1F
-
- mov dx, 0x3D4 ; restore the old stuff
- mov al, [esp-6]
- out dx, al
-
- mov dx, 0xCFC ; restore smramc
- mov al, [esp-5]
- out dx, al
-
- mov dx, 0xCF8 ; restore the old PCI config value
- mov eax, [esp-4]
- out dx, eax
-
mov al, [needclear]
cmp al, 0
jz noclear
rsm ; and leave SMM
-needclear:
- db 0x01
-
align 0x4
gdtr:
db 0x27, 0x00
db 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x9B, 0xCF, 0x00 ; code segment
db 0xFF, 0xFF, 0x00, 0x80, 0x0A, 0x9B, 0xCF, 0x00 ; code segment for trampoline
-cstat:
- db 0x00
+needclear:
+ db 0x01
-TIMES 512-($-$$) DB 0
dataptr:
; 4 bytes of stack top
; 4 bytes of BSS start
; 4 bytes of BSS length
- ; 4 bytes of C entry point
\ No newline at end of file
+ ; 4 bytes of C entry point
+ ; These show up
+#include <io.h>
+
char counter = 0;
+unsigned long pcisave;
+unsigned char vgasave;
+unsigned char thestr[512];
-#define outb(port, val) \
-({ asm volatile("outb %0, %%dx" : : "a" ((unsigned char)(val)) , "d" ((unsigned short)(port))); })
+void memcpy(char *dst, char *src, int c)
+{
+ while (c--)
+ *(dst++) = *(src++);
+}
+
+void strcpy(char *dst, char *src)
+{
+ while (*src)
+ *(dst++) = *(src++);
+}
+
+unsigned char vgaread(unsigned char idx)
+{
+ outb(0x3D4, idx);
+ inb(0x3D5);
+}
+
+void strblit(char *src)
+{
+ char *destp = (char*)(0xB8000 | (vgaread(0xC) << 5) | (vgaread(0xD) << 1));
+ while (*src)
+ {
+ *(destp++) = *(src++);
+ *(destp++) = 0x1F;
+ }
+}
void __start (void)
{
+ unsigned char smramc;
+
+ pcisave = inl(0xCF8);
+ vgasave = inb(0x3D4);
+
counter++;
- outb (0x80, counter);
+ outb(0x80, counter);
+
+ strcpy(thestr, "15-412!");
+
+ smramc = pci_read8(0, 0, 0, 0x70);
+ pci_write8(0, 0, 0, 0x70, (smramc & 0xF3) | 0x08);
+ strblit(thestr);
+ pci_write8(0, 0, 0, 0x70, smramc);
+
+ outl(0xCF8, pcisave);
+ outb(0x3D4, vgasave);
}
--- /dev/null
+#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))); })
+
+#endif
--- /dev/null
+#include <io.h>
+#include <inttypes.h>
+
+static void __pci_config(int bus, int slot, int fn, int addr)
+{
+ outl(0xCF8, 0x80000000ULL | (bus << 16) | (slot << 11) | (fn << 8) | addr);
+}
+
+void pci_write32(int bus, int slot, int fn, int addr, uint32_t data)
+{
+ __pci_config(bus, slot, fn, addr);
+ outl(0xCFC, data);
+}
+
+void pci_write16(int bus, int slot, int fn, int addr, uint16_t data)
+{
+ __pci_config(bus, slot, fn, addr);
+ outw(0xCFC, data);
+}
+
+void pci_write8(int bus, int slot, int fn, int addr, uint8_t data)
+{
+ __pci_config(bus, slot, fn, addr);
+ outb(0xCFC, data);
+}
+
+uint32_t pci_read32(int bus, int slot, int fn, int addr)
+{
+ __pci_config(bus, slot, fn, addr);
+ return inl(0xCFC);
+}
+
+uint16_t pci_read16(int bus, int slot, int fn, int addr)
+{
+ __pci_config(bus, slot, fn, addr);
+ return inw(0xCFC);
+}
+
+uint8_t pci_read8(int bus, int slot, int fn, int addr)
+{
+ __pci_config(bus, slot, fn, addr);
+ return inb(0xCFC);
+}