A.nechi
A.nechi

Reputation: 541

Linking m5ops.h to a C project

I have a C application that is using a function from the Gem5 operations called "m5_dumpreset_stats()".

So, I did the following, I included the header file of this function:

#include "../gem5-stable/util/m5/m5op.h"

then in my source file I called the function:

void foo()
{
   m5_dumpreset_stats(0,0);
   /* For loop */
   m5_dumpreset_stats(0,0);
}

To build my project I'm using a Makefile :

CC=arm-linux-gnueabi-gcc
CFLAGS=-g -c -Wall -O3 -mfpu=neon
LDFLAGS=-static

SOURCES=$ foo.c
OBJECTS=$(SOURCES:.c=.o)

EXECUTABLE=foo

all: $(TASKMAP) $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS) 
$(CC) $(LDFLAGS) $(OBJECTS) -lm -o $@

.c.o:
    $(CC) $(CFLAGS) $< -lm -o $@

 clean: 
    rm -fr $(OBJECTS) $(EXECUTABLE)

My first guess is that I have to link the library using the Makefile but honestly, I don't know how? Could someone show me the right way to do it?

P.S : m5_dumpreset_stats(delay,period): Save and reset simulation statistics to a file in delay nanoseconds; repeat this every period nanoseconds.

Upvotes: 3

Views: 1258

Answers (3)

Ciro Santilli
Ciro Santilli

Reputation: 4073

gem5 20 updated procedure

How to use m5 in gem5-20

Hardcode the assembly directly

Sometimes, it is just easier to hack it up and add the assembly inline. E.g. on aarch64, to dump stats you can do:

mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x41 << 16);

A list of some of those instructions is available here and how you can deduce them on your own is explained here.

Upvotes: 0

A.nechi
A.nechi

Reputation: 541

Thank you for your contributions. This was my solution: See that I'm using ARM core for simulation I used Makefile.arm to generate a library called "m5" then I had to do following changes in my own Makefile:

$(EXECUTABLE): $(OBJECTS) 
 $(CC) $(LDFLAGS) $(OBJECTS) -lm -L"/home/anoir/gem5-stable/util/m5" -lm5 -o $@

and I kept the inclusion in my header file to call m5op.h like this:

  #include "/home/anoir/gem5-stable/util/m5/m5op.h"

Finally, I've tested it in the simulator and checked the stats file and Works perfectly Thanks to you.

Upvotes: 1

cdlane
cdlane

Reputation: 41895

Since your header is in a directory that's not normally searched, that's likely true of your library as well. So you'll need two flags: -l to reference the library and -L to add other library directory to search.

If my library was libm5op.a located in "../gem5-stable/util/m5", I might do:

$(CC) $(LDFLAGS) $(OBJECTS) -lm -L"../gem5-stable/util/m5" -lm5op -o $@

or some such as is appropriate to your situation.

Upvotes: 2

Related Questions