Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

Assembly code within C (ARMv8 architecture)

i am working on a Cortex-A72 (Armv8) and i need to implement this pseudocode:

put addr1 into X9
put addr2 into X10
for i := 0 to N ? 1 do
STR X0, [X9]
STR X0, [X10]
DC CVAC, X9
DC CVAC, X10

Following my C code:

int main(){

    unsigned char temp = 0xff;
    unsigned char *mem;
    mem = mmap(NULL, BUF_SIZE, PROT_READ | PROT_WRITE,MAP_ANON | MAP_PRIVATE, -1, 0);
    if (mem == MAP_FAILED){
        perror("mmap()");
        return 1;
    }
    memset(mem,0xff,BUF_SIZE);
    /* Select two random addresses within memory pool*/
    size_t offset1 = (rand()<<12)%BUF_SIZE;
    size_t offset2 = (rand()<<12)%BUF_SIZE;
    unsigned char *addr1 = (unsigned char*) (mem+offset1);  
    unsigned char *addr2= (unsigned char*) (mem+offset2)

    for (int i = 0; i < 10000; i++){
        asm volatile("str %x1, %x0" : "=m"(*addr1) : "r"(temp));
        asm volatile("str %x1, %x0" : "=m"(*addr2) : "r"(temp));
        __asm__ __volatile__("dc cvac, %0
" : : "r" (addr1));
        __asm__ __volatile__("dc cvac, %0
" : : "r" (addr2));
    }
      
     .
     .
     .
    
}

I just want to know if I am using the assembly code in the right way. The goal is to access data directly in physical memory, bypassing cache.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...