diff --git a/arch/riscv64/mcount.S b/arch/riscv64/mcount.S index 7b3e21501..c3d4a29ac 100644 --- a/arch/riscv64/mcount.S +++ b/arch/riscv64/mcount.S @@ -3,60 +3,82 @@ .text GLOBAL(_mcount) - /* setup frame pointer & return address */ - addi sp, sp, -80 - sd ra, 72(sp) - sd s0, 64(sp) - addi s0, sp, 80 - - /* save arguments */ - sd a0, 56(sp) - sd a1, 48(sp) - sd a2, 40(sp) - sd a3, 32(sp) - sd a4, 24(sp) - sd a5, 16(sp) - sd a6, 8(sp) - sd a7, 0(sp) - - /* parent location */ - ld t0, 64(sp) - mv a0, t0 - - /* child addr */ - mv a1, ra - - /* mcount_args */ - mv a2, sp - - /* call mcount_entry func */ - call mcount_entry - - /* restore argunents */ - ld a7, 0(sp) - ld a6, 8(sp) - ld a5, 16(sp) - ld a4, 24(sp) - ld a3, 32(sp) - ld a2, 40(sp) - ld a1, 48(sp) - ld a0, 56(sp) - - /* restore frame pointer */ - ld s0, 64(sp) - ld ra, 72(sp) - - addi sp, sp, 80 - - ret + /* setup frame pointer & return address */ + addi sp, sp, -80 + sd ra, 72(sp) + sd s0, 64(sp) + addi s0, sp, 80 + + /* save arguments */ + sd a0, 56(sp) + sd a1, 48(sp) + sd a2, 40(sp) + sd a3, 32(sp) + sd a4, 24(sp) + sd a5, 16(sp) + sd a6, 8(sp) + sd a7, 0(sp) + + /* parent location */ + ld t1, 64(sp) + addi t1, t1, -8 + mv a0, t1 + + /* child addr */ + mv a1, ra + + /* mcount_args */ + mv a2, sp + + /* call mcount_entry func */ + call mcount_entry + + /* restore argunents */ + ld a7, 0(sp) + ld a6, 8(sp) + ld a5, 16(sp) + ld a4, 24(sp) + ld a3, 32(sp) + ld a2, 40(sp) + ld a1, 48(sp) + ld a0, 56(sp) + + /* restore frame pointer */ + ld s0, 64(sp) + ld ra, 72(sp) + + addi sp, sp, 80 + + ret END(_mcount) ENTRY(mcount_return) -/* - TODO : This was implemented as a meaningless value because we - focused on successful builds with no compilation errors. + /* setup frame pointer & return address */ + addi sp, sp, -24 + sd ra, 16(sp) + sd fp, 8(sp) + addi fp, sp, 24 + + /* save return values */ + sd a0, 0(sp) + + /* set the first argument of mcount_exit as pointer to return values */ + addi a0, sp, 0 + + /* call mcount_exit func */ + call mcount_exit + + mv t1, a0 + + /* restore return values */ + ld a0, 0(sp) + + /* restore frame pointer */ + ld s0, 8(sp) + ld ra, 16(sp) + + addi sp, sp, 24 - Therefore, it should be modified for future RISC-V 64-bit - architectures. -*/ + /* call return address */ + jr t1 END(_mcount)