]> Joshua Wise's Git repositories - netwatch.git/commitdiff
Merge nyus.joshuawise.com:/storage/git/netwatch
authorJoshua Wise <joshua@rebirth.joshuawise.com>
Fri, 5 Sep 2008 21:42:14 +0000 (17:42 -0400)
committerJoshua Wise <joshua@rebirth.joshuawise.com>
Fri, 5 Sep 2008 21:42:14 +0000 (17:42 -0400)
aseg/Makefile [new file with mode: 0644]
aseg/aseg.asm
aseg/aseg.lds [new file with mode: 0644]
aseg/counter.c [new file with mode: 0644]

diff --git a/aseg/Makefile b/aseg/Makefile
new file mode 100644 (file)
index 0000000..5bef71f
--- /dev/null
@@ -0,0 +1,10 @@
+all: aseg.elf
+
+aseg.bin: aseg.asm
+       nasm -o aseg.bin aseg.asm
+
+aseg.o: aseg.bin
+       objcopy -I binary -B i386 -O elf32-i386 aseg.bin aseg.o
+
+aseg.elf: aseg.bin aseg.lds counter.o
+       ld -o aseg.elf -T aseg.lds counter.o
index 51a28111986652c96ce4ca90daed569a721bf123..ee83272652e66bf3595dd8129eecc6c857b2efb3 100644 (file)
@@ -1,48 +1,33 @@
-       org 0x0
+       org 0xA8000
 [bits 16]
 entry:
-;      mov al, 0x01            ; Say where we are.
-;      out 0x80, al
        mov ax, 0xA800
        mov ds, ax              ; Take us out of flat unreal mode, and
        mov es, ax              ; put us in true real mode.
        mov fs, ax
        mov gs, ax
        mov ss, ax
-       jmp 0xA800:entry2               ; Long jump to a correct cs.
+       jmp 0xA800:(entry2-0xA8000)     ; Long jump to a correct cs.
 entry2:
-;      mov al, 0x02
-;      out 0x80, al
-       lgdt [gdtr]                     ; Set up a new GDT.
+       lgdt [(gdtr-0xA8000)]           ; Set up a new GDT.
        mov eax, 0x1
        mov cr0, eax                    ; ... and enter pmode!
-       mov al, 0x03                    ; Say we got here.
-       out 0x80, al
-       jmp long 0x10:(continue+0xA8000)        ; Now longjmp into the new code.
+       jmp long 0x10:continue          ; Now longjmp into the new code.
 [bits 32]
 continue:
-;      mov al, 0x04                    ; Now we're in protected mode.
-;      out 0x80, al
-       
        mov ax, 0x08                    ; Set up segment selectors.
        mov ds, ax
        mov es, ax
        mov fs, ax
        mov gs, ax
        mov ss, ax
-       mov esp, 0x1fffffff
+       mov esp, [dataptr]
 
-;      mov al, 0x05
+;      mov al, [cstat]
+;      add al, 1
 ;      out 0x80, al
-
-       mov al, [(cstat + 0xA8000)]
-       add al, 1
-       out 0x80, al
-       mov [(cstat + 0xA8000)], al
+;      mov [cstat], al
        
-       mov eax, 0x11223344
-       mov dword [(status + 0xA8000)], eax
-
        mov dx, 0xCF8                   ; save off the old config value
        in dword eax, dx
        mov [esp-4], eax
@@ -73,26 +58,33 @@ continue:
        shl eax, 1
        add eax, 0xB8000                ; yay
        mov byte [eax+0], '1'
-       mov byte [eax+1], 0xA0
+       mov byte [eax+1], 0x1F
        mov byte [eax+2], '5'
-       mov byte [eax+3], 0xA0
+       mov byte [eax+3], 0x1F
        mov byte [eax+4], '-'
-       mov byte [eax+5], 0xA0
+       mov byte [eax+5], 0x1F
        mov byte [eax+6], '4'
-       mov byte [eax+7], 0xA0
+       mov byte [eax+7], 0x1F
        mov byte [eax+8], '1'
-       mov byte [eax+9], 0xA0
+       mov byte [eax+9], 0x1F
        mov byte [eax+10], '2'
-       mov byte [eax+11], 0xA0
+       mov byte [eax+11], 0x1F
        
-       mov dx, 0x3D4
+       mov dx, 0x3D4                   ; restore the old stuff
        mov al, [esp-6]
        out dx, al
-       
+
+       mov al, 0
+       mov edi, [dataptr+4]            ; clear BSS
+       mov ecx, [dataptr+8]
+       rep stosb
 
        mov dx, 0xCFC                   ; restore smramc
        mov al, [esp-5]
        out dx, al
+       
+       mov eax, [dataptr+12]
+       call eax
 
        mov dx, 0xCF8                   ; restore the old config value
        mov eax, [esp-4]
@@ -115,7 +107,7 @@ continue:
        align 0x4
 gdtr:
        db 0x27, 0x00
-       dd (gdt + 0xA8000)
+       dd gdt
        align 0x4
 gdt:
        db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
@@ -123,8 +115,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
 
-TIMES   512-($-$$) DB 0
-status:
-       dd 0xAA55AA55
 cstat:
        db 0x00
+
+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
diff --git a/aseg/aseg.lds b/aseg/aseg.lds
new file mode 100644 (file)
index 0000000..a3a8ece
--- /dev/null
@@ -0,0 +1,29 @@
+OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
+OUTPUT_ARCH(i386)
+SECTIONS
+{
+       . = 0xA8000;
+       .aseg : {
+               _start = .;
+               aseg.o
+               LONG(_stacktop);
+               LONG(_bss);
+               LONG(_bssend - _bss);
+               LONG(__start);
+               *(.text);
+               *(.data);
+               *(.rodata);
+       }
+
+       . = 0x1FF80000;
+       .bss : {
+               _bss = .;
+               *(.bss);
+               _bssend = .;
+       }
+       .stack : { 
+               . = . + 0x10000;
+               . = ALIGN(0x10);
+               _stacktop = .;
+       }
+}
diff --git a/aseg/counter.c b/aseg/counter.c
new file mode 100644 (file)
index 0000000..891c075
--- /dev/null
@@ -0,0 +1,10 @@
+char counter = 0;
+
+#define outb(port, val) \
+({ asm volatile("outb %0, %%dx" : : "a" ((unsigned char)(val)) , "d" ((unsigned short)(port))); })
+
+void __start (void) {
+       counter++;
+       outb (0x80, counter);
+}
+
This page took 0.032866 seconds and 4 git commands to generate.