Flags, no-operation and power
| Instruction | Encoding | Chip | What it does |
|---|---|---|---|
nop | 0000 0000 0000 1001 | SH-1 | Does nothing. The usual delay-slot filler. |
clrt | 0000 0000 0000 1000 | SH-1 | T = 0. |
sett | 0000 0000 0001 1000 | SH-1 | T = 1. |
clrmac | 0000 0000 0010 1000 | SH-1 | MACH = MACL = 0. |
clrs | 0000 0000 0100 1000 | SH-3 | S = 0 (no saturation in mac.w and mac.l). |
sets | 0000 0000 0101 1000 | SH-3 | S = 1. |
sleep | 0000 0000 0001 1011 | SH-1 | Stop the processor until an interrupt or a reset (the standby modes depend on the chip's registers). Privileged on SH-3 and later. |
ldtlb | 0000 0000 0011 1000 | SH-3 | Load the TLB entry chosen by MMUCR from PTEH, PTEL (and PTEA). Privileged. |
Control registers: LDC and STC
The ldc and stc instructions move the control registers SR, GBR and VBR (SH-1), SSR, SPC and the other-bank registers (SH-3), SGR and DBR (SH-4; the SH-4 can only read SGR with stc, writing it with ldc starts with the SH-4A). The
.l forms use memory with post-increment (ldc.l @Rm+,Reg) or pre-decrement (stc.l Reg,@-Rn), which is how an interrupt handler saves and restores registers on the stack.
In SH-3 and later every one of them except GBR is privileged.
| Instruction | Encoding | Chip | What it does |
|---|---|---|---|
ldc Rm,SRldc Rm,GBRldc Rm,VBRldc Rm,SSRldc Rm,SPCldc Rm,DBRldc Rm,Rb_BANK |
0100 mmmm 0000 11100100 mmmm 0001 11100100 mmmm 0010 11100100 mmmm 0011 11100100 mmmm 0100 11100100 mmmm 1111 10100100 mmmm 1bbb 1110 |
SH-1 SH-1 SH-1 SH-3 SH-3 SH-4 SH-3 | Load the control register from Rm. Rb_BANK is r0_bank to r7_bank: the register of the bank that is not selected by SR.RB. |
ldc.l @Rm+,SRldc.l @Rm+,GBRldc.l @Rm+,VBRldc.l @Rm+,SSRldc.l @Rm+,SPCldc.l @Rm+,DBRldc.l @Rm+,Rb_BANK |
0100 mmmm 0000 01110100 mmmm 0001 01110100 mmmm 0010 01110100 mmmm 0011 01110100 mmmm 0100 01110100 mmmm 1111 01100100 mmmm 1bbb 0111 |
SH-1 SH-1 SH-1 SH-3 SH-3 SH-4 SH-3 | Load the control register from the longword at Rm, then add 4 to Rm. |
stc SR,Rnstc GBR,Rnstc VBR,Rnstc SSR,Rnstc SPC,Rnstc SGR,Rnstc DBR,Rnstc Rb_BANK,Rn |
0000 nnnn 0000 00100000 nnnn 0001 00100000 nnnn 0010 00100000 nnnn 0011 00100000 nnnn 0100 00100000 nnnn 0011 10100000 nnnn 1111 10100000 nnnn 1bbb 0010 |
SH-1 SH-1 SH-1 SH-3 SH-3 SH-4 SH-4 SH-3 | Store the control register in Rn. |
stc.l SR,@-Rnstc.l GBR,@-Rnstc.l VBR,@-Rnstc.l SSR,@-Rnstc.l SPC,@-Rnstc.l SGR,@-Rnstc.l DBR,@-Rnstc.l Rb_BANK,@-Rn |
0100 nnnn 0000 00110100 nnnn 0001 00110100 nnnn 0010 00110100 nnnn 0011 00110100 nnnn 0100 00110100 nnnn 0011 00100100 nnnn 1111 00100100 nnnn 1bbb 0011 |
SH-1 SH-1 SH-1 SH-3 SH-3 SH-4 SH-4 SH-3 | Subtract 4 from Rn, then store the control register there. |
System registers: LDS and STS
The lds and sts instructions move MACH, MACL, PR and, on the SH-4, FPUL and FPSCR. They are not privileged.
On a chip without an FPU (the SH-4 and SH-4A without FPU, SH4_NOFPU, SH4A_NOFPU, and the chips before the SH-2E/SH-3E) lds, lds.l, sts and sts.l of FPUL and FPSCR are undefined, like the whole of line F: the SH-4A manual counts “the H'F*** instructions and the LDS (.L)/STS (.L) instructions using FPUL/FPSCR” as FPU instructions, and the SH-2A manual lists an FPU or FPU-related CPU instruction in a product with no FPU among the undefined codes. The decoder shows them as not available on those variants.
Loading FPSCR changes the SZ, PR and FR modes that decide how the floating-point instructions that follow read.
| Instruction | Encoding | Chip | What it does |
|---|---|---|---|
lds Rm,MACHlds Rm,MACLlds Rm,PRlds Rm,FPULlds Rm,FPSCR |
0100 mmmm 0000 10100100 mmmm 0001 10100100 mmmm 0010 10100100 mmmm 0101 10100100 mmmm 0110 1010 |
SH-1 SH-1 SH-1 SH-4 SH-4 | Load the system register from Rm. |
lds.l @Rm+,MACHlds.l @Rm+,MACLlds.l @Rm+,PRlds.l @Rm+,FPULlds.l @Rm+,FPSCR |
0100 mmmm 0000 01100100 mmmm 0001 01100100 mmmm 0010 01100100 mmmm 0101 01100100 mmmm 0110 0110 |
SH-1 SH-1 SH-1 SH-4 SH-4 | Load the system register from the longword at Rm, then add 4 to Rm. lds.l @r15+,pr is the usual function epilogue. |
sts MACH,Rnsts MACL,Rnsts PR,Rnsts FPUL,Rnsts FPSCR,Rn |
0000 nnnn 0000 10100000 nnnn 0001 10100000 nnnn 0010 10100000 nnnn 0101 10100000 nnnn 0110 1010 |
SH-1 SH-1 SH-1 SH-4 SH-4 | Store the system register in Rn. sts macl,Rn reads a multiplication result. |
sts.l MACH,@-Rnsts.l MACL,@-Rnsts.l PR,@-Rnsts.l FPUL,@-Rnsts.l FPSCR,@-Rn |
0100 nnnn 0000 00100100 nnnn 0001 00100100 nnnn 0010 00100100 nnnn 0101 00100100 nnnn 0110 0010 |
SH-1 SH-1 SH-1 SH-4 SH-4 | Subtract 4 from Rn, then store the system register there. sts.l pr,@-r15 is the usual function prologue. |
Privileged instructions
On SH-3 and later the processor is in user mode or privileged mode (SR.MD). In user mode the following raise a general illegal instruction exception:
ldc and stc (and their .l forms) of every register except GBR, rte, sleep, ldtlb. The SH-1 and SH-2 have no modes. The explorer notes "privileged" on these.
The list is the manuals' (SH-3 Rev. 4.00 section 6.1.11; the SH-4 core manual and the SH-4A Rev. 1.50 exception chapters): the privileged instructions are LDC, STC, RTE, LDTLB and SLEEP, excluding the LDC/STC instructions that access GBR; LDS and STS are not privileged. The instruction-cache and operand-cache instructions have their own rules on the cache page. LDC Rm,SR and LDC.L @Rm+,SR are additionally slot illegal (delay slots).
Exceptions, TRAPA and the vector offsets
The tables are from the SH-4A Software Manual (Rev. 1.50, 10/04, section 5) and agree with the SH-4 core manual where it has the same exception; the SH-1 and SH-2 use a vector table in memory indexed by the exception number, which was not read. In the SH-3 and later the handlers sit at fixed offsets from VBR; the exception code goes into EXPEVT (interrupts: INTEVT). On a general exception the processor saves PC in SPC, SR in SSR and (SH-4, SH-4A) R15 in SGR, sets SR.MD, SR.RB and SR.BL to 1 and jumps to VBR plus the offset.
| Exception | Vector offset | EXPEVT code |
|---|---|---|
| Power-on reset, H-UDI reset | PC = H'A0000000 | H'000 |
| Manual reset | PC = H'A0000000 | H'020 |
| TLB multiple hit (instruction or data) | PC = H'A0000000 | H'140 |
| User break before instruction | VBR + H'100 (or DBR) | H'1E0 |
| Instruction address error; data address error (read) | VBR + H'100 | H'0E0 |
| Data address error (write) | VBR + H'100 | H'100 |
| Instruction TLB miss; data TLB miss (read) | VBR + H'400 | H'040 |
| Data TLB miss (write) | VBR + H'400 | H'060 |
| Instruction TLB protection violation; data TLB protection violation (read) | VBR + H'100 | H'0A0 |
| Data TLB protection violation (write) | VBR + H'100 | H'0C0 |
| General illegal instruction | VBR + H'100 | H'180 |
| Slot illegal instruction | VBR + H'100 | H'1A0 |
| General FPU disable; slot FPU disable | VBR + H'100 | H'800; H'820 |
| FPU exception | VBR + H'100 | H'120 |
| Initial page write | VBR + H'100 | H'080 |
TRAPA (unconditional trap) | VBR + H'100 | H'160 |
| User break after instruction | VBR + H'100 (or DBR) | H'1E0 |
| Nonmaskable interrupt | VBR + H'600 | H'1C0 (in INTEVT) |
| General interrupt request | VBR + H'600 | (the interrupt code, in INTEVT) |
TRAPA. TRAPA #imm saves PC + 2 in SPC and SR in SSR, stores imm << 2 in the TRA register (the trap number times four), sets EXPEVT to H'160 and jumps to VBR + H'100; the handler reads TRA to find which trap it is. The SH-4 and SH-4A also save R15 in SGR. (On the SH-1 and SH-2 TRAPA takes its vector from the table in memory: entry number imm.)
MMU and cache registers (memory mapped)
These are not instruction operands; they are read and written as memory in the P4 area (the second address is the area-7 address through the TLB). From the SH-4A manual (Table 5.1, 7.1, 8.x):
| Register | Abbr. | P4 address | Role |
|---|---|---|---|
| Page table entry high | PTEH | H'FF000000 | virtual page number and ASID loaded into the TLB by ldtlb |
| Page table entry low | PTEL | H'FF000004 | the second register ldtlb loads into the TLB (ldtlb: PTEH/PTEL to TLB) |
| Translation table base | TTB | H'FF000008 | named in the manual; its use is the TLB handler’s |
| TLB exception address | TEA | H'FF00000C | the virtual address of the last MMU exception |
| MMU control | MMUCR | H'FF000010 | includes AT (address translation on: the virtual address space is mapped by the TLB when AT = 1) and SV; reset value 0 |
| TRAPA exception | TRA | H'FF000020 | the TRAPA operand times four |
| Exception event | EXPEVT | H'FF000024 | the exception code (0 after a power-on reset, H'20 after a manual reset) |
| Interrupt event | INTEVT | H'FF000028 | the interrupt code |
| Cache control | CCR | H'FF00001C | the cache control register (section 8.2.1 of the SH-4A manual); reset value 0 |
| Queue address control 0, 1 | QACR0, QACR1 | H'FF000038, H'FF00003C | named in the manual (8.2.2, 8.2.3) |
| On-chip memory control | RAMCR | H'FF000074 | named in the manual |
The bit layouts of these registers are not given here, and the SH-3 and SH-4 have the same register names at addresses that differ by chip (the SH-4 core manual and the Renesas SH-4 manual were not re-read for the addresses).
Not described
Known, not yet covered
- Reference and viewer: SH-2A control instructions (
ldc Rm,TBR,stc TBR,Rn,resbank,ldbank,stbank) and the DSP control registers.
Unknown
- Reference: the bit layouts of the MMU and cache registers, the SH-1 and SH-2 exception vector table, and the SH-3 and SH-4 (as opposed to SH-4A) register addresses and exception codes were not read.