Skip to content

[rsp] Introduce microcode build process, disassemble and build both rspboot versions#2764

Open
Thar0 wants to merge 6 commits into
zeldaret:mainfrom
Thar0:rsp-building
Open

[rsp] Introduce microcode build process, disassemble and build both rspboot versions#2764
Thar0 wants to merge 6 commits into
zeldaret:mainfrom
Thar0:rsp-building

Conversation

@Thar0

@Thar0 Thar0 commented May 30, 2026

Copy link
Copy Markdown
Collaborator

This PR introduces a build system for rsp microcodes, using armips as the assembler:

  • Microcode sources are in a new directory rsp/
  • Microcode sources are preprocessed with the C preprocessor
  • armips assembles the preprocessed source into separate text and data binary files
  • rsp2elf.s is a template file for assembling those binaries into a unified elf file for the microcode
  • The elf file is included in the spec for linking into the project

To exercise this build system, both variants of rspboot are included. The anti-piracy variant (rspboot_ap) is used in N64 versions while the non-anti-piracy variant (rspboot) is used in all others.

Other microcodes to come in future PRs.

@Pepe20129

Copy link
Copy Markdown
Contributor

Wouldn't it be better to combine rspboot.s & rspboot_ap.s and use #ifdefs?

@Thar0

Thar0 commented May 30, 2026

Copy link
Copy Markdown
Collaborator Author

The two files haven't got enough common text to warrant that, even the regular functions unrelated to anti-piracy measures were rewritten. I think once you get to just a single ifdef for all the code in a file it makes more sense to just have separate files at that point.

@Dragorn421 Dragorn421 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Build system looks good, I want to take a closer look at rspboot.s before merging

Can you document how you came up with the single file armips and from which revision of it

@Dragorn421 Dragorn421 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I find it mildly interesting that rspboot is assembled from origin IMEM_START_VA instead of IMEM_START like rspboot_ap

Comment thread rsp/rspboot.s Outdated
Comment thread rsp/rspboot_ap.s Outdated
Comment thread rsp/rspboot.s Outdated
Comment thread rsp/rspboot_ap.s
#include "sptask.h"
#include "rspboot.h"

#define OSTASK_FIELD(field) (-0x40 + OS_TASK_OFF_##field)($zero)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

for grepability I would personally prefer if this macro took the full OS_TASK_OFF_ macro name directly

Suggested change
#define OSTASK_FIELD(field) (-0x40 + OS_TASK_OFF_##field)($zero)
#define OSTASK_FIELD(fieldOffset) (-0x40 + fieldOffset)($zero)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't think it's worth prioritizing grep-friendliness over readability here, the latter should be the common case here

Comment thread rsp/rspboot_ap.s Outdated
Comment thread rsp/rspboot_ap.s Outdated
Comment thread rsp/rspboot.s Outdated
Comment on lines +45 to +47
// Return the semaphore and jump to the ucode that was loaded
jr $7
mtc0 $zero, SP_SEMAPHORE

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

where / by what was the semaphore acquired?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The semaphore can be released whether or not it was acquired, in which case it's a no-op. This is probably done for deadlock prevention, in case some previous task or the cpu had acquired the semaphore and failed to release it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Return the semaphore and jump to the ucode that was loaded
jr $7
mtc0 $zero, SP_SEMAPHORE
// Release the semaphore as a just-in-case measure and jump to the ucode that was loaded
jr $7
mtc0 $zero, SP_SEMAPHORE

?

Comment thread rsp/rspboot.s
Comment thread rsp/rspboot_ap.s Outdated
break

antipiracy_test:
// Checks that $4, $5, $6 and $11 all have expected register values set by IPL3

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Checks that $4, $5, $6 and $11 all have expected register values set by IPL3
// Checks that $4, $5, $6 and $11 all have expected register values set by the cic6105 microcode

afaik IPL3 never runs anything on the rsp (merely at some point the cpu executes from imem/dmem)

@Thar0 Thar0 Jun 13, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This isn't the case, IPL3 runs RSP code

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh 🤔 all flavors of it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not all, but the case we care about (X105) does

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we add a mention of X105 to this comment?

Comment thread rsp/rspboot_ap.s Outdated
@Pepe20129

Copy link
Copy Markdown
Contributor

Apparently it's possible to mark a file as auto-generated so that GitHub hides the changes by default by adding this to the .gitattributes file (docs):

tools/armips.cpp linguist-generated=true

@Dragorn421

Copy link
Copy Markdown
Collaborator

Apparently it's possible to mark a file as auto-generated so that GitHub hides the changes by default by adding this to the .gitattributes file (docs):

tools/armips.cpp linguist-generated=true

Thanks for the suggestion but I don't think we really need that
(I would also rather see changes to this file for security reasons)

@Pepe20129

Pepe20129 commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

(I would also rather see changes to this file for security reasons)

IIRC, it only collapses it by default, you can still expand it, it's mostly to avoid lagging out the ui when you don't want to see the changes in that file.

@Dragorn421 Dragorn421 added the Approved 2+ approvals, can be merged label Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved 2+ approvals, can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants