This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
H8300 Patch - Use 16 bit registers for pointer arithmetic in NORMAL MODE
- From: "Dhananjay R. Deshpande" <dhananjayd at KPITCummins dot com>
- To: <newlib at sources dot redhat dot com>
- Date: Tue, 28 Oct 2003 17:29:03 +0530
- Subject: H8300 Patch - Use 16 bit registers for pointer arithmetic in NORMAL MODE
Hi,
In NORMAL MODE of H8/300H and H8S, the pointer is 16 bit but currently pointer arithmetic
is done on 32 bit registers. As a result if the extended register is not zero, we get
wrong results.
Attached patch defines 16 bit pointer registers and uses substitute insns for adds and subs which are available only for 32 bit registers.
-Dhananjay
Changelog -
2003-10-28 Dhananjay Deshpande <dhananjayd@kpitcummins.com>
* libc/machine/h8300/defines.h : Correct pointer register defines for normal mode
* libc/machine/h8300/memcpy.S : Use add/sub instead of adds/subs for normal mode
* libc/machine/h8300/reg_memcpy.S : Likewise
* libc/machine/h8300/reg_memset.S : Likewise
* libc/machine/h8300/strcmp.S : Likewise
==============================================================================
diff -uprN newlib.old/libc/machine/h8300/defines.h newlib/libc/machine/h8300/defines.h
--- newlib.old/libc/machine/h8300/defines.h Fri Feb 18 01:09:46 2000
+++ newlib/libc/machine/h8300/defines.h Wed Sep 10 17:15:13 2003
@@ -44,6 +44,23 @@
#endif
#ifdef __H8300H__
+#ifdef __NORMAL_MODE__
+#define MOVP mov.w /* pointers are 16 bits */
+#define ADDP add.w
+#define CMPP cmp.w
+#define PUSHP push
+#define POPP pop
+
+#define A0P r0
+#define A1P r1
+#define A2P r2
+#define A3P r3
+#define S0P r4
+#define S1P r5
+#define S2P r6
+
+#else
+
#define MOVP mov.l /* pointers are 32 bits */
#define ADDP add.l
#define CMPP cmp.l
@@ -58,6 +75,8 @@
#define S1P er5
#define S2P er6
+#endif
+
#define A0E e0
#define A1E e1
#define A2E e2
@@ -65,6 +84,23 @@
#endif
#ifdef __H8300S__
+#ifdef __NORMAL_MODE__
+#define MOVP mov.w /* pointers are 16 bits */
+#define ADDP add.w
+#define CMPP cmp.w
+#define PUSHP push
+#define POPP pop
+
+#define A0P r0
+#define A1P r1
+#define A2P r2
+#define A3P r3
+#define S0P r4
+#define S1P r5
+#define S2P r6
+
+#else
+
#define MOVP mov.l /* pointers are 32 bits */
#define ADDP add.l
#define CMPP cmp.l
@@ -78,6 +114,8 @@
#define S0P er4
#define S1P er5
#define S2P er6
+
+#endif
#define A0E e0
#define A1E e1
diff -uprN newlib.old/libc/machine/h8300/memcpy.S newlib/libc/machine/h8300/memcpy.S
--- newlib.old/libc/machine/h8300/memcpy.S Wed Jun 25 01:13:58 2003
+++ newlib/libc/machine/h8300/memcpy.S Wed Sep 10 17:43:36 2003
@@ -23,7 +23,11 @@ _memcpy:
bne byteloop
wordloop:
+#ifdef __NORMAL_MODE__
+ sub #2,A1P
+#else
subs #2,A1P ; point to word
+#endif
mov.w @A1P,A2 ; get word
mov.w A2,@-A0P ; save word
CMPP A0P,A3P ; at the front again ?
@@ -31,7 +35,11 @@ wordloop:
rts
byteloop:
+#ifdef __NORMAL_MODE__
+ sub #1,A1P
+#else
subs #1,A1P ; point to byte
+#endif
mov.b @A1P,A2L ; get byte
mov.b A2L,@-A0P ; save byte
CMPP A0P,A3P ; at the front again ?
diff -uprN newlib.old/libc/machine/h8300/reg_memcpy.S newlib/libc/machine/h8300/reg_memcpy.S
--- newlib.old/libc/machine/h8300/reg_memcpy.S Wed Jun 25 01:13:58 2003
+++ newlib/libc/machine/h8300/reg_memcpy.S Wed Sep 10 17:44:08 2003
@@ -15,7 +15,12 @@ ___reg_memcpy:
beq quit
-loop: subs #1,A1P ; point to byte
+loop:
+#ifdef __NORMAL_MODE__
+ sub #1,A1P
+#else
+ subs #1,A1P ; point to byte
+#endif
mov.b @A1P,A2L ; get byte
mov.b A2L,@-A0P ; save byte
CMPP A0P,A3P ; at the front again ?
diff -uprN newlib.old/libc/machine/h8300/reg_memset.S newlib/libc/machine/h8300/reg_memset.S
--- newlib.old/libc/machine/h8300/reg_memset.S Wed Jun 25 01:13:58 2003
+++ newlib/libc/machine/h8300/reg_memset.S Wed Sep 10 17:44:54 2003
@@ -14,8 +14,13 @@ ___reg_memset:
memloop:
mov.b A1L,@A0P
+#ifdef __NORMAL_MODE__
+ add #1,A0P
+ sub #1,A2P
+#else
adds #1,A0P
subs #1,A2P
+#endif
MOVP A2P,A2P
bne memloop
diff -uprN newlib.old/libc/machine/h8300/strcmp.S newlib/libc/machine/h8300/strcmp.S
--- newlib.old/libc/machine/h8300/strcmp.S Wed Jun 25 01:13:58 2003
+++ newlib/libc/machine/h8300/strcmp.S Wed Sep 10 17:46:02 2003
@@ -14,7 +14,11 @@ _strcmp:
mov.b @A3P+,A0L
cmp.b A0L,A1L
beq .L5
+#ifdef __NORMAL_MODE__
+ sub #1,A3P
+#else
subs #1,A3P
+#endif
.L3:
mov.b @(-1,A2P),A0L
mov.b @A3P,A1L
==============================================================================