Monday, November 05, 2007

Problems with flushing the instruction cache on Nokia n800

Chris Double noted that he was having trouble bootstrapping Factor on his Linux/ARM-based Nokia n800 Internet tablet. The crashes were random and we determined that it was due to the instruction cache not being flushed.

Factor was using the following code to flush the instruction cache:
syscall(__ARM_NR_cacheflush,start,start + len,0);

Now I wasn't checking the return value of this... silly me. After adding a check for the return value, Chris's tablet was returning "operation not permitted" from the above call.

After some Googling, I came across a post on the Parrot mailing list. Here, they were flushing the instruction cache by calling the system call directly, without using the syscall wrapper. I asked Chris to try their code, and it worked. Here it is:
 __asm__ __volatile__ (
"mov r0, %1\n"
"sub r1, %2, #1\n"
"mov r2, #0\n"
"swi " __sys1(__ARM_NR_cacheflush) "\n"
"mov %0, r0\n"
: "=r" (result)
: "r" (start), "r" (start + len)
: "r0","r1","r2");

Now, I'm pretty confused by this. In theory, the syscall function should do the same thing as the above. So either the syscall function in the version of libc shipped by Nokia is broken, or I'm stupid and missing something obvious.

Either way, it appears that Factor works on the n800 now.

1 comment:

Anonymous said...

I'd love to get my hands on the N800 executable and associated image file... any leads would be appreciated.