OVP Forums - A community of assistance, help, questions, and answers.
  FAQFAQ    SearchSearch      RegisterRegister  ProfileProfile    Log in to check your private messagesLog in to check your private messages    Log inLog in
Memory Callback Functions Problems

 
Post new topic   Reply to topic    Open Virtual Platforms Forum Index -> Ask a Question
View previous topic :: View next topic  
Author Message
DominicChan



Joined: 21 Aug 2008
Posts: 15
Location: Hong Kong, China

PostPosted: Wed Nov 04, 2009 3:12 am    Post subject: Memory Callback Functions Problems Reply with quote

Dear Sir,

I created two memory write call back functions for two addresses (address_1 and address_2) for a processor.

In the address_1 call back function, I use icmWriteProcessorMemory to write to address_2.

And OVPSim craches. Does OVPSim distinguishes between a memory access from within a processor and from using icm functions?

I am trying to simulate a status register using address_2.

Please help,

Dominic
Back to top
View user's profile Send private message Visit poster's website
DuncGrah
OVP Technologist
OVP Technologist


Joined: 27 Feb 2008
Posts: 1646
Location: United Kingdom

PostPosted: Thu Nov 05, 2009 3:50 am    Post subject: Reply with quote

I created myself a small example platform that is doing what you describe. I even tried installing callbacks over a memory region using both the icmMapExternalMemory and icmAddWriteCallback API calls. Both methods are working with no problems in my example.

Can you provide a small example showing the problem?
Back to top
View user's profile Send private message Visit poster's website
DominicChan



Joined: 21 Aug 2008
Posts: 15
Location: Hong Kong, China

PostPosted: Thu Nov 05, 2009 10:30 pm    Post subject: Code Reply with quote

I am using OVPSim v20090319.0.

For the platform, I have two files:

platorm.c

Code:

#include <stdlib>
#include <stdio>

#include "icm/icmCpuManager.h"
#include "icm/icmMessage.h"

#define AUDIO_SIM_FLAGS (ICM_ATTR_SIMEX)  // (ICM_ATTR_SIMEX | ICM_ATTR_DEBUG)
#define HOST_SIM_FLAGS (ICM_ATTR_SIMEX | ICM_ATTR_DEBUG)

#define OVP_STACK_MEM       0x0003FFFF  /* SIZE = OVP_STACK_HI_ADD+1 (256KB) */
#define OVP_STACK_MAP       0xFFFC0000  /* stack will fill up to 0xFFFFFFFF */

#define OVP_PROG_DATA_MEM   0x000FFFFF  /* SIZE = OVP_PROG_DATA_MEM (1MB) */
#define OVP_PROG_DATA_MAP   0x00000000

#define OVP_SHARE_MEM       (0xFFFFFFFF-OVP_STACK_MEM-OVP_PROG_DATA_MEM-2)
#define OVP_SHARE_MAP       (OVP_PROG_DATA_MEM+1)

void OVP_FIFO_REG_init(icmProcessorP audio_processor, icmProcessorP host_processor);

/****************
 * The Platform
 ****************/
int main(int argc, char ** argv) {

    int  portNum;
    char *appAudio, *appHost;

   // check for the application program name argument
    if(argc!=4) {
        // incorrect arguments
        icmPrintf("Usage : %s <application> <application> <portnumber>\n", argv[0]);
        return -1;
    }

    appAudio = argv[1];
    appHost = argv[2];
    sscanf(argv[3], "%d", &portNum);

    // select library components
    const char *vlnvRoot = NULL; //When NULL use default library
    const char *model       = icmGetVlnvString(vlnvRoot, "ovpworld.org", "processor", "or1k", "1.0", "model");
    const char *semihosting = icmGetVlnvString(vlnvRoot, "ovpworld.org", "semihosting", "or1kNewlib", "1.0", "model");

    // initialize CpuManager
    icmInit(0, "localhost", portNum);

    //******************************************************************
    // create OVP components audio processor, memory and interrupt lines
    //******************************************************************
    // create AP (Audio) and HP (Host) processors
    icmProcessorP audio_processor = icmNewProcessor(
        "AP",               // CPU name
        "or1k",             // CPU type
        0,                  // CPU cpuId
        0,                  // CPU model flags
        32,                 // address bits
        model,              // model file
        "modelAttrs",       // morpher attributes
        AUDIO_SIM_FLAGS,    // instance attributes
        0,                  // user-defined attributes
        semihosting,        // semi-hosting file
        "modelAttrs"        // semi-hosting attributes
    );
    icmProcessorP host_processor = icmNewProcessor(
        "HP",               // CPU name
        "or1k",             // CPU type
        0,                  // CPU cpuId
        0,                  // CPU model flags
        32,                 // address bits
        model,              // model file
        "modelAttrs",       // morpher attributes
        HOST_SIM_FLAGS,    // instance attributes
        0,                  // user-defined attributes
        semihosting,        // semi-hosting file
        "modelAttrs"        // semi-hosting attributes
    );

    // create the processor buses
    icmBusP bus_host = icmNewBus("bus_host", 32);
    icmBusP bus_audio = icmNewBus("bus_audio", 32);

    // Host Memory
    icmMemoryP memory_host = icmNewMemory("mem_host", ICM_PRIV_RWX, OVP_PROG_DATA_MEM);
    icmMemoryP stack_host = icmNewMemory("stack_host", ICM_PRIV_RWX, OVP_STACK_MEM);

    // Audio Memory
    icmMemoryP memory_audio = icmNewMemory("mem_audio", ICM_PRIV_RWX, OVP_PROG_DATA_MEM);
    icmMemoryP stack_audio = icmNewMemory("stack_audio", ICM_PRIV_RWX, OVP_STACK_MEM);

    // Shared Memory
    icmMemoryP memory_share = icmNewMemory("mem_share", ICM_PRIV_RWX, OVP_SHARE_MEM);

    //**********************************************************************
    // end create OVP components audio processor, memory and interrupt lines
    //**********************************************************************

    //*******************************************************************
    // connect OVP components audio processor, memory and interrupt lines
    //*******************************************************************
    // connect processors onto the buses
    icmConnectProcessorBusses(host_processor, bus_host, bus_host);
    icmConnectProcessorBusses(audio_processor, bus_audio, bus_audio);

    // connect memory to the audio bus and host bus
    icmConnectMemoryToBus(bus_host, "mp1", memory_share, OVP_SHARE_MAP);
    icmConnectMemoryToBus(bus_audio, "mp2", memory_share, OVP_SHARE_MAP);

    icmConnectMemoryToBus(bus_host, "mp1", memory_host, OVP_PROG_DATA_MAP);
    icmConnectMemoryToBus(bus_host, "mp1", stack_host, OVP_STACK_MAP);

    icmConnectMemoryToBus(bus_audio, "mp1", memory_audio, OVP_PROG_DATA_MAP);
    icmConnectMemoryToBus(bus_audio, "mp1", stack_audio, OVP_STACK_MAP);

    // load the processors with application object file
    icmLoadProcessorMemory(audio_processor, appAudio, False, False, True);
    icmLoadProcessorMemory(host_processor, appHost, False, False, True);

    //***********************************************************************
    // end connect OVP components audio processor, memory and interrupt lines
    //***********************************************************************

    //*************************
    // show the bus connections
    //*************************
    icmPrintf("\nbus_host CONNECTIONS\n");
    icmPrintBusConnections(bus_host);icmPrintf("\n");
    icmPrintf("\nbus_audio CONNECTIONS\n");
    icmPrintBusConnections(bus_audio);icmPrintf("\n");

    OVP_FIFO_REG_init(audio_processor, host_processor);

    // simulate the platform
    icmSimulatePlatform();

    // free simulation data structures
    icmTerminate();

    return 0;
}


and ovp_fifo.c

Code:

#include <stdlib>
#include <stdio>

#include "icm/icmCpuManager.h"
#include "icm/icmMessage.h"

#define EC_AP_REG_BASE         0xFFFA0000
#define EC_AP_H2AC                0x0058
#define EC_AP_INTSTSAP          0x008C

ICM_MEM_WRITE_FN(watchWriteHost_H2AC)
{
    unsigned int val32;

    val32 = 1;

    icmReadProcessorMemory(processor,(EC_AP_REG_BASE+EC_AP_INTSTSAP),&val32,4);
    val32 = ~val32;
    icmWriteProcessorMemory(processor,(EC_AP_REG_BASE+EC_AP_INTSTSAP),&val32,4);
}


