Goal
Provide the ability to load a task
In the last labwork, you implemented a command prompt, you need to be able to execute commands in it. This means that when you type hello for example, you OS should execute the cmd_hello function.
Things you need
- create a
cmddirectory in your lab folder - download an updated Makefile to your lab folder and replace the original one
- create a
cmd_somecommand.cincmddirectory you created
A cmd_* file must have the following structure:
void cmd_somecommand (void) {
// your code goes here
}
If you compile you project using the new Makefile, then the cmd_somecommand function will be available in your kernel. This means that you will be able to call cmd_somecommand in your OS, without #include-ing the cmd file in your source code.
This also means that if you want to add a new command to your OS, you need to create a new cmd_* file in your cmd folder.
Challenges
Load a task without ifs or switches (+20 EXP)
Find a way to execute dynamically the function which the user typed.
Pass parameters to your commands (+30 EXP)
Your kernel must pass command parameters to the command function, this means that the command accepts a char* as a parameter.
This also changes the fingerprint of a command to:
void cmd_somecommand (char *args) {
// your code goes here
}
To demonstrate this you will need to write a sample comand which greets the user. When I will type greet Andrei, the command must output hello, Andrei!
Implement console switching (+50 EXP)
You should be able to run multiple command prompts at the same time, and switch them using Ctrl+<id> or any other hotkey of your choosing.
This means that you have to allocate several memory pools for each screen, and when you switch to a terminal, you write it’s memory to video memory and set it as active.
To achieve that, you’ll need to take care of several things:
- change the
putcfunction to write to current terminal, rather than directly to video memory. - implement
getc, which will does the same things asgetchar, with the diffrence that when it receivesCtrl+<number>, it should switch the terminals, otherwise it should delegate the control further togetchar.