Skip to content

Commit

Permalink
go64: add elfload API
Browse files Browse the repository at this point in the history
  • Loading branch information
stsp committed Feb 1, 2025
1 parent b88a65e commit ab42527
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/go64.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

void pltcall32(__dpmi_regs *regs, __dpmi_paddr addr);
int elfexec(const char *path, int argc, char **argv);
int elfload(int num);

#endif
19 changes: 19 additions & 0 deletions src/djdev64/djexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@
#include <stdio.h>
#include <setjmp.h>
#include <dlfcn.h>
#include <assert.h>
#include "djdev64/djdev64.h"

#define MAX_PATHS 10
static const char *exec_path[MAX_PATHS];
static int num_exec_path;

struct exec_info {
/* volatile because of longjmp() vs auto storage */
/* unsigned char to not clash with go64/dj64 errors */
Expand Down Expand Up @@ -77,3 +82,17 @@ static void exit_exec(void *handle, int rc)
ei->exit_code = rc;
longjmp(ei->exit_jmp, 1);
}

int djdev64_add_load_path(const char *path)
{
assert(num_exec_path < MAX_PATHS);
exec_path[num_exec_path] = path;
return num_exec_path++;
}

int djdev64_load(int num, unsigned flags)
{
if (num >= num_exec_path)
return -1;
return djdev64_exec(exec_path[num], flags, 0, NULL);
}
3 changes: 2 additions & 1 deletion src/djdev64/include/djdev64/dj64init.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

typedef int (dj64cdispatch_t)(int handle, int libid, int fn, unsigned esi,
uint8_t *sp);
#define DJ64_API_VER 13
#define DJ64_API_VER 14
enum { DJ64_PRINT_LOG, DJ64_PRINT_TERMINAL, DJ64_PRINT_SCREEN };

/* pushal */
Expand Down Expand Up @@ -62,6 +62,7 @@ struct dj64_api {
void (*exit)(int rc);
void *(*malloc)(size_t size);
void (*free)(void *ptr);
int (*elfload)(int num);
};
#define DJ64_INIT_ONCE_FN dj64init_once
typedef int (dj64init_once_t)(const struct dj64_api *api, int api_ver);
Expand Down
2 changes: 2 additions & 0 deletions src/djdev64/include/djdev64/djdev64.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ int djdev64_ctrl(int handle, int libid, int fn, unsigned esi,
void djdev64_close(int handle);

int djdev64_exec(const char *path, unsigned flags, int argc, char **argv);
int djdev64_add_load_path(const char *path);
int djdev64_load(int num, unsigned flags);

#endif
2 changes: 1 addition & 1 deletion src/djdev64/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LIBELF := $(shell $(PKG_CONFIG) --silence-errors --libs libelf)
ifeq ($(LIBELF),)
$(error libelf not installed)
endif
CFLAGS += -iquote include -fpic -ggdb3 -Wall -Og -MD \
CFLAGS += -iquote include -fpic -ggdb3 -Wall -Wmissing-prototypes -Og -MD \
$(shell $(PKG_CONFIG) --cflags libelf) \
-DCRT0=\"$(prefix)/i386-pc-dj64/lib/crt0.elf\"

Expand Down
6 changes: 6 additions & 0 deletions src/libc/dj64/thunks.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <libc/djctx.h>
#include <libc/internal.h>
#include <dpmi.h>
#include <go64.h>
#include <sys/nearptr.h>
#include <stddef.h>
#include <stdlib.h>
Expand Down Expand Up @@ -605,3 +606,8 @@ void *djsbrk(int increment)
assert(increment > 0);
return dj64api->malloc(increment);
}

int elfload(int num)
{
return dj64api->elfload(num);
}

0 comments on commit ab42527

Please sign in to comment.