Question

9. During a drivers interrupt handling routine, once the interrupt has been acknowledgedit is possible for another interrupt to occur that will invoke the same handler. Drivers that produce correct results in this scenario are called reentrant. Consider the following interrupt handler: or athe 1 char temp void interrupt hardlar(void) char , x2; x1-inb (Ox120); // read from 1/0 port x2 1nb (0x121); // read from 1/0 Port 1 acknovledgeinterrupt O 12 temp=x1; x1-x2 x2-tep printf(Cot and swapped x1-% d x2-%d\n. x1, x2); is

A) Why is this code not reentrant? On what line would an interrupt haveto occur to cause the bug to manifest? Please explain your answer

B) How could you fix it so that it is reentrant? Please explain your answer

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Reentrant:

If an interrupt that pauses its execution and shifts control to another function.After complete the function then control is again transferred to the starting function and it returns the execution phase.

Reentrants are used in application like hardware interrupt handling,recursion.

Reentrant must satisfy the below conditions:

1)It may not use global and static data,because the interrupt may change certain global values and resuming the course of action.

2)It should not modify it's own code.

This is important because the course of action of the function should remain the same throughout the code.

3)Should not call another non-reenterant function.

Example:

int factorial(int i)

{

return i*5;

}

int mul(int i)

{

return factorial(i) *5;

}

Above example mul function is a reentrant because it interrupt it's execution and go to the factorial function complete the execution of factorial function and control come to the mul function and execute the instructions in that block.

So mul is a reenterant.

a) char temp;

void interrupt_handler(void)
{

char x1,x2;
x1=inb(0x120);
x2=inb(0x121);

acknowledge_interrupt();

temp=x1;
x1=x2;
x2=temp;

printf("Get and swapped x1=%d x2=%d \n",x1,x2);

}

Above program is not a reentrant because global variable is used in function void interrupt_handler(void) function.

Reenterant most follows above specified 2 conditions.

Interrupt well have occured in 5th line because the variable read from the i/o port.

Then control stop execution and go to the i/o port this called a interrupt.

And we find bug on the function opening brace.

b)

We declare temp variable in inside the function and we can fix it to reenterant.

And given above program there is no code in acknowldge_interrupt() funcion.

We don't whether acknowldge_interrupt() funcion reenterant or non-reenterant function if the function is non-reenterant then it fix to the reenterant function.

Add a comment
Know the answer?
Add Answer to:
A) Why is this code not reentrant? On what line would an interrupt haveto occur to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I...

    I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT