From c2aef230fc4004ead3969840e9cc384daccb6720 Mon Sep 17 00:00:00 2001 From: Aren Elchinyan Date: Sun, 15 Oct 2023 18:44:29 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modlib/system.h | 50 +++++++++++++++++++++++++++++++++++++ modules/helloworld/build.sh | 2 +- modules/helloworld/main.c | 22 ++++++++++++++++ modules/helloworld/main.cpp | 10 -------- 4 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 modlib/system.h create mode 100644 modules/helloworld/main.c delete mode 100644 modules/helloworld/main.cpp diff --git a/modlib/system.h b/modlib/system.h new file mode 100644 index 0000000..3a2ddf1 --- /dev/null +++ b/modlib/system.h @@ -0,0 +1,50 @@ +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; +typedef long long int64_t; + +typedef struct { + void (*fb_printf)(char *str, ...); +} env_t; + +typedef struct { + int reserved; +} framebuffer_t; + +typedef struct { + int reserved; +} sys_info_t; + +typedef struct { + char *name; + void *addr; +} module_func_t; + +typedef struct { + char *name; + char *message; + int err_code; + uint64_t func_count; + module_func_t *func[]; +} module_info_t; + +typedef struct { + int reserved; +} func_t; + +typedef struct { + uint8_t a[4]; + uint8_t b[4]; + uint8_t c[4]; + uint8_t d[4]; +} uid_t; + +typedef struct { + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t second; +} time_t; + +void (*fb_printf)(char *str, ...); \ No newline at end of file diff --git a/modules/helloworld/build.sh b/modules/helloworld/build.sh index d282b5a..73d0638 100755 --- a/modules/helloworld/build.sh +++ b/modules/helloworld/build.sh @@ -1,6 +1,6 @@ #/bin/sh echo "Название: Hello world" echo "Лицензия: Публичное достояние" -g++ -O0 -finput-charset=UTF-8 -fexec-charset=cp1251 -c -fPIC -nostdlib main.cpp -o hello.o +gcc -I../../modlib -O0 -finput-charset=UTF-8 -fexec-charset=cp1251 -c -fPIC -nostdlib main.c -o hello.o gcc -shared -nostdlib hello.o -o hello.so -Wl,--entry=_start echo "Сборка завершена, файл: hello.so" diff --git a/modules/helloworld/main.c b/modules/helloworld/main.c new file mode 100644 index 0000000..449ec45 --- /dev/null +++ b/modules/helloworld/main.c @@ -0,0 +1,22 @@ +#include + +const char name[] = "Привет мир!"; +const char message[] = "Привет из модуля!"; +module_info_t info; +env_t *env; + +void hello( ) {} +module_func_t func_table[] = { "hello", hello }; + +module_info_t *_start(env_t *env) { + fb_printf = env->fb_printf; + fb_printf("[hello]message=[%s]\n", message); + + info.name = (char *)&name; + info.message = (char *)&message; + info.func_count = 1; + info.func = &func_table; + info.err_code = 2023; + + return &info; +} \ No newline at end of file diff --git a/modules/helloworld/main.cpp b/modules/helloworld/main.cpp deleted file mode 100644 index b2429be..0000000 --- a/modules/helloworld/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -typedef struct { - void (*fb_printf)(char *str, ...); -} env_t; - -const char message[] = "Привет из модуля!"; - -extern "C" long long _start(env_t *env) { - env->fb_printf("[hello]message=[%s]\n", message); - return (long long)&message; -} \ No newline at end of file