]> Joshua Wise's Git repositories - netwatch.git/commitdiff
Move more functionality out to C
authorJoshua Wise <joshua@rebirth.joshuawise.com>
Sat, 6 Sep 2008 00:42:56 +0000 (20:42 -0400)
committerJoshua Wise <joshua@rebirth.joshuawise.com>
Sat, 6 Sep 2008 00:42:56 +0000 (20:42 -0400)
aseg/Makefile
aseg/aseg.asm
aseg/counter.c
include/io.h [new file with mode: 0644]
pci/pci-smm.c [new file with mode: 0644]

index 20e5ae9f6f663a3527609213b0b89b470cd50031..56764890d90c773918f2d1cb954164e77e0e54dd 100644 (file)
@@ -1,3 +1,5 @@
+CFLAGS=-I../include
+
 all: aseg.elf
 
 aseg.bin: aseg.asm
@@ -6,5 +8,5 @@ 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
index 244cafc359f3ae87669952727d914f2d43b9f0ed..93b61d75c0f0a8047ed8a1a2e999c84e5d7547ab 100644 (file)
@@ -23,65 +23,6 @@ continue:
        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
@@ -109,9 +50,6 @@ noclear:
 
        rsm                             ; and leave SMM
 
-needclear:
-       db 0x01
-
        align 0x4
 gdtr:
        db 0x27, 0x00
@@ -123,12 +61,12 @@ gdt:
        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 
index edad0217a4a258607d1b55b992ba64c697a176ca..de82574dc50fac9245e3ee564feb3569d174ea04 100644 (file)
@@ -1,11 +1,56 @@
+#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);
 }
 
diff --git a/include/io.h b/include/io.h
new file mode 100644 (file)
index 0000000..5fd0b19
--- /dev/null
@@ -0,0 +1,11 @@
+#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
diff --git a/pci/pci-smm.c b/pci/pci-smm.c
new file mode 100644 (file)
index 0000000..117a8b5
--- /dev/null
@@ -0,0 +1,43 @@
+#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);
+}
This page took 0.032331 seconds and 4 git commands to generate.