Skip to content

Commit 1c43c83

Browse files
author
Louis Jenkins
committed
I finally have multitasking working correcty, and even basic scrolling.
As well, I have a new dynamic array implementation to replace the horrible linked list one, and it works! Very good progress, I'd say.
1 parent 1f2c45a commit 1c43c83

File tree

11 files changed

+341
-325
lines changed

11 files changed

+341
-325
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,26 @@ The below depicts an early "schedule" or rather a path I will be taking in terms
1414
- [x] Keyboard Driver
1515
- [x] Memory Management (Physical + Virtual)
1616
- [x] Higher Half Kernel
17+
- [x] Multitasking and Scheduling
1718
- [ ] File System
1819
- [ ] Process Creation and Managements
19-
- [ ] Multitasking and Scheduling
2020
- [ ] Networking
2121
- [ ] ELF Binary Support
2222
- [ ] Interactive Shell
2323
- [ ] Graphical User Interfaces
2424

2525
#Progress Update & Changelog
2626

27+
## Version .002a
28+
29+
It took me a while, but finally, I've got it! Multitasking! Currently, the CPU may as well be a uniprocessor, but I do implement task switching that allows me to have a VERY simple and __minimal__ multitasking kernel! They are still only threads because they do not have their own page directory (and hence share the same virtual address space). This meant that to create these tasks I had to copy the 'parent' stack for the 'child', and do a ton of trickery to get it working.
30+
31+
As well, the time sharing has no current way to 'yield' to the 'scheduler' either, as I use the software context switching method (meaning, I only task switch from an interrupt handler).
32+
33+
Good news is that I have fixed the Real-Time Clock, and I have it update in the top right corner, and as well as have the last pressed key right below it. I've also taken the time to implement scrolling! Now it buffers each line of the VGA buffer so that scrolling up and down will save and restore them appropriately!
34+
35+
![Screenshot](/multitasking.JPG)
36+
2737
## Version .002
2838

2939
It is FINALLY here! I have implemented not only memory management (paging and a heap allocator), but even converted to a higher-half kernel approach, which was also easier, surprisingly, than a normal identity-mapped system. I've also fixed up the tests and their output format to better portray the significance of the initialization of the kernel thus far. I am very satisfied with what I have done, but unfortunately, I have to attend to another project for the time being.

multitasking.JPG

55.5 KB
Loading

