flat assembler
Message board for the users of flat assembler.

Index > OS Construction > MiniDOS Bootsector Question(s)

Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
I'm reading through the MiniDOS Bootsector trying to understand how FAT16 is implemented in it, and I'm starting to understand a little bit more, but I'm confused mainly about 4 things as of now.

1.) When you start, why divide this stuff by 16?

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Reserve some memory for the boot sector and the stack ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        sub     ax, 512 / 16    ; reserve 512 bytes for the boot sector code
        mov     es, ax          ; es:0 -> top - 512

        sub     ax, 2048 / 16   ; reserve 2048 bytes for the stack
        mov     ss, ax          ; ss:0 -> top - 512 - 2048
        mov     sp, 2048        ; 2048 bytes for the stack    
    


2.) What's the standard size of a cluster?

3.) What's your definition of/How do you measure a "paragraph"?

4.) What's LBA and how does it work?

Here's where the LBA question takes place for me:

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Reserve some memory for a FAT12 image (6KB max) and load it whole ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        mov     ax, [bpbBytesPerSector]
        shr     ax, 4                   ; ax = sector size in paragraphs
        mov     cx, [bpbSectorsPerFAT]  ; cx = FAT size in sectors
        mul     cx                      ; ax = FAT size in paragraphs

        mov     di, ss
        sub     di, ax
        mov     es, di
        xor     bx, bx                  ; es:bx -> buffer for the FAT

        mov     eax, [bpbHiddenSectors]
        mov     edx, [bpbHiddenSectors+2]
        add     ax, [bpbReservedSectors]
        adc     dx, bx                  ; dx:ax = LBA

        call    ReadSector

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Reserve some memory for a root directory and load it whole ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
Post 04 May 2007, 15:34
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Also, I'm wondering "Wouldn't you load 512 into bpbBytesPerSector?" Because I see it still set as 0 in the code. :confused:
Post 04 May 2007, 15:36
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
1) The CPU calculates the effective address as [segment * 16 + offset].

2) Not sure, 4 KB?

3) A paragraph is 16 bytes.

4) Logical Block Addressing. Instead of using the CHS (cylinder, head, sector) addressing you just specify a sector number. I haven't got the MiniDOS sources so I don't know its exact use, here Dex must reply.
Post 04 May 2007, 15:45
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thanks for the help that you gave, Loco. Stuff is starting to make the slightest bit of sense. =-) (kinda helps when you know the terminology used)
Post 04 May 2007, 16:01
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
First MiniDos uses fat12 and here's some answers to your ?.

1. The first thing it does on booting, is move it's self to top of Conventional Memory, it does this by doing a int 12h to find how much Conventional Memory is on the sys.
Code:
        int     12h             ; get conventional memory size (in KBs)        shl     ax, 6           ; and convert it to paragraphs    

Then it converts it to paragraphs, then we sub size of boot sector (512bytes) and move the size of conventional memory -512 into es, then we sub 2048 bytes from ax for the stack and move it into ss, so ss = top of Conventional Memory -512-2048, then we set sp to 2048 for top of stack (search for how stacks work).
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Reserve some memory for the boot sector and the stack ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;        sub     ax, 512 / 16    ; reserve 512 bytes for the boot sector code        mov     es, ax          ; es:0 -> top - 512        sub     ax, 2048 / 16   ; reserve 2048 bytes for the stack        mov     ss, ax          ; ss:0 -> top - 512 - 2048        mov     sp, 2048        ; 2048 bytes for the stack    

Then we move the boot sector from 7C00h to top of conventional memory -512.
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Copy ourself to top of memory ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;        mov     cx, 256        mov     si, 7C00h        xor     di, di        mov     ds, di        rep     movsw;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Jump to relocated code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    

2.
A cluster is group of sectors, that the sys treats as a unit of storage space.Theres no standared size for a cluster, but for a fat12 1.44 floppy, it would be 512bytes or 1 sector ( a sector =512byte), but for fat16/32 it could be any number of sectors, but its always a power of 2, such as 1, 2, 4, 8 etc sectors.

3. paragraphs = 16 bytes

4. See here : http://en.wikipedia.org/wiki/Logical_block_addressing

PS @LocoDelAssembly, I took it off my site as i did not think anyone downloaded it anymore, also note: MiniDos is load by "bootprog" a com/exe file loader.
Post 04 May 2007, 19:59
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thanks, Dex. I was starting to make some sense of it after Loco explained to me a few terms, yet that sorta topped it off by giving me a more in-depth explaination of how it works. Also, I mainly know of the stack as an area set up in memory which you can temporarily store variables on in the FILO method (First In Last Out).

Thanks again!
Post 05 May 2007, 02:58
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.