OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Apr 28, 2024 5:46 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Loading OS files from the floppy (bootstrap, kernel)
PostPosted: Fri May 31, 2002 5:18 pm 
Of course, we put the bootloader in the bootsector. And, I was manually (with DOS' debug) putting the bootstrap in the 2nd sector on the disk, but now I'm over 512 bytes for the bootstrap and I need a different approach. Can I incorporate (with code) to use the FAT12 so I can just put the bootstrap/kernel files on the disk and then instead of hardcoding the sector to load from, use some filesystem programming?

How would I go about this? Thanks!


Top
  
 
 Post subject: Re:Loading OS files from the floppy (bootstrap, kernel)
PostPosted: Fri May 31, 2002 7:37 pm 
Most boot loaders that you see in operating systems available on the net will load one or more files from a disk, enable protected mode, and jump to the kernel. The general scheme of things is:
  • Load sectors from the root directory and look for the file (things get easier if you just handle files in the root)
  • Load the first block of the file's entries in the FAT, then load the sectors the block points to.
  • Repeat for the other blocks in the FAT chain

Off the top of my head, this code should do what you want: http://debs.future.easyspace.com/Progra ... index.html

Note that you can get away with only loading one file from the boot sector if you designate that file as the second stage loader; the second stage loader can go off and load the other files that are required (and, not being restricted to 512 bytes, it can be a bit more clever). It can then switch to protected mode and boot the kernel.


Top
  
 
 Post subject: Re:Loading OS files from the floppy (bootstrap, kernel)
PostPosted: Fri May 31, 2002 7:47 pm 
>> Note that you can get away with only loading one file from the boot sector if you designate that file as the second stage loader; the second stage loader can go off and load the other files that are required (and, not being restricted to 512 bytes, it can be a bit more clever). It can then switch to protected mode and boot the kernel. <<

Right, this is what I'm doing. I'm loading the bootstrap (2nd stage bootloader) from the bootloader and then I don't have the 512 limit.

I'll take a look at that link you supplied and get back with results/questions. Thanks!


Top
  
 
 Post subject: Re:Loading OS files from the floppy (bootstrap, kernel)
PostPosted: Fri May 31, 2002 8:02 pm 
First, let me apologize if I'm misunderstanding your problem. If you are booting from a floppy, the loader ought to be on the boot sector of the floppy.

c:\>partcopy boot.bin 0 200 -f0

Second, I don't see the need for FAT at this stage of the game.

Here are some bits of code for reading sectors off the floppy with BIOS. Check RBIL to make sure I didn't make a typo.

Get the sectors before you do your switch to pmode. Or you could temporarily switch back to "unreal" mode as shown in "baby steps #8"

===============================
mov [bootdrv], dl ;BIOS records the boot drive

bios_reset_drive:
mov ah, 0 ; reset drive function
int 0x13 ; call bios disk i/o


mov ax, 0x400
mov es, ax
mov bx, 0 ; kernel image destination
mov al, 4 ; read four sectors
mov cl, 2 ; starting at sector 2 (1 is first sector)
call bios_read_sectors
???
; Turn off the floppy motor
???mov edx,0x3f2
???mov al,0x0c
out dx,al


bios_read_sectors
; input : es:bx = address of destination
; al = sector count
; cl = sector start number

mov ah, 0x02 ; read sectors function
mov ch, 0 ; cylinder 0
mov dl, [bootdrv] ; drive number
mov dh, 0 ; head number
int 0x13 ; call bios disk i/o
jc bios_read_sectors
ret

bootdrv db 0

======================

After switching to pmode, you would get to the rest of your code like this, where 0x10 is the selector. See the text below for the offsett

jmp 0x10:0x4000


======================
Here's your 32-bit setup code.


[BITS 32]
[ORG 0x4000]

; rest of your setup here
; IDT, timer, PIC, etc.
; note that I padded this out to four sectors
; to match what you read off the floppy


times 2048-($-$$) db 0 ; padding


======================

Again, sorry if I wasn't understanding correctly.


Top
  
 
 Post subject: Re:Loading OS files from the floppy (bootstrap, kernel)
PostPosted: Sat Jun 01, 2002 9:50 am 
Well, that's not really what I want to do. For one thing, I don't know how to write the 2nd stage loader (which is 513+ bytes) to a number of sectors. What would do that (program)?

Secondly, when I get further into the dev of my OS, I'm going to need to load the kernel, drivers, and all sorts of files and I can't just write them to sectors explicitly on the disk. That's why I should incorporate the FAT12 for reading and loading from the floppy.


Top
  
 
 Post subject: Re:Loading OS files from the floppy (bootstrap, kernel)
PostPosted: Sat Jun 01, 2002 10:34 am 
Tommy wrote:
Well, that's not really what I want to do. For one thing, I don't know how to write the 2nd stage loader (which is 513+ bytes) to a number of sectors. What would do that (program)?


partcopy lets you specify how much you want to write and where to. For instance,

partcopy boot.asm 0 400 -f0 200

will write two sectors (1024 bytes) starting at the second sector (i.e. location 200). You could also write your own program to do this.

On the second point, certainly a file system makes sense at some stage of the game. My opinion is that it is an unnecessary complication to the problem of facing the basic design issues of loading, setting up the hardware, and task maintenance. In the 'baby steps' series for instance, I intended to show that A20 had nothing to do with switching to pmode. It simply adds more code to debug when things don't go as hoped.
There are many gotchas in this process that could be harder to ferret out inside a structure of superfluous code. It is a simple matter to go back and add stuff. Again, this is just my opinion. Other, more sensible people, might disagree.


Top
  
 
 Post subject: Re:Loading OS files from the floppy (bootstrap, kernel)
PostPosted: Sat Jun 01, 2002 11:12 am 
So you think I should just use partcopy and read specific sectors? Where can I get this partcopy anyway? Thanks!


Top
  
 
 Post subject: Re:Loading OS files from the floppy (bootstrap, kernel)
PostPosted: Sat Jun 01, 2002 11:40 am 
I do. You can download Partcopy here:

http://www.execpc.com/~geezer/johnfine/

Tim's link does exactly what you were looking for, but it introduces File management a bit early in the process. You have to write to the boot sector anyway, so I don't see that dragging/dropping FAT files is any great help.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 28 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group