汎用レジスタ(r0〜r31)、CP0レジスタ、SFR:Special Function Registersのレジスタ群があり、その概要を示します。
| CPU Register | Symbolic | Register Usage |
|---|---|---|
| r0 | zero | Always ‘0’(Hardware enforced) |
| r1 | at | Assembler Temporary |
| r2 - r3 | v0-v1 | Function Return Values |
| r4 - r7 | a0-a3 | Function Arguments |
| r8 - r15 | t0-t7 | Temporary - Caller does not need to preserve contents |
| r16 - r23 | s0-s7 | Saved Temporary - Caller must preserve contents |
| r24 - r25 | t8-t9 | Temporary - Caller does not need to preserve contents |
| r26 - r27 | k0-k1 | Kernel temporary - Used for interrupt and exception handling |
| r28 | gp | Global Pointer - Used for fast-access common data |
| r29 | sp | Stack Pointer - Software stack |
| r30 | s8 or fp | Saved Temporary - Caller must preserve contents または Frame Pointer - Pointer to procedure frame on stack |
| r31 | ra | Return Address (Hardware enforced) |
| Register Number | Register Name | Function | 備考 |
|---|---|---|---|
| 0-6 | Reserved | M4K マイクロプロセッサ コア内で予約済み | |
| 7 | HWREna | Enables access via the RDHWR instruction to selected hardware registers. | |
| 8 | BadVAddr(1) | 直前に発生したアドレス関連の例外のアドレスを格納します。 | |
| 9 | Count(1) | Processor cycle count. | |
| 10 | Reserved | M4K マイクロプロセッサ コア内で予約済み | |
| 11 | Compare(1) | Timer interrupt control. | |
| 12 | Status(1) | Processor status and control. | |
| 12 | IntCtl(1) | Interrupt system status and control. | |
| 12 | SRSCtl(1) | Shadow register set status and control. | |
| 12 | SRSMap(1) | Provides mapping from vectored interrupt to a shadow set. | |
| 13 | Cause(1) | Cause of last general exception. | 直前の例外の原因を示す |
| 14 | EPC(1) | Program counter at last exception. | |
| 15 | PRId | Processor identification and revision. | |
| 15 | EBASE | Exception vector base register. | 割込みベクタのベースアドレス |
| 16 | Config | Configuration register. | |
| 16 | Config1 | Configuration Register 1. | |
| 16 | Config2 | Configuration Register 2. | |
| 16 | Config3 | Configuration Register 3. | |
| 17-22 | Reserved | M4K マイクロプロセッサ コア内で予約済み | |
| 23 | Debug(2) | Debug control and exception status. | |
| 24 | DEPC(2) | Program counter at last debug exception. | |
| 25-29 | Reserved | M4K マイクロプロセッサ コア内で予約済み | |
| 30 | ErrorEPC(1) | Program counter at last error. | |
| 31 | DESAVE(2) | Debug handler scratchpad register. |
unsigned int status = _CP0_GET_STATUS();// Status レジスタ(CP0 レジスタ12、Select 0)で[0x00100001]が得られる
unsigned int intctl = _CP0_GET_INTCTL();// IntCtl レジスタ(CP0 レジスタ12、Select 1)で[0x00000020]が得られる
この実行で、intctlに[0x00000020]得られると、bit 9-5 VS<4:0>: Vector Spacing bitsが0x01であることからベクタ間隔は32bitであると分かる。
_CP0_SET_COUNT(0);//コアタイマを0にセット(CP0の9番レジスタ)
_CP0_SET_COMPARE(2000000u);// コンペアレジスタに引数の値を設定(コアタイマがそれに達すると割り込み)
_CP0_BIC_DEBUG(_CP0_DEBUG_COUNTDM_MASK);// halt core timer and program at a debug breakpoint
//_CP0_SET_CAUSE(_CP0_GET_CAUSE() | _CP0_CAUSE_IV_MASK);//特殊な割り込みベクタ(0x200) を使う
| Peripheral | Virtual Address | 備考 | |
|---|---|---|---|
| Base | Offset Start | ||
| Watchdog Timer | 0xBF80 | 0x0000 | |
| RTCC | 0x0200 | ||
| Timer1-5 | 0x0600 | ||
| Input Capture 1-5 | 0x2000 | ||
| Output Compare 1-5 | 0x3000 | ||
| IC1 and IC2 | 0x5000 | ||
| SPI1 and SPI2 | 0x5800 | ||
| UART1 and UART2 | 0x6000 | ||
| PMP | 0x7000 | ||
| ADC | 0x9000 | ||
| CVREF | 0x9800 | ||
| Comparator | 0xA000 | ||
| CTMU | 0xA200 | ||
| Oscillator | 0xF000 | ||
| Device and Revision ID | 0xF220 | ||
| Peripheral Module Disable | 0xF240 | ||
| Flash Controller | 0xF400 | NVMCON,NVMKEY, | |
| Reset | 0xF600 | ||
| PPS | 0xFA04 | ||
| Interrupts | 0xBF88 | 0x1000 | |
| Bus Matrix | 0x2000 | ||
| DMA | 0x3000 | ||
| USB | 0x5050 | ||
| PORTA-PORTC | 0x6000 | ||
| Configuration | 0xBFC0 | 0x0BF0 | |
BMXDKPBA = 0x00002000;//8 KB のカーネルデータ (データRAM カーネルプログラム ベースアドレス レジスタ)
BMXDUDBA = 0x00008000;//24 KB のカーネルプログラム (データRAM ユーザデータベースアドレス レジスタ)
BMXDUPBA = 0x00008000;//ユーザデータのサイズ = 0、ユーザプログラムのサイズ = 0(データRAM ユーザプログラム ベースアドレス レジスタ)
BMXDKPBA = 0x00004000;//16 KB のカーネルデータ
BMXDUDBA = BMXDKPBA+0x0000C000;//48 KB のカーネルプログラム
BMXDUPBA = BMXDUDBA;//ユーザデータのサイズ = 0、ユーザプログラムのサイズ = 0
以上で、16Kをのカーネルデータ、残り48Kをプログラムに設定しています。
Kernel Program RAM Partition KSEG 0 48 KB は「0x80004000」から始まります。