"Properly" dereferencing pointer to address zero in RISC-V

135 views Asked by At

I am developing bare metal code for a RV32IMC chip using gcc. I have memory mapped starting from address 0x0. I use simple pointers like uint32_t *p = 0x0; to access that address.

I was surprised when gcc compiled my function into a single ebreak. It turned out to be by design.

To access address zero I eventually added __attribute__((optimize("no-delete-null-pointer-checks"))) to the whole function. Is that the proper way to access address zero in RISC-V gcc and avoid getting the code optimized out? Are there better options?

0

There are 0 answers