Сборка модулей

This commit is contained in:
Aren 2023-10-13 17:44:35 +03:00
parent 3861e4b8c1
commit d6b3ab1186
10 changed files with 79 additions and 12 deletions

2
.gitignore vendored
View File

@ -9,3 +9,5 @@ ovmf/
iso_root/
modules/helloworld/helloworld.elf
modules/com/com.elf
modules/helloworld/hello.o
modules/helloworld/hello.so

View File

@ -115,7 +115,7 @@ def create_hdd(IMAGE_NAME):
subprocess.run(["mcopy", "-i", IMAGE_NAME+".hdd@@1M",
"kernel.elf", "configs/limine.cfg", "limine/limine-bios.sys", "::/"])
subprocess.run(["mcopy", "-i", IMAGE_NAME+".hdd@@1M",
"modules/com/com.elf", "modules/helloworld/helloworld.elf", "::/mod"])
"modules/com/com.elf", "modules/helloworld/hello.so", "::/mod"])
subprocess.run(["mcopy", "-i", IMAGE_NAME+".hdd@@1M",
"limine/BOOTX64.EFI", "limine/BOOTIA32.EFI", "::/EFI/BOOT"])
subprocess.run(["mcopy", "-i", IMAGE_NAME+".hdd@@1M",
@ -134,7 +134,7 @@ def create_iso(IMAGE_NAME):
"iso_root/"])
subprocess.run(["mkdir", "-p", "iso_root/EFI/BOOT"])
subprocess.run(["mkdir", "-p", "iso_root/mod"])
subprocess.run(["cp", "-v", "modules/helloworld/helloworld.elf", "iso_root/mod/"])
subprocess.run(["cp", "-v", "modules/helloworld/hello.so", "iso_root/mod/"])
subprocess.run(["cp", "-v", "modules/com/com.elf", "iso_root/mod/"])
subprocess.run(["cp", "-v", "limine/BOOTX64.EFI", "iso_root/EFI/BOOT/"])
subprocess.run(["cp", "-v", "limine/BOOTIA32.EFI", "iso_root/EFI/BOOT/"])
@ -162,5 +162,6 @@ if __name__ == "__main__":
compile_all()
create_iso("bmosp")
create_hdd("bmosp")
os.system("cd modules/helloworld/ && ./build.sh")
print(f"Не забудьте сохранить изменения! Номер сборки: {major}.{minor}, {build}")

0
build.sh Normal file → Executable file
View File

View File

@ -13,11 +13,8 @@ BACKGROUND_PATH=boot:///boot.png
KASLR=no
KERNEL_PATH=boot:///kernel.elf
MODULE_PATH=boot:///mod/helloworld.elf
MODULE_CMDLINE=helloworld
MODULE_PATH=boot:///mod/hello.so
MODULE_CMDLINE=[MOD]hello.so
MODULE_PATH=boot:///mod/com.elf
MODULE_CMDLINE=com
MODULE_PATH=boot:///boot.png
MODULE_CMDLINE=bootimage
#MODULE_PATH=boot:///boot.png
#MODULE_CMDLINE=bootimage

0
deploy_to_sdc.sh Normal file → Executable file
View File

View File

@ -1,3 +1,3 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 1
#define VERSION_BUILD 17
#define VERSION_BUILD 22

View File

@ -2,6 +2,59 @@
#include <limine.h>
#include <mod.h>
// Структуры соответствующие ELF заголовкам
typedef struct {
unsigned char e_ident[16];
uint16_t e_type;
uint16_t e_machine;
uint32_t e_version;
uint64_t e_entry;
uint64_t e_phoff;
uint64_t e_shoff;
uint32_t e_flags;
uint16_t e_ehsize;
uint16_t e_phentsize;
uint16_t e_phnum;
uint16_t e_shentsize;
uint16_t e_shnum;
uint16_t e_shstrndx;
} elf64_header_t;
void *elf_entry(void *module, uint64_t size) {
// Приводим заголовок ELF файла к типу elf64_header_t
elf64_header_t *elf_header = (elf64_header_t *)module;
// Выводим данные о заголовке ELF файла
fb::printf("ELF Header:\n");
fb::printf(" Magic number: ");
for (int i = 0; i < 16; i++) {
fb::printf("0x%x ", elf_header->e_ident[i]);
}
fb::printf("\n");
fb::printf(" Class: ELF64\n");
fb::printf(" Version: %u\n", elf_header->e_ident[6]);
fb::printf(" OS/ABI: %u\n", elf_header->e_ident[7]);
fb::printf(" Type: %u\n", elf_header->e_type);
fb::printf(" Machine: %u\n", elf_header->e_machine);
fb::printf(" Version: %u\n", elf_header->e_version);
fb::printf(" Entry point: 0x%x\n", elf_header->e_entry);
fb::printf(" Program header offset: %u\n", elf_header->e_phoff);
fb::printf(" Section header offset: %u\n", elf_header->e_shoff);
fb::printf(" Flags: %u\n", elf_header->e_flags);
fb::printf(" ELF header size: %u (bytes)\n",
elf_header->e_ehsize);
fb::printf(" Program header entry size: %u (bytes)\n",
elf_header->e_phentsize);
fb::printf(" Program header count: %u\n", elf_header->e_phnum);
fb::printf(" Section header entry size: %u (bytes)\n",
elf_header->e_shentsize);
fb::printf(" Section header count: %u\n", elf_header->e_shnum);
fb::printf(" Section header string index: %u\n", elf_header->e_shstrndx);
// Возвращаем указатель на точку входа
return (void *)elf_header->e_entry;
}
namespace mod {
static volatile struct limine_module_request module_request = {
.id = LIMINE_MODULE_REQUEST,
@ -24,9 +77,12 @@ void init( ) {
fb::printf("->Size: %u, media_type: %u, partition_index: %u\n",
module_ptr->size, module_ptr->media_type,
module_ptr->partition_index);
fb::printf("->mbr_disk_id: %u, tftp_ip: %u, tftp_port: %u\n\n",
fb::printf("->mbr_disk_id: %u, tftp_ip: %u, tftp_port: %u\n",
module_ptr->mbr_disk_id, module_ptr->tftp_ip,
module_ptr->tftp_port);
fb::printf("\t->Entry point: 0x%x\n\n",
elf_entry(module_ptr->address, module_ptr->size));
}
}
} // namespace mod

6
modules/helloworld/build.sh Executable file
View File

@ -0,0 +1,6 @@
#/bin/sh
echo "Название: Hello world"
echo "Лицензия: Публичное достояние"
g++ -c -fPIC -nostdlib main.cpp -o hello.o
gcc -shared -nostdlib hello.o -o hello.so -Wl,--entry=_start
echo "Сборка завершена, файл: hello.so"

View File

@ -0,0 +1,5 @@
extern "C" int _start( ) {
return 80;
}

2
run.sh Normal file → Executable file
View File

@ -1,2 +1,2 @@
#!/bin/sh
qemu-system-x86_64 -cpu max -m 2G -smp 1 -bios ovmf/OVMF.fd -hda mseos.hdd
qemu-system-x86_64 -cpu max -m 2G -smp 1 -bios ovmf/OVMF.fd -hda bmosp.hdd