Small fixes: uptime, printf %f, math, and readme

This commit is contained in:
xamidev
2024-08-08 13:28:47 +02:00
parent 99b26c1220
commit da127ee6b2
6 changed files with 23 additions and 28 deletions

View File

@@ -19,6 +19,16 @@ The long-term goal of this OS is to be capable of running user programs and havi
## Usage ## Usage
Download the latest BlankOS ISO image from the "Releases" tab, and emulate it directly using the QEMU emulator:
```
qemu-system-i386 blankOS-i386-1.4.45.iso
```
Alternatively, burn the image on a USB stick and use it on a machine (see section "Real Hardware").
## Building from source
### Dependencies ### Dependencies
For Debian-based distros: For Debian-based distros:
@@ -42,7 +52,7 @@ A cross-compiler is needed to build the system. More info on why [here](https://
Why didn't I use one sooner? Can't tell. Maybe I was too lazy. This is actually problematic because I wasn't able to use some libraries and I had to put in a bunch of weird compilation flags. It's better like this. Why didn't I use one sooner? Can't tell. Maybe I was too lazy. This is actually problematic because I wasn't able to use some libraries and I had to put in a bunch of weird compilation flags. It's better like this.
## Building and running To clone and build, do:
``` ```
git clone https://github.com/xamidev/blankos git clone https://github.com/xamidev/blankos
@@ -50,7 +60,8 @@ make
make run make run
``` ```
This will start a new Bochs debugger instance. To proceed with the kernel execution, you will have to type `c` in the shell spawning Bochs. Serial output will be saved under the `com1.out` file, this way you can debug the kernel by viewing its log messages. To quit, type `q`. Feel free to open issues or pull requests. This will start a new Bochs debugger instance. To proceed with the kernel execution, you will have to type `c` in the shell spawning Bochs. Serial output will be saved under the `com1.out` file, this way you can debug the kernel by viewing its log messages. To quit, type `q`.
You can try out QEMU too.
## Running on real hardware ## Running on real hardware

Binary file not shown.

View File

@@ -3,6 +3,7 @@
#include "gdt.h" #include "gdt.h"
#include "idt.h" #include "idt.h"
#include "system.h" #include "system.h"
//#include <stdarg.h>
char* ascii_title = char* ascii_title =
"\n" "\n"

View File

@@ -183,7 +183,6 @@ void dtostrf(double val, char *buffer, int precision)
double fractional_part = val - whole_part; double fractional_part = val - whole_part;
if (fractional_part < 0) fractional_part = -fractional_part; if (fractional_part < 0) fractional_part = -fractional_part;
char *start = buffer;
if (whole_part == 0) if (whole_part == 0)
{ {
*buffer++ = '0'; *buffer++ = '0';

View File

@@ -87,7 +87,6 @@ Token lexer_get_next_token(Lexer *lexer)
} }
lexer->current_token.type = TOKEN_NUMBER; lexer->current_token.type = TOKEN_NUMBER;
lexer->current_token.value = value; lexer->current_token.value = value;
//printf("NUMBER %f\n", value);
return lexer->current_token; return lexer->current_token;
} }
@@ -95,7 +94,6 @@ Token lexer_get_next_token(Lexer *lexer)
{ {
lexer_advance(lexer); lexer_advance(lexer);
lexer->current_token.type = TOKEN_PLUS; lexer->current_token.type = TOKEN_PLUS;
printf("PLUS\n");
return lexer->current_token; return lexer->current_token;
} }
@@ -103,7 +101,6 @@ Token lexer_get_next_token(Lexer *lexer)
{ {
lexer_advance(lexer); lexer_advance(lexer);
lexer->current_token.type = TOKEN_MINUS; lexer->current_token.type = TOKEN_MINUS;
printf("MINUS\n");
return lexer->current_token; return lexer->current_token;
} }
@@ -111,7 +108,6 @@ Token lexer_get_next_token(Lexer *lexer)
{ {
lexer_advance(lexer); lexer_advance(lexer);
lexer->current_token.type = TOKEN_MULTIPLY; lexer->current_token.type = TOKEN_MULTIPLY;
printf("MULTIPLY\n");
return lexer->current_token; return lexer->current_token;
} }
@@ -119,7 +115,6 @@ Token lexer_get_next_token(Lexer *lexer)
{ {
lexer_advance(lexer); lexer_advance(lexer);
lexer->current_token.type = TOKEN_DIVIDE; lexer->current_token.type = TOKEN_DIVIDE;
printf("DIVIDE\n");
return lexer->current_token; return lexer->current_token;
} }
@@ -127,7 +122,6 @@ Token lexer_get_next_token(Lexer *lexer)
{ {
lexer_advance(lexer); lexer_advance(lexer);
lexer->current_token.type = TOKEN_LPAREN; lexer->current_token.type = TOKEN_LPAREN;
printf("LPAREN\n");
return lexer->current_token; return lexer->current_token;
} }
@@ -135,16 +129,14 @@ Token lexer_get_next_token(Lexer *lexer)
{ {
lexer_advance(lexer); lexer_advance(lexer);
lexer->current_token.type = TOKEN_RPAREN; lexer->current_token.type = TOKEN_RPAREN;
printf("RPAREN\n");
return lexer->current_token; return lexer->current_token;
} }
printf("Unknown character %c\n", current_char); printf("\nUnknown character %c\n", current_char);
//shell_install(); shell_install();
} }
lexer->current_token.type = TOKEN_END; lexer->current_token.type = TOKEN_END;
printf("END\n");
return lexer->current_token; return lexer->current_token;
} }
@@ -166,8 +158,8 @@ void parser_eat(Parser *parser, TokenType type)
{ {
parser->current_token = lexer_get_next_token(&parser->lexer); parser->current_token = lexer_get_next_token(&parser->lexer);
} else { } else {
printf("Unexpected token %d\n", parser->current_token.type); printf("\nUnexpected token %d\n", parser->current_token.type);
//shell_install(); shell_install();
} }
} }
@@ -181,17 +173,15 @@ double parser_factor(Parser *parser)
if (token.type == TOKEN_NUMBER) if (token.type == TOKEN_NUMBER)
{ {
parser_eat(parser, TOKEN_NUMBER); parser_eat(parser, TOKEN_NUMBER);
//printf("Factor: %f\n", token.value);
return token.value; return token.value;
} else if (token.type == TOKEN_LPAREN) { } else if (token.type == TOKEN_LPAREN) {
parser_eat(parser, TOKEN_LPAREN); parser_eat(parser, TOKEN_LPAREN);
double result = parser_expression(parser); double result = parser_expression(parser);
parser_eat(parser, TOKEN_RPAREN); parser_eat(parser, TOKEN_RPAREN);
//printf("Factor (expression): %f\n", result);
return result; return result;
} else { } else {
printf("Unexpected token in factor %d\n", token.type); printf("\nUnexpected token in factor %d\n", token.type);
//shell_install(); shell_install();
} }
return -1; return -1;
} }
@@ -199,7 +189,6 @@ double parser_factor(Parser *parser)
double parser_term(Parser *parser) double parser_term(Parser *parser)
{ {
double result = parser_factor(parser); double result = parser_factor(parser);
//printf("Initial term: %f\n", result);
while (parser->current_token.type == TOKEN_MULTIPLY || parser->current_token.type == TOKEN_DIVIDE) while (parser->current_token.type == TOKEN_MULTIPLY || parser->current_token.type == TOKEN_DIVIDE)
{ {
@@ -208,11 +197,9 @@ double parser_term(Parser *parser)
{ {
parser_eat(parser, TOKEN_MULTIPLY); parser_eat(parser, TOKEN_MULTIPLY);
result *= parser_factor(parser); result *= parser_factor(parser);
//printf("Term after multiply: %f\n", result);
} else if (token.type == TOKEN_DIVIDE) { } else if (token.type == TOKEN_DIVIDE) {
parser_eat(parser, TOKEN_DIVIDE); parser_eat(parser, TOKEN_DIVIDE);
result /= parser_factor(parser); result /= parser_factor(parser);
//printf("Term after divide: %f\n", result);
} }
} }
return result; return result;
@@ -221,7 +208,6 @@ double parser_term(Parser *parser)
double parser_expression(Parser *parser) double parser_expression(Parser *parser)
{ {
double result = parser_term(parser); double result = parser_term(parser);
//printf("Initial expression: %f\n", result);
while (parser->current_token.type == TOKEN_PLUS || parser->current_token.type == TOKEN_MINUS) while (parser->current_token.type == TOKEN_PLUS || parser->current_token.type == TOKEN_MINUS)
{ {
@@ -230,11 +216,9 @@ double parser_expression(Parser *parser)
{ {
parser_eat(parser, TOKEN_PLUS); parser_eat(parser, TOKEN_PLUS);
result += parser_term(parser); result += parser_term(parser);
//printf("Expression after plus: %f\n", result);
} else if (token.type == TOKEN_MINUS) { } else if (token.type == TOKEN_MINUS) {
parser_eat(parser, TOKEN_MINUS); parser_eat(parser, TOKEN_MINUS);
result -= parser_term(parser); result -= parser_term(parser);
//printf("Expression after minus: %f\n", result);
} }
} }
return result; return result;
@@ -245,7 +229,6 @@ double parse(const char* text)
Parser parser; Parser parser;
parser_init(&parser, text); parser_init(&parser, text);
double result = parser_expression(&parser); double result = parser_expression(&parser);
//printf("Final result: %f\n", result);
return result; return result;
} }
@@ -254,7 +237,6 @@ void program_math()
char input_buffer[BUFFER_SIZE]; char input_buffer[BUFFER_SIZE];
puts("Expression? "); puts("Expression? ");
get_input(input_buffer, BUFFER_SIZE); get_input(input_buffer, BUFFER_SIZE);
printf("Input: %s\n", input_buffer);
double result = parse(input_buffer); double result = parse(input_buffer);
printf("\n%f\n", result); printf("\n%f\n", result);
} }

View File

@@ -35,5 +35,7 @@ void program_clear()
void program_uptime() void program_uptime()
{ {
printf("%d ticks\n", uptime()); int ticks = uptime();
double seconds = ticks/18.2065; // PIC channel 0 freq
printf("%d ticks\t%f seconds\n", ticks, seconds);
} }