Reboot on Exception?

Technical questions regarding the XTC tools and programming with XMOS.
ozel
Active Member
Posts: 45
Joined: Wed Sep 08, 2010 10:16 am

Post by ozel »

thanks for the quick reply!
I tried to do what you suggested, but I'm not shure if I'm doing it right.
I have now in reset.S:

Code: Select all

.text

.extern kernel1
.globl kernel1
.globl kernel1.nstackwords
.globl kernel1.maxthreads
.globl kernel1.maxtimers
.globl kernel1.maxchanends
.linkset kernel1.nstackwords, 1
.linkset kernel1.maxthreads,  0
.linkset kernel1.maxtimers,   0
.linkset kernel1.maxchanends, 0
.cc_top kernel1.func, kernel1

.align 128              // align the kernel section to 128 bytes
kernel1:                 // entry point for exceptions
    entsp 1             // increase current stack with 1 word
    bl ex_handler_1       // jump to the exception handler written in C
inf_loop1:
    // we do not expect to get here!
    bu inf_loop1

.cc_bottom kernel1.func

.extern kernel2
.globl kernel2
.globl kernel2.nstackwords
.globl kernel2.maxthreads
.globl kernel2.maxtimers
.globl kernel2.maxchanends
.linkset kernel2.nstackwords, 1
.linkset kernel2.maxthreads,  0
.linkset kernel2.maxtimers,   0
.linkset kernel2.maxchanends, 0
.cc_top kernel2.func, kernel2

.align 128              // align the kernel section to 128 bytes
kernel2:                 // entry point for exceptions
    entsp 1             // increase current stack with 1 word
    bl ex_handler_2       // jump to the exception handler written in C
inf_loop2:
    // we do not expect to get here!
    bu inf_loop2

.cc_bottom kernel2.func

.extern kernel3
.globl kernel3
.globl kernel3.nstackwords
.globl kernel3.maxthreads
.globl kernel3.maxtimers
.globl kernel3.maxchanends
.linkset kernel3.nstackwords, 1
.linkset kernel3.maxthreads,  0
.linkset kernel3.maxtimers,   0
.linkset kernel3.maxchanends, 0
.cc_top kernel3.func, kernel3

.align 128              // align the kernel section to 128 bytes
kernel3:                 // entry point for exceptions
    entsp 1             // increase current stack with 1 word
    bl ex_handler_3       // jump to the exception handler written in C
inf_loop3:
    // we do not expect to get here!
    bu inf_loop3

.cc_bottom kernel3.func

.extern kernel4
.globl kernel4
.globl kernel4.nstackwords
.globl kernel4.maxthreads
.globl kernel4.maxtimers
.globl kernel4.maxchanends
.linkset kernel4.nstackwords, 1
.linkset kernel4.maxthreads,  0
.linkset kernel4.maxtimers,   0
.linkset kernel4.maxchanends, 0
.cc_top kernel4.func, kernel4

.align 128              // align the kernel section to 128 bytes
kernel4:                 // entry point for exceptions
    entsp 1             // increase current stack with 1 word
    bl ex_handler_4       // jump to the exception handler written in C
inf_loop4:
    // we do not expect to get here!
    bu inf_loop4

.cc_bottom kernel4.func
and then for each core I do from XC main():

Code: Select all

asm("ldap r11, kernel1":::"r11");
asm("set kep, r11");

asm("ldap r11, kernel2":::"r11");
asm("set kep, r11");

asm("ldap r11, kernel3":::"r11");
asm("set kep, r11");

asm("ldap r11, kernel4":::"r11");
asm("set kep, r11");
please note, I had to replace "__asm__ __volatile__ ()" with asm(), otherwiese it wouldn't compile.


User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm
Contact:

Post by Bianco »

Can you upload a complete project with all the source code for me to test?
I suggest to start with one thread first, if that works, extend it to multiple threads/cores.
You don't need to write a new exception handler for each thread, they can use the same handler, it just needs to be set up for each thread individually.
ozel
Active Member
Posts: 45
Joined: Wed Sep 08, 2010 10:16 am

Post by ozel »

It works!
I misread your message and thought it's enough to install it only per core.
Just calling the two asm lines in each thread works, just as you discribed it.

Sorry, I can't upload the code. Currently I get different runtime errors in sc_ethernet (with nothing else on that core running), where I couldn't find out the reason.
So this tip is pure gold me. Thanks again!

(we aren't allowed to use xmos for nuclear reactors anyways, if I remember that license disclaimer correctly ;-)
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm
Contact:

Post by Bianco »

To do it properly the kernel actually should use the kernel stack which should be set up in advance and every thread should have its own kernel stack space (for when multiple threads are causing exceptions at the same time). This is because the tools do not know how much stack space the kernel needs. But for a reset it doesn't matter much i guess. Using the kernel stack makes calling regular C functions harder since they use the regular stack.
Post Reply