From 5f80286cc5325b59e078d971c0ac56b0a305f50f Mon Sep 17 00:00:00 2001
From: patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>
Date: Sat, 8 Mar 2008 21:19:39 +0000
Subject: [PATCH] Initial fixes for Z8Encore debug

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@726 42af7a65-404d-4744-a932-0658087f49c3
---
 arch/z80/src/common/up_allocateheap.c        | 12 +++--
 arch/z80/src/z8/z8_head.S                    | 29 ++++++------
 configs/z8encore000zco/ostest/ostest.linkcmd |  3 +-
 configs/z8encore000zco/ostest/ostest.zfpproj | 47 ++++++++++----------
 4 files changed, 50 insertions(+), 41 deletions(-)

diff --git a/arch/z80/src/common/up_allocateheap.c b/arch/z80/src/common/up_allocateheap.c
index 270e3e0d93..0ebb416e4e 100644
--- a/arch/z80/src/common/up_allocateheap.c
+++ b/arch/z80/src/common/up_allocateheap.c
@@ -61,7 +61,13 @@
  ****************************************************************************/
 
 /* For the ZiLOG ZDS-II toolchain(s), the heap will be set using linker-
- * defined values.
+ * defined values:
+ *
+ *   far_heapbot  : set to the offset to the first unused value in EDATA
+ *   far_stacktop : set to the highest address in EDATA
+ *
+ * The top of the heap is then determined by the amount of stack setaside
+ * in the NuttX configuration file
  */
 
 #ifdef __ZILOG__
@@ -70,8 +76,8 @@
 #    define CONFIG_HEAP1_BASE ((uint16)&far_heapbot)
 #  endif
 #  ifndef CONFIG_HEAP1_END
-     extern far unsigned long far_heaptop;
-#    define CONFIG_HEAP1_END ((uint16)&far_heaptop)
+     extern far unsigned long far_stacktop;
+#    define CONFIG_HEAP1_END (((uint16)&far_stacktop) - CONFIG_PROC_STACK_SIZE + 1)
 #  endif
 #endif
 
diff --git a/arch/z80/src/z8/z8_head.S b/arch/z80/src/z8/z8_head.S
index 49e0bd7565..63ff144829 100755
--- a/arch/z80/src/z8/z8_head.S
+++ b/arch/z80/src/z8/z8_head.S
@@ -92,8 +92,7 @@
 	xref	_len_pramseg
 	xref	_low_pram_romdata
 #endif
-	xref	_far_stack
-	xref	_near_stack
+	xref	_far_stacktop
 	xdef	_z8_reset
 	xdef	__intrp
 
@@ -128,8 +127,8 @@ _z8_reset:
 
 	/* Initialize the stack pointer */
 
-	ldx     spl, #low(_far_stack+1)
-	ldx     sph, #high(_far_stack+1)
+	ldx     spl, #low(_far_stacktop+1)
+	ldx     sph, #high(_far_stacktop+1)
 
 	/* Clear internal register ram area (c_nearbss) */
 
@@ -165,16 +164,20 @@ _z8_reset3:
 	/* Copy ROM data into internal RAM */
 
 _z8_reset4:
+#ifdef CONFIG_Z8_COPYNEARDATA
 	ld	r0, #high(_low_near_romdata)
 	ld	r1, #low(_low_near_romdata)
 	ld	r3, #_len_neardata
 	ld	r4, #_low_neardata
-	or	r3, r3
+	cp	r3, #0
+	jr	z, _z8_reset6
 
 _z8_reset5:
 	ldci	@r4, @rr0
 	djnz    r3, _z8_reset5
 
+_z8_reset6:
+#endif
 	/* Copy ROM data into extended RAM */
 
 	ld	r0, #high(_low_fardata)
@@ -186,19 +189,19 @@ _z8_reset5:
 
 	ld	r6, r4
 	or	r6, r5
-	jr	z, _z8_reset7
+	jr	z, _z8_reset8
 
-_z8_reset6:
+_z8_reset7:
 	ldc	r6, @rr2
 	ldx     @rr0, r6
 	incw	rr0
 	incw	rr2
 	decw	rr4
-	jr	nz, _z8_reset6
+	jr	nz, _z8_reset7
 
 	/* Copy ROM copy of code into Program RAM */
 
-_z8_reset7:
+_z8_reset8:
 #ifdef CONFIG_Z8_COPYPRAM
 	ld	r0, #high(_low_pramseg)
 	ld	r1, #low(_low_pramseg)
@@ -209,17 +212,17 @@ _z8_reset7:
 
 	ld	r6, r4
 	or	r6, r5
-	jr	z, _z8_reset9
+	jr	z, _z8_reset10
 
-_z8_reset8:
+_z8_reset9:
 	ldc	r6, @rr2
 	ldc     @rr0, r6
 	incw	rr0
 	incw	rr2
 	decw	rr4
-	jr	nz, _z8_reset8
+	jr	nz, _z8_reset9
 
-_z8_reset9:
+_z8_reset10:
 #endif
 
 	/* Start NuttX */
diff --git a/configs/z8encore000zco/ostest/ostest.linkcmd b/configs/z8encore000zco/ostest/ostest.linkcmd
index 4c291a67ed..befb1ac713 100755
--- a/configs/z8encore000zco/ostest/ostest.linkcmd
+++ b/configs/z8encore000zco/ostest/ostest.linkcmd
@@ -61,8 +61,7 @@ define _low_nearbss = base of NEAR_BSS
 define _len_nearbss = length of NEAR_BSS
 define _low_farbss = base of FAR_BSS
 define _len_farbss = length of FAR_BSS
-define _far_heaptop = highaddr of EDATA
-define _far_stack = highaddr of EDATA
+define _far_stacktop = highaddr of EDATA
 define _near_stack = highaddr of RDATA
 define _far_heapbot = top of EDATA
 define _near_heaptop = highaddr of RDATA
diff --git a/configs/z8encore000zco/ostest/ostest.zfpproj b/configs/z8encore000zco/ostest/ostest.zfpproj
index 0c65b6ec72..d46a19859b 100644
--- a/configs/z8encore000zco/ostest/ostest.zfpproj
+++ b/configs/z8encore000zco/ostest/ostest.zfpproj
@@ -1,8 +1,9 @@
 <project type="Standard" project-type="Standard" configuration="Debug" created-by="{{build_number}}" modified-by="b:4.10:06121401">
-<cpu>Z8F6423</cpu>
+<cpu>Z8F6403</cpu>
 
 <!-- file information -->
 <files>
+<file filter-key="">.\zsldevinit.asm</file>
 <file filter-key="flash">..\..\..\nuttx.hex</file>
 </files>
 
@@ -12,7 +13,7 @@
 <tools>
 <tool name="Assembler">
 <options>
-<option name="define" type="string" change-action="assemble">_Z8F6423=1,_Z8ENCORE_F642X=1</option>
+<option name="define" type="string" change-action="assemble">_Z8F6403=1,_Z8ENCORE_640_FAMILY=1,_Z8ENCORE_F640X=1</option>
 <option name="include" type="string" change-action="assemble"></option>
 <option name="list" type="boolean" change-action="none">true</option>
 <option name="listmac" type="boolean" change-action="none">false</option>
@@ -20,7 +21,7 @@
 <option name="pagelen" type="integer" change-action="none">56</option>
 <option name="pagewidth" type="integer" change-action="none">80</option>
 <option name="quiet" type="boolean" change-action="none">true</option>
-<option name="revaa" type="boolean" change-action="rebuild">false</option>
+<option name="revaa" type="boolean" change-action="rebuild">true</option>
 <option name="sdiopt" type="boolean" change-action="assemble">true</option>
 </options>
 </tool>
@@ -28,7 +29,7 @@
 <options>
 <option name="codegen" type="string" change-action="none">UserDefined</option>
 <option name="const" type="string" change-action="compile">RAM</option>
