Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

assemble under nios2

Hi all,

i write a program under nios2 using assemble lanauge, following is the source code

# include <linux/module.h># include <linux/kernel.h>

void print(void)

{

printk("function print\n");

}

typedef void(*pointer)(void);

ulong code[3];

void jump(void)

{

__asm__("movia r12, print");

__asm__("jmp r12");

}

int __init init_filter(void)

{

jump();

}

void __exit exit_filter(void)

{

}

module_init(init_filter);

module_exit(exit_filter);

this can work well, but if i change the function init_filter as bellow, the system will reboot,

int __init init_filter(void)

{

pointer p;

code[0]=0x03000034;

code[1]=0x63000004;

code[2]=0x6000683a;

p = (pointer)code;

p();

}

code[0]~code[2] is the hex value that i get from nios2-elf-objdump according to two assemble sentences.

how should i do?

thanks a lot

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi qiunuoku,

    I&#39;m assuming that &#39;code&#39; is a valid pointer ... and the opcodes are correct. That said, if you&#39;re

    using a data cache, you need to flush the region you modified with the new instructions.

    Then if you&#39;re using and instruction cache, you need invalidate the appropiate region as well.

    Otherwise, you will likely be executing stale bits rather than your copied code.

    Regards,

    --Scott