Изменен пример
This commit is contained in:
parent
2479b48989
commit
c2aef230fc
50
modlib/system.h
Normal file
50
modlib/system.h
Normal 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, ...);
|
@ -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
22
modules/helloworld/main.c
Normal 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;
|
||||
}
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user