diff --git a/README.md b/README.md index 0fa4573..14961a1 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,19 @@ # BlankOS -Rewritten monolithic version of Blank OS for the x86 processor architecture. Features a framebuffer, serial port driver, GDT, IDT. The OS relies on an old, legacy version of GRUB as the bootloader (eltorito). This *should* be GRUB 2 compatible. Emulation was tested on Arch Linux 6.9.7-arch1-1. The long-term goal of this OS is to be capable of running user programs and having its own complete kernel C library so that users can write their own C programs and expand the system! +Rewritten monolithic version of Blank OS for the x86 processor architecture. The OS relies on an old, legacy version of GRUB as the bootloader (eltorito). This *should* be GRUB 2 compatible. Emulation was tested on Bochs and QEMU using Arch Linux 6.9.7-arch1-1, and on real hardware too. +The long-term goal of this OS is to be capable of running user programs and having its own complete kernel C library so that users can write their own C programs and expand the system! -Next steps for this project will be: -- User programs -- Completing the kernel libc -- Filesystem support +## Features + +- Serial port driver (output & debug) +- Framebuffer driver (output) +- PS/2 Keyboard and PIC driver (input) +- PIT (system clock/timer) driver +- Working IDT, GDT, ISRs, and IRQs +- Kernel panicking (exception handling) +- A kernel-space shell +- Cool color output!! +- Some small working kernel-space programs!! ## Usage @@ -51,9 +59,26 @@ sudo dd bs=4M if=blankos.iso of=/dev/sdX status=progress oflag=sync Replace `sdX` with your USB drive name (you can find it by doing `sudo fdisk -l`). Tada! You now have a working BlankOS USB stick. Go ahead and try it out! -## Post-install guides +## Post-install -Two documents are available to help you understand the project better. One is the User's Manual, labelled `USERS.md`, and the other one is the Developer's Manual, labelled `DEVELOPERS.md`. They are full of useful resources around Blank OS. +Two documents are available to help you understand the project better. One is the User's Manual, labelled `USERS.md`, and the other one is the Developer's Manual, labelled `DEVELOPERS.md`. They are full of useful resources around Blank OS. You'll learn how to use the system and how to contribute to it. + +### Next Steps? + +Next steps for this project will be: + +- User programs +- Completing the kernel libc +- Filesystem support + +### Resources + +- the [OSDev.org](https://wiki.osdev.org/Expanded_Main_Page) wiki and forums +- the [Nanobyte](https://www.youtube.com/watch?v=9t-SPC7Tczc&list=PLFjM7v6KGMpiH2G-kT781ByCNC_0pKpPN) YouTube channel +- the [Daedalus Community](https://www.youtube.com/@DaedalusCommunity) YouTube channel +- a great book named *Operating Systems: From 0 to 1*, by Tu, Do Hoang +- the Intel [64 and IA-32 Architectures Software Developer Manuals](https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html) +- [Bran's Kernel Development Tutorial](http://www.osdever.net/bkerndev/index.php) ### ⚠️ Disclaimer diff --git a/USERS.md b/USERS.md index bf15b39..45e19df 100644 --- a/USERS.md +++ b/USERS.md @@ -12,6 +12,41 @@ Once you have launched the OS for the first time, you should first see the welco To get the list of available commands on the system, type `help`. -## Next what? +### Commands -Once programs will be added, there will be more info here. For now you can just play around and make the kernel panic. That's it. +#### `help` + +Shows all of the available commands, which are explained here. + +#### `panic` + +Triggers a kernel panic by trying to divide four by zero. + +#### `words` + +Prints ten random words using an arbitrary dictionary that you can expand in `src/programs/words.c`. + +#### `primes` + +Computes prime numbers up to `PRIMES_MAX`, defined in `src/programs/primes.c`. + +#### `rainbow` + +Asks for text and then outputs it with different vibrant colors. + +#### `clear` + +Clears the screen by scrolling (screen height) times. + +#### `math` + +**This program is not working!** +The lexer and parser should be okay, but I can't figure out the `%f` floating point format specifier in the freestanding printf implementation; it triggers weird exceptions that I don't understand. So no math interpreter for now. + +#### `bf` + +A brainfuck interpreter with every instruction and default tape size (30k cells). + +#### `uptime` + +Gets system uptime from the timer in ticks. Ticks are incremented at a rate of 18.222Hz (18.222 ticks per second). diff --git a/iso/boot/kernel.elf b/iso/boot/kernel.elf index 7b70d9e..51c05f1 100755 Binary files a/iso/boot/kernel.elf and b/iso/boot/kernel.elf differ diff --git a/src/drivers/kb.h b/src/drivers/kb.h new file mode 100644 index 0000000..f50cab5 --- /dev/null +++ b/src/drivers/kb.h @@ -0,0 +1,6 @@ +#ifndef KB_H +#define KB_H + +char keyboard_getchar(); + +#endif diff --git a/src/drivers/timer.c b/src/drivers/timer.c index d10744f..29520c0 100644 --- a/src/drivers/timer.c +++ b/src/drivers/timer.c @@ -19,3 +19,8 @@ void delay(int ticks) eticks = global_ticks + ticks; while (global_ticks < eticks); } + +int uptime() +{ + return global_ticks; +} diff --git a/src/kernel/shell.c b/src/kernel/shell.c index 6e1872e..815fe5a 100644 --- a/src/kernel/shell.c +++ b/src/kernel/shell.c @@ -21,7 +21,7 @@ void shell_install() } else if (strcmp(input_buffer, "help") == 0) { - printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\n"); + printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\tuptime\n"); } else if (strcmp(input_buffer, "panic") == 0) { @@ -47,6 +47,14 @@ void shell_install() { program_math(); } + else if (strcmp(input_buffer, "bf") == 0) + { + program_bf(); + } + else if (strcmp(input_buffer, "uptime") == 0) + { + program_uptime(); + } else { printf("Unknown command %s\n", input_buffer); } diff --git a/src/kernel/system.h b/src/kernel/system.h index f551d0c..0ca520e 100644 --- a/src/kernel/system.h +++ b/src/kernel/system.h @@ -22,6 +22,7 @@ void delay(int ticks); void keyboard_install(); char keyboard_getchar(); void shell_install(); +int uptime(); extern volatile unsigned long global_ticks; diff --git a/src/programs/bf.c b/src/programs/bf.c new file mode 100644 index 0000000..33bcb03 --- /dev/null +++ b/src/programs/bf.c @@ -0,0 +1,55 @@ + +#include "../kernel/system.h" +#include "../libc/stdio.h" + +#define BUF_SIZE 256 + +void brainfuck(char* input) +{ + unsigned char tape[30000] = {0}; + unsigned char* ptr = tape; + char current_char; + size_t i; + size_t loop; + + for (i=0; input[i] != 0; i++) + { + current_char = input[i]; + if (current_char == '>') { + ++ptr; + } else if (current_char == '<') { + --ptr; + } else if (current_char == '+') { + ++*ptr; + } else if (current_char == '-') { + --*ptr; + } else if (current_char == '.') { + putc(*ptr); + } else if (current_char == ',') { + *ptr = keyboard_getchar(); + } else if (current_char == '[') { + continue; + } else if (current_char == ']' && *ptr) { + loop = 1; + while (loop > 0) + { + current_char = input[--i]; + if (current_char == '[') { + loop--; + } else if (current_char == ']') { + loop++; + } + } + } + } +} + +void program_bf() +{ + char input_buffer[BUF_SIZE]; + puts("Brainfuck code? "); + get_input(input_buffer, BUF_SIZE); + brainfuck(input_buffer); + //brainfuck(",[.[-],]"); + puts("\n"); +} diff --git a/src/programs/misc.c b/src/programs/misc.c index 3836373..321c9a6 100644 --- a/src/programs/misc.c +++ b/src/programs/misc.c @@ -1,6 +1,7 @@ // Miscellaneous small programs #include "../libc/stdio.h" +#include "../kernel/system.h" // Print a rainbow colorful text for testing @@ -29,3 +30,10 @@ void program_clear() { for (int i=0; i