ece291 lecture 10 interrupts ii. ece 291 lecture 9slide 2 of 22 lecture outline installing/removing...

22
ECE291 ECE291 Lecture 10 Lecture 10 Interrupts II Interrupts II

Upload: julianna-harrell

Post on 18-Jan-2018

225 views

Category:

Documents


0 download

DESCRIPTION

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

TRANSCRIPT

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

ECE291ECE291Lecture 10Lecture 10Interrupts IIInterrupts II

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 22 of 22 of 22

Lecture outlineLecture outline

• Installing/Removing ISRsInstalling/Removing ISRs• Interrupt SchedulingInterrupt Scheduling• INT 21hINT 21h• INT 16hINT 16h• INT 10hINT 10h

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 33 of 22 of 22

Interrupt Service RoutinesInterrupt 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 Currently running program should have no idea that it

was interrupted. was interrupted. ISRs should be as short as possible because lower ISRs should be as short as possible because lower

priority interrupts are blocked from executing until the priority interrupts are blocked from executing until the higher priority ISR completeshigher priority ISR completes

Function Action

INT 21h Function 25h Set Interrupt vectorINT 21h Function 35h Get Interrupt vectorINT 21h Function 31h Terminate and stay resident

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 44 of 22 of 22

Installing ISRsInstalling ISRs

Let Let N N be the interrupt to servicebe 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 Set AL = NAL = N Call DOS Function Call DOS Function AH = 35hAH = 35h,, INT 21h INT 21h Returns: Returns: ES:BXES:BX = Address stored at vector N = 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 Set DS:DX DS:DX = New Routine = New Routine Set Set AL = NAL = N DOS FunctionDOS Function AH = 25hAH = 25h, , INT 21hINT 21h

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 55 of 22 of 22

Installing ISRsInstalling ISRs• Interrupts can be installed, Interrupts can be installed,

chained, or called chained, or called

• Install New interruptInstall New interruptreplace old interruptreplace old interrupt

• Chain into interruptChain into interruptService myCode firstService myCode first

• Call Original InterruptCall Original InterruptService MyCode lastService 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

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 66 of 22 of 22

Removing ISRsRemoving ISRs

• To remove your ISR from the interrupt To remove your ISR from the interrupt vector table, you simply write the value of vector table, you simply write the value of the original handler back to the tablethe original handler back to the table

• This will overwrite the CS:IP of the ISR This will overwrite the CS:IP of the ISR you specified when you installed ityou specified when you installed it

• Again, use INT 21h, function 25h to set the Again, use INT 21h, function 25h to set the value of a vector in the tablevalue of a vector in the table

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 77 of 22 of 22

Timer Example – Install interruptTimer Example – Install interrupt;====== Install Interrupt =====InstallTimer ;Install new INT 8

vectorpush espush dxpush axpush bx

movmov al, 8al, 8 ;INT = 8;INT = 8

movmov ah, 35hah, 35h ;Read Vector ;Read Vector Subfunction Subfunction

intint 21h21h ;DOS Service;DOS Service

movmov word [oldv+0], bxword [oldv+0], bxmovmov word [oldv+2], esword [oldv+2], esmovmov al, 8al, 8 ;INT = 8;INT = 8

movmov ah, 25hah, 25h ;Set Vector Subfunction;Set Vector Subfunctionmovmov dx, myint dx, myint

;DS:DX point to function;DS:DX point to functionintint 21h21h ;DOS Service;DOS Service

pop bx pop bx pop axpop axpop dxpop dxpop espop esretret

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 88 of 22 of 22

Timer interrupt – Uninstall InterruptTimer interrupt – Uninstall Interrupt;====== Uninstall Interrupt ===========RemoveTimer ; Uninstall Routine (Reinstall old vector)

push dspush dxpush axmov dx, word [oldv+0]mov ds, word [oldv+2]

mov al, 8 ; INT = 8mov ah, 25h ; Subfunction = Set Vector

int 21h ; DOS Service

pop axpop dxpop dsret

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 99 of 22 of 22

