Изменен пример

This commit is contained in:
Aren Elchinyan 2023-10-15 18:44:29 +03:00
parent 2479b48989
commit c2aef230fc
4 changed files with 73 additions and 11 deletions

50
modlib/system.h Normal file
View File

@ -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, ...);

View File

@ -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"

22
modules/helloworld/main.c Normal file
View File

@ -0,0 +1,22 @@
#include <system.h>
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;
}

View File

@ -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;
}