flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Help with FAT12 bootloader

Author
Thread Post new topic Reply to topic
me239



Joined: 06 Jan 2011
Posts: 200
me239 14 Jan 2011, 09:45
Hello everyone, recently I've been building a new DOS project(Codename: DOS of Prey) and have run into a snag with the bootloader. The problem is nothing shows up. I've been trying to tweak it and read several articles and tutorials on it, but still don't know what I'm doing wrong. code attached.


Description: Booloader
Download
Filename: boot.asm
Filesize: 3.97 KB
Downloaded: 344 Time(s)

Post 14 Jan 2011, 09:45
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 15 Jan 2011, 03:20
If the BPB is correct, you should be able to view the disk contents.
Can you view it, or is the file format unrecognized?
Also FASM does a two byte jump if within range, so we
must manually account for code requiring 3 byte jump...
Code:
jmp start
nop
    

Its very cold here so i cant spend much time looking at your code (sorry).
Maybe my loader can help you?
http://board.flatassembler.net/topic.php?t=11774
Not very robust, but it did what i needed it to Smile
Post 15 Jan 2011, 03:20
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239 15 Jan 2011, 04:07
bitshifter wrote:
If the BPB is correct, you should be able to view the disk contents.
Can you view it, or is the file format unrecognized?
Also FASM does a two byte jump if within range, so we
must manually account for code requiring 3 byte jump...
Code:
jmp start
nop
    

Its very cold here so i cant spend much time looking at your code (sorry).
Maybe my loader can help you?
http://board.flatassembler.net/topic.php?t=11774
Not very robust, but it did what i needed it to Smile

I can read all the files, it just won't boot.
Post 15 Jan 2011, 04:07
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239 15 Jan 2011, 05:50
bitshifter wrote:
If the BPB is correct, you should be able to view the disk contents.
Can you view it, or is the file format unrecognized?
Also FASM does a two byte jump if within range, so we
must manually account for code requiring 3 byte jump...
Code:
jmp start
nop
    

Its very cold here so i cant spend much time looking at your code (sorry).
Maybe my loader can help you?
http://board.flatassembler.net/topic.php?t=11774
Not very robust, but it did what i needed it to Smile

I based my loader off yours and it still doesn't work. I know I'm doing something wrong that I keep overlooking.
Code:
org 7c00h
jmp start
nop
        db      "DOSOPREY"
        dw      512
 db      1
   dw      1
   db      2
   dw      224
 dw      2880
        db      0f0h
        dw      9
sectpertrack dw 18
headpercylinder dw 2
     dd       0
  dd       0
drivenum db        0
  db       0
  db       29h
        dd       0
  db       "DOSOFPREY  "
    db       "FAT12   "
filen  db       "KERNEL  BIN"
start:
      cld
 mov     ax, cs
      mov     ds, ax
      mov     es, ax
      mov     [ds:drivenum], dl
       cli
 mov     ss, ax
      mov     sp, sstack
  sti
 mov     al, 14
      mov     bx, buffer
  mov     cx, 2
       mov     dh, 1
       call    readsectors
 mov     si, filen
   mov     di, bx
      mov     cx, 224
findfile:
    pusha
       mov     cx, 11
      rep     cmpsb
       popa
        je      load_fat
    add     di, 20h
     loop    findfile
load_fat:
   mov     si, [es:di+1ah]
 mov     al, 9
       mov     cx, 2
       xor     dx, dx
      call    readsectors
 mov     ax, 0050h
   mov     es, ax
      mov     fs, ax
      mov     gs, ax
      xor     bx, bx
load_file:
    mov     ax, si
      add     ax, 31d
     xor     dx, dx
      div     word[ds:sectpertrack]
   inc     dx
  mov     cl, dl
      xor     dx, dx
      div     word[ds:headpercylinder]
        mov     ch, al
      mov     dh, dl
      mov     al, 1
       call    readsectors
 add     bx, 200h
    mov     ax, si
      mov     cx, 3
       mul     cx
  dec     cx
  div     cx
  mov     di, ax
      mov     si, [ds:di+buffer]
      push    es
  pop     ds
  push    es
  push    0
   retf
readsectors:
    pusha
       mov     dl, [ds:drivenum]
       mov     si, 5
.loop1:
        mov     ah, 02h
     stc
 int     13h
 jnc     .done
       dec     si
  jnc     .reset
      jmp     error
.reset:
        mov     di, 5
.retry:
        xor     ah, ah
      stc
 int     13h
 jnc     .loop1
      dec     di
  jnc     .retry
      jmp     error
.done:
 ret
error:
   mov     si, msg
printf:
      lodsb
       cmp     al, 0
       je      $
   mov     ah, 0eh
     int     10h
 jmp     printf
