SYSTEM function for special register

General discussions about working with the Astrobe IDE and programming ARM Cortex-M0, M3, M4 and M7 microcontrollers.
Post Reply
Marc
Posts: 6
Joined: Thu Oct 04, 2018 3:41 pm

SYSTEM function for special register

Post by Marc » Thu Oct 25, 2018 9:44 am

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

cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: SYSTEM function for special register

Post by cfbsoftware » Thu Oct 25, 2018 10:16 am

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.

Marc
Posts: 6
Joined: Thu Oct 04, 2018 3:41 pm

Re: SYSTEM function for special register

Post by Marc » Thu Oct 25, 2018 10:26 am

Yes I know, but why there exists a convenient SYSTEM.VMSR() function but not a more useful SYSTEM.MSR() ?

cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: SYSTEM function for special register

Post by cfbsoftware » Thu Oct 25, 2018 10:38 am

We were not aware that MSR is more useful than VMSR. What sort of applications are you hoping to use it for?

Marc
Posts: 6
Joined: Thu Oct 04, 2018 3:41 pm

Re: SYSTEM function for special register

Post by Marc » Thu Oct 25, 2018 10:42 am

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 ...

Marc
Posts: 6
Joined: Thu Oct 04, 2018 3:41 pm

Re: SYSTEM function for special register

Post by Marc » Thu Oct 25, 2018 10:44 am

An application related example, is the global interrupt en/disable set in the PRIMASK register.

cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: SYSTEM function for special register

Post by cfbsoftware » Thu Oct 25, 2018 12:00 pm

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.

Marc
Posts: 6
Joined: Thu Oct 04, 2018 3:41 pm

Re: SYSTEM function for special register

Post by Marc » Thu Oct 25, 2018 12:41 pm

This way round, it's rather tedious for every special register but okay, I understand.

Post Reply