This commit is contained in:
ridethepig 2022-09-16 17:40:58 +08:00
parent 8ff1943441
commit 5a65458c56
3 changed files with 43 additions and 9 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.bin
*.img

19
Makefile Normal file
View File

@ -0,0 +1,19 @@
CC = gcc
ASM = nasm
QEMU = qemu
IMG = boot.bin
boot.bin: boot.asm
$(ASM) $< -o $@
compile: boot.bin
.DEFAULT_GOAL=compile
run: compile
$(QEMU) -boot order=c -drive file=$(IMG),format=raw
clean:
rm boot.bin
.PHONY: compile clean run

View File

@ -5,14 +5,27 @@
call DispStr ; 调用显示字符串例程
jmp $ ; 无限循环
DispStr:
mov ax, BootMessage
mov bp, ax ; ES:BP = 串地址
mov cx, 16 ; CX = 串长度
mov ax, 01301h ; AH = 13, AL = 01h
mov bx, 000ch ; 页号为0(BH = 0) 黑底红字(BL = 0Ch,高亮)
mov dl, 0
mov ax, 0600h
mov bx, 0h
mov cx, 0h
mov dh, 25-1
mov dl, 80-1 ; vga text-mode: 80x25
int 10h ; clear screen
mov ax, 0200h
mov bx, 0h
mov dx, 1326h ; 19=13H, 38=26H
int 10h ; set cursor position
mov ax, NWPU
mov bp, ax ; ES:BP = 串地址, es has been set to the same seg
mov cx, 4 ; CX = 串长度
mov ax, 01300h ; AH = 13, AL = 01h
mov bx, 00f9h ; 页号为0(BH = 0) 黑底红字(BL = 0Ch,高亮)
int 10h ; 10h 号中断
mov ax, 0200h
mov bx, 0h
mov dx, 0h
int 10H ; reset cursor to 0,0
ret
BootMessage: db "Hello, OS world!"
NWPU: db "NWPU"
times 510-($-$$) db 0 ; 填充剩下的空间使生成的二进制代码恰好为512字节
dw 0xaa55 ; 结束标志