Skip to content

Conversation

@cadmic
Copy link
Contributor

@cadmic cadmic commented Feb 26, 2025

I un-"bugged" this, the previous version didn't handle the delay slot (or rather, asserted the delay slot was a nop). I also did some light refactoring to help with N32. Tested on OoT

uint32_t jtbl_addr;
uint32_t num_cases;
rabbitizer::Registers::Cpu::GprO32 index_reg;
bool jtbl_is_pic;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any non-pic jumptable anywhere in IDO?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not currently, but there are in ld and strip as you know. I don't think it's N32-specific though, and technically the current logic can detect IDO non-PIC jumptables anyway but it wasn't wired up

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, I was thinking on the n32 programs

Comment on lines +544 to +545
} else if (srdata_vaddr <= case_addr && case_addr < srdata_vaddr + srdata_section_len) {
target_addr = read_u32_be(srdata_section + (case_addr - srdata_vaddr));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, are there actually any jumptables in srdata? Are those non-pic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there's one in strip:

    /* 016C4C 10016C4C 8F868024 */  lw          $a2, %got(jtbl_1002F8B8)($gp)
    /* 016C50 10016C50 DCA50050 */  ld          $a1, 0x50($a1)
    /* 016C54 10016C54 24C6F8B8 */  addiu       $a2, $a2, %lo(jtbl_1002F8B8)
    /* 016C58 10016C58 30A50007 */  andi        $a1, $a1, 0x7
    /* 016C5C 10016C5C 00052800 */  sll         $a1, $a1, 0
    /* 016C60 10016C60 2CA10008 */  sltiu       $at, $a1, 0x8
    /* 016C64 10016C64 00052880 */  sll         $a1, $a1, 2
    /* 016C68 10016C68 10200026 */  beqz        $at, .L10016D04
    /* 016C6C 10016C6C 00A62821 */   addu       $a1, $a1, $a2
    /* 016C70 10016C70 8CA60000 */  lw          $a2, 0x0($a1)
    /* 016C74 10016C74 00C00008 */  jr          $a2
    /* 016C78 10016C78 00000000 */   nop

It's not PIC, the jump table targets are absolute addresses (even though the jump table itself loaded via the GOT)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, it is pretty weird given the generated code should be position independent...

@AngheloAlf AngheloAlf merged commit 00d8cb0 into decompals:main Feb 27, 2025
8 checks passed
@cadmic cadmic deleted the jtbl-switch branch February 27, 2025 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants