续1个人开发操作系统之初篇
本文任务是读取软盘18个Sector,编写video.s显示8bit,320*200黑屏,并进入32bit保护模式,编写func.s 和bootpack.c显示白屏,并用编写Makefile编译源文件。
1. boot.s读入18个sector
reading:
mov ax,0x0820
mov es,ax ;0x0820(es) * 16=0x8200 ;第二个Sector的数据读入到内存的0x8200地址。
mov ch,0 ;track/cylinder number
mov dh,0 ;head number
mov cl,2 ;sector number
readloop:
mov si,0 ; count failure times
retry:
;http://en.wikipedia.org/wiki/BIOS_interrupt_call#INT_13h_AH.3D02h:_Read_Sectors_From_Drive
mov ah,0x02 ;status of reading disk sector
mov al,1 ;number of sectors read
mov bx,0 ;0x0820(es) * 16 + 0(bx)=0x8200, 0x7e00~0x9fbff之间
mov dl,0x00 ;A drive
int 0x13 ;Read
jnc next ;no error goto next
add si,1 ;si +1
cmp si,5 ;compare 5
jae error ;goto error
mov ah,0x00 ;
mov dl,0x00 ; a drive
int 0x13 ; drive reset
jmp retry
next:
mov ax,es ; add 0x200(512)
add ax,0x20
mov es,ax
add cl,1 ;cl+1
cmp cl,18 ;compare 18,18 sectors
jbe readloop ;<18,continue
mov cl,1
add dh,1
cmp dh,2 ;读完正面18个Sector后,读反面18个
jb readloop ;dh<2 goto readloop
mov dh,0
add ch,1
cmp ch,CYLS
jb readloop ;ch<CYLS goto readloop
2. 调到video.s
;读完所有数据后,调到0x8200位置
fin:
mov [0x0ff0],ch ;remember the position of cylinder
JMP 0x8200 ;jump to video.s
hlt ;cpu停止