Presentation is loading. Please wait.

Presentation is loading. Please wait.

嵌入式處理器架構與程式設計 王建民 中央研究院 資訊所 2008 年 7 月. 2 Contents Introduction Computer Architecture ARM Architecture Development Tools  GNU Development Tools ARM Instruction.

Similar presentations

Presentation on theme: "嵌入式處理器架構與程式設計 王建民 中央研究院 資訊所 2008 年 7 月. 2 Contents Introduction Computer Architecture ARM Architecture Development Tools  GNU Development Tools ARM Instruction."— Presentation transcript:

1 嵌入式處理器架構與程式設計 王建民 中央研究院 資訊所 2008 年 7 月

2 2 Contents Introduction Computer Architecture ARM Architecture Development Tools  GNU Development Tools ARM Instruction Set ARM Assembly Language ARM Assembly Programming  GNU ARM ToolChain Interrupts and Monitor

3 Lecture 1 Introduction

4 4 Outline Basic Concepts Course Info Embedded Systems Programming Systems

5 5 Computer Systems Hardware Firmware Software Application software System software  Programming systems  Utilities  Operating systems

6 6 Computer Software Application software is designed to solve a specific problem. System software is intended to support the operation and use of the computer itself. Provide a general programming environment. Provide functions used by application software and users. Provide mechanisms to share the hardware in an orderly fashion.

7 7 Foundations of Computer Systems Users Application Software Programming System Hardware Operating System

8 8 Evolution of Programming 1 Machine Language Binary format 11100101100111110001000000010000 11100101100111110000000000001000 11100000100000010101000000000000 11100101100011110101000000001000 Hexadecimal format E59F1010 E59F0008 E0815000 E58F5008

9 9 Evolution of Programming 2 Assembly Language Mnemonic codes E59F1010LDRR1, num1 E59F0008LDRR0, num2 E0815000ADDR5, R1, R0 E58F5008STRR5, sum High-Level Language C language sum = num1 + num2;

10 10 How instructions are executed?... E59F1010 E59F0008 E0815000 E59F5008...

11 11 How a source program is compiled? int main() {... sum = num1 + num2;... }... E59F1010 E59F0008 E0815000 E59F5008...

12 12 How to develop embedded software? #define GREETING “Hello, World!\n” int main() { printf(GREETING); }

13 13 What are you going to learn? How instructions are executed? Computer Architecture How a source program is compiled? Development tools How to develop embedded software? Embedded processors Assembly language and programming Cross development Software interrupts

14 14 Outline Basic Concepts Course Info Embedded Systems Programming Systems

15 15 Prerequisites and Related Courses Prerequisites 計算機概論 C/C++ 程式設計 資料結構 Related Courses 計算機結構 系統程式 作業系統 嵌入式系統

16 16 Course Info 1 Related Links  Slides and documents The ARM processor GNU software Open source software for handheld systems

17 17 Course Info 2 PC Software Linux Cygwin GNU Software GNU ARM ToolChain

18 18 Course Info 3 Reference Books Computer Organization and Design: The Hardware/Software Interface, Patterson and Hennessy System software: an introduction to systems programming, 3 rd edition, Leland L. Beck. Compilers – Principles, Techniques, and Tools, A. V. Aho, R. Sethi, and J. D. Ullman. Operating System Concepts, Abraham Silberschatz.

19 19 Outline Basic Concepts Course Info Embedded Systems Programming Systems

20 20 What are embedded systems? Anything that uses a microprocessor but isn't a general-purpose computer  PDAs  Set-top boxes  Televisions  Video games  Refrigerators  Cars  Planes  Elevators  Remote controls  Alarm systems More than just a computer; it's a complete system

21 21 What is an embedded system? Computer purchased as part of some other piece of equipment Typically dedicated software Often replaces previously electromechanical components Often no “real” keyboard Often limited display or no general purpose display device But, every system is unique. There are always exceptions.

22 22 Why are embedded systems important? Engineering reasons Why does a satellite need a Windows prompt ? Does the McDonald’s POS (point-of-sale) terminal need MacOS? Any device that needs to be controlled can be controlled by a microprocessor

23 23 Why are embedded systems important? Market reasons The general-purpose computing market is in billions of US $ The embedded systems market is also in billions of $ ~80 Million PCs vs. ~3 Billion Embedded CPUs annually  Embedded market growing; PC market mostly saturated In year 2000, about $2,700 of every car went to electronics

24 24 Why are embedded systems important? Pedagogical reasons General-purpose system designers specialize HW vs. SW Embedded system designers are often Jackofmanytrades Need to know hardware, software, and some combination of networking, control theory and signal processing business models

25 25 Embedded Systems: An Introduction What makes embedded systems different? Real-time operation Many sets of constraints on designs  Size  Cost  Time  Reliability  Energy  Safety  Security

26 26 An Engineer’s View: A Computer Measured by: performance, cost Compilers & OS matters

27 27 An Embedded Computer Measured by: cost, I/O connections, memory size, performance

