Page 1 of 1

some questions

Posted: Tue Dec 14, 2004 4:43 am
by bubach
1) wtf is wrong with this forums search function? i get errors 70% of the time i try to use it..

2) do someone have a fat12 bootsector that is as small and easy as possible, with org 0x7c00 and no ugly defines or variable usage?
i am trying do make a new fat12 bootsector with pmode and a20, but for some reson i can?t get it to work like i want.
i want it to be or 0x7c00, i dont know why, i just feel like it.. ;-)

3) why is it so damn hard to get a simple fat12 bootsector to work? i feel like an idiot...

/ Christoffer

Re:some questions

Posted: Tue Dec 14, 2004 5:14 am
by Pype.Clicker
bubach wrote: 1) wtf is wrong with this forums search function? i get errors 70% of the time i try to use it..
That's what comes with YABBse ... I fear we can do little about it ... That's why i try to link threads to the FAQ everytime i can ...
3) why is it so d*mn hard to get a simple fat12 bootsector to work? i feel like an idiot...
Having a bootsector that works is certainly not the easiest problem to solve... Making it understand a file system in addition require full concentration from you ...

Re:some questions

Posted: Tue Dec 14, 2004 5:46 am
by Candy
www.sourceforge.net/projects/atlantisos -> bootloader 0.0.2.2

It loads from fat12 one (or two) given files for use, and jumps to the first. I believe it loads one to 0x10000 and the other to 0x20000.

Busy with a rewrite since it should start loading from *FS which is as of yet not defined enough to load from :)

Re:some questions

Posted: Tue Dec 14, 2004 7:25 am
by bubach
we could make a new and improved search function, like rip phpBB?s and change it to fit this board...?

i have downloaded your bootloader, but i think i remember that u and someone else was talking about a john fine-boot that u had modified, which thread was that (as i think that would siut me better)?

Re:some questions

Posted: Tue Dec 14, 2004 7:45 am
by Candy
bubach wrote: we could make a new and improved search function, like rip phpBB?s and change it to fit this board...?
Good point. You might want to ask DF about that.
i have downloaded your bootloader, but i think i remember that u and someone else was talking about a john fine-boot that u had modified, which thread was that (as i think that would siut me better)?
I would like to help you but I never used any of John Fine's code. Period.

Re:some questions

Posted: Tue Dec 14, 2004 8:07 am
by bubach
hmm.. then who was it...?
i am very fastidious (if you don?t know the word, get a dictionary, i did..) about the code i need.. ;-)
it should be org 0x7c00 (other than that your code is nice..), it should not use defines and extra variables in the code, it should have a very clean syntax, and be very small..

i really can?t get any of my old sources to work if i try to convert it..
you may wonder why i so despratly wants it to be org 0x7c00, well i don?t know. i just thinks it looks nicer.. ;-)

Re:some questions

Posted: Tue Dec 14, 2004 1:56 pm
by distantvoices
You are soo desperately looking for a boot loader understanding fat12 ... I don't envy you.

have you tried the stuff at http://www.execpc.com/~~geezer/ ?
There's also a mirror of John Fine's stuff.

Re:some questions

Posted: Tue Dec 14, 2004 2:57 pm
by gaf
hmm.. then who was it...?
i am very fastidious (if you don?t know the word, get a dictionary, i did..) about the code i need.. ;-)
it should be org 0x7c00 (other than that your code is nice..), it should not use defines and extra variables in the code, it should have a very clean syntax, and be very small..
Well... I was using one of John Fine's bootsectors for quite some time to boot my kernel.
As beyond infinity already said you can get them from Chris Giese's site (http://my.execpc.com/~geezer/johnfine/).
I was using bootr01.zip which is the most basic of all (just loads the kernel and jumps to it - no a20, no pmode) - probably this is also the right one for you to start. The code is heavily commented and quite small.. and its origin is 0x7c00 :)

regards,
gaf

