diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 749aace..c83e0b0 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -10,13 +10,20 @@ void kernelMain() { drawLogo(); - initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work ): otherwise, _kernel_end should be passed here + initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work :( otherwise, _kernel_end should be passed here initOSTasks(); printf("Switching to otherTask... \n"); yields(); printf("Returned to mainTask!\n\n"); - for (int i = 0; i < 20; i++) { - printf("%x\n", i); - } + // for (int i = 0; i < 20; i++) { + // printf("%x\n", i); + // } + char* data = "Hello World from the new system!\n"; + Message message; + message.data = data; + message.size = strlen(data); + message.next = 0x00; + sendMessage(getPrinterTask(), &message); + schedule(getPrinterTask()); yield(); } \ No newline at end of file diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 749aace..c83e0b0 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -10,13 +10,20 @@ void kernelMain() { drawLogo(); - initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work ): otherwise, _kernel_end should be passed here + initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work :( otherwise, _kernel_end should be passed here initOSTasks(); printf("Switching to otherTask... \n"); yields(); printf("Returned to mainTask!\n\n"); - for (int i = 0; i < 20; i++) { - printf("%x\n", i); - } + // for (int i = 0; i < 20; i++) { + // printf("%x\n", i); + // } + char* data = "Hello World from the new system!\n"; + Message message; + message.data = data; + message.size = strlen(data); + message.next = 0x00; + sendMessage(getPrinterTask(), &message); + schedule(getPrinterTask()); yield(); } \ No newline at end of file diff --git a/src/kernel/lib/task/osTasks.c b/src/kernel/lib/task/osTasks.c index 74d70f6..f053d31 100644 --- a/src/kernel/lib/task/osTasks.c +++ b/src/kernel/lib/task/osTasks.c @@ -2,19 +2,31 @@ #include #include #include +#include Task mainTask; -Task testTask; +Task printerTask; -void testMain() { - printf("Hello from another task!\n"); - yields(); - printf("wait. . . Hello again\n"); - destroyCurrentTask(); +void printLoop() { + while (1) { + yield(); + Message* message = popMessage(&printerTask); + if (message == 0x00) { + continue; + } + printf("PRINT\n"); + putChars(message->data, message->size); + free(message->data); + free(message); + } } void initOSTasks() { setRunningTask(&mainTask); - createTask(&testTask, (uint32_t) testMain, 0x0, 0x0); - schedule(&testTask); + createTask(&printerTask, (uint32_t) printLoop, 0x0, 0x0); + schedule(&printerTask); +} + +inline Task* getPrinterTask() { + return &printerTask; } \ No newline at end of file diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 749aace..c83e0b0 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -10,13 +10,20 @@ void kernelMain() { drawLogo(); - initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work ): otherwise, _kernel_end should be passed here + initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work :( otherwise, _kernel_end should be passed here initOSTasks(); printf("Switching to otherTask... \n"); yields(); printf("Returned to mainTask!\n\n"); - for (int i = 0; i < 20; i++) { - printf("%x\n", i); - } + // for (int i = 0; i < 20; i++) { + // printf("%x\n", i); + // } + char* data = "Hello World from the new system!\n"; + Message message; + message.data = data; + message.size = strlen(data); + message.next = 0x00; + sendMessage(getPrinterTask(), &message); + schedule(getPrinterTask()); yield(); } \ No newline at end of file diff --git a/src/kernel/lib/task/osTasks.c b/src/kernel/lib/task/osTasks.c index 74d70f6..f053d31 100644 --- a/src/kernel/lib/task/osTasks.c +++ b/src/kernel/lib/task/osTasks.c @@ -2,19 +2,31 @@ #include #include #include +#include Task mainTask; -Task testTask; +Task printerTask; -void testMain() { - printf("Hello from another task!\n"); - yields(); - printf("wait. . . Hello again\n"); - destroyCurrentTask(); +void printLoop() { + while (1) { + yield(); + Message* message = popMessage(&printerTask); + if (message == 0x00) { + continue; + } + printf("PRINT\n"); + putChars(message->data, message->size); + free(message->data); + free(message); + } } void initOSTasks() { setRunningTask(&mainTask); - createTask(&testTask, (uint32_t) testMain, 0x0, 0x0); - schedule(&testTask); + createTask(&printerTask, (uint32_t) printLoop, 0x0, 0x0); + schedule(&printerTask); +} + +inline Task* getPrinterTask() { + return &printerTask; } \ No newline at end of file diff --git a/src/kernel/lib/task/osTasks.h b/src/kernel/lib/task/osTasks.h index 880cedb..b1adecb 100644 --- a/src/kernel/lib/task/osTasks.h +++ b/src/kernel/lib/task/osTasks.h @@ -3,7 +3,8 @@ #include -extern void testMain(); extern void initOSTasks(); +extern Task* getPrinterTask(); + #endif \ No newline at end of file diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 749aace..c83e0b0 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -10,13 +10,20 @@ void kernelMain() { drawLogo(); - initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work ): otherwise, _kernel_end should be passed here + initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work :( otherwise, _kernel_end should be passed here initOSTasks(); printf("Switching to otherTask... \n"); yields(); printf("Returned to mainTask!\n\n"); - for (int i = 0; i < 20; i++) { - printf("%x\n", i); - } + // for (int i = 0; i < 20; i++) { + // printf("%x\n", i); + // } + char* data = "Hello World from the new system!\n"; + Message message; + message.data = data; + message.size = strlen(data); + message.next = 0x00; + sendMessage(getPrinterTask(), &message); + schedule(getPrinterTask()); yield(); } \ No newline at end of file diff --git a/src/kernel/lib/task/osTasks.c b/src/kernel/lib/task/osTasks.c index 74d70f6..f053d31 100644 --- a/src/kernel/lib/task/osTasks.c +++ b/src/kernel/lib/task/osTasks.c @@ -2,19 +2,31 @@ #include #include #include +#include Task mainTask; -Task testTask; +Task printerTask; -void testMain() { - printf("Hello from another task!\n"); - yields(); - printf("wait. . . Hello again\n"); - destroyCurrentTask(); +void printLoop() { + while (1) { + yield(); + Message* message = popMessage(&printerTask); + if (message == 0x00) { + continue; + } + printf("PRINT\n"); + putChars(message->data, message->size); + free(message->data); + free(message); + } } void initOSTasks() { setRunningTask(&mainTask); - createTask(&testTask, (uint32_t) testMain, 0x0, 0x0); - schedule(&testTask); + createTask(&printerTask, (uint32_t) printLoop, 0x0, 0x0); + schedule(&printerTask); +} + +inline Task* getPrinterTask() { + return &printerTask; } \ No newline at end of file diff --git a/src/kernel/lib/task/osTasks.h b/src/kernel/lib/task/osTasks.h index 880cedb..b1adecb 100644 --- a/src/kernel/lib/task/osTasks.h +++ b/src/kernel/lib/task/osTasks.h @@ -3,7 +3,8 @@ #include -extern void testMain(); extern void initOSTasks(); +extern Task* getPrinterTask(); + #endif \ No newline at end of file diff --git a/src/kernel/lib/task/task.c b/src/kernel/lib/task/task.c index 7f4518f..7830302 100644 --- a/src/kernel/lib/task/task.c +++ b/src/kernel/lib/task/task.c @@ -62,4 +62,25 @@ Task* getCurrentTask() { return currentTask; +} + +void sendMessage(Task* task, Message* message) { + if (task->message == 0x00) { + task->message = message; + return; + } + Message* currentMessage = task->message; + while (currentMessage->next == 0x00) { + currentMessage = currentMessage->next; + } + currentMessage->next = message; +} + +Message* popMessage(Task* task) { + Message* currentMessage = task->message; + if (currentMessage != 0x00) { + task->message = currentMessage->next; + + } + return currentMessage; } \ No newline at end of file diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 749aace..c83e0b0 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -10,13 +10,20 @@ void kernelMain() { drawLogo(); - initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work ): otherwise, _kernel_end should be passed here + initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work :( otherwise, _kernel_end should be passed here initOSTasks(); printf("Switching to otherTask... \n"); yields(); printf("Returned to mainTask!\n\n"); - for (int i = 0; i < 20; i++) { - printf("%x\n", i); - } + // for (int i = 0; i < 20; i++) { + // printf("%x\n", i); + // } + char* data = "Hello World from the new system!\n"; + Message message; + message.data = data; + message.size = strlen(data); + message.next = 0x00; + sendMessage(getPrinterTask(), &message); + schedule(getPrinterTask()); yield(); } \ No newline at end of file diff --git a/src/kernel/lib/task/osTasks.c b/src/kernel/lib/task/osTasks.c index 74d70f6..f053d31 100644 --- a/src/kernel/lib/task/osTasks.c +++ b/src/kernel/lib/task/osTasks.c @@ -2,19 +2,31 @@ #include #include #include +#include Task mainTask; -Task testTask; +Task printerTask; -void testMain() { - printf("Hello from another task!\n"); - yields(); - printf("wait. . . Hello again\n"); - destroyCurrentTask(); +void printLoop() { + while (1) { + yield(); + Message* message = popMessage(&printerTask); + if (message == 0x00) { + continue; + } + printf("PRINT\n"); + putChars(message->data, message->size); + free(message->data); + free(message); + } } void initOSTasks() { setRunningTask(&mainTask); - createTask(&testTask, (uint32_t) testMain, 0x0, 0x0); - schedule(&testTask); + createTask(&printerTask, (uint32_t) printLoop, 0x0, 0x0); + schedule(&printerTask); +} + +inline Task* getPrinterTask() { + return &printerTask; } \ No newline at end of file diff --git a/src/kernel/lib/task/osTasks.h b/src/kernel/lib/task/osTasks.h index 880cedb..b1adecb 100644 --- a/src/kernel/lib/task/osTasks.h +++ b/src/kernel/lib/task/osTasks.h @@ -3,7 +3,8 @@ #include -extern void testMain(); extern void initOSTasks(); +extern Task* getPrinterTask(); + #endif \ No newline at end of file diff --git a/src/kernel/lib/task/task.c b/src/kernel/lib/task/task.c index 7f4518f..7830302 100644 --- a/src/kernel/lib/task/task.c +++ b/src/kernel/lib/task/task.c @@ -62,4 +62,25 @@ Task* getCurrentTask() { return currentTask; +} + +void sendMessage(Task* task, Message* message) { + if (task->message == 0x00) { + task->message = message; + return; + } + Message* currentMessage = task->message; + while (currentMessage->next == 0x00) { + currentMessage = currentMessage->next; + } + currentMessage->next = message; +} + +Message* popMessage(Task* task) { + Message* currentMessage = task->message; + if (currentMessage != 0x00) { + task->message = currentMessage->next; + + } + return currentMessage; } \ No newline at end of file diff --git a/src/kernel/lib/task/task.h b/src/kernel/lib/task/task.h index f7bfd9e..0c5e1d0 100644 --- a/src/kernel/lib/task/task.h +++ b/src/kernel/lib/task/task.h @@ -2,6 +2,7 @@ #define TASK_H #include +#include extern void initTasking(); @@ -13,6 +14,7 @@ Registers registers; // the register states for the task struct Task *nextTask; // linked list of tasks that need to be done void* stack; + Message* message; } Task; extern void initTasking(); @@ -20,10 +22,13 @@ extern void yield(); extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); // swicht from the old to the new task +extern void switchTask(Registers *old, Registers *new); extern void schedule(Task* task); // schedule a task to be run in the future extern void destroyCurrentTask(); extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); #endif \ No newline at end of file diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 749aace..c83e0b0 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -10,13 +10,20 @@ void kernelMain() { drawLogo(); - initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work ): otherwise, _kernel_end should be passed here + initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work :( otherwise, _kernel_end should be passed here initOSTasks(); printf("Switching to otherTask... \n"); yields(); printf("Returned to mainTask!\n\n"); - for (int i = 0; i < 20; i++) { - printf("%x\n", i); - } + // for (int i = 0; i < 20; i++) { + // printf("%x\n", i); + // } + char* data = "Hello World from the new system!\n"; + Message message; + message.data = data; + message.size = strlen(data); + message.next = 0x00; + sendMessage(getPrinterTask(), &message); + schedule(getPrinterTask()); yield(); } \ No newline at end of file diff --git a/src/kernel/lib/task/osTasks.c b/src/kernel/lib/task/osTasks.c index 74d70f6..f053d31 100644 --- a/src/kernel/lib/task/osTasks.c +++ b/src/kernel/lib/task/osTasks.c @@ -2,19 +2,31 @@ #include #include #include +#include Task mainTask; -Task testTask; +Task printerTask; -void testMain() { - printf("Hello from another task!\n"); - yields(); - printf("wait. . . Hello again\n"); - destroyCurrentTask(); +void printLoop() { + while (1) { + yield(); + Message* message = popMessage(&printerTask); + if (message == 0x00) { + continue; + } + printf("PRINT\n"); + putChars(message->data, message->size); + free(message->data); + free(message); + } } void initOSTasks() { setRunningTask(&mainTask); - createTask(&testTask, (uint32_t) testMain, 0x0, 0x0); - schedule(&testTask); + createTask(&printerTask, (uint32_t) printLoop, 0x0, 0x0); + schedule(&printerTask); +} + +inline Task* getPrinterTask() { + return &printerTask; } \ No newline at end of file diff --git a/src/kernel/lib/task/osTasks.h b/src/kernel/lib/task/osTasks.h index 880cedb..b1adecb 100644 --- a/src/kernel/lib/task/osTasks.h +++ b/src/kernel/lib/task/osTasks.h @@ -3,7 +3,8 @@ #include -extern void testMain(); extern void initOSTasks(); +extern Task* getPrinterTask(); + #endif \ No newline at end of file diff --git a/src/kernel/lib/task/task.c b/src/kernel/lib/task/task.c index 7f4518f..7830302 100644 --- a/src/kernel/lib/task/task.c +++ b/src/kernel/lib/task/task.c @@ -62,4 +62,25 @@ Task* getCurrentTask() { return currentTask; +} + +void sendMessage(Task* task, Message* message) { + if (task->message == 0x00) { + task->message = message; + return; + } + Message* currentMessage = task->message; + while (currentMessage->next == 0x00) { + currentMessage = currentMessage->next; + } + currentMessage->next = message; +} + +Message* popMessage(Task* task) { + Message* currentMessage = task->message; + if (currentMessage != 0x00) { + task->message = currentMessage->next; + + } + return currentMessage; } \ No newline at end of file diff --git a/src/kernel/lib/task/task.h b/src/kernel/lib/task/task.h index f7bfd9e..0c5e1d0 100644 --- a/src/kernel/lib/task/task.h +++ b/src/kernel/lib/task/task.h @@ -2,6 +2,7 @@ #define TASK_H #include +#include extern void initTasking(); @@ -13,6 +14,7 @@ Registers registers; // the register states for the task struct Task *nextTask; // linked list of tasks that need to be done void* stack; + Message* message; } Task; extern void initTasking(); @@ -20,10 +22,13 @@ extern void yield(); extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); // swicht from the old to the new task +extern void switchTask(Registers *old, Registers *new); extern void schedule(Task* task); // schedule a task to be run in the future extern void destroyCurrentTask(); extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); #endif \ No newline at end of file diff --git a/src/kernel/lib/textMode/stdio.c b/src/kernel/lib/textMode/stdio.c index fbddfd0..c6ebd37 100644 --- a/src/kernel/lib/textMode/stdio.c +++ b/src/kernel/lib/textMode/stdio.c @@ -129,4 +129,18 @@ void setTextStyle(uint8_t style) { format = style; +} + +void putChars(char* string, uint32_t length) { + for (uint32_t i = 0; i < length; i++) { + putChar(string[i]); + } +} + +uint32_t strlen(char* string) { + uint32_t length = 0; + while (string[length] != 0) { + length++; + } + return length; } \ No newline at end of file diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 749aace..c83e0b0 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -10,13 +10,20 @@ void kernelMain() { drawLogo(); - initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work ): otherwise, _kernel_end should be passed here + initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work :( otherwise, _kernel_end should be passed here initOSTasks(); printf("Switching to otherTask... \n"); yields(); printf("Returned to mainTask!\n\n"); - for (int i = 0; i < 20; i++) { - printf("%x\n", i); - } + // for (int i = 0; i < 20; i++) { + // printf("%x\n", i); + // } + char* data = "Hello World from the new system!\n"; + Message message; + message.data = data; + message.size = strlen(data); + message.next = 0x00; + sendMessage(getPrinterTask(), &message); + schedule(getPrinterTask()); yield(); } \ No newline at end of file diff --git a/src/kernel/lib/task/osTasks.c b/src/kernel/lib/task/osTasks.c index 74d70f6..f053d31 100644 --- a/src/kernel/lib/task/osTasks.c +++ b/src/kernel/lib/task/osTasks.c @@ -2,19 +2,31 @@ #include #include #include +#include Task mainTask; -Task testTask; +Task printerTask; -void testMain() { - printf("Hello from another task!\n"); - yields(); - printf("wait. . . Hello again\n"); - destroyCurrentTask(); +void printLoop() { + while (1) { + yield(); + Message* message = popMessage(&printerTask); + if (message == 0x00) { + continue; + } + printf("PRINT\n"); + putChars(message->data, message->size); + free(message->data); + free(message); + } } void initOSTasks() { setRunningTask(&mainTask); - createTask(&testTask, (uint32_t) testMain, 0x0, 0x0); - schedule(&testTask); + createTask(&printerTask, (uint32_t) printLoop, 0x0, 0x0); + schedule(&printerTask); +} + +inline Task* getPrinterTask() { + return &printerTask; } \ No newline at end of file diff --git a/src/kernel/lib/task/osTasks.h b/src/kernel/lib/task/osTasks.h index 880cedb..b1adecb 100644 --- a/src/kernel/lib/task/osTasks.h +++ b/src/kernel/lib/task/osTasks.h @@ -3,7 +3,8 @@ #include -extern void testMain(); extern void initOSTasks(); +extern Task* getPrinterTask(); + #endif \ No newline at end of file diff --git a/src/kernel/lib/task/task.c b/src/kernel/lib/task/task.c index 7f4518f..7830302 100644 --- a/src/kernel/lib/task/task.c +++ b/src/kernel/lib/task/task.c @@ -62,4 +62,25 @@ Task* getCurrentTask() { return currentTask; +} + +void sendMessage(Task* task, Message* message) { + if (task->message == 0x00) { + task->message = message; + return; + } + Message* currentMessage = task->message; + while (currentMessage->next == 0x00) { + currentMessage = currentMessage->next; + } + currentMessage->next = message; +} + +Message* popMessage(Task* task) { + Message* currentMessage = task->message; + if (currentMessage != 0x00) { + task->message = currentMessage->next; + + } + return currentMessage; } \ No newline at end of file diff --git a/src/kernel/lib/task/task.h b/src/kernel/lib/task/task.h index f7bfd9e..0c5e1d0 100644 --- a/src/kernel/lib/task/task.h +++ b/src/kernel/lib/task/task.h @@ -2,6 +2,7 @@ #define TASK_H #include +#include extern void initTasking(); @@ -13,6 +14,7 @@ Registers registers; // the register states for the task struct Task *nextTask; // linked list of tasks that need to be done void* stack; + Message* message; } Task; extern void initTasking(); @@ -20,10 +22,13 @@ extern void yield(); extern void yields(); // yield, but schedule the currently running task -extern void switchTask(Registers *old, Registers *new); // swicht from the old to the new task +extern void switchTask(Registers *old, Registers *new); extern void schedule(Task* task); // schedule a task to be run in the future extern void destroyCurrentTask(); extern void setRunningTask(Task* task); // set the task currently executed +extern void sendMessage(Task* task, Message* message); + +extern Message* popMessage(Task* task); #endif \ No newline at end of file diff --git a/src/kernel/lib/textMode/stdio.c b/src/kernel/lib/textMode/stdio.c index fbddfd0..c6ebd37 100644 --- a/src/kernel/lib/textMode/stdio.c +++ b/src/kernel/lib/textMode/stdio.c @@ -129,4 +129,18 @@ void setTextStyle(uint8_t style) { format = style; +} + +void putChars(char* string, uint32_t length) { + for (uint32_t i = 0; i < length; i++) { + putChar(string[i]); + } +} + +uint32_t strlen(char* string) { + uint32_t length = 0; + while (string[length] != 0) { + length++; + } + return length; } \ No newline at end of file diff --git a/src/kernel/lib/textMode/stdio.h b/src/kernel/lib/textMode/stdio.h index e9fd30a..b5d4f87 100644 --- a/src/kernel/lib/textMode/stdio.h +++ b/src/kernel/lib/textMode/stdio.h @@ -13,5 +13,8 @@ extern void putCharAt(char c, uint8_t x, uint8_t y); extern void putCharsAt(char* string, uint8_t x, uint8_t y); extern void puts(char* string); +extern void putChars(char* string, uint32_t length); + +extern uint32_t strlen(char* string); #endif \ No newline at end of file