cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing a skip-jump table

kevishu
Associate II
Posted on February 08, 2006 at 08:12

Implementing a skip-jump table

7 REPLIES 7
kevishu
Associate II
Posted on July 22, 2005 at 13:34

I'm trying to implement a skip-jump table for my IAP project but have not yet figured out how to write a function call (using C with Cosmic compiler) at a specific location in memory. For example, how do I write a function CALL at location 0xDFDC in memory.

I've already have the vector table (in sector 0) loaded with the correct addresses of where the function CALLS should be (in sector 2). I just don't know how to write those function calls.

AN1796 shows example of skip-jump table written in assembly, which is fine. But what they have doesn't work using the Cosmic compiler. This is what they have:

Here's a snipit of the code example:

segment byte at: FDD0 'program'

jp dummyisr

This appears to be exactly what I need, however, the ''segment byte at:'' command, which I assume forces the ''jp dummyisr'' command at that specific location (0xFDD0), is not recognized by Cosmic compiler. How do I effectively do the same type of thing with Cosmic. Also, is there a way to do this in C? I thought the ''@ 0xFDDC'' would somehow work, but am having no luck.

Hope someone can shed some light!

🙂

wolfgang2399
Associate II
Posted on July 25, 2005 at 07:59

There are two ways in C language to declaire a pointer to a function/procedure. With these pointers you can form a jump-table as you do it in the vectortable.

I give you an example:

- 1st declaration:

void (* const proc1[3])(void) =

{

Task_1, /* Task_1() to Task_3() are ... */

Task_2, /* ...void procedures, already declared anywhere before */

Task_3

};

- 2nd via typedef (already predefined in the systemheader stdtypes.h of the HiWare Compiler. Don't know how Cosmic does it.):

...

typedef void (*PROC)(void); /* parameterless function pointer (Procedure variable) */

.....

const PROC proc2[3] =

{

Task_1,

Task_2,

Task_3

};

const PROC proc3 = Task_1; /* single pointer */

....

And you call the procedures of your table with

.....

proc1[0]();

proc1[1]();

proc1[2]();

proc2[0]();

proc2[1]();

proc2[2]();

.....

or the single one

....

proc3();

....

Best regards

WoRo

luca239955_st
Associate III
Posted on July 26, 2005 at 06:43

Scooby,

please find below one possible way of addressing you problem (redirecting interrupt vectors for use with IAP).

It contains some inline assembler but I think it's more clear this way (I can give you a full C solution if needed).

Hope it helps.

Regards,

Luca (Cosmic)

*****************************************

try the following:

your vector table (file vector.c)

extern char INT_jump_table[];

char * const _vectab[] = {

INT_jump_table,

INT_jump_table + 3,

INT_jump_table + 6,

};

and the corresponding line in the linker file

+seg .const -b 0xffe0 # vectors start address

vector.o

your actual vectors should be defined as follows:

#pragma section(INT_JMP)

char INT_jump_table()

{

#asm

xref _irq_trap,_irq_sci,_irq_rtc;

jp _irq_trap // PWM ART

jp _irq_sci // SCI

jp _irq_rtc // MCC/RTC

#endasm

}

#pragma END

and the section placed in the linker file as

+seg .INT_JMP -b 0x1000

I've tried on my PC and it works as I think you expect; the vector addresses will be

ffe0 1000 bset

ffe2 1003 bset

ffe4 1006 bset

and at address 0x1000 you will find

1000 ccfaf7 jp _irq_trap

1003 ccfaf8 jp _irq_sci

1006 ccfaf9 jp _irq_rtc

Regards,

Luca

sergey3
Associate II
Posted on January 03, 2006 at 04:52

Quote:

On 26-07-2005 at 10:13, Anonymous wrote:

Scooby,

please find below one possible way of addressing you problem (redirecting interrupt vectors for use with IAP).

It contains some inline assembler but I think it's more clear this way (I can give you a full C solution if needed).

Hope it helps.

Regards,

Luca (Cosmic)

*****************************************

Hi Luca !

Can you send me please C solution of redirecting interrupt vectors for use with IAP ?

my email:

sergey@sysmop.com

Best regards !

luter
Associate II
Posted on February 07, 2006 at 09:08

Hello, _luca.

Could you provide me with code as well. I will be much appreciated.

my mail is :

mailto:andrei.kirys@erl-elektronik.de

Tnx.

luca239955_st
Associate III
Posted on February 08, 2006 at 08:06

Hi,

I'm afraid I have been a bit optimistic when talking about a ''full C solution''...

With reference to the original solution proposed above:

- the declaration of the jump table can only be done in assembler; I know no ways of having the compiler generate a list of jumps like that.

- the declaration of the vectors can be done in a different way, maybe more portable, but also less readable, in my opinion

Code:

typedef struct jump { // the typedef eases the next constructs

char jmp_code;

void (*addr);

} JUMP;

JUMP jump_table[10] @0x1000; // with the actual number of vectors

JUMP * const vectab[] = { // this is the processor vector table

&jump_table[0],

&jump_table[1],

&jump_table[2],

};

will generate the same code (actually, only a set of addresses) as the originally proposed

Code:

extern char INT_jump_table[];

char * const _vectab[] = {

INT_jump_table,

INT_jump_table + 3,

INT_jump_table + 6,

};

hope it helps.

Regards,

Luca (Cosmic)

luter
Associate II
Posted on February 08, 2006 at 08:12

Tnx for help.