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
How to write into memory
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Open Virtual Platforms Forum Index -> Getting started
View previous topic :: View next topic  
Author Message
IlyaKorobkov



Joined: 24 May 2013
Posts: 27
Location: Saint-Petersburg, Russia

PostPosted: Thu Aug 28, 2014 6:09 am    Post subject: How to write into memory Reply with quote

Hello,

I want to create platform consisting of: CPU (for example, MIPS32 4KEp), Memory and bus between them, Applicfation. Application should be simple: read and write bytes into Memory.

Could you give me advices what demo, examples I should have a look. May be you have some experience how to do it.

I have explored demo of MIPS32, memory (Imperas/Examples/Platforms/memory).

As I understood there is only one way how to Application can write data into Memory. It is icmMapExternalMemory . Is it right?

Please explain how to write into Memory. It will be very good if you can give me some code-examples.
Back to top
View user's profile Send private message Visit poster's website
LeeMoore
OVP Technologist
OVP Technologist


Joined: 27 Feb 2008
Posts: 635

PostPosted: Mon Sep 01, 2014 1:28 am    Post subject: Reply with quote

Hi,

I am not sure what you are asking.

An application reads and writes memory by performing loads/stores.

The platform can create memory which is simulated internally by the simulator, or mapped to an external memory outside of the simulator.
In either case the access to this memory by the application is the same, ie using loads/stores.

Maybe you need to explain your requirement in a little more detail

Thx
Lee
Back to top
View user's profile Send private message
IlyaKorobkov



Joined: 24 May 2013
Posts: 27
Location: Saint-Petersburg, Russia

PostPosted: Tue Sep 02, 2014 11:20 pm    Post subject: Reply with quote

LeeMoore Thank you for the reply!

I understood about application that reads/writes data into memory.

Really I want to create a platform that will have MIPS32, bus, Memory and My SystemC/TLM module.

Here is the architectural diagram.



My application will read/write data into Memory by means of pointer.
For example:
Code:
int main()
{
    unsigned int *p = (unsigned int) 0x00400000;  //pointer
    *p = 0x11; p++;
    *p = 0x22; p++;
    *p = 0x33; p++;

    return 1;
}


LeeMoore, is it correct example how to write data into memory?


The matter of fact I don't know how to connect My SystemC/TLM module to Bus. Could you please recommend to read some manuals or code examples from Imperas?
Back to top
View user's profile Send private message Visit poster's website
LeeMoore
OVP Technologist
OVP Technologist


Joined: 27 Feb 2008
Posts: 635

PostPosted: Wed Sep 03, 2014 9:53 am    Post subject: Reply with quote

Hi,

There are a number of TLM examples available - do none of these work as a starting point for your example ?

I would suggest looking at one of the system TLM demos such as
Imperas/Demo/OVPsim_linux_MipsMalta_tlm2.0

Thx
Lee
Back to top
View user's profile Send private message
DuncGrah
OVP Technologist
OVP Technologist


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

PostPosted: Fri Sep 05, 2014 4:51 am    Post subject: Reply with quote

You may want to also look at Imperas/Examples/Platforms/SystemC_TLM2.0. This is a platform examples with a processor and a UART peripheral.
Back to top
View user's profile Send private message Visit poster's website
IlyaKorobkov



Joined: 24 May 2013
Posts: 27
Location: Saint-Petersburg, Russia

PostPosted: Fri Sep 05, 2014 5:38 am    Post subject: Reply with quote

I woulk like to ask one more question about access to memory via application.

I created very simple platform with MIPS32 4KEp. This is the main function of my platform. This platform has no bus and any external memory.

