Loading file from disk

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
spider

Loading file from disk

Post by spider »

Hi im currently writing a boot loader for my OS, it loads that fine and loads the second program off the disk which takes care of everything else (loading the kernel at the moment) the problem is that I cant seem to get it to load my kernel of the disk it finds the file ok but after that it doesn?t work it just seems to get into an endless loop, well here is the code that im using to load the kernel.

Code: Select all

   LoadKernelSector:
        mov si, Dot
       call PrintMsg

      pop bx      ; Restore write address
      push ax      ; Preserve sectore number

      add ax, 001Fh   ; Add data cluster offset
      mov cx, 0001h   ; Load 1 sector
      call LoadSectors

      pop ax      ; Restore sector number
      push bx      ; Preserve write address

      mov bx, ax   ; Copy sector number
      shr bx, 0001h   ; Divide by 2
      add bx, ax   ; Add orginal sector number
      add bx, 0200h   ; Add offset to FAT
      mov bx, WORD [bx]   ; Load next sector number

      test ax, 0001h   ; Get lostest byte of sector number
      jnz ODD      ; If present the number is odd
      and bx, 0FFFh   ; if even take low 12 bytes
      jmp Done
      ODD:
         shr bx, 0004h   ; If odd take high 12 bytes

      Done:
         mov ax, bx   ; Move sector number back into ax
         cmp ax, 0FF0h   ; Check for EOF
         jb LoadKernelSector ;load next sector

        mov si, KernelDone
       call PrintMsg
B.E

Re:Loading file from disk

Post by B.E »

there is nothing wrong with can you post more code
spider

Re:Loading file from disk

Post by spider »

yeah sure u little prick ypu can download it from the whole secound stage from http://www.boschchat.com/SOsStrap.asm, (just incase you lost it when i gave it to you on msn ;D )
B.E

Re:Loading file from disk

Post by B.E »

at the start you do this

Code: Select all

mov ax,9c00h
mov es,ax
and don't change it untill atfer

Code: Select all

mov ax, 0001h      ; Sector offset of FAT
mov bx, 0200h      ; Load FATs over top of root directory
mov cx, 12h
call LoadSectors   ; Load FATs
and after that you

Code: Select all

mov ax, 1000h   ; Prepare 0x1000 segment
mov es, ax      ; Load 0x1000 segment
mov bx, 1000h   ; Target address for the kernel
so

Code: Select all

mov bx, WORD [bx]   ; Load next sector number
will load 0 (ds:0 = 0)into bx
and then because it is not a EOF marker it will repeat it self
it will go back up to
which will read the 0th custer. and

Code: Select all

mov bx, WORD [bx]   ; Load next sector number
will again load 0 (ds:0 = 0) into bx
and again because it is not a EOF marker it will continue.


@spider everyone else needs more info than you gave
Post Reply