Monday, March 21, 2022

Interaction with Hardware through 'C'

 Interrupt & Interrupt Vector table

What is Interrupt?

The interrupt is a signal produced by hardware or software when a process or an event needs immediate attention. It alerts the processor of a system to stop / suspend the current working process and give attention to the process which generates an interrupt.

After the execution of the interrupt service routine, the processor resumes the execution of the suspended program / process.

There are two types of interrupts

i)      Software Interrupt

A software interrupt is caused either by an exceptional condition or a special instruction in the program, which causes an interrupt when it is executed by the processor.

ii)    Hardware Interrupt

A hardware interrupt is an electronic signal sent to the processor from an external device or an external peripheral. For example, when we press a key on the keyboard or move the mouse, they trigger hardware interrupts which cause the processor to read the keystroke or mouse position.

Interrupt Vector Table:

The interrupt vector table, often abbreviated to IVT, is a data structure that associates a list of interrupt handlers i.e. an array of pointers to functions. The IVT and the handlers are used to handle specific exceptions, such as faults, system service requests from the application, and interrupt requests from peripherals.

ROMBIOS Philosophy:

Calling a ROM-BIOS functions is not so simple, because, ROM-BIOS functions do not have names. These can be called by obtaining their addresses, and passing control to these addresses. The addresses of ROM-BIOS functions are stored in the Interrupt Vector Table (IVT).

At the specific moment when the ROM-BIOS function is called, the microprocessor is usually busy doing something; and the microprocessor is capable of performing only one task at a time.

All ROM-BIOS functions are invoked through 'interrupts'. Each interrupt instruction selects a particular address in the IVT and passes control to this address. This design makes it possible for any program to use a ROM-BIOS function without knowing its specific memory location.

There are numerous ROM-BIOS functions available. They have been divided into subject categories, each with its own controlling interrupt. For example, all functions related with VDU are grouped under interrupt number 16, all functions related with printer are grouped under interrupt number 23 and so on.

Invoking ROM-BIOS Function:

To call ROM-BIOS function we should perform the following steps:

i)       Make an Interrupt occur.

ii)     Find the interrupt number occurred

iii)  Obtain the address of Interrupt Service Routine form IVT

iv)   Place the values in CPU registers as required by ROMBIOS function

v)     Execute the ROMBIOS function

From the steps above, except for steps (i) and (iv) all other steps are performed by the microprocessor itself. So our task is just place the values needed by the ROM-BIOS routine and make a software interrupt to occur.

In language ‘C’ the software interrupt can be caused by using the standard library function int86( ), this function is also used to place values in CPU registers, as required by the ROM-BIOS function.

The ROM-BIOS functions have been written in such a manner that, some functions expect values to be placed in registers AX, BX, CX etc., whereas some functions expect a different value in high byte (AH) of AX register, and a different value in low byte (AL) of AX register, and so on.

int86( ) function

The int86() is a standard library function present in the <dos.h> header file, is used to make a software interrupt occur and thus invoke a ROM-BIOS function. Here int stands for interrupt and 86 refers to the 8086 family of microprocessors.

The function int86( ) requires three arguments:

-          An interrupt number corresponding to the ROM-BIOS function to invoked.

-          Two union variables. The first union variable represents the value being sent to the ROM-BIOS routine and the second variable represents the value which being returned from ROM-BIOS routines.

 

The general syntax for int86( ) function is:

            int86( interrupt_no, inputRegis, outputRegis);

Example:

            Int86(16, &inregs, &outregs);

Here 16 is the interrupt number, inregs represents the register value to be sent to ROM-BIOS function and outregs represents the register value returned by the ROM-BIOS function.

Interrupts to access ROMBIOS Services.

There are number of ROM-BIOS services available, these services are grouped together according to their similarities under one interrupt for example the interaction with VDU / Monitor are grouped together under interrupt number 16.

The following table gives description of some of the ROM-BIOS services under that interrupt number.



No comments:

Post a Comment