Merge pull request #5 from xamidev/dev

Small adjustments, pi program
This commit was merged in pull request #5.
This commit is contained in:
xamidev
2024-08-26 16:02:18 +02:00
committed by GitHub
10 changed files with 92 additions and 24 deletions

View File

@@ -39,7 +39,7 @@ Tada! You now have a working BlankOS USB stick. Go ahead and try it out!
## Documentation
Two other documents are available to help you understand the project better. One is the User's Manual, labelled [USERS.md](docs/USERS.md), and the other one is the Developer's Manual, labelled [DEVELOPERS.md](docs/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. *(The docs might not always be up-to-date)*
Two other documents are available to help you understand the project better. One is the User's Manual, labelled [USERS.md](docs/USERS.md), and the other one is the Developer's Manual, labelled [DEVELOPERS.md](docs/DEVELOPERS.md). They are full of useful resources: you'll learn how to use the system and how to contribute to it. *(The docs might not always be up-to-date)*
### Resources
@@ -56,11 +56,12 @@ Two other documents are available to help you understand the project better. One
- [X] Booting with GRUB
- [X] Common basic structures (IDT, GDT, ISRs, IRQs)
- [X] Common drivers (framebuffer, keyboard, serial, timer)
- [X] Common drivers (framebuffer, keyboard, serial, timer, RTC, ATA PIO)
- [X] Kernel-space utilities (shell, simple programs)
- [ ] Filesystem (FAT32 or VFS ramdisk)
- [ ] Changing the default VGA font
- [X] Paging/Page Frame Allocation
- [ ] Dynamic memory allocator (get memmap from GRUB?)
- [ ] Paging/Page Frame Allocation
- [ ] TCP/IP Network stack
- [ ] Getting to Ring-3 (userspace)
- [ ] Multitasking (via round robin scheduling)

View File

@@ -2,11 +2,10 @@
## Table of Contents
- [Getting Started](#getting-started)
- [Writing programs for BlankOS](#writing-programs)
- [Changing the TTY font](#changing-font)
- Getting Started
- Writing programs for BlankOS
- Changing the TTY font
<a name="getting-started"/>
## Getting Started
### System description
@@ -34,7 +33,6 @@ gdb kernel.elf
(gdb) target remote localhost:1234
```
<a name="getting-started"/>
## Writing programs for BlankOS
Be warned, these are not actual programs in the sense you'd expect. These are indeed functions that are called from the shell, and embedded in the kernel ELF binary. Real programs apart from the kernel are not yet a thing here, but might be one day.
@@ -96,7 +94,6 @@ The linking process should be taken care of by the appropriate Linker script `li
If you're proud of what you've made, you can clone the repo, make your changes, open a pull request and maybe your program will be added to the main BlankOS repo, and later distributed in the new ISOs!
<a name="changing-font"/>
## Changing the TTY font
In order to change the default font, first get your hands on a 8x16 `.psf` (PC Screen Font 2) formatted font. Then, put it in `include/fonts` and remove the default one (`UniCyr_8x16.psf`).

View File

@@ -39,7 +39,7 @@ Shows all of the available commands, which are explained here.
#### `panic`
Triggers a kernel panic by trying to divide four by zero.
Triggers a kernel panic by reserved exception.
#### `words`
@@ -57,7 +57,7 @@ Options:
- `<nothing>` will default to `PRIMES_MAX` (a million)
- `<integer>` will compute primes up to that number
#### `rainbow`
#### `rainbow <string>`
Asks for text and then outputs it with different vibrant colors.
@@ -77,11 +77,11 @@ A brainfuck interpreter with every instruction and default tape size (30k cells)
Gets system uptime from the timer in ticks. Ticks are incremented at a rate of 18.222Hz (18.222 ticks per second).
#### `echo`
#### `echo <string>`
The classic echo command, that outputs your input.
#### `sysinfo`
#### `sysinfo [option]`
Outputs information about the current system (CPU and RAM).
@@ -89,7 +89,7 @@ Options:
- `<nothing>` will show basic info about the CPUid and lower/upper memory.
- `-v` will output the CPUID, lower/upper memory, and the memory map.
#### `conway`
#### `conway [option]`
A classic Game of Life implementation with standard rules and 100 generations.
@@ -98,14 +98,18 @@ Options:
- `-g` will spawn a classic glider
- `-l` will spawn a lightweight spaceship
#### `rot13`
#### `rot13 <string>`
Encode a string using the rot13 cipher.
#### `morse`
#### `morse <string>`
Convert a string to its morse equivalent.
#### `cowsay`
#### `cowsay <string>`
Makes a cow speak!
#### `pi <terms>`
Computes Pi up to a couple of digits using the Leibniz series; takes one integer argument, the number of terms of the series to compute.

View File

@@ -7,13 +7,14 @@ global loader
section .multiboot_header
mb_start:
align 8
; ASM macros
MAGIC_NUMBER equ 0xe85250d6 ; multiboot2 magic
FLAGS equ 0x0 ; 32-bit protected mode for i386
HEADER_LEN equ 44 ; Tags=2+2+4+4+4+4+2+2+4=28
HEADER_LEN equ mb_end-mb_start
CHECKSUM equ -(MAGIC_NUMBER + FLAGS + HEADER_LEN)
; Multiboot 2 header, according to specification (16bytes)
@@ -42,6 +43,7 @@ CHECKSUM equ -(MAGIC_NUMBER + FLAGS + HEADER_LEN)
dd 8 ; 4
; End of Multiboot 2 header
mb_end:
section .text:

View File

@@ -16,13 +16,35 @@
#define MAX_ARGS 64
// Splash screen: esthetic stuff.
char* motd[] =
{
"I should be root, really.",
"Not watching you!",
"Now in 2D!",
"Supercalifragilisticexpialidocious!",
"Tylko jedno w glowie mam!",
"Greetings, magic poppy!",
"I'm stuck in this kernel's shell, get me out!",
"And now, solve that equation!",
"Powered by TCC Incorporated.",
"Compiled at 69, CoquaineBaule Ave.",
"Shouldn't we be, uh, doing something?",
"We are the florists, we pick the plants!",
"Lalalalala, I pick the plants!",
"Woah, we're half-way there...",
"The CROU will never die!",
"Technoblade never dies!",
"Hi. My name is Guitar.",
"space station No. 9",
"May the orange juice be with you !",
"Bloody grated carrots!",
"Good night, kiddos...",
"I like trains",
"I fear planes",
"Bruteforce.exe",
"Ohayogozaimasu!",
};
int motd_size = sizeof(motd)/sizeof(motd[0]);
bool do_splash = true;
@@ -113,6 +135,7 @@ void shell_install()
register_command("time", program_time);
register_command("read", program_read);
register_command("reboot", program_reboot);
register_command("pi", program_pi);
for (;;)
{

View File

@@ -73,7 +73,7 @@ void program_uptime()
void program_help()
{
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\n");
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\npi\n");
}
// Panic

34
src/programs/pi.c Normal file
View File

@@ -0,0 +1,34 @@
// Program for Pi computation using Leibniz series
// Author: xamidev
// Licensed under the Unlicense. See the repo below.
// https://github.com/xamidev/blankos
#include "../libc/stdio.h"
#include "../libc/string.h"
void program_pi(int argc, char* argv[])
{
if (argc < 2)
{
printf("Usage: %s <terms>\n", argv[0]);
return;
}
double pi = 0.0;
int terms = atoi(argv[1]);
for (int i=0; i<terms; i++)
{
double term = 1.0/(2*i+1);
if (i%2 == 0)
{
pi += term;
} else {
pi -= term;
}
}
pi *= 4;
printf("%f\n", pi);
}

View File

@@ -31,9 +31,12 @@ void program_primes(int argc, char* argv[])
for (long long x=0; x<primes_max; x++)
{
if (isPrime(x))
if (isPrime(x) && x != 3301)
{
printf("%d ", x);
} else if(x == 3301)
{
colorputs("3301 ", red, black);
}
delay(1);
}

View File

@@ -17,6 +17,7 @@ void get_meminfo(unsigned int multiboot_info_address);
void program_conway();
void program_cowsay();
void cowsay(); // Splash screen
void program_pi();
// Ciphers
void program_rot13();

View File

@@ -40,6 +40,7 @@ void get_cpuid()
printf("CPU information\n\tvendor: %s\n\tfamily: %u\n\tmodel: %u\n\tfeatures: 0x%x\n", vendor, family, model, edx);
}
// Not really working anymore as it was made for multiboot1, now using multiboot2
void get_meminfo(unsigned int multiboot_info_address, int verbose)
{
// RAM
@@ -56,13 +57,15 @@ void get_meminfo(unsigned int multiboot_info_address, int verbose)
while ((unsigned int)mmap < multiboot_info_address + *((unsigned int*)(multiboot_info_address + 40)))
{
/*
if (mmap->length_high != 0 && mmap->length_low != 0)
{
{*/
printf("0x%x%x | 0x%x%x | %u\n",
mmap->base_addr_high, mmap->base_addr_low,
mmap->length_high, mmap->length_low,
mmap->type);
}
//}
mmap = (multiboot_memory_map_t*)((unsigned int)mmap + mmap->size + sizeof(unsigned int));
}
}