Quantcast
Viewing all articles
Browse latest Browse all 4565

Bare metal, Assembly language • Data Abort, MMU and atomic operation (casal)

Hello, I'm trying to make a small bare metal system in C that could integrate the OCaml runtime. I would like to propose this solution for Raspberry Pi 5 (so aarch64). My code is available here: https://git.robur.coop/dinosaure/smol-gilbraltar

I've managed to initialize the essentials (UART, exception table, memory). There's also the MMU activation, which I've taken over from the Circle project (but with C). See https://github.com/rsta2/circle

The problem is that this type of code throws me a Data Abort exception:

Code:

#include <log.h>#include <caml/callback.h>#include <memory.h>#include <string.h>typedef _Atomic(char *) foo;static foo bar = NULL;char *strdup(const char *s){size_t l = strlen(s);char *d = malloc(l+1);if (!d) return NULL;return memcpy(d, s, l+1);}void bug(foo *table) {  char *prev = atomic_load(table);  char *test = strdup("Hello World!");  // table = 0xe9a30 <bar>  // prev = 0  // test = 0x40000050 <- this is wrong!  atomic_compare_exchange_weak(table, &prev, test);}// Synchronous exception (pc: 0x8538c, ec: 0x25, iss: 0x410, far: 0x0, sp: 0x29f560, lr: 0x85388, spsr: 0x80000304)// ec: 0x25, 0b100101 (Data Abort)// iss: 0b10000010000// |- DFSC: 10000 -> Synchronous External abort, not on translation table walk or hardware update of translation table.// |- FnV: 0 -> FAR is not valid, and holds an UNKNOWN value.// spsr: 0x80000304// |- M: 0b100 -> EL1 with SP_EL0 (EL1t)int main(int ac, const char *av[]) {  volatile int value = 0;  while (value == 0) { __asm("nop"); }  bug(&bar);  return (0);}
You can see a description in the comments of the exception I get. It seems that, from what I understand, the MMU can't access to the pointer that has just been allocated (whose address should correspond to something like 0x400000xx (above 1 GB, the place where I initialized the C heap).

So it seems that I'm initializing the MMU incorrectly and that it's misconfigured. However, having taken over Circle's code, it's quite difficult to understand what's working and what's not. Do you have any clues about the code and the way I initialize the MMU?

Statistics: Posted by dinosaure — Thu Jan 30, 2025 9:20 pm — Replies 0 — Views 6



Viewing all articles
Browse latest Browse all 4565

Trending Articles