| View previous topic :: View next topic |
| Author |
Message |
thestew42 Guest
|
Posted: Tue Jun 17, 2008 3:07 am Post subject: Boot Loader Purpose |
|
|
I'm having trouble understanding exactly what a boot loader is
supposed to do.
A few days ago I got really excited about programming an operating
system. I have been doing C/C++ stuff for years now. So I did some
research, and determined that I needed to write a boot loader to
start. I went and learned some basic assembly, read many tutorials,
and wrote a boot loader... but all it does is print a string to the
screen. Yay.
I understand that a boot loader is supposed to load your os kernel,
but I'm not even sure of how to do this because none of the things
that I read on boot loaders taught you how to do anything but print
characters to the screen. I did read something about needing to write
a FAT compatible boot loader and kernel, but is this really necessary?
I mean, if you have control over all of the file system, why cant you
just put the kernel right after to boot loader and be done with it?
Why do you have to use FAT?
Now that's not my only question From everything that I have read,
all that a boot loader does is loads a kernel and enable the A20 line.
If this is true, why do people talk about loading another program from
the boot loader because 512 bytes is not enough? What else goes into
the boot loader that takes up all of that space?
I know that this question makes it very obvious that I'm a noob and
don't know what I'm talking about, but I would really appreciate your
help. Thanks. |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
Guest
|
Posted: Tue Jun 17, 2008 4:22 am Post subject: Re: Boot Loader Purpose |
|
|
On Jun 16, 11:07 pm, thestew42 <prgmer...@gmail.com> wrote:
| Quote: |
I'm having trouble understanding exactly what a boot loader is
supposed to do.
A few days ago I got really excited about programming an operating
system. I have been doing C/C++ stuff for years now. So I did some
research, and determined that I needed to write a boot loader to
start. I went and learned some basic assembly, read many tutorials,
and wrote a boot loader... but all it does is print a string to the
screen. Yay.
I understand that a boot loader is supposed to load your os kernel,
but I'm not even sure of how to do this because none of the things
that I read on boot loaders taught you how to do anything but print
characters to the screen. I did read something about needing to write
a FAT compatible boot loader and kernel, but is this really necessary?
I mean, if you have control over all of the file system, why cant you
just put the kernel right after to boot loader and be done with it?
Why do you have to use FAT?
Now that's not my only question From everything that I have read,
all that a boot loader does is loads a kernel and enable the A20 line.
If this is true, why do people talk about loading another program from
the boot loader because 512 bytes is not enough? What else goes into
the boot loader that takes up all of that space?
I know that this question makes it very obvious that I'm a noob and
don't know what I'm talking about, but I would really appreciate your
help. Thanks.
|
And you've stumbled upon the great question. Truth be told, all of us
go through this, but at the end of the day, we (well, most of us) come
to the same realization. A boot loader (at least one people will
actually use) already exists: grub. There's no reason to write a boot
loader, because it's been done, much more robustly than you could hope
to acheive. It's such a small part of the OS, and incredibly time
consuming and complex to get right. My advice is to learn how to
write a multiboot compliant kernel and forget the rest. You get the
advantage of being able to use the filesystem of your choice, you get
the machine in a known state, and you can concentrate on YOUR os, not
on a problem that's been tackled for two decades.
Just my $0.02.
Don't get me wrong, it's a very educational experience, but you'll
spend 6 months on it, and at the end you'll realize that if you really
want other people to use your OS, it'll need to work with grub. At
that point, you're still at square 1, but you've wasted tons of time
that you could've used toward something more productive. |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
Benjamin David Lunt Guest
|
Posted: Tue Jun 17, 2008 9:03 am Post subject: Re: Boot Loader Purpose |
|
|
"thestew42" <prgmer101@gmail.com> wrote in message
news:725caa6b-fad2-4f27-a260-e1264e7264e8@34g2000hsf.googlegroups.com...
| Quote: |
I'm having trouble understanding exactly what a boot loader is
supposed to do.
A few days ago I got really excited about programming an operating
system. I have been doing C/C++ stuff for years now. So I did some
research, and determined that I needed to write a boot loader to
start. I went and learned some basic assembly, read many tutorials,
and wrote a boot loader... but all it does is print a string to the
screen. Yay.
I understand that a boot loader is supposed to load your os kernel,
but I'm not even sure of how to do this because none of the things
that I read on boot loaders taught you how to do anything but print
characters to the screen. I did read something about needing to write
a FAT compatible boot loader and kernel, but is this really necessary?
I mean, if you have control over all of the file system, why cant you
just put the kernel right after to boot loader and be done with it?
Why do you have to use FAT?
|
Amen. You can do anything you want. However, the reason why most
people do a FAT compatible loader/file system is to be able to write
files directly to the disk using Windows or Linux instead of having
to rebuild the file system each and everytime you change a single
file.
| Quote: |
Now that's not my only question From everything that I have read,
all that a boot loader does is loads a kernel and enable the A20 line.
If this is true, why do people talk about loading another program from
the boot loader because 512 bytes is not enough? What else goes into
the boot loader that takes up all of that space?
I know that this question makes it very obvious that I'm a noob and
don't know what I'm talking about, but I would really appreciate your
help. Thanks.
|
Well, your boot sector is only 512 bytes, and even less than that if
you are FAT compatible. Usually comes out to about 480 bytes or so.
Not really enough to load a kernel into memory above the 1meg mark,
though it has been done. You can write a boot sector that is larger
than 512 bytes as long as you load the remaining sectors into memory
just after your boot code. The only thing that you have to remember
is that you can not call any of that code until after it is loaded
into memory. The biggest mistake I have seen people do is place
the read_sectors code past the 512 byte mark in their boot code and
then when it doesn't work, they wonder why. You can not use the
read_sectors code if it hasn't been loaded yet.
You have many options and since you are in control of the whole process
you can do what ever you want.
1. write a 512 byte boot sector that loads a loader
write a loader that loads the kernel and other files.
2. write a 512+ byte boot sector that loads the rest of itself
then loads the kernel and other files.
3. write a 512 byte boot sector that loads the kernel
then let the kernel load everything else.
4. what ever you decide to do.
Remember though that you can only use the BIOS to load sectors
from the disk while in real mode, or v86 mode, though v86 mode
takes a lot of code to set up, just for a boot sector.
I made multiple boot sectors, one for each file system I support.
Some are single 512 byte sectors while others are larger and require
themselves to load their remaining sectors.
Each one then loads a single loader file, the same loader file
no matter the file system. This loader file is coded with each
of the file systems I support.
This loader sets up unreal mode (big real mode, whatever), and
then loads a list of files from the file system to specified
places in memory. Simply add to the list for multiple files.
Once this loader is complete, it jumps to the kernel.
It does do a few other things before this though. Like getting
the date from the bios, getting the 1Eh floppy vector, etc. while
still in real mode to be able to use the BIOS.
Ben |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
James Harris Guest
|
Posted: Tue Jun 17, 2008 9:38 am Post subject: Re: Boot Loader Purpose |
|
|
On 17 Jun, 04:07, thestew42 <prgmer...@gmail.com> wrote:
....
| Quote: |
I understand that a boot loader is supposed to load your os kernel,
but I'm not even sure of how to do this because none of the things
that I read on boot loaders taught you how to do anything but print
characters to the screen. I did read something about needing to write
a FAT compatible boot loader and kernel, but is this really necessary?
I mean, if you have control over all of the file system, why cant you
just put the kernel right after to boot loader and be done with it?
Why do you have to use FAT?
|
Welcome to the community!
For something like a floppy (readable by int 0x13 0x0201) as Ben has
pointed out you don't need to use FAT. If you do, however, it will
allow the floppy to be recognised by Windows and Linux. Otherwise
Windows will offer to format it for you. Yuck. Writing a robust FAT-
following boot loader is also good experience for testing the water to
see if writing an entire kernel is for you. If requires research and
some detailed assembler work. Although most of a kernel can be written
in C some assembler is usually needed.
I think you can store the proper loader (or your kernel) in reserved
sectors on a floppy so they come right after the boot sector. This
allows the floppy to be FAT-formatted but avoids FAT following.
Perhaps someone can correct me on that.
On the other hand you can just get a boot sector to load specific
sectors on a non-FAT diskette. That's fine too, however you prefer it.
At the end of the day you will need to do a number of things in order
to get a CPU running in Protected Mode (PM). Off the top of my head
they include these
Be aware of what the BIOS will have set before running your code
- Lower memory (below 32k) layout
- Stack
- Segement regs (none but CS and SS)
- NMI may be tied to a watchdog (?)
- Already extant interrupt vectors
- There may be less than 640k of base mem available
Identify the basic CPU
If CPU too old print a diagnostic and stop (preferably in a halt loop)
Ensure your disk read code is loaded (for accessing the disk after
moving to PM). You may want to checksum (or even CRC) your code to be
sure it all loaded properly.
Capture data already on screen if desired
Set video mode if desired
Get memory map - try a sequence of methods until one works
- start with int 0x15 0xe820
- you should find other calls documented therefrom
Gather other info from the BIOS
- various calls
- not easy to do once in PM
Enable A20
- must be done in real mode
- a raft of different methods depending on the machine
Set up PM data structures
- GDT
- LDT (or at least handle failed refs to it)
- IDT
Possibly identify the PICs - 1 or 2
Redirect (or at least ensure you've covered) PIC IRQs
Fill in basic IDT entries to handle IRQs and other interrupts
Disable NMI
cli
Go to PM
| Quote: |
Now that's not my only question From everything that I have read,
all that a boot loader does is loads a kernel and enable the A20 line.
If this is true, why do people talk about loading another program from
the boot loader because 512 bytes is not enough? What else goes into
the boot loader that takes up all of that space?
|
See the list above. You can, and probably should, deal with most of
that in a file which is loaded by your boot sector. In other words,
keep the boot sector as simple and generic as you can.
Some general comments on other things that would require more space
than is available in a boot sector:
Be prepared to print diagnostics. Your code at the moment is a good
start in that in that it prints to the screen. But it sounds as though
you expect simple code to work on any machine. Remember that if normal
program code fails the OS deals with it and communicates with the
user. If you are the OS you need to deal with any failures that may
occur.
Bear in mind that all PCs are not the same. In fact they are _very_
different. Handling the differences is a big part of writing an OS if
you want your code to work on real machines.
Think as an engineer. Program defensively and include checks.Code
according to specs rather than specific machines. Look out for non-
conforming machine behaviour as, unfortunately, your code will be
expected to work round anomalies (rather than the manufacturer fix the
PC!).
Consider what would happen if your OS were booted in a non-English
speaking country. Would the diagnostics be helpful? (Supplying paper
documentation to explain the English diagnostics may be enough.)
| Quote: |
I know that this question makes it very obvious that I'm a noob and
don't know what I'm talking about, but I would really appreciate your
help. Thanks.
|
Not at all. It's a good question. Don't be afraid to post 'daft'
questions here but do check the archives (available on Google if not
elsewhere) and make use of the FAQ that goes with this newsgroup
http://aodfaq.wikispaces.com
--
James |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
Ciaran Keating Guest
|
Posted: Tue Jun 17, 2008 11:03 am Post subject: Re: Boot Loader Purpose |
|
|
On Tue, 17 Jun 2008 14:22:23 +1000, <robhorvath@att.net> wrote:
| Quote: |
There's no reason to write a boot
loader, because it's been done, much more robustly than you could hope
to acheive.
write a multiboot compliant kernel and forget the rest. You get the
advantage of being able to use the filesystem of your choice, you get
the machine in a known state, and you can concentrate on YOUR os, not
on a problem that's been tackled for two decades.
|
I think I know what you mean, but I still always find it funny that some
people dismiss writing your own bootloader as reinventing the wheel
because there are already lots of bootloaders out there, but they don't
make the same judgement about writing your own OS.
| Quote: |
Don't get me wrong, it's a very educational experience,
|
It is, and that's my sole motivation. That's why I was happy to write my
own :-)
Indeed, for education (depending on just what kind of education you want)
it may be a disadvantage to have someone else's bootloader put the machine
in a known state for you.
| Quote: |
but you'll spend 6 months on it,
|
Perhaps, if you want to write a robust industrial-strength bootloader!
(And I confess, once again, that it was easier for me to write my own than
to figure out how to use grub!)
| Quote: |
and at the end you'll realize that if you really
want other people to use your OS, it'll need to work with grub.
|
Probably true. So, to thestew42: do you want other people to use your OS?
| Quote: |
tons of time
that you could've used toward something more productive.
|
Again, probably true. But of course it does depend on your definition of
"productive".
--
Ciaran Keating
Amadan Technologies |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
James Harris Guest
|
Posted: Tue Jun 17, 2008 2:52 pm Post subject: Re: Boot Loader Purpose |
|
|
On 17 Jun, 05:22, robhorv...@att.net wrote:
....
| Quote: |
And you've stumbled upon the great question. Truth be told, all of us
go through this, but at the end of the day, we (well, most of us) come
to the same realization. A boot loader (at least one people will
actually use) already exists: grub. There's no reason to write a boot
loader, because it's been done, much more robustly than you could hope
to acheive. It's such a small part of the OS, and incredibly time
consuming and complex to get right. My advice is to learn how to
write a multiboot compliant kernel and forget the rest. You get the
advantage of being able to use the filesystem of your choice, you get
the machine in a known state, and you can concentrate on YOUR os, not
on a problem that's been tackled for two decades.
|
Well, this sounds good but Grub seems awful! I've tried a number of
times (quite half-heartedly I grant you) to see if I could work with
Grub. In fact IIRC when I wrote my floppy boot loader Lilo was the
weapon of choice and people told me I should have used it. Each time I
got to screeds of unhelpful documentation and chose to go back to the
simpler and arguably better documented 0x7c00 PC boot method.
To take the case in point (and to be sure my prejudice against Grub
was not misplaced from Lilo) I checked for current Grub docs. I find
that there are two versions of Grub. The latest, version 2, does not
seem to be documented yet. Version "legacy" docs seem to talk about
running Grub under Linux rather than using it a a boot tool for my OS.
Can anyone provide a direct link on how to use it for booting?
The Grub "legacy" manual makes this not-encouraging statement:
"To create a GRUB boot floppy, you need to take the files stage1 and
stage2 from the image directory, and write them to the first and the
second block of the floppy disk, respectively.
"Caution: This procedure will destroy any data currently stored on the
floppy."
Nice!
| Quote: |
Don't get me wrong, it's a very educational experience, but you'll
spend 6 months on it, and at the end you'll realize that if you really
want other people to use your OS, it'll need to work with grub. At
that point, you're still at square 1, but you've wasted tons of time
that you could've used toward something more productive.
|
Again, the principle seems good but Grub seems to me to be very poor.
Even when using it to boot Linux it is _so_ user unfriendly. Is it
really better than writing one's own boot loader?
--
James |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
Kristof Benes Guest
|
Posted: Tue Jun 17, 2008 6:05 pm Post subject: Re: Boot Loader Purpose |
|
|
On Jun 16, 8:07 pm, thestew42 <prgmer...@gmail.com> wrote:
| Quote: |
I'm having trouble understanding exactly what a boot loader is
supposed to do.
A few days ago I got really excited about programming an operating
system. I have been doing C/C++ stuff for years now. So I did some
research, and determined that I needed to write a boot loader to
start. I went and learned some basic assembly, read many tutorials,
and wrote a boot loader... but all it does is print a string to the
screen. Yay.
I understand that a boot loader is supposed to load your os kernel,
but I'm not even sure of how to do this because none of the things
that I read on boot loaders taught you how to do anything but print
characters to the screen. I did read something about needing to write
a FAT compatible boot loader and kernel, but is this really necessary?
I mean, if you have control over all of the file system, why cant you
just put the kernel right after to boot loader and be done with it?
Why do you have to use FAT?
Now that's not my only question From everything that I have read,
all that a boot loader does is loads a kernel and enable the A20 line.
If this is true, why do people talk about loading another program from
the boot loader because 512 bytes is not enough? What else goes into
the boot loader that takes up all of that space?
I know that this question makes it very obvious that I'm a noob and
don't know what I'm talking about, but I would really appreciate your
help. Thanks.
|
Hi Stew,
Glad to see another C programmer in here :-)
When you start out your kernel, 99% of the time it will be on a
floppy. Porting to work off of a hard disk is a post user binary
handling thing IMO. Usually that is, you can do it however you want,
thats the beauty of OS development. But I've found that if your
loader can support FAT12, it makes it a lot easier to test on real
hardware. You can just copy the kernel file from Window$ to the A
drive. Unfortunately it does take up most of the 512 bytes available
to load a file into memory, much less all the other things needed to
set the system up to run a C program. Myself, I have a two stage
loader, the bootsector loads a file, jumps to it which in turn loads
the kernel binary, relocates it to where it needs to go, sets up A20,
GDT, and Pmode and off it goes. Then I simply have to copy kernel.bin
from my project directory to the floppy to test it.
Theres a great FAT 12 tutorial at http://www.vnutz.com/content/program_a_bootstrap_loader
also look at the bibliography at the end, some useful links down there
too.
I hope youve also had a look at Bochs? That makes life a ton easier
too. The problem with the above tutorial which includes NASM code for
a whole compliant bootsector is that it loads the file at 0x500. So
its not entirely a cut and paste operation. As you may see on the
posts here, messing around below 0x800 is a bad idea. Also if you
reuse the FAT12 code for a second stage, its very likely that your
kernel will grow to over 64k, and that example code couldnt handle
it. So youd need to change that too if you decide to use a two stage
loader.
Also what environment are you planning to do the kernel (C code) of it
in? If its Cygwin or gcc on a *nix box, I've got a great section of
code that loads an elf file into memory where its supposed to go and
can give some pointers on the compile flags. Also its a good idea to
get a thourough understanding of how your compiler works. What C code
makes what ASM. There are several times you will have to use ASM and
C mixed and need to manipulate some things that normal C programmers
wouldnt dare (syscalls and task switching to name a few). Anyway that
might be getting ahead, but its best to plan now cause it sucks to
come back to a bootloader problem after writing half your kernel, or
to realize that your current tools will take you only so far.
Best of luck and were all usually always happy to help. |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
Kristof Benes Guest
|
Posted: Tue Jun 17, 2008 6:15 pm Post subject: Re: Boot Loader Purpose |
|
|
On Jun 17, 7:52 am, James Harris <james.harri...@googlemail.com>
wrote:
| Quote: |
On 17 Jun, 05:22, robhorv...@att.net wrote:
...
And you've stumbled upon the great question. Truth be told, all of us
go through this, but at the end of the day, we (well, most of us) come
to the same realization. A boot loader (at least one people will
actually use) already exists: grub. There's no reason to write a boot
loader, because it's been done, much more robustly than you could hope
to acheive. It's such a small part of the OS, and incredibly time
consuming and complex to get right. My advice is to learn how to
write a multiboot compliant kernel and forget the rest. You get the
advantage of being able to use the filesystem of your choice, you get
the machine in a known state, and you can concentrate on YOUR os, not
on a problem that's been tackled for two decades.
Well, this sounds good but Grub seems awful! I've tried a number of
times (quite half-heartedly I grant you) to see if I could work with
Grub. In fact IIRC when I wrote my floppy boot loader Lilo was the
weapon of choice and people told me I should have used it. Each time I
got to screeds of unhelpful documentation and chose to go back to the
simpler and arguably better documented 0x7c00 PC boot method.
To take the case in point (and to be sure my prejudice against Grub
was not misplaced from Lilo) I checked for current Grub docs. I find
that there are two versions of Grub. The latest, version 2, does not
seem to be documented yet. Version "legacy" docs seem to talk about
running Grub under Linux rather than using it a a boot tool for my OS.
Can anyone provide a direct link on how to use it for booting?
The Grub "legacy" manual makes this not-encouraging statement:
"To create a GRUB boot floppy, you need to take the files stage1 and
stage2 from the image directory, and write them to the first and the
second block of the floppy disk, respectively.
"Caution: This procedure will destroy any data currently stored on the
floppy."
Nice!
Don't get me wrong, it's a very educational experience, but you'll
spend 6 months on it, and at the end you'll realize that if you really
want other people to use your OS, it'll need to work with grub. At
that point, you're still at square 1, but you've wasted tons of time
that you could've used toward something more productive.
Again, the principle seems good but Grub seems to me to be very poor.
Even when using it to boot Linux it is _so_ user unfriendly. Is it
really better than writing one's own boot loader?
--
James
|
Yeah GRUB is gay I agree. Besides look at the real world, whats the
only OS that uses it? Linux. And I would bet that it has more to do
with Richard Stallman than actual necessity. BSDs dont use it. QNX,
BeOS, Plan9, or any of the other myriad of alternative operating
systems dont use it. Although theoretically possible to use it to
boot anything, I'd like to see someone use GRUB to boot FreeBSD.
Every operating system has its own boot scheme, and maybe thats the
way it should be. Have you ever disassembled a Windows boot sector?
Scary. |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
thestew42 Guest
|
Posted: Wed Jun 18, 2008 1:56 am Post subject: Re: Boot Loader Purpose |
|
|
Alright, thanks a lot everyone. This is certainly a lot to think
about. I now understand why you may want to make the boot loader
compatible with the file system of it's drive.
Thanks to everyone for the nice welcome too! I will definitely
remember this group if I am in need of assistance. |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
thestew42 Guest
|
Posted: Wed Jun 18, 2008 2:04 am Post subject: Re: Boot Loader Purpose |
|
|
On Jun 17, 2:05 pm, Kristof Benes <Chris.Bene...@gmail.com> wrote:
| Quote: |
On Jun 16, 8:07 pm, thestew42 <prgmer...@gmail.com> wrote:
I'm having trouble understanding exactly what a boot loader is
supposed to do.
A few days ago I got really excited about programming an operating
system. I have been doing C/C++ stuff for years now. So I did some
research, and determined that I needed to write a boot loader to
start. I went and learned some basic assembly, read many tutorials,
and wrote a boot loader... but all it does is print a string to the
screen. Yay.
I understand that a boot loader is supposed to load your os kernel,
but I'm not even sure of how to do this because none of the things
that I read on boot loaders taught you how to do anything but print
characters to the screen. I did read something about needing to write
a FAT compatible boot loader and kernel, but is this really necessary?
I mean, if you have control over all of the file system, why cant you
just put the kernel right after to boot loader and be done with it?
Why do you have to use FAT?
Now that's not my only question From everything that I have read,
all that a boot loader does is loads a kernel and enable the A20 line.
If this is true, why do people talk about loading another program from
the boot loader because 512 bytes is not enough? What else goes into
the boot loader that takes up all of that space?
I know that this question makes it very obvious that I'm a noob and
don't know what I'm talking about, but I would really appreciate your
help. Thanks.
Hi Stew,
Glad to see another C programmer in here :-)
When you start out your kernel, 99% of the time it will be on a
floppy. Porting to work off of a hard disk is a post user binary
handling thing IMO. Usually that is, you can do it however you want,
thats the beauty of OS development. But I've found that if your
loader can support FAT12, it makes it a lot easier to test on real
hardware. You can just copy the kernel file from Window$ to the A
drive. Unfortunately it does take up most of the 512 bytes available
to load a file into memory, much less all the other things needed to
set the system up to run a C program. Myself, I have a two stage
loader, the bootsector loads a file, jumps to it which in turn loads
the kernel binary, relocates it to where it needs to go, sets up A20,
GDT, and Pmode and off it goes. Then I simply have to copy kernel.bin
from my project directory to the floppy to test it.
Theres a great FAT 12 tutorial athttp://www.vnutz.com/content/program_a_bootstrap_loader
also look at the bibliography at the end, some useful links down there
too.
I hope youve also had a look at Bochs? That makes life a ton easier
too. The problem with the above tutorial which includes NASM code for
a whole compliant bootsector is that it loads the file at 0x500. So
its not entirely a cut and paste operation. As you may see on the
posts here, messing around below 0x800 is a bad idea. Also if you
reuse the FAT12 code for a second stage, its very likely that your
kernel will grow to over 64k, and that example code couldnt handle
it. So youd need to change that too if you decide to use a two stage
loader.
|
I have gotten Bochs, but I haven't really used it yet. Until now I've
just been using an old laptop that boots up fairly quickly.
| Quote: |
Also what environment are you planning to do the kernel (C code) of it
in? If its Cygwin or gcc on a *nix box, I've got a great section of
code that loads an elf file into memory where its supposed to go and
can give some pointers on the compile flags. Also its a good idea to
get a thourough understanding of how your compiler works. What C code
makes what ASM. There are several times you will have to use ASM and
C mixed and need to manipulate some things that normal C programmers
wouldnt dare (syscalls and task switching to name a few). Anyway that
might be getting ahead, but its best to plan now cause it sucks to
come back to a bootloader problem after writing half your kernel, or
to realize that your current tools will take you only so far.
Best of luck and were all usually always happy to help.
|
Yes, I have Cygwin and DJGPP. I haven't actually started any kernel
coding but I think I'll try Cygwin first because it's what most people
seem to recommend. |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
Rod Pemberton Guest
|
Posted: Wed Jun 18, 2008 6:24 am Post subject: Re: Boot Loader Purpose |
|
|
"Kristof Benes" <Chris.Benesch@gmail.com> wrote in message
news:ac2aaa8c-23d5-4e7b-b8bd-caec15a923d9@p25g2000pri.googlegroups.com...
| Quote: |
When you start out your kernel, 99% of the time it will be on a
floppy.
|
Why?
Why take that route with QEMU, Bochs, etc., available? Produce your OS as a
standard executable for your host environment. Write your bootloader to
exec that executable format or use a multi-boot header. I'm starting from a
32-bit DPMI DOS exe... uses a TSR to unload DPMI:
http://groups.google.com/group/alt.os.development/msg/527670c048676d5d
| Quote: |
I've got a great section of
code that loads an elf file into memory where its supposed to go and
can give some pointers on the compile flags.
|
Chris Giese's MBLOAD
http://my.execpc.com/~geezer/temp/mbload.zip
Rod Pemberton |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
Kristof Benes Guest
|
Posted: Wed Jun 18, 2008 9:16 pm Post subject: Re: Boot Loader Purpose |
|
|
On Jun 17, 6:24 pm, "Rod Pemberton" <do_not_h...@nohavenot.cmm> wrote:
| Quote: |
"Kristof Benes" <Chris.Bene...@gmail.com> wrote in message
news:ac2aaa8c-23d5-4e7b-b8bd-caec15a923d9@p25g2000pri.googlegroups.com...
When you start out your kernel, 99% of the time it will be on a
floppy.
Why?
Why take that route with QEMU, Bochs, etc., available? Produce your OS as a
standard executable for your host environment. Write your bootloader to
exec that executable format or use a multi-boot header. I'm starting from a
32-bit DPMI DOS exe... uses a TSR to unload DPMI:http://groups.google.com/group/alt.os.development/msg/527670c048676d5d
I've got a great section of
code that loads an elf file into memory where its supposed to go and
can give some pointers on the compile flags.
Chris Giese's MBLOADhttp://my.execpc.com/~geezer/temp/mbload.zip
Rod Pemberton
|
Everyones got their preferences. Most people do the floppy thing. |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
James Harris Guest
|
Posted: Wed Jun 18, 2008 11:24 pm Post subject: Re: Boot Loader Purpose |
|
|
On 18 Jun, 22:05, Francesco Salvestrini <salvestr...@gmail.com> wrote:
| Quote: |
James Harris wrote:
On 17 Jun, 05:22, robhorv...@att.net wrote:
...
The Grub "legacy" manual makes this not-encouraging statement:
"To create a GRUB boot floppy, you need to take the files stage1 and
stage2 from the image directory, and write them to the first and the
second block of the floppy disk, respectively.
"Caution: This procedure will destroy any data currently stored on the
floppy."
Nice!
In order to speed-up the change-compile-test phase I use grub and bochs,
booting my multiboot compliant elf-kernel from an ISO image created using
mkisofs.
PROS: The procedure avoids mounting a dd image using loop.
CONS: Every time I must rebuild the whole image.
A stripped-down procedure (ask comments, if interested) to build the image:
* mkdir -p iso/boot/grub
* cp -f /lib/grub/i386-pc/stage2_eltorito iso/boot/grub
* cp -f src/kernel iso/boot
* echo -e "timeout=1\ntitle KERNEL\n\tkernel /boot/kernel"
iso/boot/grub/menu.lst
* /usr/bin/mkisofs -R -b
boot/grub/stage2_eltorito -no-emul-boot -boot-load-size
4 -boot-info-table -o image.iso iso
The real procedure uses some utility scripts in order to avoid hard-wired
paths.
|
Thanks for posting this. It's more helpful than what I found in the
Grub docs. It's quite a sequence, though. By way of comparison, I
copied my stage 1 boot loader to the boot sector of a standard floppy
and, once that was done I can copy the stage 2 loader to the floppy
any time with a normal copy command, e.g. under Windows/DOS
copy osload01.sys a:\
It's been a long time since I used Bochs. Presumably the same floppy
image can be used. |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
thestew42 Guest
|
Posted: Thu Jun 19, 2008 12:46 am Post subject: Re: Boot Loader Purpose |
|
|
Alright, I've been working at this thing for a good amount of time
now. I'm still having trouble grasping how to load different sectors
from the disk. I decided to make a FAT compatible boot sector that
loads a segment of code which initializes everything else. The problem
is, that I'm not sure how to load the initialization code sector from
the disk. I have the boot sector and initialization code in separate
source files. Do you just use a jmp instruction with the memory
location of the initialization code as the parameter? Also, does it
matter if the initialization code is more than 512 bytes or do I have
to do something special in order to load all of the sectors? Thank you
all for your previous assistance, I really appreciate your answers. |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
Kristof Benes Guest
|
Posted: Thu Jun 19, 2008 2:56 am Post subject: Re: Boot Loader Purpose |
|
|
On Jun 18, 5:46 pm, thestew42 <prgmer...@gmail.com> wrote:
| Quote: |
Alright, I've been working at this thing for a good amount of time
now. I'm still having trouble grasping how to load different sectors
from the disk. I decided to make a FAT compatible boot sector that
loads a segment of code which initializes everything else. The problem
is, that I'm not sure how to load the initialization code sector from
the disk. I have the boot sector and initialization code in separate
source files. Do you just use a jmp instruction with the memory
location of the initialization code as the parameter? Also, does it
matter if the initialization code is more than 512 bytes or do I have
to do something special in order to load all of the sectors? Thank you
all for your previous assistance, I really appreciate your answers.
|
Stew,
Have a look at http://www.vnutz.com/content/program_a_bootstrap_loader
And in reply to Francesco, there is a neat utility in OpenBSD called
vnd which allows you to set up a file as a raw disk image and then
mount it and copy files to it, etc... Then once its done, just
unmount, dd the data out of /dev/vnd0 and theres your disk image. I
dont know if Linux has something similar? |
|
| Back to top |
|
 |
| |
Ads |
Advertising
Sponsor
|
|
|
|
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
|

130 Attacks blocked
Powered by phpBB © 2001, 2005 phpBB Group
|