.include "defines.h" .data hello: ta8 .string - - PDF document

include defines h data hello ta8 string hello world n
SMART_READER_LITE
LIVE PREVIEW

.include "defines.h" .data hello: ta8 .string - - PDF document

System call example .include "defines.h" .data hello: ta8 .string "hello world\n" .text .globl _start _start: movl $SYS_write,%eax // SYS_write = 4 Spring 200 6 movl $STDOUT,%ebx // fd =


slide-1
SLIDE 1

1

1

הנבמ םיבשחמ

ta8

Spring 2006 Amar Lior

Adapted from Computer Organization&Design, H/S interface, Patterson Hennessy@UCB,3rd edition 2

Exceptions and Interrupts

Exception: An unscheduled event that

disrupts program execution and change its flow

Interrupts: An exception that comes from

  • utside of the processor

3

Exception types:

Program

e.g. overflow, division by zero, using undefined

instruction

Invoking the operating system from user

program systemcall

Timer

Generated by internal processor timer Used in pre-emptive multi-tasking

I/O

from I/O controller (keyboard, disk)

Hardware failure

e.g. memory parity error 4

System call example

.include "defines.h" .data hello: .string "hello world\n" .text .globl _start _start: movl $SYS_write,%eax // SYS_write = 4 movl $STDOUT,%ebx // fd = fileno(stdio) movl $hello,%ecx // buf = str movl $12,%edx // count = 0x6 int $0x80 movl $SYS_exit,%eax xorl %ebx,%ebx int $0x80 ret

5

Program Flow Control

6

How Exception are Handled

The address of the affected address is saved

in the EPC register

The cause of the register is used to record

the exception type.

Than the process jump to the exception

address which is the operating system entry point for exception handling

In MIPS 0x8000 0180 In SPIM 0x8000 0080

slide-2
SLIDE 2

2

7

Interrupt Cycle

Added to instruction cycle Processor checks for interrupt

Indicated by an interrupt signal

If no interrupt, fetch next instruction If interrupt pending:

Suspend execution of current program Save context Set PC to start address of interrupt handler routine Process interrupt Restore context and continue interrupted program 8

Instruction Cycle (with Interrupts) - State Diagram

9

Multiple Interrupts

Disable interrupts

Processor will ignore further interrupts whilst processing

  • ne interrupt

Interrupts remain pending and are checked after first

interrupt has been processed

Interrupts handled in sequence as they occur

Define priorities

Low priority interrupts can be interrupted by higher

priority interrupts

When higher priority interrupt has been processed,

processor returns to previous interrupt

10

Multiple Interrupts - Sequential

11

Multiple Interrupts - Nested

12

Example - PC Bus

80x86 has one interrupt line 8086 based systems use one 8259A

interrupt controller

8259A has 8 interrupt lines Called Programmable Interrupt Controller

PIC in short.

slide-3
SLIDE 3

3

13

Sequence of Events

8259A accepts interrupts 8259A determines priority 8259A signals 8086 (raises INTR line) CPU Acknowledges 8259A puts correct vector on data bus CPU processes interrupt

14

PC Interrupt Layout

8086 INTR 8259A IRQ0 IRQ1 IRQ2 IRQ3 IRQ4 IRQ5 IRQ6 IRQ7

System Timer Keyboard Slave 8259A Serial port Serial port IDE controller Floppy controller LPT1 15

The 8086 Interrupt table

Trap

Invalid opcode

6

Available for software and hardware interrupts

32-255 Fault

Page Fault

14 Trap

Overflow

4 Trap

Breakpoint

3 Trap Non-Maskable Interrupt (NMI) 2 Trap or Fault Debug exception 1 Fault Divide by zero Type Description Number

  • Fault – The return address point to the instruction that

caused the exception

  • Trap – The return address points to the instruction after the
  • ne that caused the interrupt

16

Exception Handling in MIPS (SPIM)

In MIPS processors, a part of the CPU called

coprocessor 0 records the information that software needs to handle exception

Not all the coprocessor 0’s registers are

implemented by SPIM

The mfc0 and mtc0 instructions are used to

access those registers

The EPC contain the address of the offending

instruction (if the exception was internal)

And the address if the next instruction if the

exception was external

17

Interrupt related registers

Address of instruction that caused exception 14 Epc Exception type and pending interrupt bits 13 Cause Interrupt mask and enable bits 12 Status Value compared against timer that caused interrupt when they match 11 Compare Timer 9 Count Memory address at which offending memory reference

  • ccurred

8 BadVAddr Usage Register Number Register Name

18

The Status Register

  • The interrupt mask contain a bit for each of the six hardware and two software

interrupt level

  • Value of 1 means interrupt from that level can interrupt the processor
  • When an interrupt arrive it sets its “interrupt pending” bit in the cause register even if

the mask is 0

  • When an interrupt is pending it will interrupt the processor when the mask is enabled.
  • The user mode is 0 when in kernel mode and 1 when in user mode (always 1 in

spim)

  • The exception level is usually 0 but is set to 1 when exception occur, in this

situation interrupts are disabled and the EPC is not updated if another exception

  • ccur. Enable exception handler from being disturbed by an Exception or

interrupt

  • If the interrupt enable bit is 1 interrupt are allowed

I n t e r r u p t e n a b l e 1 E x c e p t i

  • n

L e v e l 4 U s e r M

  • d

e 8 15

Interrupt mask

slide-4
SLIDE 4

4

19

Cause Register

The delayed branch is 1 if the last exception

  • ccurred in the delay slot of a branch

The interrupt pending bits become 1 when

an interrupt is raised at a given hardware or software level

The exception code describe the cause of the

exception through the codes in next slide

2 6 8 15

Pending Interrupts Exception Code Branch Delay

31 20

Exception codes

Floating point exception FPE 15 Trap Tr 13 Arithmetic overflow exception Ov 12 Coprocessor unimplemented CpU 11 Reserved instruction exception RI 10 Breakpoint exception Bp 9 Syscall exception Sys 8 Buss error on data load or store DBE 7 Buss error in instruction fetch IBE 6 Address error exception (store) AdES 5 Address error exception (load or fetch) AdEL 4 Interrupt (hardware) Int

Cause of Exception Name Number

21

Handling the Exception

Exception and interrupts cause the MIPS

processor to jump to a piece of code at address 0x8000 0180 (kernel address space)

Called the exception handler This code examine the exception’s code and

jumps to an appropriate point in the

  • perating system

The operating system respond by

terminating the process or by performing some action

22

Exception handler example