rellermeyer / course_os

CS 439 course OS
BSD 3-Clause "New" or "Revised" License
38 stars 26 forks source link

Parsing Kernel Arguments #21

Open rellermeyer opened 10 years ago

rellermeyer commented 10 years ago

Once we have more of the kernel up and running we might want to pass arguments to it, e.g., to selectively load user processes. Therefore, we need an argument parser.

SheldonSandbekkhaug commented 10 years ago

I'm willing to work on this.

SheldonSandbekkhaug commented 10 years ago

Do you mean something like a command line prompt for the OS, or arguments given at "VersatilePB" prompt?

rellermeyer commented 10 years ago

Sorry, I missed this one. The former would be a shell to me, I am thinking something else, the arguments passed to qemu and/or the bootloader. E.g., in Linux that would be the "root=..." etc.

SheldonSandbekkhaug commented 10 years ago

I added basic argument parsing functionality (it will be later expanded) with commit d617f8f451593cac267115fb7206def47ef76849. I'm still trying to find a way to correctly pass arguments to the kernel via QEMU (perhaps -append ARGS is what I'm looking for). Do arguments from -append ARGS get passed to start()?

rellermeyer commented 10 years ago

I don't think so. Maybe you find documentation where Linux gets them from. It should happen in Linux' init/main.c file.

SheldonSandbekkhaug commented 10 years ago

I've looked through the Linux source code and I've been trying to understand how kernel parameters are read. This is my understanding:

From main.c, start_kernel() calls setup_arch() in arch/arm/kernel/setup.c, which calls which calls setup_machine_tags() in arch/arm/kernel/atags_parse.c. setup_machine_tags() copies a variable called "from" to boot_command_line. I think "from" is set by a function that mdesc has a function pointer to.

Here's where I'm stumped: setup_machine_tags() has struct machine desc called "mdesc" that is set to a variable named "p". Unfortunately, I can't find a struct machine desc called "p".

Here's the part in question:

http://lxr.free-electrons.com/source/arch/arm/kernel/atags_parse.c#L196

Am I going in the right direction, or is there a better way?

SheldonSandbekkhaug commented 10 years ago

I seemed to be blocked by this. Now that the test is over, am I moving in the right direction? I still can't figure out how to obtain the kernel arguments.

rellermeyer commented 10 years ago

The bootloader should pass you a parameter list in R2: https://www.kernel.org/doc/Documentation/arm/Booting

I pushed some minor changes so that you now get the start address of the parameter list as the first argument in start.c

The current implementation simply prints them to the screen. I guess that should give you what you need.

rellermeyer commented 10 years ago

Here is some more information about the tagged list format. I guess all we need at the moment is the content of the ATAG_CMDLINE tag, all others can be skipped over.

http://www.simtec.co.uk/products/SWLINUX/files/booting_article.html#ATAG_CORE

SheldonSandbekkhaug commented 10 years ago

I added a function to read ATAG_CMDLINE in b6ab304f4a0e47d228248f9696b787eb7bba2b18. However, I tried adding -append "option=value" to the qemu command, but "option=value" doesn't appear in ATAG_CMDLINE. Is this the right way to pass arguments through qemu?