Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE291 Lecture 10 Interrupts II. ECE 291 Lecture 9Slide 2 of 22 Lecture outline Installing/Removing ISRsInstalling/Removing ISRs Interrupt SchedulingInterrupt.

Similar presentations


Presentation on theme: "ECE291 Lecture 10 Interrupts II. ECE 291 Lecture 9Slide 2 of 22 Lecture outline Installing/Removing ISRsInstalling/Removing ISRs Interrupt SchedulingInterrupt."— Presentation transcript:

1 ECE291 Lecture 10 Interrupts II

2 ECE 291 Lecture 9Slide 2 of 22 Lecture outline Installing/Removing ISRsInstalling/Removing ISRs Interrupt SchedulingInterrupt Scheduling INT 21hINT 21h INT 16hINT 16h INT 10hINT 10h

3 ECE 291 Lecture 9Slide 3 of 22 Interrupt Service Routines DOS facilities to install ISRsDOS facilities to install ISRs Restrictions on ISRsRestrictions on ISRs Currently running program should have no idea that it was interrupted. Currently running program should have no idea that it was interrupted. ISRs should be as short as possible because lower priority interrupts are blocked from executing until the higher priority ISR completes ISRs should be as short as possible because lower priority interrupts are blocked from executing until the higher priority ISR completes FunctionAction INT 21h Function 25hSet Interrupt vector INT 21h Function 35hGet Interrupt vector INT 21h Function 31hTerminate and stay resident

4 ECE 291 Lecture 9Slide 4 of 22 Installing ISRs Let N be the interrupt to service Read current function pointer in vector tableRead current function pointer in vector table Use DOS function 35h Use DOS function 35h Set AL = N Set AL = N Call DOS Function AH = 35h, INT 21h Call DOS Function AH = 35h, INT 21h Returns: ES:BX = Address stored at vector N Returns: ES:BX = Address stored at vector N Set new function pointer in vector tableSet new function pointer in vector table Use DOS function 25h Use DOS function 25h Set DS:DX = New Routine Set DS:DX = New Routine Set AL = N Set AL = N DOS Function AH = 25h, INT 21h DOS Function AH = 25h, INT 21h

5 ECE 291 Lecture 9Slide 5 of 22 Installing ISRs Interrupts can be installed, chained, or calledInterrupts can be installed, chained, or called Install New interrupt replace old interruptInstall New interrupt replace old interrupt Chain into interrupt Service myCode firstChain into interrupt Service myCode first Call Original Interrupt Service MyCode lastCall Original Interrupt Service MyCode last MyIntVector Save Registers Service Hardware Reset PIC Restore Registers IRET MyIntVector Save Registers MyCode Restore Registers JMP CS:Old_Vector MyIntVector PUSHF CALL CS:Old_Vector Save Registers MyCode Restore Registers IRET

6 ECE 291 Lecture 9Slide 6 of 22 Removing ISRs To remove your ISR from the interrupt vector table, you simply write the value of the original handler back to the tableTo remove your ISR from the interrupt vector table, you simply write the value of the original handler back to the table This will overwrite the CS:IP of the ISR you specified when you installed itThis will overwrite the CS:IP of the ISR you specified when you installed it Again, use INT 21h, function 25h to set the value of a vector in the tableAgain, use INT 21h, function 25h to set the value of a vector in the table

7 ECE 291 Lecture 9Slide 7 of 22 Timer Example – Install interrupt ;====== Install Interrupt ===== InstallTimer;Install new INT 8 vector pushes pushdx pushax pushbx moval, 8;INT = 8 movah, 35h;Read Vector Subfunction int21h;DOS Service movword [oldv+0], bx movword [oldv+2], es moval, 8;INT = 8 movah, 25h;Set Vector Subfunction movdx, myint ;DS:DX point to function int21h;DOS Service pop bx pop ax pop dx pop es ret

8 ECE 291 Lecture 9Slide 8 of 22 Timer interrupt – Uninstall Interrupt ;====== Uninstall Interrupt =========== RemoveTimer ; Uninstall Routine (Reinstall old vector) pushds pushdx pushax movdx, word [oldv+0] movds, word [oldv+2] moval, 8 ; INT = 8 movah, 25h ; Subfunction = Set Vector int21h ; DOS Service popax popdx popds ret

9 ECE 291 Lecture 9Slide 9 of 22 The complete code with exe www.ece.uiuc.edu/ece291/lecture/timer.asmwww.ece.uiuc.edu/ece291/lecture/timer.asmwww.ece.uiuc.edu/ece291/lecture/timer.asm www.ece.uiuc.edu/ece291/lecture/timer.exewww.ece.uiuc.edu/ece291/lecture/timer.exewww.ece.uiuc.edu/ece291/lecture/timer.exe

