UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
10,454 Views
Registered: ‎02-23-2009

Editing the crtinit.s file "Default C run-time initialization for MicroBlaze"

Hello everyone!

 

I am trying to call a C function writen by me before the main program is called and executed in a Microblaze system. I found the main function call in crtinit.s (Default C run-time initialization for MicroBlaze) file "brlid    r15, main" and just inserted my function call before it "brlid    r15, myfunction", so it looks like this

 

brlid    r15, myfunction              /* call myfunction before executing the main program   
brlid    r15, main                       /* Execute the program */ 

 

However main() program is called and executed but my function is never called before it. Could someone please tell me what is going on and what I am doing wrong.

 

Thanks in advance. 

0 Kudos
5 Replies
Adventurer
Adventurer
10,420 Views
Registered: ‎01-04-2008

Re: Editing the crtinit.s file "Default C run-time initialization for MicroBlaze"

Davit:

 

The brlid branch instruction has a delay slot, meaning that the next instruction after the branch is executed as the branch target address is calculated.  In this case, this means that the branch to the main function may begin execution.  The proper way to call your function before main is:

 

*****************************************************

// Call function and fill delay slot with a No-op

brlid r15, myFunction

nop

 

// Call main

brlid r15, main

// instruction located here will be executed "during" the branch

 *****************************************************

 

Give this a try to see if it solves your problem.

 

-Jason

0 Kudos
10,403 Views
Registered: ‎02-23-2009

Re: Editing the crtinit.s file "Default C run-time initialization for MicroBlaze"

Thanks for the reply. The problem is whatever I change in the Microblaze initialization assembly files, the changes are not there when I debug. I think somehow the assembly files shoud be compiled into object files, which are included in a project (XPS) and used when running the system. So, a way should be found to make the project (XPS) aknowledge the changes in those files.
0 Kudos
Adventurer
Adventurer
10,398 Views
Registered: ‎01-04-2008

Re: Editing the crtinit.s file "Default C run-time initialization for MicroBlaze"

Which assembly files are you changing?   Are they located within your XPS project directory or are they in the $XILINX_EDK installation path?

 

I believe that the software/lib files in $XILINX_EDK are just for show, and the actual files used are in .o format in the compiler directory for mb-gcc.

 

 $XILINX_EDK/gnu/microblaze/lin64/microblaze-xilinx-elf/lib

 

(NOTE: lin64 should be changed depending on your type of system)

 

Also, I would make a backup of the old .o file just to make sure it doesn't become corrupted.

 

0 Kudos
10,322 Views
Registered: ‎02-23-2009

Re: Editing the crtinit.s file "Default C run-time initialization for MicroBlaze"

I found the object files in the "EDK\gnu\microblaze\nt\microblaze-xilinx-elf\lib" directory but I don't actually know how to modify them. My guess is I should complile the modified assembly files into those object files using a make file. Is there any guidance on how to do it?

I don't know how those object files are added to my project. If I could find out that I could exclude them from my project and include my own initialization files.

Message Edited by davit.mirzoyan on 03-16-2009 04:37 AM
0 Kudos
Highlighted
Adventurer
Adventurer
9,555 Views
Registered: ‎01-04-2008

Re: Editing the crtinit.s file "Default C run-time initialization for MicroBlaze"

Page 138 of the edk10_est_rm.pdf guide says...

 

"Modifying Startup Files:

The initialization files are distributed in both pre-compiled and source form with EDK. The
pre-compiled object files are found in the compiler library directory. Sources for the
initialization files for the MicroBlaze GNU compiler can be found in the
<XILINX_EDK>/sw/lib/microblaze/src directory, where <XILINX_EDK> is the
EDK installation area.
To fulfill a custom startup file requirement, you can take the files from the source area and
include them as a part of your application sources. Alternatively, you can assemble the files
into .o files and place them in a common area. To refer to the newly created object files
instead of the standard files, use the -B directory-name command-line option while
invoking mb-gcc. To prevent the default startup files from being used, use -
nostartfiles on final compile line. Note that the miscellaneous compiler standard CRT
files, such as crti.o, and crtbegin.o, are not provided with source code. They are
available in the installation to be used as is. You may need to bring them in on your final
link command."

0 Kudos