Re:some questions

Posted: Wed Dec 15, 2004 1:37 am
by bubach
i coded some on my own yesterday, now the read_sectors rutine work. but my code for checking and reading the file clusters isn?t...

Code: Select all

     found: 
          mov     dx, [es:di+15]                      ; starting cluster number 
          mov     di, 0x0100                          ; load file to 0x1000:0x0000 
          jmp     chk 

     ;------------------------------------------------; 
     ;  search and read the file clusters to 0x1000   ; 
     ;------------------------------------------------; 
     fat_cont: 
          mov     ax, dx 
          mov     cx, dx 
          shr     dx, 1                               ; divide by 2 
          add     cx, dx                              ; cx = 1.5 

          mov     bx, 0x2100                          ; FAT offset 
          add     bx, cx 
          mov     dx, word [es:bx] 

          test    ax, 1 
          jnz     .odd 
          and     dx, 0x0FFF 
          jmp     chk 
     .odd: 
          shr     dx, 4 
     chk: 
          mov     ax, dx 
          push    ax 
          cmp     ax, 0x0FFF 
          je      quit 

          sub     ax, 2                               ; FAT to LBA 
          mov     cx, 1 
          mul     cx 
          add     ax, 33                              ; start of data-area, compute this instead? 

          call    read_sectors 
          pop     dx 
          jmp     fat_cont 
anything wrong with this? i starred myself blind...
one more thing, is "mov dx, [es:di+15]" correct? soem people add 26 and some add 15, which one should it be?

for full source, visit: http://bubach.1go.dk/BOS/view_asm.php?src=BOS_boot.asm

thanks in advance
/ Christoffer

Re:some questions

Posted: Wed Dec 15, 2004 5:02 am
by IRBMe
The starting cluster number is offset 26 bytes from the start of the directory entry, so that should be 26, or 0x1A, not 15.

But apart from that, I can't really see anything wrong with the code. It seems to work the same as mine, and mine works.

Here's my code anyway which loads the image. Perhaps somebody else can spot the difference.

Notes:

- The cluster variable is calculated like so:

Code: Select all


; The following table shows the format of a single FAT12 directory entry
;
; Bytes   | Meaning
; ----------------------------------------
; 1 - 8   | File Name
; 9 - 11  | File Extension
;   12    | Attributes
;   13    | Reserved
;   14    | Creation Time - Milliseconds
; 15 - 16 | Creation Time (hh:mm:ss)
; 17 - 18 | Creation Date
; 19 - 20 | Last Accessed Date
; 21 - 22 | Unused 
; 23 - 24 | Last modified Time
; 25 - 26 | Last modified Date
; 27 - 28 | Starting Cluster
; 29 - 32 | File Size

; Examining the table reveals that the 27th and 28th bytes contain the
; starting cluster, which we want. So if we add on 26 (0x1A) to di, which 
; points to the directory entry, then we get a pointer to the starting 
; cluster
      
; Save the starting cluster in the cluster variable.
mov     dx, word [di + 0x001A]
mov     word [cluster], dx
- The cluster_lba function looks like this:

Code: Select all

cluster_lba:
   sub     ax, 0x0002                   ; Zero base cluster number
   xor     cx, cx
   mov     cl, byte [SectorsPerCluster]   ; Convert byte to word
   mul     cx
   add     ax, word [dataSector]     ; Base data sector
   ret
- LOADER_ADDRESS_SEGMENT:LOADER_ADDRESS_OFFSET is the address to load the image file (loader.bin) at

- END_OF_FILE is defined to be 0xFF0

Code: Select all

; Store LOADER_ADDRESS_SEGMENT in the es register
mov     ax, LOADER_ADDRESS_SEGMENT
mov     es, ax
      
; Store LOADER_ADDRESS_OFFSET in the bx register and save it on the stack
mov     bx, LOADER_ADDRESS_OFFSET
push    bx

.load_image:
   
   ; read_sectors reads cx sectors starting at ax into memory location es:bx
   ;
   ; ax = Sector to read (calculated from cluster)
   ; cx = Sectors per cluster
   ; es = LOADER_ADDRESS_SEGMENT
   ; bx = LOADER_ADDRESS_OFFSET
   
   
   ; ax = Sector to read (calculated from cluster)
   mov     ax, word [cluster]
   call    cluster_lba
   
   ; bx = LOADER_ADDRESS_OFFSET
   pop     bx
   
   ; cx = Sectors per cluster
   xor     cx, cx
   mov     cl, byte [SectorsPerCluster]
   
   ; Now read the actual sectors
   ; Note that read_sectors will also increment bx by the number of sectors   
   ; read so we don't need to do that.
   call    read_sectors
   
   ; And save bx (LOADER_ADDRESS_OFFSET) again
   push    bx
       
       
   ; Compute the location of the next cluster in the FAT and store it in 
   ; bx using the following algorithm:
   ;
   ; bx = end_boot + (cluster + (cluster >> 1))
   ;
   ; Which is multiplying cluster by 1.5 (remember >> 1 is the same   
   ; as dividing by 2) and adding it on to end_boot, where the FAT
   ; is located

   mov     ax, word [cluster]   ; ax = cluster
   mov     cx, ax         ; cx = cluster
   mov     dx, ax         ; dx = cluster
   shr     dx, 0x0001         ; dx = dx >> 1
   add     cx, dx         ; cx = cx + dx
   mov     bx, end_boot      ; bx = end_boot
   add     bx, cx         ; bx = bx + cx
   
   ; Now bx contains a pointer to the entry in the FAT containing the
   ; next cluster so load the next cluster into dx
   mov     dx, word [bx]
      
   ; At this point we have an entire word from the FAT instead of only
   ; the 12 bits we want. We use the following algorithm to get the 12 bits 
   ; we're interested in:
   ;
   ; if the cluster (ax) is even then 
   ;    dx = dx AND 0x0FFF (mask off lower 12 bits)
   ; else
   ;   dx = dx >> 4 (get the upper 12 bits)
   ; end if
   
   test    ax, 0x0001
   jnz     .odd_cluster
  .even_cluster:
   and     dx, 0xFFF
   jmp     .check_cluster
  .odd_cluster:
   shr     dx, 0x0004 
   
   ; Now we have a pointer to the next cluster stored in dx
   ; We need to check if this is the end of the file, denoted by a cluster
   ; greater than or equal to the END_OF_FILE marker, in which case we keep
   ; looping back to .load_image, otherwise we keep loading sectors
   
  .check_cluster
   mov     word [cluster], dx
   cmp     dx, END_OF_FILE
   jb      .load_image
I attached the entire boot loader (note: it doesn't turn on A20 address line or switch to pmode)

Re:some questions

Posted: Wed Dec 15, 2004 5:05 am
by IRBMe
OK it didn't want to attach for some reason (something about same file name ???) so here is the url:

http://evil-geni.us/~irbme/boot.asm

Re:some questions

Posted: Wed Dec 15, 2004 8:39 am
by bubach
thanks for the help, i?ll test some when i get home..

Re:some questions

Posted: Wed Dec 15, 2004 9:33 am
by ASHLEY4
May be the ones that put 15 bytes, have search the files name + extension, so are at offset 11, so they add 15bytes, means they are at offset 26.

\\\\||////
(@@)
ASHLEY4.

Batteries not included, Some assembly required.

Re:some questions

Posted: Wed Dec 15, 2004 11:34 am
by bubach
yeah, i thought of that, right after i asked...

Re:some questions

Posted: Thu Dec 16, 2004 10:09 am
by bubach
i really don?t get it.. it?s supposed to print a couple of "!"?s when its ready, but all it does is hang.
i?ve done all sorts of changes, it hangs with the floppy light on...