-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Модули теперь используют статичную библиотеку
- Loading branch information
Showing
16 changed files
with
368 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
#!/bin/sh | ||
|
||
cd modlib/lib/ | ||
chmod +x build.sh | ||
./build.sh | ||
cd ../.. | ||
|
||
cd modules/ | ||
mkdir -p bin | ||
dos2unix */*.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
libmod.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#/bin/sh | ||
|
||
CC="gcc" | ||
AR="ar" | ||
ARCH_FLAGS="-ffreestanding -O0 -g -fPIC -static -nostdlib " | ||
|
||
if [ -d "../../sdk" ]; then | ||
CC="../../sdk/bin/x86_64-elf-gcc" | ||
AR="../../sdk/bin/x86_64-elf-ar" | ||
fi | ||
|
||
mkdir -p bin | ||
|
||
$CC $ARCH_FLAGS -I../../modlib -finput-charset=UTF-8 -fexec-charset=cp1251 -c system.c -o bin/system.o | ||
$CC $ARCH_FLAGS -I../../modlib -finput-charset=UTF-8 -fexec-charset=cp1251 -c tool.c -o bin/tool.o | ||
$AR -rcs ../../modlib/lib/libmod.a ../../modlib/lib/bin/system.o ../../modlib/lib/bin/tool.o | ||
ranlib ../../modlib/lib/libmod.a |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* system.c | ||
* Системные вызовы модулей | ||
* | ||
* Основные функции для работы с функцияи системы | ||
* | ||
*/ | ||
|
||
#include <modstd.h> | ||
#include <system.h> | ||
|
||
void *(*alloc)(uint64_t size); | ||
void (*free)(void *ptr); | ||
void (*fb_printf)(char *str, ...); | ||
module_info_t *(*get_module)(char *module_id); | ||
framebuffer_t (*alloc_framebuffer)( ); | ||
void (*free_framebuffer)(framebuffer_t *frame); | ||
void (*exit)(int code); | ||
int (*get_error)( ); | ||
sys_info_t *(*get_info)( ); | ||
uint64_t (*new_thread)(uint64_t func); | ||
int (*delete_thread)(uint64_t thread_id); | ||
time_t (*get_time)( ); | ||
uint64_t offset; | ||
|
||
void init_env(env_t *loader_env) { | ||
offset = loader_env->offset; | ||
fb_printf = loader_env->fb_printf; | ||
alloc = loader_env->alloc; | ||
free = loader_env->free; | ||
get_module = loader_env->get_module; | ||
alloc_framebuffer = loader_env->alloc_framebuffer; | ||
free_framebuffer = loader_env->free_framebuffer; | ||
exit = loader_env->exit; | ||
get_error = loader_env->get_error; | ||
get_info = loader_env->get_info; | ||
new_thread = loader_env->new_thread; | ||
delete_thread = loader_env->delete_thread; | ||
get_time = loader_env->get_time; | ||
} | ||
|
||
void *realloc(void *addr, size_t size) { | ||
if (size == 0) { | ||
free(addr); | ||
return NULL; | ||
} | ||
|
||
if (addr == NULL) { return alloc(size); } | ||
|
||
void *new_addr = alloc(size); | ||
|
||
if (new_addr == NULL) { return NULL; } | ||
|
||
memcpy(new_addr, addr, size); | ||
free(addr); | ||
|
||
return new_addr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
/** | ||
* tool.c | ||
* Дополнительные функции | ||
* | ||
* Вспомогательные функции для работы с данными | ||
* | ||
*/ | ||
|
||
#include <modstd.h> | ||
#include <system.h> | ||
|
||
uint64_t strlen(char *str) { | ||
uint64_t length = 0; | ||
while (*str) { | ||
length++; | ||
str++; | ||
} | ||
return length; | ||
} | ||
|
||
void strcpy(char *dest, char *src) { | ||
size_t i = 0; | ||
while (src[i] != '\0') { | ||
dest[i] = src[i]; | ||
i++; | ||
} | ||
dest[i] = '\0'; // добавляем завершающий нулевой символ | ||
} | ||
|
||
size_t strspn(char *str, char *accept) { | ||
size_t count = 0; | ||
char *ptr = str; | ||
char *acc; | ||
|
||
while (*ptr) { | ||
acc = accept; | ||
while (*acc) { | ||
if (*ptr == *acc) { | ||
count++; | ||
break; | ||
} | ||
acc++; | ||
} | ||
if (*acc == '\0') break; | ||
ptr++; | ||
} | ||
|
||
return count; | ||
} | ||
|
||
size_t strcspn(char *str, char *reject) { | ||
size_t count = 0; | ||
char *ptr = str; | ||
char *r; | ||
|
||
while (*ptr) { | ||
r = reject; | ||
while (*r) { | ||
if (*ptr == *r) { return count; } | ||
r++; | ||
} | ||
count++; | ||
ptr++; | ||
} | ||
|
||
return count; | ||
} | ||
|
||
char *strtok(char *str, char *delim) { | ||
char *token = NULL; | ||
char *next_token = NULL; | ||
|
||
if (str != NULL) { | ||
token = str; | ||
} else { | ||
token = next_token; | ||
} | ||
|
||
if (token == NULL) { return NULL; } | ||
|
||
token += strspn(token, delim); | ||
|
||
if (*token == '\0') { | ||
next_token = NULL; | ||
return NULL; | ||
} | ||
|
||
next_token = token + strcspn(token, delim); | ||
|
||
if (*next_token != '\0') { | ||
*next_token = '\0'; | ||
next_token++; | ||
} else { | ||
next_token = NULL; | ||
} | ||
|
||
return token; | ||
} | ||
|
||
size_t strtol(char *str, char **endptr, int64_t base) { | ||
size_t num = 0; | ||
int64_t sign = 1; | ||
|
||
// Пропускаем пробелы в начале строки | ||
while (*str == ' ') { str++; } | ||
|
||
// Проверяем знак числа | ||
if (*str == '-') { | ||
sign = -1; | ||
str++; | ||
} else if (*str == '+') { | ||
str++; | ||
} | ||
|
||
// Проверяем основание системы счисления | ||
if (base == 0) { | ||
// Автоопределение основания | ||
if (*str == '0') { | ||
str++; | ||
if (*str == 'x' || *str == 'X') { | ||
base = 16; // Шестнадцатеричная система счисления | ||
str++; | ||
} else { | ||
base = 8; // Восьмеричная система счисления | ||
} | ||
} else { | ||
base = 10; // Десятичная система счисления | ||
} | ||
} | ||
|
||
// Преобразование строки в число | ||
while (*str != '\0') { | ||
int64_t digit; | ||
if (*str >= '0' && *str <= '9') { | ||
digit = *str - '0'; | ||
} else if (*str >= 'A' && *str <= 'Z') { | ||
digit = *str - 'A' + 10; | ||
} else if (*str >= 'a' && *str <= 'z') { | ||
digit = *str - 'a' + 10; | ||
} else { | ||
break; // Некорректный символ - прерываем преобразование | ||
} | ||
|
||
if (digit >= base) { | ||
break; // Некорректная цифра - прерываем преобразование | ||
} | ||
|
||
num = num * base + digit; | ||
str++; | ||
} | ||
|
||
if (endptr != NULL) { | ||
//*endptr = (char *)str; // Указатель на символ, следующий за числом | ||
} | ||
|
||
return num * sign; | ||
} | ||
|
||
char *strchr(char *str, char c) { | ||
// пройти по каждому символу строки | ||
while (*str != '\0') { | ||
// если символ найден, вернуть указатель на него | ||
if (*str == c) { return (char *)str; } | ||
str++; // переход к следующему символу | ||
} | ||
// символ не найден, вернуть NULL | ||
return NULL; | ||
} | ||
|
||
int strcmp(const char *s1, const char *s2) { | ||
while (*s1 == *s2) { | ||
if (*s1 == '\0') { return 0; } | ||
s1++; | ||
s2++; | ||
} | ||
return *s1 - *s2; | ||
} | ||
|
||
char *trstr(char *str, char sym) { | ||
size_t left, size = strlen(str); | ||
for (left = 0x00U; left < size; left++) | ||
if (str[left] == sym) break; | ||
|
||
size++; | ||
left++; | ||
|
||
if (left < size) | ||
size -= left; | ||
else | ||
left = 0x00U; | ||
|
||
char *res = alloc(size); | ||
memcpy(res, str + left, size); | ||
return res; | ||
} | ||
|
||
char *strdup(char *str) { | ||
size_t len = strlen(str) + 1; | ||
char *dup = alloc(len); | ||
|
||
if (dup != NULL) { memcpy(dup, str, len); } | ||
|
||
return dup; | ||
} | ||
|
||
size_t count_chars(char *str, char c) { | ||
size_t count = 0; | ||
size_t len = strlen(str); | ||
|
||
for (size_t i = 0; i < len; i++) { | ||
if (str[i] == c) { count++; } | ||
} | ||
|
||
return count; | ||
} | ||
|
||
void memcpy(void *dest, void *src, size_t n) { | ||
char *d = (char *)dest; | ||
char *s = (char *)src; | ||
|
||
for (size_t i = 0; i < n; i++) { d[i] = s[i]; } | ||
} | ||
|
||
void *memset(void *ptr, uint8_t n, size_t size) { | ||
uint8_t *p = (uint8_t *)ptr; | ||
for (size_t i = 0; i < size; i++) { p[i] = n; } | ||
return ptr; | ||
} | ||
|
||
void *memmove(void *dest, void *src, size_t n) { | ||
char *d = (char *)dest; | ||
const char *s = (const char *)src; | ||
|
||
if (d > s) { | ||
// копирование с конца массива, чтобы предотвратить перекрытие | ||
for (size_t i = n; i > 0; --i) { d[i - 1] = s[i - 1]; } | ||
} else if (d < s) { | ||
// копирование с начала массива | ||
for (size_t i = 0; i < n; ++i) { d[i] = s[i]; } | ||
} | ||
|
||
return dest; | ||
} |
Oops, something went wrong.