28 28 An Embedded Control System Measured by: Cost, time to market, performance, functionality, dependability

29 29 Some Embedded System Examples Pocket remote control RF transmitter 100 KIPS, water/crushproof, fits in pocket, 5 year battery life Software handcrafted for small size (less than 1 KB) Industrial equipment controller (e.g., elevator; jet engine) 1~10 MIPS for 1 to 10 CPUs, 1~8 MB memory Safety critical software; real time control loops Military signal processing (e.g., Radar/Sonar) 1 GFLOPS, 1 GB/sec I/O, 32 MB memory Software handcrafted for extremely high performance

30 30 Categories of Embedded Systems 1 General Computing Applications similar to desktop computing, but in an embedded package Video games, set top boxes, wearable computers, automatic tellers Control Systems Closed loop feedback control of real time system Vehicle engines, chemical processes, nuclear power, flight control

31 31 Categories of Embedded Systems 2 Signal Processing Computations involving large data streams Radar, Sonar, video compression Communication & Networking Switching and information transmission Telephone system, Internet

32 32 Functions of Embedded Systems 1 Control Laws PID control Fuzzy logic,... Sequencing Logic Finite state machines Switching modes between control laws Signal Processing Multimedia data compression Digital filtering

33 33 Functions of Embedded Systems 2 Application Specific Interfacing Buttons, bells, lights,... High speed I/O Fault Response Detection & reconfiguration Diagnosis …

34 34 Distinctive Attributes 1 Reactive: computations occur in response to external events Periodic events (e.g., rotating machinery and control loops) Aperiodic events (e.g., button closures)

35 35 Distinctive Attributes 2 Real-Time: timing correctness is part of system correctness Hard real-time  Absolute deadline, beyond which answer is useless  May include minimum time as well as maximum time Soft real-time  Missing a deadline is not catastrophic  Utility of answer degrades with time difference from deadline Example:  a train is entering an urban area...  the railway gate in the city allows automotive traffic to go over the tracks  when should the railway gate close? In general, Real Time != “Real Fast”

36 36 Embedded System Constraints 1 Small Size, Low Weight Handheld electronics Transportation applications weight costs money Low Power Battery power for 8+ hours (laptops often last only 2 hours) Limited cooling may limit power even if AC power available

37 37 Embedded System Constraints 2 Harsh Environment Heat, vibration, shock Power fluctuations, RF interference, lightning Water, corrosion, physical abuse Safety Critical Operation Must function correctly Must not function incorrectly Extreme Cost Sensitivity $.05 adds up over 1,000,000 units

38 38 Embedded System Design View A complex set of tradeoffs: Optimize for more than just speed Consider more than just the computer Take into account more than just initial product design Multi-Discipline Electronic Hardware Software Mechanical Hardware Control Algorithms Humans Society/Institutions MultiObjective Dependability Affordability Safety Security Scalability Timeliness MultiPhase Requirements Design Manufacturing Deployment Logistics Retirement xx

