diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-07-05 02:34:11 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-07-05 02:34:11 +0200 |
| commit | beb76e4dd362374b8f42cd971d394bba1074cd8d (patch) | |
| tree | 3ea4cc342737afb9225c01160c92647ba66c78bd /libpsn00b/psxetc/_dl_resolve_wrapper.S | |
| parent | 5d9aa2d3dfc7d6e51c2eb942ab4cdbae5571a40a (diff) | |
| download | psn00bsdk-fix-include.tar.gz | |
Replace .include with #includefix-include
For some reason, both mipsel-unknown-elf-gcc 8.2.0 and mipsel-non-elf
15.1.0 were unable to resolve .include assembler directives.
As a workaround, it is still possible to use the preprocessor, and
therefore the usual #include preprocessor directive. However, this
requires the assembly files to use the uppercase .S file extension.
Diffstat (limited to 'libpsn00b/psxetc/_dl_resolve_wrapper.S')
| -rw-r--r-- | libpsn00b/psxetc/_dl_resolve_wrapper.S | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/libpsn00b/psxetc/_dl_resolve_wrapper.S b/libpsn00b/psxetc/_dl_resolve_wrapper.S new file mode 100644 index 0000000..b715720 --- /dev/null +++ b/libpsn00b/psxetc/_dl_resolve_wrapper.S @@ -0,0 +1,48 @@ +# PSn00bSDK dynamic linker +# (C) 2021-2022 spicyjpeg - MPL licensed +# +# This function is called by the lazy loader stubs generated by GCC in the +# .plt/.MIPS.stubs section when attempting to call a GOT entry whose address +# hasn't yet been resolved. The generated stubs conform to the MIPS ABI and +# uses the following registers: +# - $t7 = address the resolved function should return to (i.e. $ra of the +# caller that triggered the stub) +# - $t8 = index of the function in the .dynsym symbol table +# - $t9 = _dl_resolve_wrapper itself's address + +.set noreorder + +.section .text._dl_resolve_wrapper, "ax", @progbits +.global _dl_resolve_wrapper +.type _dl_resolve_wrapper, @function + +_dl_resolve_wrapper: + # Save the arguments being passed to the function to be resolved. + addiu $sp, -20 + sw $a0, 0($sp) + sw $a1, 4($sp) + sw $a2, 8($sp) + sw $a3, 12($sp) + sw $t7, 16($sp) # (will be restored directly to $ra) + + # Figure out where the DLL's struct is. dlinit() places a pointer to the + # struct in the second GOT entry, so it's just a matter of indexing the GOT + # using $gp. Then call _dl_resolve_helper with the struct and $t8 as + # arguments, and store the return value into $t0. + lw $a0, -0x7fec($gp) # dll = &((uint32_t *) (gp - 0x7ff0))[1] + move $a1, $t8 + + jal _dl_resolve_helper + addiu $sp, -8 + addiu $sp, 8 + + # Restore the arguments from the stack and tail-call the function at the + # address returned by the resolver. + lw $a0, 0($sp) + lw $a1, 4($sp) + lw $a2, 8($sp) + lw $a3, 12($sp) + lw $ra, 16($sp) + + jr $v0 + addiu $sp, 20 |
