Skip to content

Commit

Permalink
Work to make OS/2 API available to native apps, not just OS/2 binaries.
Browse files Browse the repository at this point in the history
GLoaderState is moved to a new lib2ine library, which everything links
to and sets up what it can in a DLL constructor, so your app can just
link to doscalls or whatever and it'll have what it needs without
something like lx_loader doing a lot of heavy lifting before your
main() runs.
  • Loading branch information
icculus committed Feb 28, 2018
1 parent 1220421 commit aa8f842
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 371 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Expand Up @@ -67,10 +67,16 @@ endif()
# !!! FIXME
include_directories("/usr/local/include/SDL2")

add_library(2ine SHARED "lib2ine.c")
set_target_properties(2ine PROPERTIES COMPILE_FLAGS "-m32")
set_target_properties(2ine PROPERTIES LINK_FLAGS "-m32 -ggdb3")
target_link_libraries(2ine "pthread")

foreach(_I doscalls;msg;nls;quecalls;viocalls;kbdcalls;sesmgr;som;pmwin;pmshapi;pmgpi;tcpip32)
add_library(${_I} SHARED "native/${_I}.c")
set_target_properties(${_I} PROPERTIES COMPILE_FLAGS "-m32")
set_target_properties(${_I} PROPERTIES LINK_FLAGS "-m32 -ggdb3")
target_link_libraries(${_I} 2ine)
endforeach()

target_link_libraries(doscalls "pthread")
Expand All @@ -81,6 +87,7 @@ target_link_libraries(pmwin "${CMAKE_CURRENT_SOURCE_DIR}/libSDL2-2.0.so.0")
add_executable(lx_dump lx_dump.c)

add_executable(lx_loader lx_loader.c)
target_link_libraries(lx_loader 2ine)
target_link_libraries(lx_loader "dl")
set_target_properties(lx_loader PROPERTIES COMPILE_FLAGS "-m32")
set_target_properties(lx_loader PROPERTIES LINK_FLAGS "-m32 -ggdb3")
Expand Down
29 changes: 21 additions & 8 deletions lx_loader.h → lib2ine.h
Expand Up @@ -6,8 +6,11 @@
* This file written by Ryan C. Gordon.
*/

#ifndef _INCL_LX_LOADER_H_
#define _INCL_LX_LOADER_H_ 1
/* lib2ine is support code and data that is common between various native
reimplementations of the OS/2 API, and the OS/2 binary loader. */

#ifndef _INCL_LIB2INE_H_
#define _INCL_LIB2INE_H_ 1

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
Expand Down Expand Up @@ -219,44 +222,54 @@ typedef struct LxPostTIB

#define LXTIBSIZE (sizeof (LxTIB) + sizeof (LxTIB2) + sizeof (LxPostTIB))

#define LX_MAX_LDT_SLOTS 8192

typedef struct LxLoaderState
{
LxModule *loaded_modules;
LxModule *main_module;
uint8 main_tibspace[LXTIBSIZE];
LxPIB pib;
int using_lx_loader;
int subprocess;
int running;
int trace_native;
int trace_events;
uint8 main_tib_selector;
uint16 original_cs;
uint16 original_ds;
uint16 original_es;
uint16 original_ss;
uint32 ldt[8192];
uint32 *ldt; //[LX_MAX_LDT_SLOTS];
char *libpath;
uint32 libpathlen;
uint32 *tlspage;
uint32 tlsmask; // one bit for each TLS slot in use.
uint8 tlsallocs[32]; // number of TLS slots allocated in one block, indexed by starting block (zero if not the starting block).
void (*dosExit)(uint32 action, uint32 result);
uint16 (*initOs2Tib)(uint8 *tibspace, void *_topOfStack, const size_t stacklen, const uint32 tid);
void (*initOs2Tib)(uint8 *tibspace, void *_topOfStack, const size_t stacklen, const uint32 tid);
uint16 (*setOs2Tib)(uint8 *tibspace);
LxTIB *(*getOs2Tib)(void);
void (*deinitOs2Tib)(const uint16 selector);
int (*findSelector)(const uint32 addr, uint16 *outselector, uint16 *outoffset, int iscode);
void (*freeSelector)(const uint16 selector);
void *(*convert1616to32)(const uint32 addr1616);
uint32 (*convert32to1616)(void *addr32);
LxModule *(*loadModule)(const char *modname);
int (*locatePathCaseInsensitive)(char *buf);
char *(*makeUnixPath)(const char *os2path, uint32 *err);
char *(*makeOS2Path)(const char *fname);
void __attribute__((noreturn)) (*terminate)(const uint32 exitcode);
} LxLoaderState;

typedef const LxExport *(*LxNativeModuleInitEntryPoint)(LxLoaderState *lx_state, uint32 *lx_num_exports);
typedef const LxExport *(*LxNativeModuleInitEntryPoint)(uint32 *lx_num_exports);
typedef void (*LxNativeModuleDeinitEntryPoint)(void);

// !!! FIXME: need to change this symbol name.
extern __attribute__((visibility("default"))) LxLoaderState GLoaderState;

#define LX_NATIVE_CONSTRUCTOR(modname) void __attribute__((constructor)) lxNativeConstructor_##modname(void)
#define LX_NATIVE_DESTRUCTOR(modname) void __attribute__((destructor)) lxNativeDestructor_##modname(void)

#endif

// end of lx_loader.h ...
// end of lib2ine.h ...

3 changes: 2 additions & 1 deletion lx_dump.c
Expand Up @@ -10,7 +10,8 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "lx_loader.h"

#include "lib2ine.h"

// !!! FIXME: some cut-and-paste with lx_loader.c ...

Expand Down

0 comments on commit aa8f842

Please sign in to comment.