Difference between ISR and function call?

I want to understand the difference between an ISR (Interrupt Service Routine) and a function call.

I believe the function call and ISR are the same in terms of hardware. Please correct me if I am wrong. All I could find about an ISR call and function is as follows:

ISR:

  • Asynchronous event that may occur at any time during program execution

  • Saves PCs, flags, and registers on the stack and disables all interrupts and loads the ISR address

  • ISR has no arguments that can be passed to it

  • Unable to return values
  • Turns on Interrupts
  • They are usually small because they take the time of another process.
  • Some of the ISRs have their own stack.

Function:

  • Occurs when there is a function call

  • Saves PC and registers on the stack

  • May have arguments

  • May return values

  • There are no restrictions on the size and duration of execution

Is there any other difference besides this? Please let me know. I also read about calling a function from ISR how this happens. Please select it.

+7
embedded operating-system function-calls computer-architecture isr
source share
5 answers

They do not necessarily match your status at the first point in the ISR: interrupts are asynchronous and therefore must somehow "interrupt" the operation of the main processor (s).

For example, let's look at this address-decorated MIPS code that does nothing useful:

4000. add $1, $2, $3 4004. sw $ra, 0($sp) 4008. jal subr # function call, sets $ra to 4012 and jumps to 4024 4012. lw $ra, 0($sp) 4016. jr $ra 4020. 4024. subr: sub $2, $1, $3 4028. jr $ra 

This code can be transmitted from the main processor: arithmetic operations (lines 1, 7) are performed by the arithmetic device, memory access (lines 2, 4) by the memory controller and jumps (lines 3, 5, 8) are also performed by the main processor. (The actual jal address is set during the binding of the object file.)

This is for function calls. At any time, it is determined where the code is right now and what code is executed at the next moment in time (that is, when the program counter increases: PC + = 4).

Now comes the moment when your functions do something complicated, but you still want the software to respond to a keystroke. Then the so-called coprocessor comes into play. This coprocessor waits until an event occurs (for example, a key stroke on the keyboard), and then calls the interrupt handler. This is a block of code located at a specific address in memory.

Think of the processor in the calculation above, but in the meantime you want to save the number of keystrokes at the keys address. Then you write a program starting with the address 0x80000180 (this is defined as the address of the exeption handler in MIPS):

 lw $at, keys addi $at, $at, 1 sw $at, keys eret 

Now what happens when you press a key?

  • The coprocessor learns about a key press.
  • The current PC of the main processor is saved
  • The main processor PC is set to 0x80000180, an interrupt code is executed
  • In eret PC is installed on the PC of the main processor before the interruption occurred.
  • The main program execution continues.

There is a transition from normal execution to handling interrupts between steps 2 and 3 and vice versa from 4 to 5.

Note. I simplified this a lot, but it should be clear how interrupts differ from function calls and how hardware should have additional capabilities for handling interrupts.

+1
source share

The main difference is that interrupt handlers (usually) caused by peripheral equipment - the actual hardware signal is generated by the peripheral device and the hardware in the processor, transfers control to the corresponding processor without any action using the code that was run before the interrupt. Unlike functions, there is no call - execution is interrupted from interrupted code by the processor hardware.

In operating systems that support multithreading / processes, function calls are executed in the same process / thread context as the caller. An interrupt, OTOH, does not have a thread or a process context - a network interrupt that occurs due to the background loading of BitTorrent can occur while editing a Word document, and therefore the handler is very limited in what it can do. It can load data into / from pre-allocated buffers belonging to the process / thread to which it is attached, it can signal a semaphore, it can set OS event flags. This is about it.

Often the interrupt handler performs a direct interrupt return, so it allows the interrupted code to be executed to continue any further interference. On simpler controllers such as yopur 8051, which often run embedded code without compex, this is the only course available. With a proactive multi-threaded OS, the interrupt handler has the additional ability to execute its interrupt-return through the OS code and, thus, leads to the launch of the scheduler. This allows interrupt handlers to create threads that are waiting for the interrupt to complete and possibly working (and possibly crowding out the thread that was originally interrupted). This allows such systems to have good I / O performance without any polls.

Sources of hardware interruption are peripheral devices embedded in the processor chip - network controllers, disk controllers, display controllers, DMA controllers, USB controllers, intercore-comms controllers (on processors with multiple cores), timers, etc. pin / s request on the package can be used to generate an interrupt from an external source of hardware (possibly a keypad, keyboard, keyboard, or touch screen hardware).

+2
source share

So, asserting that they are the same, you go on to how they differ from each other, which probably answers your question more likely.

Your first four points about ISR are generally and generally true. Points about allowing interrupts do not necessarily occur and are a decision of the implementation by the programmer and can be determined by the architecture, and being small is not a requirement, but "small" is completely subjective. "

The differences are not so much in the way they are encoded (although the ISR usually imposes a number of restrictions and may also have privileges that normal functions do not perform), but rather in how they are called and the behavior of the processor,

The function (or the procedure or subroutine as a whole) must be explicitly called and is part of the same context and execution flow as the caller. The hardware ISR is not explicitly called, but rather caused by some external event (external to the processor core, which is the built-in peripherals, can generate interrupts). When an interrupt is called the context of the current thread, it is automatically saved until the context switches to the ISR. When returning, the reverse context switch restores the processor to interruption, so that execution continues from the point of interruption.

The mechanism may be complicated by the presence of a multi-threaded operating system or scheduler, whereby the ISR itself can cause a thread context switch, so that when it returns from the ISR, another thread of execution or context switches. mechanisms are controlled by the operating system in this case.

Some processors support a different type of ISR - software interrupt. A software interrupt is used as a function call in the sense that it is explicitly called by an instruction and not by a single event, but offers an indirect mechanism by which the caller does not need to know the ISR address, and indeed, this address can change. In this sense, this is slightly different from calling a function through a pointer, but since it is an ISR that it starts in the context of the interrupt, and not in the context of the caller, it can therefore have restrictions and privileges that are not in the normal function.

Basically, an interrupt can respond directly and deterministically to events in which otherwise you could interrogate or test the event and then process it, but you could process it only at the moment you decide to check it, and not to its actual appearance that may be variable and unacceptably long.

+2
source share

The above answers are pretty much complete ... special attention to Clifford's software interrupts.

The only addition I would make is this. The register context stored in the function call is defined by the Procedure Call Convention for CPU architecture. This usually means that the caller saves something on the stack, and the caller saves some things and is largely static. Exception: IA64, which has a dynamic register window, saves / restores.

The ISR stores the only register that will be used in the ISR. If a single register is used, only that register is saved or restored.

In most cases, the set of registers stored / restored in the function call is much larger than those stored / restored in the ISR due to the static nature of the procedure call conventions.

+1
source share

A function call is usually generated by a program.

An interrupt is usually generated by hardware.

for example: if you program in C, you call the function by executing the function. There is a main function and subfunction. Sub functions are programmed by the programmer.

Interrupts, however, are hardware. for example: On a computer, the processor processes the program and launches it. If you press a key on the keyboard, the keyboard will then switch the keyboard to the processor. Now the processor can act on keystrokes.

Best way to summarize? 1. Functions are created by programmers. 2. interrupts are physically designed in hardware and are used by other equipment https://www.youtube.com/SaqibJaved

0
source share

All Articles