PowerPC goes to SPR variable

I am writing a build macro in a C program, and being completely new, I am stuck on something. I am trying to write a macro to move data from a general purpose to a special purpose register.

My problem is that the syntax that I found to move data from GPR to SPR takes on the value of the constant SPR, while I want to use a variable stored in a different register.

# SPR is constant, rA is the value to be written
mtspr SPR, rA

I'm for something like this:

# rA contains the number of the SPR, and rB the value to be moved.
AWESOMEmtspr rA, rB

Is there a reason this macro is not available, and how would I do it myself?

Thank you very much in advance.

---- Edit: ---- As it now looks, I have a giant switch case in my C code that jumps to the correct mtspr section. I have twenty separate read and write sections that contain SPR: s, each of which looks the same but has a constant value.

+3
source share
3 answers

, , , - register. , , , , . , , ( , , , OR ), . ( ).

, ? , SPR (, ), , , ,

MTPSR PSRx, val
RET
MTPSR PSRx+1, val
RET

, "", , . , NOP, , PowerPC, , .

+4

, :

#define stringify (s) tostring (s)

#define tostring (s) #s

#define mfspr (rn) ({unsigned int rval; \           asm volatile ( "mfspr% 0", stringify (rn) \                    : "= r" (rval)); RVAL;})

#define mtspr (rn, v) asm volatile ( "mtspr" stringify (rn) ",% 0":: "r" (v))

U-Boot PowerPC.

+1

, , - , , rA - mtspr. , SPR.

0

Source: https://habr.com/ru/post/1754395/


All Articles