AnsweredAssumed Answered

VBR Not getting set properly on MCF2110

Question asked by HENRY MCDONALD on Sep 21, 2017
Latest reply on Sep 25, 2017 by TomE

This is a project I've inherited.  I'm seeing an issue where the VBR doesn't appear to be getting set correctly.

 

My linker script contains:

MEMORY {
vectorrom (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000500
code (RX) : ORIGIN = 0x00000500, LENGTH = 0x0001DB00
vectorram (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00000400
userram (RWX) : ORIGIN = 0x20000400, LENGTH = 0x00003B00
}
...
___VECTOR_RAM = ADDR(.vectorram);
...

And I have verified that mcf5xxx_startup() is getting called at startup:

asm void mcf5xxx_wr_vbr(unsigned long) { /* Set VBR */
move.l 4(SP),D0
movec d0,VBR
nop
rts
}

void mcf5xxx_startup(void)
{
extern __declspec(system) uint8 __DATA_ROM[];
extern __declspec(system) uint8 __DATA_RAM[];
extern __declspec(system) uint8 __DATA_END[];
extern __declspec(system) uint8 __BSS_START[];
extern __declspec(system) uint8 __BSS_END[];
extern __declspec(system) uint32 VECTOR_TABLE[];
extern __declspec(system) uint32 __VECTOR_RAM[];

register uint32 n;
register uint8 *dp, *sp;

if (__VECTOR_RAM != VECTOR_TABLE)
{
   for (n = 0; n < 256; n++)
     __VECTOR_RAM[n] = VECTOR_TABLE[n];
}
mcf5xxx_wr_vbr((uint32)__VECTOR_RAM);

// There's more stuff here, but the issue I'm trying to resolve is with the mcf5xxx_wr_vbr function
}

The problem that I'm seeing is that after mcf5xxx_wr_vbr is called, I think the VBR register is not 0x20000000 (I think the lowest 20 bits are don't-cares though).  Before mcf5xxx_wr_vbr((uint32)__VECTOR_RAM) is called, the debugger is showing register D0 as 0x00000684 and VBR as 0x20000134.  The disassembly of the function call shows that A0 is being loaded with 0x20000000, A0 is then written to D0, then the jump to the mcf5xxx_wr_vbr function is executed.  Once in mcf5xxx_wr_vbr, D0 is then overwritten when it already has what I want in it.

 

I'm tempted to just comment out the first line of  mcf5xxx_wr_vbr, but I'd like to understand what the issue is and why this project used to work before I started working on it.

Outcomes