Скачать презентацию Device Identification Multiple Interrupt Line Software Скачать презентацию Device Identification Multiple Interrupt Line Software

b5fd378ac5719b51a81cb596c3301bee.ppt

  • Количество слайдов: 51

Device Identification § § Multiple Interrupt Line Software poll Daisy Chain Bus Arbitration 1 Device Identification § § Multiple Interrupt Line Software poll Daisy Chain Bus Arbitration 1

Review 2 Review 2

CS 501 Advanced Computer Architecture Lecture 28 Dr. Noor Muhammad Sheikh 3 CS 501 Advanced Computer Architecture Lecture 28 Dr. Noor Muhammad Sheikh 3

Multiple Interrupt Lines • Most straightforward approach • Impractical to implement • Each line Multiple Interrupt Lines • Most straightforward approach • Impractical to implement • Each line might have multiple I/O modules attached to it 4

Software poll • CPU polls to identify the interrupting module and branches to ISR Software poll • CPU polls to identify the interrupting module and branches to ISR on detecting an interrupt • Identification is done using special commands or reading the device status register 5

Simplified Interrupt Circuit for an I/O Interface Data (23… 16) Data (0… 15) ireq Simplified Interrupt Circuit for an I/O Interface Data (23… 16) Data (0… 15) ireq Vect(7… 0) Interrupt request D Info (15… 0) Q Q Interrupt enable D Q Q o. c. iack 6

Priority Chain • The wired OR interrupt signal allows several devices to request interrupt Priority Chain • The wired OR interrupt signal allows several devices to request interrupt simultaneously. • For properation, only one device receives an acknowledge signal. • This situation is called priority chain. 7

Equation iackj= iack j-1^(reqj-1^enb j-1) 8 Equation iackj= iack j-1^(reqj-1^enb j-1) 8

 • The only requesting and enabled device to receive an acknowledge signal is • The only requesting and enabled device to receive an acknowledge signal is the lowest-numbered one. 9

Example using SRC 10 Example using SRC 10

Daisy Chain I/O bus data ireq iack I/O device 0 I/O device 1 I/O Daisy Chain I/O bus data ireq iack I/O device 0 I/O device 1 I/O device j 11

31 30 Unused Ready 4 11 0 vect Interrupt Request Interrupt enable CICTL : 31 30 Unused Ready 4 11 0 vect Interrupt Request Interrupt enable CICTL : The Control Register 12

 • The program has two parts: 1): Initialization subroutine, i. e. , Get. • The program has two parts: 1): Initialization subroutine, i. e. , Get. In 2): Interrupt handler for SRC character input 13

Get. In is called to initialize: • the device • the line done flag Get. In is called to initialize: • the device • the line done flag • Pointer to the buffer 14

 • Upon press of a key, an interrupt is generated. • The ISR • Upon press of a key, an interrupt is generated. • The ISR is entered once for each character of the line. • Carriage return sets the Done flag. • The interrupt handler code is placed at vector address. 15

Conditions for the program: • Only two registers are saved and restored, i. e. Conditions for the program: • Only two registers are saved and restored, i. e. , r 0 and r 1. • PC is stored by interrupt response sequence. • PC is restored by the rfi instruction. 16

Getline Subroutine for Interrupt. Driven Character I/O ; Getline is called with return address Getline Subroutine for Interrupt. Driven Character I/O ; Getline is called with return address in R 31 and a pointer to a ; character buffer in R 1. It will input characters up to a carriage ; return under interrupt control, setting Done to -1 when complete. CR. equ 13 ; ASCII code for carriage return. CIvec. equ 01 F 0 H ; Character input interrupt vector address. Bufp: . dw 1 ; Pointer to next character location. Save: . dw 2 ; Save area for registers on interrupt. Done: . dw 1 ; Flag location is -1 if input complete. Getln: st r 1, Bufp ; Record pointer to next character. edi ; Disable interrupts while changing mask. la r 2, 1 F 1 H ; Get vector address and device enable bit st r 2, CICTL ; and put into control register of device. la r 3, 0 ; Clear the st r 3, Done ; line input done flag. een ; Enable Interrupts br r 31 ; and return to caller. 17

