Initial import

This commit is contained in:
Jozef Nagy 2025-01-20 21:52:47 +01:00
commit 94aad4b8e1
Signed by untrusted user who does not match committer: crz
GPG key ID: 459A4811CEAC7068
77 changed files with 4414 additions and 0 deletions

View file

@ -0,0 +1,78 @@
/*********************************************************************************/
/* Module Name: config.c */
/* 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. */
/*********************************************************************************/
#include <config/config.h>
#include <firmware/file.h>
#include <lib/string.h>
#include <print.h>
#include <axboot.h>
#include <stdint.h>
#include <stddef.h>
char *config_paths[] = {
"\\axboot.cfg",
"\\System\\axboot.cfg",
"\\EFI\\axboot.cfg",
"\\EFI\\BOOT\\axboot.cfg",
};
void config_init(void)
{
FILE *config_file;
char *config_buffer;
int filesize;
for (size_t i = 0; i < ARRAY_LENGTH(config_paths); i++) {
config_file = fw_file_open(NULL, config_paths[i]);
if (config_file != NULL) {
break;
}
}
if (config_file == NULL) {
//print("No configuration file found! Please refer to the AxBoot documentation.\n");
//print("Entering console...\n\n");
//console();
}
filesize = fw_file_size(config_file);
config_buffer = malloc(filesize);
if (config_buffer == NULL) {
log("Entering console...\r\n\r\n");
//console();
}
fw_file_read(config_file, filesize, config_buffer);
// TODO: parse configuration file
free(config_buffer);
/*
if (config_errors != 0 || config_get_menu_root() == NULL) {
//print("\nConfiguration invalid!\n");
//print("Please correct your config file.\n");
//print("Entering console...\n\n");
//console();
}
*/
fw_file_close(config_file);
}

128
boot/common/lib/string.c Normal file
View file

@ -0,0 +1,128 @@
/*********************************************************************************/
/* Module Name: string.c */
/* 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. */
/*********************************************************************************/
#include <lib/string.h>
#include <stdint.h>
#include <stddef.h>
size_t mbstowcs(wchar_t *dest, const char **src, size_t len)
{
char *lsrc = (char *)*src;
size_t count = len;
if (dest == NULL) {
return 0;
}
while (count) {
if ((*dest = *lsrc) == 0) {
lsrc = NULL;
break;
}
if (*dest >= 0x80) {
return -1;
}
lsrc++;
dest++;
count--;
}
return len - count;
}
size_t strlen(const char *str)
{
size_t count = 0;
if (str == NULL) {
return 0;
}
do {
count++;
} while (str[count] != '\0');
return count;
}
char *strcpy(char *dest, const char *src)
{
if (dest == NULL || src == NULL) {
return NULL;
}
char *pdest = dest;
while (*src != '\0') {
*dest = *src;
dest++;
src++;
}
*dest = '\0';
return pdest;
}
void *memset(void *dest, int val, size_t len)
{
unsigned char *ptr = dest;
while (len-- > 0) {
*ptr++ = (unsigned char)val;
}
return dest;
}
void *memcpy(void *dest, void *src, size_t len)
{
char *d = (char *)dest;
const char *s = (const char *)src;
while (len-- > 0) {
*d++ = *s++;
}
return dest;
}
int memcmp(const void *a, const void *b, size_t len)
{
unsigned char *ap = (unsigned char *)a;
unsigned char *bp = (unsigned char *)b;
int ret = 0;
if (a == b) {
return 0;
}
while (len > 0) {
if (*ap != *bp) {
ret = (*ap > *bp) ? 1 : -1;
break;
}
len--;
ap++;
bp++;
}
return ret;
}

64
boot/common/print.c Normal file
View file

@ -0,0 +1,64 @@
/*********************************************************************************/
/* Module Name: print.c */
/* 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. */
/*********************************************************************************/
#define NANOPRINTF_IMPLEMENTATION
#define NANOPRINTF_USE_FIELD_WIDTH_FORMAT_SPECIFIERS 1
#define NANOPRINTF_USE_PRECISION_FORMAT_SPECIFIERS 1
#define NANOPRINTF_USE_FLOAT_FORMAT_SPECIFIERS 1
#define NANOPRINTF_USE_LARGE_FORMAT_SPECIFIERS 1
#define NANOPRINTF_USE_BINARY_FORMAT_SPECIFIERS 0
#define NANOPRINTF_USE_WRITEBACK_FORMAT_SPECIFIERS 0
#include <nanoprintf.h>
#include <debug/serial.h>
#include <print.h>
#include <stddef.h>
#include <stdint.h>
#include <stdarg.h>
#include <stdbool.h>
int32_t _fltused = 0;
int32_t __eqdf2 = 0;
int32_t __ltdf2 = 0;
void log(const char *fmt, ...)
{
va_list args;
char buf[4096];
va_start(args, fmt);
npf_vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
//printstr(buf);
}
void debug(const char *fmt, ...)
{
va_list args;
char buf[4096];
va_start(args, fmt);
npf_vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
//serial_sendstr(buf);
}