Page 1 of 1

SYSTEM function for special register

Posted: Thu Oct 25, 2018 9:44 am
by Marc
Hi,

I want to set some registers which can be only accessed via MSR instructions.
So where can i find regarding SYSTEM functions for it ?

Thanks,
Marc

Re: SYSTEM function for special register

Posted: Thu Oct 25, 2018 10:16 am
by cfbsoftware
You can construct any 32-bit ARM Thumb-2 instruction (including illegal ones!) using SYSTEM.EMIT. See the source code of Traps.mod or Main.mod (Astrobe for Cortex-M4/M7 only) for examples of its use. Use at your own risk.

Re: SYSTEM function for special register

Posted: Thu Oct 25, 2018 10:26 am
by Marc
Yes I know, but why there exists a convenient SYSTEM.VMSR() function but not a more useful SYSTEM.MSR() ?

Re: SYSTEM function for special register

Posted: Thu Oct 25, 2018 10:38 am
by cfbsoftware
We were not aware that MSR is more useful than VMSR. What sort of applications are you hoping to use it for?

Re: SYSTEM function for special register

Posted: Thu Oct 25, 2018 10:42 am
by Marc
I'm developing on a bare metal M4 target (Apollo-2).
According to ARM prog. manual all the registers " APSR, IPSR, EPSR, IEPSR, IAPSR, EAPSR, PSR, MSP, PSP, PRIMASK, BASEPRI, BASEPRI_MAX, FAULTMASK, or CONTROL" are MSR /MRS accessible only , so quit alot ...

Re: SYSTEM function for special register

Posted: Thu Oct 25, 2018 10:44 am
by Marc
An application related example, is the global interrupt en/disable set in the PRIMASK register.

Re: SYSTEM function for special register

Posted: Thu Oct 25, 2018 12:00 pm
by cfbsoftware
OK - thanks for the info. I would use SYSTEM.EMIT in one-line helper procedures for specialised tasks such as these. I haven't tested the following but this should give you a good start. They rely on the fact that register r11 is used for single parameters / return results from leaf procedures. Use the gnu assembler gas to ascertain the hex value of each instruction.

Code: Select all

MODULE MSRExample;

IMPORT SYSTEM;

PROCEDURE* SetPRIMASK(i: INTEGER);
BEGIN
  (* MSR PRIMASK, r11 *)
  SYSTEM.EMIT(08BF31088H)
END SetPRIMASK;

PROCEDURE* SetBASEPRI(i: INTEGER);
BEGIN
  (* MSR BASEPRI, r11 *)
  SYSTEM.EMIT(08BF31188H)
END SetBASEPRI;

PROCEDURE* SetFAULTMASK(i: INTEGER);
BEGIN
  (* MSR FAULTMASK, r11 *)
  SYSTEM.EMIT(08BF31388H)
END SetFAULTMASK;

PROCEDURE* PRIMASK(): INTEGER;
VAR i: INTEGER;
BEGIN
  (* MRS r11, PRIMASK *)
  SYSTEM.EMIT(0EFF31088H);
  RETURN i
END PRIMASK;

PROCEDURE* BASEPRI(): INTEGER;
VAR i: INTEGER;
BEGIN
  (* MRS r11, BASEPRI *)
  SYSTEM.EMIT(0EFF31188H)
  RETURN i
END BASEPRI;

PROCEDURE* FAULTMASK(): INTEGER;
VAR i: INTEGER;
BEGIN
  (* MRS r11, FAULTMASK *)
  SYSTEM.EMIT(0EFF31388H)
  RETURN i
END FAULTMASK;

END MSRExample.

Re: SYSTEM function for special register

Posted: Thu Oct 25, 2018 12:41 pm
by Marc
This way round, it's rather tedious for every special register but okay, I understand.