-<option name="define" type="string" change-action="compile">_Z8F6423,_Z16F_SERIES,_Z8ENCORE_F642X</option>
+<option name="define" type="string" change-action="compile">_Z8F6403,_Z16F_SERIES,_Z8ENCORE_640_FAMILY,_Z8ENCORE_F640X</option>
 <option name="genprintf" type="boolean" change-action="compile">true</option>
 <option name="keepasm" type="boolean" change-action="none">false</option>
 <option name="keeplst" type="boolean" change-action="none">true</option>
@@ -38,7 +39,7 @@
 <option name="optlink" type="boolean" change-action="compile">false</option>
 <option name="promote" type="boolean" change-action="compile">true</option>
 <option name="regvar" type="string" change-action="compile">Normal</option>
-<option name="regvarcache" type="string" change-action="none">false</option>
+<option name="regvarcache" type="string" change-action="none">Normal</option>
 <option name="reduceopt" type="boolean" change-action="compile">false</option>
 <option name="stdinc" type="string" change-action="compile"></option>
 <option name="usrinc" type="string" change-action="compile"></option>
@@ -47,8 +48,8 @@
 </tool>
 <tool name="Debugger">
 <options>
-<option name="target" type="string" change-action="rebuild">Z8F64200100KIT</option>
-<option name="debugtool" type="string" change-action="none">USBSmartCable</option>
+<option name="target" type="string" change-action="rebuild">Z8ENCORE00ZC0</option>
+<option name="debugtool" type="string" change-action="none">Simulator</option>
 <option name="zemul_enableevents" type="boolean" change-action="none">false</option>
 <option name="zemul_brkonfull" type="boolean" change-action="none">false</option>
 <option name="usepageerase" type="boolean" change-action="none">true</option>
@@ -85,7 +86,7 @@
 </tool>
 <tool name="Librarian">
 <options>
-<option name="outfile" type="string" change-action="build"></option>
+<option name="outfile" type="string" change-action="build">.\ostest.lib</option>
 </options>
 </tool>
 <tool name="Linker">
@@ -108,21 +109,21 @@
 <option name="quiet" type="boolean" change-action="none">false</option>
 <option name="rdata" type="string" change-action="build">20-FF</option>
 <option name="relist" type="boolean" change-action="build">false</option>
-<option name="rom" type="string" change-action="build">000000-007FFF</option>
+<option name="rom" type="string" change-action="build">0-FFF</option>
 <option name="sort" type="string" change-action="none">name</option>
-<option name="startuptype" type="string" change-action="build">1</option>
+<option name="startuptype" type="string" change-action="build">Standard</option>
 <option name="startuplnkcmds" type="boolean" change-action="build">true</option>
 <option name="undefisfatal" type="boolean" change-action="none">true</option>
 <option name="useadddirectives" type="boolean" change-action="build">false</option>
 <option name="usecrun" type="boolean" change-action="build">true</option>
 <option name="warnisfatal" type="boolean" change-action="none">false</option>
-<option name="warnoverlap" type="boolean" change-action="none">false</option>
+<option name="warnoverlap" type="boolean" change-action="none">true</option>
 <option name="xref" type="boolean" change-action="none">false</option>
 </options>
 </tool>
 <tool name="Middleware">
 <options>
-<option name="usezsl" type="boolean" change-action="rebuild">false</option>
+<option name="usezsl" type="boolean" change-action="rebuild">true</option>
 <option name="zslports" type="string" change-action="rebuild"></option>
 <option name="zsluarts" type="string" change-action="rebuild"></option>
 <option name="zslpramisrs" type="string" change-action="rebuild"></option>
@@ -134,7 +135,7 @@
 <tools>
 <tool name="Assembler">
 <options>
-<option name="define" type="string" change-action="assemble">_Z8F6423=1,_Z16F_SERIES=1,_Z8ENCORE_F642X=1</option>
+<option name="define" type="string" change-action="assemble">_Z8F6403=1,_Z16F_SERIES=1,_Z8ENCORE_640_FAMILY=1,_Z8ENCORE_F640X=1</option>
 <option name="include" type="string" change-action="assemble"></option>
 <option name="list" type="boolean" change-action="none">true</option>
 <option name="listmac" type="boolean" change-action="none">false</option>
