UNDEF stack initialization fix for ARM GDB stub

Pavel Pisa ppisa4lists at pikron.com
Wed Dec 28 01:00:12 UTC 2005

Hello Jay and all others,

I have tried the serial ARM GDB stub from Jay some time ago,
but I have not been successfull with that so I tried to finish
porting of my previous system-less port of the Linux kernel debugger.

I have succeed with it on MX1 MCU. It hooks to the UNDEF exception
for compiled-in and debugger breakpoint support, it connects to
the FIQ and manages one of the serial ports to generate FIQ on the
character receiption. If the char is \003 (^C) it breaks into the
GDB stub core.

This is whole system controlling GDB stub => it does-not recognize
and limit breakpoints to the RTEMS threads. It is disadvantage
in some cases but it is not bad for RTEMS core and its drivers
debugging (MMC/SD fighting in my case).

The KGDB is licensed under strict GPL => it cannot be linked into final
applications but it can help to debug code during development.
I expect, that there should not be problem to port other version
of the ARM GDB stub to the RTEMS, when one is proved to work now.

The main problem, which probably prevent my test of Jay's stub
to work, has been missing initialization of the UNDEF mode stack.
I am sending patch with this code for CSB336 BSP. It can be simply
extended for all ARM targets. If there is possibility to integrate
it into RTEMS CVS, I can try to add this to other
ARM BSPs as well.

If there is interrest, I can put somewhere other pieces
of the KGDB port code, still not fully finished i.MX MMC/SD
code and more support code pieces (cache flushing, required
for stub and MMC/SD DMA transfers, the generic ARM exception
handler capable to store/restore state of all registers in the GDB
accessible form, etc).

I would be happy, if some of Jay's and my ARM targetted patches
can be integrated to the RTEMS CVS.

There is summary of patches I use against my last RTEMS-051009 checkout


The repository can be accessed through DARCS or patches
can be downloaded from next directory


The "series" file defines application order.
In the fact, it is my Quilt patch series control file.

I wish you all the best in the year 2006
(health, happiness in the family, enjoyment of work and non-broken
chips and MCUs)

Best wishes again

                Pavel Pisa
        e-mail: pisa at cmp.felk.cvut.cz
        www:    http://cmp.felk.cvut.cz/~pisa
        work:   http://www.pikron.com

Fix of missing initialize stack for UNDEF exception in the RTEMS ARM BSPs 
startup code.

This omission prevented debugger stubs to work.

Index: rtems-051009/c/src/lib/libbsp/arm/csb336/start/start.S
--- rtems-051009.orig/c/src/lib/libbsp/arm/csb336/start/start.S
+++ rtems-051009/c/src/lib/libbsp/arm/csb336/start/start.S
@@ -72,6 +72,13 @@ _bss_init:        
         ldr     sp, =_abt_stack
         add     sp, sp, r1
+        /* Enter UNDEF mode and set up the UNDEF stack pointer */
+        mov     r0, #(PSR_MODE_UNDEF | PSR_I | PSR_F)     /* No interrupts */
+        msr     cpsr, r0
+        ldr     r1, =_undef_stack_size
+        ldr     sp, =_undef_stack
+        add     sp, sp, r1
         /* Set up the SVC stack pointer last and stay in SVC mode */
         mov     r0, #(PSR_MODE_SVC | PSR_I | PSR_F)     /* No interrupts */
         msr     cpsr, r0
Index: rtems-051009/c/src/lib/libbsp/arm/csb336/startup/linkcmds
--- rtems-051009.orig/c/src/lib/libbsp/arm/csb336/startup/linkcmds
+++ rtems-051009/c/src/lib/libbsp/arm/csb336/startup/linkcmds
@@ -33,7 +33,8 @@ _sdram_size = DEFINED(_sdram_size) ? _sd
 _irq_stack_size = DEFINED(_irq_stack_size) ? _irq_stack_size : 0x1000;
 _fiq_stack_size = DEFINED(_fiq_stack_size) ? _fiq_stack_size : 0x400;
-_abt_stack_size = DEFINED(_abt_stack_size) ? _abt_stack_size : 0x100;
+_abt_stack_size = DEFINED(_abt_stack_size) ? _abt_stack_size : 0x400;
+_undef_stack_size = DEFINED(_undef_stack_size) ? _undef_stack_size : 0x400;
 _svc_stack_size = DEFINED(_svc_stack_size) ? _svc_stack_size : 0x1000;
@@ -167,6 +168,10 @@ SECTIONS
 	. += _abt_stack_size;
 	. = ALIGN (256);
+	_undef_stack = .;
+	. += _undef_stack_size;
+	. = ALIGN (256);
 	_irq_stack = .;
 	. += _irq_stack_size;

More information about the users mailing list