5
COMP 4550 Context Switch Autonomous Agents Lab, University of Manitoba [email protected] http://www.cs.umanitoba.ca/~jacky http://aalab.cs.umanitoba.ca

COMP 4550 Context Switch - Department of Computer Science · 2012. 3. 17. · Context Switch Outline 1. Save all registers 2. Find next task 3. Setup thread context 4. Return from

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

  • COMP 4550Context Switch

    Autonomous Agents Lab, University of [email protected]

    http://www.cs.umanitoba.ca/~jackyhttp://aalab.cs.umanitoba.ca

  • Context Switch Outline

    1. Save all registers2. Find next task3. Setup thread context4. Return from interrupt

    ● Area to save the registers○ Reserve memory in task control block (TCB)○ Stack

  • AVR Interrupt Processing

    ● When an interrupt occurs, the following events will take place

    1. PC is pushed onto stack (2 Bytes)2. ISR is responsible for saving the SREG register3. Save RAMPZ register

    ○ AtMega128 (>64kB of ROM)

    ● Sample interrupt handler routinepush __zero_reg__ ; R1push __tmp_reg__ ; R0in __tmp_reg__,_SFR_IO_ADDR(SREG) ; Software has to save SREG/PSWpush __tmp_reg__push r18 ; Save remaining volatile GP registerspush r19...

  • Interrupt Handler Definition

    ISR(CONTEXT_TIMER_ISR, ISR_NAKED ISR_BLOCK) { // save state // general and special purpose registersasm volatile( "\t push __zero_reg__\n" "\t push __tmp_reg__\n" "\t in __tmp_reg__,__SREG__\n" "\t push __tmp_reg__\n"#if defined(RAMPZ) "\t in __tmp_reg__,%0\n" "\t push __tmp_reg__\n"#endif "\t clr __zero_reg__\n" "\t push r2\n" "\t push r3\n" ... : : "I"(_SFR_IO_ADDR(RAMPZ)) : );

  • AVR Interrupt Processing

    To restore context

    1. Setup stack pointer to point to common stack2. pop registers, SREG, RAMPZ3. RETI (Enables I Bit in SREG)