Code:
int main(int argc, char **argv) {

    parseArgs(argc, argv);

    // initialize OVPsim, enabling verbose mode to get statistics at end of execution
    unsigned int icmAttrs = ICM_VERBOSE | ICM_STOP_ON_CTRLC;

    if(autoGDBConsole) {
        icmAttrs |= ICM_GDB_CONSOLE;
    }
    icmInit(icmAttrs, enableDebug ? "rsp" : 0, portNum);

    // Select components from library
    const char *vendorP = selectVendor();
    const char *mipsModel    = icmGetVlnvString(NULL, vendorP, "processor", "mips32", "1.0", "model");
    const char *mipsSemihost = icmGetVlnvString(NULL, vendorP, "semihosting", "mips32Newlib", "1.0", "model");


    // Enable debugging for this processor if requested
    unsigned int simAttrs = ICM_ATTR_DEFAULT;

    // Setup the configuration attributes for the MIPS model
    icmAttrListP userAttrs = icmNewAttrList();
    icmAddStringAttr(userAttrs, "endian", "little" );     // setup endianess
    icmAddStringAttr(userAttrs, "variant", variant);    // Select the processor configuration

    // create a processor instance
    icmProcessorP processor = icmNewProcessor(
        "cpu0"  ,           // CPU name
        "MIPS",             // CPU type
        0,                  // CPU cpuId
        0,                  // CPU model flags
        32,                 // address bits
        mipsModel,          // model file
        "modelAttrs",       // morpher attributes
        simAttrs,           // attributes
        userAttrs,          // user-defined attributes
        mipsSemihost,       // semi-hosting file
        "modelAttrs"        // semi-hosting attributes
    );


    if(!icmLoadProcessorMemory(processor, application,  ICM_LOAD_DEFAULT, False, True)) {     
        return -1;
    }


    //icmIgnoreMessage ("MIPS32_IAS_COP0_READ");      // Ignore specific Info messages
    //icmIgnoreMessage ("MIPS32_IAS_COP0_WRITE");


    icmProcessorP final = icmSimulatePlatform();      // simulate the platform

    // was simulation interrupted or did it complete
    if(final && (icmGetStopReason(final)==ICM_SR_INTERRUPT)) {
        icmPrintf("*** simulation interrupted\n");
    }
   
    icmTerminate(); // Finish simulating

    return 0;
}


I wrote very simple application that allocate memory step by step by 1 Kbyte. Application code is here.
Code:
int main()
{     
    unsigned int Kbyte;
    unsigned int total = 0, n = 1024;
    unsigned char *p;
    printf("\n\n");
    for (Kbyte = 1; Kbyte < 5*1024; Kbyte++) {
        p = (unsigned char *) malloc(n * sizeof(unsigned char));
        total = total + n;
        if (p == NULL)  {
            printf("         GOOD: %.2f MB, %.2f KB, %u bytes\n", (total-n)/(1024*1024.0), (total-n)/1024.0, total-n);
            printf("NOT ALLOCATED: %.2f MB, %.2f KB, %u bytes\n", total/(1024*1024.0), total/1024.0, total);
            break;
        }
        else {
            if (total%((1024*1024)) == 0)
                printf("         GOOD: %.2f MB, %.2f KB, %u bytes\n", total/(1024*1024.0), total/1024.0, total);
        }
    }
    printf("\n\n");
   
    return 0;
}


I launched the platform with 4KEp variant of processor MIPS32.
I got this log.
Code:
         GOOD: 1.00 MB, 1024.00 KB, 1048576 bytes         
         GOOD: 2.00 MB, 2048.00 KB, 2097152 bytes
         GOOD: 3.00 MB, 3072.00 KB, 3145728 bytes
         GOOD: 4.00 MB, 4096.00 KB, 4194304 bytes
         GOOD: 4.96 MB, 5077.00 KB, 5198848 bytes
NOT ALLOCATED: 4.96 MB, 5078.00 KB, 5199872 bytes


I suppose my application successfully allocated 5077.00 KB. To allocate more memory it was impossible.

Then I added bus and memory into my platform.
Code:
icmBusP bus = icmNewBus("bus", 32);
icmConnectProcessorBusses(processor, bus, bus);
icmMemoryP local = icmNewMemory("local", ICM_PRIV_RWX, 0xffffffff/2);
icmConnectMemoryToBus(bus, "mp1", local, 0);

icmPrintBusConnections(bus);


Unfortunately my application couldn't allocate more memory than at first case. Here is the last log.
Code:
BUS MASTERS: 2
   PORT 'DATA' of 'cpu0'
   PORT 'INSTRUCTION' of 'cpu0'
BUS SLAVES: 1
   0x00000000:0x7fffffff: PORT 'mp1' of 'local'
   0x80000000:0xffffffff: xxxxxxxx unmapped xxxxxxxx
       
         GOOD: 1.00 MB, 1024.00 KB, 1048576 bytes       
         GOOD: 2.00 MB, 2048.00 KB, 2097152 bytes       
         GOOD: 3.00 MB, 3072.00 KB, 3145728 bytes       
         GOOD: 4.00 MB, 4096.00 KB, 4194304 bytes       
         GOOD: 4.96 MB, 5077.00 KB, 5198848 bytes
NOT ALLOCATED: 4.96 MB, 5078.00 KB, 5199872 bytes


Could you please explain why I couldn't allocate more memory? It's very interesting for me.
Back to top
View user's profile Send private message Visit poster's website
LeeMoore
OVP Technologist
OVP Technologist


