Hello kef,
thank you for the quick response. I din't expect to get any answer in 2008...
Sorry, I wasn't clear enough:
"movec d0,CPUCR" is part of asm void _startup(void) {...} which is shown in more detail below. The instruction is commented out as it never worked until now.
Yes, A5 is set to _SDA_BASE. Thank you for the tip with negative offsets, which allow also to near address data in the predefined short data.
But how are the short (A5-relative) addresses computed? It would of course be logical to compute them "near_address= address-_SDA_BASE". But it isn't mentioned anywhere in the documentation. As the program is translated and linked even when _SDA_BASE is not defined, this symbol cannot be the (only) used base. But when I define _SDA_BASE with different values, the near addresses change accordingly such that the effective addresses are correct. Examples:
Below you will find some lines of the source code with some dummy variable declarations and the linker control file. _SDA_BASE is defined one time to ff8000 (at the beginning of the first data segment) and the other time to ff801c, the beginning of .nzbss, a noninitialized data segment.
Code:
_SDA_BASE: ff8000 ff801c relative addresses of savedSRS 1C 0relative addresses of dummy 18 -4
Both variables which were accessed by near addresses get the correct relative addresses. The only difference between the 2 codes is the declaration of _SDA_BASE in the linker control file.
What happens when I use another symbol? I replaced the name _SDA_BASE by SDA_BASE2 (experimental computer sciences...
) and the realtive addresses were computed relative to ff8000.
This lets me assume that
- ff8000 (beginning of RAM) is used by default, but
- _SDA_BASE is used if it is defined.
This sounds simple, but I would really like to know if it is correct; I couldn't find it mentioned in any documentation.
Explicit near/far declarations are obviously ignored, for example the near word nw or components of the near byte array (code below) are accessed in far mode.
Even when addresses are correct, the values written into the simulated RAM by the simulator are simply wrong. But this will be an extra thread when I don't find out why.
Again, thank you!
Helmut
Code:
============================================================================Source file:At first some data declarations of different kinds: __declspec(nzbss) static byte savedSRS; /* not cleared during startup */// dummy variables to check addressing mode
static far long fl;static near word nw;static word dummy= 0x1667;static near byte nbarr[]= {1, 2, 3, 4, 5, 6, 7, 8, 9};static far word fwarr[]= {11, 22, 33, 44, 55};static far word fw= 0x1234;...asm void _startup(void) { move.w #0x2700,sr lea _SP_INIT,a7 movea.l #0,a6 link a6,#0 lea _SDA_BASE,a5 // move.l #0xc0000000,d0 // movec d0,CPUCR was "movec d0,0x802" both versions don't work jmp _hal_init}static void _hal_init(void) { asm (naked); savedSRS= SRS; SRS=0; /* translated to and executed as follows: MOVE.B 0xFFFF9800,D0 yields D0=82 (correct) MOVE.B D0,28(A5) simulator stores 00 at FFFF801C (wrong) CLR.B 0xFFFF9800 clears SRS (correct) */ ... nw= 0xaffe; // MOVE.W #-20482,D0 MOVW.W D0,FFFF8020 -->far
dummy= 0; // CLR.W 20(A5) correct (near)
nbarr[2]=254; // (MOVE.B #-2,D1 earlier) MOVE.B D1,FFFF8002 -->far
// the addresses are far, but correct. The values written into
// the simulated memory are wrong: nw= 0xC000, nbarr[2]= 0x04 ...
...
}============================================================================Linker control file:# Linker script for ColdFire MCF51JM128 - BadgeBoardRC Transmitter# Version 1.00 MEMORY { vectortable (RX) : ORIGIN = 0x00000000, LENGTH = 0x000003FE nonvolatile (R) : ORIGIN = 0x000003FE, LENGTH = 0x00000012 code (RX) : ORIGIN = 0x00000410, LENGTH = 0x0001FBF0 userram (RWX) : ORIGIN = 0xFFFF8000, LENGTH = 0x00004000}SECTIONS { ___RAM_ADDRESS = 0x00800000; ___RAM_SIZE = 0x00004000; ___FLASH_ADDRESS = 0x00000000; ___FLASH_SIZE = 0x00020000; ___heap_size = 0x0400; ___stack_size = 0x0400; .userram: {} > userram .code: {} > code .text: { OBJECT(__startup,startup.c) *(.text) .=ALIGN (4); *(.rodata) .=ALIGN (4); __DATA_ROM=.; } >> code .data: AT(__DATA_ROM) { .=ALIGN (4); __SDA_BASE=.; .=ALIGN(4); __DATA_RAM=.; *(.data) .=ALIGN (4); *(.sdata) .=ALIGN (4); __DATA_END=.; .=ALIGN (4);# __SDA_BASE=.; } >> userram .bss:{ # uninitialized data, shall be zeroed out in startup .=ALIGN (4); *(.nzbss) .=ALIGN (4); __START_BSS=.; *(.sbss) .=ALIGN (4); *(.bss) .=ALIGN (4); __END_BSS=.; __BSS_SIZE=__END_BSS -__START_BSS; . = ALIGN(4); } >> userram .custom: { __SP_END = .; __SP_INIT = __SP_END + ___stack_size; .=ALIGN (4); } >> userram}