diff options
author | Benji Dial <benji@benjidial.net> | 2024-05-18 21:53:38 -0400 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-05-18 21:53:38 -0400 |
commit | b1a912a8a6ff472a49b2e0a09cfd433adfc2cb24 (patch) | |
tree | 5009d4415ba13e4baa37f3d0271852528130fd3b /euler/include | |
parent | a8a80d326de9550b2a25b1255a2093ab43219ede (diff) | |
download | hilbert-os-b1a912a8a6ff472a49b2e0a09cfd433adfc2cb24.tar.gz |
reorganization, cross compiler
Diffstat (limited to 'euler/include')
-rw-r--r-- | euler/include/cstdio | 15 | ||||
-rw-r--r-- | euler/include/cstring | 8 | ||||
-rw-r--r-- | euler/include/euler/heap.hpp | 8 | ||||
-rw-r--r-- | euler/include/euler/stream.hpp | 48 | ||||
-rw-r--r-- | euler/include/euler/syscall.hpp | 61 |
5 files changed, 140 insertions, 0 deletions
diff --git a/euler/include/cstdio b/euler/include/cstdio new file mode 100644 index 0000000..27073db --- /dev/null +++ b/euler/include/cstdio @@ -0,0 +1,15 @@ +#pragma once + +#include <euler/stream.hpp> +#include <stddef.h> + +namespace std { + + typedef euler::stream FILE; + + FILE *fopen(const char *filename, const char *mode); + int fclose(FILE *stream); + + size_t fread(void *buffer, size_t size, size_t count, FILE *stream); + +} diff --git a/euler/include/cstring b/euler/include/cstring new file mode 100644 index 0000000..45bc94e --- /dev/null +++ b/euler/include/cstring @@ -0,0 +1,8 @@ +#pragma once + +#include <stddef.h> + +namespace std { + size_t strlen(const char *str); + void *memcpy(void *dest, const void *src, size_t count); +} diff --git a/euler/include/euler/heap.hpp b/euler/include/euler/heap.hpp new file mode 100644 index 0000000..e2a4852 --- /dev/null +++ b/euler/include/euler/heap.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include <stdint.h> + +namespace euler { + void *alloc(uint64_t bytes); + void dealloc(void *start, uint64_t bytes); +} diff --git a/euler/include/euler/stream.hpp b/euler/include/euler/stream.hpp new file mode 100644 index 0000000..a364ec4 --- /dev/null +++ b/euler/include/euler/stream.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include <euler/syscall.hpp> + +namespace euler { + + class stream { + + public: + virtual ~stream(); + virtual bool try_read(void *into, uint64_t bytes) = 0; + virtual bool try_seek(__euler_seek_from from, int64_t offset) = 0; + + }; + + class file_stream : public stream { + + private: + + __euler_stream_handle handle; + bool is_readable; + bool is_writable; + uint64_t length; + uint64_t offset; + + uint8_t *buffer; + uint64_t buffer_offset; + uint64_t buffer_size; + bool buffer_dirty; + + void write_buffer(); + + public: + + bool good; + + file_stream( + __euler_stream_handle handle, bool is_readable, bool is_writable, + bool clear, bool seek_to_end); + + ~file_stream(); + + bool try_read(void *into, uint64_t bytes) override; + bool try_seek(__euler_seek_from from, int64_t offset) override; + + }; + +} diff --git a/euler/include/euler/syscall.hpp b/euler/include/euler/syscall.hpp new file mode 100644 index 0000000..9255642 --- /dev/null +++ b/euler/include/euler/syscall.hpp @@ -0,0 +1,61 @@ +#pragma once + +#include <stdint.h> + +enum __euler_stream_result : uint64_t { + __EULER_SR_SUCCESS = 0, + __EULER_SR_BAD_HANDLE, + __EULER_SR_IO_ERROR, + __EULER_SR_OUT_OF_BOUNDS, + __EULER_SR_DOES_NOT_EXIST, + __EULER_SR_NOT_A_REGULAR_FILE, + __EULER_SR_NOT_AN_EXECUTABLE, + __EULER_SR_NOT_WRITABLE, + __EULER_SR_NOT_SEEKABLE, + __EULER_SR_SOCKET_ID_ALREADY_IN_USE, + __EULER_SR_SOCKET_ID_NOT_IN_USE, + __EULER_SR_SOCKET_LISTENER_CLOSED, + __EULER_SR_OTHER_END_CLOSED, + __EULER_SR_ALREADY_EXISTS, + __EULER_SR_NOT_SIZED +}; + +enum __euler_seek_from : uint8_t { + __EULER_SF_BEGINNING = 0, + __EULER_SF_END, + __EULER_SF_CURRENT_POSITION +}; + +typedef uint64_t __euler_stream_handle; + +extern "C" __euler_stream_result __euler_open_file( + const char *path, uint64_t path_len, __euler_stream_handle &handle_out, + bool allow_creation, bool only_allow_creation); + +extern "C" [[noreturn]] void __euler_end_this_thread(int32_t exit_code); + +extern "C" __euler_stream_result __euler_seek_stream( + __euler_stream_handle handle, __euler_seek_from from, int64_t offset); + +extern "C" __euler_stream_result __euler_set_stream_length( + __euler_stream_handle handle, uint64_t new_length); + +extern "C" void __euler_close_stream(__euler_stream_handle handle); + +extern "C" __euler_stream_result __euler_get_stream_length( + __euler_stream_handle handle, uint64_t &length_out); + +extern "C" void *__euler_get_new_pages(uint64_t count); + +extern "C" __euler_stream_result __euler_write_to_stream( + __euler_stream_handle handle, uint64_t count, const void *buffer); + +extern "C" __euler_stream_result __euler_read_from_stream( + __euler_stream_handle handle, uint64_t count, void *buffer); + +extern "C" uint32_t *__euler_get_framebuffer( + uint32_t &width_out, uint32_t &height_out, uint32_t &pitch_out); + +extern "C" uint32_t __euler_encode_color(uint8_t r, uint8_t g, uint8_t b); + +extern "C" uint32_t __euler_read_key_packet(); |