1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 4: Review, Simulation, ABI, and Memory-Mapped I/O September.

Slides:



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

1 ARM Movement Instructions u MOV Rd, ; updates N, Z, C Rd = u MVN Rd, ; Rd = 0xF..F EOR.
Run-time Environment for a Program different logical parts of a program during execution stack – automatically allocated variables (local variables, subdivided.
The 8051 Microcontroller and Embedded Systems
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 3: ISA, Assembly, and Toolchains September 13, 2011.
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
PC hardware and x86 3/3/08 Frans Kaashoek MIT
Choice for the rest of the semester New Plan –assembler and machine language –Operating systems Process scheduling Memory management File system Optimization.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
Slides developed in part by Mark Brehob
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 4: Memory-Mapped I/O, Bus Architectures January 20, 2015.
ARM C Language & Assembler. Using C instead of Java (or Python, or your other favorite language)? C is the de facto standard for embedded systems because.
Overview von Neumann Model Components of a Computer Some Computer Organization Models The Computer Bus An Example Organization: The LC-3.
Software Development and Software Loading in Embedded Systems.
Cortex-M3 Programming. Chapter 10 in the reference book.
System Calls 1.
6.828: PC hardware and x86 Frans Kaashoek
Lecture 4: Advanced Instructions, Control, and Branching cont. EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
4-1 Chapter 4 - The Instruction Set Architecture Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring.
1 EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Lecture 2: Architecture, Assembly, and ABI Sept. 5, 2013 Slides developed.
4-1 Chapter 4 - The Instruction Set Architecture Department of Information Technology, Radford University ITEC 352 Computer Organization Principles of.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Instruction Set Architecture Assembly Language Programming Software.
4-1 Chapter 4 - The Instruction Set Architecture Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 2: Architecture, Assembly, and ABI September 9, 2010.
4-1 Chapter 4 - The Instruction Set Architecture Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
CS 111 – Sept. 15 Chapter 2 – Manipulating data by performing instructions “What is going on in the CPU?” Commitment: –Please read through section 2.3.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
1 EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Lecture 4: Bit of ssembly, Memory-mapped I/O, APB January 21, 2014.
F28PL1 Programming Languages Lecture 4: Assembly Language 3.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 4: Memory and Memory-Mapped I/O September 16, 2010.
Our programmer needs to do this !
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 2: Architecture, Assembly, and ABI September 4, 2014 Slides.
CS 478: Microcontroller Systems University of Wisconsin-Eau Claire Dan Ernst Bus Protocols and Interfacing Bus basics I/O transactions MPC555 bus Reference:
Bus Protocols and Interfacing (adopted Steven and Marios’s slides) Bus basics I/O transactions MPC823 bus Reference: Chapter 13 of “White Book”
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.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
ARM-7 Assembly: Example Programs 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
The Stack. ARMSim memory space: 0x Unused 0x x11400 Stack 0x x09400 Heap 0x?????-0x01400 Data 0x x????? Text 0x x01000.
Practical Session 8. Position Independent Code- self sufficiency of combining program Position Independent Code (PIC) program has everything it needs.
F28HS Hardware-Software Interface Lecture 11: ARM Assembly Language 5.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
List three things that distinguish embedded
Lecture 3 Translation.
Writing Functions in Assembly
Format of Assembly language
Slides developed in part by Mark Brehob & Prabal Dutta
ECE 3430 – Intro to Microcomputer Systems
The Stack.
The Cortex-M3/m4 Embedded Systems: Cortex-M3/M4 Instruction Sets
The Stack.
The 8051 Microcontroller and Embedded Systems
Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 4 – The Instruction Set Architecture.
William Stallings Computer Organization and Architecture 8th Edition
Writing Functions in Assembly
Arithmetic using a stack
Slides developed in part by Prof. Dutta
EECS 373 Design of Microprocessor-Based Systems Mark Brehob
ARM Assembly Programming
Chapter 7 LC-2 Assembly Language.
Passing by-value vs. by-reference in ARM
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
ECE 3430 – Intro to Microcomputer Systems
COMS 361 Computer Organization
8051 ASSEMBLY LANGUAGE PROGRAMMING
Some Assembly (Part 2) set.html.
Introduction to Assembly Chapter 2
An Introduction to the ARM CORTEX M0+ Instructions
Presentation transcript:

1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 4: Review, Simulation, ABI, and Memory-Mapped I/O September 13, 2012

2 Announcements / Clarifications push {reg_list}: reg_list is stored on the stack in –Numerical order –With lowest numbered register at lowest memory address pop {reg_list} : reg_list is stored on the stack in –Numerical order –With lowest numbered register at lowest memory address –If PC is in reg_list, causes branch to addr popped off stack Examples –push {r0, r4-r7} –push {r2, lr} –pop {r0, r1} ARM stack is full-descending so a push causes the SP to hold a lower address.

3 Outline Minute quiz Announcements Review Assembly, C, and the ABI Memory Memory-mapped I/O

What happens after a power-on-reset (POR)? On the ARM Cortex-M3 SP and PC are loaded from the code (.text) segment Initial stack pointer –LOC: 0x –POR: SP  mem(0x ) Interrupt vector table –Initial base: 0x –Vector table is relocatable –Entries: 32-bit values –Each entry is an address –Entry #1: reset vector LOC: 0x POR: PC  mem(0x ) Execution begins 4.equSTACK_TOP, 0x text.syntaxunified.thumb.global_start.typestart, %function _start:.wordSTACK_TOP, start start: movs r0, #10...

ARMv7 ARM Instruction encoding Instructions are encoded in machine language opcodes Sometimes –Distinguish opcodes from each other –Necessary to decode opcodes and itemize arch state impacts How? Instructions movs r0, #10 movs r1, #0 Register Value Memory Value 001|00|000| (LSB) (MSB) (msb) (lsb) 0a |00|001|

Instruction encoding/decoding Thumb instructions are a sequence of half-word-aligned half-words Each Thumb instruction is either –a 16-bit half-word in that stream –A 32-bit instruction consisting of two half-words in that stream If bits [15:11] of the half-word being decoded take on any of the following values –0b11101 –0b11110 –0b11111 –then half-word is the first half-word of a 32-bit instruction –otherwise the half-word is a 16-bit instruction See ARM ARM A5.1, A5.5, A5-13

Instruction encoding/decoding (class-level)

Instruction encoding/decoding (instruction-level)

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 (r), write (w) and execute (x) out of it. We’ve named it “ram” “.” is a reference to the current memory location First align to a word (4 byte) boundry 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. 9

10 Some things to think about (TTTA) What instruction set? Thumb! What is conditional execution (ARM ARM, A4.1.2)? What are the side effects of instruction execution?

11 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

12 Outline Minute quiz Announcements Review Assembly, C, and the ABI Memory Memory-mapped I/O

13 int main() { int i; int n; unsigned int input = 40, output = 0; for (i = 0; i < 10; ++i) { n = factorial(i); printf("factorial(%d) = %d\n", i, n); } __asm("nop\n"); __asm("mov r0, %0\n" "mov r3, #5\n" "udiv r0, r0, r3\n" "mov %1, r0\n" :"=r" (output) : "r" (input) : "cc", "r3" ); __asm("nop\n"); printf("%d\n", output); } Cheap trick: use asm() or __asm() macros to sprinkle simple assembly in standard C code! $ arm-none-eabi-gcc \ -mcpu=cortex-m3 \ -mthumb main.c \ -T generic-hosted.ld \ -o factorial $ qemu-arm -cpu cortex-m3 \./factorial factorial(0) = 1 factorial(1) = 1 factorial(2) = 2 factorial(3) = 6 factorial(4) = 24 factorial(5) = 120 factorial(6) = 720 factorial(7) = 5040 factorial(8) = factorial(9) = Answer: 40/5 

14 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)

