1 / 31

Computer Systems

Computer Systems. The instruction set architecture. Intel Processors. A stable platform for nearly 20 years 8086 (1978) 8 bits 80186 (1980) 8 or 16 bits 80286 (1982) 16 bits 80386 (1985) 32 bits (33 MHz) Pentium 4 (2001) 32 bits (3.2 GHz). Intel Architecture 32-bit.

gasha
Télécharger la présentation

Computer Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Systems The instruction set architecture Computer Systems – the instruction set architecture

  2. Intel Processors • A stable platform for nearly 20 years • 8086 (1978) 8 bits • 80186 (1980) 8 or 16 bits • 80286 (1982) 16 bits • 80386 (1985) 32 bits (33 MHz) • Pentium 4 (2001) 32 bits (3.2 GHz) Computer Systems – the instruction set architecture

  3. Intel Architecture 32-bit • Each processor was designed to be backward compatible • Co-processor is been integrated • Extra instructions are added for vector manipulation (MMX, SSE) • Gcc didn’t use these instructions until version 3.1 (May 2002) Computer Systems – the instruction set architecture

  4. 2 3 1 0 Y Y Y Y A A A A X & Y X + Y X ^ Y X - Y B B B B X X X X A L U A L U A L U A L U ALU is still the core • Unit that performs arithmetic / logic operations on two inputs Computer Systems – the instruction set architecture

  5. Basic Knowledge • Introduced in ‘Digitale Techniek’ Computer Systems – the instruction set architecture

  6. Timing • For an subtraction, you needed three steps (automated with an sequencer) Computer Systems – the instruction set architecture

  7. Registerfile ALU Micro-instructions int subtract(int invoer1, int invoer2) { return (invoer1 - invoer2); } _subtract: pushl %ebp movl %esp, %ebp movl 12(%ebp), %edx movl 8(%ebp), %eax subl %edx, %eax popl %ebp ret Gcc -S • The ‘invoer’ is moved from memory to two registers (a,d), followed by operation subl Computer Systems – the instruction set architecture

  8. Integer Arithmetic Operations Of the 15 operations, we concentrate on 4 (Y86) Computer Systems – the instruction set architecture

  9. Disassemblers Objdump –d subtract.o│ gdb>disas subtract (page 205) 00000022 <_subtract>: 22: 55 push %ebp 23: 89 e5 mov %esp,%ebp 25: 8b 55 0c mov 0xc(%ebp),%edx 28: 8b 45 08 mov 0x8(%ebp),%eax 2b: 29 d0 sub %edx,%eax 2d: 5d pop %ebp 2e: c3 ret 2f: 90 nop • The ‘l’ behind subl is omitted (refers to the standard 32-bits dataformat of IA32: ‘long word’ {int, float, pointer}) Computer Systems – the instruction set architecture

  10. Memory invisible to user code 0xffffffff Kernel virtual memory 0xc0000000 User stack (created at runtime) Memory mapped region for shared libraries printf() function 0x40000000 Run-time heap (created at runtime by malloc) Read/write data Loaded from the hello executable file Read-only code and data 0x08048000 Unused 0 Procedure call Calling procedure push parameter2 on stack Push parameter1 on stack Call subroutine Clean parameters off stack • Stack is part of virtual memory • Every called procedure gets frame on the stack Computer Systems – the instruction set architecture

  11. Stack-based languages • Languages that Support Recursion • e.g., C, Pascal, Java • Code must be “Reentrant” • Multiple simultaneous instantiations of single procedure • Need some place to store state of each instantiation • Arguments • Local variables • Return pointer • Stack Allocated in Frames • state for single procedure instantiation Computer Systems – the instruction set architecture

  12. Stack Frames OlderFrames Caller Frame • (gdb) info stack#0 subtract()#1 main() • (gdb) up / down • (gdb) info framepointersArglistLocalsSaved registers Arguments Frame Pointer (%ebp) Return Addr Old %ebp Saved Registers + Local Variables Argument Build Stack Pointer (%esp) Computer Systems – the instruction set architecture

  13. Call Chain Example Code Structure Call Chain • yoo(…) • { • • • • • who(); • • • • • } • who(…) • { • • • • • amI(); • • • • • amI(); • • • • • } yoo who • amI(…) • { • • • • • amI(); • • • • • } amI amI amI • Procedure amI recursive amI Computer Systems – the instruction set architecture

  14. %ebp Stack Pointer %esp • • • Stack Operation Call Chain yoo • yoo(…) • { • • • • • who(); • • • • • } yoo Computer Systems – the instruction set architecture

  15. Frame Pointer %ebp Stack Pointer %esp • • • Stack Operation Call Chain yoo • who(…) • { • • • • • amI(); • • • • • amI(); • • • • • } yoo who who Computer Systems – the instruction set architecture

  16. Frame Pointer %ebp Stack Pointer %esp • • • Stack Operation Call Chain yoo • amI(…) • { • • • • • amI(); • • • • • } yoo who who amI amI Computer Systems – the instruction set architecture

  17. Frame Pointer %ebp Stack Pointer %esp • • • Stack Operation Call Chain yoo • amI(…) • { • • • • • amI(); • • • • • } yoo who who amI amI amI amI Computer Systems – the instruction set architecture

  18. Frame Pointer %ebp Stack Pointer %esp • • • Stack Operation Call Chain yoo • amI(…) • { • • • • • amI(); • • • • • } yoo who who amI amI amI amI amI amI Computer Systems – the instruction set architecture

  19. Frame Pointer %ebp Stack Pointer %esp • • • Stack Operation Call Chain yoo • amI(…) • { • • • • • amI(); • • • • • } yoo who who amI amI amI amI amI Computer Systems – the instruction set architecture

  20. Frame Pointer %ebp Stack Pointer %esp • • • Stack Operation Call Chain yoo • amI(…) • { • • • • • amI(); • • • • • } yoo who who amI amI amI amI Computer Systems – the instruction set architecture

  21. Frame Pointer %ebp Stack Pointer %esp • • • Stack Operation Call Chain yoo • who(…) • { • • • • • amI(); • • • • • amI(); • • • • • } yoo who who amI amI amI Computer Systems – the instruction set architecture

  22. Frame Pointer %ebp Stack Pointer %esp • • • Stack Operation Call Chain yoo • amI(…) • { • • • • • • • • • } yoo who who amI amI amI amI amI Computer Systems – the instruction set architecture

  23. Frame Pointer %ebp Stack Pointer %esp • • • Stack Operation Call Chain yoo • who(…) • { • • • • • amI(); • • • • • amI(); • • • • • } yoo who who amI amI amI amI Computer Systems – the instruction set architecture

  24. %ebp Stack Pointer %esp • • • Stack Operation Call Chain yoo • yoo(…) • { • • • • • who(); • • • • • } yoo who amI amI amI amI Computer Systems – the instruction set architecture

  25. Machine language Figure 3.17 • Calling routinepush parm2push parm1call subroutine • Calleepush %ebpmov %esp, %ebp…. body of subroutinepop %ebpret Computer Systems – the instruction set architecture

  26. call Dest Dest ret 8 9 0 0 Subroutine Call and Return • Push address of next instruction onto stack • Start executing instructions at Dest • Pop value from stack • Use as address for next instruction Computer Systems – the instruction set architecture

  27. IA32/Linux Register Usage %eax Integer Registers • Two for the stack %ebp, %esp • Three are callee-save %ebx, %esi, %edi save on stack prior to using • Three are as caller-save %eax, %edx, %ecx save on stack prior to calling subroutine • Register %eax also stores returned value Caller-Save Temporaries %edx %ecx %ebx Callee-Save Temporaries %esi %edi %esp Special %ebp Computer Systems – the instruction set architecture

  28. Summary • The Stack Makes Recursion Work • Private storage for each instance of procedure call • Instantiations don’t clobber each other • Addressing of locals + arguments can be relative to stack positions • Can be managed by stack discipline • Procedures return in inverse order of calls • Added as wrapper around ‘your’ code by compiler Computer Systems – the instruction set architecture

  29. Summary • IA32 Procedures Combination of Instructions + Conventions • Call / Ret instructions • Register usage conventions • Caller / Callee save • %ebp and %esp • Stack frame organization conventions Computer Systems – the instruction set architecture

  30. We understand know how the simplest of subroutines is translated in micro-instructions int subtract(int invoer1, int invoer2) { return (invoer1 - invoer2); } _subtract: pushl %ebp movl %esp, %ebp movl 12(%ebp), %edx movl 8(%ebp), %eax subl %edx, %eax popl %ebp ret Conclusion Gcc -S Computer Systems – the instruction set architecture

  31. Assignment • Practice Problem 3.2 (page 142) • Movl $0x4050, %eax Immediate → Register • Movl %ebp, %esp Register→ Register • Movl (%edi,%ecx), %eax Memory → Register • Movl $-17, (%esp) Immediate → Register • Movl %eax, -12(%ebp) Immediate → Memory • Defuse the first two phases of the binary-bomb Computer Systems – the instruction set architecture

More Related