Home arrow Forums
OSDEV Forums  


steffylove
User

Fresh Osdever
Posts: 3
graphgraph
Karma: 0  
hi hello - 2006/03/05 16:02 hi! i'm new here. pleased to meet you all. before anythingelse... i'm a guy.

os dev is a new thing to me and i have so far, a little experience with bootloaders. i was able to make one that loads a file in sector two but i'm stuck at that though and i'm looking for directions about what to do next. e.g. protected mode, enabling a20 and some intros about how to go about making a kernel itself. i'm browsing this (http://www.osdcom.info/download.php?list.4) at the moment. hopefully i can pick some things up.

some concepts are still a bit blurry though... like what if the file i'm trying to load is more than 512 bytes big already? i hope to understand them all with this community's help.
  | | The administrator has disabled public write access.
OSDEV
Community
Advertisement
   
gaf
User

Platinum Osdever
Posts: 153
graph
Karma: 10  
Re: hi hello - 2006/03/07 11:46 Hello Stephanie
What if the file i'm trying to load is more than 512 bytes big already

What you wrote is probably a bootsector and not a bootloader, hence the 512byte restriction. The bootsector, which is loaded by the BIOS at system boot-up, is only meant to get the bootloader from the disk and thus can be kept very small. To do this it uses the BIOS functions to read the disk's file-system and locate the loader, which it then copies to memory. Once the loader has finished initializing the system (pmode, a20, etc), it gets the kernel from the disk and jumps to its entrypoint. Both bootloader and kernel are ordinary files of the disk's filesystem and may thus be as big as neccessary.

I'm looking for directions about what to do next. e.g. protected mode, enabling a20 and some intros about how to go about making a kernel itself.

In general there are two ways of getting the computer booted and your kernel up and running: write your own boosector/bootloader or use an already existing loader like GRUB.
If you want to go on with rolling your own loader, you'd first have to extend your bootsector to load a bootloader (key words: FAT12, 0x10 BIOS interrupt) from your floppy, which would then initialize the computer (a20, VESA?, pmode) before passing control to the kernel. The second approach saves you from doing the initialization by yourself. You can directly start with writing your pmode kernel without having to worry about how it's getting loaded as this is all handled by GRUB.
Personally I prefere using GRUB, not only because it saves me from a lot of work, but also because it has som quite usefull features (f. ex. multiboot) and is in general a more complete bootloader than you or I may ever write. Also there's hardly anything that your loader might do in a much different way as the booting process is quite standartized by the hardware..

Have you already decided which language you want to use for your kernel ? In case that it's going to be in C/C++ you might want to have a look at some of whyme_t's tutorials.

By the way, another resource for beginner tutorials can be found at bonafide. Apart from that the osfaq can also be very usefull if you need to look-up on something.

regards,
gaf
  | | The administrator has disabled public write access.
steffylove
User

Fresh Osdever
Posts: 3
graphgraph
Karma: 0  
Re: hi hello - 2006/03/07 16:59 [blockquote]
Hello Stephanie
What you wrote is probably a bootsector and not a bootloader, hence the 512byte restriction. The bootsector, which is loaded by the BIOS at system boot-up, is only meant to get the bootloader from the disk and thus can be kept very small. To do this it uses the BIOS functions to read the disk's file-system and locate the loader, which it then copies to memory. Once the loader has finished initializing the system (pmode, a20, etc), it gets the kernel from the disk and jumps to its entrypoint. Both bootloader and kernel are ordinary files of the disk's filesystem and may thus be as big as neccessary.[/blockquote]ahhh i see i see! well, i made two files. a 512 byte one and another one that just prints a string so i can verify if things worked here. it's my blog by the way where i document my learning experiences. some sort of a progress report for myself.

so far, i'm still struggling with the GDT concepts. not easy
[blockquote]
In general there are two ways of getting the computer booted and your kernel up and running: write your own boosector/bootloader or use an already existing loader like GRUB.
If you want to go on with rolling your own loader, you'd first have to extend your bootsector to load a bootloader (key words: FAT12, 0x10 BIOS interrupt) from your floppy, which would then initialize the computer (a20, VESA?, pmode) before passing control to the kernel. The second approach saves you from doing the initialization by yourself. You can directly start with writing your pmode kernel without having to worry about how it's getting loaded as this is all handled by GRUB.
Personally I prefere using GRUB, not only because it saves me from a lot of work, but also because it has som quite usefull features (f. ex. multiboot) and is in general a more complete bootloader than you or I may ever write. Also there's hardly anything that your loader might do in a much different way as the booting process is quite standartized by the hardware..[/blockquote]
groovy! i'd use grub or any other better loader for that matter but i deem that these are concepts i can't afford to skip. much less try not to make and not understand. i'll make one even if it will suck. after that, i'll be more than willing (and at peace with myself) to use grub.

[blockquote]Have you already decided which language you want to use for your kernel ? In case that it's going to be in C/C++ you might want to have a look at some of whyme_t's tutorials.

By the way, another resource for beginner tutorials can be found at bonafide. Apart from that the osfaq can also be very usefull if you need to look-up on something.

regards,
gaf
[/blockquote]i've found some articles here and at osdver. will take a look into them after i finish understanding the loader thingy and most of the important things under it. taking them baby steps at a time might i add.
  | | The administrator has disabled public write access.
gaf
User

Platinum Osdever
Posts: 153
graph
Karma: 10  
Re: hi hello - 2006/03/08 13:32 I made two files, a 512 byte one and another one that just prints a string so i can verify if things worked

I had a look at the code you posted to your blog and was wondering where on the disk the second stage actually gets stored. If you copy it to the sectors following right after the bootsectors, you have to use a rawwrite/dd/partcopy everytime you want to update your code, which is quite tedious in my opion. An alternative would be to use a minimum bootsector as the ones that have been written by John Fine (bootr01, used it myseld before I switched to GRU or Alexei Frounze. Unlike more elaborate bootloaders, they don't initialize the computer for you (a20, pmode still disabled), but only fetch a second-stage loader from the disk and jump to it. The advantage is that the 2nd stage might now be stored as an ordinary file that can be copied much easier and faster.
Apart from that I was a bit surprised that you load the 2nd stage from a hard-disk rather than a floppy. Are you running this on some emulator ? If so, please remember that you should always test your code on real hardware once in a while to make sure that it really works.

I'd use grub or any other better loader for that matter but i deem that these are concepts i can't afford to skip.

Actually you could skip them without too many complications. The only reason why todays computers still boot from real-mode with a20 disabled is that Intel didn't want to break backwards compatiblity with old, and often hackish, DOS software. Once you've disabled all these lagacy features you'll never again need most of the knowledge that was neccessary to write the bootsector. In fact the a20 linegate is the perfect example for what I mean, have a look here.

As for pmode (initialization/gdt/idt/tss/etc..) - you really need to learn about it, but that shouldn't keep you from using GRUB. Just because you start off in pmode doesn't mean that wouldn't have to reload descriptor tables..

regards,
gaf
  | | The administrator has disabled public write access.
steffylove
User

Fresh Osdever
Posts: 3
graphgraph
Karma: 0  
Re: hi hello - 2006/03/08 15:44 [blockquote]I had a look at the code you posted to your blog and was wondering where on the disk the second stage actually gets stored. If you copy it to the sectors following right after the bootsectors, you have to use a rawwrite/dd/partcopy everytime you want to update your code, which is quite tedious in my opion.[/blockquote] yeah.. hehehe that's another thing i found really srewy.. how to actually look for a file inside of a disk instead of just specifying a hard coded start sector.. so for starters .. i "dd seek=1" the stage2 thingy. i will study those links you gave me.. hopefully, i'll come back here more intelligent than puzzled.. hehehe

[blockquote]Apart from that I was a bit surprised that you load the 2nd stage from a hard-disk rather than a floppy. Are you running this on some emulator ? [/blockquote] yep. as i've no hardware to test things on i'm stuck with just images. the file name of my image is actually "floppy.img" but that's a bit misleading coz i'm loading it as a hard disk. im using qemu for my emulator and i have yet to try it's "-fdX" paramater that implies file to be a floppy disk image. my image is on ext2fs btw, don't know if that would have any impact as of now though..

[blockquote]As for pmode (initialization/gdt/idt/tss/etc..) - you really need to learn about it, but that shouldn't keep you from using GRUB. Just because you start off in pmode doesn't mean that wouldn't have to reload descriptor tables..[/blockquote] yes sir!
  | | The administrator has disabled public write access.

A WebArticles site. Sponsored by Evoleto. Motorola V525 / Business Directory / Delaware Incorporation / Home Made Bazaar