Muteki
EABI code execution on Besta® RTOS devices.
Loading...
Searching...
No Matches
loader.h
Go to the documentation of this file.
1/*
2 * Copyright 2021-present dogtopus
3 * SPDX-License-Identifier: MIT
4 */
5
10
11#ifndef __MUTEKI_LOADER_H__
12#define __MUTEKI_LOADER_H__
13
14#include "common.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
30
46
55 unsigned int unk_0x0;
59 unsigned int unk_0x4;
67 unsigned int unk_0xc;
71 void *unk_0x10;
75 unsigned char unk_0x14;
79 unsigned char size_high_8;
83 unsigned char unk_0x16;
87 unsigned char unk_0x17;
91 unsigned int unk_0x18;
95 unsigned int unk_0x1c;
97
110 void *parent_fd; /* Created by retype action */
118 size_t size;
126 short unk_0x14; /* _OpenSubFile sets this to 1 */
130 short unk_0x16;
134 unsigned int unk_0x18;
138 unsigned int unk_0x1c;
140
146 size_t mapped_size;
147 size_t mapped_offset;
148 size_t data_size;
149 size_t data_offset;
152
158 size_t base;
159 size_t size;
161
166typedef struct loader_image_info_s {
167 size_t bestape_code_size;
168 size_t bestape_data_size;
169 size_t bestape_bss_size;
170 size_t bestape_total_raw_size; /* Size of headers and all raw section data */
171 size_t bestape_total_size;
172 size_t bestape_header_size;
173 unsigned int bestape_checksum;
174 unsigned int unk_0x1c;
175 unsigned char unk_0x20[24];
177
178typedef union loader_symbol_id_u {
179 const char *name;
180 unsigned int ordinal;
181} loader_symbol_id_t;
182
186typedef struct loader_impl_s {
190 void *(*load)(loader_file_descriptor_t *ldrfd);
194 void *(*load_into)(loader_file_descriptor_t *ldrfd, void *load_address);
198 void (*unload)(void *module);
203 int (*exec)(void *module, int subroutine, void *arg1, void *arg2);
211 void *(*dlopen)(char *pathname);
215 void (*dlclose)(void *module);
219 void *(*dlsym)(void *module, loader_symbol_id_t symbol_or_ordinal);
223 size_t (*get_module_filename)(void *module, char *out_filename, size_t size);
229 void *(*get_module)(const char *pathname);
233 loader_resource_descriptor_t *(*open_resource_descriptor)(loader_file_descriptor_t *ldrfd);
243 const UTF16 *res_type,
244 const UTF16 *res_name,
246 );
252
316
320typedef struct loader_applet_info_s {
324 unsigned short rom_magic;
328 unsigned short unused_0x2;
332 unsigned short rom_type;
336 unsigned short unused_0x4;
341 unsigned int exe_checksum;
349 unsigned char unused_0x10[0x74];
351
372extern loader_file_descriptor_t *_OpenFile(const char *pathname, const char *mode_or_subfile);
373
382extern loader_file_descriptor_t *_OpenFileW(const UTF16 *pathname, const void *mode_or_subfile);
383
392
401extern size_t _ReadFile(loader_file_descriptor_t *ldrfd, void *buf, size_t size);
402
412extern int _FseekFile(loader_file_descriptor_t *ldrfd, size_t offset, int whence);
413
420extern ssize_t _FileSize(loader_file_descriptor_t *ldrfd);
421
433extern loader_file_descriptor_t *_OpenSubFile(loader_file_descriptor_t *parent, size_t base, size_t max_size);
434
441extern ssize_t _TellFile(loader_file_descriptor_t *ldrfd);
442
452extern int RunApplicationA(const char *pathname,int subroutine,void *applet_arg1,void *applet_arg2);
453
463extern size_t GetApplicationNameA(const char *pathname, UTF16 *out_name, size_t max_size);
464
472extern loader_loaded_t *LoadProgramA(const char *pathname);
473
481extern int FreeProgram(loader_loaded_t *applet);
482
501extern int ExecuteProgram(loader_loaded_t *applet, int subroutine, void *applet_arg1, void *applet_arg2);
502
509extern const char *GetCurrentPathA(void);
510
518extern loader_loaded_t *ProgramIsRunningA(const char *pathname);
519
529extern int RunApplicationW(const UTF16 *pathname, int subroutine, void *applet_arg1, void *applet_arg2);
530
541extern size_t GetApplicationNameW(const UTF16 *pathname, UTF16 *out_name, size_t max_size);
542
550extern loader_loaded_t *LoadProgramW(const UTF16 *pathname);
551
558extern const UTF16 *GetCurrentPathW(void);
559
567extern loader_loaded_t *ProgramIsRunningW(const UTF16 *pathname);
568
577
585extern loader_loaded_t *LoadHFileProgramA(loader_file_descriptor_t *ldrfd, const char *pathname);
586
605extern loader_loaded_t *GetApplicationProcA(const char *pathname);
606
615extern int StayResidentProgramA(const char *pathname);
616
625extern int UnStayResidentProgramA(const char *pathname);
626
635
657
666extern int StayResidentProgramW(const UTF16 *pathname);
667
676extern int UnStayResidentProgramW(const UTF16 *pathname);
677
686extern int GetApplicationHeadInfoA(const char *pathname,loader_applet_info_t *info);
687
696extern int GetApplicationHeadInfoW(const UTF16 *pathname, loader_applet_info_t *info);
697
698#ifdef __cplusplus
699} // extern "C"
700#endif
701
702#endif // __MUTEKI_LOADER_H__
Common include file for all muteki-shims headers.
#define UTF16
"Portable" Besta UTF-16 type used by other headers.
Definition common.h:54
struct loader_impl_s loader_impl_t
Loader implementation function table.
loader_file_descriptor_t * _OpenFile(const char *pathname, const char *mode_or_subfile)
Open a loader file descriptor from a file.
int GetApplicationHeadInfoW(const UTF16 *pathname, loader_applet_info_t *info)
Obtain information on loaded applet by its LFN pathname.
struct loader_file_descriptor_s loader_file_descriptor_t
File descriptor specific to loader.
int UnStayResidentProgramW(const UTF16 *pathname)
Unmark a loaded applet as stay resident by its LFN pathname.
loader_loaded_t * LoadHFileProgramA(loader_file_descriptor_t *ldrfd, const char *pathname)
Load an applet executable from a loader file descriptor.
int StayResidentProgramW(const UTF16 *pathname)
Mark a loaded applet as stay resident by its LFN pathname.
struct loader_cart_descriptor_s loader_cart_descriptor_t
Cart file descriptor.
const UTF16 * GetCurrentPathW(void)
Get the path to the current running executable (argv[0]). (UTF-16 variant).
loader_file_descriptor_t * _OpenSubFile(loader_file_descriptor_t *parent, size_t base, size_t max_size)
Open a sub-file from a parent loader file descriptor.
const char * GetCurrentPathA(void)
Get the path to the current running executable (argv[0]).
loader_loaded_t * ProgramIsRunningA(const char *pathname)
Return the instance of a running applet by its DOS 8.3 path name.
int RunApplicationW(const UTF16 *pathname, int subroutine, void *applet_arg1, void *applet_arg2)
Load and execute an applet by its LFN pathname.
loader_loaded_t * LoadProgramA(const char *pathname)
Load an applet executable.
struct loader_resource_subfile_request_s loader_resource_subfile_request_t
Resource descriptor subfile request.
struct loader_loaded_s loader_loaded_t
Loaded applet executable.
loader_loaded_t * GetApplicationProcA(const char *pathname)
Search and return the applet instance by DOS 8.3 pathname.
int _FseekFile(loader_file_descriptor_t *ldrfd, size_t offset, int whence)
Seek to a specific position in an opened sub-file.
int StayResidentProgramA(const char *pathname)
Mark a loaded applet as stay resident by its DOS 8.3 pathname.
size_t _ReadFile(loader_file_descriptor_t *ldrfd, void *buf, size_t size)
Read data from a loader file descriptor.
int _CloseFile(loader_file_descriptor_t *ldrfd)
Close a loader file descriptor.
loader_file_descriptor_t * _OpenFileW(const UTF16 *pathname, const void *mode_or_subfile)
Open a loader file descriptor from a file (LFN path).
struct applet_args_v4_s applet_args_v4_t
Applet argument passing V4 struct.
loader_loaded_t * LoadHFileProgramW(loader_file_descriptor_t *ldrfd, const UTF16 *pathname)
Load an applet executable from a loader file descriptor.
loader_loaded_t * GetApplicationProcW(const UTF16 *pathname)
Search and return the applet instance by LFN.
int ExecuteProgram(loader_loaded_t *applet, int subroutine, void *applet_arg1, void *applet_arg2)
Invoke a specific subroutine of the loaded applet with arguments.
ssize_t _TellFile(loader_file_descriptor_t *ldrfd)
Get the current offset of sub-file.
size_t GetApplicationNameA(const char *pathname, UTF16 *out_name, size_t max_size)
Get the title name of the ROM file.
int FreeProgram(loader_loaded_t *applet)
Unload a loaded applet.
int GetApplicationHeadInfoA(const char *pathname, loader_applet_info_t *info)
Obtain information on loaded applet by its DOS 8.3 pathname.
int CheckProgramIsStayResident(loader_loaded_t *applet)
Check if an loaded applet has been set to stay resident.
loader_loaded_t * ProgramIsRunningW(const UTF16 *pathname)
Return the instance of a running applet by its LFN.
int UnStayResidentProgramA(const char *pathname)
Unmark a loaded applet as stay resident by its DOS 8.3 pathname.
struct loader_image_info_s loader_image_info_t
Executable image info.
applet_subroutine_e
Definition loader.h:24
@ APPLET_SUBROUTINE_RESET_STATES
Definition loader.h:28
@ APPLET_SUBROUTINE_MAIN
Definition loader.h:26
int RunApplicationA(const char *pathname, int subroutine, void *applet_arg1, void *applet_arg2)
Load and execute an applet by its DOS 8.3 pathname.
loader_loaded_t * LoadProgramW(const UTF16 *pathname)
Load an applet executable. (UTF-16 variant).
struct loader_resource_descriptor_s loader_resource_descriptor_t
Resource descriptor.
size_t GetApplicationNameW(const UTF16 *pathname, UTF16 *out_name, size_t max_size)
Get the title name of the ROM file (LFN path).
struct loader_applet_info_s loader_applet_info_t
Basic info on a loaded applet.
ssize_t _FileSize(loader_file_descriptor_t *ldrfd)
Get the size of sub-file.
Applet argument passing V4 struct.
Definition loader.h:36
char * dospath
Definition loader.h:38
void ** applet_arg1
Definition loader.h:42
void ** applet_arg2
Definition loader.h:44
int * subroutine
Definition loader.h:40
Basic info on a loaded applet.
Definition loader.h:320
unsigned short rom_type
Type field inside the ROM spec.
Definition loader.h:332
unsigned short unused_0x4
Unknown, seems unused.
Definition loader.h:336
unsigned short unused_0x2
Unknown, seems unused.
Definition loader.h:328
unsigned char unused_0x10[0x74]
Unknown, seems unused.
Definition loader.h:349
size_t exe_raw_size
File size of the executable.
Definition loader.h:345
unsigned short rom_magic
Magic bytes of ROM spec.
Definition loader.h:324
unsigned int exe_checksum
Checksum of the executable file.
Definition loader.h:341
Cart file descriptor.
Definition loader.h:51
unsigned char unk_0x16
Unknown.
Definition loader.h:83
unsigned int unk_0xc
Unknown.
Definition loader.h:67
unsigned char size_high_8
High 8 bits of the capacity of the cart.
Definition loader.h:79
void * unk_0x10
Unknown.
Definition loader.h:71
unsigned char unk_0x17
Unknown.
Definition loader.h:87
unsigned int unk_0x1c
Unknown.
Definition loader.h:95
unsigned int unk_0x4
Unknown.
Definition loader.h:59
unsigned int unk_0x18
Unknown.
Definition loader.h:91
size_t size_low_32
Low 32 bits of the capacity of the cart.
Definition loader.h:63
unsigned int unk_0x0
Unknown.
Definition loader.h:55
unsigned char unk_0x14
Unknown.
Definition loader.h:75
File descriptor specific to loader.
Definition loader.h:101
loader_cart_descriptor_t * cart
ROM cart descriptor.
Definition loader.h:105
size_t size
Base offset of this sub-file, within parent_fd.
Definition loader.h:118
size_t subfile_offset
Current ftell offset of this sub-file.
Definition loader.h:122
void * parent_fd
Parent file descriptor.
Definition loader.h:110
unsigned int unk_0x1c
Unknown.
Definition loader.h:138
size_t subfile_base
Base offset of the sub-file.
Definition loader.h:114
short unk_0x16
Unknown.
Definition loader.h:130
unsigned int unk_0x18
Unknown.
Definition loader.h:134
short unk_0x14
Unknown. Seems to be unused.
Definition loader.h:126
Executable image info.
Definition loader.h:166
Loader implementation function table.
Definition loader.h:186
void(*) unload(void *module)
Unload a module.
Definition loader.h:198
int(*) probe(loader_file_descriptor_t *ldrfd)
Probe a ldrfd for the.
Definition loader.h:207
int(*) collect_image_info(loader_file_descriptor_t *ldrfd, loader_image_info_t *info)
Collect information from a module file opened as ldrfd .
Definition loader.h:250
int(*) get_resource(loader_resource_descriptor_t *res, const UTF16 *res_type, const UTF16 *res_name, loader_resource_subfile_request_t *out_subfile)
Find resource entry (optional).
Definition loader.h:241
int(*) exec(void *module, int subroutine, void *arg1, void *arg2)
Execute a registered subroutine in the module.
Definition loader.h:203
size_t(*) get_module_filename(void *module, char *out_filename, size_t size)
Get the filename of a loaded module.
Definition loader.h:223
void(*) close_resource_descriptor(loader_resource_descriptor_t *res)
Close the resource descriptor of a module (optional).
Definition loader.h:237
void(*) dlclose(void *module)
Close a previously opened shared module/DLL.
Definition loader.h:215
Loaded applet executable.
Definition loader.h:256
unsigned char * mapped_executable
Mapped executable.
Definition loader.h:276
short unk_0x64
Unknown.
Definition loader.h:284
unsigned char unk_0x78[28]
Unknown.
Definition loader.h:309
char path[80]
DOS 8.3 path to executable file.
Definition loader.h:260
loader_file_descriptor_t * asset_file
Assets bundle file descriptor.
Definition loader.h:301
unsigned int rom_spec_offset_0xc
Unknown.
Definition loader.h:293
int active_refcount
Reference counter for currently active (running) instances.
Definition loader.h:272
int refcount
Reference counter.
Definition loader.h:268
void * path_lfn
LFN path.
Definition loader.h:297
loader_file_descriptor_t * ldrfd
Executable file descriptors.
Definition loader.h:305
short type
Executable type.
Definition loader.h:288
void * posixfd_rom
POSIX file descriptor of the executable.
Definition loader.h:314
loader_impl_t * loader
Loader implementation being used to load this applet.
Definition loader.h:280
int id
Numerical ID of loaded applet.
Definition loader.h:264
Resource descriptor.
Definition loader.h:145
Resource descriptor subfile request.
Definition loader.h:157
Definition loader.h:178