15 Passing parameters via the stack Benefits? Drawbacks?

16 Passing parameters via the registers/stack

ABI Basic Rules 1.A subroutine must preserve the contents of the registers r4-r11 and SP 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. 17

Other useful facts Stack grows down. –And pointed to by “SP” Address we need to go back to in “LR” And useful things for the example Assembly instructions –add adds two values –mulmultiplies two values –bxbranch to register 18

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 19

Same thing, but for no good reason using the stack int bob(int a, int b) –returns a 2 + b 2 20

Some disassembly 0x : push {r7} 0x : sub sp, #20 0x : add r7, sp, #0 0x : str r0, [r7, #4] 0x : str r1, [r7, #0] x=a*a; 0x a : ldr r3, [r7, #4] 0x c : ldr r2, [r7, #4] 0x e : mul.w r3, r2, r3 0x200004a2 : str r3, [r7, #8] y=b*b; 0x200004a4 : ldr r3, [r7, #0] 0x200004a6 : ldr r2, [r7, #0] 0x200004a8 : mul.w r3, r2, r3 0x x=x+y; 0x200004ae : ldr r2, [r7, #8] 0x200004b0 : ldr r3, [r7, #12] 0x200004b2 : add r3, r2 0x200004b4 : str r3, [r7, #8] 0x200004ac : str r3, [r7, #12] return(x); 0x200004b6 : ldr r3, [r7, #8] } 0x200004b8 : mov r0, r3 0x200004ba : add.w r7, r7, #20 0x200004be : mov sp, r7 0x200004c0 : pop {r7} 0x200004c2 : bx lr 21 int bob(int a, int b) { int x, y; x=a*a; y=b*b; x=x+y; return(x); }

22 Outline Minute quiz Announcements Review Assembly, C, and the ABI Memory Memory-mapped I/O

System Memory Map

24 Outline Minute quiz Announcements Review Assembly, C, and the ABI Memory Memory-mapped I/O

The idea is really simple –Instead of real memory at a given memory address, have an I/O device respond. Example: –Let’s say we want to have an LED turn on if we write a “1” to memory location 5. –Further, let’s have a button we can read (pushed or unpushed) by reading address 4. If pushed, it returns a 1. If not pushed, it returns a 0. 25

Now… How do you get that to happen? –We could just say “magic” but that’s not very helpful. –Let’s start by detailing a simple bus and hooking hardware up to it. We’ll work on a real bus next time! 26

Basic example Discuss a basic bus protocol –Asynchronous (no clock) –Initiator and Target –REQ#, ACK#, Data[7:0], ADS[7:0], CMD CMD=0 is read, CMD=1 is write. REQ# low means initiator is requesting something. ACK# low means target has done its job.

A read transaction Say initiator wants to read location 0x24 –Initiator sets ADS=0x24, CMD=0. –Initiator then sets REQ# to low. (why do we need a delay? How much of a delay?) –Target sees read request. –Target drives data onto data bus. –Target then sets ACK# to low. –Initiator grabs the data from the data bus. –Initiator sets REQ# to high, stops driving ADS and CMD –Target stops driving data, sets ACK# to high terminating the transaction

Read transaction ADS[7:0] CMD Data[7:0] REQ# ACK# ?? 0x24 ?? 0x55 A B C D E F G HI

A write transaction (write 0xF4 to location 0x31) –Initiator sets ADS=0x31, CMD=1, Data=0xF4 –Initiator then sets REQ# to low. –Target sees write request. –Target reads data from data bus. (Just has to store in a register, need not write all the way to memory!) –Target then sets ACK# to low. –Initiator sets REQ# to high & stops driving other lines. –Target sets ACK# to high terminating the transaction

The push-button (if ADS=0x04 write 0 or 1 depending on button) ADS[7] ADS[6] ADS[5] ADS[4] ADS[3] ADS[2] ADS[1] ADS[0] REQ# Button (0 or 1) 0 Data[7] Data[0].. Delay ACK# Button (0 or 1)

The push-button (if ADS=0x04 write 0 or 1 depending on button) ADS[7] ADS[6] ADS[5] ADS[4] ADS[3] ADS[2] ADS[1] ADS[0] REQ# Button (0 or 1) 0 Data[7] Data[0].. Delay ACK# What about CMD?

The LED (1 bit reg written by LSB of address 0x05) ADS[5] ADS[7] ADS[6] ADS[4] ADS[3] ADS[2] ADS[1] ADS[0] REQ# Flip-flop which controls LED clock D DATA[5] DATA[7] DATA[6] DATA[4] DATA[3] DATA[2] DATA[1] DATA[0] Delay ACK#

Basic example Discuss a basic bus protocol –Asynchronous (no clock) –Initiator and Target –REQ#, ACK#, Data[7:0], ADS[7:0], CMD CMD=0 is read, CMD=1 is write. REQ# low means initiator is requesting something. ACK# low means target has done its job.

A read transaction Say initiator wants to read location 0x24 –Initiator sets ADS=0x24, CMD=0. –Initiator then sets REQ# to low. (why do we need a delay? How much of a delay?) –Target sees read request. –Target drives data onto data bus. –Target then sets ACK# to low. –Initiator grabs the data from the data bus. –Initiator sets REQ# to high, stops driving ADS and CMD –Target stops driving data, sets ACK# to high terminating the transaction

Read transaction ADS[7:0] CMD Data[7:0] REQ# ACK# ?? 0x24 ?? 0x55 A B C D E F G HI

A write transaction (write 0xF4 to location 0x31) –Initiator sets ADS=0x31, CMD=1, Data=0xF4 –Initiator then sets REQ# to low. –Target sees write request. –Target reads data from data bus. (Just has to store in a register, need not write all the way to memory!) –Target then sets ACK# to low. –Initiator sets REQ# to high & stops driving other lines. –Target sets ACK# to high terminating the transaction

The push-button (if ADS=0x04 write 0 or 1 depending on button) ADS[7] ADS[6] ADS[5] ADS[4] ADS[3] ADS[2] ADS[1] ADS[0] REQ# Button (0 or 1) 0 Data[7] Data[0].. Delay ACK# Button (0 or 1)

The push-button (if ADS=0x04 write 0 or 1 depending on button) ADS[7] ADS[6] ADS[5] ADS[4] ADS[3] ADS[2] ADS[1] ADS[0] REQ# Button (0 or 1) 0 Data[7] Data[0].. Delay ACK# What about CMD?

The LED (1 bit reg written by LSB of address 0x05) ADS[5] ADS[7] ADS[6] ADS[4] ADS[3] ADS[2] ADS[1] ADS[0] REQ# Flip-flop which controls LED clock D DATA[5] DATA[7] DATA[6] DATA[4] DATA[3] DATA[2] DATA[1] DATA[0] Delay ACK#

41 Questions? Comments? Discussion?