diff --git a/TODO b/TODO
index 69250b1692f795dcc108a43c15f201be476a5245..a38b5b3d0d30227426b777e1d7d6e1573cd0db28 100644
--- a/TODO
+++ b/TODO
@@ -231,7 +231,7 @@ o Build system
   Priority:    Low
 
   Description: Dependencies do not work correctly under configs/<board>/src
-               (same as arch/<arch>/src/board).
+               (same as arch/<arch>/src/board) with SDCC.
   Status:      Open
   Priority:    Medium
 
diff --git a/arch/z80/include/z80/irq.h b/arch/z80/include/z80/irq.h
index a187fd4c34429191a382fc1d625db3d11282cf9d..12dd502c12748bf9aa10336e06325dd0eb8132de 100644
--- a/arch/z80/include/z80/irq.h
+++ b/arch/z80/include/z80/irq.h
@@ -51,7 +51,7 @@
 
 /* Z80 Interrupts */
 
-#define Z80_IRQ_SYSTIMER (1)
+#define Z80_IRQ_SYSTIMER (0)
 #define NR_IRQS          (1)
 
 /* IRQ Stack Frame Format
diff --git a/arch/z80/src/common/up_head.asm b/arch/z80/src/common/up_head.asm
index 36a145be7f4f7749cc0be8be0f26478d560540eb..fd3bf20a10c4b0b7186aeacbeb93b429c20b31cd 100644
--- a/arch/z80/src/common/up_head.asm
+++ b/arch/z80/src/common/up_head.asm
@@ -111,15 +111,22 @@ forever:
 	push	af			; Offset 0: I with interrupt state in carry
 	di
 
-	 ; Call the interrupt decode logic. SP points to the beggining of the reg structure
+	; Call the interrupt decode logic. SP points to the beggining of the reg structure
+
 	ld	hl, #0			; Argument is the beginning of the reg structure
 	add	hl, sp			;
-	push	hl			;
+	push	hl			; Place argument at the top of thest
 	call	_up_decodeirq		; Decode the IRQ
 
+	; On return, HL points to the beginning of the reg structure to restore
+	; Note that (1) the argument pushed on the stack is not popped, and (2) the
+	; original stack pointer is lost.  In the normal case (no context switch),
+	; HL will contain the value of the SP before the argument was pushed.
+
+	ld	sp, hl			; Use the new stack pointer
+
 	; Restore registers.  HL points to the beginning of the reg structure to restore
 
-	ld	sp, hl			; Use the temp stack pointer
 	ex	af, af'			; Select alternate AF
 	pop	af			; Offset 0: AF' = I with interrupt state in carry
 	pop	bc			; Offset 1: BC
diff --git a/arch/z80/src/common/up_irq.c b/arch/z80/src/common/up_irq.c
index 5f8897a41660e9ad9f9f2fb0807ebb716ebc907e..ef7c8c1c61237b0ff0311fb00d6304b1f3d5b734 100644
--- a/arch/z80/src/common/up_irq.c
+++ b/arch/z80/src/common/up_irq.c
@@ -92,13 +92,14 @@ irqstate_t irqsave(void) __naked
 void irqrestore(irqstate_t flags) __naked
 {
   _asm
+	di			; Assume disabled
 	pop	hl		; HL = return address
 	pop	af		; AF Carry bit hold interrupt state
 	jr	nc, statedisable
 	ei
-	ret
 statedisable:
-	di
-	ret
+	push	af		; Restore stack
+	push	hl		;
+	ret			; and return
   _endasm;
 }
diff --git a/arch/z80/src/z80/chip.h b/arch/z80/src/z80/chip.h
index 9f85f1475ca1a60c5112857d04e51144e70106b7..d5c36bd19f43b47a25cebe0f5dda204144a6d809 100644
--- a/arch/z80/src/z80/chip.h
+++ b/arch/z80/src/z80/chip.h
@@ -45,6 +45,15 @@
  * Definitions
  ************************************************************************************/
 
+/* Bits in the Z80 FLAGS register */
+
+#define Z80_C_FLAG      0x01       /* Bit 0: Carry flag */
+#define Z80_N_FLAG      0x02       /* Bit 1: Add/Subtract flag  */
+#define Z80_PV_FLAG     0x04       /* Bit 2: Parity/Overflow flag */
+#define Z80_H_FLAG      0x10       /* Bit 4: Half carry flag */
+#define Z80_Z_FLAG      0x40       /* Bit 5: Zero flag */
+#define Z80_S_FLAG      0x80       /* Bit 7: Sign flag */
+
 /************************************************************************************
  * Public Function Prototypes
  ************************************************************************************/
