Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some arm7 interrupt documentation #201

Merged
merged 2 commits into from
Oct 28, 2023

Conversation

adakite1
Copy link
Contributor

I was working on some arm7 reversing and found some mirrored code between arm9 and arm7 where EnableIrqFlag and SetIrqFlag were being used, and from there I was able to find a few more arm9 interrupt functions in the arm7 as well. Interestingly although all of these ones are identical, the last interrupt function GetIrqFlag is not, and it does an and with a different mask, so I didn't include it here.

Also a note for all future arm7 documentation: I did a checksum on the arm7.bin of all three editions of EoS and they are all identical (SHA256 CB2A9B26D77A6E7D0ADD85C27E3642105918695D040D02F70D5EBC1D52C9495B), and since they are also all loaded at 0x2380000, addresses for all editions will be identical if the function is in the binary. There do appear to be some functions that seem to be written in during runtime though, so this might not apply for those ones.

@UsernameFodder
Copy link
Owner

Interestingly although all of these ones are identical, the last interrupt function GetIrqFlag is not, and it does an and with a different mask, so I didn't include it here.

If we know what the function is, can we just add it with a different name (doesn't have to be this PR though)? I think it's better to have it somewhere than not.

@UsernameFodder UsernameFodder self-requested a review October 28, 2023 02:31
Copy link
Owner

@UsernameFodder UsernameFodder left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks! I'm not 100% sure if I like duplicating the function names (since pmdsky.h has one global namespace), but seeing as these are actually mirrored functions, I suppose it's okay. We can revisit this later if needed.

@UsernameFodder UsernameFodder merged commit 7c10fa6 into UsernameFodder:master Oct 28, 2023
10 checks passed
@adakite1
Copy link
Contributor Author

Interestingly although all of these ones are identical, the last interrupt function GetIrqFlag is not, and it does an and with a different mask, so I didn't include it here.

If we know what the function is, can we just add it with a different name (doesn't have to be this PR though)? I think it's better to have it somewhere than not.

We can do that but only once we know a bit about its purpose, otherwise I'm not even sure what its name should be lol xP
It does an and with a really weird bitmask.

@Frostbyte0x70
Copy link
Collaborator

Where is that function located?

@adakite1
Copy link
Contributor Author

adakite1 commented Oct 29, 2023

Right after 02385f28h SetIrqFiqFlags, at 02385f40h. It looks similar to GetIrqFlag, but it gets all 5 lower bits of cpsr instead of the bit 7 (admittedly I'm not very familiar with the cpsr...) The functions following this don't seem to be related to interrupts, they don't touch the cpsr, and in fact the 2nd function following calls the registration function for ipc event handling of event type 0xc. The functions before also don't seem to touch cpsr, so it's kind of weird to me why there wouldn't be a GetIrqFlag function inside arm7, it seems like the correct thing to have here.

@Frostbyte0x70
Copy link
Collaborator

Bits 0 trhrough 4 contain the execution mode of the processor, so that's what the function seems to be returning. I'd call it GetProcessorMode.
From the No$GBA docs:

The Mode Bits M4-M0 contain the current operating mode.
  Binary Hex Dec  Expl.
  0xx00b 00h 0  - Old User       ;\26bit Backward Compatibility modes
  0xx01b 01h 1  - Old FIQ        ; (supported only on ARMv3, except ARMv3G,
  0xx10b 02h 2  - Old IRQ        ; and on some non-T variants of ARMv4)
  0xx11b 03h 3  - Old Supervisor ;/
  10000b 10h 16 - User (non-privileged)
  10001b 11h 17 - FIQ
  10010b 12h 18 - IRQ
  10011b 13h 19 - Supervisor (SWI)
  10111b 17h 23 - Abort
  11011b 1Bh 27 - Undefined
  11111b 1Fh 31 - System (privileged 'User' mode) (ARMv4 and up)
Writing any other values into the Mode bits is not allowed.

@adakite1
Copy link
Contributor Author

Bits 0 trhrough 4 contain the execution mode of the processor, so that's what the function seems to be returning. I'd call it GetProcessorMode. From the No$GBA docs:

The Mode Bits M4-M0 contain the current operating mode.
  Binary Hex Dec  Expl.
  0xx00b 00h 0  - Old User       ;\26bit Backward Compatibility modes
  0xx01b 01h 1  - Old FIQ        ; (supported only on ARMv3, except ARMv3G,
  0xx10b 02h 2  - Old IRQ        ; and on some non-T variants of ARMv4)
  0xx11b 03h 3  - Old Supervisor ;/
  10000b 10h 16 - User (non-privileged)
  10001b 11h 17 - FIQ
  10010b 12h 18 - IRQ
  10011b 13h 19 - Supervisor (SWI)
  10111b 17h 23 - Abort
  11011b 1Bh 27 - Undefined
  11111b 1Fh 31 - System (privileged 'User' mode) (ARMv4 and up)
Writing any other values into the Mode bits is not allowed.

I'll do a pr. Should I include this table in the description for reference?

@Frostbyte0x70
Copy link
Collaborator

Seems a bit excessive, it's general ARM knowledge. Maybe you could define an enum with each state and use it as the return type, but it might not be worth it.

@adakite1
Copy link
Contributor Author

Sure, I'll leave it out.

@adakite1 adakite1 deleted the arm7 branch October 29, 2023 12:51
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.

3 participants