Interrupt Handler for SRC Character Input. org str ldr ld st addi str lar Interrupt Handler for SRC Character Input. org str ldr ld st addi str lar CIvec r 0, Save r 1, Save+4 r 1, Bufp r 0, CIN r 0, 0(r 1) r 1, 4 r 1, Bufp r 1, Exit addi r 0, -CR brnz la str Exit: ldr rfi r 1, r 0, 0 r 0, CICTL r 0, -1 r 0, Done ldr r 0, Save r 1, Save+4 ; Start handler at vector address. ; Save the registers that ; will be used by the interrupt handler. ; Get pointer to next character position. ; Get the character and enable next input. ; Store character in line buffer. ; Advance pointer and ; store for next interrupt. ; Set branch target. ; Carriage return? addi with minus CR. ; Exit if not CR, else complete line. ; Turn off input device by ; disabling its interrupts. ; Get a -1 indicator, and ; report line input complete. ; Restore registers ; of interrupted program. ; Return to interrupted program. 18

CR. equ 13 ; ASCII code for carriage return. CIvec. equ 01 F 0 CR. equ 13 ; ASCII code for carriage return. CIvec. equ 01 F 0 H ; Character input interrupt vector ; address. Bufp: . dw 1 ; Pointer to next character location. 19

Save: . dw 2 Done: . dw 1 Getln: str 1, Bufp ; Save Save: . dw 2 Done: . dw 1 Getln: str 1, Bufp ; Save area for registers on interrupt. ; Flag location is -1 if input complete. ; Record pointer to next character. 20

edi ; Disable interrupts while changing mask. la r 2, 1 F 1 H; edi ; Disable interrupts while changing mask. la r 2, 1 F 1 H; Get vector address and device enable bit st r 2, CICTL; and put into control register of device. 21

la r 3, 0 st r 3, Done een br r 31 ; Clear la r 3, 0 st r 3, Done een br r 31 ; Clear the ; line input done flag. ; Enable Interrupts ; and return to caller. 22

Interrupt Handler for SRC Character Input. org CIvec ; Start handler at vector address. Interrupt Handler for SRC Character Input. org CIvec ; Start handler at vector address. str r 0, Save ; Save the registers that str r 1, Save+4 ; will be used by the interrupt ; handler. 23

ldr r 1, Bufp ld r 0, CIN st r 0, 0(r 1) ; ldr r 1, Bufp ld r 0, CIN st r 0, 0(r 1) ; Get pointer to next character ; position. ; Get the character and enable ; next input. ; Store character in line buffer. 24

addi r 1, 4 str r 1, Bufp lar r 1, Exit ; Advance addi r 1, 4 str r 1, Bufp lar r 1, Exit ; Advance pointer and ; store for next interrupt. ; Set branch target. 25

Example consider an output device, such as a parallel printer connected to the FALCON-A Example consider an output device, such as a parallel printer connected to the FALCON-A CPU. Now suppose that we want to print a document while using an application program like a word processor or a spread sheet. In this section, we will explain the important aspects of hardware and software for implementing an interrupt driven parallel printerface for the FALCON-A. During this discussion, we will also explain the differences and similarities between this interface and the one discussed before. 26

Assumptions • To make things simple, we have made the following assumptions: 1. Only Assumptions • To make things simple, we have made the following assumptions: 1. Only one interrupt pin is available on the FALCON-A, and only one interrupt is possible at a given time with this CPU. This has the implications shown on the next slide 27

Implications of allowing only one interrupt at a time • No NMI possible • Implications of allowing only one interrupt at a time • No NMI possible • No nesting of interrupts possible • No priority structure needed for multiple devices • No arbitration needed for simultaneous interrupts • No need for vectored interrupts, therefore, no need of interrupt vectors and interrupt vector tables • Effect of software initiated interrupts and internal interrupts (exceptions) has to be ignored in this discussion 28

More assumptions 2. 3. 4. 5. 6. 7. 8. Hardware sets and clears the More assumptions 2. 3. 4. 5. 6. 7. 8. Hardware sets and clears the interrupt flag, in addition to other things like saving PC, etc. The address of the ISR is stored at absolute address 2 in memory The ISR will set up a stack in the memory for saving the CPU’s environment One character stored per 16 -bit word in the FALCON-A’s memory and one character transferred during a 16 -bit transfer The calling program will call the ISR for printing the first character through the printer driver Printer will activate ACKNLG# only when not BUSY The exchange of hardware signals between the CPU and the printer will be according to the diagram shown on the next slide 29

