Skip to content

Commit

Permalink
Merge pull request #11 from 0Nera/feature
Browse files Browse the repository at this point in the history
Изменение API
  • Loading branch information
0Nera authored Sep 16, 2024
2 parents d845778 + 03742e3 commit ae0c7db
Show file tree
Hide file tree
Showing 40 changed files with 399 additions and 456 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: install limine
run: |
git clone https://git.synapseos.ru/Aren/limine.git --branch=v5.x-branch-binary --depth=1
git clone https://git.synapseos.ru/mirrors/limine.git --branch=v5.x-branch-binary --depth=1
cd limine && make && cd ..
- name: build
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

- name: install limine
run: |
git clone https://git.synapseos.ru/Aren/limine.git --branch=v5.x-branch-binary --depth=1
git clone https://git.synapseos.ru/mirrors/limine.git --branch=v5.x-branch-binary --depth=1
cd limine && make && cd ..
- name: build
Expand Down Expand Up @@ -64,7 +64,6 @@ jobs:
draft: true
files: |
${{ github.workspace }}/rel/kernel.elf
${{ github.workspace }}/rel/bmosp.hdd
${{ github.workspace }}/rel/bmosp.iso
${{ github.workspace }}/rel/LICENSE
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ limine/
ovmf/
iso_root/
output/
sdk/
_sdk/
sdk*/
*.so
*.o
*.ko
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

dos2unix *.sh

python3 scripts/pbuild.py

cd modlib/lib/
dos2unix build.sh
chmod +x build.sh
Expand All @@ -22,5 +24,3 @@ for dir in */; do
done

cd ..

python3 scripts/pbuild.py
3 changes: 0 additions & 3 deletions configs/limine.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ TERM_WALLPAPER=boot:///mod/boot.jpg
MODULE_PATH=boot:///mod/pci_vendors.txt
MODULE_CMDLINE=[PCI][DATA][VENDORS]

MODULE_PATH=boot:///mod/simd.ko
MODULE_CMDLINE=[MOD]simd.ko

MODULE_PATH=boot:///mod/pci_data.ko
MODULE_CMDLINE=[MOD]pci_data.ko

Expand Down
24 changes: 22 additions & 2 deletions include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void arch_init( );
void task_init( );
void task_after_init( );
void task_switch( );
uint64_t task_new_thread(void (*func)(void *), char *name);
uint64_t task_new_thread(void (*func)(void *), char *name, void *arg);
void task_del_current( );
void task_del(uint64_t id);
void cpu_init( );
Expand All @@ -77,7 +77,7 @@ void idt_set_int(uint8_t vector, int_entry_t handler);
uint64_t arch_get_tick_b( );
uint64_t arch_get_tick_l( );
uint64_t arch_get_tick( );
void com_write_byte(uint8_t byte);
void com_write_byte(char byte);
void com_write_bytes(char *c, uint64_t n);
time_t rtc_get_time( );

Expand Down Expand Up @@ -105,6 +105,26 @@ static inline void io_wait( ) {
outb(0x80, 0);
}

static inline void *hal_memset(void *s, char c, int64_t count) {
int64_t d0, d1;
asm volatile("rep\n\t"
"stosb"
: "=&c"(d0), "=&D"(d1)
: "a"(c), "1"(s), "0"(count)
: "memory");
return s;
}

static inline void *hal_memset_32(void *s, uint32_t c, int64_t count) {
int64_t d0, d1;
asm volatile("rep\n\t"
"stosl"
: "=&c"(d0), "=&D"(d1)
: "a"(c), "1"(s), "0"(count)
: "memory");
return s;
}

#define GET_TICK_BIG arch_get_tick_b( )
#define GET_TICK_lOW arch_get_tick_l( )

Expand Down
1 change: 1 addition & 0 deletions include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
void log_init( );
void log_init_mem( );
void log_printf(char *str, ...);
char *utf8cp(char *str);

#ifndef NO_DEBUG
#define LOG(...) \
Expand Down
18 changes: 18 additions & 0 deletions include/mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@
#define ELFMAG3 'F'
#define SHT_SYMTAB 2

#define STT_NOTYPE 0 // Тип символа не указан
#define STT_OBJECT 1 // Символ является объектом данных
#define STT_FUNC 2 // Символ является объектом кода
#define STT_SECTION 3 // Символ связан с разделом
#define STT_FILE 4 // Имя символа является именем файла
#define STT_COMMON 5 // Символ является общим объектом данных
#define STT_TLS 6 // Символ является объектом данных локального потока
#define STT_NUM 7 // Количество определенных типов.
#define STT_GNU_IFUNC 10 // Символ является объектом непрямого кода

#define ELF32_ST_BIND(val) (((unsigned char)(val)) >> 4)
#define ELF32_ST_TYPE(val) ((val)&0xf)
#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type)&0xf))

#define ELF64_ST_BIND(val) ELF32_ST_BIND(val)
#define ELF64_ST_TYPE(val) ELF32_ST_TYPE(val)
#define ELF64_ST_INFO(bind, type) ELF32_ST_INFO((bind), (type))

typedef uint64_t elf64_addr_t; // Адрес
typedef uint64_t elf64_offset_t; // Смещение
typedef uint64_t elf64_xword_t; // Целочисленное длинное слово без знака
Expand Down
4 changes: 3 additions & 1 deletion include/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef struct {
void *irq_handler; // Адрес обработчика прерываний
void *(*get_func)(uint64_t id);
void (*after_init)( );
void *env; // env_t
} __attribute__((packed)) module_info_t;

typedef struct {
Expand All @@ -76,9 +77,10 @@ typedef struct {
sys_info_t *(*get_info)( );
module_info_t *(*get_module)(char *module_id);
module_info_t *(*mod_list_get)(uint64_t *count);
uint64_t (*new_thread)(void (*func)(void *), char *name);
uint64_t (*new_thread)(void (*func)(void *), char *name, void *arg);
void (*delete_thread)( );
time_t (*get_time)( );
module_info_t *ret;
} __attribute__((packed)) env_t;

env_t *sys_install(env_t *module);
Expand Down
2 changes: 2 additions & 0 deletions include/tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ static inline void pause( ) {

void tool_memcpy(void *dest, void *src, uint64_t n);
void *tool_memset(void *ptr, uint8_t n, uint64_t size);
void tool_memmove(void *dest, void *src, uint64_t n);
uint64_t tool_strlen(const char *str);
void tool_strcpy(char *dest, char *src);
int tool_strcmp(const char *s1, const char *s2);
uint64_t tool_starts_with(const char *str, const char *prefix);
uint64_t tool_str_contains(const char *str, const char *substr);
void tool_format(void (*putc)(char c), const char *format_string, va_list args);
Expand Down
2 changes: 1 addition & 1 deletion include/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_BUILD 58
#define VERSION_BUILD 162
2 changes: 1 addition & 1 deletion kernel/cpu/com.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static inline int com_is_transmit_empty(uint16_t com) {
return inb(com + 5) & 0x20;
}

void com_write_byte(uint8_t byte) {
void com_write_byte(char byte) {
while (!com_is_transmit_empty(0x3F8)) {}

outb(0x3F8, byte);
Expand Down
18 changes: 18 additions & 0 deletions kernel/cpu/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <tool.h>

static bool acpi_msrs_support = false;
static char fxsave_region[512] __attribute__((aligned(16)));

static void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) {
asm volatile("cpuid" : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) : "a"(leaf));
Expand Down Expand Up @@ -142,4 +143,21 @@ void cpu_init( ) {
if ((edx >> 5) & 1) { LOG("Программный терморегулятор (STC) поддерживается!\n"); }

brandname( );

cpuid(1, &eax, &ebx, &ecx, &edx);

if ((edx >> 0) & 1) {
asm volatile("finit");
LOG("FPU(x87) поддерживается!\n");
}

if ((edx >> 25) & 1) {
LOG("SSE2 поддерживается!\n");
LOG("Адрес региона fxsave 0x%x\n", &fxsave_region);
asm volatile(" fxsave %0 " ::"m"(fxsave_region));
uint32_t sse_version = (ecx >> 25) & 0x7;
LOG("SSE%u включен\n", sse_version);
}

if ((ecx >> 28) & 1) { LOG("AVX поддерживается!\n"); }
}
5 changes: 4 additions & 1 deletion kernel/cpu/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void task_switch( ) {
task_switch_asm(last, next);
}

uint64_t task_new_thread(void (*func)(void *), char *name) {
uint64_t task_new_thread(void (*func)(void *), char *name, void *arg) {
LOG("Выделение потока\n");

uint64_t cr3;
Expand All @@ -64,6 +64,7 @@ uint64_t task_new_thread(void (*func)(void *), char *name) {
stack[--stack_top] = (uint64_t)0;

new_task->rsp = (uint64_t)new_task->stack + sizeof(uint64_t) * stack_top;
new_task->rdi = (uint64_t)arg;
new_task->cpu_time = 500;
new_task->cpu_time_expired = new_task->cpu_time;
new_task->id = next_thread_id++;
Expand Down Expand Up @@ -120,9 +121,11 @@ void task_del_current( ) {
prev->next = next;
next->last = prev;

LOG("Очистка потока ID: %u, %s\n", current_task->id, current_task->id_str);
mem_free(current_task->stack);
mem_free(current_task);

LOG("Смена ID: %u, %s\n", next->id, next->id_str);
current_task = next;
if (full_init) { task_switch( ); }
}
Expand Down
65 changes: 57 additions & 8 deletions kernel/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <mod.h>
#include <stdint.h>
#include <tool.h>

elf64_header_t *elf64_get_header(void *data) {
return (elf64_header_t *)(data);
Expand Down Expand Up @@ -52,7 +53,7 @@ unsigned long elf64_hash(unsigned char *name) {
while (*name) {
h = (h << 4) + *name++;
// Проверка на overflow
if (g = h & 0xf0000000) h ^= g >> 24;
if (g = (h & 0xf0000000)) h ^= g >> 24;
// Ограничение хэша
h &= 0xffffffff;
}
Expand All @@ -70,22 +71,28 @@ void *elf_entry(void *module_bin) {
LOG("\t\tОшибка! Модуль неправильно собран!\n");
for (;;) { asm volatile("pause"); }
}
elf_parse((elf64_header_t *)module_bin);
void *h = elf_parse((elf64_header_t *)module_bin);

if (h == NULL) { return NULL; }

// Возвращаем указатель на точку входа
return (void *)((uint64_t)elf_header->e_entry + (uint64_t)module_bin);
return (void *)((uint64_t)h + (uint64_t)module_bin);
}

void import_test( ) {
LOG("123");
}

void *elf_parse(elf64_header_t *head) {
elf64_section_header_t *symtab = NULL;
// elf64_section_header_t *symtab = NULL;

if (head->e_ident[0] != ELFMAG0 || head->e_ident[1] != ELFMAG1 || head->e_ident[2] != ELFMAG2 ||
head->e_ident[3] != ELFMAG3) {
LOG("Ошибка: Неправильный формат!\n");
return -1;
return NULL;
}

LOG("Точка входа: 0x%x\n", head->e_entry);
// LOG("Точка входа: 0x%x\n", head->e_entry);

elf64_section_header_t *symtab_section = NULL;
char *string_table = NULL;
Expand All @@ -100,17 +107,59 @@ void *elf_parse(elf64_header_t *head) {
}

if (symtab_section && string_table) {
#ifdef DEBUG_ELF
LOG("\nТаблица символов:\n");
LOG("%s %s %s %s\n", "Индекс", "Значение", "Размер", "Наименование");
#endif

int num_symbols = symtab_section->sh_size / symtab_section->sh_entsize;
for (int i = 0; i < num_symbols; i++) {
elf64_sym_t *sym = elf64_get_symval(head, symtab_section - elf64_sheader(head), i);
if (sym) { LOG("%6u %8x %6x %s\n", i, sym->st_value, sym->st_size, string_table + sym->st_name); }
if (sym) {
#ifdef DEBUG_ELF
LOG("%6u %8x %6x %18s ", i, sym->st_value, sym->st_size, string_table + sym->st_name);
#endif
switch (ELF64_ST_TYPE(sym->st_info)) {
case STT_NOTYPE:

#ifdef DEBUG_ELF
log_printf("без типа\n");
#endif
break;
case STT_OBJECT:
#ifdef DEBUG_ELF
log_printf("объект данных\n");
#endif
if (!(string_table + sym->st_name)) { break; }
// log_printf("%u\n", tool_strcmp(string_table + sym->st_name, "import_test"));
if (tool_strcmp(string_table + sym->st_name, "import_test") == 0) {
#ifdef DEBUG_ELF
log_printf("0x%x\n", head + sym->st_value);
#endif
// void (*imp)( ) = (void *)head + sym->st_value;
// imp = &import_test;
}
break;
#ifdef DEBUG_ELF
case STT_FUNC: log_printf("объект кода\n"); break;
case STT_SECTION: log_printf("символ раздела\n"); break;
case STT_FILE: log_printf("имя файла\n"); break;
case STT_COMMON: log_printf("общий объект данных\n"); break;
case STT_TLS: log_printf("объект данных локального потока\n"); break;
case STT_NUM: log_printf("количество определенных типов\n"); break;
case STT_GNU_IFUNC: log_printf("объект непрямого кода\n"); break;
#endif
default:
#ifdef DEBUG_ELF
log_printf("???\n");
#endif
break;
}
}
}
} else {
LOG("Таблица символов не найдена!\n");
}

return (void *)0;
return (void *)head->e_entry;
}
7 changes: 4 additions & 3 deletions kernel/fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ void fb_init( ) {

for (uint64_t i = 0; i < width * height; i++) { fb_addr[i] = background; }

LOG("0x%x %ux%u\n", fb_addr, width, height);

if (framebuffer_response->framebuffer_count == 1) { return; }

#ifdef DEBUG_FB
LOG("Инициализация дополнительных: %u мониторов\n", framebuffer_response->framebuffer_count);

#endif
for (uint64_t i = 1; i < framebuffer_response->framebuffer_count; i++) {
struct limine_framebuffer *framebuffer = framebuffer_response->framebuffers[i];
uint32_t *framebuffer_addr = (uint32_t *)framebuffer->address;
#ifdef DEBUG_FB
LOG("[%u]->0x%x %ux%u\n", i, framebuffer->address, framebuffer->width, framebuffer->height);
#endif
for (uint64_t ij = 0; ij < width * height; ij++) { framebuffer_addr[ij] = background; }
}
}
Expand Down
Loading

0 comments on commit ae0c7db

Please sign in to comment.