diff --git a/configs/z80sim/defconfig b/configs/z80sim/defconfig
index 0603818d0bc556510a31e17e1a7f8cf2388d21af..a993a6aeb1fcfa22086074bc9a361da0fd602ff8 100644
--- a/configs/z80sim/defconfig
+++ b/configs/z80sim/defconfig
@@ -285,5 +285,5 @@ CONFIG_CUSTOM_STACK=n
 CONFIG_PROC_STACK_SIZE=1024
 CONFIG_PTHREAD_STACK_MIN=
 CONFIG_PTHREAD_STACK_DEFAULT=
-CONFIG_HEAP_SIZE=32768
-CONFIG_HEAP_BASE=CONFIG_DRAM_SIZE-CONFIG_HEAP_SIZE
+CONFIG_HEAP_SIZE=
+CONFIG_HEAP_BASE=
diff --git a/configs/z80sim/src/z80_irq.c b/configs/z80sim/src/z80_irq.c
index b6e81b32e1d2c3c671deba8ef05b0549a00cd7c4..5fd15035984effc7ef4439a2183da9443ec784d8 100644
--- a/configs/z80sim/src/z80_irq.c
+++ b/configs/z80sim/src/z80_irq.c
@@ -76,10 +76,21 @@ void up_irqinitialize(void)
 
   current_regs = NULL;
 
-  /* And finally, enable interrupts */
+  /* Attach the timer interrupt -- There is not special timer interrupt
+   * enable in the simulation so it must be enabled here before interrupts
+   * are enabled.
+   *
+   * NOTE:  Normally, there are seperate enables for "global" interrupts
+   * and specific device interrupts.  In such a "normal" case, the timer
+   * interrupt should be attached and enabled in the the function up_timerinit()
+   */
+
+  irq_attach(Z80_IRQ_SYSTIMER, (xcpt_t)up_timerisr);
+
+  /* And finally, enable interrupts (including the timer) */
 
 #ifndef CONFIG_SUPPRESS_INTERRUPTS
-  irqrestore(TRUE);
+  irqrestore(Z80_C_FLAG);
 #endif
 }
 
@@ -93,7 +104,7 @@ void up_irqinitialize(void)
 
 void up_disable_irq(int irq)
 {
-  irqrestore(FALSE);
+  irqrestore(0);
 }
 
 /****************************************************************************
diff --git a/configs/z80sim/src/z80_timerisr.c b/configs/z80sim/src/z80_timerisr.c
index e56678d13e0952f016c24415baa15e15add79cb7..a088d14b862fd0a3f26dbc77567f67c148dbe53d 100644
--- a/configs/z80sim/src/z80_timerisr.c
+++ b/configs/z80sim/src/z80_timerisr.c
@@ -91,5 +91,6 @@ int up_timerisr(int irq, FAR chipreg_t *regs)
 
 void up_timerinit(void)
 {
+  /* The timer interrupt was attached in up_irqinitialize -- see comments there */
 }
 
diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h
index 1de7138439f3c819abb29c04bd5f7969e64ce77e..3fa2eace633980f1585ebde1f9bc295bb197d7c4 100644
--- a/include/nuttx/sched.h
+++ b/include/nuttx/sched.h
@@ -268,7 +268,7 @@ typedef struct _TCB _TCB;
 
 /* This is the callback type used by sched_foreach() */
 
-typedef void (sched_foreach_t)(FAR _TCB *tcb, FAR void *arg);
+typedef void (*sched_foreach_t)(FAR _TCB *tcb, FAR void *arg);
 
 #endif /* __ASSEMBLY__ */
 
diff --git a/mm/mm_initialize.c b/mm/mm_initialize.c
index 95b8a20376d6cb1c3129cf208b45621ec9c95382..c7416eaacdf44848d9ed0e22ce9373353c1bce7c 100644
--- a/mm/mm_initialize.c
+++ b/mm/mm_initialize.c
@@ -162,7 +162,7 @@ void mm_addregion(FAR void *heapstart, size_t heapsize)
   heapend  = MM_ALIGN_DOWN((size_t)heapstart + (size_t)heapsize);
   heapsize = heapend - heapbase;
 
-  mlldbg("Region %d: base=%p size=%d\n", IDX+1, heapstart, heapsize);
+  mlldbg("Region %d: base=%p size=%u\n", IDX+1, heapstart, heapsize);
 
   /* Add the size of this region to the total size of the heap */