flat assembler
Message board for the users of flat assembler.

Index > OS Construction > debugging BOOTMOSF

Author
Thread Post new topic Reply to topic
viki



Joined: 03 Jan 2006
Posts: 40
Location: Czestochowa, Poland
viki 18 Apr 2006, 11:54
Based on BOOTMOSF.asm from MenuetOS I've prepared version you can debug in dos mode using for example td.exe. I prepared also small kernel for test. To test it please copy kernel.bin on floppy and run td boot.com.

kernel.asm

Code:
  org 0h

  mov  si,beg_txt
  call disp_txt
  retf

;-------------------------------------------------------------------------
disp_txt:
;-------------------------------------------------------------------------
  lodsb
  or   al,al
  jz   @f
  mov  ah,0eh
  mov  bx,07h
  int  010h
  jmp  disp_txt
@@:
  ret

beg_txt db "Kernel loaded",0  
    


boot.asm

Code:
  pos_read_tmp    equ 0700h ;position for temporary read
  boot_program    equ 07c00h ;position for boot code
  seg_read_kernel equ 01000h ;seguiment to kernel read
  org  100h

  jmp start
  nop

  OEM_ID            db 'KOLIBRI '
  BytesPerSector    dw 512
  SectorsPerCluster db 1
  ReservedSectors   dw 1
  TotalFATs         db 2
  MaxRootEntries    dw 224
  TotalSectorsSmall dw 2880
  MediaDescriptor   db 0f0h
  SectorsPerFAT     dw 9
  SectorsPerTrack   dw 18
  NumHeads          dw 2
  HiddenSectors     dd 0
  TotalSectorsLarge dd 0
  DriveNumber       db 0
  Flags             db 0
  Signature         db 029h
  VolumeID          dd 12
  VolumeLabel       db 'KOLIBRI    '
  SystemID          db 'FAT12   '

;-------------------------------------------------------------------------
start:
;-------------------------------------------------------------------------
  cld
  mov  ax,ss
  mov  [old_ss],ax
  mov  [old_sp],sp

  mov  ax,9000h ; segment for stack
  mov  ss,ax
  mov  sp,boot_program

  mov  si,msg_load
  call disp_txt

  push ss
  pop  es
  mov  ax,020eh ;read, 14 sectors for directory
  mov  bx,pos_read_tmp ;es:bx read position
  mov  cx,02h ;track 0, sector 2
  mov  dx,0100h ;head 1, drive 0 (aSmile
  call read_sector
  mov  di,bx

loop_find_kernel:
  mov  cx,11 ;file name
  mov  si,kernel_name
  rep  cmpsb
  je   load_fat
  add  di,21
  cmp  di,pos_read_tmp+(512*14) ;end of directory
  jb   loop_find_kernel

disp_err:
  mov  si,msg_err
  call disp_txt

load_fat:
  mov  bp,[es:di+15] ;starting cluster
  mov  [cluster1st], bp

  mov  ax,0209h ;read, 9 sectors
  mov  bx,pos_read_tmp ;es:bx read position
  mov  cx,02h ;track 0, sector 2
  xor  dx,dx ;head 0, drive 0 (aSmile
  call read_sector
  jc   disp_err
  mov  ax,seg_read_kernel
  mov  es,ax
  xor  bx,bx

loop_read_kernel:
  call read_floppy
  jc   disp_err

  push bx
  mov  bx,es
  add  bx,0x20
  mov  es,bx
  pop  bx

  mov  di,bp
  shr  di,01h
  pushf
  add  di,bp
  add  di,pos_read_tmp
  mov  ax,[ss:di]
  popf
  jc   even_sector
  and  ax,0fffh
  jmp  if_last_sector
even_sector:
  mov  cl,4
  shr  ax,cl
if_last_sector:
  cmp  ax,0ff8h
  jae  run_kernel
  mov  bp,ax
  jmp  loop_read_kernel

;-------------------------------------------------------------------------
run_kernel:
;-------------------------------------------------------------------------
  push word seg_read_kernel
  pop  ds
  push cs
  push 0
  push word seg_read_kernel
  push word 00h
  retf

koniec:
  cli
  mov  sp,[old_sp]
  mov  ax,[old_ss]
  mov  ss,ax
  sti
  ret

;-------------------------------------------------------------------------
disp_txt:
;-------------------------------------------------------------------------
  lodsb
  or   al,al
  jz   @f
  mov  ah,0eh
  mov  bx,07h
  int  010h
  jmp  disp_txt
@@:
  ret

;-------------------------------------------------------------------------
read_floppy: ;es:bx -> position in read buffer
;-------------------------------------------------------------------------
  ;bp -> logical sector to read
  ;carry <- 0 read OK
  ;carry <- 1 read error
  push bx
  mov  ax,0e5fh ;underline
  xor  bh,bh
  int  010h
  pop  bx
  mov  ax,bp ;data sector to read
writesec:
  add  ax,31 ;get logical sector
  mov  cx,36 ;sector/track
  xor  dx,dx
  div  cx
  mov  ch,al ;track transfer
  xor  dh,dh ;head 0
  cmp  dl,18
  jb   @f
  sub  dl,18
  inc  dh ;head 1
@@:
  inc  dl
  mov  cl,dl
  xor  dl,dl ;drive 0 (aSmile
patchhere:
  mov  ax,0201h ;read 1 sector
  call read_sector
  retn

;-------------------------------------------------------------------------
read_sector:
;-------------------------------------------------------------------------
  push bp
  mov  bp,20
@@:
  dec  bp
  jz   disp_err
  push ax bx cx dx
  int  0x13
  pop  dx cx bx ax
  jc   @b
  pop  bp
  retn

old_ss       dw  ?
old_sp       dw  ?

msg_load:    db  "Loading VikiOS v0.01 - 2006.04.01",13,10,"Please Wait...",0
msg_err:     db  "FDD read error",0
kernel_name  db 'KERNEL  BIN'
cluster1st   dw ?
loader_block dw 1
                         
Post 18 Apr 2006, 11:54
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.