Attempt to print register values in regdump
This commit is contained in:
parent
951900bce9
commit
947f1fca89
2 changed files with 52 additions and 19 deletions
63
calc.s
63
calc.s
|
@ -4,6 +4,8 @@
|
||||||
# Provide program starting address to linker
|
# Provide program starting address to linker
|
||||||
.global _start
|
.global _start
|
||||||
|
|
||||||
|
.extern tohex
|
||||||
|
|
||||||
/* newlib system calls */
|
/* newlib system calls */
|
||||||
.set SYSEXIT, 93
|
.set SYSEXIT, 93
|
||||||
.set SYSWRITE, 64
|
.set SYSWRITE, 64
|
||||||
|
@ -54,7 +56,7 @@ end:
|
||||||
li a1, 1 # 1
|
li a1, 1 # 1
|
||||||
li a2, 0x80000000 # 0.5
|
li a2, 0x80000000 # 0.5
|
||||||
li a3, 1 # 1
|
li a3, 1 # 1
|
||||||
jal add64
|
# jal add64
|
||||||
#add t1, a0, 0 # copy a0 to t0 as end with overwrite it
|
#add t1, a0, 0 # copy a0 to t0 as end with overwrite it
|
||||||
jal regdump
|
jal regdump
|
||||||
|
|
||||||
|
@ -83,11 +85,25 @@ add64:
|
||||||
# Print values of all registers (in hex)
|
# Print values of all registers (in hex)
|
||||||
# write syscall uses t0, a0, a1, a2
|
# write syscall uses t0, a0, a1, a2
|
||||||
regdump:
|
regdump:
|
||||||
addi sp, sp, -16 # allocate stack space
|
# save all registers to preserve their state when entering the function
|
||||||
sw a0, 12(sp) # save contents of a0
|
# except sp, which will be offset by -64
|
||||||
sw a1, 8(sp) # save contents of a0
|
addi sp, sp, -64 # allocate stack space to stash all registers
|
||||||
sw a2, 4(sp) # save contents of a0
|
sw x0, 0(sp)
|
||||||
sw t0, 0(sp) # save contents of a0
|
sw x1, 4(sp)
|
||||||
|
sw x2, 8(sp)
|
||||||
|
sw x3, 12(sp)
|
||||||
|
sw x4, 16(sp)
|
||||||
|
sw x5, 20(sp)
|
||||||
|
sw x6, 24(sp)
|
||||||
|
sw x7, 28(sp)
|
||||||
|
sw x8, 32(sp)
|
||||||
|
sw x9, 36(sp)
|
||||||
|
sw x10, 40(sp)
|
||||||
|
sw x11, 44(sp)
|
||||||
|
sw x12, 48(sp)
|
||||||
|
sw x13, 52(sp)
|
||||||
|
sw x14, 56(sp)
|
||||||
|
sw x15, 60(sp)
|
||||||
|
|
||||||
li t0, SYSWRITE # "write" syscall
|
li t0, SYSWRITE # "write" syscall
|
||||||
li a0, 1 # 1 = standard output (stdout)
|
li a0, 1 # 1 = standard output (stdout)
|
||||||
|
@ -107,32 +123,45 @@ regdump_loop:
|
||||||
# copy regname to buf
|
# copy regname to buf
|
||||||
la a0, buf # load address of buf into a0 as dest
|
la a0, buf # load address of buf into a0 as dest
|
||||||
li a2, 2 # copy 2 bytes
|
li a2, 2 # copy 2 bytes
|
||||||
|
addi sp, sp, -4 # allocate stack space
|
||||||
addi sp, sp, -4 # allocate stack space
|
sw ra, 0(sp) # save contents of ra
|
||||||
sw ra, 0(sp) # save contents of ra
|
|
||||||
jal memcpy
|
jal memcpy
|
||||||
lw ra, 0(sp) # save contents of ra
|
lw ra, 0(sp) # restore contents of ra
|
||||||
addi sp, sp, 4 # deallocate stack space
|
addi sp, sp, 4 # deallocate stack space
|
||||||
# append ': \n'
|
# append ': '
|
||||||
li t0, ':
|
li t0, ':
|
||||||
sb t0, 0(a0)
|
sb t0, 0(a0)
|
||||||
li t0, 0x20
|
li t0, 0x20
|
||||||
sb t0, 1(a0)
|
sb t0, 1(a0)
|
||||||
li t0, '\n
|
addi a0, a0, 2 # bump a0 address over ': ' text
|
||||||
sb t0, 2(a0)
|
mv a1, a0 # load address of output buffer to a1
|
||||||
|
slli a2, s0, 2 # calculate the offset of the register value relative to sp
|
||||||
|
add a2, a2, sp # a2 = sp + (s0 * 4)
|
||||||
|
lw a0, 0(a2) # load register value to format into a0
|
||||||
|
addi sp, sp, -8 # allocate stack space
|
||||||
|
sw a1, 4(sp) # save contents of a1
|
||||||
|
sw ra, 0(sp) # save contents of ra
|
||||||
|
jal tohex
|
||||||
|
lw ra, 0(sp) # restore contents of ra
|
||||||
|
lw a1, 4(sp) # restore contents of a1 (buffer)
|
||||||
|
addi sp, sp, 8 # deallocate stack space
|
||||||
|
li t0, '\n # append newline
|
||||||
|
sb t0, 8(a1)
|
||||||
|
|
||||||
# print the register name
|
# print the register name and value
|
||||||
li t0, SYSWRITE # "write" syscall
|
li t0, SYSWRITE # "write" syscall
|
||||||
li a0, 1 # 1 = standard output (stdout)
|
li a0, 1 # 1 = standard output (stdout)
|
||||||
la a1, buf
|
la a1, buf
|
||||||
li a2, 5 # length of register name string
|
li a2, 4+8+1 # length of register name string:
|
||||||
|
# rr: 12345678\n
|
||||||
ecall # invoke syscall to print the string
|
ecall # invoke syscall to print the string
|
||||||
|
|
||||||
addi s0, s0, 1
|
addi s0, s0, 1
|
||||||
j regdump_loop
|
j regdump_loop
|
||||||
|
|
||||||
regdump_done:
|
regdump_done:
|
||||||
addi sp, sp, 16 # deallocate stack space
|
# TODO: Restore s0 & s1
|
||||||
|
addi sp, sp, 64 # deallocate stack space
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
8
hex.s
8
hex.s
|
@ -16,10 +16,12 @@ hexchars:
|
||||||
# return:
|
# return:
|
||||||
# none
|
# none
|
||||||
tohex:
|
tohex:
|
||||||
|
addi sp, sp, -20 # allocate stack space
|
||||||
|
sw s0, 12(sp) # save contents of s0
|
||||||
|
sw s1, 8(sp) # save contents of s1
|
||||||
li s0, 0 # set up loop variables
|
li s0, 0 # set up loop variables
|
||||||
li s1, 4
|
li s1, 4
|
||||||
addi a1, a1, 6 # offset output address to end chars
|
addi a1, a1, 6 # offset output address to end chars
|
||||||
addi sp, sp, -12 # allocate stack space
|
|
||||||
tohex_loop:
|
tohex_loop:
|
||||||
sw ra, 8(sp) # save contents of ra
|
sw ra, 8(sp) # save contents of ra
|
||||||
sw a0, 4(sp) # save contents of ra
|
sw a0, 4(sp) # save contents of ra
|
||||||
|
@ -33,7 +35,9 @@ tohex_loop:
|
||||||
addi a1, a1, -2 # decrement output buffer address
|
addi a1, a1, -2 # decrement output buffer address
|
||||||
addi s0, s0, 1 # increment loop counter
|
addi s0, s0, 1 # increment loop counter
|
||||||
blt s0, s1, tohex_loop # TODO: we don't need the loop counter and output addr
|
blt s0, s1, tohex_loop # TODO: we don't need the loop counter and output addr
|
||||||
addi sp, sp, 12 # deallocate stack space
|
lw s0, 12(sp) # restore s0 & s1
|
||||||
|
lw s1, 8(sp)
|
||||||
|
addi sp, sp, 20 # deallocate stack space
|
||||||
ret
|
ret
|
||||||
|
|
||||||
# Convert byte to ASCII hex
|
# Convert byte to ASCII hex
|
||||||
|
|
Loading…
Reference in a new issue