exit codes
This commit is contained in:
parent
bc933dcafd
commit
9f168af022
2
build.sh
2
build.sh
|
@ -1 +1 @@
|
|||
clang src/main.c -o build/main
|
||||
clang -nostartfiles src/main.c -o build/main
|
|
@ -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"
|
||||
#include "exit.h"
|
||||
|
||||
|
||||
#include "collections/vec.c"
|
38
src/ableos_std/collections/vec.c
Normal file
38
src/ableos_std/collections/vec.c
Normal file
|
@ -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){}
|
27
src/ableos_std/exit.h
Normal file
27
src/ableos_std/exit.h
Normal file
|
@ -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;
|
||||
}
|
13
src/ableos_std/math.h
Normal file
13
src/ableos_std/math.h
Normal file
|
@ -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;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
typedef enum {
|
||||
Success,
|
||||
ProcessSuccess,
|
||||
NoPermission,
|
||||
NoProcess,
|
||||
|
||||
|
|
|
@ -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);
|
26
src/ableos_std/services/memory_service.c
Normal file
26
src/ableos_std/services/memory_service.c
Normal file
|
@ -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;
|
||||
}
|
15
src/ableos_std/start.c
Normal file
15
src/ableos_std/start.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <stdlib.h>
|
||||
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);
|
||||
}
|
97
src/keyb.c
Normal file
97
src/keyb.c
Normal file
|
@ -0,0 +1,97 @@
|
|||
#include <stdio.h>
|
||||
#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;
|
||||
};
|
||||
|
94
src/main.c
94
src/main.c
|
@ -1,97 +1,9 @@
|
|||
#include <stdio.h>
|
||||
#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();
|
||||
register_exit_code(ecode_new("File System Error"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
#include "ableos_std/start.c"
|
||||
|
|
Loading…
Reference in a new issue