]> wirehaze git hosting - lifeboot.git/blob - lifeboot.asm

wirehaze git hosting

a3b4658fbbf6f6c1839718c149188cc457a8587a
[lifeboot.git] / lifeboot.asm
1 bits 16
2 org 0x7c00
3
4 %define ORG 0x7c00 ; where we are loaded initially
5
6 %define VGA_SEG 0xb800 ; video memory starts at 0xb8000
7 %define VGA_COL 80
8 %define VGA_ROW 25
9 %define VGA_LENW VGA_COL * VGA_ROW
10
11 %define FILL_CHAR 0xfa ; middle dot
12 %define FILL_COLOR 0x04 ; red on black
13 %define PRINT_COLOR 0x07 ; grey on black
14
15 ; entry point -----------------------------------------------------------------
16
17 ; initialize segment registers
18 xor ax, ax
19 mov ds, ax
20 mov es, ax
21 mov ss, ax
22
23 ; set stack pointers
24 mov sp, ORG
25 mov bp, ORG
26
27 ; clear screen ----------------------------------------------------------------
28
29 ; disable cursor
30 mov ch, 0x3f
31 mov ah, 0x01
32 int 0x10
33
34 ; clear video memory
35 mov cx, VGA_LENW
36 mov ax, VGA_SEG
37 mov es, ax
38 xor di, di
39 mov ax, (FILL_COLOR << 8) | FILL_CHAR
40
41 rep stosw ; fill cx words at es:di with ax
42
43 ; errors ----------------------------------------------------------------------
44
45 hello:
46 mov si, str.hello
47
48 ; print the error message string in si and halt
49 ; note: we assume es = VGA_SEG and ds = 0
50 printerr:
51 xor di, di
52 mov ah, PRINT_COLOR
53
54 ; es:di = video memory
55 ; ds:si = error message
56 ; al = current char
57 ; ah = color attribute
58
59 write_char:
60 lodsb ; al = [ds:si], si += 1
61 or al, al ; on null terminator,
62 jz halt ; halt
63 stosw ; [es:di] = ax, di += 2
64 jmp write_char
65
66 halt:
67 cli ; disable interrupts
68 hlt
69 jmp halt
70
71 ; data ------------------------------------------------------------------------
72
73 str:
74 .hello:
75 db "lifeboot", 0
76
77 times 510 - ($ - $$) db 0 ; fill remaining bytes with zeroes
78 dw 0xaa55 ; mbr magic byte