tribes
Posts: 4
Joined: Fri Nov 11, 2016 2:54 pm

How to handle a simple IRQ via QEMU

Fri Nov 11, 2016 3:01 pm

I have been trying to handle a simple IRQ from the emulated RPI 2 with QEMU but wasn't successful :/

Here is my commented code: http://lpaste.net/586201347288727552

Let me explain roughly what I do:
- Put my interrupt table at 0x00
- Set up the interrupt stack
- Handle the interrupt, save the state, print a Hello IRQ, then return to the previous state

On the C side all I do is printing a "Hello world" on the serial port then run a simple loop

My IRQ handler is supposed to print "Hello IRQ" the same way "Hello world" is printed

Anyone seeing an error or have any idea of what could go wrong ?

Thanks,
Tribes

User avatar
Ultibo
Posts: 160
Joined: Wed Sep 30, 2015 10:29 am
Location: Australia
Contact: Website

Re: How to handle a simple IRQ via QEMU

Sun Nov 13, 2016 4:58 am

tribes wrote:Anyone seeing an error or have any idea of what could go wrong ?
Just a thought, are you sure the variation of LDM you are using in irq_interrupt_handler is correct for an exception return?

According to the "ARM® Architecture Reference Manual ARM®v7-A and ARM®v7-R" section B6.1.2 the LDM (exception return) can have a mode of DA, DB, IA, IB but it doesn't list FD. If you are not using the exception return version of the LDM instruction then it will return to the location in LR without restoring CPSR from SPSR and therefore not return to the original mode.
Ultibo.org | Make something amazing
https://ultibo.org

Threads, multi-core, OpenGL, Camera, FAT, NTFS, TCP/IP, USB and more in 3MB with 2 second boot!

tribes
Posts: 4
Joined: Fri Nov 11, 2016 2:54 pm

Re: How to handle a simple IRQ via QEMU

Tue Nov 15, 2016 7:19 pm

Hi Ultibo,
Ultibo wrote:If you are not using the exception return version of the LDM instruction then it will return to the location in LR without restoring CPSR from SPSR and therefore not return to the original mode.
ARM System Developer's Guide wrote: The ^ at the end of the LDMFD instruction means that the cpsr will be restored from the spsr, which is only valid if the pc is loaded at the same time.
Tribes

AlfredJingle
Posts: 69
Joined: Thu Mar 03, 2016 10:43 pm

Re: How to handle a simple IRQ via QEMU

Wed Nov 16, 2016 9:05 am

In my irq handling routine I do the following different from you:

Code: Select all

		stmfd r13!, {r0-r12, lr}	@ no need to save sp -  r13=IRQ stack, to be set at system init.
		
		@ here I do the actual irq actions and enabling and disabling of the irq and what have you not

		ldmfd r13!, {r0-r12, lr}
		subs pc, lr, #4            @ return from irq

Works for me.
going from a 6502 on an Oric-1 to an ARMv8 is quite a big step...

Return to “Bare metal, Assembly language”