Go to advanced search

by mattgrum
Sun Jul 01, 2018 8:49 am
Forum: Bare metal, Assembly language
Topic: prevent crashes from unaligned memory accesses when porting code
Replies: 9
Views: 1922

Re: prevent crashes from unaligned memory accesses when porting code

Thanks for the replies. Firstly, I don't see how this constitutes "misusing structures" since this is perfectly valid C, and it's possible to generate correct machine code from it, which is the job of the compiler. Unfortunately adding __attribute__((__packed__, aligned(1))) doesn't help, the code s...
by mattgrum
Fri May 11, 2018 7:28 pm
Forum: Bare metal, Assembly language
Topic: prevent crashes from unaligned memory accesses when porting code
Replies: 9
Views: 1922

Re: prevent crashes from unaligned memory accesses when porting code

Thanks for your response. I've added that code to my startup but unfortunately the problem persists. I can read unaligned structs from an array but if I write one the system hangs. Here is the disassembly of kernel.elf, the code appears as expected: kernel7.elf: file format elf32-littlearm Disassemb...
by mattgrum
Wed May 09, 2018 7:55 pm
Forum: Bare metal, Assembly language
Topic: prevent crashes from unaligned memory accesses when porting code
Replies: 9
Views: 1922

prevent crashes from unaligned memory accesses when porting code

I'm porting some C code to the Pi 3 baremetal, and I have found that reading/writing structs from unaligned memory addresses causes a crash. For example the following will crash: typedef struct { short a; short b; short c; } S; S array[2]; S s = {1,2,3}; array[1] = s; This can be fixed by adding __a...

Go to advanced search