Repository navigation
Expand file tree
/
Copy pathbootloader.asm
More file actions
62 lines (45 loc) · 1.49 KB
/
Copy pathbootloader.asm
File metadata and controls
62 lines (45 loc) · 1.49 KB
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
53
54
55
56
57
58
59
60
bits 16 ; Use 16-bit mode (the state a PC starts in)
[org 0x7c00]
mov ah, 0x0e ; BIOS teletype function to print a character
; Call BIOS video interrupt
%include "drivers/keyboard.asm"
%include "drivers/mouse.asm"
%include "drivers/disk.asm"
%include "drivers/network.asm"
call net_card_detect
call read_disk
call keylog
call mouse_handler
call update_cursor
[org 0x7c00]
bits 16
start:
; 1. Set up segment registers and stack
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0x7c00
; 2. Load the kernel from disk to 0x1000:0x0000
mov ah, 0x02 ; BIOS read sectors function
mov al, 10 ; Number of sectors to read (increase if kernel is large)
mov ch, 0x00 ; Cylinder 0
mov dh, 0x00 ; Head 0
mov cl, 0x02 ; Start at Sector 2 (Sector 1 is the bootloader)
; DL is already set to the boot drive by the BIOS
mov bx, 0x1000 ; Target Segment
mov es, bx
mov bx, 0x0000 ; Target Offset (ES:BX = 0x1000:0x0000)
int 0x13 ; Call BIOS
jc disk_err ; If carry flag is set, read failed
; 3. Jump to the kernel
jmp 0x1000:0x0000
disk_err:
mov ah, 0x0e
mov al, 'E'
int 0x10 ; Print 'E' if disk read fails
jmp $
call 0x1000:0x0000 ; Kernel init
jmp $ ; Jump to current address (infinite loop) to stop execution
times 510-($-$$) db 0 ; Fill the rest of the 512 bytes with zeros
dw 0xaa55 ; The "magic number" that tells BIOS this disk is bootable