Skip to content

Commit

Permalink
Improve FP argument passing test and fix MIPS register save code.
Browse files Browse the repository at this point in the history
  • Loading branch information
yugr committed Apr 10, 2024
1 parent 50593e9 commit 11a0ae5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
13 changes: 2 additions & 11 deletions arch/mips/table.S.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ _${lib_suffix}_save_regs_and_resolve:
#define POP_REG(reg) addiu $$sp, $$sp, 4; .cfi_adjust_cfa_offset -4; lw reg, 0($$sp); .cfi_restore reg

// dwarf_num = 32 + reg_num
#define PUSH_FREG(reg, dwarf_num) addiu $$sp, $$sp, -4; .cfi_adjust_cfa_offset 4; swc1 reg, 4($$sp); .cfi_rel_offset dwarf_num, 0
#define POP_FREG(reg, dwarf_num) addiu $$sp, $$sp, 4; .cfi_adjust_cfa_offset -4; lwc1 reg, 0($$sp); .cfi_restore dwarf_num
#define PUSH_FREG(reg, dwarf_num) addiu $$sp, $$sp, -8; .cfi_adjust_cfa_offset 8; sdc1 reg, 8($$sp); .cfi_rel_offset dwarf_num, 0
#define POP_FREG(reg, dwarf_num) addiu $$sp, $$sp, 8; .cfi_adjust_cfa_offset -8; ldc1 reg, 0($$sp); .cfi_restore dwarf_num

PUSH_REG($$ra)
PUSH_REG($$a0)
Expand All @@ -53,13 +53,8 @@ _${lib_suffix}_save_regs_and_resolve:
PUSH_REG($$a3)
PUSH_REG($$a3) // For alignment

#if 0
// FIXME: GCC complains about odd FP regs without -modd-spreg
PUSH_FREG($$f12, 44)
PUSH_FREG($$f13, 45)
PUSH_FREG($$f14, 46)
PUSH_FREG($$f15, 47)
#endif

// Vector arguments are passed on stack so we don't save vector regs

Expand All @@ -70,12 +65,8 @@ _${lib_suffix}_save_regs_and_resolve:
1: jalr $$25
nop

#if 0
POP_FREG($$f15, 47)
POP_FREG($$f14, 46)
POP_FREG($$f13, 45)
POP_FREG($$f12, 44)
#endif

POP_REG($$a3)
POP_REG($$a3)
Expand Down
8 changes: 8 additions & 0 deletions arch/mips64/table.S.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ _${lib_suffix}_save_regs_and_resolve:
PUSH_FREG($$f13, 45)
PUSH_FREG($$f14, 46)
PUSH_FREG($$f15, 47)
PUSH_FREG($$f16, 48)
PUSH_FREG($$f17, 49)
PUSH_FREG($$f18, 50)
PUSH_FREG($$f19, 51)

// Vector arguments are passed on stack so we don't save vector regs

Expand All @@ -75,6 +79,10 @@ _${lib_suffix}_save_regs_and_resolve:
1: jalr $$25
nop

POP_FREG($$f19, 51)
POP_FREG($$f18, 50)
POP_FREG($$f17, 49)
POP_FREG($$f16, 48)
POP_FREG($$f15, 47)
POP_FREG($$f14, 46)
POP_FREG($$f13, 45)
Expand Down
19 changes: 16 additions & 3 deletions tests/stack-args/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@

#include "interposed.h"

int main() {
foo(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
bar(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
#include <string.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
if (argc != 2)
return 1;

if (0 == strcmp(argv[1], "int")) {
foo(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
} else if (0 == strcmp(argv[1], "float")) {
bar(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
} else {
fprintf(stderr, "Invalid option: %s\n", argv[1]);
return 1;
}

return 0;
}
5 changes: 4 additions & 1 deletion tests/stack-args/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ ${PYTHON:-} ../../implib-gen.py -q --target $TARGET libinterposed.so
# Build app
$CC $CFLAGS main.c libinterposed.so.tramp.S libinterposed.so.init.c $LIBS

LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH:-} $INTERP ./a.out > a.out.log
LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH:-} $INTERP ./a.out int > a.out.log
diff test.ref a.out.log

LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH:-} $INTERP ./a.out float > a.out.log
diff test.ref a.out.log

echo SUCCESS
1 change: 0 additions & 1 deletion tests/stack-args/test.ref
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 comments on commit 11a0ae5

Please sign in to comment.