From 0ac8fdc499d7261cae8bbfc1e7fb7b171bb8aceb Mon Sep 17 00:00:00 2001 From: Brooke Vibber Date: Mon, 5 Jan 2026 14:20:39 -0800 Subject: [PATCH] wip - annotated disassembly --- hello/hello-fwrite.txt | 124 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 hello/hello-fwrite.txt diff --git a/hello/hello-fwrite.txt b/hello/hello-fwrite.txt new file mode 100644 index 0000000..086ce97 --- /dev/null +++ b/hello/hello-fwrite.txt @@ -0,0 +1,124 @@ +0000000000010b36 : + ; ra = return address + ; a0 = buffer + ; a1 = size + ; a2 = count + ; a3 = stream + + ; -- Entry point for fwrite + ; Function protocol + 10b36: 7139 addi sp,sp,-64 + ; Check an internal word in the FILE to see if it needs to lock + 10b38: 08c6a783 lw a5,140(a3) + 10b3c: f426 sd s1,40(sp) + ; Set s1 = 1 if a1/size is non-zezro + 10b3e: 00b034b3 snez s1,a1 + 10b42: f822 sd s0,48(sp) + 10b44: f04a sd s2,32(sp) + 10b46: ec4e sd s3,24(sp) + ; Set s1 = -1 if a1/size is non-zero + 10b48: 409004b3 neg s1,s1 + 10b4c: fc06 sd ra,56(sp) + 10b4e: e852 sd s4,16(sp) + ; Set s0 = size * count + 10b50: 02c58433 mul s0,a1,a2 + ; Set s2 = stream + 10b54: 8936 mv s2,a3 + ; Set s3 = size + 10b56: 89ae mv s3,a1 + ; Set s1 = count if size is non-zero, or 0 if size is zero + 10b58: 8cf1 and s1,s1,a2 + ; Branch to lock path if needed: + 10b5a: 0207d463 bgez a5,10b82 + ; -- exit point bgez: likely branch 10b5e, rare branch 10b82 + + ; -- entry through branch + ; Call through to __fwritex + 10b5e: 8636 mv a2,a3 + 10b60: 85a2 mv a1,s0 + 10b62: f27ff0ef jal 10a88 <__fwritex> + ; -- exit point jal, return address 10b66 + + ; -- Entry point from return + ; Check the return value from __fwritex to see if we wrote + ; all requested bytes. + 10b66: 8a2a mv s4,a0 + 10b68: 01440463 beq s0,s4,10b70 + ; -- exit point beq: likely 10b6c, rare 10b70 + + ; -- Entry point from 10ba6 + ; -- Entry point from 10baa + ; Note this overlaps the previous trace! + ; Check the return value from __fwritex to see if we wrote + ; all requested bytes. + 10b68: 01440463 beq s0,s4,10b70 + ; -- exit point beq: likely 10b6c, rare 10b70 + + ; -- Entry point from 10b68 + ; Divide to the count in records from the count in bytes + 10b6c: 033a54b3 divu s1,s4,s3 + ; Function outro + 10b70: 70e2 ld ra,56(sp) + 10b72: 7442 ld s0,48(sp) + 10b74: 7902 ld s2,32(sp) + 10b76: 69e2 ld s3,24(sp) + 10b78: 6a42 ld s4,16(sp) + 10b7a: 8526 mv a0,s1 + 10b7c: 74a2 ld s1,40(sp) + 10b7e: 6121 addi sp,sp,64 + 10b80: 8082 ret + ; -- end point ret + + ; Entry point from 10b68 + ; Return the original record count, skipping the division. + ; Note this overlaps the previous two traces! + 10b70: 70e2 ld ra,56(sp) + 10b72: 7442 ld s0,48(sp) + 10b74: 7902 ld s2,32(sp) + 10b76: 69e2 ld s3,24(sp) + 10b78: 6a42 ld s4,16(sp) + 10b7a: 8526 mv a0,s1 + 10b7c: 74a2 ld s1,40(sp) + 10b7e: 6121 addi sp,sp,64 + 10b80: 8082 ret + ; -- end point ret + + ; Lock the FILE if needed + ; Call through to __lockfile + 10b82: 8a2a mv s4,a0 + 10b84: 8536 mv a0,a3 + 10b86: e456 sd s5,8(sp) + 10b88: c95ff0ef jal 1081c <__lockfile> + ; -- end point jal - return address 10b8c + + + ; -- entry through return address + ; Call through to __fwritex + 10b8c: 8aaa mv s5,a0 + 10b8e: 864a mv a2,s2 + 10b90: 8552 mv a0,s4 + 10b92: 85a2 mv a1,s0 + 10b94: ef5ff0ef jal 10a88 <__fwritex> + ; -- exit through call; return address 10b98 + + ; -- entry through return address + 10b98: 8a2a mv s4,a0 + 10b9a: 000a8763 beqz s5,10ba8 + ; -- exit through beqz; likely branch 10b9e; rare branch 10ba8 + + ; -- entry through branch from 10b9a + ; Call through to __unlockfile + 10b9e: 854a mv a0,s2 + 10ba0: d25ff0ef jal 108c4 <__unlockfile> + ; -- end through jal; return address 10ba4 + + ; -- entry through return address + 10ba4: 6aa2 ld s5,8(sp) + 10ba6: b7c9 j 10b68 + ; -- exit through jump to 10b68 + + ; -- entry point from branch at 10b9a + ; Head back to the exit path + 10ba8: 6aa2 ld s5,8(sp) + 10baa: bf7d j 10b68 + ; -- exit through jump to 10b68