Skip to content

Commit

Permalink
Some initial VIOCALLS support via ncurses, other 16-bit updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Oct 29, 2016
1 parent d265193 commit c4d2d5e
Show file tree
Hide file tree
Showing 9 changed files with 641 additions and 31 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Expand Up @@ -46,13 +46,33 @@ endif()
add_definitions(-std=c99 -Wall -ggdb3)
add_definitions(-D_FILE_OFFSET_BITS=64)

set(CURSES_NEED_WIDE TRUE)
set(CURSES_NEED_NCURSES TRUE)
find_package(Curses)
if(NOT CURSES_FOUND)
message(FATAL_ERROR "ncurses not found")
endif()

include_directories(${CURSES_INCLUDE_DIR})
if(CURSES_HAVE_NCURSESW_NCURSES_H)
add_definitions(-DHAVE_NCURSESW_NCURSES_H)
elseif(CURSES_HAVE_NCURSESW_CURSES_H)
add_definitions(-DHAVE_NCURSESW_CURSES_H)
elseif(CURSES_HAVE_NCURSESW_H)
add_definitions(-DHAVE_NCURSESW_H)
elseif(CURSES_HAVE_CURSES_H)
add_definitions(-DHAVE_CURSES_H)
endif()

foreach(_I doscalls;msg;nls;quecalls;viocalls;kbdcalls;sesmgr)
add_library(${_I} SHARED "native/${_I}.c")
set_target_properties(${_I} PROPERTIES COMPILE_FLAGS "-m32")
set_target_properties(${_I} PROPERTIES LINK_FLAGS "-m32 -ggdb3")
endforeach()

target_link_libraries(doscalls "pthread")
# FIXME target_link_libraries(viocalls ${CURSES_LIBRARIES})
target_link_libraries(viocalls ncursesw)

add_executable(lx_dump lx_dump.c)

Expand Down
23 changes: 23 additions & 0 deletions lx_loader.c
Expand Up @@ -449,13 +449,35 @@ static void freeSelector(const uint16 selector)

static void *convert1616to32(const uint32 addr1616)
{
if (addr1616 == 0)
return NULL;

const uint16 selector = (uint16) (addr1616 >> 19); // slide segment down, and shift out control bits.
const uint16 offset = (uint16) (addr1616 % 0x10000); // all our LDT segments start at 64k boundaries (at the moment!).
assert(GLoaderState->ldt[selector] != 0);
//printf("convert1616to32: 0x%X -> %p\n", (uint) addr1616, (void *) (size_t) (GLoaderState->ldt[selector] + offset));
return (void *) (size_t) (GLoaderState->ldt[selector] + offset);
} // convert1616to32

static uint32 convert32to1616(void *addr32)
{
if (addr32 == NULL)
return 0;

uint16 selector = 0;
uint16 offset = 0;
if (!findSelector((uint32) addr32, &selector, &offset)) {
fprintf(stderr, "Uhoh, ran out of LDT entries?!\n");
return 0; // oh well, crash, probably.
} // if

//printf("selector: 0x%X\n", (uint) selector);
selector = (selector << 3) | 7;
//printf("shifted selector: 0x%X\n", (uint) selector);
return (((uint32)selector) << 16) | ((uint32) offset);
} // convert32to1616