The complete code with exeThe complete code with exe• www.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.exe

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 1010 of 22 of 22

Interrupt SchedulingInterrupt Scheduling

• Consider a system that needs to perform Consider a system that needs to perform several periodic tasks within a given timeseveral periodic tasks within a given time

• These tasks are in the form of interrupts These tasks are in the form of interrupts with different priorities and different with different priorities and different behavior (preemptive/non-preemptive)behavior (preemptive/non-preemptive)

• We need to determine if the tasks are We need to determine if the tasks are schedulableschedulable – if there exists an – if there exists an arrangement of them such that all are arrangement of them such that all are completed by their respective deadlinescompleted by their respective deadlines

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 1111 of 22 of 22

Interrupt SchedulingInterrupt 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

TaskTask PriorityPriority Run TimeRun Time DeadlineDeadline FreqFreq PeriodPeriod LoadLoad

PartyingPartying 11 3 hrs3 hrs 10 hrs10 hrs 1/15 hrs1/15 hrs 15 hrs15 hrs 20%20%

BeerBeer 22 5 hrs5 hrs 15 hrs15 hrs 1/20 hrs1/20 hrs 20 hrs20 hrs 25%25%

SleepSleep 33 11 hrs11 hrs 30 hrs30 hrs 1/33 hrs1/33 hrs 33 hrs33 hrs 33%33%

SchoolSchool 33 4 hrs4 hrs 20 hrs20 hrs 1/50 hrs1/50 hrs 50 hrs50 hrs 8%8%

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 1212 of 22 of 22

Interrupt SchedulingInterrupt Scheduling

• Here’s a timing diagram corresponding to the Here’s a timing diagram corresponding to the previous tableprevious table

• We’ll use it in order to calculate the worst-case We’ll use it in order to calculate the worst-case completion times of Johnny’s taskscompletion times of Johnny’s tasks

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 1313 of 22 of 22

INT 21hINT 21h• DOS provides DOS provides INT 21hINT 21h, which is called the , which is called the DOS function DOS function

dispatcherdispatcher and supports functions such as: read from the and supports functions such as: read from the keyboard, write to the screen, write to the printer, read keyboard, write to the screen, write to the printer, read and write to disk files, etc.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 this information is passed by placing the function number in the

AH registerAH register depending on the function being used, other information may be depending on the function being used, other information may be

neededneeded

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 1414 of 22 of 22

INT 21h, AH = 02hINT 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 Return: AL = last character output (despite the official docs which state nothing is returned)state nothing is returned)

• Notes: ^C/^Break are checked, and INT 23 executed if pressed. Notes: ^C/^Break are checked, and INT 23 executed if pressed. Standard output is always the screen under DOS 1.x, but may be Standard output is always the screen under DOS 1.x, but may be redirected under DOS 2+. The last character output will be the 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 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 tabs are expanded to blanks. If standard output is redirected to a file, no error checks (write- protected, full media, etc.) are performed file, no error checks (write- protected, full media, etc.) are performed

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 1515 of 22 of 22

INT 21h, AH = 6INT 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 Return: AL = character output (despite official docs which state nothing is returned) (at least DOS 2.1-7.0)nothing is returned) (at least DOS 2.1-7.0)

• Notes: Does not check ^C/^Break. Writes to standard output, which Notes: Does not check ^C/^Break. Writes to standard output, which is always the screen under DOS 1.x, but may be redirected under is always the screen under DOS 1.x, but may be redirected under DOS 2+ DOS 2+

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 1616 of 22 of 22

Displaying A Single CharacterDisplaying A Single CharacterUsing INT 21hUsing INT 21h

Example:Example:• Suppose that the letter ‘A’ is to be printed to the screen Suppose that the letter ‘A’ is to be printed to the screen

at the current cursor positionat the current cursor position• Can use function 02h or 06hCan use function 02h or 06h• INT 21h must also be told which letter to print INT 21h must also be told which letter to print

the ASCII code must be placed into DL registerthe ASCII code must be placed into DL register

