[BOOTLOADER] Passing arguements to kernel

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
dh

[BOOTLOADER] Passing arguements to kernel

Post by dh »

I'm totally n00bed about writing a bootloader so I have to ask questions before I go up to my neck :P.

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 :D) 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 :P)
Rob

Re:[BOOTLOADER] Passing arguements to kernel

Post 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.
User avatar
kataklinger
Member
Member
Posts: 381
Joined: Fri Nov 04, 2005 12:00 am
Location: Serbia

Re:[BOOTLOADER] Passing arguements to kernel

Post 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.
User avatar
kataklinger
Member
Member
Posts: 381
Joined: Fri Nov 04, 2005 12:00 am
Location: Serbia

Re:[BOOTLOADER] Passing arguements to kernel

Post 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.
Rob

Re:[BOOTLOADER] Passing arguements to kernel

Post 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.
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Re:[BOOTLOADER] Passing arguements to kernel

Post 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?
User avatar
kataklinger
Member
Member
Posts: 381
Joined: Fri Nov 04, 2005 12:00 am
Location: Serbia

Re:[BOOTLOADER] Passing arguements to kernel

Post 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.
dh

Re:[BOOTLOADER] Passing arguements to kernel

Post 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 :P)
  • I'm fussy
Thanks for the words :D.

Cheers, DH.
User avatar
kataklinger
Member
Member
Posts: 381
Joined: Fri Nov 04, 2005 12:00 am
Location: Serbia

Re:[BOOTLOADER] Passing arguements to kernel

Post by kataklinger »

Sorry for asking, but what do you want to do in real mode? :D
Dex4u

Re:[BOOTLOADER] Passing arguements to kernel

Post by Dex4u »

dh

Re:[BOOTLOADER] Passing arguements to kernel

Post by dh »

@Dex: kool :D. 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 :D.

Cheers, DH.

PS. I'm not going to be very active for the next week or so, I have exams :P. I'll be working on the bootloader starting saturday to get a basic Stage1 (based on various sources) fleshed out :D. Thanks for the advice!
dh

Re:[BOOTLOADER] Passing arguements to kernel

Post by dh »

@zateam: sorry, i'll pass on that offer :P.

Cheers, DH.
Post Reply