From 5a65458c5625eb62a832690396e591cb845c150a Mon Sep 17 00:00:00 2001 From: ridethepig Date: Fri, 16 Sep 2022 17:40:58 +0800 Subject: [PATCH] finish --- .gitignore | 2 ++ Makefile | 19 +++++++++++++++++++ boot.asm | 31 ++++++++++++++++++++++--------- 3 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7cf5001 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.bin +*.img diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f9538d8 --- /dev/null +++ b/Makefile @@ -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 \ No newline at end of file diff --git a/boot.asm b/boot.asm index e6a71cf..6fcced4 100644 --- a/boot.asm +++ b/boot.asm @@ -3,16 +3,29 @@ mov ds, ax mov es, ax call DispStr ; 调用显示字符串例程 - jmp $ ; 无限循环 + 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 - int 10h ; 10h 号中断 + 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 ; 结束标志