Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Initial commit master
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Wed, 7 Apr 2010 18:16:50 +0000 (20:16 +0200)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Wed, 7 Apr 2010 18:16:50 +0000 (20:16 +0200)
Makefile [new file with mode: 0644]
erase-mbr.s [new file with mode: 0644]
gdbinit [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..c2ed361
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+ASM = $(wildcard *.s)
+OBJ = $(ASM:%.s=%.o)
+SYM = $(ASM:%.s=%.sym)
+
+.PHONY: all clean
+
+all: $(OBJ)
+
+clean:
+       $(RM) $(OBJ) $(SYM)
+
+%.o: %.s
+       as86 -w- -b $@ -s $*.sym $<
+
diff --git a/erase-mbr.s b/erase-mbr.s
new file mode 100644 (file)
index 0000000..7162db2
--- /dev/null
@@ -0,0 +1,124 @@
+;;; Bootsector to erase MBR
+;;; Compile with: as86 -b erase-mbr.o -s erase-mbr.sym erase-mbr.s
+;;; Copyright (c) 2009, Arnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
+
+use16
+
+.org 0x7c00
+        
+start:
+        xor ax, ax
+        mov ds, ax
+        mov es, ax
+        
+        mov bp, #str_message
+        call puts
+
+        ;; clear 512 bytes
+        xor ax, ax
+        mov di, #(endflag + 2)
+        mov cx, #256
+        cld
+        rep
+        stosw
+        
+        ;; erase MBR
+        mov ax, #0x0301
+        mov dx, #0x0080
+        mov cx, #0x0001
+        mov bx, #(endflag + 2)
+        int 0x13
+        jc error
+        mov bp, #str_done
+        call puts
+        jmp clrkb
+
+error:
+        mov bx, ax
+        shr ax, #12
+        shr bx, #8
+        and bx, #0x000f
+
+        cld
+        mov di, #error_code
+        mov si, #hex_digits
+        add si, ax
+        movsb
+        mov si, #hex_digits
+        add si, bx
+        movsb
+
+        mov bp, #str_error
+        call puts
+        
+clrkb:  
+        ;; clear keyboard buffer
+        mov ah, #0x01
+        int 0x16
+        jz clrkb_end
+        mov ah, #0x00
+        int 0x16
+        jmp clrkb
+clrkb_end:      
+
+        ;; wait for any key
+        mov bp, #str_reboot
+        call puts
+        mov ah, #0x00
+        int 0x16
+
+        ;; reboot
+        mov ax, #0x0040
+        mov es, ax
+        mov di, #0x0072
+        mov ax, #0x0000
+        stosw
+        jmp 0xffff:0000
+
+;;; INPUT
+;;; es:bp       asciz string address
+;;; OUTPUT
+;;;             string is printed on screen
+;;; MODIFIED
+;;; ax, bx, cx, dx, di 
+puts:
+        ;;  current screen page -> bh
+        mov ah, #0x0f
+        int 0x10
+        ;; cursor position -> dh:dl
+        mov ah, #0x03
+        int 0x10
+        ;; compute string length
+        mov di, bp
+        mov al, #0
+        mov cx, #0xffff
+        cld
+        repne
+        scasb
+        neg cx
+        add cx, #0xfffe
+        ;; print string
+        mov bl, #0x07
+        mov ax, #0x1301
+        int 0x10
+        ret
+
+;;; DATA
+hex_digits:     
+        .ascii "0123456789ABCDEF"
+str_message:
+        .asciz "Erasing partition table..."
+str_done:
+        .asciz " done.\n\r"
+str_error:
+        .ascii " ERROR "
+error_code:     
+        .ascii "??"
+        .asciz ".\n\r"
+str_reboot:
+        .asciz "Press any key to reboot.\n\r"
+        
+padding:        
+        .space (512 - 2) - (padding - start)
+endflag:        
+        dw 0xaa55
diff --git a/gdbinit b/gdbinit
new file mode 100644 (file)
index 0000000..86da1f3
--- /dev/null
+++ b/gdbinit
@@ -0,0 +1,5 @@
+layout regs
+target remote :1234
+set arch i8086
+set disassemble-next-line on
+break *0x7c00