From 078675fa3fc72b573c3cda9de99411671e538b24 Mon Sep 17 00:00:00 2001 From: Vincenzo Alesksey Brocato Date: Sun, 28 Jul 2024 11:24:38 +0200 Subject: [PATCH 1/4] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index a1074ce..70c23f8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +

This is the "Coding" branch, the code in this branch is full of bugs and errors or simply doesn't compile, please use the main branch!

+
+ Hey all, Vincenzo Aleskey Brocato (VinceAle7082) here!
This is a little project where I try to make an OS just for fun

From 95a01632bbf8cbfd90b15687f15e4e11f382c00f Mon Sep 17 00:00:00 2001 From: VinceAle7082 Date: Wed, 31 Jul 2024 19:22:04 +0200 Subject: [PATCH 2/4] I'm back (I reinstalled Gentoo) --- .gitignore | 3 ++- src/bootloader/stage2/main.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 07b498d..17a1953 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/ -.mailmap \ No newline at end of file +.mailmap +.vscode \ No newline at end of file diff --git a/src/bootloader/stage2/main.c b/src/bootloader/stage2/main.c index 7592ea9..1e7137d 100644 --- a/src/bootloader/stage2/main.c +++ b/src/bootloader/stage2/main.c @@ -1,7 +1,7 @@ #include "stdint.h" #include "stdio.h" -void _cdecl cstart_(uint16_t bootDrive) +void _cdecl cstart_(uint16_t bootDrive) { puts("Hello World from the Stage 2 of the bootloader written in C!"); for (;;); From 8e45bd516008b74fb7c258c2e158ab68d2b44dc8 Mon Sep 17 00:00:00 2001 From: VinceAle7082 Date: Wed, 31 Jul 2024 20:59:39 +0200 Subject: [PATCH 3/4] Half implemented printf() [DOESN'T COMPILE] Idk what to write, a friend wants to play minecraft so... here is the code I wrote before him calling me. --- src/bootloader/stage2/main.err | 2 +- src/bootloader/stage2/stdint.h | 4 +- src/bootloader/stage2/stdio.c | 151 ++++++++++++++++++++++++++++++++ src/bootloader/stage2/stdio.err | 35 +++++++- src/bootloader/stage2/stdio.h | 3 +- 5 files changed, 191 insertions(+), 4 deletions(-) diff --git a/src/bootloader/stage2/main.err b/src/bootloader/stage2/main.err index f07be74..d9b76d9 100644 --- a/src/bootloader/stage2/main.err +++ b/src/bootloader/stage2/main.err @@ -1,3 +1,3 @@ -stdio.h(4): Warning! W138: No newline at end of file +stdio.h(5): Warning! W138: No newline at end of file main.c(8): Warning! W138: No newline at end of file main.c(4): Warning! W303: Parameter 'bootDrive' has been defined, but not referenced diff --git a/src/bootloader/stage2/stdint.h b/src/bootloader/stage2/stdint.h index a250c54..2999fd9 100644 --- a/src/bootloader/stage2/stdint.h +++ b/src/bootloader/stage2/stdint.h @@ -8,5 +8,7 @@ typedef signed long int int32_t; typedef unsigned long int uint32_t; typedef signed long int int64_t; typedef unsigned long int uint64_t; +typedef uint8_t bool; - +#define true 1 +#define false 0 diff --git a/src/bootloader/stage2/stdio.c b/src/bootloader/stage2/stdio.c index 327355c..439bf8f 100644 --- a/src/bootloader/stage2/stdio.c +++ b/src/bootloader/stage2/stdio.c @@ -13,3 +13,154 @@ void puts(const char *str) str++; } } + +#define PRINTF_STATE_NORMAL 0 +#define PRINTF_STATE_LENGHT 1 +#define PRINTF_STATE_LENGHT_SHORT 2 +#define PRINTF_STATE_LENGHT_LONG 1 +#define PRINTF_STATE_SPEC 4 +#define PRINTF_LENGTH_DEFAULT 0 +#define PRINTF_LENGTH_SHORT_SHORT 1 +#define PRINTF_LENGTH_SHORT 2 +#define PRINTF_LENGTH_LONG 3 +#define PRINTF_LENGTH_LONG_LONG 4 +int* printf_number(int *argp, int length, bool sign, int radix) +const char g_HexChars[] = '0123456789abcdef' + +void _cdecl printf(const char *fmt, ...) +{ + int *argp = (int*)&fmt; + int state = PRINTF_STATE_NORMAL; + int length = PRINTF_LENGTH_DEFAULT; + int radix = 10; + bool sign = false; + argp++; + while (*fmt) + { + switch (state) + { + case PRINTF_STATE_NORMAL: + switch (*fmt) + { + case '%': + state = PRINTF_STATE_LENGHT; + break; + default: + putc(*fmt); + break; + } + + case PRINTF_STATE_LENGHT: + switch (*fmt) + { + case 'h': + length = PRINTF_LENGTH_SHORT; + state = PRINTF_STATE_LENGHT_SHORT; + break; + case 'l': + length = PRINTF_LENGTH_LONG; + state = PRINTF_STATE_LENGHT_LONG; + break; + + default: + goto PRINTF_STATE_SPEC; + } + break; + + case PRINTF_LENGTH_SHORT: + if (*fmt == 'h') + { + length = PRINTF_LENGTH_SHORT_SHORT; + state = PRINTF_STATE_SPEC; + } + else + { + goto PRINTF_STATE_SPEC; + } + break; + + case PRINTF_STATE_SPEC: + switch (*fmt) + { + case 'c': + putc((char)*argp); + argp++; + break; + case 's': + puts(*(char **)argp); + argp++; + break; + case '%': + putc('%'); + break; + case 'd': + case 'i': + radix = 10; + sign = true; + argp = printf_number(argp, length, sign, radix); + break; + case 'u': + radix = 10; + sign = false; + argp = printf_number(argp, length, sign, radix); + break; + case 'x': + case 'X': + case 'p': + radix = 16; + sign = false; + argp = printf_number(argp, length, sign, radix); + break; + case 'o': + radix = 8; + sign = false; + argp = printf_number(argp, length, sign, radix); + break; + //Se รจ messo un carattere non valido questo codice fa in modo che li ignora. + default: + break; + } + //Porta le variabili allo stato di default / normale. + state = PRINTF_STATE_NORMAL; + length = PRINTF_LENGTH_DEFAULT; + radix = 10; + sign = false; + break; + } + fmt++; + } +} + +int* printf_number(int* argp, int length, bool sign, int radix) +{ + char buffer[32]; + unsigned long long number; + int number_sign = 1; + int pos = 0; + + switch (length) + { + case PRINTF_LENGTH_SHORT_SHORT: + case PRINTF_LENGTH_SHORT: + case PRINTF_LENGTH_LONG: + case PRINTF_LENGTH_LONG_LONG: + case PRINTF_LENGTH_DEFAULT: + if (sign) + { + int n = *argp; + if (n < 0) + { + n = -n; + number_sign = -1; + } + number = n; + } + else + { + number = (*unsigned int*)argp; + + } + argp++; + break; + } +} \ No newline at end of file diff --git a/src/bootloader/stage2/stdio.err b/src/bootloader/stage2/stdio.err index f5ae572..a8b28db 100644 --- a/src/bootloader/stage2/stdio.err +++ b/src/bootloader/stage2/stdio.err @@ -1,2 +1,35 @@ -stdio.h(4): Warning! W138: No newline at end of file +stdio.h(5): Warning! W138: No newline at end of file x86.h(4): Warning! W138: No newline at end of file +stdio.c(31): Error! E1024: Declared symbol 'printf' is not in parameter list +stdio.c(31): Error! E1076: Missing semicolon at end of declaration +stdio.c(32): Error! E1034: Symbol 'argp' already defined +stdio.c(32): Note! I2002: 'argp' defined in: stdio.c(28) +stdio.c(32): Error! E1011: Symbol 'fmt' has not been declared +stdio.c(34): Error! E1034: Symbol 'length' already defined +stdio.c(34): Note! I2002: 'length' defined in: stdio.c(28) +stdio.c(35): Error! E1034: Symbol 'radix' already defined +stdio.c(35): Note! I2002: 'radix' defined in: stdio.c(28) +stdio.c(36): Error! E1034: Symbol 'sign' already defined +stdio.c(36): Note! I2002: 'sign' defined in: stdio.c(28) +stdio.c(38): Error! E1029: Expression must be 'pointer to ...' +stdio.c(43): Error! E1029: Expression must be 'pointer to ...' +stdio.c(49): Error! E1029: Expression must be 'pointer to ...' +stdio.c(49): Error! E1151: Parameter count does not agree with previous definition +stdio.c(49): Note! I2002: 'putc' defined in: stdio.c(4) +stdio.c(54): Error! E1029: Expression must be 'pointer to ...' +stdio.c(66): Error! E1038: Expecting label for goto statement +stdio.c(71): Error! E1029: Expression must be 'pointer to ...' +stdio.c(78): Error! E1038: Expecting label for goto statement +stdio.c(83): Error! E1029: Expression must be 'pointer to ...' +stdio.c(28): Warning! W303: Parameter 'sign' has been defined, but not referenced +stdio.c(28): Warning! W303: Parameter 'length' has been defined, but not referenced +stdio.c(28): Warning! W303: Parameter 'radix' has been defined, but not referenced +stdio.c(28): Warning! W303: Parameter 'argp' has been defined, but not referenced +stdio.c(132): Warning! W107: Missing return value for function 'printf_number' +stdio.c(135): Error! E1034: Symbol 'printf_number' already defined +stdio.c(137): Warning! W138: No newline at end of file +stdio.c(134): Warning! W303: Parameter 'sign' has been defined, but not referenced +stdio.c(134): Warning! W303: Parameter 'length' has been defined, but not referenced +stdio.c(134): Warning! W303: Parameter 'radix' has been defined, but not referenced +stdio.c(134): Warning! W303: Parameter 'argp' has been defined, but not referenced +stdio.c(137): Warning! W107: Missing return value for function 'printf_number' diff --git a/src/bootloader/stage2/stdio.h b/src/bootloader/stage2/stdio.h index f25dc1c..0735127 100644 --- a/src/bootloader/stage2/stdio.h +++ b/src/bootloader/stage2/stdio.h @@ -1,4 +1,5 @@ #pragma once void putc(char c); -void puts(const char *str); \ No newline at end of file +void puts(const char* str); +void _cdecl printf(const char *fmt, ...); \ No newline at end of file From 423e5478b433fa988b7aa5ff814cc770aa0de23f Mon Sep 17 00:00:00 2001 From: VinceAle7082 Date: Wed, 31 Jul 2024 21:04:57 +0200 Subject: [PATCH 4/4] Idk why those files are here, so I removed them. --- src/bootloader/stage2/main.err | 3 --- src/bootloader/stage2/stdio.err | 35 --------------------------------- 2 files changed, 38 deletions(-) delete mode 100644 src/bootloader/stage2/main.err delete mode 100644 src/bootloader/stage2/stdio.err diff --git a/src/bootloader/stage2/main.err b/src/bootloader/stage2/main.err deleted file mode 100644 index d9b76d9..0000000 --- a/src/bootloader/stage2/main.err +++ /dev/null @@ -1,3 +0,0 @@ -stdio.h(5): Warning! W138: No newline at end of file -main.c(8): Warning! W138: No newline at end of file -main.c(4): Warning! W303: Parameter 'bootDrive' has been defined, but not referenced diff --git a/src/bootloader/stage2/stdio.err b/src/bootloader/stage2/stdio.err deleted file mode 100644 index a8b28db..0000000 --- a/src/bootloader/stage2/stdio.err +++ /dev/null @@ -1,35 +0,0 @@ -stdio.h(5): Warning! W138: No newline at end of file -x86.h(4): Warning! W138: No newline at end of file -stdio.c(31): Error! E1024: Declared symbol 'printf' is not in parameter list -stdio.c(31): Error! E1076: Missing semicolon at end of declaration -stdio.c(32): Error! E1034: Symbol 'argp' already defined -stdio.c(32): Note! I2002: 'argp' defined in: stdio.c(28) -stdio.c(32): Error! E1011: Symbol 'fmt' has not been declared -stdio.c(34): Error! E1034: Symbol 'length' already defined -stdio.c(34): Note! I2002: 'length' defined in: stdio.c(28) -stdio.c(35): Error! E1034: Symbol 'radix' already defined -stdio.c(35): Note! I2002: 'radix' defined in: stdio.c(28) -stdio.c(36): Error! E1034: Symbol 'sign' already defined -stdio.c(36): Note! I2002: 'sign' defined in: stdio.c(28) -stdio.c(38): Error! E1029: Expression must be 'pointer to ...' -stdio.c(43): Error! E1029: Expression must be 'pointer to ...' -stdio.c(49): Error! E1029: Expression must be 'pointer to ...' -stdio.c(49): Error! E1151: Parameter count does not agree with previous definition -stdio.c(49): Note! I2002: 'putc' defined in: stdio.c(4) -stdio.c(54): Error! E1029: Expression must be 'pointer to ...' -stdio.c(66): Error! E1038: Expecting label for goto statement -stdio.c(71): Error! E1029: Expression must be 'pointer to ...' -stdio.c(78): Error! E1038: Expecting label for goto statement -stdio.c(83): Error! E1029: Expression must be 'pointer to ...' -stdio.c(28): Warning! W303: Parameter 'sign' has been defined, but not referenced -stdio.c(28): Warning! W303: Parameter 'length' has been defined, but not referenced -stdio.c(28): Warning! W303: Parameter 'radix' has been defined, but not referenced -stdio.c(28): Warning! W303: Parameter 'argp' has been defined, but not referenced -stdio.c(132): Warning! W107: Missing return value for function 'printf_number' -stdio.c(135): Error! E1034: Symbol 'printf_number' already defined -stdio.c(137): Warning! W138: No newline at end of file -stdio.c(134): Warning! W303: Parameter 'sign' has been defined, but not referenced -stdio.c(134): Warning! W303: Parameter 'length' has been defined, but not referenced -stdio.c(134): Warning! W303: Parameter 'radix' has been defined, but not referenced -stdio.c(134): Warning! W303: Parameter 'argp' has been defined, but not referenced -stdio.c(137): Warning! W107: Missing return value for function 'printf_number'