@@ -150,17 +151,17 @@
 <options>
 <option name="codegen" type="string" change-action="none">UserDefined</option>
 <option name="const" type="string" change-action="compile">RAM</option>
-<option name="define" type="string" change-action="compile">_Z8F6423,_Z16F_SERIES,_Z8ENCORE_F642X</option>
+<option name="define" type="string" change-action="compile">_Z8F6403,_Z16F_SERIES,_Z8ENCORE_640_FAMILY,_Z8ENCORE_F640X</option>
 <option name="genprintf" type="boolean" change-action="compile">true</option>
 <option name="keepasm" type="boolean" change-action="none">false</option>
-<option name="keeplst" type="boolean" change-action="none">false</option>
+<option name="keeplst" type="boolean" change-action="none">true</option>
 <option name="list" type="boolean" change-action="none">false</option>
 <option name="listinc" type="boolean" change-action="none">false</option>
 <option name="model" type="string" change-action="compile">S</option>
 <option name="optlink" type="boolean" change-action="compile">false</option>
 <option name="promote" type="boolean" change-action="compile">true</option>
-<option name="regvar" type="string" change-action="compile">true</option>
-<option name="regvarcache" type="string" change-action="none">false</option>
+<option name="regvar" type="string" change-action="compile">Normal</option>
+<option name="regvarcache" type="string" change-action="none">Normal</option>
 <option name="reduceopt" type="boolean" change-action="compile">false</option>
 <option name="stdinc" type="string" change-action="compile"></option>
 <option name="usrinc" type="string" change-action="compile"></option>
@@ -170,7 +171,7 @@
 <tool name="Debugger">
 <options>
 <option name="target" type="string" change-action="rebuild"></option>
-<option name="debugtool" type="string" change-action="none">ZPAKII</option>
+<option name="debugtool" type="string" change-action="none">Simulator</option>
 <option name="zemul_enableevents" type="boolean" change-action="none">false</option>
 <option name="zemul_brkonfull" type="boolean" change-action="none">false</option>
 <option name="usepageerase" type="boolean" change-action="none">true</option>
@@ -199,7 +200,7 @@
 <tool name="General">
 <options>
 <option name="warn" type="boolean" change-action="none">true</option>
-<option name="debug" type="boolean" change-action="assemble">false</option>
+<option name="debug" type="boolean" change-action="assemble">true</option>
 <option name="debugcache" type="boolean" change-action="none">true</option>
 <option name="igcase" type="boolean" change-action="assemble">false</option>
 <option name="outputdir" type="string" change-action="compile">.</option>
@@ -230,21 +231,21 @@
 <option name="quiet" type="boolean" change-action="none">false</option>
 <option name="rdata" type="string" change-action="build">20-FF</option>
 <option name="relist" type="boolean" change-action="build">false</option>
-<option name="rom" type="string" change-action="build">000000-007FFF</option>
+<option name="rom" type="string" change-action="build">0-FFF</option>
 <option name="sort" type="string" change-action="none">name</option>
-<option name="startuptype" type="string" change-action="build">1</option>
+<option name="startuptype" type="string" change-action="build">Standard</option>
 <option name="startuplnkcmds" type="boolean" change-action="build">true</option>
 <option name="undefisfatal" type="boolean" change-action="none">true</option>
 <option name="useadddirectives" type="boolean" change-action="build">false</option>
 <option name="usecrun" type="boolean" change-action="build">true</option>
 <option name="warnisfatal" type="boolean" change-action="none">false</option>
-<option name="warnoverlap" type="boolean" change-action="none">false</option>
+<option name="warnoverlap" type="boolean" change-action="none">true</option>
 <option name="xref" type="boolean" change-action="none">false</option>
 </options>
 </tool>
 <tool name="Middleware">
 <options>
-<option name="usezsl" type="boolean" change-action="rebuild">false</option>
+<option name="usezsl" type="boolean" change-action="rebuild">true</option>
 <option name="zslports" type="string" change-action="rebuild"></option>
 <option name="zsluarts" type="string" change-action="rebuild"></option>
 <option name="zslpramisrs" type="string" change-action="rebuild"></option>
-- 
GitLab