30 30

FALCON-A CPU IREQ IACK QSD Logic 1 DFF ACKNLG# R from IRQEN Logic Diagram FALCON-A CPU IREQ IACK QSD Logic 1 DFF ACKNLG# R from IRQEN Logic Diagram for Interrupt Driven I/O on the FALCON-A CPU 31

 • Recall that IRQEN is bit 4 on the centronics control port at • Recall that IRQEN is bit 4 on the centronics control port at logical address 2. • This is mapped onto address 60 of the FALCON-A’s I/O space. • The rest of the hardware is the same as for programmed I/O. 32

Interrupt Software • Our software for the interrupt driven printer example consists of three Interrupt Software • Our software for the interrupt driven printer example consists of three parts: 1). Dummy calling program 2). Printer Driver 3). ISR 33

Sequence of events • Normal processing is assumed to be taking place, e. g. Sequence of events • Normal processing is assumed to be taking place, e. g. , a word processor is executing • User invokes a print command • Printer driver called, and necessary parameters passed to it 34

Main Program (e. g. Word) in progress User invokes Print command Use r 5 Main Program (e. g. Word) in progress User invokes Print command Use r 5 to pass Bufp, r 7 to pass NOB , and r 4 to pass return address to the printer driver Call Printer Driver Return with error code in r 7 NO ERROR? (r 7=0? ) N (r 7≠ 0) Y (r 7=0) Resume Normal Processing Send Error message and invoke Error Routine 35

Responsibility of the Calling Program • Pass the number of bytes to be printed Responsibility of the Calling Program • Pass the number of bytes to be printed and the starting address of the buffer where these bytes are stored to the printer driver • Provide return address • Handle error conditions 36

 • The calling program can also be called the main program. Assumptions: • • The calling program can also be called the main program. Assumptions: • The total number of bytes to be printed is 40. • They are placed in a buffer having the starting address 1024. • The return address of the calling program is stored in r 4. 37

; filename: Example_11 -10. asm ; This program sends a single character ; to ; filename: Example_11 -10. asm ; This program sends a single character ; to a FALCON-A parallel printer ; using an interrupt driven I/O interface ; ; Notes: ; 1. 8 -bit printer data bus connected to ; D<7. . 0> of the FALCON-A (remember big-endian) ; Thus, the printer actually uses addresses 57, 59 & 61 ; ; 2. one character per 16 -bits of data xfered ; ; . org 0 jump [main] a 4 ISR: . sw begin. ISR a 4 PD: . sw Pdriver dv 1: . sw 1024 dv 2: . sw 40 Bufp: . dw 1 NOB: . dw 1 PB: . dw 1 temp: . dw 6 ; 38

; Dummy Calling Program, e. g. , a word processor ; . org 32 ; Dummy Calling Program, e. g. , a word processor ; . org 32 main: load r 6, [a 4 PD] ; r 6 holds address of printer driver ; ; user invokes print command here ; load r 5, [dv 1] ; Prepare registers for passing load r 7, [dv 2] ; information about print buffer. ; ; ; call printer driver ; call r 4, r 6 ; Handle error conditions, if any , upon retun. ; Normal processing resumes ; halt 39

Printer Driver Activities • • • Set port addresses Set up variables for the Printer Driver Activities • • • Set port addresses Set up variables for the STROBE# pulse Initialize printer and enable its IRQEN. Set up printer ISR by pointing to the buffer and initializing counter Make sure that the previous print job is not in progress Set PB flag to block further print jobs till current one is complete Invoke ISR for the first time Pass error message to main program if ISR reports an error 40 Return to main program

The Printer Driver Initialization of the variables* Check the PB flag A message indicating The Printer Driver Initialization of the variables* Check the PB flag A message indicating printing NO in progress PB flag = 0 ? YES Set the PB flag *datap: . equ 56 statusp: . equ 58 controlp: . equ 60 reset: . equ 17 disable: . equ 5 strb_H: . equ 21 strb_L: . equ 20 Initialize the printer and enable interrupt Store the address of the character buffer in Bufp Store the total number of bytes to be printed in NOB Call ISR Return to the Caller ISR Return from ISR 41

