Page 1 of 1
[BOOTLOADER] Passing arguements to kernel
Posted: Sat Jan 14, 2006 6:14 pm
by dh
I'm totally n00bed about writing a bootloader so I have to ask questions before I go up to my neck
.
Firstly, when the second stage loads, and opens up a menu (simple text menu, where a number is an OS to load. Purly Chainloading). I want to have the Bootloader do some GRUB-like activities (minus the entry of P-Mode of coarse
) like setting the A20 gate (unreal mode), finding memory size, CPU speed and abilities (MMX, SSE2, etc.), then pass all that to the kernel in a nice simple structure placed before the kernel (the kernel is loaded to 1m, 8k) at 1m 1k (giving me ~7k flexability). I have a few questions regarding this:
- Is it a GOOD IDEA to pass [some] things to the kernel via the stack instead of using a section of memory
- If so, where's and ideal place to place the stack
My mind just went blank (and these sheets of looseleaf with designs isn't helping). All I can think of is: load kernel, make BOOTSTRUCT, put things on stack, then jump to x86_boot.
Cheers, DH.
ps. I'll have more later (I hope
)
Re:[BOOTLOADER] Passing arguements to kernel
Posted: Sat Jan 14, 2006 6:31 pm
by Rob
I have no experience with this, but why not pass a pointer
(either 32 bit p-mode or 16-bit with segment en offset) to
a structure both sides understand? That structure can point
to other places / structures in a similar way. That should
keep it flexible where you store things and you only need to
pass a 32-bit value (or 64-bit of you are developing for that
platform). Which can be done in one or multiple registers for
example.
Re:[BOOTLOADER] Passing arguements to kernel
Posted: Sat Jan 14, 2006 6:33 pm
by kataklinger
Well stack IS section of memory, so it's the same. And there is no wrong (except ROM or MM device space
) or right place to put the information. The best place should be where kernel can easily see it.
And about CPU abilities: I would leave it to kernel.
Re:[BOOTLOADER] Passing arguements to kernel
Posted: Sat Jan 14, 2006 6:41 pm
by kataklinger
The only difference between these two cases is register's names:
- SS:ESP = stack
- DS/ES/FS/GS:EAX/EBX... = memory section
or maybe rsp, rax... if you use 64bit CPU.
Re:[BOOTLOADER] Passing arguements to kernel
Posted: Sat Jan 14, 2006 7:06 pm
by Rob
kataklinger: that's true, it's all semantics. I just wanted to
show a different "thought". When I hear stack I'm thinking
about pushing a popping which didn't make a whole lot of
sense with a "structure" (or multiple ones). Of course you
could push a pointer up the stack and pop that, which I
think makes more sense. Or pass it in a register. In the end
it all belongs to your design and what you thinks best suits
the task.
Re:[BOOTLOADER] Passing arguements to kernel
Posted: Sat Jan 14, 2006 7:40 pm
by Kevin McGuire
It is a good idea to pass things to the kernel on the stack, if you have enough room on the stack for them and some extra space for your kernel's functions which will be pushing and poping arguments.
It is also a good idea to use some place in memory to place the arguments.
It just depends on what is easier for you. Using the stack may be better and more compact if possible - keeping you from trying to find the perfect place to put those arbitrary arguments you are passing.
You were loading your kernel to the 1MB mark. How about placing the stack right before your kernel, or after it. You could give the stack only 512 bytes and it should be fine.
I know you said you wanted to do some GRUB like things, but it may be easier to use GRUB instead?
Re:[BOOTLOADER] Passing arguements to kernel
Posted: Sun Jan 15, 2006 4:35 am
by kataklinger
If you need to pass a lot of data, think about some place where you can discharge memory. The good place should be on page bound, before kernel.
Re:[BOOTLOADER] Passing arguements to kernel
Posted: Sun Jan 15, 2006 12:19 pm
by dh
GRUB gave me nothing but problems.
- Couldn't access structure
- P-Mode (i want to do stuff in Real-Mode FIRST, and it's a hassle to switch back )
- I'm fussy
Thanks for the words
.
Cheers, DH.
Re:[BOOTLOADER] Passing arguements to kernel
Posted: Sun Jan 15, 2006 4:31 pm
by kataklinger
Sorry for asking, but what do you want to do in real mode?
Re:[BOOTLOADER] Passing arguements to kernel
Posted: Sun Jan 15, 2006 8:07 pm
by Dex4u
Re:[BOOTLOADER] Passing arguements to kernel
Posted: Wed Jan 18, 2006 6:41 pm
by dh
@Dex: kool
. I'll check it out (it appears to be a tad dated). Thanks
I want to be able to do VESA stuff without the V86 stuff later. Basically, I'm planning for future development where this _may_ be usefull
.
Cheers, DH.
PS. I'm not going to be very active for the next week or so, I have exams
. I'll be working on the bootloader starting saturday to get a basic Stage1 (based on various sources) fleshed out
. Thanks for the advice!
Re:[BOOTLOADER] Passing arguements to kernel
Posted: Fri Jan 20, 2006 10:55 pm
by zateam
Re:[BOOTLOADER] Passing arguements to kernel
Posted: Sat Jan 21, 2006 10:26 am
by dh
@zateam: sorry, i'll pass on that offer
.
Cheers, DH.