CS454 Lecture Notes - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

CS454 Lecture Notes

Description:

As a result of pop: sp points to the location where the return address is saved. ... load PC from top of stack and increment SP (pop stack) ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 15
Provided by: toddli
Category:
Tags: cs454 | lecture | notes | pop

less

Transcript and Presenter's Notes

Title: CS454 Lecture Notes


1
CS454 Lecture Notes
  • Process Management In Xinu

2
Process Management (Ch 4)
  • Refer to notes for the x86 register definitions.
  • Context switch Method of saving the state
    (context) of the machine during execution of one
    process (registers), and restoring the machine
    state of another process and continue execution.
  • Context switches can occur in the following
    situations
  • Current process time quantum expires
  • Waiting for I/O request
  • Semaphore wait

3
Context Switching During Subroutine Execution
  • Caller
  • Push parameters on stack. (1st parameter is on
    TOP of the stack)
  • Call subroutine (JSR)
  • Callee
  • Create a current frame ptr (push BP, which points
    to the previous record).
  • Reserve space for locals save registers used
    for locals.
  • Execute Parameters and locals are accessed from
    stack using BP as the base pointer.
  • Release space for locals restore registers used
    for locals.
  • Restore the previous frame pointer (pop BP).
  • Return from subroutine (RTS)
  • Caller
  • Remove the parameters from the stack.

4
General C Stack Diagram
  • C Stack

5
C Conventions Function Invocation
  • 1. Type conversion takes place when arguments are
    pass to functions
  • char, short --gt int (long) (4 bytes)
  • float --gt double (8 bytes)
  • 2. Return value
  • char, short, int, float returned through d0 as 4
    bytes
  • double returned through d0, d1 as 8 bytes
  • 3. Before any procedure (function) call
  • Push parameters in the reverse order on the stack
    (callers responsibility)
  • 4. Jump to subroutine instruction
  • return address is pushed on the stack
  • control goes to the subroutine

6
C Conventions Function Invocation cont.
  • 5. When any procedure (function) is compiled
  • the first instruction is always link, a6, -d
  • d is the number of bytes for local variables
  • link is a powerful instruction, its effect is as
    follows
  • push a6
  • sp -gt a6
  • sp - d -gt sp
  • 6. The register a6 is used as the Frame Pointer
    (FP) for the activation stack record (frame) for
    the procedure call. The local variables and
    parameters are accessed relative to a6. The
    activation stack record is released when the
    procedure returns.

7
C Conventions Function Invocation cont.
  • 7. In the compiled code for a procedure, the
    instruction before the return instruction (rts or
    rte) is always unlk a6
  • The effect of the unlk instruction is as
    follows
  • a6 -gt sp (release local variable area)
  • pop a6 (recover old FP pop the contents and
    store in a6)
  • As a result of pop sp points to the location
    where the return address is saved. The register
    a6 points to the activation stack record before
    the call.
  • 8. Return instruction
  • To return from a call, the called routine
    executes an rts (return from subroutine) or an
    rte (return from exception).
  • rts expects the top of the stack to contain the
    return address
  • rts
  • load PC from top of stack and increment SP (pop
    stack)
  • rte expects the top of the stack to contain the
    new value of SR (process status word) and below
    that in the stack there should be a return
    address
  • rte
  • load SR from top of stack and then pop stack
  • load PC from top of stack and pop stack

8
C Conventions Function Invocation cont.
  • 9. The jump to subroutine instruction is always
    followed by an instruction addq e, sp. The
    purpose of the instruction is to release the
    parameter area. Note here the convention is that
    the caller removes the parameters from the stack
    once the call is returned.
  • 10. As a result of the conventions for a
    procedure call the first argument (for the
    procedure) is always supposed to be located at 8
    relative to FP (also known as a6).

9
Diagrams of Subroutine Context Switches
  • Caller before JSR

10
Diagram cont.
  • Caller JSR

11
Diagram cont.
  • Callee
  • Link a6, -d
  • Push a6
  • SP -gt a6
  • SP - d -gt SP

12
Diagram cont.
  • Callee
  • Unlk
  • a6 -gt SP
  • pop a6

13
Diagram cont.
  • Callee
  • RTS
  • pop (PC)

14
Diagram cont.
  • Caller
  • Releases the arguments
Write a Comment
User Comments (0)
About PowerShow.com