1 EECS 373 Design of Microprocessor-Based Systems Branden Ghena University of Michigan Lecture 3: Assembly, Tools, and ABI September 9, 2014 Slides developed.

Slides:



Advertisements
Similar presentations
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Advertisements

Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Computer Science Education
SE 292 (3:0) High Performance Computing L2: Basic Computer Organization R. Govindarajan
Embedded Software 1. General 8051 features (excluding I/O) CPU 8 bit microcontroller The basic registers include (more discussed later) The 8-bit A (accumulator)
ABC Technology Project
Review Pseudo Code Basic elements of Pseudo code
Based on Mike Feeley’s original slides; Modified by George Tsiknis Unit 11 Local Variables, Parameters and the Stack Relevant Information CPSC 213 Companion.
Squares and Square Root WALK. Solve each problem REVIEW:
1 Advanced C Programming from Expert C Programming: Deep C Secrets by Peter van der Linden CIS*2450 Advanced Programming Concepts.
© 2012 National Heart Foundation of Australia. Slide 2.
25 seconds left…...
Week 1.
1 Patt and Patel Ch. 7 LC-3 Assembly Language. 2 LC-3 is a load/store RISC architecture Has 8 general registersHas 8 general registers Has a flat 16-bit.
We will resume in: 25 Minutes.
Copyright 2013 – Noah Mendelsohn Compiling C Programs Noah Mendelsohn Tufts University Web:
Introduction to Recursion and Recursive Algorithms
Datorteknik OperatingSystem bild 1 the Operating System (OS)
Data Structures Using C++ 2E
ARM Assembly Programming Computer Organization and Assembly Languages Yung-Yu Chuang with slides by Peng-Sheng Chen.
Compiler Construction Sohail Aslam Lecture Code Generation  The code generation problem is the task of mapping intermediate code to machine code.
ARM versions ARM architecture has been extended over several versions.
Tutorial Essentially all the Blackfin instruction you need for all of ENCM511. The instructions are easy. Its knowing when to use them that is the difficult.
Cosc 2150: Computer Organization
Suranaree University Of Technology มทส  2002 Anant Oonsivilai 2002/2/27 Microcomputers and Microprocessors Chapter Assembly Language Programming.
Chapter 3 โพรเซสเซอร์และการทำงาน The Processing Unit
CPSC 330 Fall 1999 HW #1 Assigned September 1, 1999 Due September 8, 1999 Submit in class Use a word processor (although you may hand-draw answers to Problems.
Passing by-value vs. by-reference in ARM by value C code equivalent assembly code int a;.section since a is not assigned an a:.skip initial.
THUMB Instructions: Branching and Data Processing
ITEC 352 Lecture 13 ISA(4).
Code Generation.
Based on Mike Feeley’s and Tamara Munzner’s original slides; Modified by George Tsiknis Parameters and Local Variables Relevant Information CPSC 213 Companion.
1 ARM Movement Instructions u MOV Rd, ; updates N, Z, C Rd = u MVN Rd, ; Rd = 0xF..F EOR.
Optimizing ARM Assembly Computer Organization and Assembly Languages Yung-Yu Chuang with slides by Peng-Sheng Chen.
The 8051 Microcontroller and Embedded Systems
Procedures Procedures are very important for writing reusable and maintainable code in assembly and high-level languages. How are they implemented? Application.
UEE072HM Linking HLL and ALP An example on ARM. Embedded and Real-Time Systems We will mainly look at embedded systems –Systems which have the computer.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 3: ISA, Assembly, and Toolchains September 13, 2011.
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
Slides developed in part by Mark Brehob
Cortex-M3 Programming. Chapter 10 in the reference book.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 2: Architecture, Assembly, and ABI September 8, 2011 Slides.
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
1 EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Lecture 2: Architecture, Assembly, and ABI Sept. 5, 2013 Slides developed.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Instruction Set Architecture Assembly Language Programming Software.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 2: Architecture, Assembly, and ABI September 9, 2010.
Topic 2d High-Level languages and Systems Software
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 4: Memory and Memory-Mapped I/O September 16, 2010.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 2: Architecture, Assembly, and ABI September 4, 2014 Slides.
1 EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Lecture 3: Toolchain, ABI, Memory Mapped I/O January 14 th, 2016 Slides.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 4: Review, Simulation, ABI, and Memory-Mapped I/O September.
List three things that distinguish embedded
Procedures Procedures are very important for writing reusable and maintainable code in assembly and high-level languages. How are they implemented? Application.
Writing Functions in Assembly
ECE 3430 – Intro to Microcomputer Systems
Writing Functions in Assembly
Slides developed in part by Prof. Dutta
ARM Assembly Programming
Slides developed in part by Mark Brehob
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
ECE 3430 – Intro to Microcomputer Systems
Optimizing ARM Assembly
Slides developed in part by Mark Brehob
Program Assembly.
Presentation transcript:

