computer systems a programmer s perspec8ve have a tour of
play

Computer Systems A Programmers Perspec8ve Have a - PowerPoint PPT Presentation

Whats next Computer Systems A Programmers Perspec8ve Have a tour of computer system at first... Chapter 1 1 Computer System Runs


  1. What’s ¡next… ¡ ¡ Computer ¡Systems… ¡ ¡ A ¡Programmer’s ¡Perspec8ve ¡ ¡ Have ¡a ¡tour ¡of ¡computer ¡system ¡at ¡first... ¡ Chapter ¡1 ¡ 1 ¡

  2. Computer ¡System ¡ Runs ¡the ¡soKware ¡and ¡ manages ¡the ¡hardware ¡ RISC ¡vs ¡CISC ¡ LOAD/STORE ¡ SOFTWARE ¡ ETC ¡ ADDRESS ¡ } ¡ BUS ¡ Opera8ng ¡ System ¡ DATA ¡ BUS ¡ HARDWARE ¡ ADDRESSIBILITY ¡ BIG/LITTLE ¡ ENDIAN ¡ ALIGNMENT ¡ ISA ¡ PIPELINING ¡ 2 ¡

  3. Opera8ng ¡System ¡ 3 ¡

  4. The ¡role ¡of ¡the ¡opera8ng ¡system ¡ • Protect ¡the ¡computer ¡from ¡misuse ¡ • Provide ¡an ¡abstrac<on ¡for ¡using ¡the ¡hardware ¡ so ¡that ¡programs ¡can ¡be ¡wri?en ¡for ¡a ¡variety ¡ of ¡different ¡hardware ¡ • Manage ¡the ¡resources ¡to ¡allow ¡for ¡reasonable ¡ use ¡by ¡all ¡users ¡and ¡programs ¡on ¡a ¡computer ¡ 4 ¡

  5. The ¡UNIX ¡Opera8ng ¡System ¡ • Developed ¡in ¡1970s ¡at ¡Bell ¡Labs ¡ • Kernel ¡wri?en ¡in ¡C, ¡also ¡developed ¡at ¡the ¡ same ¡<me ¡ – C ¡was ¡developed ¡for ¡the ¡purpose ¡of ¡wri<ng ¡UNIX ¡ and ¡systems ¡programming ¡ • We ¡are ¡using ¡a ¡variant ¡of ¡UNIX ¡named ¡Linux ¡ – Other ¡UNIX ¡variants ¡exist, ¡such ¡as ¡Solaris, ¡and ¡the ¡ various ¡BSDs ¡(OpenBSD, ¡NetBSD, ¡FreeBSD, ¡OSX) ¡ 5 ¡

  6. Linux ¡-­‑ ¡OS ¡ h?ps://www.explainxkcd.com/wiki/index.php/456:_Cau<onary ¡ 6 ¡

  7. SoKware ¡ 7 ¡

  8. Text/Ascii ¡ • A ¡file ¡is ¡a ¡sequence ¡of ¡bytes ¡-­‑ ¡not ¡a ¡magical ¡ container ¡holding ¡the ¡bytes, ¡but ¡the ¡bytes ¡ themselves ¡ • How ¡this ¡informa<on ¡is ¡treated ¡depends ¡on ¡the ¡ context ¡ – the ¡same ¡sequence ¡of ¡bits ¡can ¡be ¡used ¡to ¡represent ¡a ¡ character, ¡or ¡an ¡integer, ¡or ¡a ¡floa<ng-­‑point ¡number, ¡ or ¡an ¡instruc<on, ¡or... ¡ • It's ¡all ¡a ¡ma?er ¡of ¡interpreta<on ¡ • % ¡emacs ¡hellob.c ¡& ¡ 8 ¡

  9. Why ¡assembly ¡language? ¡ • Instruc<on ¡based ¡execu<on ¡ – Each ¡program ¡on ¡a ¡computer ¡is ¡a ¡sequence ¡of ¡ instruc<ons ¡wri?en ¡in ¡machine ¡language ¡ – Processor ¡executes ¡one ¡instruc<on ¡at ¡a ¡<me ¡in ¡a ¡ program, ¡then ¡executes ¡the ¡next ¡one ¡in ¡turn ¡ ¡ – To ¡study ¡code ¡in ¡this ¡form, ¡it's ¡helpful ¡to ¡use ¡ assembly ¡language ¡rather ¡than ¡machine ¡language ¡ code ¡ • gcc ¡–S ¡hellob.c ¡ 9 ¡

  10. Assembly ¡language… ¡really?! ¡ • Chances ¡are, ¡you’ll ¡never ¡write ¡programs ¡in ¡assembly ¡ – Compilers ¡are ¡much ¡be?er ¡& ¡more ¡pa<ent ¡than ¡you ¡are ¡ • But: ¡Understanding ¡assembly ¡is ¡key ¡to ¡machine-­‑level ¡ execu<on ¡model ¡ – Behavior ¡of ¡programs ¡in ¡presence ¡of ¡bugs ¡ • High-­‑level ¡language ¡models ¡break ¡down ¡ – Tuning ¡program ¡performance ¡ • Understand ¡op<miza<ons ¡done/not-­‑done ¡by ¡the ¡compiler ¡ • Understanding ¡sources ¡of ¡program ¡inefficiency ¡ – Implemen<ng ¡system ¡sokware ¡ • Compiler ¡has ¡machine ¡code ¡as ¡target ¡ • Opera<ng ¡systems ¡must ¡manage ¡process ¡state ¡ – Crea<ng ¡/ ¡figh<ng ¡malware ¡ • x86 ¡assembly ¡is ¡the ¡language ¡of ¡choice! ¡ 10 ¡

  11. The ¡compila8on ¡system… ¡revisited ¡ hello.c ¡ Type ¡in ¡program ¡using ¡an ¡editor ¡of ¡ your ¡choice ¡(file.c); ¡plain ¡text ¡ %gcc ¡ ¡-­‑o ¡ ¡hello ¡ ¡hello.c ¡ .c ¡+ ¡.h ¡= ¡.i ¡which ¡is ¡the ¡“ul<mate ¡source ¡ code”? ¡i.e. ¡# ¡includes ¡expanded ¡and ¡ #defines ¡replaced ¡ .i ¡ à ¡.s ¡ ¡which ¡is ¡assembler ¡source ¡code ¡ .s ¡ à ¡.o ¡which ¡is ¡an ¡object ¡file; ¡fragments ¡of ¡ machine ¡code ¡with ¡unresolved ¡symbols ¡i.e. ¡ some ¡addresses ¡not ¡yet ¡known ¡(vars/subrs). ¡ ¡ .o ¡+ ¡library ¡links ¡ à ¡a.out ¡(default ¡name); ¡ resolves ¡symbols, ¡generates ¡an ¡ executable. ¡ hello ¡ %hello ¡ 11 ¡

  12. Declara8ons ¡and ¡the ¡Preprocessor ¡ • #include ¡ – provides ¡ability ¡to ¡include ¡declara<ons ¡from ¡other ¡files ¡ • usually ¡have ¡the ¡file ¡name ¡extension ¡.h ¡ – generally ¡only ¡include ¡func<on ¡prototypes, ¡and ¡type ¡and ¡ variable ¡declara<ons ¡ – actual ¡code ¡is ¡kept ¡in ¡a ¡different ¡file, ¡usually ¡with ¡the ¡ extension ¡.c ¡ • files ¡with ¡code ¡are ¡compiled ¡individually ¡to ¡ object ¡ code ¡and ¡then ¡ linked ¡together ¡to ¡create ¡a ¡file ¡with ¡ executable ¡ code ¡ • Two ¡ways ¡to ¡use ¡ #include ¡ – #include ¡<stdio.h> ¡ for ¡standard ¡system ¡files ¡ – #include ¡"swap.h“ ¡ for ¡user-­‑wri?en ¡files ¡ • Very ¡rarely/never ¡ #include ¡ a ¡ .c ¡ file ¡(link ¡.c ¡files) ¡ 12 ¡

  13. Compila8on ¡stages ¡ Preprocessor ¡ • – used ¡to ¡make ¡sure ¡the ¡program ¡parts ¡see ¡declara<ons ¡they ¡need ¡(and ¡other ¡ purposes ¡too, ¡e.g., ¡macros) ¡ – direc<ves ¡begin ¡with ¡a ¡ # ¡ (pound ¡sign) ¡ – do ¡not ¡end ¡in ¡a ¡; ¡like ¡C ¡statements ¡do ¡ Transla<on ¡ • – makes ¡sure ¡individual ¡parts ¡are ¡consistent ¡within ¡themselves ¡ – creates ¡an ¡object ¡(.o) ¡file ¡ Linking ¡ • – joins ¡one ¡or ¡more ¡compiled ¡object ¡files ¡together ¡ • includes ¡matching ¡func<on ¡call ¡to ¡callee ¡across ¡separate ¡files ¡ • and ¡matching ¡global ¡variable ¡use ¡to ¡where ¡it’s ¡defined ¡ – makes ¡sure ¡caller/callee ¡consistent ¡with ¡each ¡other ¡ – creates ¡an ¡executable ¡file ¡(the ¡conven<on ¡in ¡Unix ¡is ¡no ¡filename ¡extension ¡is ¡ used ¡for ¡executable ¡files, ¡although ¡some<mes ¡.x ¡or ¡.exe ¡are ¡used) ¡ 13 ¡

  14. Compiling ¡a ¡C ¡program ¡ C ¡programs ¡must ¡be ¡compiled ¡to ¡be ¡executed ¡ • Use ¡the ¡ gcc ¡ program ¡to ¡build ¡your ¡programs ¡ • – invoca<on: ¡ gcc ¡ op<ons ¡source-­‑files ¡ – common ¡op<ons ¡ • -­‑ansi ¡ enforces ¡the ¡ansi ¡standards ¡ • -­‑g ¡ enable ¡debugging ¡ • -­‑Wall ¡ warn ¡about ¡common ¡things ¡that ¡may ¡be ¡problems ¡ • -­‑Werror ¡ treat ¡warnings ¡as ¡errors ¡ • -­‑o ¡filename ¡ place ¡output ¡in ¡filename ¡ • -­‑c ¡ only ¡compile ¡to ¡object ¡file, ¡don't ¡link ¡(.o ¡file ¡created) ¡ • -­‑S ¡ generate ¡assembly ¡code, ¡don’t ¡link ¡(.s ¡file ¡created) ¡ – a ¡very ¡simple ¡compila<on ¡command ¡ • gcc ¡file.c ¡ – a ¡simple ¡compila<on ¡command ¡ • gcc ¡-­‑g ¡-­‑Wall ¡–Werror ¡–ansi ¡-­‑o ¡prog1 ¡prog1.c ¡tools.c ¡ – executable ¡is ¡run ¡in ¡UNIX ¡by ¡just ¡typing ¡its ¡name ¡(some<mes ¡preceded ¡by ¡" ./ ", ¡ like ¡this: ¡ ./prog1 ) ¡ 14 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend