From 4da6d2b4141751f40b2cd92ef3efd94cdb6a2703 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20K=C3=BChling?= <dvdkhlng@gmx.de>
Date: Mon, 13 Feb 2012 00:03:51 +0100
Subject: [PATCH] Use GAS macros to assemble wcsr/rcsr opcodes for non-standard registers.

Now compiles with normal non-patched binutils.
---
 software/mmu-bios/crt0.S        |   13 ++++++---
 software/mmu-bios/csr-opcodes.h |   52 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 5 deletions(-)
 create mode 100644 software/mmu-bios/csr-opcodes.h

diff --git a/software/mmu-bios/crt0.S b/software/mmu-bios/crt0.S
index 67cdea7..18f8de3 100644
--- a/software/mmu-bios/crt0.S
+++ b/software/mmu-bios/crt0.S
@@ -22,10 +22,13 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-
+		
+	
 /* Exception handlers - Must be 32 bytes long. */
 .section    .text, "ax", @progbits
 .global     _start
+.include    "./csr-opcodes.h"
+	
 _start:
 _reset_handler:
 	xor	r0, r0, r0
@@ -133,19 +136,19 @@ loop:
 /* TLBVADDR = 0x00000000 */
 	xor r1, r1, r1
 	ori r1, r1, 0x0001
-	wcsr TLBVADDR, r1
+	WCSR_EXT CSR_TLBVADDR, 1
 /* TLBPADDR = 0x00001000 */
 	xor r1, r1, r1
 	ori r1, r1, 0x1001
-	wcsr TLBPADDR, r1
+	WCSR_EXT CSR_TLBPADDR, 1
 /* TLBCTRL = 0x80000010 which is cmd DTLB_UPDATE */
 	xor r1, r1, r1
 	ori r1, r1, 5
-	wcsr TLBCTRL, r1
+	WCSR_EXT CSR_TLBCTRL, 1
 /* TLBCTRL = 0x00000011 which is cmd DTLB_SWITCH_TO_USER_MODE */
 	xor r1, r1, r1
 	ori r1, r1, 0x0011
-	wcsr TLBCTRL, r1
+	WCSR_EXT CSR_TLBCTRL, 1
 /* Now DTLB should be active 
  * All accesses to virtual page 0 should be remapped to physical page 1
  */
diff --git a/software/mmu-bios/csr-opcodes.h b/software/mmu-bios/csr-opcodes.h
new file mode 100644
index 0000000..3eac7c4
--- /dev/null
+++ b/software/mmu-bios/csr-opcodes.h
@@ -0,0 +1,52 @@
+/* -*- asm -*-
+ *
+ * Macros to assemble LM32 CSR read/write instructions for *any* CSR, even the
+ * ones not supported by GNU binutils.
+ *
+ * Author: David Kühling <dvdkhlng TA gmx TOD de>
+ * Created: Feb 2012
+ *
+ * License: (at your opinion) GPLv2 or later or LM32 open-source license.
+ */
+
+	.set CSR_IE, 0 
+	.set CSR_IM, 1 
+	.set CSR_IP, 2 
+	.set CSR_ICC, 3 
+	.set CSR_DCC, 4 
+	.set CSR_CC, 5 
+	.set CSR_CFG, 6 
+	.set CSR_EBA, 7 
+	.set CSR_DC, 8 
+	.set CSR_DEBA, 9 
+	.set CSR_JTX, 14 
+	.set CSR_JRX, 15 
+	.set CSR_BP0, 16 
+	.set CSR_BP1, 17 
+	.set CSR_BP2, 18 
+	.set CSR_BP3, 19 
+	.set CSR_WP0, 24 
+	.set CSR_WP1, 25 
+	.set CSR_WP2, 26 
+	.set CSR_WP3, 27 
+	.set CSR_TLBCTRL, 28 
+	.set CSR_TLBVADDR, 29 
+	.set CSR_TLBPADDR, 30 
+	
+	/* usage:  WCSR_EXT  CSR_NR, REG_NR 
+	 * 
+	 * example: WCSR_EXT  CSR_IM, 7
+	 */ 
+	.macro WCSR_EXT dst_csr, src_reg
+	.word 0xD0000000+(\dst_csr<<21)+(\src_reg<<16)
+	.endm
+
+	/* usage:  RCSR_EXT  REG_NR, CSR_NR
+	 * 
+	 * example: RCSR_EXT  5, CSR_IM
+	 */ 
+	.macro RCSR_EXT dst_reg, src_csr
+	.word 0x90000000+(\src_csr<<21)+(\dst_reg<<11)
+	.endm
+
+	    
-- 
1.7.2.5

