I am trying to write self-study code in C and ARM. I previously asked a similar question about MIPS and am now trying to transfer the project to ARM.
My system: = Raspbian on raspberries pi, ARMv6, GCC
There are a few things I'm not sure about:
- Is ARM required to refuse write / I-cache D-cache (cache-flash)? If so, how can we do this?
I also tried an example
#include <stdio.h> #include <stdint.h> #include <stdlib.h> int inc(int x){ //increments x uint16_t *ret = malloc(2 * sizeof(uint16_t)); *(ret + 0) = 0x3001; //add r0 1 := r0 += 1 *(ret + 1) = 0x4770; //bx lr := jump back to inc() int(*f)(int) = (int (*)(int)) ret; return (*f)(x); } int main(){ printf("%d",inc(6)); //expect '7' to be printed exit(0);}
but I keep getting segmentation error. I use the aapcs call convention, which I was given to understand, this is the default value for all ARM
I would really appreciate if someone pointed me in the right direction
Bonus question (that is, it really doesn’t need to be answered, but it would be nice to know) - I “came from the MIPS background”, how the hell are ARM programmers without a register of 0? (e.g. case encoded to value 0)
source share