; Printer driver ; . org 50 ; starting address of Printer driver ; ; Printer driver ; . org 50 ; starting address of Printer driver ; datap: . equ 56 statusp: . equ 58 controlp: . equ 60 ; reset: . equ 17 ; or 11 h ; used to set unidirectional, enable interrupts, ; auto line feed, and strobe high disable: . equ 5 ; strb_H: . equ 21 ; or 15 h strb_L: . equ 20 ; or 14 h ; ; check PB flag first, if set, ; return with message. ; 42

Pdriver: load r 1, [PB] jnz r 1, [message] movi r 1, 1 store Pdriver: load r 1, [PB] jnz r 1, [message] movi r 1, 1 store r 1, [PB] ; a 1 in PB indicates Print In Progress movi r 1, reset ; use r 1 for data xfer out r 1, controlp store r 5, [Bufp] store r 7, [NOB] ; ; int ; jump [finish] message: nop ; in actual situation, put a message routine here ; to indicate print in progress finish: ret r 4 ; 43

 • int IPC← PC, PC ← M[2], IF ← 0 transfer control to • int IPC← PC, PC ← M[2], IF ← 0 transfer control to ISR • iret PC ← IPC, IF ← 1 return from the ISR Note: Other registers must be saved by the user. 44

ISR Functions for our example • • Save CPU environment Set mask Recover buffer ISR Functions for our example • • Save CPU environment Set mask Recover buffer information Read printer status § Send error message if busy, restore environment and return to calling program. • Load character from buffer and send to printer • Activate STROBE# • Update buffer pointer and character counter § If counter = 0, disable interrupts, clear PB flag. • Restore environment • Return to the calling program 45

; ISR starts here ; . org 100 begin. ISR: movi r 6, temp ; ISR starts here ; . org 100 begin. ISR: movi r 6, temp store r 1, [r 6] store r 3, [r 6+2] store r 4, [r 6+4] store r 5, [r 6+6] store r 7, [r 6+8] ; movi r 3, 1 shiftl r 3, 7 ; to set mask to 0080 h ; load r 5, [Bufp] ; not necessary to use r 5 & r 7 here load r 7, [NOB] ; using r 7 as character counter ; in r 1, statusp ; and r 1, r 3 ; test if BUSY = 1 ? jnz r 1, [error] ; error if BUSY = 1 ; 46

load r 1, [r 5] buffer out r 1, datap movi r 1, strb_L load r 1, [r 5] buffer out r 1, datap movi r 1, strb_L out r 1, controlp movi r 1, strb_H out r 1, controlp addi r 5, 2 store r 5, [Bufp] subi r 7, 1 counter store r 7, [NOB] jz r 7, [suspend] jump [last] ; get char from printer ; update buffer pointer ; update character 47

suspend: store r 7, [PB] ; clear PB flag movi r 1, disable ; suspend: store r 7, [PB] ; clear PB flag movi r 1, disable ; disable future interrupts till out r 1, controlp ; printer driver called again jump [last] error: movi r 7, -1 ; error code in r 7 ; other error codes go here ; last: load r 1, [r 6] load r 3, [r 6+2] load r 4, [r 6+4] load r 5, [r 6+6] load r 7, [r 6+8] iret. end 48

Note that: • We are testing the printer’s BUSY flag within the ISR also. Note that: • We are testing the printer’s BUSY flag within the ISR also. • The testing is being done for a different reason, and it is done only once for each call to the ISR. 49

Save the CPU environment Set mask Recover buffer information Read the printer’s status ISR Save the CPU environment Set mask Recover buffer information Read the printer’s status ISR Error message YES Printer Busy ? NO Load character from the buffer, and send to the printer Activate STROBE# Update buffer pointer and character counter Test the counter NO Counter = 0 ? YES Disable the interrupts and clear PB flag Restore the environment and return to the Calling Program 50

Memory Map for our ISR 0 2 4 32 50 100 Entry Point Address Memory Map for our ISR 0 2 4 32 50 100 Entry Point Address of ISR Data and Pointer Area Main Program (Dummy Calling Program ) Printer Driver ISR. . . 1024 Print Buffer. . . 51