bootstrap from floppy disk

bootsect.S is used to boostrap kernel from floppy disk, both zImage and bzImage.

BIOS load bootsect to 0x07c0:0000 and jump to it. 

 

  /* bootsect moves itself to 0x9000:0000 and jump to */

  mov ax,#BOOTSEG
  mov ds,ax
  mov ax,#INITSEG
  mov es,ax
  mov cx,#256
  sub si,si
  sub di,di
  cld
  rep
  movsw
  jmpi go,INITSE

 

 /* set stack to 0x9000:3ff4 */

go: mov di,#0x4000-12

  mov ds,ax
  mov ss,ax  ! put stack at INITSEG:0x4000-12.
  mov sp,di

 

 /* change maxinum sector number of disk parameter table (0x0000:0078) from default (e.g. 7) to 36 for multi-sector reading kernel image */

  mov fs,cx
  mov bx,#0x78  ! fs:bx is parameter table address
  push ds
  seg fs
  lds si,(bx)   ! ds:si is source

  mov cl,#6   ! copy 12 bytes
  cld
  push di

  rep
  movsw

  pop di
  pop ds

  movb 4(di),*36  ! patch sector count

  seg fs
  mov (bx),di
  seg fs
  mov 2(bx),es

 

/* load setup sectors (4 secotr from the second sector) to 0x9000:0200 */

load_setup:
  xor ah,ah   ! reset FDC
  xor dl,dl
  int  0x13 

  xor dx, dx   ! drive 0, head 0
  mov cl,#0x02  ! sector 2, track 0
  mov bx,#0x0200  ! address = 512, in INITSEG
  mov ah,#0x02  ! service 2, nr of sectors
  mov al,setup_sects  ! (assume all on head 0, track 0)
  int 0x13   ! read it
  jnc ok_load_setup  ! ok - continue

  push ax   ! dump error code
  call print_nl
  mov bp, sp
  call print_hex
  pop ax 

  jump load_setup


 /* get number of sectors per track, guess 36, 18, 15, 9 in order */

  mov si,#disksizes  ! table of sizes to try

probe_loop:
  lodsb
  cbw    ! extend to word
  mov sectors, ax
  cmp si,#disksizes+4
  jae got_sectors  ! if all else fails, try 9
  xchg ax, cx   ! cx = track and sector
  xor dx, dx   ! drive 0, head 0
  xor bl, bl
  mov bh,setup_sects
  inc bh
  shl bh,#1   ! address after setup (es = cs)
  mov ax,#0x0201  ! service 2, 1 sector
  int 0x13
  jc probe_loop  ! try next value

 

/* print "Loading" message */

  mov ax,#INITSEG
  mov es,ax

  mov ah,#0x03  ! read cursor pos
  xor bh,bh
  int 0x10
 
  mov cx,#9
  mov bx,#0x0007  ! page 0, attribute 7 (normal)
  mov bp,#msg1
  mov ax,#0x1301  ! write string, move cursor
  int 0x10

 

/* load kernel image from floppy disk to 0x1000:0000 */

  mov ax,#SYSSEG
  mov es,ax  ! segment of 0x010000
  call read_it
  call kill_motor
  call print_nl

 

/* read left bytes in current track */

ok1_read:
  mov ax,sectors
  sub ax,sread
  mov cx,ax
  shl cx,#9
  add cx,bx
  jnc ok2_read
  je ok2_read
  xor ax,ax
  sub ax,bx
  shr ax,#9

 

/* if current track is read out, then read head 1 if current one is 0,  otherwise reading next track */

ok2_read:
  call read_track
  mov cx,ax
  add ax,sread
  cmp ax,sectors
  jne ok3_read
  mov ax,#1
  sub ax,head
  jne ok4_read
  inc track
ok4_read:
  mov head,ax
  xor ax,a

 

/* add read bytes to bx, if exceed 64k, then change es to next segment, then continue */

ok3_read:
  mov sread,ax
  shl cx,#9
  add bx,cx
  jnc rp_read
  mov ax,es
  add ah,#0x10
  mov es,ax
  xor bx,bx
  jmp rp_rea

 

/* read data from floppy disk */

read_track:
  pusha
  pusha 
  mov ax, #0xe2e  ! loading... message 2e = .
  mov bx, #7
  int 0x10
  popa  

  mov dx,track
  mov cx,sread
  inc cx
  mov ch,dl
  mov dx,head
  mov dh,dl
  and dx,#0x0100
  mov ah,#2
 
  push dx    ! save for error dump
  push cx
  push bx
  push ax

  int 0x13
  jc bad_rt
  add sp, #8
  popa
  ret

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值