diff --git a/iso/boot/grub/menu.lst b/iso/boot/grub/menu.lst deleted file mode 100644 index 9c7846e..0000000 --- a/iso/boot/grub/menu.lst +++ /dev/null @@ -1,5 +0,0 @@ -default=0 -timeout=0 - -title tree-os -kernel /boot/tree-os.elf \ No newline at end of file diff --git a/iso/boot/grub/menu.lst b/iso/boot/grub/menu.lst deleted file mode 100644 index 9c7846e..0000000 --- a/iso/boot/grub/menu.lst +++ /dev/null @@ -1,5 +0,0 @@ -default=0 -timeout=0 - -title tree-os -kernel /boot/tree-os.elf \ No newline at end of file diff --git a/iso/boot/grub/stage2_eltorito b/iso/boot/grub/stage2_eltorito deleted file mode 100644 index 9e1617c..0000000 --- a/iso/boot/grub/stage2_eltorito +++ /dev/null Binary files differ diff --git a/iso/boot/grub/menu.lst b/iso/boot/grub/menu.lst deleted file mode 100644 index 9c7846e..0000000 --- a/iso/boot/grub/menu.lst +++ /dev/null @@ -1,5 +0,0 @@ -default=0 -timeout=0 - -title tree-os -kernel /boot/tree-os.elf \ No newline at end of file diff --git a/iso/boot/grub/stage2_eltorito b/iso/boot/grub/stage2_eltorito deleted file mode 100644 index 9e1617c..0000000 --- a/iso/boot/grub/stage2_eltorito +++ /dev/null Binary files differ diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 44453e8..749aace 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -8,30 +8,15 @@ extern uint32_t _kernel_end; -void memoryTest() { - void* one = malloc(0x100); - printf("alloc one: %x\n", one); - void* two = malloc(0x100); - printf("alloc two: %x\n", two); - mfree(one); - printf("free one\n"); - void* three = malloc(1); - printf("alloc three: %x\n", three); - mfree(two); - printf("free two\n"); - printMemoryStack(); - void* four = malloc(0x180); - printf("alloc four: %x\n", four); - printMemoryStack(); -} - void kernelMain() { drawLogo(); - initMemoryAllocation(0x100000); // initializing stacks after the kernel seems to not work :( otherwise, _kernel_end should be passed here - memoryTest(); + 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"); + printf("Returned to mainTask!\n\n"); + for (int i = 0; i < 20; i++) { + printf("%x\n", i); + } yield(); } \ No newline at end of file diff --git a/iso/boot/grub/menu.lst b/iso/boot/grub/menu.lst deleted file mode 100644 index 9c7846e..0000000 --- a/iso/boot/grub/menu.lst +++ /dev/null @@ -1,5 +0,0 @@ -default=0 -timeout=0 - -title tree-os -kernel /boot/tree-os.elf \ No newline at end of file diff --git a/iso/boot/grub/stage2_eltorito b/iso/boot/grub/stage2_eltorito deleted file mode 100644 index 9e1617c..0000000 --- a/iso/boot/grub/stage2_eltorito +++ /dev/null Binary files differ diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 44453e8..749aace 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -8,30 +8,15 @@ extern uint32_t _kernel_end; -void memoryTest() { - void* one = malloc(0x100); - printf("alloc one: %x\n", one); - void* two = malloc(0x100); - printf("alloc two: %x\n", two); - mfree(one); - printf("free one\n"); - void* three = malloc(1); - printf("alloc three: %x\n", three); - mfree(two); - printf("free two\n"); - printMemoryStack(); - void* four = malloc(0x180); - printf("alloc four: %x\n", four); - printMemoryStack(); -} - void kernelMain() { drawLogo(); - initMemoryAllocation(0x100000); // initializing stacks after the kernel seems to not work :( otherwise, _kernel_end should be passed here - memoryTest(); + 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"); + printf("Returned to mainTask!\n\n"); + for (int i = 0; i < 20; i++) { + printf("%x\n", i); + } yield(); } \ No newline at end of file diff --git a/src/kernel/lib/task/task.c b/src/kernel/lib/task/task.c index 21eef66..b112c2b 100644 --- a/src/kernel/lib/task/task.c +++ b/src/kernel/lib/task/task.c @@ -14,7 +14,7 @@ task->registers.eflags = flags; task->registers.eip = mainFunction; task->registers.cr3 = (uint32_t) pagedir; - task->registers.esp = 0xF000 + (uint32_t) malloc(0xF000); + task->registers.esp = 0xF000 + (uint32_t) malloc(0x1000); task->nextTask = 0; } @@ -23,7 +23,9 @@ runningTask = runningTask->nextTask; if (runningTask == 0x00) { printf("No more tasks to run, halting . . .\n"); - asm("hlt"); + while (1) { + asm("hlt"); + } } last->nextTask = 0x00; switchTask(&(last->registers), &(runningTask->registers)); @@ -33,6 +35,9 @@ Task* test = runningTask; while (test->nextTask != 0x0) { test = test->nextTask; + if (test->nextTask == task) { + return; // don't schedule if the task is already in the queue + } } test->nextTask = task; } diff --git a/iso/boot/grub/menu.lst b/iso/boot/grub/menu.lst deleted file mode 100644 index 9c7846e..0000000 --- a/iso/boot/grub/menu.lst +++ /dev/null @@ -1,5 +0,0 @@ -default=0 -timeout=0 - -title tree-os -kernel /boot/tree-os.elf \ No newline at end of file diff --git a/iso/boot/grub/stage2_eltorito b/iso/boot/grub/stage2_eltorito deleted file mode 100644 index 9e1617c..0000000 --- a/iso/boot/grub/stage2_eltorito +++ /dev/null Binary files differ diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 44453e8..749aace 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -8,30 +8,15 @@ extern uint32_t _kernel_end; -void memoryTest() { - void* one = malloc(0x100); - printf("alloc one: %x\n", one); - void* two = malloc(0x100); - printf("alloc two: %x\n", two); - mfree(one); - printf("free one\n"); - void* three = malloc(1); - printf("alloc three: %x\n", three); - mfree(two); - printf("free two\n"); - printMemoryStack(); - void* four = malloc(0x180); - printf("alloc four: %x\n", four); - printMemoryStack(); -} - void kernelMain() { drawLogo(); - initMemoryAllocation(0x100000); // initializing stacks after the kernel seems to not work :( otherwise, _kernel_end should be passed here - memoryTest(); + 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"); + printf("Returned to mainTask!\n\n"); + for (int i = 0; i < 20; i++) { + printf("%x\n", i); + } yield(); } \ No newline at end of file diff --git a/src/kernel/lib/task/task.c b/src/kernel/lib/task/task.c index 21eef66..b112c2b 100644 --- a/src/kernel/lib/task/task.c +++ b/src/kernel/lib/task/task.c @@ -14,7 +14,7 @@ task->registers.eflags = flags; task->registers.eip = mainFunction; task->registers.cr3 = (uint32_t) pagedir; - task->registers.esp = 0xF000 + (uint32_t) malloc(0xF000); + task->registers.esp = 0xF000 + (uint32_t) malloc(0x1000); task->nextTask = 0; } @@ -23,7 +23,9 @@ runningTask = runningTask->nextTask; if (runningTask == 0x00) { printf("No more tasks to run, halting . . .\n"); - asm("hlt"); + while (1) { + asm("hlt"); + } } last->nextTask = 0x00; switchTask(&(last->registers), &(runningTask->registers)); @@ -33,6 +35,9 @@ Task* test = runningTask; while (test->nextTask != 0x0) { test = test->nextTask; + if (test->nextTask == task) { + return; // don't schedule if the task is already in the queue + } } test->nextTask = task; } diff --git a/src/kernel/lib/task/task.h b/src/kernel/lib/task/task.h index 6a617cd..50c4de2 100644 --- a/src/kernel/lib/task/task.h +++ b/src/kernel/lib/task/task.h @@ -10,7 +10,7 @@ } Registers; typedef struct Task { - Registers registers; + Registers registers; // the register states for the task struct Task *nextTask; // linked list of tasks that need to be done } Task; @@ -18,10 +18,10 @@ extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); extern void yield(); -extern void yields(); // yield, but first schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); +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 schedule(Task* task); // schedule a task to be run in the future -extern void setRunningTask(Task* task); +extern void setRunningTask(Task* task); // set the task currently executed #endif \ No newline at end of file diff --git a/iso/boot/grub/menu.lst b/iso/boot/grub/menu.lst deleted file mode 100644 index 9c7846e..0000000 --- a/iso/boot/grub/menu.lst +++ /dev/null @@ -1,5 +0,0 @@ -default=0 -timeout=0 - -title tree-os -kernel /boot/tree-os.elf \ No newline at end of file diff --git a/iso/boot/grub/stage2_eltorito b/iso/boot/grub/stage2_eltorito deleted file mode 100644 index 9e1617c..0000000 --- a/iso/boot/grub/stage2_eltorito +++ /dev/null Binary files differ diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 44453e8..749aace 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -8,30 +8,15 @@ extern uint32_t _kernel_end; -void memoryTest() { - void* one = malloc(0x100); - printf("alloc one: %x\n", one); - void* two = malloc(0x100); - printf("alloc two: %x\n", two); - mfree(one); - printf("free one\n"); - void* three = malloc(1); - printf("alloc three: %x\n", three); - mfree(two); - printf("free two\n"); - printMemoryStack(); - void* four = malloc(0x180); - printf("alloc four: %x\n", four); - printMemoryStack(); -} - void kernelMain() { drawLogo(); - initMemoryAllocation(0x100000); // initializing stacks after the kernel seems to not work :( otherwise, _kernel_end should be passed here - memoryTest(); + 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"); + printf("Returned to mainTask!\n\n"); + for (int i = 0; i < 20; i++) { + printf("%x\n", i); + } yield(); } \ No newline at end of file diff --git a/src/kernel/lib/task/task.c b/src/kernel/lib/task/task.c index 21eef66..b112c2b 100644 --- a/src/kernel/lib/task/task.c +++ b/src/kernel/lib/task/task.c @@ -14,7 +14,7 @@ task->registers.eflags = flags; task->registers.eip = mainFunction; task->registers.cr3 = (uint32_t) pagedir; - task->registers.esp = 0xF000 + (uint32_t) malloc(0xF000); + task->registers.esp = 0xF000 + (uint32_t) malloc(0x1000); task->nextTask = 0; } @@ -23,7 +23,9 @@ runningTask = runningTask->nextTask; if (runningTask == 0x00) { printf("No more tasks to run, halting . . .\n"); - asm("hlt"); + while (1) { + asm("hlt"); + } } last->nextTask = 0x00; switchTask(&(last->registers), &(runningTask->registers)); @@ -33,6 +35,9 @@ Task* test = runningTask; while (test->nextTask != 0x0) { test = test->nextTask; + if (test->nextTask == task) { + return; // don't schedule if the task is already in the queue + } } test->nextTask = task; } diff --git a/src/kernel/lib/task/task.h b/src/kernel/lib/task/task.h index 6a617cd..50c4de2 100644 --- a/src/kernel/lib/task/task.h +++ b/src/kernel/lib/task/task.h @@ -10,7 +10,7 @@ } Registers; typedef struct Task { - Registers registers; + Registers registers; // the register states for the task struct Task *nextTask; // linked list of tasks that need to be done } Task; @@ -18,10 +18,10 @@ extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); extern void yield(); -extern void yields(); // yield, but first schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); +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 schedule(Task* task); // schedule a task to be run in the future -extern void setRunningTask(Task* task); +extern void setRunningTask(Task* task); // set the task currently executed #endif \ No newline at end of file diff --git a/src/kernel/lib/textMode/stdio.c b/src/kernel/lib/textMode/stdio.c index 41ad6f4..9a6de47 100644 --- a/src/kernel/lib/textMode/stdio.c +++ b/src/kernel/lib/textMode/stdio.c @@ -7,14 +7,26 @@ uint16_t* framebuffer = (uint16_t*) FRAMEBUFFER_LOCATION; char format = 0x0F; -void putCharAtOffset(char c, uint16_t position) { - *(framebuffer + position) = (c | format << 8); +void putCharWithFormatAtOffset(uint16_t c, uint16_t position) { + *(framebuffer + position) = c; +} + +void putCharWithFormatAt(uint8_t x, uint8_t y, uint32_t c) { + putCharWithFormatAtOffset(c, (x + y * VIDEO_WIDTH)); +} + +void putCharAtOffset(char c, uint16_t offset) { + putCharWithFormatAtOffset(c | format << 8, offset); } void putCharAt(char c, uint8_t x, uint8_t y) { putCharAtOffset(c, (x + y * VIDEO_WIDTH)); } +uint16_t getCharWithFormatAt(uint8_t x, uint8_t y) { + return *(framebuffer + x + y * VIDEO_WIDTH); +} + void putCharsAt(char* string, uint8_t x, uint8_t y) { uint16_t position = 0; char c = *string; @@ -38,14 +50,23 @@ } } +void shiftUp() { + for (int y = 1; y < VIDEO_HEIGHT; y++) { + for (int x = 0; x < VIDEO_WIDTH; x++) { + putCharWithFormatAt(x, y-1, getCharWithFormatAt(x, y)); + } + } +} + void newLine() { uint16_t offset = getCursorOffset(); uint8_t x = offset % VIDEO_WIDTH; uint8_t y = offset / VIDEO_WIDTH; x = 0; y++; - if (y > VIDEO_HEIGHT) { - // shiftUp(); : TODO + if (y >= VIDEO_HEIGHT) { + shiftUp(); + y--; } setCursorPosition(x, y); } diff --git a/iso/boot/grub/menu.lst b/iso/boot/grub/menu.lst deleted file mode 100644 index 9c7846e..0000000 --- a/iso/boot/grub/menu.lst +++ /dev/null @@ -1,5 +0,0 @@ -default=0 -timeout=0 - -title tree-os -kernel /boot/tree-os.elf \ No newline at end of file diff --git a/iso/boot/grub/stage2_eltorito b/iso/boot/grub/stage2_eltorito deleted file mode 100644 index 9e1617c..0000000 --- a/iso/boot/grub/stage2_eltorito +++ /dev/null Binary files differ diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 44453e8..749aace 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -8,30 +8,15 @@ extern uint32_t _kernel_end; -void memoryTest() { - void* one = malloc(0x100); - printf("alloc one: %x\n", one); - void* two = malloc(0x100); - printf("alloc two: %x\n", two); - mfree(one); - printf("free one\n"); - void* three = malloc(1); - printf("alloc three: %x\n", three); - mfree(two); - printf("free two\n"); - printMemoryStack(); - void* four = malloc(0x180); - printf("alloc four: %x\n", four); - printMemoryStack(); -} - void kernelMain() { drawLogo(); - initMemoryAllocation(0x100000); // initializing stacks after the kernel seems to not work :( otherwise, _kernel_end should be passed here - memoryTest(); + 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"); + printf("Returned to mainTask!\n\n"); + for (int i = 0; i < 20; i++) { + printf("%x\n", i); + } yield(); } \ No newline at end of file diff --git a/src/kernel/lib/task/task.c b/src/kernel/lib/task/task.c index 21eef66..b112c2b 100644 --- a/src/kernel/lib/task/task.c +++ b/src/kernel/lib/task/task.c @@ -14,7 +14,7 @@ task->registers.eflags = flags; task->registers.eip = mainFunction; task->registers.cr3 = (uint32_t) pagedir; - task->registers.esp = 0xF000 + (uint32_t) malloc(0xF000); + task->registers.esp = 0xF000 + (uint32_t) malloc(0x1000); task->nextTask = 0; } @@ -23,7 +23,9 @@ runningTask = runningTask->nextTask; if (runningTask == 0x00) { printf("No more tasks to run, halting . . .\n"); - asm("hlt"); + while (1) { + asm("hlt"); + } } last->nextTask = 0x00; switchTask(&(last->registers), &(runningTask->registers)); @@ -33,6 +35,9 @@ Task* test = runningTask; while (test->nextTask != 0x0) { test = test->nextTask; + if (test->nextTask == task) { + return; // don't schedule if the task is already in the queue + } } test->nextTask = task; } diff --git a/src/kernel/lib/task/task.h b/src/kernel/lib/task/task.h index 6a617cd..50c4de2 100644 --- a/src/kernel/lib/task/task.h +++ b/src/kernel/lib/task/task.h @@ -10,7 +10,7 @@ } Registers; typedef struct Task { - Registers registers; + Registers registers; // the register states for the task struct Task *nextTask; // linked list of tasks that need to be done } Task; @@ -18,10 +18,10 @@ extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir); extern void yield(); -extern void yields(); // yield, but first schedule the currently running task -extern void switchTask(Registers *old, Registers *new); -extern void schedule(Task* task); +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 schedule(Task* task); // schedule a task to be run in the future -extern void setRunningTask(Task* task); +extern void setRunningTask(Task* task); // set the task currently executed #endif \ No newline at end of file diff --git a/src/kernel/lib/textMode/stdio.c b/src/kernel/lib/textMode/stdio.c index 41ad6f4..9a6de47 100644 --- a/src/kernel/lib/textMode/stdio.c +++ b/src/kernel/lib/textMode/stdio.c @@ -7,14 +7,26 @@ uint16_t* framebuffer = (uint16_t*) FRAMEBUFFER_LOCATION; char format = 0x0F; -void putCharAtOffset(char c, uint16_t position) { - *(framebuffer + position) = (c | format << 8); +void putCharWithFormatAtOffset(uint16_t c, uint16_t position) { + *(framebuffer + position) = c; +} + +void putCharWithFormatAt(uint8_t x, uint8_t y, uint32_t c) { + putCharWithFormatAtOffset(c, (x + y * VIDEO_WIDTH)); +} + +void putCharAtOffset(char c, uint16_t offset) { + putCharWithFormatAtOffset(c | format << 8, offset); } void putCharAt(char c, uint8_t x, uint8_t y) { putCharAtOffset(c, (x + y * VIDEO_WIDTH)); } +uint16_t getCharWithFormatAt(uint8_t x, uint8_t y) { + return *(framebuffer + x + y * VIDEO_WIDTH); +} + void putCharsAt(char* string, uint8_t x, uint8_t y) { uint16_t position = 0; char c = *string; @@ -38,14 +50,23 @@ } } +void shiftUp() { + for (int y = 1; y < VIDEO_HEIGHT; y++) { + for (int x = 0; x < VIDEO_WIDTH; x++) { + putCharWithFormatAt(x, y-1, getCharWithFormatAt(x, y)); + } + } +} + void newLine() { uint16_t offset = getCursorOffset(); uint8_t x = offset % VIDEO_WIDTH; uint8_t y = offset / VIDEO_WIDTH; x = 0; y++; - if (y > VIDEO_HEIGHT) { - // shiftUp(); : TODO + if (y >= VIDEO_HEIGHT) { + shiftUp(); + y--; } setCursorPosition(x, y); } diff --git a/src/kernel/lib/textMode/stdio.h b/src/kernel/lib/textMode/stdio.h index cbfc8ad..e9fd30a 100644 --- a/src/kernel/lib/textMode/stdio.h +++ b/src/kernel/lib/textMode/stdio.h @@ -5,7 +5,7 @@ #define FRAMEBUFFER_LOCATION 0x000B8000 #define VIDEO_WIDTH 80 -#define VIDEO_HEIGHT 50 +#define VIDEO_HEIGHT 25 extern void setTextStyle(uint8_t style); extern void clearScreen();