msg   db      "AN ERROR OCCURRED!", 0
times      512-($-$$) db 0
buffer:
rb 8192
rb 8190
sstack:
rb 2    
Post 15 Jan 2011, 05:50
View user's profile Send private message Reply with quote
neville



Joined: 13 Jul 2008
Posts: 507
Location: New Zealand
neville 15 Jan 2011, 06:06
AFAIK most BIOSs still insist on the historical 'Boot Signature' - the last two bytes in the bootsector must be 55H, 0AAH

TIMES 7C00H+510-$
DW 0AA55H
; or DB 55H, 0AAH

_________________
FAMOS - the first memory operating system
Post 15 Jan 2011, 06:06
View user's profile Send private message Visit poster's website Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239 15 Jan 2011, 06:24
neville wrote:
AFAIK most BIOSs still insist on the historical 'Boot Signature' - the last two bytes in the bootsector must be 55H, 0AAH

TIMES 7C00H+510-$
DW 0AA55H
; or DB 55H, 0AAH

Nope, still not doing it.
Post 15 Jan 2011, 06:24
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 15 Jan 2011, 10:09
I fixed my code, the stack that is.
I thought for some reason that push had placed the value before
decrementing the stack pointer, but it gets decremented first.
So instead of:
Code:
rb 8190 
sstack: 
rb 2
    

It becomes corrected as:
Code:
rb 8192
sstack:
    

Thanks for making me notice this Smile

As for fixing your code, it took me a long time to write my own.
I have not the time to learn and fix yours also.
You have choices, use other peoples code or write your own.
In this situation i would use other peoples code for now.
Then you will not burn yourself out trying to find rodents.
Later, you will peek at your code and it will become apparent what is problem.
Post 15 Jan 2011, 10:09
View user's profile Send private message Reply with quote
neville



Joined: 13 Jul 2008
Posts: 507
Location: New Zealand
neville 15 Jan 2011, 10:35
me239:
Well I forgot the DB 0H at the end of my TIMES statement, but where did you put it? Is your bootsector exactly 512 bytes?

_________________
FAMOS - the first memory operating system
Post 15 Jan 2011, 10:35
View user's profile Send private message Visit poster's website Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239 15 Jan 2011, 18:52
neville wrote:
me239:
Well I forgot the DB 0H at the end of my TIMES statement, but where did you put it? Is your bootsector exactly 512 bytes?

Yes it's exactly 512 bytes ending with dw 0aa55h.
Post 15 Jan 2011, 18:52
View user's profile Send private message Reply with quote
SeproMan



Joined: 11 Oct 2009
Posts: 70
Location: Belgium
SeproMan 05 Feb 2011, 15:33
Why do you initialize your stackpointer at an odd address?
Better write : mov sp,0FFFEh
Post 05 Feb 2011, 15:33
View user's profile Send private message Reply with quote
SeproMan



Joined: 11 Oct 2009
Posts: 70
Location: Belgium
SeproMan 06 Feb 2011, 21:59
Errors in "boot.asm"

  • 'jmp start' gets encoded with 2 bytes, so you need to insert 1 extra byte to sync your data structure.
  • 'sig' must equal 29h, not 29d
  • Always use even stackpointers
  • After loading the entire root directory CX=0 and DI=[1,5]. You need :
    mov di,200h
    mov cx,[MaxRootEntries]
  • Why does 'clusterlba' multiply by 9 ? Should be :
    mul byte[SectorsPerCluster]
  • 'mov cl,byte[sectorpercluster]'
    I don't see how this line gets past the FASM compiler since that label does not exist !
  • The BIOS Teletype also needs at least BH=0 (BX=0007h)


General observations

  • Many times you hardcode numbers instead of using the values provided in the BPB. Not a good practice.
  • The first time you used 'cwd' is quite useless because it's followed by a word multiplication.
  • Your calculation of "SectorsPerRoot" doesn't take into account a possible leftover of the division. This is only fine with the current BPB values which yield CX=14
  • Make sure that the direction flag is clear before using 'cmpsb'
  • Why do you load both FAT's ?
  • Loading "KERNEL.BIN" at address 1000h imposes a size limit on that file of 7C00h-1000h bytes. This might prove a problem in the future when you long forgot about this fact.
  • Several times you empty a word register followed by setting it's low byte. Better set the word register at once.
  • Please try to develop a personal yet consistent programming style!
    e.g. Don't mix both ways to specify hexadecimal numbers (0x07C0, 0ffffh)
  • A motto of this forum being "First make it work, then ..." I won't even start suggesting optimizations.


I'm sure you did not read the comments I made earlier on Bitshifter's version of a bootloader because you made the same mistakes!
Perhaps you could take a look at http://board.flatassembler.net/topic.php?t=11748


Description: FAT12 Bootloader
Download
Filename: GoodBoot.ASM
Filesize: 8.34 KB
Downloaded: 351 Time(s)


_________________
Real Address Mode.
Post 06 Feb 2011, 21:59
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.