did some stuff, will probably refactor later

This commit is contained in:
Jozef Nagy 2025-05-11 22:20:45 +02:00
parent 10ee4fcbd9
commit bc4ec556e2
Signed by untrusted user who does not match committer: crz
GPG key ID: 459A4811CEAC7068
46 changed files with 1013 additions and 35635 deletions

View file

@ -0,0 +1,94 @@
/*********************************************************************************/
/* Module Name: math.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _ARCH_LIB_MATH_H
#define _ARCH_LIB_MATH_H
#include <stdbool.h>
static double _sqrt(double n)
{
double out;
__asm__ volatile("fldl %[input];"
"fsqrt;"
"fstpl %[output];"
: [ output ] "=g"(out)
: [ input ] "g"(n)
:);
return out;
}
static double _cos(double n)
{
double out;
__asm__ volatile("fldl %[input];"
"fcos;"
"fstpl %[output];"
: [ output ] "=g"(out)
: [ input ] "g"(n)
:);
return out;
}
static double _acos(double n)
{
double imd = _sqrt(1 - (n * n));
double out;
__asm__ volatile("fldl %[imd];"
"fldl %[input];"
"fpatan;"
"fstpl %[output];"
: [ output ] "=g"(out)
: [ input ] "g"(n), [ imd ] "g"(imd)
:);
return out;
}
static int _ifloor(double d)
{
if ((((double)((int)d)) == d) || (d >= 0))
return (int)d;
return (int)(d - 1);
}
static int _iceil(double d)
{
if ((((double)((int)d)) == d) || (d < 0))
return (int)d;
return (int)(d + 1);
}
static double _pow(double a, int n)
{
double prod = 1;
bool neg = (n < 0);
n = neg ? -n : n;
for (int i = 0; i < n; i++)
prod = prod * a;
if (neg)
prod = 1 / prod;
return prod;
}
static double _fmod(double x, double y)
{
return x - ((int)(x / y)) * y;
}
#endif /* _ARCH_LIB_MATH_H */

View file

@ -29,6 +29,9 @@
#define UNREACHABLE() __builtin_unreachable()
#endif
// TODO: This is hacky
#define axboot_halt() while (1);
void axboot_init(void);
#endif /* _AXBOOT_H */

View file

@ -0,0 +1,42 @@
/*********************************************************************************/
/* Module Name: config.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _CONFIG_CONFIG_H
#define _CONFIG_CONFIG_H
struct axboot_cfg {
// overridable stuff
int default_entry;
int timeout;
int entry_count;
};
struct axboot_entry {
char *name;
char *description;
char *image_path;
int protocol;
};
void config_init(void);
int config_get_entry_count();
#endif /* _CONFIG_CONFIG_H */

86
boot/include/config/ini.h Normal file
View file

@ -0,0 +1,86 @@
/*********************************************************************************/
/* Module Name: ini.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _CONFIG_INI_H
#define _CONFIG_INI_H
enum token_type {
SECTION,
KEY,
VALUE,
EOF,
ILLEGAL,
};
struct string_view {
char *data;
unsigned int len;
};
struct token {
enum token_type type;
struct string_view lit;
};
struct token_array {
struct token *items;
unsigned int count;
unsigned int capacity;
};
struct lexer {
char *input;
unsigned int pos;
unsigned int read_pos;
char ch;
};
struct parser {
struct token_array *tokens;
unsigned int pos;
unsigned int read_pos;
struct token *cur_token;
};
struct key_value {
struct string_view key;
struct string_view value;
};
struct section {
struct string_view name;
struct key_value *items;
unsigned int count;
unsigned int capacity;
};
struct ini_file {
struct section root;
struct section *items;
unsigned int count;
unsigned int capacity;
};
void parse_ini(struct ini_file *ini, char *buf);
char *ini_get_value(struct ini_file *ini, char *section, char *key);
int ini_get_value_int(struct ini_file *ini, char *section, char *key);
#endif /* _CONFIG_INI_H */

41
boot/include/data/da.h Normal file
View file

