Tuesday, July 24, 2012

Lab3 User Environment



[Preface] A Hope That My Crude Remarks May Draw Forth By Abler People
[前言]拋磚引玉
  • How to do the following lab3?
    • Read following list:
      • Lec4 JOS memory layout.
      • Lec5: Process Creation System call/Interrupt, and Exception Handling
      • Hw5 Hw4
      • Ch.9 of 80386 Programmer's Manual/Ch05 of the IA-32 Developer's Manual.
      • Lab3 assignment.
    • Dig everything unknown more:
  • Basic setup:
    • IDT.
      • Breakpoint exception.
      • System call exception.
      • Other exceptions.
    • Allocate the memory space for Env structure.
      • Be cared about address mapping.
      • Link each element in the right order.
    • Exercise 1 & 2 is done
  • More setup 
    • Make programs run.
      • Setup the env's virtual memory mapping
        • Map only user level's need address mapping from kern_pgdir.
        • Load ELF file.
        • Stack.
        • Entry address.
        • Set the env's fields well
          • env_status/env_type...etc
      • Let user programs be capable of trapping into kernel.
        • Push the needed variable/registers into kernel stack!
        • Default error handling: Not supported exceptions.
      • Get PartA's grade.
    • Setup exception handlers:
      • Trap entries to support user's functionality.
      • system call setup
        • Handle 0x30 IDT entry.
          • Organize the trap frame..
          • Push the right esp as the trap call's input parameter(trap frame address).
        • Dispatch the eax (syscall num) to the corresponding handler.
          • Extract parameters in the right slot.
          • Return value.
        • User level's this env assignment.
        • Pass exercise 7&8
          • kdebug.c not yet.
      • Protections
        • user_mem_check
          •  permission.
          • legal contiguous memory coverage.
        • evilhello: address' permission setup must be right.
        • Pass All
  • Challenge implementation: fast system call
    • Read carefully about sysenter/sysexit/wrmsr/rdmsr in Intel manual.
    • Setup the following slot in the right vale.
      • MSR_IA32_SYSTEM_CS.
        • GDT must own the right order between ring0/ring3's cs ss
          • ring0:CS
          • ring0:SS
          • ring3:CS
          • ring3:SS
      • MSR_IA32_SYSTEM_EIP.
      • MSR_IA32_SYSTEM_ESP
    • library wrapper
      • Assign the right value into regs.
        • ebp(stack pointer used by sysenter).
        • esi (intruction pointer used by sysenter).
        • place arguments into the right registers.
      • Be careful about push/restore clobber registers.
    • Trap entry's handler
      • Before calling system call function.
        • push the needed vars into stack to organize the Trapframe.
        • push the organize trapframe pointer into stack
      • After calling system call function.
        • Assign the right value into regs.
          • edx(stack pointer used by sysenter).
          • ecx (intruction pointer used by sysenter).
        • Retroe the needed regs
    • Finish Fast Syscall Challenge



No comments:

Post a Comment

歡迎正面積極的討論。