Skip to content

Commit

Permalink
Сборка модулей
Browse files Browse the repository at this point in the history
  • Loading branch information
Aren committed Oct 13, 2023
1 parent 3861e4b commit d6b3ab1
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ ovmf/
iso_root/
modules/helloworld/helloworld.elf
modules/com/com.elf
modules/helloworld/hello.o
modules/helloworld/hello.so
5 changes: 3 additions & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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/"])
Expand Down Expand Up @@ -162,5 +162,6 @@ def create_iso(IMAGE_NAME):
compile_all()
create_iso("bmosp")
create_hdd("bmosp")
os.system("cd modules/helloworld/ && ./build.sh")

print(f"Не забудьте сохранить изменения! Номер сборки: {major}.{minor}, {build}")
Empty file modified build.sh
100644 → 100755
Empty file.
11 changes: 4 additions & 7 deletions configs/limine.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Empty file modified deploy_to_sdc.sh
100644 → 100755
Empty file.
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 1
#define VERSION_BUILD 17
#define VERSION_BUILD 22
58 changes: 57 additions & 1 deletion kernel/mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 changes: 6 additions & 0 deletions modules/helloworld/build.sh
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions modules/helloworld/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


extern "C" int _start( ) {
return 80;
}
2 changes: 1 addition & 1 deletion run.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d6b3ab1

Please sign in to comment.