6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 11:43 pm

All times are UTC




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Hardware Interrupts?
PostPosted: Tue Oct 08, 2013 5:45 am 
Offline

Joined: Tue Oct 08, 2013 5:40 am
Posts: 72
Location: /home/sci4me
Hi all. I am writing an emulator for a theoretical processor I am designing for fun and learning, and I am basing it heavily off of the 6502 (registers, addressing, instructions, etc.) and I am currently working on interrupts. I basically need to learn all there is to know about interrupts. I understand the concept, but the thing I don't get is how an interrupt is triggered and how that would be emulated. I am also wondering if/what data comes along with an interrupt, if no data comes along with an interrupt and multiple devices are causing interrupts, how do i know which one is causing the interrupt?


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Tue Oct 08, 2013 5:56 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
I have a 6502 interrupts primer online.  It's really for microprocessor users, not particularly for microprocessor designers, but it gives the details of how they're enabled, generated, distinguished, serviced, etc., which is apparently what you're looking for.  (Enjoy the outdated cartoons!)

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Tue Oct 08, 2013 6:00 am 
Offline

Joined: Tue Oct 08, 2013 5:40 am
Posts: 72
Location: /home/sci4me
Thanks. I'll be back here if I need any further help! :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Tue Oct 08, 2013 6:01 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8513
Location: Midwestern USA
sci4me wrote:
Hi all. I am writing an emulator for a theoretical processor I am designing for fun and learning, and I am basing it heavily off of the 6502 (registers, addressing, instructions, etc.) and I am currently working on interrupts. I basically need to learn all there is to know about interrupts. I understand the concept, but the thing I don't get is how an interrupt is triggered and how that would be emulated. I am also wondering if/what data comes along with an interrupt, if no data comes along with an interrupt and multiple devices are causing interrupts, how do i know which one is causing the interrupt?

Most of your questions can be answered if you use a little diligence with a search engine. That said, you should give Garth Wilson's interrupt primer a good read. It goes into quite a bit of detail on 6502 interrupt processing.

Also, please stop by the "introduce yourself" topic and tell us a bit about yourself and what you are trying to accomplish.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Tue Oct 08, 2013 6:02 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8513
Location: Midwestern USA
GARTHWILSON wrote:
I have an interrupts primer at http://6502.org/tutorials/interrupts.html. It's really for microprocessor users, not particularly for microprocessor designers, but it gives the details of how they're enabled, generated, distinguished, serviced, etc., which is apparently what you're looking for. (Enjoy my outdated cartoons!)

Oops! You posted just as I was posting. :lol:

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Tue Oct 08, 2013 6:16 am 
Offline

Joined: Tue Oct 08, 2013 5:40 am
Posts: 72
Location: /home/sci4me
So, as far as the processor design goes... instead of having the interrupt vector stored in a memory address (which would be hardcoded...) would it be a bad idea to have a register for it? Can't see why that would be a bad thing really..


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Tue Oct 08, 2013 6:23 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
sci4me wrote:
So, as far as the processor design goes... instead of having the interrupt vector stored in a memory address (which would be hardcoded...) would it be a bad idea to have a register for it? Can't see why that would be a bad thing really..

I brought it up recently at the bottom of the page at viewtopic.php?f=1&t=1419&start=150 and then there were responses to it.  The topic this is in is a very long one on making a 32-bit 65-family processor.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Wed Oct 09, 2013 9:09 pm 
Offline

Joined: Tue Oct 08, 2013 5:40 am
Posts: 72
Location: /home/sci4me
So, the difference between IRQ and NMI is that NMI takes precedence over IRQ yes?

For my CPU design, would it be a good/bad/either way idea to do something like this:

IRQ₁
IRQ₂
IRQ₃

etc.. for some fixed number and basically have multiple interrupt handlers and pins to trigger them? If I did this, well.. I would have to figure out how to determine what happend first, I would prefer to just execute them in the order they come in though..


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Wed Oct 09, 2013 9:20 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8513
Location: Midwestern USA
sci4me wrote:
So, the difference between IRQ and NMI is that NMI takes precedence over IRQ yes?

The important difference is that an NMI can't be ignored. An IRQ can be ignored by setting the I (interrupt disable) bit in the status register. I recommend you read up on and fully understand the 6502 architecture before attempting to emulate/simulate a 6502. In my opinion, you're putting the cart before the horse right now, as your questions indicate that you lack the knowledge needed to accomplish your goal.

Incidentally, if an IRQ and NMI simultaneously hit ("simultaneously" meaning during the same instruction processing cycle) the 65xx family will acknowledge NMI first.

Quote:
For my CPU design, would it be a good/bad/either way idea to do something like this:

IRQ₁
IRQ₂
IRQ₃

etc.. for some fixed number and basically have multiple interrupt handlers and pins to trigger them? If I did this, well.. I would have to figure out how to determine what happend first, I would prefer to just execute them in the order they come in though..

