最近想把DSP核的exception 使用起来。遇到了以下的问题:
1仿真器调试时,通过代码制造内部异常 Internal exception, 异常发生时,可以成功调用预先在cfg中配置好的hook函数,也可以看见控制台打印得异常信息。
打印信息里包含了异常发生时B26~B31核寄存器以及IEER、NRP等寄存器的值。
问题是:异常发生时,我希望能够通过全局变量的方式将打印出来的这些寄存器值保存下来,已经做实验,除了B26~B31寄存器,其余的寄存器都可以直接读取并保存,请问如何访问保存B26~B31寄存器的值?
2 在保存了这些值的基础上,对我来说,我希望能够在异常发生时,异常中断服务程序中保存的B26~B31以及其他的IEER寄存器等信息,用于问题定位,B26~B31寄存器应该如何分析?
xiaxia gong:
其实我的目的就是为了在异常发生时能够获知现场信息,以帮助寻找BUG,想请教大牛,如何才能达到这个目的?
Tony Tang:
回复 xiaxia gong:
哈哈,你把问题发到这了,那我就在这里回答你吧。下在是我在e2e上找到的回复,以前也有人问过类似问题。总的来说,建议不要做,因为通用寄存器一直在不停的变化,尤其是C语言代码,用户不清楚到底用了哪些通用寄存器。所以下面说了,如果非要做,就写一段汇编去把寄存器存下来,因为写汇编时,寄存器的使用是由用户控制的,比较好控制。
https://e2e.ti.com/support/embedded/tirtos/f/355/t/445395
I think the best thing to do is to write a function in assembly to dump the registers to a structure, which you can then access from C code. If you try using inline assembly within a C function you’ll probably have lots of problems as the compiler moves values in/out of registers for its own purposes.
For a starting point, you can pull some code from one of the Exception source files and modify that. For example, open the file Exception_asm.s64P in the “src/ti/sysbios
/family/c64p” subdirectory of your SYS/BIOS installation. Look at the code in the function “_ti_sysbios_family_c64p_Exception_dispatch__E”. There is code here for handling the exception, but you can extract out just the code that saves the A and B-side registers into a structure, and put that in our own assembly function, which you can call from C to fill up the structure.
https://e2e.ti.com/support/microcontrollers/stellaris_arm/f/471/t/263786
You can define where the stack starts in memory. If you ensure that you have nothing, or a known quantity on the stack at a given time (have fun with doing that), you can trigger an interrupt in software and the aforementioned registers will be in memory at known offsets from your known stack pointer. Then all you have to do is set a pointer variable to SP-offset, read/write the pointed-to address, and end the interrupt.
Do not do this if anyone is paying or grading you for the resulting program 🙂 It would be difficult/tedious to write and verify a useful C program that would play nice with the stack. Use the debugger to read registers, or if you must do it in a program, assembly instead.