Using ITIM in assembly


I’m somewhat new this whole embedded game so apologies in advance if I’ve made some obvious mistakes here.

I’ve been playing around running in pure assembly on my hifive1 rev B and was trying to test running code from the ITIM. I’ve read the FE310-G002 manual and also tried to look at what the example-itim project does in the freedom-e-sdk, but I don’t think I’ve got it quite right.

I was hoping it would be a case of sticking a “.section .itim” in my file but there’s probably more I’m missing.

Here is my main assembly file:

.section .text

.global _start
    .cfi_undefined ra

    # Global Pointer setup
    .option push
    .option norelax
    la gp, __global_pointer$
    .option pop

    # Stack Pointer setup
    la sp, __stack_pointer$

    j _testie


My other test file:

.section .itim

.global _testie
    addi t0, t0, 1
    j _testie

my linker script:



    itim : ORIGIN = 0x8000000,  LENGTH = 8K
    ram  : ORIGIN = 0x80000000, LENGTH = 16K
    rom  : ORIGIN = 0x20010000, LENGTH = 512M

    __stack_size = DEFINED(__stack_size) ? __stack_size : 2K;

    .text : {
    } > rom

    .rodata : {
    } > rom

   .itim : ALIGN(8) {
    } > rom

    .data : ALIGN(8) {
        . = ALIGN(8);
        PROVIDE( __global_pointer$ = . + 0x800 );
    } > ram AT > rom

    .bss (NOLOAD): ALIGN(8) {
    } > ram

    .stack ORIGIN(ram) + LENGTH(ram) - __stack_size : ALIGN(16) {
        PROVIDE( __stack_pointer$ = . );
    } > ram


and these are the options I’m passing to the assembler/linker:


ARCHFLAGS=-march=rv32imac -mabi=ilp32
LDFLAGS=-m $(EMU) -nostartfiles -nostdlib

Not sure if there’s anything else I can provide that will be of use

Not sure what’s the problem that you are facing here. I assume you tried to compile and link the code to ITIM section and such code can’t be found there.

If that’s the case, couple suggestions. 1st, freedom-e-sdk BSP for hifive1 board has the ITIM defined in the linker script. You can use it 1st then debug the problem later. See freedom-e-sdk-root/bsp/sifive-hifive1-revb/ for detail.

To do quick test, you can use function attribute to link a C function to ITIM section in C code.

 __attribute__((section(".itim"))) void myfunc() {
volatile int i=0;

Once you have a working linker script then you can check your assembly code. I did not spot any obvious problem here.

2nd thing to check is whether the function that is linked to the ITIM are called in the main program. By default freedom-e-sdk will remove unused function.

3rd thing to check is use -fno-inline force compile don’t inline the code.

This is not related to your problem but notice that we have “-o0” in the CFLAGS. It should be “-O0”.

Thanks for the reply gnek.

I found out the issue was due to my own messing with the assembly file and that I had to have:


after the the .itim section for this to work along with updating the .itim section to use ‘> itim AT > rom’ in the linker script