bochs completed the first operating system in ten minutes

bochs completed the first operating system in ten minutes

Prepare a floppy image

insert image description here
The name of the floppy disk image here is a, img matches the configuration in .bochsrc

assembly code

Create the file boot.asm

org 07c00h
mov ax, cs
mov ds, ax
mov es, ax
call DispStr
jmp $
DispStr:
mov ax, BootMessage
mov bp, ax
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 号中断
ret
BootMessage: db "Hello, OS world!"
times 510 - ($-$$) db 0 ; 填充剩下的空间,使生成的二进制代码恰好为512字节
dw 0xaa55 ; 结束标志

Compile and run

 nasm boot.asm  -o boot.bin
 # 将编译结果装入软盘镜像
 dd if=boot.bin of=a.img bs=512 count=1 conv=notrunc
 # 运行
 ./bochs -qf .bochsrc

Press c to run in the running command line.

insert image description here
insert image description here

boot sector

What has just been completed is only one end of the boot sector.
When the computer is powered on, it will first perform a power-on self-test POST, and then look for a boot disk. If booting from a floppy disk, the computer will check the 0 side 0 track 1 sector of the floppy disk, if it ends with 0xAA55, the BIOS thinks it is a boot sector. Should include 512 bytes of execution code.
Once the BIOS finds the boot sector, it will load the 512-byte content into the memory address 0000:7c00, and then jump to 0000:7c00 to completely hand over the control to this boot code. At this point, the computer is no longer controlled by a program inherent in the BIOS, but by a part of the operating system.
The first line of code will have something like "org0x7c00". That's right, this line of code is to tell the compiler that our program will be loaded at the memory offset address 0x7c00 in the future.

Guess you like

Origin blog.csdn.net/greatcoder/article/details/128593273