// EMX (and probably many other things) occasionally has to call a 16-bit
// system API, and assumes its stack is tiled in the LDT; it'll just shift
// the stack pointer and use it as a stack segment for the 16-bit call
Expand Down Expand Up @@ -2066,6 +2088,7 @@ int main(int argc, char **argv, char **envp)
GLoaderState->findSelector = findSelector;
GLoaderState->freeSelector = freeSelector;
GLoaderState->convert1616to32 = convert1616to32;
GLoaderState->convert32to1616 = convert32to1616;
GLoaderState->loadModule = loadLxModuleByPathOrModuleName;
GLoaderState->locatePathCaseInsensitive = locatePathCaseInsensitive;
GLoaderState->makeUnixPath = makeUnixPath;
Expand Down
1 change: 1 addition & 0 deletions lx_loader.h
Expand Up @@ -226,6 +226,7 @@ typedef struct LxLoaderState
int (*findSelector)(const uint32 addr, uint16 *outselector, uint16 *outoffset);
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);
Expand Down
30 changes: 20 additions & 10 deletions native/doscalls.c
Expand Up @@ -240,6 +240,7 @@ LX_NATIVE_MODULE_INIT({ if (!initDoscalls()) return NULL; })
LX_NATIVE_EXPORT(DosExitMustComplete, 381),
LX_NATIVE_EXPORT(DosSetRelMaxFH, 382),
LX_NATIVE_EXPORT(DosFlatToSel, 425),
LX_NATIVE_EXPORT(DosSelToFlat, 426),
LX_NATIVE_EXPORT(DosAllocThreadLocalMemory, 454),
LX_NATIVE_EXPORT(DosFreeThreadLocalMemory, 455),
LX_NATIVE_EXPORT(DosR3ExitAddr, 553),
Expand Down Expand Up @@ -619,16 +620,7 @@ APIRET DosSetExceptionHandler(PEXCEPTIONREGISTRATIONRECORD rec)
ULONG _DosFlatToSel(PVOID ptr)
{
TRACE_NATIVE("DosFlatToSel(%p)", ptr);

uint16 selector = 0;
uint16 offset = 0;
if (!GLoaderState->findSelector((uint32) ptr, &selector, &offset)) {
fprintf(stderr, "Uhoh, ran out of LDT entries?!\n");
return 0; // oh well, crash.
} // if

selector = (selector << 3) | 7;
return (((uint32)selector) << 16) | ((uint32) offset);
return GLoaderState->convert32to1616(ptr);
} // _DosFlatToSel

// DosFlatToSel() passes its argument in %eax, so a little asm to bridge that...
Expand Down Expand Up @@ -2851,5 +2843,23 @@ APIRET DosQueryThreadContext(TID tid, ULONG level, PCONTEXTRECORD pcxt)
return ERROR_INVALID_PARAMETER;
} // DosQueryThreadContext

ULONG _DosSelToFlat(void *ptr)
{
TRACE_NATIVE("DosSelToFlat(%p)", ptr);
return (ULONG) GLoaderState->convert1616to32((uint32) ptr);
} // _DosSelToFlat

// DosSelToFlat() passes its argument in %eax, so a little asm to bridge that...
__asm__ (
".globl DosSelToFlat \n\t"
".type DosSelToFlat, @function \n\t"
"DosSelToFlat: \n\t"
" pushl %eax \n\t"
" call _DosSelToFlat \n\t"
" addl $4, %esp \n\t"
" ret \n\t"
".size _DosSelToFlat, .-_DosSelToFlat \n\t"
);

// end of doscalls.c ...

1 change: 1 addition & 0 deletions native/doscalls.h
Expand Up @@ -445,6 +445,7 @@ APIRET OS2API DosQueryFHState(HFILE hFile, PULONG pMode);
APIRET OS2API DosQueryExtLIBPATH(PSZ pszExtLIBPATH, ULONG flags);
APIRET OS2API DosSetMaxFH(ULONG cFH);
APIRET OS2API DosQueryThreadContext(TID tid, ULONG level, PCONTEXTRECORD pcxt);
ULONG OS2API DosSelToFlat(VOID);

#ifdef __cplusplus
}
Expand Down
6 changes: 6 additions & 0 deletions native/os2native16.h
Expand Up @@ -201,6 +201,12 @@ RETF 0x22 ; ...and back to the (far) caller, clearing the args (Pascal calling
} \
}

#define LX_NATIVE_MODULE_16BIT_BRIDGE_ARG(typ, var) \
const typ var = *((typ *) args); args += sizeof (typ)

#define LX_NATIVE_MODULE_16BIT_BRIDGE_PTRARG(typ, var) \
typ var = (typ) GLoaderState->convert1616to32(*((uint32 *) args)); args += sizeof (uint32)

#define LX_NATIVE_EXPORT16(fn, ord) { ord, #fn, &fn##16, &obj16 }

#endif
Expand Down
1 change: 1 addition & 0 deletions native/os2types.h
Expand Up @@ -68,6 +68,7 @@ typedef HANDLE TID, *PTID;
typedef SHANDLE HVIO, *PHVIO;
typedef SHANDLE HKBD, *PHKBD;
typedef PCHAR PSZ;
typedef PCHAR PCH;

typedef int (APIENTRY *PFN)(void);

Expand Down

0 comments on commit c4d2d5e

Please sign in to comment.