1 / 22

ECE291

ECE291. Lecture 10 Interrupts II. Lecture outline. Installing/Removing ISRs Interrupt Scheduling INT 21h INT 16h INT 10h. Interrupt Service Routines. DOS facilities to install ISRs Restrictions on ISRs Currently running program should have no idea that it was interrupted.

ita
Download Presentation

ECE291

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ECE291 Lecture 10 Interrupts II

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

  3. Interrupt Service Routines • DOS facilities to install ISRs • Restrictions on ISRs • 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 Function Action INT 21h Function 25h Set Interrupt vector INT 21h Function 35h Get Interrupt vector INT 21h Function 31h Terminate and stay resident ECE 291 Lecture 9 Slide 3 of 22

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

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

  6. Removing ISRs • To 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 it • Again, use INT 21h, function 25h to set the value of a vector in the table ECE 291 Lecture 9 Slide 6 of 22

  7. ;====== Install Interrupt ===== InstallTimer;Install new INT 8 vector push es push dx push ax push bx mov al, 8 ;INT = 8 mov ah, 35h ;Read Vector Subfunction int 21h ;DOS Service mov word [oldv+0], bx mov word [oldv+2], es mov al, 8 ;INT = 8 mov ah, 25h ;Set Vector Subfunction mov dx, myint ;DS:DX point to function int 21h ;DOS Service pop bx pop ax pop dx pop es ret Timer Example – Install interrupt ECE 291 Lecture 9 Slide 7 of 22

  8. ;====== Uninstall Interrupt =========== RemoveTimer; Uninstall Routine (Reinstall old vector) push ds push dx push ax mov dx, word [oldv+0] mov ds, word [oldv+2] mov al, 8 ; INT = 8 mov ah, 25h ; Subfunction = Set Vector int 21h ; DOS Service pop ax pop dx pop ds ret Timer interrupt – Uninstall Interrupt ECE 291 Lecture 9 Slide 8 of 22

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

  10. Interrupt Scheduling • Consider 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) • We need to determine if the tasks are schedulable – if there exists an arrangement of them such that all are completed by their respective deadlines ECE 291 Lecture 9 Slide 10 of 22

  11. Interrupt Scheduling • Johnny’s back… let’s look at his tasks: • Need to complete the table ECE 291 Lecture 9 Slide 11 of 22

  12. Interrupt Scheduling • Here’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 tasks ECE 291 Lecture 9 Slide 12 of 22

  13. 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. • INT 21h must be told which function is being requested • this information is passed by placing the function number in the AH register • depending on the function being used, other information may be needed ECE 291 Lecture 9 Slide 13 of 22

  14. INT 21h, AH = 02h • DOS 1+ - WRITE CHARACTER TO STANDARD OUTPUT • AH = 02h • DL = character to write • 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 performed ECE 291 Lecture 9 Slide 14 of 22

  15. INT 21h, AH = 6 • DOS 1+ - DIRECT CONSOLE OUTPUT • AH = 06h • 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) • 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+ ECE 291 Lecture 9 Slide 15 of 22

  16. Displaying A Single CharacterUsing INT 21h Example: • Suppose that the letter ‘A’ is to be printed to the screen at the current cursor position • Can use function 02h or 06h • INT 21h must also be told which letter to print • the ASCII code must be placed into DL register MOV DL, ‘A’ MOV AH, 06h INT 21h ECE 291 Lecture 9 Slide 16 of 22

  17. INT 21h, AH = 09h • DOS 1+ - WRITE STRING TO STANDARD OUTPUT • AH = 09h • DS:DX -> '$'-terminated string • 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:EDX ECE 291 Lecture 9 Slide 17 of 22

  18. Displaying A Character StringUsing INT 21h • DOS function 09h displays a character string that ends with ‘$’ MSG DB ‘This is a test line’,’$’ … MOV DX, MSG MOV AH, 09h INT 21h • The string will be printed beginning at the current cursor position ECE 291 Lecture 9 Slide 18 of 22

  19. INT 21h, AH = 01h • DOS 1+ - READ CHARACTER FROM STD INPUT, WITH ECHO • AH = 01h • Return: 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+ ECE 291 Lecture 9 Slide 19 of 22

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

  21. 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 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 thevideo 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: function 03h reads cursor position (DH=Row, DL=Column, BH=Page #) function 02h sets cursor position (DH=Row, DL=Column, BH=Page #) ECE 291 Lecture 9 Slide 21 of 22

  22. INT 10h • Function 0Fh finds the number of the active page • the page number is returned in the BH register • The cursor position assumes that • 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 ECE 291 Lecture 9 Slide 22 of 22

More Related