Skip to content

Commit

Permalink
thunks: derive remaining plt bits from elf
Browse files Browse the repository at this point in the history
This simplifies plt considerably.
Completely removed SetSymTab() and FdppCtrl()!

The intention is to make that infrastructure easily portable
to other projects. Unfortunately, that requires those "other
projects" to switch to elf, too. Which they haven't done just yet...
But I'd rather write yet another custom elf loader, than to port
this silly plt stuff.
  • Loading branch information
stsp committed Oct 9, 2023
1 parent bd8e48c commit 7e1b1e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 49 deletions.
25 changes: 1 addition & 24 deletions fdpp/plt.S
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* FDPP - freedos port to modern C++
* Copyright (C) 2018 Stas Sergeev (stsp)
* Copyright (C) 2018-2023 Stas Sergeev (stsp)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -109,34 +109,11 @@ init_near_wrp:

global plt_init
plt_init:
push bp
mov bp, sp

; copy plt entry
mov ax, FDPP_BS_SEG
mov es, ax
mov ax, [es:FDPP_BS_OFF+FDPP_PLT_OFFSET]
mov bx, [es:FDPP_BS_OFF+FDPP_PLT_OFFSET+2]
mov [fdpp_plt], ax
mov [fdpp_plt + 2], bx

mov al, 0 ; reserved
mov ah, FDPP_KERNEL_VERSION
mov bx, 0 ; reserved
; fill in struct fdpp_symtab
push word IGROUP
push word init_near_wrp ; near_wrp[1]
push word TGROUP
push word near_wrp ; near_wrp[0]
; fdpp_symtab filled
mov si, sp

push ds
mov di, DGROUP
mov ds, di
call far [es:FDPP_BS_OFF+FDPP_PLT_OFFSET+4]
pop ds

mov sp, bp
pop bp
ret
33 changes: 8 additions & 25 deletions fdpp/thunks.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* FDPP - freedos port to modern C++
* Copyright (C) 2018 Stas Sergeev (stsp)
* Copyright (C) 2018-2023 Stas Sergeev (stsp)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -42,8 +42,8 @@ struct asm_dsc_s {
struct asm_dsc_s *asm_tab;
#define asm_tab_len num_cthunks
static farhlp sym_tab;
static struct far_s *near_wrp;
#define num_wrps 2
static struct far_s near_wrp[num_wrps];
static int recur_cnt;

enum { ASM_OK, ASM_NORET, ASM_ABORT, PING_ABORT };
Expand Down Expand Up @@ -131,10 +131,6 @@ int is_dos_space(const void *ptr)
return fdpp->is_dos_space(ptr);
}

struct fdpp_symtab {
struct far_s near_wrp[2];
};

static void do_relocs(UWORD old_seg, uint8_t *start_p, uint8_t *end_p,
uint16_t delta)
{
Expand Down Expand Up @@ -174,27 +170,9 @@ static void do_relocs(UWORD old_seg, uint8_t *start_p, uint8_t *end_p,
fdlogprintf("processed %i relocs\n", reloc);
}

static void FdppSetSymTab(struct fdpp_symtab *symtab)
{
free(near_wrp);
near_wrp = (struct far_s *)malloc(sizeof(struct far_s) * num_wrps);
memcpy(near_wrp, symtab->near_wrp, sizeof(struct far_s) * num_wrps);
}

int FdppCtrl(int idx, struct vm86_regs *regs)
{
#define DL_SET_SYMTAB 0
switch (idx) {
case DL_SET_SYMTAB:
if (HI_BYTE(regs->eax) != FDPP_KERNEL_VERSION) {
fdloudprintf("\nfdpp version mismatch: expected %i, got %i\n",
FDPP_KERNEL_VERSION, HI_BYTE(regs->eax));
_fail();
}
FdppSetSymTab(
(struct fdpp_symtab *)so2lin(regs->ss, LO_WORD(regs->esi)));
return 0;
}
// so empty then???
return -1;
}

Expand Down Expand Up @@ -757,6 +735,11 @@ const void *FdppKernelReloc(void *handle, uint16_t seg)
asm_tab[i].off = off;
}

f.off = elf_getsymoff(h->elf, "near_wrp");
near_wrp[0] = f;
f.off = elf_getsymoff(h->elf, "init_near_wrp");
near_wrp[1] = f;

return h->start;
}

Expand Down

0 comments on commit 7e1b1e8

Please sign in to comment.