diff --git a/build.sh b/build.sh index 486a622..c322590 100755 --- a/build.sh +++ b/build.sh @@ -1 +1 @@ -clang src/main.c -o build/main \ No newline at end of file +clang -nostartfiles src/main.c -o build/main \ No newline at end of file diff --git a/src/ableos_std/ableos_std.c b/src/ableos_std/ableos_std.c index a6ef25d..dd30e28 100644 --- a/src/ableos_std/ableos_std.c +++ b/src/ableos_std/ableos_std.c @@ -12,8 +12,13 @@ #include "services/log_service.c" #include "services/csprng_service.c" +#include "services/memory_service.c" #include "random/random.c" #include "arguments.c" -#include "process.c" \ No newline at end of file +#include "process.c" +#include "exit.h" + + +#include "collections/vec.c" \ No newline at end of file diff --git a/src/ableos_std/collections/vec.c b/src/ableos_std/collections/vec.c new file mode 100644 index 0000000..128d5aa --- /dev/null +++ b/src/ableos_std/collections/vec.c @@ -0,0 +1,38 @@ +typedef struct { + // Pointer to the vector data + void* data; + // the current size of the vector + int size; + int capacity; + // Size of the types stored + int type_size; +} Vector; + + +// initial_capacity in type_size +Vector init(int initial_capacity, int type_size) { + Vector vec; + vec.size = 0; + vec.type_size = type_size; + vec.capacity = initial_capacity; + // TODO + // vec.data = malloc(initial_capacity * vec.type_size); + + return vec; +} + +void push(Vector vec, void* ptr) { + // calculate offset + void* offset = vec.data + (vec.size * vec.type_size); + vec.size += 1; + printf("size %d", offset); + // TODO + // memcpy(offset, ptr, vec.type_size); +} +// pop + +void* get(Vector vec, int index){ + return 0; +} + +void set(Vector vec, int index, void* ptr){} diff --git a/src/ableos_std/exit.h b/src/ableos_std/exit.h new file mode 100644 index 0000000..3adcefe --- /dev/null +++ b/src/ableos_std/exit.h @@ -0,0 +1,27 @@ + +typedef struct { + String reason; +} ExitCode; + +ExitCode ecode_new(char* ptr){ + return (ExitCode) { + .reason = from_c_str(ptr), + }; +} + +typedef ExitCode ExitCodeArray[255]; + + +typedef struct { + ExitCodeArray exit_code_registry; +}ExitCodeRegistry ; + + + +ExitCodeRegistry exit_codes; +int exit_code_count = 0; + +void register_exit_code(ExitCode ecode) { + exit_codes.exit_code_registry[exit_code_count] = ecode; + exit_code_count += 1; +} diff --git a/src/ableos_std/math.h b/src/ableos_std/math.h new file mode 100644 index 0000000..6a2cd21 --- /dev/null +++ b/src/ableos_std/math.h @@ -0,0 +1,13 @@ +/*Sadly sometimes dividing people in half is a bad thing actually*/ +int divide_up(int n, int d) { + if (n % d == 0) { + return n / d; + } + return 1 + n / d; +} + +int square(int a){ + return a * a; +} int half(int a){ + return a / 2; +} \ No newline at end of file diff --git a/src/ableos_std/process.c b/src/ableos_std/process.c index 63beea2..69e2fed 100644 --- a/src/ableos_std/process.c +++ b/src/ableos_std/process.c @@ -1,7 +1,7 @@ typedef enum { - Success, + ProcessSuccess, NoPermission, NoProcess, diff --git a/src/ableos_std/random/mersenne_twister/lib.h b/src/ableos_std/random/mersenne_twister/lib.h index 5274ae9..1a4cbda 100644 --- a/src/ableos_std/random/mersenne_twister/lib.h +++ b/src/ableos_std/random/mersenne_twister/lib.h @@ -3,10 +3,10 @@ #define STATE_VECTOR_M 397 typedef struct tagMTRand { - unsigned long mt[STATE_VECTOR_LENGTH]; - int index; + u32 mt[STATE_VECTOR_LENGTH]; + i32 index; } MTRand; -MTRand mersenne_twister_seed_rand(unsigned long seed); +MTRand mersenne_twister_seed_rand(u32 seed); u32 mt_generate_u32(MTRand* rand); f64 mt_generate_f64_0_to_1(MTRand* rand); \ No newline at end of file diff --git a/src/ableos_std/services/log_service.c b/src/ableos_std/services/log_service.c index 80342a6..6db7566 100644 --- a/src/ableos_std/services/log_service.c +++ b/src/ableos_std/services/log_service.c @@ -16,10 +16,10 @@ void inner_log(Level level, const char* message, const char* file, int line) { lvl_str = "ERROR"; break; case WARN: - lvl_str = "WARN"; + lvl_str = "WARN "; break; case INFO: - lvl_str = "INFO"; + lvl_str = "INFO "; break; case DEBUG: lvl_str = "DEBUG"; diff --git a/src/ableos_std/services/memory_service.c b/src/ableos_std/services/memory_service.c new file mode 100644 index 0000000..1e6333f --- /dev/null +++ b/src/ableos_std/services/memory_service.c @@ -0,0 +1,26 @@ +/* +This is a kernel provided service +*/ + +typedef enum { + MemorySuccess, + MemoryLimitReached, +} MemoryServiceResponse; + + + + +// Limit a process to having page_limit amount of pages +void limit_pages(u64 page_limit) { + info("Limiting application memory "); +} + + +// Allocate pages amount of pages +MemoryServiceResponse page_alloc(u64 pages) { + return MemorySuccess; +} +// page_ptr ***MUST*** be a page aligned ptr that will be unallocated +MemoryServiceResponse page_dealloc(void* page_ptr) { + return MemorySuccess; +} \ No newline at end of file diff --git a/src/ableos_std/start.c b/src/ableos_std/start.c new file mode 100644 index 0000000..f2efe8b --- /dev/null +++ b/src/ableos_std/start.c @@ -0,0 +1,15 @@ +#include +void _start() { + register_exit_code(ecode_new("Success")); + int exit_code = main(); + char* ptr = exit_codes.exit_code_registry[exit_code].reason.ptr; + + if (ptr == 0) { + printf("Invalid ExitCode"); + } else { + printf("EXIT [%s]", ptr); + } + + // This is linux focused + exit(1); +} diff --git a/src/keyb.c b/src/keyb.c new file mode 100644 index 0000000..e05ce41 --- /dev/null +++ b/src/keyb.c @@ -0,0 +1,97 @@ +#include +#include "ableos_std/ableos_std.c" + +typedef enum { + // KeyUp is the default state + KeyUp = 0, + KeyDown = 0x43, +} KeyState; + +typedef struct { + KeyState kstate; + // TODO: https://github.com/rust-windowing/winit/issues/2995 + char key; +} KeyboardEvent; + + +void send_keyb_event_ipc(KeyboardEvent kevent){ + +} + + + +KeyboardEvent get_keyboard_event(){ + /* + li64(r1, 5); + li64(r2, 0x64); + eca(); + */ + + return (KeyboardEvent) { + .kstate = KeyUp, + .key = 'c' + }; + +} + +typedef enum { + ScanCodeSet1 = 0x43, + ScanCodeSet2 = 0x41, + ScanCodeSet3 = 0x3f, + + ACK = 0xFA, + Resend = 0xFE, +} PS2Response; + +typedef enum { + GetCurrent = 0, + CommandScanCodeSet1 = 1, + CommandScanCodeSet2 = 2, + CommandScanCodeSet3 = 3, +} PS2ScancodeSet; + + +PS2Response set_led() { + return Resend; +} + +PS2Response scancode_command(PS2ScancodeSet scancode) { + return Resend; +} + +// Replacement for the PS/2 Keyboard Driver on ableOS +int main() { + Argument args = get_arguments(); + + MTRand a = mersenne_twister_seed_rand(10); + f64 ac = mt_generate_f64_0_to_1(&a); + printf("%f\n\r", ac); + + int b = string_eq(args.value, from_c_str("x86-64")); + if (b == 1) { + info("running on X86"); + } else { + error("This driver cannot run on non-x86_64 machines"); + // terminate_process(); + } + + info("abc"); + bool running = false; + while (running) { + // check incoming buffer for keyb settings changes + bool changes = false; + // if they exist apply changes + if (changes) { + set_led(); + } + // check keyb state + get_keyboard_event(); + // push keyb state to a buffer + } + + create_process(); + + + return 0; +}; + diff --git a/src/main.c b/src/main.c index e05ce41..f5e5759 100644 --- a/src/main.c +++ b/src/main.c @@ -1,97 +1,9 @@ #include #include "ableos_std/ableos_std.c" -typedef enum { - // KeyUp is the default state - KeyUp = 0, - KeyDown = 0x43, -} KeyState; - -typedef struct { - KeyState kstate; - // TODO: https://github.com/rust-windowing/winit/issues/2995 - char key; -} KeyboardEvent; - - -void send_keyb_event_ipc(KeyboardEvent kevent){ - -} - - - -KeyboardEvent get_keyboard_event(){ - /* - li64(r1, 5); - li64(r2, 0x64); - eca(); - */ - - return (KeyboardEvent) { - .kstate = KeyUp, - .key = 'c' - }; - -} - -typedef enum { - ScanCodeSet1 = 0x43, - ScanCodeSet2 = 0x41, - ScanCodeSet3 = 0x3f, - - ACK = 0xFA, - Resend = 0xFE, -} PS2Response; - -typedef enum { - GetCurrent = 0, - CommandScanCodeSet1 = 1, - CommandScanCodeSet2 = 2, - CommandScanCodeSet3 = 3, -} PS2ScancodeSet; - - -PS2Response set_led() { - return Resend; -} - -PS2Response scancode_command(PS2ScancodeSet scancode) { - return Resend; -} - -// Replacement for the PS/2 Keyboard Driver on ableOS int main() { - Argument args = get_arguments(); - - MTRand a = mersenne_twister_seed_rand(10); - f64 ac = mt_generate_f64_0_to_1(&a); - printf("%f\n\r", ac); - - int b = string_eq(args.value, from_c_str("x86-64")); - if (b == 1) { - info("running on X86"); - } else { - error("This driver cannot run on non-x86_64 machines"); - // terminate_process(); - } - - info("abc"); - bool running = false; - while (running) { - // check incoming buffer for keyb settings changes - bool changes = false; - // if they exist apply changes - if (changes) { - set_led(); - } - // check keyb state - get_keyboard_event(); - // push keyb state to a buffer - } - - create_process(); - - - return 0; -}; + register_exit_code(ecode_new("File System Error")); + return 1; +} +#include "ableos_std/start.c"