public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add MIPS UFR support
@ 2013-11-08 17:44 Andrew Bennett
  2013-11-30  9:59 ` Mike Frysinger
  0 siblings, 1 reply; 11+ messages in thread
From: Andrew Bennett @ 2013-11-08 17:44 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 2183 bytes --]

Hi,

This patch adds support to the MIPS backend to deal with changing the FR mode in user mode
(which I will now refer to as UFR).  The technical details are explained in the following paragraph.

The read only field UFR (at bit 28) in the floating point implementation register (CP1 control register 0) 
represents if the CPU supports UFR.  The UFR field (bit 2) in configuration register 5 (CP0 register 16, 
select 5) allows user mode to enable or disable UFR support.  The current value of the FR mode can be 
obtained if a read is made from the UFR register (CP1 control register 1), and UFR support is enabled.  
If register zero is written to the UFR register, and UFR support is enabled, then the FR mode is set to 0.  
If register zero is written to the UNFR register (CP1 control register 4), and the UFR support is enabled, 
then the FR mode is set to 1.  

To implement this I have firstly added the config 5 register to the simulator model, and added support to 
read and write to it.  Secondly, I have added support for the CTC1 and CFC1 instructions to write/read 
to/from the UFR and UNFR registers.

I have also added a testcase to validate the implementation.  To run the testcase you will need to apply 
the following binutils patch:

https://sourceware.org/ml/binutils/2013-11/msg00065.html


The simulator patch is attached to this email and the ChangeLog is shown below.  

This is my first patch to gdb, so I am unsure the protocol on committing.  Would someone be able to clarify?


Many thanks,



Andrew


2013-11-08  Andrew Bennett  <andrew.bennett@imgtec.com>
	sim/mips/
	* interp.c (ColdReset): Reset the config 5 register and
	set FCR0 to allow user mode FR switching instructions.
	(decode_coproc): Add support for reading and setting the config 5
	register.
	* mips.igen (CTC1c): Add UFR support.
	(CFC1c): Likewise.
	* sim-main.h (_sim_cpu): Add config 5 register and support macros.

	sim/testsuite/sim/mips/
	* basic.exp: Added ufr testcase.
	* ufr.s: New.


Andrew Bennett
Software Design Engineer, MIPS Processor IP
Imagination Technologies Limited
t: +44 (0)113 2429814
www.imgtec.com



[-- Attachment #2: gnusim-ufr.patch --]
[-- Type: application/octet-stream, Size: 4859 bytes --]

From 8712d51f325ce0e97c75716dc69579288adedb36 Mon Sep 17 00:00:00 2001
From: Andrew Bennett <andrew.bennett@imgtec.com>
Date: Thu, 7 Nov 2013 15:01:35 +0000
Subject: [PATCH] Add support for MIPS UFR.

---
 sim/mips/interp.c                |   17 ++++++++++++++++
 sim/mips/mips.igen               |   27 +++++++++++++++++++++++--
 sim/mips/sim-main.h              |    5 +++++
 sim/testsuite/sim/mips/basic.exp |    2 ++
 sim/testsuite/sim/mips/ufr.s     |   40 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 89 insertions(+), 2 deletions(-)
 create mode 100644 sim/testsuite/sim/mips/ufr.s

diff --git a/sim/mips/interp.c b/sim/mips/interp.c
index 032570a..b5958ac 100644
--- a/sim/mips/interp.c
+++ b/sim/mips/interp.c
@@ -1810,6 +1810,12 @@ ColdReset (SIM_DESC sd)
 	}
       if (BigEndianMem)
 	C0_CONFIG |= 0x00008000;	/* Big Endian */
+
+      /* Initialise the Config5 register. */
+      C5_CONFIG = 0;
+
+      /* User mode FR switching instructions supported */
+      FCR0 |= status_UFRP;
     }
 }
 
@@ -2349,6 +2355,17 @@ decode_coproc (SIM_DESC sd,
 #endif
 	      }
 	  }
+	/* This covers the case of reading and setting the Config5 register */
+	else if (((code == 0x00) || (code == 0x04))  /* MFC0 or MTC0 register 16 select 5 */
+	         && rd == 16  && ((tail & 0x07) == 5))
+	  {
+	    if (code == 0x00)
+	      GPR[rt] = C5_CONFIG;
+	    else if (FCR0 & status_UFRP)
+	      C5_CONFIG = GPR[rt];
+	    else
+	      C5_CONFIG = (GPR[rt] & ~config5_UFR);
+	  }
 	else if ((code == 0x00 || code == 0x01)
 		 && rd == 16)
 	  {
diff --git a/sim/mips/mips.igen b/sim/mips/mips.igen
index 5a6326f..5f271b8 100644
--- a/sim/mips/mips.igen
+++ b/sim/mips/mips.igen
@@ -4520,7 +4520,15 @@
       TRACE_ALU_INPUT1 (fcr);
       GPR[RT] = fcr;
     }
-  /* else NOP */
+  else if ((FS == 1) && (FCR0 & status_UFRP))
+    {
+      if (C5_CONFIG & config5_UFR)
+        GPR[RT] = (unsigned32) ((SR & status_FR) >> 26);
+      else
+        SignalException (ReservedInstruction, instruction_0);
+    }
+  else
+    Unpredictable ();
   TRACE_ALU_RESULT (GPR[RT]);
 }
 
@@ -4562,7 +4570,22 @@
   TRACE_ALU_INPUT1 (GPR[RT]);
   if (FS == 25 || FS == 26 || FS == 28 || FS == 31)
       StoreFCR (FS, GPR[RT]);
-  /* else NOP */
+  else if ((FS == 1) && (RT == 0) && (FCR0 & status_UFRP))
+    {
+      if (C5_CONFIG & config5_UFR)
+        SR &= ~status_FR;
+      else
+        SignalException (ReservedInstruction, instruction_0);
+    }
+  else if ((FS == 4) && (RT == 0) && (FCR0 & status_UFRP))
+    {
+      if (C5_CONFIG & config5_UFR)
+        SR |= status_FR;
+      else
+        SignalException (ReservedInstruction, instruction_0);
+    }
+  else
+    Unpredictable();
 }
 
 
diff --git a/sim/mips/sim-main.h b/sim/mips/sim-main.h
index b8c75c9..c520afe 100644
--- a/sim/mips/sim-main.h
+++ b/sim/mips/sim-main.h
@@ -407,6 +407,10 @@ struct _sim_cpu {
   unsigned_word c0_config_reg;
 #define C0_CONFIG ((CPU)->c0_config_reg)
 
+  unsigned_word c5_config_reg;
+#define C5_CONFIG ((CPU)->c5_config_reg)
+#define config5_UFR	(1 << 2) 	/* Allow user mode access to StatusFR */
+
 /* The following are pseudonyms for standard registers */
 #define ZERO    (REGISTERS[0])
 #define V0      (REGISTERS[2])
@@ -551,6 +555,7 @@ struct sim_state {
 #define status_CU1       (1 << 29)      /* Coprocessor 1 usable */
 #define status_CU2       (1 << 30)      /* Coprocessor 2 usable */
 #define status_CU3       (1 << 31)      /* Coprocessor 3 usable */
+#define status_UFRP      (1 << 28)      /* User mode FR switching instructions: 0 = not supported, 1 = supported */
 /* Bits reserved for implementations:  */
 #define status_SBX       (1 << 16)      /* Enable SiByte SB-1 extensions.  */
 
diff --git a/sim/testsuite/sim/mips/basic.exp b/sim/testsuite/sim/mips/basic.exp
index 1c78c87..be7284a 100644
--- a/sim/testsuite/sim/mips/basic.exp
+++ b/sim/testsuite/sim/mips/basic.exp
@@ -86,4 +86,6 @@ if {[istarget mips*-*-elf]} {
 
     run_sim_test mips32-dsp.s $dspmodels
     run_sim_test mips32-dsp2.s $dspmodels
+
+    run_sim_test ufr.s $submodels
 }
diff --git a/sim/testsuite/sim/mips/ufr.s b/sim/testsuite/sim/mips/ufr.s
new file mode 100644
index 0000000..1870827
--- /dev/null
+++ b/sim/testsuite/sim/mips/ufr.s
@@ -0,0 +1,40 @@
+# mips test ufr, expected to pass.
+# mach:	 mips32r2 mips64r2
+# as:		-mabi=eabi
+# ld:		-N -Ttext=0x80010000
+#output:	*\\npass\\n
+
+	.include "testutils.inc"
+
+	setup
+
+	.set noreorder
+
+	.ent DIAG
+DIAG:
+	writemsg "[1] Enable writing to FR"
+	li $2, 0x4
+	mfc0 $3, $16, 5
+	or $3, $3, $2
+	mtc0 $3, $16, 5
+	mfc0 $3, $16, 5
+	and $3, $3, $2
+	beq $3, $0, _fail
+	nop
+
+	writemsg "[2] Change to FR 0 mode"
+	ufr 0
+	cfc1 $2, $f1
+	bne $2, $0, _fail
+	nop
+
+	writemsg "[3] Change to FR 1 mode"
+	ufr 1
+	cfc1 $2, $f1
+	li $3, 1
+	bne $2, $3, _fail
+	nop
+
+	pass
+
+	.end DIAG
-- 
1.7.10.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-12-19 17:17 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-08 17:44 [PATCH] Add MIPS UFR support Andrew Bennett
2013-11-30  9:59 ` Mike Frysinger
2013-11-30 18:23   ` Maciej W. Rozycki
2013-12-09 16:45   ` Andrew Bennett
2013-12-18 15:36     ` Andrew Bennett
2013-12-18 20:07       ` Mike Frysinger
2013-12-19 17:17         ` Andrew Bennett
2013-12-19  4:37       ` Joel Brobecker
2013-12-19 10:50         ` Andrew Bennett
2013-12-19 10:59           ` Joel Brobecker
2013-12-19 11:03             ` Andrew Bennett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).