src/kernel/drivers/kbd.c

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ static const char *to_string(uint8_t code) {
212212
str = "NUMLOCK";
213213
break;
214214
case KBD_KP_KEY_ASTERISK:
215-
str = "(keypad) ASTERISK";
215+
str = "(KP) ASTERISK";
216216
break;
217217
case KBD_KP_KEY_MINUS:
218-
str = "(keypad) MINUS";
218+
str = "(KP) MINUS";
219219
break;
220220
case KBD_KEY_TAB:
221221
str = "TAB";
@@ -260,16 +260,16 @@ static const char *to_string(uint8_t code) {
260260
str = "BACK_SLASH";
261261
break;
262262
case KBD_KP_KEY_7:
263-
str = "(keypad) 7";
263+
str = "(KP) 7";
264264
break;
265265
case KBD_KP_KEY_8:
266-
str = "(keypad) 8";
266+
str = "(KP) 8";
267267
break;
268268
case KBD_KP_KEY_9:
269-
str = "(keypad) 9";
269+
str = "(KP) 9";
270270
break;
271271
case KBD_KP_KEY_PLUS:
272-
str = "(keypad) PLUS";
272+
str = "(KP) PLUS";
273273
break;
274274
case KBD_KEY_CAPS_LOCK:
275275
str = "CAPS_LOCK";
@@ -311,13 +311,13 @@ static const char *to_string(uint8_t code) {
311311
str = "ENTER";
312312
break;
313313
case KBD_KP_KEY_4:
314-
str = "(keypad) 4";
314+
str = "(KP) 4";
315315
break;
316316
case KBD_KP_KEY_5:
317-
str = "(keypad) 5";
317+
str = "(KP) 5";
318318
break;
319319
case KBD_KP_KEY_6:
320-
str = "(keypad) 6";
320+
str = "(KP) 6";
321321
break;
322322
case KBD_KEY_LSHIFT:
323323
str = "LSHIFT";
@@ -356,13 +356,13 @@ static const char *to_string(uint8_t code) {
356356
str = "RSHIFT";
357357
break;
358358
case KBD_KP_KEY_1:
359-
str = "(keypad) 1";
359+
str = "(KP) 1";
360360
break;
361361
case KBD_KP_KEY_2:
362-
str = "(keypad) 2";
362+
str = "(KP) 2";
363363
break;
364364
case KBD_KP_KEY_3:
365-
str = "(keypad) 3";
365+
str = "(KP) 3";
366366
break;
367367
case KBD_KEY_LCTRL:
368368
str = "LCTRL";
@@ -383,10 +383,10 @@ static const char *to_string(uint8_t code) {
383383
str = "SUPER";
384384
break;
385385
case KBD_KP_KEY_0:
386-
str = "(keypad) 0";
386+
str = "(KP) 0";
387387
break;
388388
case KBD_KP_KEY_PERIOD:
389-
str = "(keypad) PERIOD";
389+
str = "(KP) PERIOD";
390390
break;
391391
default:
392392
str = "(NULL)";
@@ -401,13 +401,13 @@ static const char *escaped_to_string(uint8_t code) {
401401
const char *str;
402402
switch (code) {
403403
case KBD_KP_KEY_ENTER:
404-
str = "(keypad) ENTER";
404+
str = "(KP) ENTER";
405405
break;
406406
case KBD_KEY_RCTRL:
407407
str = "RCTRL";
408408
break;
409409
case KBD_KP_KEY_SLASH:
410-
str = "(keypad) SLASH";
410+
str = "(KP) SLASH";
411411
break;
412412
case KBD_KEY_RALT:
413413
str = "RALT";
@@ -465,13 +465,20 @@ static void keyboard_irq_handler(struct registers *UNUSED(regs)) {
465465
// State-Based machine, which determines which scan table to decode from.
466466
switch (state) {
467467
// Waiting for first byte
468-
case 0:
469-
// On each key press, we write prettily to the same line.
470-
vga_clear_line();
471-
vga_set_x(0);
472-
printf("Scancode: %x, You %s: ", scancode, released ? "Released" : "Pressed");
473-
printf("%s", to_string(KBD_SCAN_TABLE[scancode]));
468+
case 0: {
469+
char *str = to_string(KBD_SCAN_TABLE[scancode]);
470+
uint32_t x = vga_get_x();
471+
uint32_t y = vga_get_y();
472+
vga_set_x(65);
473+
vga_set_y(1);
474+
for (int i = 0; i < 15 - strlen(str); i++) {
475+
vga_putc(' ');
476+
}
477+
printf("%s", str);
478+
vga_set_x(x);
479+
vga_set_y(y);
474480
return;
481+
}
475482
// Waiting for second byte of multibyte sequence
476483
case 1:
477484
switch (KBD_ESCAPED_SCAN_TABLE[scancode]) {
@@ -481,12 +488,19 @@ static void keyboard_irq_handler(struct registers *UNUSED(regs)) {
481488
case KBD_KEY_UP:
482489
vga_scroll_up();
483490
break;
484-
default:
485-
// On each key press, we write prettily to the same line.
486-
vga_clear_line();
487-
vga_set_x(0);
488-
printf("Scancode: %x, You %s: ", scancode, released ? "Released" : "Pressed");
489-
printf("%s", escaped_to_string(KBD_ESCAPED_SCAN_TABLE[scancode]));
491+
default: {
492+
char *str = escaped_to_string(KBD_ESCAPED_SCAN_TABLE[scancode]);
493+
uint32_t x = vga_get_x();
494+
uint32_t y = vga_get_y();
495+
vga_set_x(65);
496+
vga_set_y(1);
497+
for (int i = 0; i < 15 - strlen(str); i++) {
498+
vga_putc(' ');
499+
}
500+
printf("%s", str);
501+
vga_set_x(x);
502+
vga_set_y(y);
503+
}
490504
}
491505
state = 0;
492506
}

0 commit comments

Comments
 (0)