Blob Blame History Raw
/***********************************************************/
/*  ntux: native translation und extension                 */
/*  Copyright (C) 2016--2018  Z. Gilboa                    */
/*  Released under GPLv2 and GPLv3; see COPYING.NTUX.      */
/***********************************************************/

#ifndef PE_LDSO
#define PE_LDSO 1
#endif

#include <ntapi/nt_status.h>
#include <ntapi/nt_process.h>

#include <psxtypes/psxtypes.h>
#include <pemagine/pemagine.h>
#include <psxscl/psxglue.h>
#include <ntux/ntux.h>

#ifdef NTUX_STANDALONE

/* framework (rtdata) abi */
static const struct pe_guid  __ldsoabi  = NT_PROCESS_GUID_RTDATA;

/* loader standalone (single directory) name */
static const unsigned short __sdldso[] = {'l','i','b','p','s','x','s','c','l',
				          '.','s','o',0};

/* pty server standalone name */
static const unsigned short __sdctty[] = {'n','t','c','t','t','y',
				          '.','e','x','e',0};

/* system call layer init context */
static struct __psx_context ctx = {sizeof(ctx),0,0,0,0,0,0,0,0,0,0,0,0};

/* ldso buffer */
static uintptr_t	__attribute__((section(".dsodata")))
			__dsodata[65536/sizeof(unsigned long)];

int ntux_entry_routine(
	int(*__psx_init_routine)(int *,char ***,char ***,void *),
	struct __psx_context * ctx);

static int ntux_usrmain(void)
{
	return 0;
}

void ntux_entry_point(void)
{
	int		status;
	void *		hroot;
	void *		hdsodir;
	void *		ldsobase;
	int  		(*__psx_init)(
				int *,char ***,char ***,
				void *);

	if ((status = __ldso_load_framework_loader_ex(
			&ldsobase,&hroot,&hdsodir,
			&__ldsoabi,
			__sdldso,0,ntux_main,
			__dsodata,sizeof(__dsodata),
			PE_LDSO_STANDALONE_EXECUTABLE,
			&(unsigned int){0})))
		__ldso_terminate_current_process(status);

	if (!(__psx_init = __ldso_get_procedure_address(
			ldsobase,"__psx_init")))
		__ldso_terminate_current_process(NT_STATUS_NOINTERFACE);

	ctx.options = __PSXOPT_VRFS;
	ctx.ctty    = __sdctty;
	ctx.usrmain = ntux_usrmain;

	ntux_entry_routine(__psx_init,&ctx);
}

#endif