Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bus error when trying to use a struct to access intc registers #1

Closed
scintill opened this issue Sep 25, 2020 · 0 comments
Closed

Bus error when trying to use a struct to access intc registers #1

scintill opened this issue Sep 25, 2020 · 0 comments

Comments

@scintill
Copy link

While working on the clock lab, I ran into bus errors when trying to access the intc via a struct pointer. Some minimal code (won't help anyone do the lab) to show this issue is here. On my board the output looks like this:

$ sudo apps/interrupt_test/interrupt_test 
-------------------------------------------------------
Welcome to the interrupt test.
When you press or release a button, or move a switch, the program will print a message.
The buttons may bounce, so you may sometimes see multiple messages on a button press.
-------------------------------------------------------
Bus error
$ dmesg | tail -n3
[ 4269.957460] Unhandled fault: external abort on non-linefetch (0x1818) at 0x36f8c000
[ 4269.963730] pgd = 5ed84000
[ 4269.965115] [36f8c000] *pgd=1588c831, *pte=41800743, *ppte=41800c33

gdb identifies the problematic instruction:

   0x00010608 <+96>:	ldr	r3, [r3, #0]
   0x0001060a <+98>:	ldrb	r2, [r3, #0]
   0x0001060c <+100>:	movs	r2, #0
   0x0001060e <+102>:	orr.w	r2, r2, #1
=> 0x00010612 <+106>:	strb	r2, [r3, #0]
   0x00010614 <+108>:	ldrb	r2, [r3, #1]
   0x00010616 <+110>:	movs	r2, #0

On the other hand, the ptr_write function doesn't use strb:

Dump of assembler code for function ptr_write:
   0x00010584 <+0>:	push	{r7}
   0x00010586 <+2>:	sub	sp, #20
   0x00010588 <+4>:	add	r7, sp, #0
   0x0001058a <+6>:	str	r0, [r7, #12]
   0x0001058c <+8>:	str	r1, [r7, #8]
   0x0001058e <+10>:	str	r2, [r7, #4]
   0x00010590 <+12>:	ldr	r2, [r7, #12]
   0x00010592 <+14>:	ldr	r3, [r7, #8]
   0x00010594 <+16>:	add	r3, r2
   0x00010596 <+18>:	ldr	r2, [r7, #4]
   0x00010598 <+20>:	str	r2, [r3, #0]
   0x0001059a <+22>:	nop
   0x0001059c <+24>:	adds	r7, #20
   0x0001059e <+26>:	mov	sp, r7
   0x000105a0 <+28>:	ldr.w	r7, [sp], #4
   0x000105a4 <+32>:	bx	lr

If I point the struct pointer at some stack memory, the strb works, so I guess it is not a fundamental memory alignment issue, but specific to the intc peripheral.

Anyway, it would be nice to fix if possible. Can the IP be generated to allow access via strb? Can we add a compiler flag that will avoid this? Is there something I'm doing wrong?

My workaround was to first assign the value I wanted to put in a register to a local uint32_t variable, then assign that into the struct.

@jgoeders jgoeders closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants