Add: brainfuck interpreter; documentation; uptime
This commit is contained in:
39
README.md
39
README.md
@@ -1,11 +1,19 @@
|
|||||||
# BlankOS
|
# 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:
|
## Features
|
||||||
- User programs
|
|
||||||
- Completing the kernel libc
|
- Serial port driver (output & debug)
|
||||||
- Filesystem support
|
- 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
|
## 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`).
|
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!
|
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
|
### ⚠️ Disclaimer
|
||||||
|
|
||||||
|
|||||||
39
USERS.md
39
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`.
|
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).
|
||||||
|
|||||||
Binary file not shown.
6
src/drivers/kb.h
Normal file
6
src/drivers/kb.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef KB_H
|
||||||
|
#define KB_H
|
||||||
|
|
||||||
|
char keyboard_getchar();
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -19,3 +19,8 @@ void delay(int ticks)
|
|||||||
eticks = global_ticks + ticks;
|
eticks = global_ticks + ticks;
|
||||||
while (global_ticks < eticks);
|
while (global_ticks < eticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int uptime()
|
||||||
|
{
|
||||||
|
return global_ticks;
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ void shell_install()
|
|||||||
}
|
}
|
||||||
else if (strcmp(input_buffer, "help") == 0)
|
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)
|
else if (strcmp(input_buffer, "panic") == 0)
|
||||||
{
|
{
|
||||||
@@ -47,6 +47,14 @@ void shell_install()
|
|||||||
{
|
{
|
||||||
program_math();
|
program_math();
|
||||||
}
|
}
|
||||||
|
else if (strcmp(input_buffer, "bf") == 0)
|
||||||
|
{
|
||||||
|
program_bf();
|
||||||
|
}
|
||||||
|
else if (strcmp(input_buffer, "uptime") == 0)
|
||||||
|
{
|
||||||
|
program_uptime();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
printf("Unknown command %s\n", input_buffer);
|
printf("Unknown command %s\n", input_buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ void delay(int ticks);
|
|||||||
void keyboard_install();
|
void keyboard_install();
|
||||||
char keyboard_getchar();
|
char keyboard_getchar();
|
||||||
void shell_install();
|
void shell_install();
|
||||||
|
int uptime();
|
||||||
|
|
||||||
extern volatile unsigned long global_ticks;
|
extern volatile unsigned long global_ticks;
|
||||||
|
|
||||||
|
|||||||
55
src/programs/bf.c
Normal file
55
src/programs/bf.c
Normal file
@@ -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");
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
// Miscellaneous small programs
|
// Miscellaneous small programs
|
||||||
|
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
|
#include "../kernel/system.h"
|
||||||
|
|
||||||
// Print a rainbow colorful text for testing
|
// Print a rainbow colorful text for testing
|
||||||
|
|
||||||
@@ -29,3 +30,10 @@ void program_clear()
|
|||||||
{
|
{
|
||||||
for (int i=0; i<ROWS; i++) scroll(1);
|
for (int i=0; i<ROWS; i++) scroll(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get uptime in ticks
|
||||||
|
|
||||||
|
void program_uptime()
|
||||||
|
{
|
||||||
|
printf("%d ticks\n", uptime());
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,8 +4,11 @@
|
|||||||
void program_words();
|
void program_words();
|
||||||
void program_primes();
|
void program_primes();
|
||||||
void program_math();
|
void program_math();
|
||||||
|
void program_bf();
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
void program_rainbow();
|
void program_rainbow();
|
||||||
void program_clear();
|
void program_clear();
|
||||||
|
void program_uptime();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user