39 39 Mission Critical Applications 1 Loss of Arianne inaugural flight in June, 1996 Lost a $400 million scientific payload (the rocket was extra) Efforts to reduce system costs led to the failure Reuse of Inertial Reference System software from Ariane 4 64bit float converted to 16bit int assumed not to overflow Improperly handled exception caused by variable overflow during New flight profile (that wasn't simulated because of cost/schedule)

40 40 Mission Critical Applications 2 Exception caused dual hardware shutdown (software doesn't fail!) What really happened? The narrow view: it was a software bug; fix it The broad view: the loss was caused by a lack of system robustness in an exceptional (unanticipated) situation Many embedded systems must be robust

41 41 Software Drives Designs Hardware is mostly a recurring cost Cost proportional to number of units manufactured Software is a “one time” nonrecurring engineering design cost (NRE) Paid for ''only once'' But bug fixes may be expensive, or impossible Cost is related to complexity & number of functions Market pressures lead to feature creep Software Is NOT free!!!!!

42 42 Review What is an embedded system? More than just a computer it's a complete system What makes embedded systems different? Reactive and/or real-time Many sets of constraints on designs What embedded system designers need to know ? Multi-objective: cost, dependability, performance, etc. Multidiscipline: hardware, software, electromechanical, etc. Life-cycle: specification, design, prototyping, deployment, support, retirement

43 43 Outline Basic Concepts Course Info Embedded Systems Programming Systems

44 44 How a source program is executed? #define GREETING “Hello, World!\n” int main() { printf(GREETING); }

45 45 Source Model vs. Real Machine Representation in text Arbitrary variable names Rules for name scope Everything in memory Fancy operations Model uniform across computers Binary representation All numerical addresses No address scope Hierarchical memory Limited operations Significant difference between processors

46 46 Approaches Machine IndependentMachine Dependent Human Readable High-Level Languages (C, C++, Java, Pascal) Assembly Languages Human Unreadable Pseudo Code (Bytecode, P-code) Machine Languages (x86, MIPS, ARM)

47 47 From Source to Executable Source Code Preprocessor Preprocessed Code Compiler Assembly Code Assembler Object Code Linker Executable Code Loader Debugger Libraries

48 48 An Example Program C Program /* hello.c, a simple example program */ #define GREETING “Hello, World!\n” int main() { printf(GREETING); }

49 49 C Preprocessor Preprocess the C source Strip out comments Perform textual substitution Preprocessor output # 1 “hello.c” int main() { printf(“Hello, World!\n”); }

50 50 C Compiler Translate preprocessed C into assembly.file "hello.c".section.rodata.LC0:.string "Hello, World!\n".text.align 2.globl main.type main,@function main: pushl %ebp movl %esp, %ebp subl $8, %esp andl $-16, %esp movl $0, %eax subl %eax, %esp subl $12, %esp pushl $.LC0 call printf addl $16, %esp leave ret.Lfe1:.size main,.Lfe1-main.ident "GCC: (GNU) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)"

51 51 Assembly Language Representation in text Arbitrary variable names Rules for name scope Hierarchical memory Operations specific to target processor Model dependent on target system

52 52 Assembler Convert assembly into object file 1.file "hello.c" 2.section.rodata 3.LC0: 4 0000 48656C6C.string "Hello, World!\n" 4 6F2C2057 4 6F726C64 4 210A00 5.text 6.align 2 7.globl main 8.type main,@function 9 main: 10 0000 55 pushl %ebp 11 0001 89E5 movl %esp, %ebp 12 0003 83EC08 subl $8, %esp 13 0006 83E4F0 andl $-16, %esp 14 0009 B800000000 movl $0, %eax 15 000e 29C4 subl %eax, %esp 16 0010 83EC0C subl $12, %esp 17 0013 6800000000 pushl $.LC0 18 0018 E8FCFFFFFF call printf 19 001d 83C410 addl $16, %esp 20 0020 C9 leave 21 0021 C3 ret

53 53 Linker Link the object files and libraries to form an executable Fix unresolved address ( call printf ) Put in startup code ( crt0.o ) that calls main function int main(argc,argv,envp) Create executable file

54 54 Libraries Startup Routine ( crt0.o ) Required as it is the first piece of user code executed Setup arguments and environment for your main function C Library ( glibc ) Required as they provide functions printf, open, read, close, etc. User Libraries

55 55 Loader Load executable file into memory for execution Allocate memory space from operating system Load executable file into allocated memory Perform the relocation of loaded program Bootstrap Loader An small program which enables the loading of larger, more complex programs, such as the boot loader for an operating system.

56 56 Debugger Allow you to see what is going on “inside” another program while it executes. Start your program, specifying anything that might affect its behavior. Make it stop on specified conditions. Examine what has happened, when your program has stopped. Change things in your program, so you can correct the effects of one bug and go on.

57 57 Debugging Information The debugger need information to map machine code back to original program Debugging information maps Code addresses to lines in source code Data addresses to variables Registers to variables Data in memory into meaningful types

58 58 Development Tools Preprocessor Compiler Assembler Linker Libraries Loader Debugger..., etc.

59 59 Where is the bug reported by compiler? #define GREETING “Hello, World!\n”) int main() { printf(GREETING); } # 1 “hello.c” int main() { printf(“Hello, World!\n”)); } Why are these important?

60 60 How to develop embedded software? #define GREETING “Hello, World!\n” int main() { printf(GREETING); }

61 61 Cross Development It is usually preferred to develop software on faster and better host computers Target system and development host may be completely different Development host: PC Target system: PDA May require a different breed of tools Native development tools Cross development tools

62 62 Core Cross Development Tools Cross Compiler/Assembler/Linker/Loader Assembly, object and executable file formats might be very different from native system Cross Development Libraries Need special low level components to be rewritten for each different target system Cross Debugger It needs to run on both target and host The two halves need to communicate via RPC

63 63 Cross Development Tools Preprocessor Compiler Assembler Linker Libraries Loader Debugger Archiver Simulator Emulator

64 64 Archiver Archive A single file holding a collection of other files in a structure that makes it possible to retrieve the original individual files. Most often used as libraries holding commonly needed subroutines. Archiver A program that allows you to create, modify, and extract from archives.

65 65 Simulator Software tool allows designers to analyze the system behavior Examine simulated hardware events which cause software to take actions (e.g., interrupts) Devices can be modeled (e.g., DMA) Same software as final system Does not run at full (target) speed Good for finding software bugs

66 66 Emulator Hardware and software tools allow designers to analyze the system Normally a critical component is substituted by a “plug” attached to emulator Execute at full speed Good for finding hardware bugs

Download ppt "嵌入式處理器架構與程式設計 王建民 中央研究院 資訊所 2008 年 7 月. 2 Contents Introduction Computer Architecture ARM Architecture Development Tools  GNU Development Tools ARM Instruction."

Similar presentations

Ads by Google