Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can the timer interrupt be 0x08 if the first 32 interrupts are reserved for exceptions?

I am developing an embedded program for an intel i386, and I am trying to figure out how to use the hardware timer. I have read here (and other places) that the timer interrupt is 0x08, but this page (And various other sources) say that the first 32 interrupts are reserved for exceptions, and interrupt 0x08 specifically is for double fault. Which is true? How can I setup a timer interrupt handler, using either assembly or very low-level C with no operating system calls?

I am developing a simple operating system to learn about operating system development, so I don't have access to anything like Linux or system calls (unless I implement the system calls myself. But creating a fully POSIX-compliant OS is far outside the scope of this project, so I would rather stick to simple, if slightly hacky, solutions).

If it matters, I am running this on QEMU, not an actual physical i386.

like image 584
ItsTimmy Avatar asked Feb 13 '17 16:02

ItsTimmy


People also ask

What happens when a timer interrupt occurs?

Inside the ISR, the program checks to determine the source of the interrupt. If the timer has caused the interrupt, then the timer register is reloaded, and the timer interrupt flag is cleared so that the processor can accept further interrupts from the timer. The display digits are then refreshed inside the timer ISR.

How does the ESP32 timer work with interrupt?

You can attach the desired timer to an interrupt and can assign an ISR for the same Q. How does the ESP32 timer work? The timer uses a counter which counts at a certain speed depending upon the clock frequency and the prescaler value. This counter will reset once it reaches a set value and it will trigger an interrupt.

How do you set up timer interrupts on Arduino?

Timer setup code is done inside the setup(){} function in an Arduino sketch. The code involved for setting up timer interrupts is a little daunting to look at, but it's actually not that hard. I pretty much just copy the same main chunk of code and change the prescaler and compare match register to set the correct interrupt frequency.

What is timer0 and timer2?

After the set commands are executed, the program resumes again from the same position. The Arduino comes with three timers known as Timer0 (8-bit timer), Timer1 (16-bit timer), and Timer2 (8-bit timer). They act as a clock and are used to keep track of time based events.


1 Answers

Most people assume this (Timer using INT8) a design flaw in the original IBM PC architecture. To (partially) protect the guilty, the original 8088 really didn't use this vector - It was, however, marked as "reserved" by Intel from the very beginning.

Before protected mode was invented, that conflict didn't really occur (CPUs < 80286 didn't use this double fault). In most of today's PCs, the 8259 PIC is still there, albeit not as separate chip, but hidden somewhere in the PCs chip set. Thankfully, INT08 for the timer interrupt is not carved in hardware, but rather initialized into the PIC by the PC BIOS. So protected mode OSs can easily re-map the PIC interrupts to other, more convenient places in order to avoid the conflict. To my knowledge, only DOS and other early operating systems assume the timer interrupt on INT8.

like image 148
tofro Avatar answered Jan 03 '23 17:01

tofro