10 ECE 291 Lecture 9Slide 10 of 22 Interrupt Scheduling Consider a system that needs to perform several periodic tasks within a given timeConsider a system that needs to perform several periodic tasks within a given time These tasks are in the form of interrupts with different priorities and different behavior (preemptive/non-preemptive)These tasks are in the form of interrupts with different priorities and different behavior (preemptive/non-preemptive) We need to determine if the tasks are schedulable – if there exists an arrangement of them such that all are completed by their respective deadlinesWe need to determine if the tasks are schedulable – if there exists an arrangement of them such that all are completed by their respective deadlines

11 ECE 291 Lecture 9Slide 11 of 22 Interrupt Scheduling Johnny’s back… let’s look at his tasks:Johnny’s back… let’s look at his tasks: Need to complete the tableNeed to complete the table TaskPriority Run Time DeadlineFreqPeriodLoad Partying1 3 hrs 10 hrs 1/15 hrs 15 hrs 20% Beer2 5 hrs 15 hrs 1/20 hrs 20 hrs 25% Sleep3 11 hrs 30 hrs 1/33 hrs 33 hrs 33% School3 4 hrs 20 hrs 1/50 hrs 50 hrs 8%

12 ECE 291 Lecture 9Slide 12 of 22 Interrupt Scheduling Here’s a timing diagram corresponding to the previous tableHere’s a timing diagram corresponding to the previous table We’ll use it in order to calculate the worst-case completion times of Johnny’s tasksWe’ll use it in order to calculate the worst-case completion times of Johnny’s tasks

13 ECE 291 Lecture 9Slide 13 of 22 INT 21h DOS provides INT 21h, which is called the DOS function dispatcher and supports functions such as: read from the keyboard, write to the screen, write to the printer, read and write to disk files, etc.DOS provides INT 21h, which is called the DOS function dispatcher and supports functions such as: read from the keyboard, write to the screen, write to the printer, read and write to disk files, etc. INT 21h must be told which function is being requestedINT 21h must be told which function is being requested this information is passed by placing the function number in the AH register this information is passed by placing the function number in the AH register depending on the function being used, other information may be needed depending on the function being used, other information may be needed

14 ECE 291 Lecture 9Slide 14 of 22 INT 21h, AH = 02h DOS 1+ - WRITE CHARACTER TO STANDARD OUTPUTDOS 1+ - WRITE CHARACTER TO STANDARD OUTPUT AH = 02hAH = 02h DL = character to writeDL = character to write Return: AL = last character output (despite the official docs which state nothing is returned)Return: AL = last character output (despite the official docs which state nothing is returned) Notes: ^C/^Break are checked, and INT 23 executed if pressed. Standard output is always the screen under DOS 1.x, but may be redirected under DOS 2+. The last character output will be the character in DL unless DL=09h on entry, in which case AL=20h as tabs are expanded to blanks. If standard output is redirected to a file, no error checks (write- protected, full media, etc.) are performedNotes: ^C/^Break are checked, and INT 23 executed if pressed. Standard output is always the screen under DOS 1.x, but may be redirected under DOS 2+. The last character output will be the character in DL unless DL=09h on entry, in which case AL=20h as tabs are expanded to blanks. If standard output is redirected to a file, no error checks (write- protected, full media, etc.) are performed

15 ECE 291 Lecture 9Slide 15 of 22 INT 21h, AH = 6 DOS 1+ - DIRECT CONSOLE OUTPUTDOS 1+ - DIRECT CONSOLE OUTPUT AH = 06hAH = 06h DL = character to output (except FFh)DL = character to output (except FFh) Return: AL = character output (despite official docs which state nothing is returned) (at least DOS 2.1-7.0)Return: AL = character output (despite official docs which state nothing is returned) (at least DOS 2.1-7.0) Notes: Does not check ^C/^Break. Writes to standard output, which is always the screen under DOS 1.x, but may be redirected under DOS 2+Notes: Does not check ^C/^Break. Writes to standard output, which is always the screen under DOS 1.x, but may be redirected under DOS 2+

16 ECE 291 Lecture 9Slide 16 of 22 Displaying A Single Character Using INT 21h Example: Suppose that the letter ‘A’ is to be printed to the screen at the current cursor positionSuppose that the letter ‘A’ is to be printed to the screen at the current cursor position Can use function 02h or 06hCan use function 02h or 06h INT 21h must also be told which letter to printINT 21h must also be told which letter to print the ASCII code must be placed into DL register the ASCII code must be placed into DL register MOVDL, ‘A’ MOVAH, 06h INT21h