1 EECS 373 Design of Microprocessor-Based Systems Branden Ghena University of Michigan Lecture 3: Assembly, Tools, and ABI September 9, 2014 Slides developed in part by Mark Brehob & Prabal Dutta

2 Announcements I’m not Prabal –You probably noticed Homework 1 is due No office hours this week Projects –Continue thinking about them

Today… Finish ARM assembly example from last time Software Development Tool Flow Application Binary Interface (ABI) 3

4... start: movs r0, #1 movs r1, #1 movs r2, #1 sub r0, r1 bne done movs r2, #2 done: b done... Exercise: What is the value of r2 at done?

Conditional execution: Append to many instructions for conditional execution

Application Program Status Register (APSR)

7... start: movs r0, #1// r0  1, Z=0 movs r1, #1// r1  1, Z=0 movs r2, #1// r2  1, Z=0 sub r0, r1// r0  r0-r1 // but Z flag untouched // since sub vs subs bne done// NE true when Z==0 // So, take the branch movs r2, #2// not executed done: b done// r2 is still 1... Solution: what is the value of r2 at done?

8.equSTACK_TOP, 0x /* Equates symbol to value */.text/* Tells AS to assemble region */.syntaxunified/* Means language is ARM UAL */.thumb/* Means ARM ISA is Thumb */.global_start/*.global exposes symbol */ /* _start label is the beginning */ /*...of the program region */.typestart, %function/* Specifies start is a function */ /* start label is reset handler */ _start:.wordSTACK_TOP, start/* Inserts word 0x */ /* Inserts word (start) */ start: movs r0, #10/* We’ve seen the rest... */ movs r1, #0 loop: adds r1, r0 subs r0, #1 bne loop deadloop: b deadloop.end Real assembly example

9.equSTACK_TOP, 0x /* Sets symbol to value (#define)*/.text/* Tells AS to assemble region */.syntaxunified/* Means language is ARM UAL */.thumb/* Means ARM ISA is Thumb */.global_start/*.global exposes symbol */ /* _start label is the beginning */ /*...of the program region */.typestart, %function/* Specifies start is a function */ /* start label is reset handler */ _start:.wordSTACK_TOP, start/* Inserts word 0x */ /* Inserts word (start) */ start: movs r0, #10/* We’ve seen the rest... */ movs r1, #0 loop: adds r1, r0 subs r0, #1 bne loop deadloop: b deadloop.end What’s it all mean?

What happens after a power-on-reset (POR)? ARM Cortex-M3 (many others are similar) Reset procedure –SP  mem(0x ) –PC  mem(0x ) _start:.word __STACKTOP/* Top of Stack */.word Reset_Handler/* Reset Handler */.word NMI_Handler/* NMI Handler */.word HardFault_Handler/* Hard Fault Handler */.word MemManage_Handler/* MPU Fault Handler */.word BusFault_handler/* Bus Fault Handler */... 10

Today… Walk though of the ARM ISA Software Development Tool Flow Application Binary Interface (ABI) 11

12 How does an assembly language program get turned into a executable program image? Assembly files (.s) Object files (.o) as (assembler) ld (linker) Memory layout Memory layout Linker script (.ld) Executable image file Binary program file (.bin) Disassembled code (.lst) objcopy objdump

13 What are the real GNU executable names for the ARM? Just add the prefix “arm-none-eabi-” prefix Assembler (as) –arm-none-eabi-as Linker (ld) –arm-none-eabi-ld Object copy (objcopy) –arm-none-eabi-objcopy Object dump (objdump) –arm-none-eabi-objdump C Compiler (gcc) –arm-none-eabi-gcc C++ Compiler (g++) –arm-none-eabi-g++

Real-world example To the terminal! (code at 14

15 $ arm-none-eabi-as -mcpu=cortex-m3 -mthumb example1.s -o example1.o How are assembly files assembled? $ arm-none-eabi-as –Useful options -mcpu -mthumb -o

16 all: arm-none-eabi-as -mcpu=cortex-m3 -mthumb example1.s -o example1.o arm-none-eabi-ld -Ttext 0x0 -o example1.out example1.o arm-none-eabi-objcopy -Obinary example1.out example1.bin arm-none-eabi-objdump -S example1.out > example1.lst A simple (hardcoded) Makefile example

17 What information does the disassembled file provide?.equSTACK_TOP, 0x text.syntaxunified.thumb.global_start.typestart, %function _start:.wordSTACK_TOP, start start: movs r0, #10 movs r1, #0 loop: adds r1, r0 subs r0, #1 bne loop deadloop: b deadloop.end example1.out: file format elf32-littlearm Disassembly of section.text: : 0: word0x : word0x : 8:200a movsr0, #10 a:2100 movsr1, # c : c:1809 addsr1, r1, r0 e:3801 subsr0, #1 10:d1fc bne.nc : 12:e7fe b.n12 all: arm-none-eabi-as -mcpu=cortex-m3 -mthumb example1.s -o example1.o arm-none-eabi-ld -Ttext 0x0 -o example1.out example1.o arm-none-eabi-objcopy -Obinary example1.out example1.bin arm-none-eabi-objdump -S example1.out > example1.lst

Linker script OUTPUT_FORMAT("elf32-littlearm") OUTPUT_ARCH(arm) ENTRY(main) MEMORY { /* SmartFusion internal eSRAM */ ram (rwx) : ORIGIN = 0x , LENGTH = 64k } SECTIONS {.text : {. = ALIGN(4); *(.text*). = ALIGN(4); _etext =.; } >ram } end =.; Specifies little-endian arm in ELF format. Specifies ARM CPU Should start executing at label named “main” We have 64k of memory starting at 0x You can read, write and execute out of it. We’ve named it “ram” “.” is a reference to the current memory location First align to a word (4 byte) boundary Place all sections that include.text at the start (* here is a wildcard) Define a label named _etext to be the current address. Put it all in the memory location defined by the ram memory location. 18

19 How does a mixed C/Assembly program get turned into a executable program image? Assembly files (.s) Object files (.o) as (assembler) gcc (compile + link) Memory layout Memory layout Linker script (.ld) Executable image file Binary program file (.bin) Disassembled code (.lst) objcopy objdump ld (linker) Library object files (.o) C files (.c)

Real-world example #2 To the terminal! Again! (code at 20

Today… Finish ARM assembly example from last time Walk though of the ARM ISA Software Development Tool Flow Application Binary Interface (ABI) 21

22

ABI Basic Rules 1.A subroutine must preserve the contents of the registers r4-11 and SP –Let’s be careful with r9 though. 2. Arguments are passed though r0 to r3 –If we need more, we put a pointer into memory in one of the registers. We’ll worry about that later. 3.Return value is placed in r0 –r0 and r1 if 64-bits. 4.Allocate space on stack as needed. Use it as needed. Put it back when done… –Keep word aligned. 23

Let’s write a simple ABI routine int bob(int a, int b) –returns a 2 + b 2 Instructions you might need –add adds two values –mulmultiplies two values –bxbranch to register Other useful factoids Stack grows down. –And pointed to by “sp” Address we need to go back to in “lr” 24

When is this relevant? The ABI is a contract with the compiler –All assembled C code will follow this standard You need to follow it if you want C and Assembly to work together correctly What if you are writing everything in Assembly by hand? –Maybe less important. Unless you’re ever going to extend the code 25

26 Questions? Comments? Discussion?