Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Initial commit
[erase-mbr.git] / erase-mbr.s
1 ;;; Bootsector to erase MBR
2 ;;; Compile with: as86 -b erase-mbr.o -s erase-mbr.sym erase-mbr.s
3 ;;; Copyright (c) 2009, Arnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
4
5 use16
6
7 .org 0x7c00
8         
9 start:
10         xor ax, ax
11         mov ds, ax
12         mov es, ax
13         
14         mov bp, #str_message
15         call puts
16
17         ;; clear 512 bytes
18         xor ax, ax
19         mov di, #(endflag + 2)
20         mov cx, #256
21         cld
22         rep
23         stosw
24         
25         ;; erase MBR
26         mov ax, #0x0301
27         mov dx, #0x0080
28         mov cx, #0x0001
29         mov bx, #(endflag + 2)
30         int 0x13
31         jc error
32         mov bp, #str_done
33         call puts
34         jmp clrkb
35
36 error:
37         mov bx, ax
38         shr ax, #12
39         shr bx, #8
40         and bx, #0x000f
41
42         cld
43         mov di, #error_code
44         mov si, #hex_digits
45         add si, ax
46         movsb
47         mov si, #hex_digits
48         add si, bx
49         movsb
50
51         mov bp, #str_error
52         call puts
53         
54 clrkb:  
55         ;; clear keyboard buffer
56         mov ah, #0x01
57         int 0x16
58         jz clrkb_end
59         mov ah, #0x00
60         int 0x16
61         jmp clrkb
62 clrkb_end:      
63
64         ;; wait for any key
65         mov bp, #str_reboot
66         call puts
67         mov ah, #0x00
68         int 0x16
69
70         ;; reboot
71         mov ax, #0x0040
72         mov es, ax
73         mov di, #0x0072
74         mov ax, #0x0000
75         stosw
76         jmp 0xffff:0000
77
78 ;;; INPUT
79 ;;; es:bp       asciz string address
80 ;;; OUTPUT
81 ;;;             string is printed on screen
82 ;;; MODIFIED
83 ;;; ax, bx, cx, dx, di 
84 puts:
85         ;;  current screen page -> bh
86         mov ah, #0x0f
87         int 0x10
88         ;; cursor position -> dh:dl
89         mov ah, #0x03
90         int 0x10
91         ;; compute string length
92         mov di, bp
93         mov al, #0
94         mov cx, #0xffff
95         cld
96         repne
97         scasb
98         neg cx
99         add cx, #0xfffe
100         ;; print string
101         mov bl, #0x07
102         mov ax, #0x1301
103         int 0x10
104         ret
105
106 ;;; DATA
107 hex_digits:     
108         .ascii "0123456789ABCDEF"
109 str_message:
110         .asciz "Erasing partition table..."
111 str_done:
112         .asciz " done.\n\r"
113 str_error:
114         .ascii " ERROR "
115 error_code:     
116         .ascii "??"
117         .asciz ".\n\r"
118 str_reboot:
119         .asciz "Press any key to reboot.\n\r"
120         
121 padding:        
122         .space (512 - 2) - (padding - start)
123 endflag:        
124         dw 0xaa55