17 ECE 291 Lecture 9Slide 17 of 22 INT 21h, AH = 09h DOS 1+ - WRITE STRING TO STANDARD OUTPUTDOS 1+ - WRITE STRING TO STANDARD OUTPUT AH = 09hAH = 09h DS:DX -> '$'-terminated stringDS:DX -> '$'-terminated string Return: AL = 24h (the '$' terminating the string, despite official docs which state that nothing is returned)Return: AL = 24h (the '$' terminating the string, despite official docs which state that nothing is returned) Notes: ^C/^Break are checked, and INT 23 is called if either pressed. Standard output is always the screen under DOS 1.x, but may be redirected under DOS 2+. Under the FlashTek X-32 DOS extender, the pointer is in DS:EDXNotes: ^C/^Break are checked, and INT 23 is called if either pressed. Standard output is always the screen under DOS 1.x, but may be redirected under DOS 2+. Under the FlashTek X-32 DOS extender, the pointer is in DS:EDX

18 ECE 291 Lecture 9Slide 18 of 22 Displaying A Character String Using INT 21h DOS function 09h displays a character string that ends with ‘$’DOS function 09h displays a character string that ends with ‘$’ MSGDB‘This is a test line’,’$’ … MOVDX, MSG MOVAH, 09h INT21h The string will be printed beginning at the current cursor positionThe string will be printed beginning at the current cursor position

19 ECE 291 Lecture 9Slide 19 of 22 INT 21h, AH = 01h DOS 1+ - READ CHARACTER FROM STD INPUT, WITH ECHODOS 1+ - READ CHARACTER FROM STD INPUT, WITH ECHO AH = 01hAH = 01h Return: AL = character readReturn: AL = character read Notes: ^C/^Break are checked, and INT 23 executed if read. ^P toggles the DOS-internal echo-to-printer flag. ^Z is not interpreted, thus not causing an EOF if input is redirected. Character is echoed to standard output. Standard input is always the keyboard and standard output the screen under DOS 1.x, but they may be redirected under DOS 2+Notes: ^C/^Break are checked, and INT 23 executed if read. ^P toggles the DOS-internal echo-to-printer flag. ^Z is not interpreted, thus not causing an EOF if input is redirected. Character is echoed to standard output. Standard input is always the keyboard and standard output the screen under DOS 1.x, but they may be redirected under DOS 2+

20 ECE 291 Lecture 9Slide 20 of 22 Reading A Single Character Using INT 21h DOS function 01h reads a single character typed from the keyboard and echoes that character to the screenDOS function 01h reads a single character typed from the keyboard and echoes that character to the screen MOVAH, 01h INT21h The computer will wait until the user presses a key, then input character will be in ALThe computer will wait until the user presses a key, then input character will be in AL

21 ECE 291 Lecture 9Slide 21 of 22 INT 10h The DOS function calls allow a key to be read and a character to be displayed but the cursor is difficult to position at a specific location on the screen.The DOS function calls allow a key to be read and a character to be displayed but the cursor is difficult to position at a specific location on the screen. The BIOS function calls allow more control over the video display and require less time to execute than the DOS function callsThe BIOS function calls allow more control over the video display and require less time to execute than the DOS function calls BIOS provides interrupt INT 10h, known as the video interrupt, which gives access to various functions to control video screenBIOS provides interrupt INT 10h, known as the video interrupt, which gives access to various functions to control video screen Before we place information on the screen we should get the position of the cursor:Before we place information on the screen we should get the position of the cursor: function 03h reads cursor position (DH=Row, DL=Column, BH=Page #) function 02h sets cursor position (DH=Row, DL=Column, BH=Page #)

22 ECE 291 Lecture 9Slide 22 of 22 INT 10h Function 0Fh finds the number of the active pageFunction 0Fh finds the number of the active page the page number is returned in the BH register the page number is returned in the BH register The cursor position assumes thatThe cursor position assumes that the left hand page column is column 0 progressing across a line to column 79 the left hand page column is column 0 progressing across a line to column 79 the row number corresponds to the character line number on the screen, the top line being line 0 the row number corresponds to the character line number on the screen, the top line being line 0


Download ppt "ECE291 Lecture 10 Interrupts II. ECE 291 Lecture 9Slide 2 of 22 Lecture outline Installing/Removing ISRsInstalling/Removing ISRs Interrupt SchedulingInterrupt."

Similar presentations


Ads by Google