Page 1 of 3
FAT12...
Posted: Tue Feb 17, 2004 1:16 pm
by bubach
Hello!
I got a "standard" FAT12 bootsektor that saves the FAT (or root?) to memory and loads my "kernel loader" from the floppy. In the loader i goes into pmode and sets the A20-gate.
Now i want to load my kernel into memory (at 1 mb) but i don?t know how to do that.
I guess i would be a good idea to load the root/fat? and then serach the root from the kernel file..
But how?
/ Christoffer
Re:FAT12...
Posted: Wed Feb 18, 2004 12:32 am
by darklife
FAT12 is easy to understand if you look at the many documents on the internet about it. Since you're in protected mode, you will need to rewrite a disc driver to load your loader (no pun intended). It sounds like you're trying to find a quick hack to get your newbe kernel running? My question is, how will this help you learn the very basics if you plan to jump right into more complicated stuff? Start simple. Do **LOTS** of research. Post here when you have a well defined question.
Re:FAT12...
Posted: Wed Feb 18, 2004 2:32 am
by Pype.Clicker
okay ... Let's make things a bit clearer...
The FAT (file allocation table) just holds 'next chunk' information. Period. One file may be several chunk long and everytime you want to go to the next chunk to read more byte you have to lookup the FAT.
Code: Select all
current_chunk = FAT[current_chunk];
if (current_chunk == FAT_LAST_CHUNK) return EOF;
// warning : this is not directly appliable to FAT12
After the FAT comes the root directory, which is made of directory entries. Those entries carry (among other things) the name of the file and its first chunk.
So in order to load your kernel, you should compute the root directory's first sector (check out FAT info from OSRC), and then read each directory entry to know if the name and the extension (which are kept apart from one another iirc) matches what you're looking for.
The set current_chunk == direntry.first_chunk and start reading your file's data one chunk at a time ... Storing those data above 1MB can be handled the very same way as you'd have done it with a raw floppy -- basically unreal mode is the easiest way to go.
No need to say that all this *** shouldn't be done in pmode where you have no BIOS to help you reading from the floppy ...
Re:FAT12...
Posted: Wed Feb 18, 2004 3:31 am
by Candy
Pype.Clicker wrote:
The FAT (file allocation table) just holds 'next chunk' information. Period. One file may be several chunk long and everytime you want to go to the next chunk to read more byte you have to lookup the FAT.
Code: Select all
current_chunk = FAT[current_chunk];
if (current_chunk == FAT_LAST_CHUNK) return EOF;
// warning : this is not directly appliable to FAT12
<snip>
So in order to load your kernel, you should compute the root directory's first sector (check out FAT info from OSRC), and then read each directory entry to know if the name and the extension (which are kept apart from one another iirc) matches what you're looking for.
The set current_chunk == direntry.first_chunk and start reading your file's data one chunk at a time
As for realising that I did the right thing, thanks Pype
This explains exactly what my load-file-routine does in my bootsector. It has a function similar to read_fat (which reads from the FAT in memory), it has a function load_sector (which loads the sector to memory), and it has a function to seek a file in the file table (also in memory). It calls these in the oh-so-predictable order to load a file, and that's all there's to it. See my bootsector (download source from
www.sf.net/projects/atlantisos/ - files) in boot/bs.asm for the code
Note, you can take this code and use it, but I advise you to still write your own. It's worth the trouble knowing what every instruction does, and where the potholes are.
Re:FAT12...
Posted: Wed Feb 18, 2004 5:14 am
by Pype.Clicker
doh ? it appears to have no files in your archives (neither in .zip nor in .tar.gz ...)
Re:FAT12...
Posted: Wed Feb 18, 2004 9:33 am
by bubach
Hello.
I was in a hurry when i wrote that, but i will try to explain a bit more today.
I will load the kernel to mem before i go into pmode, and save the result in a "loading_ok db 0x00" or 0x01 if it was ok.
Then, when i am in pmode i just check if loading_ok is==1 then i jump to the kernel (1mb), else print (in the hard way) that the loading failed..
So the actual loading will be with BIOS int?s. So i can wait with pmode drivers until the kernel is loaded...
In the bootsector it saves some FAT stuff to mem (0x07c0:0x0200 i think it was).
The read_sector function is the same i guess, but the other? To load the stuff from mem (0x07c0:0x0200?) and use that to find witch sectors to read?
All the FAT documents i have read are _to_ technical and without nasm snippets..
Seriously, i learn much better with some source to look on..
/ Christoffer
Re:FAT12...
Posted: Wed Feb 18, 2004 10:09 am
by Candy
Pype.Clicker wrote:
doh ? it appears to have no files in your archives (neither in .zip nor in .tar.gz ...)
ok, good lord, something went terribly wrong with the upload. I blame sf for being unreliable at that time (took me several reloads because of server flipping on and offline). Lemme try again, but even then, the code is also in razor (0.0.2).
[edit] taking back the comment on sf being responsible, windows just has a fucked ftp. Fixed in a minute.[/edit]
Re:FAT12...
Posted: Wed Feb 18, 2004 12:02 pm
by Neo
You oculd use the bootloader
here for "some source" you needed.
The logic of reading the kernel into memory is the same as the secondary. If you want to load it to the 1MB mark just enable the A20 line or use the BIOS ints to do so.
Check my secondary attached.
HTH
[attachment deleted by admin]
Re:FAT12...
Posted: Wed Feb 18, 2004 1:24 pm
by bubach
Thats cool!! I have almost the exact same code that you posted!! Except for that FAT stuff in the secondary loader...
Nice to see how you did all the stuff... Great! Thanks!
/ Christoffer
Re:FAT12...
Posted: Thu Feb 19, 2004 12:03 pm
by Neo
Thats cool!! I have almost the exact same code that you posted!! Except for that FAT stuff in the secondary loader...
Thats because there are only some ways you cn do some things especially related to hardware. Anyway glad to know it was useful
. Best of luck
Re:FAT12...
Posted: Fri Feb 20, 2004 8:45 am
by bubach
Problems, problems....
It seems like my bootsector code loaded both the Root dir and FAT to the same location, 7c00:0200.
I based my code on this:
http://www.geocities.com/mvea/bootstrap.htm
So it didn?t work.. I tried to change the locations to:
7c00:0200 for root dir and
7c00:2eaa for FAT
and in your code:
root dir mem loc.:
7e00 = 7c00+0200
and fat mem loc. to:
AAAA = 7c00+2eaa
but as u can problably see i didn?t pass in mathclass..
So, any suggestions how to fix this?
One more question, are they any _good_ fat12 tutorials out there? except that lame microsoft spec?
like:
How do the "readsector rutine" work and how to build one in pmode?
How to find/calculate (and load) programs and dir?s in fat12?
how to delete/create files on a fat12 disc?
thanks in advance..
/ Christoffer
Re:FAT12...
Posted: Fri Feb 20, 2004 11:00 am
by Pype.Clicker
where the **** does that 0xAAAA stuff come from ? how many bytes of FAT are you reading ? and why don't you simply put the Root after those bytes ?
How do the "readsector routine" work and how to build one in pmode?
that's a complex stuff. you'll have to program the FDC and the DMA chip together, make sure you give the proper addresses to the DMA, etc. If you can avoid it (for instance, loading the whole floppy in memory -- or everything you need from it) while you're in (un)real mode, you'll make your life a lot easier ...
Never tried it myself: i consider it as a lack of my precious time as there are more and more floppyless systems ...
How to find/calculate (and load) programs and dir?s in fat12?
their first chunk is in the root directory, and from there you just have to follow the FAT to know which chunk is next...
how to delete/create files on a fat12 disc?
delete: you sweep the list of chunks for the file (in the FAT) and tag them as 'free' (there's a special number for this ... which is 0xFFE iirc) and then replace the first character of the file with a 'is deleted' character (it was the Delta on my IBM pc -- look the MS doc to be sure)
create: you sweep the directory for a free entry (check the flags), write the filename there. When you want to add datas on a new chunk, sweep the FAT for a cluster (*that*'s the word i've been seeking for . replace all the 'chunk' by 'cluster) that is tagged as 'free' and write its number in the entry for the previous cluster of your file.
For instance you have
Code: Select all
[myFile .exe] (first = 0) is an empty file
[myFile .exe] (first = 123) and FAT[123]=0 is a single-cluster file
[myFile .exe] (first = 123) and FAT[123]=124, FAT[124]=0 is a two-clusters file, etc.
Re:FAT12...
Posted: Fri Feb 20, 2004 11:44 am
by Neo
heres the FAT 12 tutorial i used. I dont remember the author or the site, well i actually modified the file a lot to make ot readable. its attached as a txt file but actually is a html file so rename it and then use it.
-Neo
[attachment deleted by admin]
Re:FAT12...
Posted: Fri Feb 20, 2004 8:28 pm
by bubach
where the **** does that 0xAAAA stuff come from ?
*lol* (the funniest thing today)
i am a bit drunk right now (03:24 in the morning) but i will try to explain..
i guess i based my math thing on this:
the fat (and??) the root dir in my fat12 bootsect where loaded to 7c00:0200 witch would be 7c00 +200 hex (200 hex == 512 dec).... becasue it saied in a comment that i was loaded after the bootsect
so i guessed that the actuall address for that would be 7e00..
(actual 0000:7e00 instead of 7c00:0200)....
r u understanding how i thought?
anyway, time to sleep so that i can get that nice hangover tomorrow.....
Cheers! Christoffer............
Re:FAT12...
Posted: Mon Feb 23, 2004 4:05 am
by Pype.Clicker
that's for 7E00, not for AAAA...