@ -0,0 +1,41 @@
/*********************************************************************************/
/* Module Name: da.b */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _DATA_DA_H
#define _DATA_DA_H
#include <mm/mman.h>
#include <print.h>
#include <stddef.h>
#include <efilib.h>
#define DA_INIT_CAPACITY 8192
#define DA_REALLOC(oldptr, newsz) mem_realloc(oldptr, newsz)
#define da_append(da, item) \
do {\
if ((da)->count >= (da)->capacity) { \
size_t new_capacity = (da)->capacity + DA_INIT_CAPACITY; \
(da)->items = DA_REALLOC((da)->items, new_capacity * sizeof((da)->items[0])); \
(da)->capacity = new_capacity; \
} \
(da)->items[(da)->count++] = (item); \
} while (0)
#endif /* _DATA_DA_H */

45
boot/include/data/list.h Normal file
View file

@ -0,0 +1,45 @@
/*********************************************************************************/
/* Module Name: list.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _DATA_LIST_H
#define _DATA_LIST_H
#include <stdint.h>
typedef struct _ListNode {
void *data;
struct _ListNode *prev;
struct _ListNode *next;
} ListNode;
typedef struct _List {
uint32_t count;
ListNode *root;
} List;
List *list_new();
int list_add(List *list, void *data);
void *list_remove_at(List *list, uint32_t idx);
ListNode *listnode_new(void *data);
void *list_get_at(List *list, uint32_t idx);
#endif /* _DATA_LIST_H */

34
boot/include/lib/assert.h Normal file
View file

@ -0,0 +1,34 @@
/*********************************************************************************/
/* Module Name: assert.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _LIB_ASSERT_H
#define _LIB_ASSERT_H
#include <print.h>
#include <axboot.h>
#define assert(expr, msg) \
do { \
if (!!(expr)) { \
log("Assertion failed in file %s, line %u: %s\n", __FILE__, __LINE__, msg); \
axboot_halt(); \
} \
} while (0)
#endif /* _LIB_ASSERT_H */

View file

@ -30,6 +30,8 @@ size_t strlen(const char *str);
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
char *strcpy(char *dest, const char *src);
char *strncpy(char *dest, const char *src, size_t n);
char *strncat(char *dest, const char *src, size_t n);
char *strdup(const char *s);
char *strtok(char *str, const char *delim);
char *strchr(char *s, int c);

View file

@ -0,0 +1,36 @@
/*********************************************************************************/
/* Module Name: loader.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _LOADER_LOADER_H
#define _LOADER_LOADER_H
enum loader_protocol {
PROTO_AURIX,
#ifdef AXBOOT_UEFI
PROTO_CHAINLOAD,
#endif
PROTO_UNSUPPORTED
};
void loader_load(struct axboot_entry *entry);
int proto_str_to_int(char *proto);
#endif /* _LOADER_LOADER_H */

File diff suppressed because it is too large Load diff

View file

@ -22,7 +22,7 @@
#include <stdint.h>
void uart_init(uint16_t baud_rate);
void uart_init(uint32_t baud_rate);
void uart_send(char c);
void uart_sendstr(char *str);

25
boot/include/ui/font.h Normal file
View file

@ -0,0 +1,25 @@
/*********************************************************************************/
/* Module Name: font.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _UI_FONT_H
#define _UI_FONT_H
void font_init(char *font_path, int initial_size);
#endif /* _UI_FONT_H */

View file

@ -36,6 +36,6 @@ struct fb_mode {
int format;
};
bool get_framebuffer(uintptr_t *fb_addr, struct fb_mode **available_modes, int *total_modes, int *current_mode_index);
bool get_framebuffer(uint32_t **fb_addr, struct fb_mode **available_modes, int *total_modes, int *current_mode_index);
#endif /* _UI_FRAMEBUFFER_H */

31
boot/include/ui/mouse.h Normal file
View file

@ -0,0 +1,31 @@
/*********************************************************************************/
/* Module Name: mouse.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _UI_MOUSE_H
#define _UI_MOUSE_H
enum {
LEFT_MOUSE_BUTTON = 0x1,
MIDDLE_MOUSE_BUTTON = 0x2,
RIGHT_MOUSE_BUTTON = 0x4
};
void get_mouse(uint16_t *mouse_x, uint16_t *mouse_y, uint8_t *mouse_buttons);
#endif /* _UI_MOUSE_H */

File diff suppressed because it is too large Load diff

View file

@ -20,6 +20,17 @@
#ifndef _UI_UI_H
#define _UI_UI_H
#include <ui/framebuffer.h>
#include <stdint.h>
struct ui_context {
uint32_t *fb_addr;
struct fb_mode *fb_modes;
int total_modes;
int current_mode;
};
void ui_init();
#endif /* _UI_UI_H */