From 329f0bd95d50fe9bd2d44f0a1899d428e0662a84 Mon Sep 17 00:00:00 2001
From: "Wesley W. Terpstra" <w.terpstra@gsi.de>
Date: Tue, 4 Oct 2011 13:12:51 +0200
Subject: [PATCH] Added a weak _debug_unit symbol to crt0.S.

When linked against debug.S, which provides this symbol, this will setup debugging.
If not linked against debug.S the symbol will be the same as _reset_handler.
---
 target/lm32/crt0.S | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/target/lm32/crt0.S b/target/lm32/crt0.S
index de7de225e..573c5ccf4 100755
--- a/target/lm32/crt0.S
+++ b/target/lm32/crt0.S
@@ -88,8 +88,9 @@
         .section    .boot, "ax", @progbits
 	
         .global	_start  
+        .weak _debug_unit
 _start: 
-	   
+_debug_unit:	   
         .global _reset_handler
         .type 	_reset_handler, @function
 _reset_handler:
@@ -127,6 +128,12 @@ _interrupt_handler:
 _crt0:
     /* Clear r0 */
     xor     r0, r0, r0
+
+    /* Setup the debug ROM if it's linked in */
+    mvhi    r1, hi(_debug_unit)
+    ori     r1, r1, lo(_debug_unit)
+    wcsr    DEBA
+
     /* Setup stack and global pointer */
     mvhi    sp, hi(_fstack)
     ori     sp, sp, lo(_fstack)
@@ -139,7 +146,7 @@ _crt0:
     mvhi    r3, hi(_ebss)
     ori     r3, r3, lo(_ebss)
     sub     r3, r3, r1
-    calli   memset
+    calli   memset
     mvi     r1, 0
     mvi     r2, 0
     mvi     r3, 0
-- 
GitLab