Announcement

Collapse
No announcement yet.

Random Code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Random Code

    I can't find my pen drive that I usually just have wherever I go to mess with code if I'm at a computer. I'm just making this post a random little sandbox thing. I doubt it would help much people. I'm making this as if I'm jumping from the "jr ra" in the "scesifsendcmd" function of a game. I'm just editing and modifying this as I go when I get time.

    // Scan for Load or Store Ops & create watch points for them.
    Address: 000FF000

    _Init:
    addiu sp, sp, $FF90

    sq ra, $0000(sp)
    sq s0, $0010(sp)
    sq s1, $0020(sp)
    sq s2, $0030(sp)
    sq s3, $0040(sp)
    sq s4, $0050(sp)
    sq s5, $0060(sp)

    lui s0, $0??? // Start Scanning Here
    //ori s0, s0, $????

    lui s1, $0??? // Stop Scanning Here
    //ori s1, s1, $????

    lui s2, $0??? // Start Making Subroutines Here
    //ori s2, s2, $????

    lui s3, $0??? // Stop Making Subroutines Here
    //ori s3, s3, $????

    lui s4, $0??? // Address You Want To Find
    ori s4, s4, $????

    //----------------

    _Init_Find_Store_Or_Load_Ops: // This just finds a starting point.
    lw t1, $0000(s0) // Load code at address.

    lui t0, $FC00 // Shortcut value for checking bits 1-6.
    and t2, t0, t1

    daddu s5, zero, zero // Will be used to determine whether you need to check the next 1 or 3 addresses. 1 = 2 addresses, 2 = 4 addresses.

    lui t3, $8000
    beq t2, t3, :_Check_Previous_Op // Is it LB?

    lui t3, $9000
    beq t2, t3, :_Check_Previous_Op // Is it LBU?

    lui t3, $A000
    beq t2, t3, :_Check_Previous_Op // Is it SB?

    lui t3, $8400
    beq t2, t3, :_Check_Previous_Op // Is it LH?

    lui t3, $9400
    beq t2, t3, :_Check_Previous_Op // Is it LHU?

    lui t3, $A400
    beq t2, t3, :_Check_Previous_Op // Is it SH?

    lui t3, $8C00
    beq t2, t3, :_Check_Previous_Op // Is it LW?

    lui t3, $9C00
    beq t2, t3, :_Check_Previous_Op // Is it LWU?

    lui t3, $AC00
    beq t2, t3, :_Check_Previous_Op // Is it SW?

    lui t3, $C400
    beq t2, t3, :_Check_Previous_Op // Is it LWC1?

    lui t3, $E400
    beq t2, t3, :_Check_Previous_Op // Is it SWC1?

    lui t3, $C800
    beq t2, t3, :_Check_Previous_Op // Is it LWC2?

    lui t3, $E800
    beq t2, t3, :_Check_Previous_Op // Is it SWC2?

    ori s5, zero, $0001
    lui t3, $DC00
    beq t2, t3, :_Check_Previous_Op // Is it LD?

    lui t3, $FC00
    beq t2, t3, :_Check_Previous_Op // Is it SD?

    lui t3, $6800
    beq t2, t3, :_Check_Previous_Op // Is it LDL?

    lui t3, $B000
    beq t2, t3, :_Check_Previous_Op // Is it SDL?

    lui t3, $6C00
    beq t2, t3, :_Check_Previous_Op // Is it LDR?

    lui t3, $B400
    beq t2, t3, :_Check_Previous_Op // Is it SDR?

    lui t3, $D400
    beq t2, t3, :_Check_Previous_Op // Is it LDC1?

    lui t3, $F400
    beq t2, t3, :_Check_Previous_Op // Is it SDC1?

    ori s5, zero, $0002
    lui t3, $7800
    beq t2, t3, :_Check_Previous_Op // Is it LQ?

    lui t3, $7C00
    beq t2, t3, :_Check_Previous_Op // Is it SQ?

    lui t3, $D800
    beq t2, t3, :_Check_Previous_Op // Is it LQC2?

    lui t3, $F800
    beq t2, t3, :_Check_Previous_Op // Is it SQC2?
    nop

    addiu s0, s0, $0004
    beq s0, s1, :_Finished_Scanning
    nop
    beq zero, zero, FFC4 // It's none, so check next address.
    nop

    //----------------

    _Check_Previous_Op:
    addiu s0, s0, $FFFC
    lw t1, $0000(s0) // Load previous op.

    lui t0, $FC1F
    ori t0, t0, $FFFF
    and t2, t0, t1
    ori t3, zero, $0008
    beq t2, t3, :_Found_Previous_JR

    lui t0, $FC00
    and t2, t0, t1
    lui t3, $0800
    beq t2, t3, :_Found_Previous_J
    lui t3, $0C00
    beq t2, t3, :_Found_Previous_JAL
    lui t3, $1000
    beq t2, t3, :_Found_Previous_BranchNormal // BEQ
    lui t3, $1400
    beq t2, t3, :_Found_Previous_BranchNormal // BNE
    lui t3, $5000
    beq t2, t3, :_Found_Previous_BranchLikely // BEQL
    lui t3, $5400
    beq t2, t3, :_Found_Previous_BranchLikely // BNEL

    lui t0, $FC1F
    and t2, t0, t1
    lui t3, $0400
    beq t2, t3, :_Found_Previous_BranchNormal // BLTZ
    lui t3, $0401
    beq t2, t3, :_Found_Previous_BranchNormal // BGEZ
    lui t3, $0402
    beq t2, t3, :_Found_Previous_BranchLikely // BLTZL
    lui t3, $0403
    beq t2, t3, :_Found_Previous_BranchLikely // BGEZL
    lui t3, $0410
    beq t2, t3, :_Found_Previous_BranchAndLink // BLTZAL
    lui t3, $0411
    beq t2, t3, :_Found_Previous_BranchAndLink // BGEZAL
    lui t3, $0412
    beq t2, t3, :_Found_Previous_BranchAndLinkLikely // BLTZALL
    lui t3, $0413
    beq t2, t3, :_Found_Previous_BranchAndLinkLikely // BGEZALL
    lui t3, $1800
    beq t2, t3, :_Found_Previous_BranchNormal // BLEZ
    lui t3, $1900
    beq t2, t3, :_Found_Previous_BranchNormal // BGTZ
    lui t3, $5800
    beq t2, t3, :_Found_Previous_BranchLikely // BLEZL
    lui t3, $5900
    beq t2, t3, :_Found_Previous_BranchLikely // BGTZL

    lui t0, $FC1F
    ori t0, t0, $0EFF
    and t2, t0, t1
    ori t3, zero, $0009
    beq t2, t3, :_Found_Previous_JALR

    lui t0, $FFFF
    and t2, t0, t1
    lui t3, $4500
    beq t2, t3, :_Found_Previous_BranchNormal // BC1F
    lui t3, $4501
    beq t2, t3, :_Found_Previous_BranchLikely // BC1FL
    lui t3, $4502
    beq t2, t3, :_Found_Previous_BranchNormal // BC1T
    lui t3, $4503
    beq t2, t3, :_Found_Previous_BranchLikely // BC1TL
    nop
    beq zero, zero, :_Check_Next_Op
    addiu s0, s0, $0004

    //----------------

    _Found_Previous_JR:
    bgezal zero, :_Check_If_There_Is_Enough_Space
    ori t0, zero, $0048 // The amount of lines it will take.
    bgezal zero, :_addiu_sp_sp_FFC0
    addiu s2, s2, $0004
    bgezal zero, :_sq_t0_0000(sp)
    nop
    bgezal zero, :_sq_t1_0010(sp)
    nop
    bgezal zero, :_sq_t2_0020(sp)
    nop
    bgezal zero, :_sq_t3_0030(sp)
    nop
    bgezal zero, :_lui_t0_SubroutineArea
    nop
    bgezal zero, :_ori_t0_t0_SubroutineArea
    nop
    bgezal zero, :_lui_t1_TargetAddress
    nop
    bgezal zero, :_ori_t1_t1_TargetAddress
    nop
    bgezal zero, :_is_t2_needed
    nop
    bgezal zero, :_addiu_t3_NormallyUsedRegister_offset
    nop
    bgezal zero, :_beql_t1_t3_0001
    nop
    bgezal zero, :_sw_t1_0000(t0)
    nop
    bne s5, zero, $ ///////

    bgezal zero, :_lq_t0_0000(sp)
    nop
    bgezal zero, :_lq_t1_0010(sp)
    nop
    bgezal zero, :_lq_t2_0020(sp)
    nop
    bgezal zero, :_lq_t3_0030(sp)
    nop
    bgezal zero, :_jr_Original
    nop
    bgezal zero, :_addiu_sp_sp_0040
    nop
    bgezal zero, :_Create_Jump_To_Subroutine
    nop
    beq zero, zero, :_Init_Find_Store_Or_Load_Ops
    addiu s0, s0, $0008

    //---------------

    _Found_Previous_J:
    bgezal zero, :_Check_If_There_Is_Enough_Space
    ori t0, zero, $0048 // The amount of lines it will take.
    bgezal zero, :_addiu_sp_sp_FFC0
    nop
    bgezal zero, :_sq_t0_0000(sp)
    nop
    bgezal zero, :_sq_t1_0010(sp)
    nop
    bgezal zero, :_sq_t2_0020(sp)
    nop
    bgezal zero, :_sq_t3_0030(sp)
    nop
    bgezal zero, :_lui_t0_SubroutineArea
    nop
    bgezal zero, :_ori_t0_t0_SubroutineArea
    nop
    bgezal zero, :_lui_t1_TargetAddress
    nop
    bgezal zero, :_ori_t1_t1_TargetAddress
    nop
    bgezal zero, :_is_t2_needed
    nop
    bgezal zero, :_addiu_t3_NormallyUsedRegister_offset
    nop
    bgezal zero, :_beql_t1_t2_0001
    nop
    bgezal zero, :_sw_t1_0000(t0)
    nop
    bgezal zero, :_lq_t0_0000(sp)
    nop
    bgezal zero, :_lq_t1_0010(sp)
    nop
    bgezal zero, :_lq_t2_0020(sp)
    nop
    bgezal zero, :_lq_t3_0030(sp)
    nop
    bgezal zero, :_j_OriginalAddress
    nop
    bgezal zero, :_addiu_sp_sp_0040
    nop
    bgezal zero, :_Create_Jump_To_Subroutine
    nop
    beq zero, zero, :_Init_Find_Store_Or_Load_Ops
    addiu s0, s0, $0008

    //----------------

    _Found_Previous_bgezal zero,:
    bgezal zero, :_Check_If_There_Is_Enough_Space
    ori t0, zero, $0050 // The amount of lines it will take.
    bgezal zero, :_addiu_sp_sp_FFC0
    nop
    bgezal zero, :_sq_t0_0000(sp)
    nop
    bgezal zero, :_sq_t1_0010(sp)
    nop
    bgezal zero, :_sq_t2_0020(sp)
    nop
    bgezal zero, :_sq_t3_0030(sp)
    nop
    bgezal zero, :_lui_t0_SubroutineArea
    nop
    bgezal zero, :_ori_t0_t0_SubroutineArea
    nop
    bgezal zero, :_lui_t1_TargetAddress
    nop
    bgezal zero, :_ori_t1_t1_TargetAddress
    nop
    bgezal zero, :_is_t2_needed
    nop
    bgezal zero, :_addiu_t3_NormallyUsedRegister_offset
    nop
    bgezal zero, :_beql_t1_t3_0001
    nop
    bgezal zero, :_sw_t1_0000(t0)
    nop
    bgezal zero, :_lq_t0_0000(sp)
    nop
    bgezal zero, :_lq_t1_0010(sp)
    nop
    bgezal zero, :_lq_t2_0020(sp)
    nop
    bgezal zero, :_lq_t3_0030(sp)
    nop
    bgezal zero, :_addiu_sp_sp_0040
    nop
    bgezal zero, :_lui_ra_OriginalAddress
    nop
    bgezal zero, :_convert_jal_to_j_OriginalAddress
    nop
    bgezal zero, :_ori_ra_ra_OriginalAddress
    nop
    bgezal zero, :_Create_Jump_To_Subroutine
    nop
    beq zero, zero, :_Init_Find_Store_Or_Load_Ops
    addiu s0, s0, $0008

    //----------------

    _Found_Previous_JALR:
    bgezal zero, :_Check_If_There_Is_Enough_Space
    ori t0, zero, $0060 // The amount of lines it will take.
    bgezal zero, :_addiu_sp_sp_FFC0
    nop
    bgezal zero, :_sq_t0_0000(sp)
    nop
    bgezal zero, :_sq_t1_0010(sp)
    nop
    bgezal zero, :_sq_t2_0020(sp)
    nop
    bgezal zero, :_sq_t3_0030(sp)
    nop
    bgezal zero, :_lui_t0_SubroutineArea
    nop
    bgezal zero, :_ori_t0_t0_SubroutineArea
    nop
    bgezal zero, :_lui_rd_0aaa
    nop
    bgezal zero, :_ori_rd_rd_aaaa
    nop
    bgezal zero, :_srl_t1_rs_2
    nop
    bgezal zero, :_lui_r2_0800
    nop
    bgezal zero, :_or_r1_r1_r2
    nop
    bgezal zero, :_sw_r1_0054(r0)
    nop
    bgezal zero, :_lui_t1_TargetAddress
    nop
    bgezal zero, :_ori_t1_t1_TargetAddress
    nop
    bgezal zero, :_is_t2_needed
    nop
    bgezal zero, :_addiu_t3_NormallyUsedRegister_offset
    nop
    bgezal zero, :_beql_t1_t3_0001
    nop
    bgezal zero, :_sw_t1_0000(t0)
    nop
    bgezal zero, :_lq_t0_0000(sp)
    nop
    bgezal zero, :_lq_t1_0010(sp)
    nop
    bgezal zero, :_lq_t2_0020(sp)
    nop
    bgezal zero, :_lq_t3_0030(sp)
    nop
    bgezal zero, :_addiu_sp_sp_0040
    nop
    bgezal zero, :_Create_Jump_To_Subroutine
    nop
    beq zero, zero, :_Init_Find_Store_Or_Load_Ops
    addiu s0, s0, $0008

    //---------------

    _Found_Previous_BranchNormal:
    // This covers BEQ, BNE, BGTZ, BLTZ, BGEZ, BLEZ, BC1F, and BC1T.
    bgezal zero, :_Check_If_There_Is_Enough_Space
    ori t0, zero, $0058 // The amount of lines it will take.
    bgezal zero, :_addiu_sp_sp_FFC0
    nop
    bgezal zero, :_sq_t0_0000(sp)
    nop
    bgezal zero, :_sq_t1_0010(sp)
    nop
    bgezal zero, :_sq_t2_0020(sp)
    nop
    bgezal zero, :_sq_t3_0030(sp)
    nop
    bgezal zero, :_lui_t0_SubroutineArea
    nop
    bgezal zero, :_ori_t0_t0_SubroutineArea
    nop
    bgezal zero, :_lui_t1_TargetAddress
    nop
    bgezal zero, :_ori_t1_t1_TargetAddress
    nop
    bgezal zero, :_is_t2_needed
    nop
    bgezal zero, :_addiu_t3_NormallyUsedRegister_offset
    nop
    bgezal zero, :_beql_t1_t3_0001
    nop
    bgezal zero, :_sw_t1_0000(t0)
    nop
    bgezal zero, :_lq_t0_0000(sp)
    nop
    bgezal zero, :_lq_t1_0010(sp)
    nop
    bgezal zero, :_lq_t2_0020(sp)
    nop
    bgezal zero, :_lq_t3_0030(sp)
    nop
    bgezal zero, :_branch_t1_t3_0003
    nop
    bgezal zero, :_addiu_sp_sp_0040
    nop
    bgezal zero, :_j_destination1
    nop
    bgezal zero, :_j_destination2
    nop
    bgezal zero, :_Create_Jump_To_Subroutine
    nop
    beq zero, zero, :_Init_Find_Store_Or_Load_Ops
    addiu s0, s0, $0008

    //---------------

    _Found_Previous_BranchLikely:
    // This covers BEQL, BNEL, BGTZL, BLTZL, BGEZL, BLEZL, BC1TL, and BC1FL.
    bgezal zero, :_Check_If_There_Is_Enough_Space
    ori t0, zero, $0058 // The amount of lines it will take.
    bgezal zero, :_addiu_sp_sp_FFC0
    nop
    bgezal zero, :_sq_t0_0000(sp)
    nop
    bgezal zero, :_sq_t1_0010(sp)
    nop
    bgezal zero, :_sq_t2_0020(sp)
    nop
    bgezal zero, :_sq_t3_0030(sp)
    nop
    bgezal zero, :_lui_t0_SubroutineArea
    nop
    bgezal zero, :_ori_t0_t0_SubroutineArea
    nop
    bgezal zero, :_lui_t1_TargetAddress
    nop
    bgezal zero, :_ori_t1_t1_TargetAddress
    nop
    bgezal zero, :_is_t2_needed
    nop
    bgezal zero, :_addiu_t3_NormallyUsedRegister_offset
    nop
    bgezal zero, :_beql_t1_t3_0001
    nop
    bgezal zero, :_sw_t1_0000(t0)
    nop
    bgezal zero, :_lq_t0_0000(sp)
    nop
    bgezal zero, :_lq_t1_0010(sp)
    nop
    bgezal zero, :_lq_t2_0020(sp)
    nop
    bgezal zero, :_lq_t3_0030(sp)
    nop
    bgezal zero, :_branch_u0_u1_0003
    nop
    bgezal zero, :_Original_Load_Or_Store_Op
    nop
    bgezal zero, :_addiu_sp_sp_0040
    nop
    bgezal zero, :_j_destination1
    nop
    bgezal zero, :_j_destination2
    nop
    bgezal zero, :_Create_Jump_To_Subroutine
    nop
    beq zero, zero, :_Init_Find_Store_Or_Load_Ops
    addiu s0, s0, $0008

    //---------------

    _Found_Previous_BranchAndLink:
    // This covers BLTZAL and BGEZAL.
    bgezal zero, :_Check_If_There_Is_Enough_Space
    ori t0, zero, $005C // The amount of lines it will take.
    bgezal zero, :_addiu_sp_sp_FFC0
    nop
    bgezal zero, :_sq_t0_0000(sp)
    nop
    bgezal zero, :_sq_t1_0010(sp)
    nop
    bgezal zero, :_sq_t2_0020(sp)
    nop
    bgezal zero, :_sq_t3_0030(sp)
    nop
    bgezal zero, :_lui_t0_SubroutineArea
    nop
    bgezal zero, :_ori_t0_t0_SubroutineArea
    nop
    bgezal zero, :_lui_t1_TargetAddress
    nop
    bgezal zero, :_ori_t1_t1_TargetAddress
    nop
    bgezal zero, :_is_t2_needed
    nop
    bgezal zero, :_addiu_t3_NormallyUsedRegister_offset
    nop
    bgezal zero, :_beql_t1_t3_0001
    nop
    bgezal zero, :_sw_t1_0000(t0)
    nop
    bgezal zero, :_lq_t0_0000(sp)
    nop
    bgezal zero, :_lq_t1_0010(sp)
    nop
    bgezal zero, :_lq_t2_0020(sp)
    nop
    bgezal zero, :_lq_t3_0030(sp)
    nop
    bgezal zero, :_addiu_sp_sp_0040
    nop
    bgezal zero, :_Remove_Linking_From_Branches
    nop
    bgezal zero, :_j_destination1
    nop
    bgezal zero, :_j_destination2
    nop
    bgezal zero, :_Create_Jump_To_Subroutine
    nop
    sw zero, $0004(s0)
    beq zero, zero, :_Init_Find_Store_Or_Load_Ops
    addiu s0, s0, $0008

    //---------------

    _Found_Previous_BranchAndLinkLikely:
    // This covers BLTZALL and BGEZALL.
    bgezal zero, :_Check_If_There_Is_Enough_Space
    ori t0, zero, $0058 // The amount of lines it will take.
    bgezal zero, :_addiu_sp_sp_FFC0
    nop
    bgezal zero, :_sq_t0_0000(sp)
    nop
    bgezal zero, :_sq_t1_0010(sp)
    nop
    bgezal zero, :_sq_t2_0020(sp)
    nop
    bgezal zero, :_sq_t3_0030(sp)
    nop
    bgezal zero, :_lui_t0_SubroutineArea
    nop
    bgezal zero, :_ori_t0_t0_SubroutineArea
    nop
    bgezal zero, :_lui_t1_TargetAddress
    nop
    bgezal zero, :_ori_t1_t1_TargetAddress
    nop
    bgezal zero, :_is_t2_needed
    nop
    bgezal zero, :_addiu_t3_NormallyUsedRegister_offset
    nop
    bgezal zero, :_beql_t1_t3_0001
    nop
    bgezal zero, :_sw_t1_0000(t0)
    nop
    bgezal zero, :_lq_t0_0000(sp)
    nop
    bgezal zero, :_lq_t1_0010(sp)
    nop
    bgezal zero, :_lq_t2_0020(sp)
    nop
    bgezal zero, :_lq_t3_0030(sp)
    nop
    bgezal zero, :_Remove_Linking_From_Branches
    nop
    bgezal zero, :_addiu_sp_sp_0040
    nop
    bgezal zero, :_j_destination1
    nop
    bgezal zero, :_j_destination2
    nop
    bgezal zero, :_Create_Jump_To_Subroutine
    nop
    beq zero, zero, :_Init_Find_Store_Or_Load_Ops
    addiu s0, s0, $0008

    //---------------

    _Check_If_There_Is_Enough_Space:
    addu t0, t0, s2
    slt t0, t0, s3
    beq t0, zero, :_Finished_Scanning // If there's no room left to create subroutines, it's done.
    nop
    jr ra
    nop

    //---------------

    _addiu_sp_sp_FFC0:
    lui t0, $27BD
    ori t0, t0, $FFC0
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _sq_t0_0000(sp):
    lui t0, $7FA8
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _lui_t0_SubroutineArea:
    lui t0, $3c08

    srl t2, s2, 16
    or t0, t0, t2
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _ori_t0_t0_SubroutineArea:
    lui t0, $3508
    andi t1, s2, $FFFF
    or t0, t0, t1
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _sq_t1_0010(sp):
    lui t0, $7FA9
    ori t0, t0, $0010
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _lui_t1_TargetAddress:
    lui t0, $3c09
    srl t2, s4, 16
    or t0, t0, t2
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _ori_t1_t1_TargetAddress:
    lui t0, $3529
    andi t1, s4, $FFFF
    or t0, t0, t1
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _sq_t2_0020(sp):
    lui t0, $7FAA
    ori t0, t0, $0020
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _is_t2_needed:
    // If it encounters registers t0, t1, t2, or t3 being used, this will be used to move their contents to t2.

    lw t0, $0004(s0)
    srl t0, t0, 21
    andi t0, t0, $001F

    lui t3, $7BAA
    ori t1, zero, $0008
    beq t0, t1, $000C
    ori t2, t3, $0000 // Load t0's contents into t2

    ori t1, zero, $0009
    beq t0, t1, $0009
    ori t2, t3, $0010 // Load t1's contents into t2

    ori t1, zero, $000A
    beq t0, t1, $0006
    ori t2, t3, $0020 // Load t2's contents into t2

    ori t1, zero, $000B
    beq t0, t1, $0003
    ori t2, t3, $0030 // Load t3's contents into t2

    jr ra
    nop
    sw t2, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _addiu_t3_NormallyUsedRegister_offset:
    lui t0, $240B

    lw t1, $0000(s0)
    lui t2, $03E0
    and t3, t1, t2

    lui t4, $0100
    bne t3, t4, $0005
    lui t4, $0120
    bne t3, t4, $0003
    lui t4, $0160
    beql t3, t4, $0001
    lui t3, $0140

    and t0, t0, t3

    andi t2, t1, $FFFF
    or t0, t0, t2

    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _branch_u0_u1_0003:
    lw t0, $0000(s0)
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _Original_Load_Or_Store_Op:
    lw t0, $0004(s0)
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _beql_t1_r0_0001:
    lui t0, $5120
    ori t0, t0, $0001

    lw t1, $0000(s0)
    lui t2, $03E0
    and t3, t1, t2

    lui t4, $0100
    bne t3, t4, $0005
    lui t4, $0120
    bne t3, t4, $0003
    lui t4, $0160
    beql t3, t4, $0001
    lui t3, $0140
    srl t3, t3, 5

    or t0, t0, t3
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _sw_t1_0000(t0):
    lui t0, $AD09

    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _lq_t0_0000(sp):
    lui t0, $7BA8
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _lq_t1_0010(sp):
    lui t0, $7BA9
    ori t0, t0, $0010
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _lq_t2_0020(sp):
    lui t0, $7BAA
    ori t0, t0, $0020
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _lq_t3_0030(sp):
    lui t0, $7BAB
    ori t0, t0, $0030
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _addiu_sp_sp_0040:
    lui t0, $27BD
    ori t0, t0, $0040
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _jr_OriginalRegister:
    lw t0, $0000(s0)
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _j_OriginalAddress:
    lui t0, $0800

    srl t2, s0, 2
    or t0, t0, t2
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _lui_ra_OriginalAddress:
    lui t0, $3c1f
    addiu t1, s0, $0008
    srl t1, t1, 16
    or t0, t0, t1
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _convert_jal_to_j_OriginalAddress:
    lw t0, $0000(s0)
    lui t1, $08FF
    ori t1, t1, $FFFF
    and t0, t0, t1 // Changes the JAL to a J.
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _ori_ra_ra_OriginalAddress:
    lui t0, $37FF
    addiu t1, s0, $0008
    andi t1, t1, $FFFF
    or t0, t0, t1
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _lui_rd_0aaa:
    lw t0, $0000(s0)
    srl t0, t0, 21
    andi t0, t0, $001F
    beql t0, zero, 0001
    ori t0, t0, $001F
    sll t0, t0, 16

    lui t1, $3C00
    or t0, t0, t1

    addiu t1, s0, $0008
    srl t1, t1, 16
    or t0, t0, t1
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _ori_rd_rd_aaaa:

    lw t0, $0000(s0)
    srl t0, t0, 21
    andi t0, t0, $001F
    beql t0, zero, 0001
    ori t0, t0, $001F
    sll t0, t0, 16

    sll t1, t0, 5
    or t0, t0, t1

    lui t1, $3400
    or t0, t0, t1

    addiu t1, s0, $0008
    andi t1, t1, $FFFF
    or t0, t0, t1
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _srl_t1_rs_2:
    ori t0, zero, $4882

    lw t1, $0000(s0)
    andi t1, t1, $F800
    sll t1, t1, 5

    or t0, t0, t1
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _lui_r2_0800:
    lui t0, $3C0A
    ori t0, t0, $0800

    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _or_t1_t1_t2:
    lui t0, $012A
    ori t0, t0, $4825

    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _sw_t1_0054(t0):
    lui t0, $AD09
    ori t0, t0, $0054

    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _branch_t1_t3_0003:
    lw t0, $0000(s0)
    srl t0, t0, 26
    sll t0, t0, 26
    ori t0, t0, $0003

    lui t1, $012b
    or t0, t0, t1

    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _j_destination1:
    addiu t0, s0, $0008
    srl t0, t0, 2
    lui t1, $0800
    or t0, t0, t1
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _j_destination2:
    srl t0, s0, 2
    addiu t0, t0, $0001

    lw t1, $0000(s0)
    andi t1, t1, $FFFF
    addiu t0, t0, t1

    lw t1, $0800
    or t0, t0, t1
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _Remove_Linking_From_Branches:
    lui t1, $FFEF
    ori t1, t1, $FFFF
    and t0, t0, t1
    sw t0, $0000(s2)
    jr ra
    addiu s2, s2, $0004

    //----------------

    _Create_Jump_To_Subroutine:
    lui t0, $0800
    srl t2, s2, 2
    addiu t2, t2, $0001
    or t0, t0, t2
    jr ra
    sw t0, $0000(s0)

    //----------------

    _Finished_Scanning:
    lq ra, $0000(sp)
    lq s0, $0010(sp)
    lq s1, $0020(sp)
    lq s2, $0030(sp)
    lq s3, $0040(sp)
    lq s4, $0050(sp)
    lq s5, $0060(sp)
    jr ra
    addiu sp, sp, $0070



    /*
    lb = 80000000
    lbu = 90000000
    sb = a0000000
    lh = 84000000
    lhu = 94000000
    sh = a4000000
    lw = 8c000000
    lwu = 9c000000
    sw = ac000000
    lwc1 = c4000000
    swc1 = e4000000
    lwc2 = c8000000
    swc2 = e8000000
    ld = dc000000
    sd = fc000000
    ldl = 68000000
    sdl = b0000000
    ldr = 6c000000
    sdr = b4000000
    ldc1 = d4000000
    sdc1 = f4000000
    lq = 78000000
    sq = 7c000000
    lqc2 = d8000000
    sqc2 = f8000000
    There's still a few more like these, like "prefetch" and "cache", but I'm not certain they are useful. I'll also need to alter this for doubles and quads since they have the possibility of missing addresses since they can use the next 12 bytes.
    */



    /*
    1 JR 000000 ????? 000000000000000 001000

    1 JALR 000000 rs??? 00000 rd??? 00000 001001

    1 BLTZ 000001 ????? 00000
    1 BGEZ 000001 ????? 00001
    1 BLTZL 000001 ????? 00010
    1 BGEZL 000001 ????? 00011
    1 BLTZAL 000001 ????? 10000
    1 BGEZAL 000001 ????? 10001
    1 BLTZALL 000001 ????? 10010
    1 BGEZALL 000001 ????? 10011
    1 BLEZ 000110 ????? 00000
    1 BGTZ 000111 ????? 00000
    1 BLEZL 010110 ????? 00000
    1 BGTZL 010111 ????? 00000

    1 J 000010
    1 JAL 000011
    1 BEQ 000100
    1 BNE 000101
    1 BEQL 010100
    1 BNEL 010101

    1 BC1F 010001 01000 00000
    1 BC1T 010001 01000 00001
    1 BC1FL 010001 01000 00010
    1 BC1TL 010001 01000 00011
    */

    Added "j" operations and some other load/store operations.

    01-01-11: Completely rewrote some things in some kind of way that just makes life easier. Should work correctly for any instances of these 3:
    "JR ??
    Load/Store Op"

    "J $0???????
    Load/Store Op"

    "JAL $0???????
    Load/Store Op"



    01-04-11: It should now work correctly for any instances of these 17:
    "JALR ?? ??
    Load/Store Op"

    "BEQ ??, ??, $0???????
    Load/Store Op"

    "BNE ??, ??, $0???????
    Load/Store Op"

    "BLTZ ??, $0???????
    Load/Store Op"

    "BGTZ ??, $0???????
    Load/Store Op"

    "BLEZ ??, $0???????
    Load/Store Op"

    "BGEZ ??, $0???????
    Load/Store Op"

    "BEQL ??, ??, $0???????
    Load/Store Op"

    "BNEL ??, ??, $0???????
    Load/Store Op"

    "BLTZL ??, $0???????
    Load/Store Op"

    "BGTZL ??, $0???????
    Load/Store Op"

    "BLEZL ??, $0???????
    Load/Store Op"

    "BGEZL ??, $0???????
    Load/Store Op"

    "BLTZAL ??, $0???????
    Load/Store Op"

    "BGEZAL ??, $0???????
    Load/Store Op"

    "BLTZALL ??, $0???????
    Load/Store Op"

    "BGEZALL ??, $0???????
    Load/Store Op"

    That's all of the branches and jumps that would interfere with this and make it harder due to those delay slots or whatever they are called since I'm creating jumps. I just need to make it find single and multiple consecutive instances of Store/Load Ops, and check after them for the branches and jumps, and check after those for any other Store/Load Ops.


    1-25-11: Added some stuff I started on for checking the next addresses' code for branches, jumps, other load/store operations, or just nothing.

    2-18-11: More heavy updating to fix whatever stuff was wrong, incomplete, or not working the way I want it to. Changed many JALs to BGEZALs. I'm about to the point where I'm going to make it correctly check results that deal with doubles or vectors.
    Last edited by bungholio; 02-18-2011, 03:44:49 PM.
    July 7, 2019

    https://www.4shared.com/s/fLf6qQ66Zee
    https://www.sendspace.com/file/jvsdbd

  • #2
    1-28-11: Still randomly working on it.

    2-11-11: Working on it more. Removed the code to find the first few registers not being used in a function, since I figured out I don't need it. Subroutines are created using t0-t3. Some other stuff. Still far from done.

    The big list of "How They Should Look"

    ...
    load/store op
    ...

    becomes

    ...
    j $s4
    ...

    {
    0000 addiu sp, sp, $FFD0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 lui t0, $WhereThisIs
    0014 ori t0, t0, $WhereThisIs
    0018 lui t1, $WhatI'mLookingFor
    001c ori t1, t1, $WhatI'mLookingFor
    0020 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0024 beql t1, t2, $0001
    0028 sw sp, $0040(t0)
    002c sq t0, $0000(sp)
    0030 sq t1, $0010(sp)
    0034 sq t2, $0020(sp)
    0038 j $ra+8
    003c addiu sp, sp, $0030
    0040 nop (sp will be stored here if it is found)
    }

    //----------------

    jr r0
    load/store op
    ...

    becomes

    j $s4
    load/store op
    ...

    {
    0000 addiu sp, sp, $FFD0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 lui t0, $WhereThisIs
    0014 ori t0, t0, $WhereThisIs
    0018 lui t1, $WhatI'mLookingFor
    001c ori t1, t1, $WhatI'mLookingFor
    0020 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0024 beql t1, t2, $0001
    0028 sw sp, $0040(t0)
    002c lq t0, $0000(sp)
    0030 lq t1, $0010(sp)
    0034 lq t2, $0020(sp)
    0038 jr r0
    003c addiu sp, sp, $0030
    0040 nop (sp will be stored here if it is found)
    }

    //----------------

    j $UnknownAddress
    load/store op
    ...

    becomes

    j $s4
    load/store op
    ...

    {
    0000 addiu sp, sp, $FFD0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 lui t0, $WhereThisIs
    0014 ori t0, t0, $WhereThisIs
    0018 lui t1, $WhatI'mLookingFor
    001c ori t1, t1, $WhatI'mLookingFor
    0020 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0024 beql t1, t2, $0001
    0028 sw sp, $0040(t0)
    002c lq t0, $0000(sp)
    0030 lq t1, $0010(sp)
    0034 lq t2, $0020(sp)
    0038 j $UnknownAddress
    003c addiu sp, sp, $0030
    0040 nop (sp will be stored here if it is found)
    }

    //----------------

    jal $UnknownAddress
    load/store op
    ...

    becomes

    j $s4
    load/store op
    ...

    {
    0000 addiu sp, sp, $FFD0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 lui t0, $WhereThisIs
    0014 ori t0, t0, $WhereThisIs
    0018 lui t1, $WhatI'mLookingFor
    001c ori t1, t1, $WhatI'mLookingFor
    0020 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0024 beql t1, t2, $0001
    0028 sw sp, $0048(t0)
    002c lq t0, $0000(sp)
    0030 lq t1, $0010(sp)
    0034 lq t2, $0020(sp)
    0038 addiu sp, sp, $0030
    003c lui ra, $s6+$0008
    0040 j $UnknownAddress
    0044 ori ra, ra, $s6+$0008
    0048 nop (sp will be stored here if it is found)
    }

    //----------------

    jalr r0 r1
    load/store op
    ...

    becomes

    j $s4
    load/store op
    ...

    {
    0000 addiu sp, sp, $FFD0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 lui t0, $WhereThisIs
    0014 ori t0, t0, $WhereThisIs
    0018 lui t1, $WhatI'mLookingFor
    001c ori t1, t1, $WhatI'mLookingFor
    0020 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0024 beql t1, t2, $0001
    0028 sw sp, $0048(t0)
    002c lq t0, $0000(sp)
    0030 lq t1, $0010(sp)
    0034 lq t2, $0020(sp)
    0038 addiu sp, sp, $0030
    003c lui r0, $s6+$0008
    0040 j $r1
    0044 ori r0, r0, $s6+$0008
    0048 nop (sp will be stored here if it is found)
    }

    //----------------

    beq/bne/bltz/blez/bgtz/bgez/bc1t/bc1f
    load/store op
    ...

    becomes

    j $s4
    load/store op
    ...

    {
    0000 addiu sp, sp, $FFD0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 lui t0, $WhereThisIs
    0014 ori t0, t0, $WhereThisIs
    0018 lui t1, $WhatI'mLookingFor
    001c ori t1, t1, $WhatI'mLookingFor
    0020 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0024 beql t1, t2, $0001
    0028 sw sp, $0050(t0)
    002c lq t0, $0000(sp)
    0030 lq t1, $0010(sp)
    0034 lq t2, $0020(sp)
    0038 beq/bne/bltz/blez/bgtz/bgez/bc1t/bc1f $0003
    003c addiu sp, sp, $0030
    0040 j $s6+$0008
    0044 nop
    0048 j $BranchAddress + BranchOffset sll 2
    004c nop
    0050 nop (sp will be stored here if it is found)
    }

    //----------------

    beql/bnel/bltzl/bgtzl/blezl/bgezl/bc1fl/bc1tl
    load/store op
    ...

    becomes

    j $s4
    nop
    ...

    {
    0000 addiu sp, sp, $FFD0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 lui t0, $WhereThisIs
    0014 ori t0, t0, $WhereThisIs
    0018 lui t1, $WhatI'mLookingFor
    001c ori t1, t1, $WhatI'mLookingFor
    0020 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0024 beql t1, t2, $0001
    0028 sw sp, $0054(t0)
    002c lq t0, $0000(sp)
    0030 lq t1, $0010(sp)
    0034 lq t2, $0020(sp)
    0038 addiu sp, sp, $0030
    003c beql/bnel/bltzl/bgtzl/blezl/bgezl/bc1fl/bc1tl $0003
    0040 load/store op
    0044 j $s6+$0008
    0048 nop
    004c j $BranchAddress + BranchOffset sll 2
    0050 nop
    0054 nop (sp will be stored here if it is found)
    }

    //----------------

    bltzal/bgezal
    load/store op
    ...

    becomes

    j $s4
    load/store op
    ...

    {
    0000 addiu sp, sp, $FFD0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 lui t0, $WhereThisIs
    0014 ori t0, t0, $WhereThisIs
    0018 lui t1, $WhatI'mLookingFor
    001c ori t1, t1, $WhatI'mLookingFor
    0020 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0024 beql t1, t2, $0001
    0028 sw sp, $0058(t0)
    002c lq t0, $0000(sp)
    0030 lq t1, $0010(sp)
    0034 lq t2, $0020(sp)
    0038 addiu sp, sp, $0030
    003c lui ra, $s6+$0008
    0040 bltz/blez $0003 // This is correct.
    0044 ori ra, ra, $s6+$0008
    0048 j $s6+$0008
    004c nop
    0050 j $BranchAddress + BranchOffset sll 2
    0054 nop
    0058 nop (sp will be stored here if it is found)
    }

    //----------------

    bltzall/bgezall
    load/store op
    ...

    becomes

    j $s4
    nop
    ...

    {
    0000 addiu sp, sp, $FFD0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 lui t0, $WhereThisIs
    0014 ori t0, t0, $WhereThisIs
    0018 lui t1, $WhatI'mLookingFor
    001c ori t1, t1, $WhatI'mLookingFor
    0020 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0024 beql t1, t2, $0001
    0028 sw sp, $005c(t0)
    002c lq t0, $0000(sp)
    0030 lq t1, $0010(sp)
    0034 lq t2, $0020(sp)
    0038 addiu sp, sp, $0030
    003c lui ra, $s6+$0008
    0040 ori ra, ra, $s6+$0008
    0044 bltzl/blezl $0003 //This is correct.
    0048 load/store op
    004c j $s6+$0008
    0050 nop
    0054 j $BranchAddress + BranchOffset sll 2
    0058 nop
    005c nop (sp will be stored here if it is found)
    }

    //----------------

    load/store op
    jr r0
    load/store op

    becomes

    load/store op
    j $s4
    load/store op

    {
    0000 addiu sp, sp, $FFC0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 sq t3, $0030(sp)
    0014 lui t0, $WhereThisIs
    0018 ori t0, t0, $WhereThisIs
    001c lui t1, $WhatI'mLookingFor
    0020 ori t1, t1, $WhatI'mLookingFor
    0024 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0028 beql t1, t2, $0001
    002c sw sp, $0054(t0)
    0030 addiu t3, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0034 beql t1, t3, $0001
    0038 sw sp, $0054(t0)
    003c lq t0, $0000(sp)
    0040 lq t1, $0010(sp)
    0044 lq t2, $0020(sp)
    0048 lq t3, $0030(sp)
    004c jr r0
    0050 addiu sp, sp, $0040
    0054 nop (sp will be stored here if it is found)
    }

    //----------------

    load/store op
    j $UnknownAddress
    load/store op

    becomes

    load/store op
    j $s4
    load/store op

    {
    0000 addiu sp, sp, $FFC0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 sq t3, $0030(sp)
    0014 lui t0, $WhereThisIs
    0018 ori t0, t0, $WhereThisIs
    001c lui t1, $WhatI'mLookingFor
    0020 ori t1, t1, $WhatI'mLookingFor
    0024 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0028 beql t1, t2, $0001
    002c sw sp, $0054(t0)
    0030 addiu t3, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0034 beql t1, t3, $0001
    0038 sw sp, $0054(t0)
    003c lq t0, $0000(sp)
    0040 lq t1, $0010(sp)
    0044 lq t2, $0020(sp)
    0048 lq t3, $0030(sp)
    004c j $UnknownAddress
    0050 addiu sp, sp, $0040
    0054 nop (sp will be stored here if it is found)
    }

    //----------------

    load/store op
    jal $UnknownAddress
    load/store op

    becomes

    load/store op
    j $s4
    load/store op

    {
    0000 addiu sp, sp, $FFC0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 sq t3, $0030(sp)
    0014 lui t0, $WhereThisIs
    0018 ori t0, t0, $WhereThisIs
    001c lui t1, $WhatI'mLookingFor
    0020 ori t1, t1, $WhatI'mLookingFor
    0024 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0028 beql t1, t2, $0001
    002c sw sp, $005c(t0)
    0030 addiu t3, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0034 beql t1, t3, $0001
    0038 sw sp, $005c(t0)
    003c lq t0, $0000(sp)
    0040 lq t1, $0010(sp)
    0044 lq t2, $0020(sp)
    0048 lq t3, $0030(sp)
    004c addiu sp, sp, $0040
    0050 lui ra, $s6+$0008
    0054 j $UnknownAddress
    0058 ori ra, ra, $s6+$0008
    005c nop (sp will be stored here if it is found)
    }

    //----------------

    load/store op
    jalr r0, r1
    load/store op

    becomes

    load/store op
    j $s4
    load/store op

    {
    0000 addiu sp, sp, $FFC0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 sq t3, $0030(sp)
    0014 lui t0, $WhereThisIs
    0018 ori t0, t0, $WhereThisIs
    001c lui t1, $WhatI'mLookingFor
    0020 ori t1, t1, $WhatI'mLookingFor
    0024 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0028 beql t1, t2, $0001
    002c sw sp, $005c(t0)
    0030 addiu t3, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0034 beql t1, t3, $0001
    0038 sw sp, $005c(t0)
    003c lq t0, $0000(sp)
    0040 lq t1, $0010(sp)
    0044 lq t2, $0020(sp)
    0048 lq t3, $0030(sp)
    004c addiu sp, sp, $0040
    0050 lui r0, $s6+$0008
    0054 j $r1
    0058 ori r0, r0, $s6+$0008
    005c nop (sp will be stored here if it is found)
    }

    //----------------

    load/store op
    beq/bne/bltz/blez/bgtz/bgez/bc1t/bc1f
    load/store op

    becomes

    load/store op
    j $s4
    load/store op

    {
    0000 addiu sp, sp, $FFC0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 sq t3, $0030(sp)
    0014 lui t0, $WhereThisIs
    0018 ori t0, t0, $WhereThisIs
    001c lui t1, $WhatI'mLookingFor
    0020 ori t1, t1, $WhatI'mLookingFor
    0024 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0028 beql t1, t2, $0001
    002c sw sp, $0064(t0)
    0030 addiu t3, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0034 beql t1, t3, $0001
    0038 sw sp, $0064(t0)
    003c lq t0, $0000(sp)
    0040 lq t1, $0010(sp)
    0044 lq t2, $0020(sp)
    0048 lq t3, $0030(sp)
    004c beq/bne/bltz/blez/bgtz/bgez/bc1t/bc1f $0003
    0050 addiu sp, sp, $0040
    0054 j $s6+$0008
    0058 nop
    005c j $BranchAddress + BranchOffset sll 2
    0060 nop
    0064 nop (sp will be stored here if it is found)
    }

    //----------------

    load/store op
    beql/bnel/bltzl/blezl/bgtzl/bgezl/bc1tl/bc1fl
    load/store op

    becomes

    load/store op
    j $s4
    nop

    {
    0000 addiu sp, sp, $FFC0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 sq t3, $0030(sp)
    0014 lui t0, $WhereThisIs
    0018 ori t0, t0, $WhereThisIs
    001c lui t1, $WhatI'mLookingFor
    0020 ori t1, t1, $WhatI'mLookingFor
    0024 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0028 beql t1, t2, $0001
    002c sw sp, $0068(t0)
    0030 addiu t3, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0034 beql t1, t3, $0001
    0038 sw sp, $0068(t0)
    003c lq t0, $0000(sp)
    0040 lq t1, $0010(sp)
    0044 lq t2, $0020(sp)
    0048 lq t3, $0030(sp)
    004c addiu sp, sp, $0040
    0050 beql/bnel/bltzl/blezl/bgtzl/bgezl/bc1tl/bc1fl $0003
    0054 load/store op
    0058 j $s6+$0008
    005c nop
    0060 j $BranchAddress + BranchOffset sll 2
    0064 nop
    0068 nop (sp will be stored here if it is found)
    }

    //----------------

    load/store op
    bltzal/bgezal
    load/store op

    becomes

    load/store op
    j $s4
    load/store op

    {
    0000 addiu sp, sp, $FFC0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 sq t3, $0030(sp)
    0014 lui t0, $WhereThisIs
    0018 ori t0, t0, $WhereThisIs
    001c lui t1, $WhatI'mLookingFor
    0020 ori t1, t1, $WhatI'mLookingFor
    0024 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0028 beql t1, t2, $0001
    002c sw sp, $006c(t0)
    0030 addiu t3, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0034 beql t1, t3, $0001
    0038 sw sp, $006c(t0)
    003c lq t0, $0000(sp)
    0040 lq t1, $0010(sp)
    0044 lq t2, $0020(sp)
    0048 lq t3, $0030(sp)
    004c addiu sp, sp, $0040
    0050 lui ra, $s6+$0008
    0054 bltz/bgez $0003 //This is correct.
    0058 ori ra, ra, $s6+$0008
    005c j $s6+$0008
    0060 nop
    0064 j $BranchAddress + BranchOffset sll 2
    0068 nop
    006c nop (sp will be stored here if it is found)
    }

    //----------------

    load/store op
    bltzall/bgezall
    load/store op

    becomes

    load/store op
    j $s4
    nop

    {
    0000 addiu sp, sp, $FFC0
    0004 sq t0, $0000(sp)
    0008 sq t1, $0010(sp)
    000c sq t2, $0020(sp)
    0010 sq t3, $0030(sp)
    0014 lui t0, $WhereThisIs
    0018 ori t0, t0, $WhereThisIs
    001c lui t1, $WhatI'mLookingFor
    0020 ori t1, t1, $WhatI'mLookingFor
    0024 addiu t2, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0028 beql t1, t2, $0001
    002c sw sp, $0070(t0)
    0030 addiu t3, "RegisterI'mChecking", $OffsetOfRegisterI'mChecking
    0034 beql t1, t3, $0001
    0038 sw sp, $0070(t0)
    003c lq t0, $0000(sp)
    0040 lq t1, $0010(sp)
    0044 lq t2, $0020(sp)
    0048 lq t3, $0030(sp)
    004c addiu sp, sp, $0040
    0050 lui ra, $s6+$0008
    0054 ori ra, ra, $s6+$0008
    0058 bltzl/bgezl $0003 //This is correct.
    005c load/store op
    0060 j $s6+$0008
    0064 nop
    0068 j $BranchAddress + BranchOffset sll 2
    006c nop
    0070 nop (sp will be stored here if it is found)
    }

    //----------------
    Last edited by bungholio; 02-11-2011, 01:37:35 PM.
    July 7, 2019

    https://www.4shared.com/s/fLf6qQ66Zee
    https://www.sendspace.com/file/jvsdbd

    Comment


    • #3
      What exactly is this code for? you didn't give much of a description

      Comment


      • #4
        I want to create a form of watchpoints that tell me which load and store operations use certain values/addresses. I completed the code to find load or store ops after instances of jr (jump return) operations and to create a little custom subroutine for it to check if the registers were a certain address. I need to figure out a way to dump memory from Silent Hill 3 because it's the perfect test I found since I noticed one of their ASM codes led to an address and a jump return before it.
        Last edited by bungholio; 01-04-2011, 01:30:01 PM.
        July 7, 2019

        https://www.4shared.com/s/fLf6qQ66Zee
        https://www.sendspace.com/file/jvsdbd

        Comment


        • #5
          Do you have a .pis file for it? Or care to explain in terms of pseudo code what is going on?

          I have a feeling it could be more optimised or you could possibly use a better method, but i'm definitely interested.

          Comment


          • #6
            So far, it looks for any store or load operations. When it finds them, it will immediately check the previous address to see if it is a "jr ??" operation. If so, it creates and replaces the "jr ??" operation with a custom subroutine for the code. The code converts the load or store operation into an "addiu" operation and checks if it is a certain address. If so, it stores the stack pointer just before the first line of the subroutine so it isn't blank and it can then find that that area of the game's ASM code used that address. I've noticed I already screwed up the "_Init". I just need to switch the order of the operations so the "s?" registers are stored before I create a thing for them. It's helping me slowly learn a little about ASM in between my weird episodes of depression and whatever else.

            I was thinking not to bother because there won't be enough space in memory for it if I completed it the way I wanted it, but I was just thinking to maybe somehow set it up to record what it is doing and undo it when needed to fix that problem (but make it a longer and more irritating process).
            Last edited by bungholio; 12-30-2010, 02:44:33 PM.
            July 7, 2019

            https://www.4shared.com/s/fLf6qQ66Zee
            https://www.sendspace.com/file/jvsdbd

            Comment


            • #7
              I'm just asking questions here out of curiosity.

              Is this game specific? is there a certain function that has a load/store code after a jr ra and you want to find out what the values of the variables used in the function are?

              Or is this supposed to be a more general "watch point" style code for any game?

              Comment


              • #8
                It's for any game. The plan was to make it find any load or store operation. Once it does, it would check the previous address to make sure it wasn't a jump or branch of some kind. If it was one, it would replace that jump/branch with a jump to a subroutine that was custom created for it to check if that store/load operation used a certain address. If there is no jump/branch before it, it would check the next address to see if it's another store/load operation. If it is, it would add that to the subroutine and check that too, and then check the next address. It keeps doing that until the next address is not a load/store operation, or another branch/jump.

                Basically, if there's a load/store op in the game, it would find it and make a jump to a custom subroutine for it, check if that uses a certain address, and if it does, store the stack pointer just before the subroutine so I'd know if it was used.

                It's nowhere near complete, and probably never will be since i need a way to test it. My only testing method would be ps2rd that would allow me to use 500 lines of code. I can't seem to dump with it. Can't dump, can't test or even use it.

                It's complete just enough so it should find every instance of this:
                "jr ??"
                "sb/sh/sw/lb/lbu/lh/lhu/lw/lwu/swc1/lwc1"
                It'll change that "jr ??" into a jump to a subroutine that converts the load/store into an "addiu" and check if it's a certain address.

                I'll probably continue to work on it at random times, even though I don't know why.
                July 7, 2019

                https://www.4shared.com/s/fLf6qQ66Zee
                https://www.sendspace.com/file/jvsdbd

                Comment

                Working...
                X