Page 141 - A Practical Guide from Design Planning to Manufacturing
P. 141

114   Chapter Four

        memory. These interrupt instructions are used to access procedures
        within other applications such as the operating system. Requests to
        access hardware are handled in this way without the calling program
        needing any details about the type of hardware being used or even the
        exact location of the handler program that will access the hardware. The
        operating system maintains a global table of pointers to these various
        handlers. Different handlers are loaded by changing the target addresses
        in this global table.
          There are three types of control flow changes that typically use global
        lookup to determine their target address: software interrupts, hard-
        ware interrupts, and exceptions. Software interrupts are caused by the
        program executing an interrupt instruction. A software interrupt differs
        from a call instruction only in how the target address is specified.
        Hardware interrupts are caused by events external to the processor.
        These might be a key on the keyboard being pressed, a USB device
        being plugged in, a timer reaching a certain value, or many others. An
        architecture cannot define all the possible hardware causes of inter-
        rupts, but it must give some thought as to how they will be handled. By
        using the same mechanism as software interrupts, these external events
        are handled by the appropriate procedure before returning control to the
        program that was running when they occurred.
          Exceptions are control flow events triggered by noncontrol flow
        instructions. When a divide instruction attempts to divide by 0, it is
        useful to have this trigger a call to a specific procedure to deal with this
        exceptional event. It makes sense that the target address for this pro-
        cedure should be stored in a global table, since exceptions allow any
        instruction to alter the control flow. An add that produced an overflow, a
        load that caused a memory protection violation, or a push that overflowed
        the stack could all trigger a change in the program flow. Exceptions are
        classified by what happens after the exception procedure completes
        (Table 4-17).
          Fault exceptions are caused by recoverable events and return to retry
        the same instruction that caused the exception. An example would be a
        push instruction executed when the stack had already used all of its
        available memory space. An exception handler might allocate more
        memory space before allowing the push to successfully execute.



        TABLE 4-17  Exception Types
         Type              Return to                 Example
        Fault     Instruction causing exception   Stack overflow
        Trap      Instruction after cause of exception  Divide by 0
        Abort     Shutdown procedure              Invalid instruction
   136   137   138   139   140   141   142   143   144   145   146