Using ITIM in assembly

Hi,

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
_start:
    .cfi_startproc
    .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

    .cfi_endproc

My other test file:

.section .itim

.global _testie
_testie:
    addi t0, t0, 1
    j _testie

my linker script:

OUTPUT_ARCH("riscv")

ENTRY(_start)

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

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

    .text : {
        *(.text*)
    } > rom

    .rodata : {
        *(.rodata*)
    } > rom

   .itim : ALIGN(8) {
        *(.itim*)
    } > rom

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

    .bss (NOLOAD): ALIGN(8) {
        *(.bss*)
        *(COMMON)
    } > 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:

ARCH=rv32imac
ABI=ilp32
EMU=elf32lriscv

ARCHFLAGS=-march=rv32imac -mabi=ilp32
CFLAGS=$(ARCHFLAGS) -g -o0
LDFLAGS=-m $(EMU) -nostartfiles -nostdlib -Tlnk.lds
AS=riscv64-unknown-elf-as
LD=riscv64-unknown-elf-ld

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/metal.default.lds 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;
i++;
return;
}

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:

“ax”,@progbits

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