init commit
This commit is contained in:
commit
6761cc0718
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
build/*
|
7
shell.nix
Normal file
7
shell.nix
Normal file
|
@ -0,0 +1,7 @@
|
|||
{ pkgs ? import <nixpkgs> { } }:
|
||||
pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs.buildPackages; [
|
||||
gnumake
|
||||
libunwind
|
||||
];
|
||||
}
|
15
src/ableos_std/ableos_std.c
Normal file
15
src/ableos_std/ableos_std.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include "types/bool.h"
|
||||
#include "types/int.h"
|
||||
|
||||
#include "types/string/string.h"
|
||||
#include "types/string/string.c"
|
||||
|
||||
#include "types/sys_id.h"
|
||||
#include "types/services.h"
|
||||
|
||||
#include "ecalls.c"
|
||||
|
||||
#include "services/log.c"
|
||||
|
||||
#include "arguments.c"
|
||||
#include "process.c"
|
13
src/ableos_std/arguments.c
Normal file
13
src/ableos_std/arguments.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
typedef struct {
|
||||
String key;
|
||||
String value;
|
||||
} Argument;
|
||||
|
||||
Argument get_arguments() {
|
||||
Argument args[0];
|
||||
|
||||
return (Argument) {
|
||||
.key = from_c_str("arch"),
|
||||
.value = from_c_str("x86-64")
|
||||
};
|
||||
}
|
12
src/ableos_std/ecalls.c
Normal file
12
src/ableos_std/ecalls.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
void ipc_send(BufferID buffer_id, const char* ptr, unsigned int length){
|
||||
// TODO: reach out to Erin and see about embedding HBASM
|
||||
}
|
||||
|
||||
void ipc_recv(BufferID buffer_id){
|
||||
// TODO: reach out to Erin and see about embedding HBASM
|
||||
}
|
||||
|
||||
// BufferID ipc_make_buffer(){
|
||||
// // TODO: Formalize the method of specifying a buffer protocol
|
||||
// // TODO: reach out to Erin and see about embedding HBASM
|
||||
// }
|
36
src/ableos_std/process.c
Normal file
36
src/ableos_std/process.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
|
||||
|
||||
typedef enum {
|
||||
Success,
|
||||
NoPermission,
|
||||
NoProcess,
|
||||
|
||||
AlreadyRunning,
|
||||
} ProcessResponse;
|
||||
|
||||
ProcessID new_id(u64 host, u64 local) {
|
||||
|
||||
return (ProcessID) {
|
||||
.host = host,
|
||||
.local = local
|
||||
};
|
||||
}
|
||||
// Kill a process
|
||||
ProcessResponse terminate_process(ProcessID pid) {
|
||||
return NoPermission;
|
||||
}
|
||||
|
||||
// Request the kernel to create a new empty process
|
||||
// A process is not started as soon as it is created
|
||||
// This gives the starting process time to set it up
|
||||
ProcessID create_process() {
|
||||
trace("New process created");
|
||||
return new_id(0,0);
|
||||
}
|
||||
|
||||
// Start execution of a created process
|
||||
ProcessResponse start_process(ProcessID pid) {
|
||||
trace("process started");
|
||||
|
||||
return AlreadyRunning;
|
||||
}
|
3
src/ableos_std/services/discovery_service.c
Normal file
3
src/ableos_std/services/discovery_service.c
Normal file
|
@ -0,0 +1,3 @@
|
|||
Services locate_services() {
|
||||
|
||||
}
|
1
src/ableos_std/services/doc.md
Normal file
1
src/ableos_std/services/doc.md
Normal file
|
@ -0,0 +1 @@
|
|||
A folder for implementations of interacting with system or kernel provided services
|
41
src/ableos_std/services/log.c
Normal file
41
src/ableos_std/services/log.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Log Levels
|
||||
typedef enum {
|
||||
ERROR = 0,
|
||||
WARN = 1,
|
||||
INFO = 2,
|
||||
DEBUG = 3,
|
||||
TRACE = 4,
|
||||
} Level;
|
||||
|
||||
// An inner log function
|
||||
// Call into the IPC log service from here
|
||||
void inner_log(Level level, const char* message, const char* file, int line) {
|
||||
const char* lvl_str = "";
|
||||
switch (level) {
|
||||
case ERROR:
|
||||
lvl_str = "ERROR";
|
||||
break;
|
||||
case WARN:
|
||||
lvl_str = "WARN";
|
||||
break;
|
||||
case INFO:
|
||||
lvl_str = "INFO";
|
||||
break;
|
||||
case DEBUG:
|
||||
lvl_str = "DEBUG";
|
||||
break;
|
||||
case TRACE:
|
||||
lvl_str = "TRACE";
|
||||
break;
|
||||
}
|
||||
BufferID log_buffer = construct_buffer_id(0, 1);
|
||||
ipc_send(log_buffer, message, c_str_len(message));
|
||||
|
||||
printf("%s [%s:%d]: %s\r\n", lvl_str, file, line, message);
|
||||
}
|
||||
|
||||
#define error(MSG) inner_log(0, (MSG), __FILE__, __LINE__)
|
||||
#define warn(MSG) inner_log(1, (MSG), __FILE__, __LINE__)
|
||||
#define info(MSG) inner_log(2, (MSG), __FILE__, __LINE__)
|
||||
#define debug(MSG) inner_log(3, (MSG), __FILE__, __LINE__)
|
||||
#define trace(MSG) inner_log(4, (MSG), __FILE__, __LINE__)
|
7
src/ableos_std/types/bool.h
Normal file
7
src/ableos_std/types/bool.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
typedef int bool;
|
||||
|
||||
#define True 1
|
||||
#define true True
|
||||
|
||||
#define False 0
|
||||
#define false False
|
9
src/ableos_std/types/int.h
Normal file
9
src/ableos_std/types/int.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned long long u64;
|
||||
|
||||
typedef char i8;
|
||||
typedef short i16;
|
||||
typedef int i32;
|
||||
typedef long long i64;
|
10
src/ableos_std/types/services.h
Normal file
10
src/ableos_std/types/services.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
typedef struct {
|
||||
|
||||
} Protocol;
|
||||
|
||||
typedef struct {
|
||||
Protocol protocol;
|
||||
BufferID buffer;
|
||||
} Service;
|
||||
|
||||
typedef Service Services[];
|
30
src/ableos_std/types/string/string.c
Normal file
30
src/ableos_std/types/string/string.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
|
||||
|
||||
inline static u32 c_str_len(char const* ptr) {
|
||||
if (ptr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
u32 len = 0;
|
||||
while (*ptr != '\0') {
|
||||
++ptr;
|
||||
++len;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
String from_c_str(char* ptr) {
|
||||
return (String) {
|
||||
.ptr = ptr,
|
||||
.len = c_str_len(ptr)
|
||||
};
|
||||
}
|
||||
|
||||
bool string_eq(String lhs, String rhs) {
|
||||
if (lhs.ptr == rhs.ptr) {
|
||||
if (lhs.len == rhs.len) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
4
src/ableos_std/types/string/string.h
Normal file
4
src/ableos_std/types/string/string.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
typedef struct {
|
||||
char* ptr;
|
||||
u32 len;
|
||||
} String;
|
23
src/ableos_std/types/sys_id.h
Normal file
23
src/ableos_std/types/sys_id.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
// All System Resource IDs are declared here
|
||||
// as well as compound IDs
|
||||
|
||||
#define HostID u64
|
||||
#define LocalID u64
|
||||
|
||||
typedef struct {
|
||||
HostID host;
|
||||
LocalID local;
|
||||
} ProcessID;
|
||||
|
||||
typedef struct {
|
||||
HostID host_id;
|
||||
LocalID local_id;
|
||||
} BufferID;
|
||||
BufferID construct_buffer_id(HostID host_id, LocalID local_id){
|
||||
return (BufferID) {
|
||||
.host_id = host_id,
|
||||
.local_id = local_id
|
||||
};
|
||||
}
|
||||
|
||||
|
94
src/main.c
Normal file
94
src/main.c
Normal file
|
@ -0,0 +1,94 @@
|
|||
#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();
|
||||
|
||||
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;
|
||||
};
|
||||
|
Loading…
Reference in a new issue