summaryrefslogtreecommitdiff
path: root/bootloader.asm
blob: bf3afb49ee2508ed9bedffab61897ff0a34634a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
ORG	0x0
BITS	16

_start:
	jmp short start
	nop

; Setup dummy BIOS Parameter block so a dumb BIOS does not corrupt us
; if it starts messing up with the parameter block
	times 33 db 0

start:
	; Set CS to 0x07c0 with label step2 as its beginning offset
	jmp 0x07c0:step2

step2:
	; Setup segments

	cli		; Disable interrupts
	mov ax, 0x07c0
	mov ds, ax
	mov es, ax
	mov ax, 0x00
	mov ss, ax
	mov sp, 0x7c00	; Stack segment starts right before ds
			; and grows down to 0x0. This works because
			; Intel implements a full descending stack
	sti		; Enable interrupts

	jmp $


; Message Print routines
print:
	mov bx, 0
.loop
	lodsb
	cmp al, 0
	je .done
	call print_char
	jmp .loop
.done:
	ret

print_char:
	mov	ah, 0x0e
	int	0x10
	ret

; Fill in to the end and add bootloader signature
	times 510 - ($ - $$) db 0
	dw 0xAA55