diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index c83e0b0..cfdf333 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -9,21 +9,11 @@ extern uint32_t _kernel_end; void kernelMain() { - drawLogo(); initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work :( otherwise, _kernel_end should be passed here initOSTasks(); + drawLogo(); printf("Switching to otherTask... \n"); yields(); printf("Returned to mainTask!\n\n"); - // 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 c83e0b0..cfdf333 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -9,21 +9,11 @@ extern uint32_t _kernel_end; void kernelMain() { - drawLogo(); initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work :( otherwise, _kernel_end should be passed here initOSTasks(); + drawLogo(); printf("Switching to otherTask... \n"); yields(); printf("Returned to mainTask!\n\n"); - // 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/message.h b/src/kernel/lib/task/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/kernel/lib/task/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index c83e0b0..cfdf333 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -9,21 +9,11 @@ extern uint32_t _kernel_end; void kernelMain() { - drawLogo(); initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work :( otherwise, _kernel_end should be passed here initOSTasks(); + drawLogo(); printf("Switching to otherTask... \n"); yields(); printf("Returned to mainTask!\n\n"); - // 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/message.h b/src/kernel/lib/task/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/kernel/lib/task/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/kernel/lib/task/osTasks.c b/src/kernel/lib/task/osTasks.c index f053d31..439a26d 100644 --- a/src/kernel/lib/task/osTasks.c +++ b/src/kernel/lib/task/osTasks.c @@ -14,7 +14,6 @@ if (message == 0x00) { continue; } - printf("PRINT\n"); putChars(message->data, message->size); free(message->data); free(message); @@ -25,6 +24,8 @@ setRunningTask(&mainTask); createTask(&printerTask, (uint32_t) printLoop, 0x0, 0x0); schedule(&printerTask); + // more tasks . . . + yields(); } inline Task* getPrinterTask() { diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index c83e0b0..cfdf333 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -9,21 +9,11 @@ extern uint32_t _kernel_end; void kernelMain() { - drawLogo(); initMemoryAllocation(0x100000); // initializing stacks after the kernel seems not to work :( otherwise, _kernel_end should be passed here initOSTasks(); + drawLogo(); printf("Switching to otherTask... \n"); yields(); printf("Returned to mainTask!\n\n"); - // 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/message.h b/src/kernel/lib/task/message.h new file mode 100644 index 0000000..2f8ddbe --- /dev/null +++ b/src/kernel/lib/task/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include + +typedef struct Message { + void* data; + uint32_t size; + struct Message* next; +} Message; + +#endif \ No newline at end of file diff --git a/src/kernel/lib/task/osTasks.c b/src/kernel/lib/task/osTasks.c index f053d31..439a26d 100644 --- a/src/kernel/lib/task/osTasks.c +++ b/src/kernel/lib/task/osTasks.c @@ -14,7 +14,6 @@ if (message == 0x00) { continue; } - printf("PRINT\n"); putChars(message->data, message->size); free(message->data); free(message); @@ -25,6 +24,8 @@ setRunningTask(&mainTask); createTask(&printerTask, (uint32_t) printLoop, 0x0, 0x0); schedule(&printerTask); + // more tasks . . . + yields(); } inline Task* getPrinterTask() { diff --git a/src/kernel/lib/textMode/stdio.c b/src/kernel/lib/textMode/stdio.c index c6ebd37..5784835 100644 --- a/src/kernel/lib/textMode/stdio.c +++ b/src/kernel/lib/textMode/stdio.c @@ -3,6 +3,10 @@ #include #include #include +#include +#include +#include +#include uint16_t* framebuffer = (uint16_t*) FRAMEBUFFER_LOCATION; char format = 0x0F; @@ -77,45 +81,87 @@ char HEX_PREFIX[] = "0x"; char HEX_CHARS[] = "0123456789ABCDEF"; -void putHex(uint32_t x) { +void putHex(char** write, uint32_t x) { uint8_t alreadyWriting = 0; - puts(HEX_PREFIX); - for (int8_t i = 7; i >= 0; i--) { - uint8_t nibble = (x >> (i << 2)) & 0x0F; - if (! alreadyWriting && nibble != 0x00) { + for (uint8_t position = 3; position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00) { alreadyWriting = 0x01; } - if (! alreadyWriting) { - continue; + if (alreadyWriting) { + **write = HEX_CHARS[byte % 256]; + *write++; + **write = HEX_CHARS[byte / 256]; + *write++; } - putChar(HEX_CHARS[nibble]); } } -void handleInsert(char insertType, uint32_t x) { +uint32_t getInsertLength(char insertType, uint32_t x) { + switch (insertType) + { + case 's': + return strlen((char*) x); + case 'x': + for (uint8_t position = 3; position >= 0; position--) { + uint8_t byte = (x >> (position * 8)) & 0xFF; + if (byte != 0x00) { + return 2*position; + } + } + return 0; + } + return 0; +} + +void handleInsert(char** write, char insertType, uint32_t x) { if (insertType == 's') { - puts((char*) x); + char* string = (char*) x; + uint32_t length = strlen(string); + for (uint32_t position = 0; position < length; position++) { + **write = string[position]; + *write++; + } + return; } if (insertType == 'x') { - putHex(x); + putHex(write, x); } } void printf(const char* format, ...) { + uint32_t size = 0; va_list valist; va_start(valist, format); for (int i = 0; format[i] != 0; i++) { - if (format[i] == '\n') { - newLine(); - continue; - } if (format[i] == '%') { - handleInsert(format[++i], va_arg(valist, int)); + size += getInsertLength(format[++i], va_arg(valist, uint32_t)); continue; } - putChar(format[i]); + size++; + } + va_start(valist, format); + + char* data = malloc(size); + char* write = data; + for (int i = 0; format[i] != 0; i++) { + if (format[i] == '%') { + handleInsert(&write, format[++i], va_arg(valist, uint32_t)); + continue; + } + *write = format[i]; + write++; } va_end(valist); + + Message message = { + message.data = data, + message.size = size, + message.next = 0x00 + }; + sendMessage(getPrinterTask(), &message); + schedule(getPrinterTask()); + yields(); } void clearScreen() { @@ -133,6 +179,10 @@ void putChars(char* string, uint32_t length) { for (uint32_t i = 0; i < length; i++) { + if (string[i] == '\n') { + newLine(); + continue; + } putChar(string[i]); } }