code and constants in same segment

cancel
Showing results for 
Search instead for 
Did you mean: 

code and constants in same segment

312 Views
rlw
Contributor I

I am using CW 5.0 for S12X.

 

I have a large, constant table that is used only by a few functions, so I want to have both the table and those functions in their own segment:

 

#pragma CONST_SEG DISPATCH_SEG

const DispatchRec DIspatchTable[] = {

// entries in dispatch table

};

#pragma CONST_SEG DEFAULT_SEG

 

#pragma CODE_SEG DISPATCH_SEG

 

However, at the #pragma to place the functions, I get the error "Segment name already used"

 

I tried using DISPATCH_TABLE and DISPATCH_CODE, then placing them into the same section in the linker directives, but unless I define a section specifically for these 2 segments, the linker places them in different 16k banks. (The 2 segments total less than 16k).

 

Is there a way to get this to work without having to define a seperate section to hold these 2 segments? The reason I ask is that there are other table/function combinations I want to treat the same way, so if I have to define a section for each pair, I am then taking full control of the memory allocation for most of my application, which is a lot of extra work.

Labels (1)
Tags (1)
0 Kudos
3 Replies

114 Views
kef
Specialist I

However, at the #pragma to place the functions, I get the error "Segment name already used"


Probably linker needs code and data to go to different placement identities. Else, I guess, it wouldn't be able to count how much data you code your have, maybe other map file issues etc.

You don't need separate segment records (segments) for code and data in prm file, but you need separate placement records so that your data and functions are combined into the same ppage. I thing there's no other known way to force dedicated data and functions to the same ppage.

 

PLACEMENT

     mydata INTO PAGE_3A;
     mycode INTO PAGE_3A;

END

 

#pragma CONST_SEG mydata
static const int tab[]=
{
...

};
#pragma CONST_SEG DEFAULT

 

#pragma CODE_SEG mycode
int foo(int i)

{}
#pragma CODE_SEG DEFAULT

0 Kudos

114 Views
CrasyCat
Specialist III

Hello

 

When programming in ANSI C you cannot mix code and constants in the same section.

 

As kef indicated in his post, you can place code and constant section in the same memory area in the .prm file.

 

CrasyCat

0 Kudos

114 Views
rlw
Contributor I

Basically what I am doing.

 

(oops, I reversed the terms segment and section)

 

By shuffling the order of sections in the PLACEMENT section of the PRM, I was able to get both sections in the same 16k page, however, it seems the best way to avoid constant reshuffling is to place each table/function section pair is to allocate a segment for each pair, then place each pair into its designated segment:

 

SEGMENTS

    DISPATCH = READ_ONLY 0x7C0000'G TO 0x7C3FFF'G;

    TASKS = READ_ONLY 0x7C4000'G TO 0x7C7FFF'G;

// other segments

END

 

PLACEMENT

    DISPATCH_TABLE, DISPATCH_CODE INTO DISPATCH;

    TASKS_TABLE, TASKS_CODE INTO TASKS;

// other placements

END

 

As for restrictions on grouping code and data, I thought that restriction only applied to Read/Write data, not constant data. Besides, 1 and 2 byte constants are often "in lined" as immediate values.

0 Kudos