Skip to content

Commit

Permalink
arch: Update 'arch/riscv64/mcount.S' for riscv64 architecture
Browse files Browse the repository at this point in the history
As part of the work to support the riscv64 architecture, and I
implemented a feedback function for the '_mcount' function and
a 'mcount_return' function.

The commit logs related to 'arch/riscv64/mcount.S', including this
comment log, are for reference only as they will be merged into
one using 'git squash' in the future.

Signed-off-by: Gichoel Choi <gichoel3101@gmail.com>
  • Loading branch information
gichoel committed Aug 21, 2023
1 parent 05a7c87 commit 1db036e
Showing 1 changed file with 74 additions and 52 deletions.
126 changes: 74 additions & 52 deletions arch/riscv64/mcount.S
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 1db036e

Please sign in to comment.