ICM_MEM_WRITE_FN(watchWriteAudio_INTSTSAP)
{
    unsigned int val32, reg32;

    val32 = *((unsigned int *) value);
    icmReadProcessorMemory(processor,(EC_AP_REG_BASE+EC_AP_INTSTSAP),&reg32,4);
    val32 = reg32 & ~val32;
    icmWriteProcessorMemory(processor,(EC_AP_REG_BASE+EC_AP_INTSTSAP),&val32,4);
}

void OVP_FIFO_REG_init(icmProcessorP audio_processor, icmProcessorP host_processor)
{

    icmAddWriteCallback(
        host_processor,                   // processor
        EC_AP_REG_BASE+EC_AP_H2AC,        // low address
        EC_AP_REG_BASE+EC_AP_H2AC+3,      // high address
        watchWriteHost_H2AC,              // callback to invoke
        "HOST write H2AC"                 // user data passed to callback
    );

   icmAddWriteCallback(
        audio_processor,                  // processor
        EC_AP_REG_BASE+EC_AP_INTSTSAP,    // low address
        EC_AP_REG_BASE+EC_AP_INTSTSAP+3,  // high address
        watchWriteAudio_INTSTSAP,         // callback to invoke
        "AUDIO write INTSTSAP"            // user data passed to callback
    );
}


For Host processor application:

host_main.c

Code:

#include <stdio>
#include <stdlib>

#define EC_AP_REG_BASE         0xFFFA0000
#define EC_AP_H2AC                   0x0058

#define REG32(add) *((volatile unsigned long *)(add))

int main ()
{
        REG32(EC_AP_REG_BASE + EC_AP_H2AC) = 1;  // invoke a callback function
}


and Audio processor application:

audio_main.c

Code:

#include <stdio>
#include <stdlib>

int main ()
{

    /* looping to wait for processing command from host */
    while(1);

}
Back to top
View user's profile Send private message Visit poster's website
DominicChan



Joined: 21 Aug 2008
Posts: 15
Location: Hong Kong, China

PostPosted: Wed Nov 11, 2009 1:56 am    Post subject: Reply with quote

In addition, gdb seems not be able to read the memory locations that are defined for a callback function.

e.g.

If I define:

icmAddWriteCallback(
host_processor,
EC_AP_REG_BASE+EC_AP_H2AC,
EC_AP_REG_BASE+EC_AP_H2AC+3,
watchWriteHost_H2AC,
"HOST write H2AC"
);

where EC_AP_REG_BASE is within the shared memory.

then gdb cannot read from EC_AP_REG_BASE. Adding a memory monitor at EC_AP_REG_BASE crashes platform.exe
Back to top
View user's profile Send private message Visit poster's website
KaMous



Joined: 17 Feb 2011
Posts: 9

PostPosted: Thu Nov 10, 2011 4:27 am    Post subject: Reply with quote

I know this thread is two years old, but I'm having the same problem. Using the ICM API to manually write memory from a callback fails, with the simulator crashing. I want to catch access to certain areas (preferably write access) and write something different to the memory address in order to simulate defective memory. Is there a non-tedious way to do that (i.e. using the ICM API as implemented by OVPsim)?
Back to top
View user's profile Send private message
KaMous



Joined: 17 Feb 2011
Posts: 9

PostPosted: Thu Nov 10, 2011 4:30 am    Post subject: Reply with quote

If it is more complicated than using the API, what do I need to do?
Back to top
View user's profile Send private message
DuncGrah
OVP Technologist
OVP Technologist


Joined: 27 Feb 2008
Posts: 1646
Location: United Kingdom

PostPosted: Thu Nov 10, 2011 5:12 am    Post subject: Reply with quote

When you use callbacks this is replacing the memory region over which the callback address is specified. So you cannot have both.

The best approach for what you want to achieve is to add an full MMC into the databus between the processor and the memory.
Use bridges to split the bus so that only the address range on which you want to create errors is mapped through the MMC because the MMC will have an impact on performance.
Within the MMC you can do 'anything' you wish to the address or data being read or written and hence manifest all forms of corruption.

I suggest you start by looking at the MMC ovpworld.org/mmc/endianSwap which uses an MMC to swap all data bytes.
Back to top
View user's profile Send private message Visit poster's website
KaMous



Joined: 17 Feb 2011
Posts: 9

PostPosted: Wed Nov 16, 2011 9:31 am    Post subject: Reply with quote

Thanks DuncGrah! This was what I was looking for. I have been able to do what I wanted to do with your help.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Open Virtual Platforms Forum Index -> Ask a Question All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Information regarding OVP © 2008-2022 Imperas Software