Joined: 27 Feb 2008
Posts: 635

PostPosted: Fri Sep 05, 2014 6:19 am    Post subject: Reply with quote

Hi

What compiler did you use to build the application ?

This is nothing to do with the simulator, this is the program execution of malloc and the compiler libc, failing to allocate any more memory.

does the compiler have an option to alter the heap/stack sizes ?

The available memory provided by the simulator will be 2**n where n is the address bus width

Thx
Lee
Back to top
View user's profile Send private message
IlyaKorobkov



Joined: 24 May 2013
Posts: 27
Location: Saint-Petersburg, Russia

PostPosted: Fri Sep 05, 2014 6:38 am    Post subject: Reply with quote

mingw32-C++.exe (GCC) 3.4.2
Back to top
View user's profile Send private message Visit poster's website
LeeMoore
OVP Technologist
OVP Technologist


Joined: 27 Feb 2008
Posts: 635

PostPosted: Fri Sep 05, 2014 6:42 am    Post subject: Reply with quote

Hi

I think you misunderstand the question:

Quote:
I wrote very simple application that allocate memory step by step by 1 Kbyte. Application code is here.

What compiler did you use to build the application ?

mingw32 is your host compiler which you use to build the simulator, but you have compiled a program to run on a model of MIPS32. This compiler must have some restrictions on the heap & stack sizes.

Thx
Lee
Back to top
View user's profile Send private message
IlyaKorobkov



Joined: 24 May 2013
Posts: 27
Location: Saint-Petersburg, Russia

PostPosted: Sun Sep 07, 2014 10:59 pm    Post subject: Reply with quote

Okey, Lee.
To compile MIPS32 applications I downloaded and installed mips-2014.05-24-mips-sde-elf.exe

Is it O'key?
Back to top
View user's profile Send private message Visit poster's website
AdminiStrator
Site Admin
Site Admin


Joined: 11 Feb 2008
Posts: 94

PostPosted: Mon Sep 08, 2014 12:13 am    Post subject: Reply with quote

I compiled this program using 2 compilers

1. mips sde
2. codesourcery mips

when I use (1), then it does not report a problem with malloc()
when I use (2) it reports the same problem you describe.

This seems to differ with your findings, becaue you say you are using the mips sde toolchain. Can you please confirm this is the case, because I do not reproduce what you are reporting.

If indeed you are using the codesourcery toolchain, then I would make a guess that there is a compiler switch to increase the amount of heap whcih can be allocated, I suggest you contact code sourcery, or take a detailed look at the compiler documentation.

I am confident the model and the simulation is wrking correctly, the issue is the compiled executable.

Thx
Lee
Back to top
View user's profile Send private message Send e-mail
IlyaKorobkov



Joined: 24 May 2013
Posts: 27
Location: Saint-Petersburg, Russia

PostPosted: Mon Sep 08, 2014 12:29 am    Post subject: Reply with quote

Dear Lee,

The matter of fact I use MIPS toolchain from CodeSourcery (Lite Edition). Could you give me the url from where I can download mips sde?
Back to top
View user's profile Send private message Visit poster's website
LeeMoore
OVP Technologist
OVP Technologist


Joined: 27 Feb 2008
Posts: 635

PostPosted: Mon Sep 08, 2014 12:58 am    Post subject: Reply with quote

go to http://www.ovpworld.org/dlp/

Then scroll down to "MIPS Toolchains"

Please be aware, this is an older toolchain than the CodeSourcery MIPS toolchain.

My recommendation is to use the CodeSourcery toolchain, and investigate the compiler to fix the problem you are seeing.
I am sure there will be a switch to the linker which will control the use of stack/heap - this is the correct way to fix this problem

Thx
Lee
Back to top
View user's profile Send private message
LeeMoore
OVP Technologist
OVP Technologist


Joined: 27 Feb 2008
Posts: 635

PostPosted: Mon Sep 08, 2014 12:59 am    Post subject: Reply with quote

Quote:
To compile MIPS32 applications I downloaded and installed mips-2014.05-24-mips-sde-elf.exe


Can you tell me where you got this installer ?

Thx
Lee
Back to top
View user's profile Send private message
IlyaKorobkov



Joined: 24 May 2013
Posts: 27
Location: Saint-Petersburg, Russia

PostPosted: Mon Sep 08, 2014 1:20 am    Post subject: Reply with quote

I downloaded from here:
https://sourcery.mentor.com/GNUToolchain/release2774
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Open Virtual Platforms Forum Index -> Getting started All times are GMT - 8 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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