MOVMOV DL, ‘A’DL, ‘A’MOVMOV AH, 06hAH, 06hINTINT 21h21h

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 1717 of 22 of 22

INT 21h, AH = 09hINT 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 Return: AL = 24h (the '$' terminating the string, despite official docs which state that nothing is returned)which state that nothing is returned)

• Notes: ^C/^Break are checked, and INT 23 is called if either Notes: ^C/^Break are checked, and INT 23 is called if either pressed. Standard output is always the screen under DOS 1.x, but pressed. Standard output is always the screen under DOS 1.x, but may be redirected under DOS 2+. Under the FlashTek X-32 DOS may be redirected under DOS 2+. Under the FlashTek X-32 DOS extender, the pointer is in DS:EDXextender, the pointer is in DS:EDX

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 1818 of 22 of 22

Displaying A Character StringDisplaying A Character StringUsing INT 21h Using INT 21h

• DOS function 09h displays a character string DOS function 09h displays a character string that ends with ‘$’that ends with ‘$’

MSGMSG DBDB ‘This is a test line’,’$’‘This is a test line’,’$’……MOVMOV DX, MSGDX, MSG

MOVMOV AH, 09hAH, 09hINTINT 21h21h

• The string will be printed beginning at the current The string will be printed beginning at the current cursor positioncursor position

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 1919 of 22 of 22

INT 21h, AH = 01hINT 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 Notes: ^C/^Break are checked, and INT 23 executed if read. ^P toggles the DOS-internal echo-to-printer flag. ^Z is not interpreted, toggles the DOS-internal echo-to-printer flag. ^Z is not interpreted, thus not causing an EOF if input is redirected. Character is echoed thus not causing an EOF if input is redirected. Character is echoed to standard output. Standard input is always the keyboard and to standard output. Standard input is always the keyboard and standard output the screen under DOS 1.x, but they may be standard output the screen under DOS 1.x, but they may be redirected under DOS 2+ redirected under DOS 2+

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 2020 of 22 of 22

Reading A Single CharacterReading A Single CharacterUsing INT 21h Using INT 21h

• DOS function 01h reads a single character typed DOS function 01h reads a single character typed from the keyboard and echoes that character to from the keyboard and echoes that character to the screenthe screen

MOVMOV AH, 01hAH, 01hINTINT 21h21h

• The computer will wait until the user presses a The computer will wait until the user presses a key, then input character will be in ALkey, then input character will be in AL

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 2121 of 22 of 22

INT 10hINT 10h• The DOS function calls allow a key to be read and a character to be 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 displayed but the cursor is difficult to position at a specific location on the screen.the screen.

• The BIOS function calls allow more control over the video display The BIOS function calls allow more control over the video display and require less time to execute than the DOS function callsand require less time to execute than the DOS function calls

• BIOS provides interrupt BIOS provides interrupt INT 10hINT 10h, known as the, known as the video interruptvideo interrupt, , which gives access to various functions to control video screenwhich gives access to various functions to control video screen

• Before we place information on the screen we should get the position Before we place information on the screen we should get the position of the cursor:of the cursor:function 03h reads cursor position (DH=Row, DL=Column, BH=Page #)function 03h reads cursor position (DH=Row, DL=Column, BH=Page #)function 02h sets cursor position (DH=Row, DL=Column, BH=Page #)function 02h sets cursor position (DH=Row, DL=Column, BH=Page #)

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

ECE 291 Lecture 9ECE 291 Lecture 9

Slide Slide 2222 of 22 of 22

INT 10h INT 10h

• Function 0Fh finds the number of the active Function 0Fh finds the number of the active pagepage the page number is returned in the BH registerthe page number is returned in the BH register

• The cursor position assumes that The cursor position assumes that the left hand page column is column 0 progressing the left hand page column is column 0 progressing

across a line to column 79across a line to column 79 the row number corresponds to the character line the row number corresponds to the character line

number on the screen, the top line being line 0number on the screen, the top line being line 0