guide into low-level systems programming by istvan haller
DESCRIPTION
Guide into low-level systems programming by Istvan Haller. Why are we here?. What is a variable? How does “print” work? How can hackers confuse software?. Here is where the magic happens!. Understanding our system. Can't I just program Java/Python?. Pros Benefits productivity Cons - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/1.jpg)
Guide into low-level systems programming
by Istvan Haller
![Page 2: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/2.jpg)
Why are we here?
What is a variable?How does “print” work?How can hackers confuse software?
![Page 3: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/3.jpg)
Here is where the magic happens!
![Page 4: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/4.jpg)
Understanding our system
![Page 5: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/5.jpg)
Can't I just program Java/Python?● Pros
– Benefits productivity● Cons
– Transparency versus manual control– Limited to sandbox– Poor understanding of underlying principles
● Know when to use different languages
![Page 6: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/6.jpg)
Low-level programming in practice● Computer Security
● Operating System Design
● Embedded Systems
![Page 7: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/7.jpg)
Hackers lurk in the shadows● Attacks exploit unexpected software behavior● Malicious code running besides user code is
visible● Malware designer understands system-level
concepts to facilitate evasion● Rootkits go beneath the OS, taking full
control
![Page 8: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/8.jpg)
SMM based rootkits● System management mode on Intel CPUs● Intended for hardware management● Complete stealth from regular system● Activated by intercepting system events
● "SMM Rootkits: A New Breed of OS Independent Malware"
![Page 9: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/9.jpg)
Black-hat vs White-hat● Cannot defend what you don’t understand● Vulnerabilities are everywhere (even Java)● Pre-emptive hacking can discover
vulnerabilities● Wide range of penetration testing companies
![Page 10: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/10.jpg)
Systems don't grow on trees● Somebody has to design the OS and
compiler● Custom compiler design enabled by LLVM● Many-cores need new paradigms in OS
design● Will you be part of the leading edge?
![Page 11: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/11.jpg)
Minix● A number of current research topics● Live updates
– Apply software patches on the fly● Many-core operating system
– Distributed drivers and software stacks● Fault tolerance and security
– User-space drivers
![Page 12: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/12.jpg)
Developments from the Big Guys● Android● iOS● Google Chrome OS● Amazon Silk● Continuous development on Linux Kernel
– Check-pointing, Live patching
![Page 13: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/13.jpg)
Embedded systems are cool (again)
● What drives your microwave, washing machine?● Simple 8 / 16 bit processors still ubiquitous● Prevalence of battery powered devices
– Pacemakers, wireless sensors● The Arduino trend among hobbyists
– 32bit but < 640KB RAM– Fun projects– Can you code with such limitations?
![Page 14: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/14.jpg)
Arduino projects on the web● Laser harp
● Open-source GameBoy
● Autonomous robots
● Many more at your fingertips...
![Page 15: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/15.jpg)
Options for getting started● Arduino board and online documentation● Custom board design + course material
– AVR ATMega, MicroChip PIC, TI MSP430● Raspberry PI for embedded systems?
– Under development (I have some ideas )● Blinking LED Playing with first sensors
Line following robot
![Page 16: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/16.jpg)
Low-level details in regular code● Arithmetic quirks
– The wonders of binary representation● Network language barrier
– “Standards” for data organization● ???
– Understanding programming rules from the perspective of the hardware
![Page 17: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/17.jpg)
Arithmetic games● int data type: to
– Why not symmetrical?● What is the value of B in the following?
A = ;if (A >= 0)
B = A;else
B = -A;
312 312 1
312
![Page 18: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/18.jpg)
Representing signed values● Sign + Value
– Sign: 1 bit, 0 positive, 1 negative– Value: remaining 31 bits– Symmetric: to (also )
● What about subtraction:
● Special arithmetic for subtraction
312 1 312 1 01 1 1 ( 1)
000...01 100...01 100...10 0
![Page 19: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/19.jpg)
Representing signed values (cont.)● 2’s Complement
– Sign: 1 bit, 0 positive, 1 negative– Value: from all 32 bits– Asymmetric: to (no )– Alternative computation:
312 312 1 0
32
32
1 ( 1) 0
1 0 1 2 1
2k k
~ 1k k
![Page 20: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/20.jpg)
Networking in Linux● The htonl() function converts the unsigned
integer hostlong from host byte order to network byte order.
● The ntohl() function converts the unsigned integer netlong from network byte order to host byte order.
● From Linux man pages● But why do we talk abut byte order?
![Page 21: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/21.jpg)
Byte order in memory– Take an arbitrary 4-byte integer: 0x12345678– Now put it into memory
– Each manufacturer has different “standard”– Network equipment also expects given order
![Page 22: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/22.jpg)
GPUs and memory coalescing
![Page 23: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/23.jpg)
Short history about DRAM● DRAM Dynamic RAM ”Volatile”
– Requires periodic refresh to maintain storage– Refresh triggered by memory access
Accessing given memory location slow
![Page 24: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/24.jpg)
Better use of DRAM● Why limit to single data?● Almost free to access nearby locations● Burst mode: transfer chunk to consecutive
data– Start address typically aligned
![Page 25: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/25.jpg)
Scope of the course● Understanding the system bottom-up
![Page 26: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/26.jpg)
Intro to computer architectures● Learning the underlying hardware concepts
and design decisions
![Page 27: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/27.jpg)
Questions to be answered● What are the basic building blocks of a CPU?● How is data organized in memory?● What happens at a conditional statement?● How are function calls managed?
![Page 28: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/28.jpg)
Crash course in machine code● Programming the processor itself ● X86 as running example
![Page 29: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/29.jpg)
Correlations with source code● Illustrate source code concepts in practice● Examples of C code snippets and their effect
![Page 30: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/30.jpg)
Practice makes perfect● Combining the concepts to interact with X86
hardware components (drivers)● Learn about timers, interrupts, output ports● Develop under minimalistic modern system● Example project presented in class● Mini-project ideas
![Page 31: Guide into low-level systems programming by Istvan Haller](https://reader035.vdocuments.us/reader035/viewer/2022062400/5681692e550346895de0753b/html5/thumbnails/31.jpg)
Course plan● Programmer's view on Computer Architecture (1)
– “Computer Organization and Design: The Hardware/Software Interface”
● by David A. Patterson and John L. Hennessy● Introduction to X86 assembly language (2)● Advanced topics in X86 assembly (3)
– “The Art of Assembly Language Programming”● by Randall Hyde
● Programming system code (4)● Interacting with X86 hardware devices (5)
– http://wiki.osdev.org