18 January 2022, 17:30 | #1 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
Interrupts interrupting interrupts
I have keyboard handling code that uses level 2 interrupts (PORTS), and mouse handling code in level 3 interrupts (VERTB). Both of these make changes to a global data structure, my event queue.
If I understand right, the level 3 interrupts can interrupt the level 2 interrupts? Yup? This could obviously lead to data corruption if my VERTB code modifies the data structure as the PORTS code is part way through modifying it. My normal, non-interrupt code consumes stuff from this queue, but disables interrupts (custom->intena = INTF_INTEN), quickly grabs what it needs, then reenables interrupts (custom->intena = INTF_SETCLR | INTF_INTEN). Is this the correct thing to do from inside my interrupt code as well? i.e should by level 2 interrupt code disable interrupts while it's accessing that data structure? Or something else? |
18 January 2022, 17:53 | #2 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Simply raise CPU SR IPL, making the modification of shared parts atomic.
Example: Code:
IRQ2_code: move #$2300,SR ... struct mods ... move #$2200,SR |
18 January 2022, 17:55 | #3 | |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
Quote:
You can do that (via INTENA) or change SR to $2300 to only allow lvl4+ interrupts to interrupt your lvl2 handler. |
|
18 January 2022, 18:05 | #4 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
While this usually works, I prefer through SR as it is 'immediate'.
INTENA use Paula that send signals to the CPU lines. And we know that in fast machines many things could happens after the write to custom registers, the most striking is having to double-write INTREQ at the end of the IRQ in some machines because of IPL delay.. EDIT: But in fact I don't know .. Paula has input lines for IRQ2,3,6, so I don't know if something strange can happen in case of deactivation through INTENA, probably it is enough Last edited by ross; 18 January 2022 at 18:23. |
18 January 2022, 18:24 | #5 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
Ok, so I need to go and understand what the SR does. Googling tells me that the important bits are an Interrupt Priority Mask, but to be comfortable I need to understand how the mask works.
|
18 January 2022, 18:29 | #6 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
Level 0 do not stop any IRQ from happening. Level 7 cannot be avoided (Paula cannot generate it, you need an external switch). |
|
18 January 2022, 18:33 | #7 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
This approach is only relavent for code within an interrupt?
|
18 January 2022, 18:36 | #8 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
|
18 January 2022, 18:37 | #9 |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,098
|
Check section 6.3.2 of MC68000UM ("currrent processor priority" is what's in the IPL part of SR) for the authoritative source (though ross is obviously close enough )
@ross: Isn't the double write to INTREQ on accelerated machines just done to ensure delay so the same interrupt isn't triggered twice? I think (but haven't tested) that another custom write would also be fine. |
18 January 2022, 18:41 | #10 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
Ok, but for my purposes, I’ll only be in supervisor within interrupt code, right? I can’t just move myself into supervisor state for everything, can I?
|
18 January 2022, 18:58 | #11 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
The second write guarantee the two CCK delay that are enough to be sure that IPL lines are proper set. So in theory anything that generates such a delay would be fine (generic access to a custom register), but there is conflicting information on this, some claim that double writing is mandatory. |
|
18 January 2022, 19:00 | #12 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
|
18 January 2022, 19:16 | #13 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
|
18 January 2022, 19:35 | #14 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
It is the only way to be sure of going into supervisor state on any processor. Yes, many games/demos do it using a TRAP # instruction (or modifying other exception vectors), but because they assume that the VBR is 0.. |
|
18 January 2022, 19:44 | #15 | |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
Quote:
|
|
18 January 2022, 19:57 | #16 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
The first that come to mind: single stack (therefore less memory used theoretically), and direct usage of some privileged instuction, like MOVE SR, on 010+ processors, but this is bad programming). Basically on the Amiga there is no point in writing code that only works in supervisor state (excluding of course SO code or something that 'replaces' it). For other machines with 68k architecture it could be very different, for example it may not be possible to write to custom registers if in user state, or others where all the code (ROM or user) is executed exclusively in supervisor state. |
|
19 January 2022, 00:04 | #17 | |
Registered User
Join Date: Jan 2012
Location: USA
Posts: 372
|
Quote:
But it's so damn simple that it's awesome. The idea of letting RTE restore the old mask is good too as it makes the solution more general (with a move #$2700, SR at the beginning of the critical section). |
|
19 January 2022, 14:03 | #18 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
So, I think my mainline code, the bit outside the interrupts that consumes the queue, should be:
Code:
void ProcessEventQueue() { using namespace input; for (;;) { Event event; asm volatile (" move %#0x2300, %%sr \n" ::: "cc", "memory"); // allow only level 4 or higher interrupts BOOL isEmpty = eventQueue.isEmpty(); if (!isEmpty) { WORD offset = eventQueue.dequeue(); event = * ((Event *) ((BYTE *) eventQueue.events + offset)); } asm volatile (" move %#0x2000, %%sr \n" ::: "cc", "memory"); // allow all interrupts if (isEmpty) break; ProcessEvent(event); } } |
19 January 2022, 14:16 | #19 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
Yeah, CCR will be erased by a move. You can use or.w #0x0300,sr and and.w #~0x0300,sr instead, if that's a problem.
|
19 January 2022, 15:41 | #20 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to: Proper no-OS interrupts | Peregrine | Coders. Asm / Hardware | 0 | 12 April 2021 20:52 |
Interrupts? | oRBIT | Coders. Asm / Hardware | 2 | 09 April 2021 15:50 |
BLITHOG and Interrupts | Ernst Blofeld | Coders. Asm / Hardware | 22 | 26 November 2020 14:45 |
Damn Interrupts | mcgeezer | Coders. Asm / Hardware | 10 | 24 March 2019 16:50 |
CIA interrupts... | bloodline | Coders. System | 6 | 18 January 2018 10:33 |
|
|