Prioritizing interrupts is usually a chore handled by a programmable interrupt controller. Most MPUs have only a few hardware interrupt inputs, IRQB being the most used one on a 6502. External hardware and/or software polling must be used to differentiate interrupt sources.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Wed Oct 09, 2013 9:27 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
NMI is non-maskable (like its name says), meaning that even if you're servicing an interrupt from IRQ and the interrupt-disable flag is set, it can still get through and cut in on the servicing of the IRQ.  But there is another important difference:  NMI is edge-triggered, not level-sensitive.  This has certain effects that cannot be ignored.  This is discussed in the 6502 interrupts primer.

Having more pins, each with its own vector, would be nice.  You could also add prioritizing to take the above concept further.  (I see BDD just posted while I was writing, and mentioned this.)  It could be done at different levels too, like completing the current interrupt service before servicing another interrupt, but then going in order of priority rather than chronological order.  It's not too big a deal though, I think, because if you're frequently getting that many interrupts on top of each other, the system is probably underpowered and isn't going to be able to do what it's supposed to.

Even with more interrupt pins, you may still need to do some polling though, like if you have two or more interrupt sources in the same I/O IC enabled at once.  The IC sends and interrupt request, and then you have to find out which of its enabled sources caused it.  Was it something coming in on the serial port?  Was it that you're sending data and the other end says it's ready for more?  Was it that a timer timed out?  Was it an active edge you selected to interrupt on?

Polling does not need to be as difficult as it is sometimes made out to be, or have as much overhead as we often see in the examples in books.  There is no sense in wasting time polling for interrupt sources that aren't even enabled; and only a small percentage of all the possible interrupts will be enabled at any one time.  Also, you don't need to save and restore registers that your ISR doesn't use.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Wed Oct 09, 2013 9:36 pm 
Offline

Joined: Tue Oct 08, 2013 5:40 am
Posts: 72
Location: /home/sci4me
As far as NMI being serviced even if I is set, I remember reading that but I forget to type it, but yeah. As far as removing polling, that's not really my intention.. It's really just for more functionality, but I would only have 2 or 3 or something like that... As far as prioritization, I would probably do what you said Garth and serve them based on priority.. And correct me if im "wrong" but the best way to do that would be to have sort of queue which would hold the requested interrupts and then whenever the clock ticks just serve any irq requests in the queue?


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Wed Oct 09, 2013 9:45 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
Even for NMI, you could, if you had to, tell the particular IC connected to NMI\ to not interrupt you until further notice.  So even though the interrupts on that line are not maskable, you can prevent them from even being generated in the first place.

The queue sounds more like just servicing them in chronological order rather than letting a higher-priority one "take cuts."

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Wed Oct 09, 2013 10:41 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8513
Location: Midwestern USA
GARTHWILSON wrote:
Even with more interrupt pins, you may still need to do some polling though, like if you have two or more interrupt sources in the same I/O IC enabled at once.

Also, there may be more interrupt sources than there are interrupt inputs. The PCI bus in a PC is a perfect example of this. It has four possible interrupts labeled A-D. However, quite a few PC motherboards that supported only PCI had five or (in rare cases) six slots. So some software polling was still required to isolate and service an interrupt. It's a case of balancing the expense of more hardware against the "expense" of a more complex ISR.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Thu Oct 10, 2013 1:27 am 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 679
Also one fine point regarding "priority" is that if an NMI handler runs a CLI instruction, that allows IRQs to interrupt it. I use this in some background processing scenarios on the C64, where a timer on the NMI starts a task, but IRQ display interrupts can still continue operating.

So there really isn't any priority aside from "simultaneous" triggering and the interrupt disable flag, which is set by the hardware when interrupted by either IRQ or NMI.

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
 Post subject: Re: Hardware Interrupts?
PostPosted: Thu Oct 10, 2013 5:35 am 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
sci4me wrote:
So, the difference between IRQ and NMI is that NMI takes precedence over IRQ yes?

For my CPU design, would it be a good/bad/either way idea to do something like this:

IRQ₁
IRQ₂
IRQ₃

etc.. for some fixed number and basically have multiple interrupt handlers and pins to trigger them? If I did this, well.. I would have to figure out how to determine what happend first, I would prefer to just execute them in the order they come in though..


If you have more than one or two interrupt sources, it's better to have a vectored interrupt controller, where every interrupt source (or group of them) has a different vector pointing to its own handler. Modern microcontrollers have dozens of different interrupt vectors with great flexibility in priorities. For instance check out datasheet of a PIC32: http://ww1.microchip.com/downloads/en/D ... 61156H.pdf with 52 interrupt vectors, and 76 interrupt sources, each with their own priority setting that the programmer can change.

Of course, this is much harder to implement if your peripherals are external to the chip, but you'll be implementing your design in an FPGA, so it's natural to implement the peripherals inside the FPGA as well, and then it's not that hard to add multiple interrupt vectors and priorities.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 80 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: