Hi!
Korona wrote:
The last point (no allocation) is interesting. How do you achieve that? Does it already work or is this only a concept?
iocoder wrote:
So do you load all programs (demons) at once when the system boots up? What if I want to execute multiple instances of the same program, wouldn't memory be dynamically allocated for the new instances in that case?
This is more than a concept by this point I think, it's more of a working prototype or something. In the kernel I have allocated a fixed amount of memory for each task and I have a fixed number of tasks (both can only be set during compile-time). Something like 1MB * 128 tasks or something like that which would take up 128MB of RAM. The programs themselves can only use their 1MB for code and data and can not allocate any more. So the only thing memory-wise that could fail is that you could run out of free tasks but as of right now the OS doesn't use a fraction of those 128 slots, more like 4 or something. Yes you can have multiple instances of the same program. Interestingly, some programs (daemons) can actually run as a single instance for example a program like "ls" and all invocations of ls would just reuse the already running one. I don't have it like that right now but I could and I have tried it just quickly but I don't know if it's a good idea. Also, starting all daemons at boot could potentially work as well but that's not how it works right now. I will have to think about it more, it's not a bad idea.
EDIT: I checked because I didn't quite remember, the actual size I use right now by default is (512K for code and data + 32K for stack) * 128 tasks.
EDIT 2: This is the hello world program, just so you can see what a userspace program looks like. Syntax/naming of stuff is subject to change. Basically it starts by setting up a channel and a bunch of callbacks for when it receives different types of messages on that channel. The badly named EMPTY message is what will be sent to this program when it is called with no inputs which will trigger the onempty handler which in turn will reply with a DATA message containing the text "Hello World!" to the source that sent the EMPTY message. Anyone can go in and hijack this reply by sending a REDIRECT message to this program telling it to forward any DATA message to some other source. If it receives the DONE message it will close the channel which will make the program quit.
Code:
#include <fudge.h>
#include <abi.h>
static void ondone(struct channel *channel, unsigned int source, void *mdata, unsigned int msize)
{
channel_close(channel);
}
static void onempty(struct channel *channel, unsigned int source, void *mdata, unsigned int msize)
{
channel_request(channel, EVENT_DATA);
channel_appendstring(channel, "Hello world!\n");
channel_place(channel, source);
}
static void onredirect(struct channel *channel, unsigned int source, void *mdata, unsigned int msize)
{
struct event_redirect *redirect = mdata;
channel_setredirect(channel, redirect->type, redirect->mode, redirect->id, source);
}
void main(void)
{
struct channel channel;
channel_init(&channel);
channel_setsignal(&channel, EVENT_DONE, ondone);
channel_setsignal(&channel, EVENT_EMPTY, onempty);
channel_setsignal(&channel, EVENT_REDIRECT, onredirect);
channel_listen(&channel);
}