el68e sistemas embarcados - dainfdouglas/el68e_cortex2015.pdf · transistor count date of...

185
EL68E Sistemas Embarcados Prof. Douglas RENAUX © Prof. Dr. Douglas Renaux

Upload: ngoquynh

Post on 13-Dec-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

EL68ESistemas Embarcados

Prof. Douglas RENAUX

© Prof. Dr. Douglas Renaux

Page 2: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Arquitetura ARM

Prof. Douglas RENAUX

© Prof. Dr. Douglas Renaux

Page 3: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ARM – HistóricoAno Evento

1984-1985 Desenvolvimento do primeiro RISC comercial na Acorn Computers Ltd (Cambridge – UK)ARM = Acorn RISC Machine

1990 Fundação da ARM (Advanced RISC Machines Ltd.)

1995 ARM7TDMI

1996-1998Desenvolvimento do ARM8 em conjunto com a DEC(adquirida pela Intel que fez o StrongARM)

1997 ARM9

1999 ARM10

2003 ARM11

2005 Cortex M3, R4, A8

2007 Cortex A9 – Multicore

2012 Arquitetura v8 – 32/64 bits (Cortex A50)

2014 Cortex M7 – pipeline superescalar

© Prof. Dr. Douglas Renaux

Page 4: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Acorn

© Prof. Dr. Douglas Renaux

BBC Micro1981

Page 5: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Developer Acorn ComputersType 8-bit home computerRelease date 1 December 1981Retail availability 12 yearsIntroductory price £235 Model A, £335 Model B (in 1981)

Discontinued 1994Units sold over 1.5 millionMedia Cassette tape, floppy disc (optional), hard disc

(rare), Laserdisc (BBC Domesday Project)

Operating system Acorn MOSPower 50 WCPU 2 MHz MOS Technology 6502/6512

Storage capacity 100–800 kB (DFS)160–1280 kB (ADFS floppy discs)

20 MB (ADFS hard disc)Memory 16–32 kB (Model A/B)

64–128 kB (Model B+)128 kB (Master)

Plus 32–128 kB ROM, expandable to 272 kBDisplay PAL/NTSC, UHF/composite/TTL RGB

Graphics 640×256, 8 colours (various framebuffermodes)

78×75, 8 colours (Teletext)

Sound Texas Instruments SN76489, 4 channels, monoTMS5220 speech synthesiser with phrase ROM(optional)

Input Keyboard, twin analogue joysticks with fire buttons,lightpen

Connectivity Printer parallel, RS-423 serial, userparallel,Econet (optional), 1 MHz bus, Tube secondprocessor interface

Page 6: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Acorn Archimedes - 1987

Page 7: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ARM FamilyARMArch.

ARM Core FeatureTypical MIPS @

MHz

ARM1 ARMv1 ARM1 First implementation

ARM2

ARMv2 ARM2ARMv2 added the MUL (multiply)instruction

4 MIPS @ 8 MHz0.33 DMIPS/MHz

ARMv2a ARM250Integrated MEMC (MMU), Graphicsand IO processor. ARMv2a added theSWP and SWPB (swap) instructions.

7 MIPS @ 12 MHz

ARM3 ARMv2a ARM3First integrated memory cache.4 KB unified

12 MIPS @25 MHz0.50 DMIPS/MHz

ARM6 ARMv3

ARM60ARMv3 first to support 32-bit memoryaddress space (previously 26-bit)

10 MIPS @12 MHz

ARM600As ARM60, cache and coprocessor bus(for FPA10 floating-point unit).

28 MIPS @33 MHz

ARM610 As ARM60, cache, no coprocessor bus.17 MIPS @20 MHz0.65 DMIPS/MHz

© Prof. Dr. Douglas Renaux

Page 8: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ARM7 ARMv3

ARM700 40 MHz

ARM710 As ARM700, no coprocessor bus. 40 MHz

ARM710a As ARM71040 MHz0.68 DMIPS/MHz

ARM7TDMI ARMv4T

ARM7TDMI(-S) 3-stage pipeline, Thumb15 MIPS @ 16.8 MHz63 DMIPS @ 70 MHz

ARM710TAs ARM7TDMI, cache 8 KB unified,MMU

36 MIPS @ 40 MHz

ARM720TAs ARM7TDMI, cache 8 KB unified,MMU

60 MIPS @ 59.8 MHz

ARM740T As ARM7TDMI, MPU

ARM7EJ ARMv5TEJ ARM7EJ-S5-stage pipeline, Thumb, Jazelle DBX,Enhanced DSP instructions

© Prof. Dr. Douglas Renaux

Page 9: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Pipeline

© Prof. Dr. Douglas Renaux

Fonte: ARM

Page 10: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ARM Cortex

© Prof. Dr. Douglas Renaux

Page 11: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ARM Cortex

© Prof. Dr. Douglas Renaux

© Prof. Dr. Douglas Renaux

Page 12: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ARM Cortex

© Prof. Dr. Douglas Renaux

© Prof. Dr. Douglas Renaux

Page 13: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Cortex-M

ARMv6-M

Cortex-M0[9]

Microcontroller profile, most Thumb + someThumb-2,[10] hardware multiply instruction(optional small), optional system timer, optionalbit-banding memory

Optional cache,no TCM, noMPU

0.84DMIPS/MHz

Cortex-M0+[11]

Microcontroller profile, most Thumb + someThumb-2,[10] hardware multiply instruction(optional small), optional system timer, optionalbit-banding memory

Optional cache,no TCM,optional MPUwith 8 regions

0.93DMIPS/MHz

Cortex-M1[12]

Microcontroller profile, most Thumb + someThumb-2,[10] hardware multiply instruction(optional small), OS option adds SVC / bankedstack pointer, optional system timer, no bit-banding memory

Optional cache,0-1024 KB I-TCM, 0-1024 KB D-TCM, no MPU

136 DMIPS@170 MHz,[13](0.8 DMIPS/MHz FPGA-dependent)[1

4]

ARMv7-M Cortex-M3[15]

Microcontroller profile, Thumb / Thumb-2,hardware multiply and divide instructions,optional bit-banding memory

Optional cache,no TCM,optional MPUwith 8 regions

1.25DMIPS/MHz

ARMv7E-M Cortex-M4[16]

Microcontroller profile, Thumb / Thumb-2 / DSP /optional VFPv4-SP single-precision FPU,hardware multiply and divide instructions,optional bit-banding memory

Optional cache,no TCM,optional MPUwith 8 regions

1.25DMIPS/MHz(1.27 w/FPU)

ARM Family ARMArchitecture ARM Core Feature Cache (I/D), MMU Typical MIPS @ MHz

Page 14: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Thumb-2Densidade de código melhora em até 35% em

relação ao código ARM.Thumb-2:

“melhor de dois mundos” independe de código ARM

© Prof. Dr. Douglas Renaux

Fonte: ARM © Prof. Dr. Douglas Renaux

Page 15: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Baixo Custo x 8 bits

© Prof. Dr. Douglas Renaux

Page 16: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

• http://www.embedded-systems.com/underthehood/210101486© Prof. Dr. Douglas Renaux

Page 17: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

© Prof. Dr. Douglas Renaux

Page 18: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ARMv8-A (64 bits)

© Prof. Dr. Douglas Renaux

Page 19: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 20: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 21: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 22: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 23: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Exynos 5250 com Cortex-A15 dual core

© Prof. Dr. Douglas Renaux

Page 24: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 25: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

64-bits - AMDHierofalcon will pack four to eight 64-bit ARM

A57 cores clocked up to 2GHz.In addition to new ARM cores, the 28nm chips

also feature 10Gbit Ethernet and PCIExpress 3.0 on board, which means theyshould be a good fit for data centres.

21-Out-2013

© Prof. Dr. Douglas Renaux

Page 26: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

NVIDEA:192 GPU4x A15ou 2x A57

Tegra K1Lançado em

2014

© Prof. Dr. Douglas Renaux

Page 27: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Tegra X1 - 2015

© Prof. Dr. Douglas Renaux

Page 28: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

NVidia - 2016

© Prof. Dr. Douglas Renaux

Page 29: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Qualcomm's Growing 64-bit SoC LineupMarketing Name Snapdragon 615 Snapdragon 610 Snapdragon 410

Internal Model Number MSM8939 MSM8936 MSM8916

Manufacturing Process 28nm LP 28nm LP 28nm LP

CPU 8 x ARM Cortex A53 4 x ARM Cortex A53 4 x ARM Cortex A531.2GHz+

ISA 32/64-bit ARMv8 32/64-bit ARMv8 32/64-bit ARMv8

GPU Qualcomm Adreno 405 Qualcomm Adreno 405 Qualcomm Adreno 306

H.265 Decode Yes Yes No

Memory Interface 1 x 64-bit LPDDR2/3 1 x 64-bit LPDDR2/3 1 x 64-bit LPDDR2/3

Integrated Modem 9x25 core, LTECategory 4, DC-HSPA+, DS-DA

9x25 core, LTECategory 4, DC-HSPA+, DS-DA

9x25 core, LTECategory 4, DC-HSPA+, DS-DA

Integrated WiFi Qualcomm VIVE802.11ac

Qualcomm VIVE802.11ac

Qualcomm VIVE802.11ac

eMMC Interface 4.5 4.5 4.5

© Prof. Dr. Douglas Renaux

Page 30: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 31: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Fev 29, 2016 – Raspberry Pi 3

© Prof. Dr. Douglas Renaux

Page 32: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Cortex-M7 (lançamento 24-Set-2014)

© Prof. Dr. Douglas Renaux

Page 33: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 34: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 35: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 36: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 37: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

RISC x CISC

© Prof. Dr. Douglas Renaux

Page 38: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Histórico ComputadoresComputador =

um dispositivo que computa(calcula, processa dados)

© Prof. Dr. Douglas Renaux

Page 39: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Gerações de ComputadoresGeração Descrição0 Máquinas Mecânicas e Eletromecânicas

solução de equações1 40’s – Válvula

ENIAC, Zuse2 50’s – Transistores

Universidade de ManchesterIBM 350

3 60’s – Circuitos integrados SSI (portas lógicas)Apolo Guidance Computer (embarcado)IBM System/360Digital VAX

4 70’s – Microprocessador

5 20?? – ótico, orgânico, computação quântica ???IA © Prof. Dr. Douglas Renaux

Page 40: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Computação Quântica -5-Out-2015

© Prof. Dr. Douglas Renaux

Page 41: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Primeira Geração

© Prof. Dr. Douglas Renaux

Colossus - UKENIAC - USA

Page 42: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Segunda Geração

© Prof. Dr. Douglas Renaux

PDP-1

Page 43: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Terceira Geração

© Prof. Dr. Douglas RenauxVAX 11/780

Page 44: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

De que forma os projetistas decomputadores (arquitetos) utilizaram oaumento significativo de transistoresdisponibilizados pela evolução rápida datecnologia de fabricação de circuitosintegrados ?

© Prof. Dr. Douglas Renaux

Page 45: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

CISCComplex Instruction Set Computer

o conjunto de instruções inicialmente simples avanços tecnológicos (transistores, CIs)

permitiram a manufatura de computadores commais transistores a menor custo

projetistas optaram por conjuntos de instruçõescada vez mais complexos

© Prof. Dr. Douglas Renaux

Page 46: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

CISCComo tornar as instruções mais complexas:

aumentar o número de modos deendereçamento

endereçamento indireto em memória [[R]] instruções com elevado grau semântico Exemplos do 68000

SBCD: Subtract Decimal with ExtendSWAP: Swap register WordsCMP2: Compare Register against Upper and Lower

Bounds

© Prof. Dr. Douglas Renaux

Page 47: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 48: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Processor Transistorcount

Date ofintroductio

n

Manufacturer Process Area

Intel 4004 2,300 1971 Intel 10 µm 12 mm²

Intel 8008 3,500 1972 Intel 10 µm 14 mm²

Motorola68000 68,000 1979 Motorola 3.5 μm 44 mm²

Intel 80286 134,000 1982 Intel 1.5 µm 49 mm²

Pentium 3,100,000 1993 Intel 0.8 µm 294 mm²

ARM 7 578977[9] 1994 ARM 0.5 µm 68.51 mm²

ARMCortex-A9

26,000,000[

12] 2007 ARM 65 nm

AMDK10 quad-core 2M L3

463,000,000[11] 2007 AMD 65 nm 283 mm²

Quad-Core +GPU Core i7 1,400,000,000 2012 Intel 22 nm 160 mm²

Xbox OneMain SoC 5,000,000,000 2013 Microsoft/AMD 28 nm 363 mm²

Page 49: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

PerguntasQual é, afinal, o objetivo primordial do arquiteto

/ projetista de computadores ?Dada uma tecnologia de fabricação e uma

área de silício (custo), como fazer o melhoraproveitamento possível ?

Quais são as conseqüências de um conjuntode instruções complexo ?

© Prof. Dr. Douglas Renaux

Page 50: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

RISC x CISCRISC CISC

Conjunto de instruções reduzido Conjunto de instruções extenso

Instruções muito simples Instruções complexas

Instruções de tamanho fixo Instruções de tamanho variável

Decodificação simplificada(tabela)

Decodificação complexa(microcódigo)

Execução regular Cada instrução executa a suamaneira

Instruções requerem o mesmonúmero de clocks para executar

Grande variação no número declocks por instrução

Possibilita o uso de pipeline Extremamente difícil / impossível ouso de pipeline

© Prof. Dr. Douglas Renaux

Page 51: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Pipeline

© Prof. Dr. Douglas Renaux

Page 52: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Diferenciais da arquitetura ARMCortex-M3

© Prof. Dr. Douglas Renaux

Page 53: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Instruções CondicionaisA maioria das instruções ARM são

condicionais só produzem efeito se os flags estiverem

setados adequadamente BEQ – Branch on Equal

executa um salto caso o bit Z esteja setado As instruções condicionais precisam estar em

um “bloco IT”exceto a instrução B (BRANCH = Salto)

ex: ADDEQ –executa uma soma caso o bit Z esteja setado

© Prof. Dr. Douglas Renaux

Page 54: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

PipelineNa arquitetura Cortex-M, as instruções são

executadas de acordo com uma dasseqüências abaixo:

1. BUSCADECODIFICAÇÃOEXECUÇÃO (OPERAÇÃO LÓG./ARIT.)

2. BUSCADECODIFICAÇÃOEXECUÇÃO (CÁLCULO ENDEREÇO)ACESSO À MEMÓRIA DE DADOS

© Prof. Dr. Douglas Renaux

Page 55: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

PipelineNo Cortex-M3 o pipeline tem três estágios:

1. BUSCA – leitura da instrução da memória2. DECODIFICAÇÃO – interpretação do código

da instrução e geração dos sinais de controle3. EXECUÇÃO – operação lógica/aritmética ou

acesso a memória de dados

* o estágio de EXECUÇÃO pode ocupar mais deum ciclo de clock

© Prof. Dr. Douglas Renaux

Page 56: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 57: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 58: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Arquitetura ARM

Prof. Douglas RENAUX

© Prof. Dr. Douglas Renaux

Page 59: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Módulo 3

A arquitetura Cortex-M3

© Prof. Dr. Douglas Renaux

Page 60: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Cortex-M3 internal structure

© Prof. Dr. Douglas Renaux

Page 61: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Instruções do Cortex-M0

© Prof. Dr. Douglas Renaux

Page 62: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 63: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 64: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

© Prof. Dr. Douglas Renaux

Page 65: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Arquitetura Cortex-M3Visão geral da Arquitetura:

Registradores Conjunto de instruções Acesso à Memória Interrupções

© Prof. Dr. Douglas Renaux

Page 66: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Módulo 4

Conjunto de Instruções Thumb-2

© Prof. Dr. Douglas Renaux

Page 67: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Arquitetura Cortex-M3Cortex-M3 usa a versão ARMv7-M de arquitetura

ARMv7-M Thumb2 Mix de instruções de 16 e 32 bits Não requer alinhamento na memória das

instruções de 32 bits

© Prof. Dr. Douglas Renaux

Page 68: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 69: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 70: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 71: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 72: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 73: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 74: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 75: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

infocenter.arm.com

Developer Guides and Articles

Software Development

© Prof. Dr. Douglas Renaux

Page 76: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Formato das Instruções Log/Arit Três operandos explícitos (Rd,Op1,Op2)

ADD R0,R1,R2R0 := R1 + R2

Dois operandos e um implícito (Rd,Op2)ADDS R0,R5R0 := R0 + R5

Dois operandos (Op1,Op2)CMP R8,R9

© Prof. Dr. Douglas Renaux

Page 77: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

1 - Lógicas e AritméticasInstrução Descrição

ADD, ADDS, ADCS Soma, soma com carry

SUB, SUBS Subtrai

RSBS Subtração reversa

MUL Multiplicação: 32b x 32b -> 32b

ANDS, ORRS, EORS Operações lógicas: E, OU, OU-EXCL (bit a bit)

BICS Operação lógica: E NÃO

CMP, CMN Comparação, comparação negada

TEQ, TST Teste de bits

MOV, MVN Move, move negado

© Prof. Dr. Douglas Renaux

Page 78: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Tipo Tamanho Tipo Tamanhochar 8 bits [ ] 32 bitsshort 16 bits struct ptr = 32 bitsint 32 bits float 32 bitsunsigned 32 bits double 64 bitslong 32 bits enum = intlong long 64 bits* 32 bits

Page 79: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

CMP, CMN, TST, MOV, MVN Formatos: CMN Rn,Rm // R0-R7 (soma Rn e Rm) CMP Rn, #imm //R0-R14; 0-255 CMP Rn,Rm TST Rn, Rm // R0-R7 (AND) MOVS Rd, Rm MOVS Rd, #imm // 0-255 MVNS Rd,Rm MOV Rd,Rm

© Prof. Dr. Douglas Renaux

Page 80: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Deslocamento (LSLS)

• n >= 32 todos os bits são zeradosn >= 33 todos os bits e o carry são zerados

• variantes: só LSLS (altera carry)LSLS {Rd},Rm,RsLSLS {Rd},Rm,#imm

• efeito de LSLS Rm, #n é Rm * 2n

© Prof. Dr. Douglas Renaux

Page 81: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Deslocamento (LSRS)

• n >= 32 todos os bits são zeradosn >= 33 todos os bits e o carry são zerados

• variantes: só LSRS (altera carry)LSRS {Rd},Rm,RsLSRS {Rd},Rm,#imm

• efeito de LSRS Rm, #n é Rm / 2n

© Prof. Dr. Douglas Renaux

Page 82: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Deslocamento (ASRS)

n >= 32 todos os bits e o carry recebem cópia do bit 31variantes: só ASRS (altera carry)

ASRS {Rd},Rm,RsASRS {Rd},Rm,#imm

efeito de ASRS Rm, #n é Rm / 2n

© Prof. Dr. Douglas Renaux

Page 83: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Rotação (RORS) / RRXn >= 32 é o mesmo que n-32variantes: só RORS (altera carry)

RORS {Rd},Rm,RsRORS {Rd},Rm,#imm

efeito de LSRS Rm, #n é Rm / 2n (para Rm semsinal)

• n = 32 o valor não é alterado e CY := Rm[31]n = 33 mesmo efeito que RORS com n = 1

• variantes: só RORS (altera carry)RORS {Rm},Rm,Rs

• não acessa regs altos• apenas dois operandos

© Prof. Dr. Douglas Renaux

Page 84: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ARM – Barrel Shifter

DestinationCF 0 Destination CF

LSL : Logical Left Shift ASR: Arithmetic Right Shift

Multiplication by a power of 2 Division by a power of 2,preserving the sign bit

Destination CF...0 Destination CF

LSR : Logical Shift Right ROR: Rotate Right

Division by a power of 2 Bit rotate with wrap aroundfrom LSB to MSB

Destination

RRX: Rotate Right Extended

Single bit rotate with wrap aroundfrom CF to MSB

CF

© Prof. Dr. Douglas Renaux

Page 85: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Operando 2

© Prof. Dr. Douglas Renaux

Page 86: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Operando 2 Registrador

R4 Registrador e deslocamento

R4, LSL #4R5, ASR #1

Constante:#4#0xAABB#-2

© Prof. Dr. Douglas Renaux

Page 87: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Deslocamentos no Operando 2Opções:

• ASR #n 1 ≤ n ≤ 32• LSL #n 1 ≤ n ≤ 31• LSR #n 1 ≤ n ≤ 32• ROR #n 1 ≤ n ≤ 31• RRX

© Prof. Dr. Douglas Renaux

Page 88: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Constantes no Operando 2Não é possível definir qualquer valor de

constante no Operando 2Apenas alguns valores podem ser formados:

Valores de 8 bits deslocados Valores do tipo 0x00XY00XY Valores do tipo 0xXY00XY00 Valores do tipo 0xXYXYXYXY

© Prof. Dr. Douglas Renaux

Page 89: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

MULTIPLICAÇÃO-1MULS Rd,Rn,Rm

Rd := Rn x Rm Rm deve ser o mesmo registrador que Rd formato preferido: MULS Rd,Rn

R0 – R732-bits x 32-bits -> 32-bits em 1 único ciclo de clockafeta N e Z

© Prof. Dr. Douglas Renaux

Page 90: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

MULTIPLICAÇÃO-2MUL Rd,Rn,Rm

Rd := Rn x Rm formato alternativo: MUL Rd,Rn

Registradores exceto SP, PC32-bits x 32-bits -> 32-bits em 1 único ciclo de clock

© Prof. Dr. Douglas Renaux

Page 91: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

MULTIPLICAÇÃO-3MLA Rd,Rn,Rm,Ra

Rd := Ra + Rn x Rm

32-bits x 32-bits -> 32-bits em 2 ciclos de clock

© Prof. Dr. Douglas Renaux

Page 92: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

MULTIPLICAÇÃO-4MLS Rd,Rn,Rm,Ra

Rd := Ra - Rn x Rm

32-bits x 32-bits -> 32-bits em 2 ciclos de clock

© Prof. Dr. Douglas Renaux

Page 93: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

MULTIPLICAÇÃO-5UMULL RdLo, RdHi, Rn, Rm

RdHi:RdLo := Rn x Rm

UMLAL RdLo, RdHi, Rn, Rm RdHi:RdLo := RdHi:RdLo + Rn x Rm

SMULL RdLo, RdHi, Rn, Rm RdHi:RdLo := Rn x Rm

SMLAL RdLo, RdHi, Rn, Rm RdHi:RdLo := RdHi:RdLo + Rn x Rm

32-bits x 32-bits -> 64-bits em 3 a 5 ciclos de clock© Prof. Dr. Douglas Renaux

Page 94: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

DIVISÃOUDIV Rd,Rn,Rm

Rd := Rn / Rm

SDIV Rd,Rn,Rm Rd := Rn / Rm

32-bits / 32-bits -> 32-bits em 4 ciclos de clock

configurável se quer gerar exceção na divisão por zero

© Prof. Dr. Douglas Renaux

Page 95: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

MOV, MOV.W, MOVT Para simplificar a carga de constantes que não

atendem o formato “8-bits com deslocamento”

MOV Ri,#16-bits (equivalente a MOV.W Ri,#16)carrega os 16 bits menos significativos de RiMOVT Ri,#16-bits

carrega os 16 bits mais significativos de Ri

Com 2 instruções pode-se carregar qualquerconstante de 32 bits em um registrador !

© Prof. Dr. Douglas Renaux

Page 96: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Exercícios1. Multiplicar o valor inteiro (32-bits) que está em R3

pela constant 9:a) Usando instrução de multiplicaçãob) Sem usar multiplicação

(sugestão: usar ADD/SUB/shift)

2. Idem, mas multiplicando por 15.3. Qual a maneira mais eficiente (menos instruções e

menos tempo) para fazer as seguintes cargas deconstantes:

1. R0 := 02. R1 := 2003. R2 := 0x12344. R3 := 0xFFFFFF005. R4 := 0xABCDEF00

© Prof. Dr. Douglas Renaux

Page 97: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Instruções que Operam em BitsBFC Rd, #lsb, #w#lsb e #w estão na faixa de 0 a 31 e 1 a 32Bit-field clear: limpa #w bits a partir de #lsbBFC R0, #4, #8 R0 = 0xFFFF F00F

BFI Rd, Rn, #lsb, #wBit-field Insert: copia #w bits de Rn:0 para Rd:#lsbBFI R1, R2, #8, #0xC R1 = 0x FFFC DDFF

© Prof. Dr. Douglas Renaux

Page 98: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Exercícios4. Alterar os bits 5 a 9 do registrador R10 para

11001a) Usando AND/OR/…b) Usando instruções de bit-field

sua solução deve funcionar para qualquer que sejao valor atual de R10.

© Prof. Dr. Douglas Renaux

Page 99: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Instruções que Operam em BitsSBFX Rd, Rn, #lsb, #w#lsb e #w estão na faixa de 0 a 31 e 1 a 32Extrai campo e faz extensão de sinal:

copia #w bits a partir de #lsb para o bit0 de Rd eestende

SBFX R0, R1, #4, #8 R0 = 0xFFFF FFBC

UBFX Rd, Rn, #lsb, #wIdem, estendendo com zeros

© Prof. Dr. Douglas Renaux

Page 100: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ExtendSXTB Rd,Rm // Rd := sign extend Rm[7:0]UXTB Rd,Rm // Rd := zero extend Rm[7:0]SXTH Rd,Rm // Rd := sign extend Rm[15:0]UXTH Rd,Rm // Rd := zero extend Rm[15:0]

R0-R7

© Prof. Dr. Douglas Renaux

Page 101: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ADRADR Rd, labelcalcula o endereço do label na forma de um

offset para o PCCarrega o Rd com o endereço do label

Faixa permitida: PC +/- 4095

Obs: no IAR o label deve estar na região dedados para que o assembler aceite o ADR

© Prof. Dr. Douglas Renaux

Page 102: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

2 - Acesso à Memória

© Prof. Dr. Douglas Renaux

Page 103: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Acessos Alinhadosum acesso à memória de dados é alinhado se:

acesso à Word é em endereço múltiplo de 4 acesso à HalfWord é em endereço múltiplo de 2 acesso à Byte é em endereço múltiplo de 1

No Cortex-M0 todos os acessos devem seralinhados ou causa um HardFault

No Cortex-M3 os acessos podem serdesalinhados

© Prof. Dr. Douglas Renaux

Page 104: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

LD(Load = Leitura)

ST(Store = Escrita)

Instruções de Acesso à Memóriade Dados

© Prof. Dr. Douglas Renaux

STRSTRDSTMPUSH

LDRLDRDLDMPOP

Page 105: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

LDRLê dado da memóriaFormatos:

LDR Rt,[Rn] LDR Rt,[Rn,#off] LDRB Rt,[Rn,#off] LDRH Rt,[Rn,#off]

Restrições: #off: -255..4095 [Rn,#off] outras restrições quando envolve os

registradores SP ou PC

© Prof. Dr. Douglas Renaux

Page 106: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

LDRLê dado da memóriaFormatos:

LDR Rt,[Rn,Rm] LDRB Rt,[Rn,Rm] LDRH Rt,[Rn,Rm]

LDR Rt,[Rn, Rm, LSL #2] //end = Rn + Rm<<2

© Prof. Dr. Douglas Renaux

Page 107: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

LDR – Pré e Pós IndexadoPré-Indexado:• LDR Rd,[Ri,#cte] !• LDR Rd,[Ri,Rm] !• Primeiro calcula endereço depois acessa memória• O ‘!’ indica que o Ri deve ser atualizado com o endereço

recém calculado. LDR R2,[R3,#4]!

Pós-Indexado• LDR Rd,[R ],#cte• LDR Rd,[Ri],Rm• Primeiro acessa memória depois calcula endereço• Sempre atualiza Ri

© Prof. Dr. Douglas Renaux

Page 108: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

LDRSB e LDRSHLê dado da memória e faz extensão de sinalFormatos:

LDRSB Rt,[Rn,#off] LDRSH Rt,[Rn,#off] LDRSB Rt,[Rn,Rm] LDRSH Rt,[Rn,Rm]

© Prof. Dr. Douglas Renaux

Page 109: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

LDR (relativo ao PC)Lê dado da memóriaO dado está em endereço próximo ao código sendo

executadoFormatos:

LDR Rt,[PC,#100] LDR Rt, label

© Prof. Dr. Douglas Renaux

Page 110: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

LDRDLê 64 bits da memória para 2 registradoresUsado para carregar inteiros de 64 bits (long long)LDRD Rt, Rt2, label // relativo ao PCLDRD Rt, Rt2, [...] // mesmos modos de

// endereçamento que LDR

Rt – word menos significativo (LSW)está no endereço especificado

Rt2 – word mais signifivativo (MSW)está no endereço seguinte (+4)

© Prof. Dr. Douglas Renaux

Page 111: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

STREscreve dado da memóriaFormatos:

STR STRB STRH

mesmas regras que para LDR

© Prof. Dr. Douglas Renaux

Page 112: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

LDM e STMTranfere múltiplos registradores de/para memóriaFormatos:

LDM R0,{R0,R1,R2} LDM R1!,{R2-R7} STM R0!,{R2-R4}

© Prof. Dr. Douglas Renaux

Page 113: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

LDM e STMVariantes:• IA = Increment After – default

1. acessa memória2. incrementa endereço

• DB = Decrement Before1. decrementa endereço2. acessa memória

• EA = Empty Ascending• FD = Full DescendingLDM = LDMIA, LDMFDSTM = STMIA, STMEA

© Prof. Dr. Douglas Renaux

Page 114: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

PUSH e POPTranfere múltiplos registradores de/para memóriaFormatos:

PUSH {R0-R7} POP {R1,R3-R6}

Full Descending Stack

STMFD sp!, {r0,r1,r3-r5}PUSH {r0,r1,r3-r5}

r5r4r3r1r0SP

FD : Full Descending

old SP

endereçobaixo

© Prof. Dr. Douglas Renaux

Page 115: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

LDM e STM

155

STMDB sp!, {r0,r1,r3-r5}STMFD sp!, {r0,r1,r3-r5}

r5r4r3r1r0SP

0x400

0x418

0x3e8

STMIA sp!, {r0,r1,r3-r5}STMEA sp!, {r0,r1,r3-r5}

r5r4r3r1r0

SP

Old SP

DB : Decrement BeforeFD : Full Descending

IA : Increment AfterEA : Empty Ascending

Old SP

© Prof. Dr. Douglas Renaux

Page 116: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Exercício – Acesso à MemóriaEm C:

crie uma struct com 3 campos: um inteiro,um char, e um short e atribua valores aestes campos.

Em assembly:some os 3 campos da struct produzindo umresultado de 32 bits com sinal.

© Prof. Dr. Douglas Renaux

Page 117: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Projetos:Parte da avaliação (equipes de 1 ou 2 pessoas)1. Comunicação por CAN, só 4 placas2. USB device: HID (p.ex. – mouse)3. PWM: gerar onda senoidal.

© Prof. Dr. Douglas Renaux

Page 118: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

3 - Saltos

© Prof. Dr. Douglas Renaux

Page 119: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

3 - SaltosB loopA ; salta para o label LoopA

(unica instrução condicional que não precisa IT)BL funC ; chamada de rotina, armazena endereço

de retorno em LRBX LR ; retorno de chamada de rotinaBLX R0 ; Chamada de rotinaBEQ labelD ; Salto condicional

© Prof. Dr. Douglas Renaux

Page 120: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

SaltosCBZ Rn, label – Testa Rn e salta se 0CBNZ Rn, label – Testa Rn e salta se não-zero

Restrições: Só saltos para frente até 130 bytes Não pode ser usado em bloco IT Não modifica flags Só R0 a R7

© Prof. Dr. Douglas Renaux

Page 121: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Bloco ITBloco consiste de 1 a 4 instruções condicionaisITxyz condx,y,z são T ou E (Then ou Else)

ITTE EQADDEQSUBEQORRNE

© Prof. Dr. Douglas Renaux

Page 122: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Bloco ITA instrução de salto condicional

Bcc label(onde cc é uma das condições)não precisa estar num bloco IT

As instruções:IT, CBZ, CBNZ, CPSIE, CPSIDNÃO podem estar em bloco IT

Uma instrução que altera PC, só pode estar numbloco IT se for a última.

© Prof. Dr. Douglas Renaux

Page 123: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

CondiçõesNo Cortex-M3 as outras instruções podem ir em blocos IT

© Prof. Dr. Douglas Renaux

Page 124: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Saltos (limites)

© Prof. Dr. Douglas Renaux

Page 125: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Exercício

© Prof. Dr. Douglas Renaux

1)

Page 126: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Exercício – continuação MDC2) Como transformar em subrotina ?3) Como chamar a partir de outra rotina em

assembly ?4) Como chamar a partir de uma função em C ?

© Prof. Dr. Douglas Renaux

Page 127: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ExercícioQual a maneira mais eficiente de implementar

um loop com número fixo de execuções,como por exemplo:

for (int i=0; i<10; i++) {// dentro do loop não se usa ia = b<<3 + a;b++;

}

© Prof. Dr. Douglas Renaux

Page 128: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Módulo 5

Registradores EspeciaisModos de OperaçãoInstruções Especiais

© Prof. Dr. Douglas Renaux

Page 129: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

priviledged

Page 130: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Pilha (Stack)pode-se trabalhar apenas com MSPo SP corrente sempre é acessado como R13 ou SPO SP está sempre com alinhamento de Word

(i.e. endereços múltiplos de 4)Instruções:

PUSH - empilha POP - desempilha

Full descending

© Prof. Dr. Douglas Renaux

Page 131: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Link RegisterR14 ou LRArmazena o endereço de retorno de uma subrotinaDeve ser salvo antes de chamar outra subrotina

© Prof. Dr. Douglas Renaux

Page 132: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Contador de ProgramaPC ou R15instrução sendo executada + 4endereço de instrução é sempre par (bit0 = 0)bit0 do PC é usado para indicar modo Thumb

após reset e em algumas instruções desalto: BX e BLX

© Prof. Dr. Douglas Renaux

Page 133: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Modo

Nível dePrivilégio

Thread

Handler

Não-Privilegiado Privilegiado

Pilha

Main (Principal)

Processo

Page 134: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 135: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Stack: selecionado pelo bit1 de CONTROL0 = main; 1 = process (este stack só pode ser usado em modo Thread)

Modo: selecionado pelo IPSR0 = Thread; >0 exception

Privilégio: bit 0 do CONTROL (0 = privilegiado, 1 = não-privilegiado)no Cortex-M0 é sempre privilegiado (sem restrição)

© Prof. Dr. Douglas Renaux© Prof. Dr. Douglas Renaux

Page 136: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 137: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

xPSR

© Prof. Dr. Douglas Renaux© Prof. Dr. Douglas Renaux

Page 138: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux

Page 139: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

IPSR

IPSR Exception number != IRQ Number (Table 320)

© Prof. Dr. Douglas Renaux

Page 140: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

CONTROL

CONTROL instruções MSR e MRS após MSR usar ISB para garantir que o novo stack

será usado© Prof. Dr. Douglas Renaux

© Prof. Dr. Douglas Renaux

Page 141: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

PRIMASK

PRIMASK só pode ser escrito em modo privilegiado instruções CPSID e CPSIE, MSR e MRS

© Prof. Dr. Douglas Renaux

Page 142: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Modo PrivilegiadoNo modo Privilegiado o código tem acesso a

TODOS os recursos.No modo NÃO-Privilegiado o código NÃO tem

acesso à: instruções como CPS que permitiriam alterar

FAULTMASK e PRIMASK maioria dos registradores do System Control

© Prof. Dr. Douglas Renaux

Page 143: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

4 - Outros

© Prof. Dr. Douglas Renaux

Page 144: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

BKPTBKPT #imm#imm é um valor de 0 a 255entrada no estado de depuraçãoesta instrução é utilizada por debugers

instrução não deve ser usada porprogramadores

© Prof. Dr. Douglas Renaux

Page 145: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

CPSChange Processor State

altera o PRIMASK

Formatos: CPSID i // desabilita IRQs CPSIE i // habilita IRQs

© Prof. Dr. Douglas Renaux

Page 146: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

DMB — The Data Memory Barrier (DMB)completa transações pendentes antes derealizar outra transação.

DSB — The Data Synchronization Barrier (DSB)completa transações pendentes antes de

executar a próxima instrução.ISB — The Instruction Synchronization Barrier

(ISB) garante que o efeito das transaçõesefetuadas seja percebido antes da próximainstrução.

© Prof. Dr. Douglas Renaux

Page 147: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Exemplos de UsoTabela de vetores: usar DMB entre uma

alteração no vetor e a habilitação da IRQcorrespondente.

Alteração no código: usar uma ISB logo após ainstrução que altera o código.

Alteração no mapa de memória: usar um DSBimediatamente após a instrução que altera omapa de memória.

© Prof. Dr. Douglas Renaux

Page 148: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

MSR, MRSMSR – Move to Special Reg from Register

MSR special_reg, RnMRS – Move to Register from Special Reg

MRS Rd, special_regSpecial Reg:

APSR, IPSR, EPSR, IEPSR, IAPSR,EAPSR, PSR, MSP, PSP, PRIMASK, orCONTROL

Rd, Rn – não podem ser SP ou PC

© Prof. Dr. Douglas Renaux

Page 149: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

NOPNão realiza nenhuma operaçãoPode ser elimininada no pipeline (i.e. pode ser

executado em tempo 0)Uso: alinhamento de código em fronteira de

word ou double-word

© Prof. Dr. Douglas Renaux

Page 150: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

SEVSend EventFormato:

SEV

Informa da ocorrência de um eventoSeria usado com WFE que não existe no

LPC11xx

© Prof. Dr. Douglas Renaux

Page 151: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

SVCChamada ao Supervisor (S.O.)Formato

SVC #imm // 0 .. 255Gera uma exceção do tipo SVCA ISR pode ler o valor de #imm para identificar

o serviço solicitado

© Prof. Dr. Douglas Renaux

Page 152: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

WFIWait for InterruptFormato:

WFIentra em modo de baixo consumo até que:

exceção IRQ, mesmo que mascarada por PRIMASK solicitação de DEBUG

© Prof. Dr. Douglas Renaux

Page 153: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Módulo 6

Acesso à Memória

© Prof. Dr. Douglas Renaux

Page 154: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

© Prof. Dr. Douglas Renaux© Prof. Dr. Douglas Renaux

Page 155: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Memória – Processadores 13xx

© Prof. Dr. Douglas Renaux

Page 156: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Módulo 7

Exceções/Interrupções

© Prof. Dr. Douglas Renaux

Page 157: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Interrupções são uma forma eficiente de seresponder às demandas solicitadas pelosperiféricos.

Alternativa é polling: desperdício de consultas atendimento mais demorado

212

Interrupções

Page 158: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Estrutura típica de Interrupção

213

MicroprocessorCore

(e.g Cortex-M)

InterruptController

Peripheral1

P2

P3

P4

Pn

IRQ

Page 159: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

InterrupçõesPrincípio de funcionamento

durante a execução de um programa, um sinal de hardware (IRQ = InterruptRequest) é ativado.

um controlador de interrupções percebe o sinal, verifica se está habilitado(desmascarado) e sua prioridade e então informa o processador da existênciade um pedido de interrupção pendente

o processador verifica se as interrupções estão habilitadas e finaliza aexecução da instrução corrente

SALVAMENTO DE CONTEXTO (registradores, palavra de status) [em alguns casos] - muda o ponteiro de pilha para IRQ_STACK busca no vetor de interrupção: identifica quem é a rotina responsável pelo

atendimento daquela interrupção específica execução da ISR (parte do salvamento de contexto pode ser feito aqui) informa ao periférico solicitante que a IRQ foi atendida informa ao controlador de interrupção que o atendimento finalizou (EOI) RECUPERA CONTEXTO dá seguimento a execução do programa que foi interrompido

214

Page 160: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

InterrupçõesÉ um processo complexoQualquer falha em algum passo causa uma

parada total do sistemaDepuração difícil, principalmente porque é um

evento assíncrono

Um programador só é realmente um programadorde sistemas embarcados quando sabe trabalharbem com o atendimento de interrupções.

Quando se usa RTOS, em geral, passa-se aoRTOS a responsabilidade de tratar as IRQs.

215

Page 161: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Controlador de InterrupçãoEm geral são vetorizados:

detectam automaticamente qual dos pedidos deinterrupção ativo é o mais prioritário, consultama tabela de endereços de ISR (vetor deinterrupção) e entregam ao processador oendereço da ISR.

portanto, a CPU só precisa ler o endereço daISR e executar a partir dali

No Cortex-M:maior eficiência obtida pelo atendimento

totalmente realizado pelo HW. 216

Page 162: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Desabilitando o Atendimento deIRQs

Também chamado de mascaramento de IRQsNo controlador de interrupções é possível

mascarar / desmascarar IRQs específicas: p.ex. mascarar apenas a IRQ da UART2

No processador é possívelmascarar / desmascarar o atendimento deinterrupções por completo.

217

Page 163: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Teste e DepuraçãoTeste e Depuração de ISRs é uma atividade

complexa.Quando finalmente se consegue atender à

primeira interrupção: o teste NÃO acaba aqui !!! atender a segunda IRQ do mesmo periférico

também requer teste e depuração p.ex. esquecer de enviar um EOI impede o

atendimento do pedido seguinte.

Importante testar situações de stress: vários pedidos simultâneos de periféricos distintos várias repetições de pedidos de interrupção do

mesmo periférico

218

Page 164: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Como registrar uma ISR numCortex-M3

Basta colocar o nome da ISR na tabela devetores de exceção localizada no endereço0 da memória.

229

Page 165: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Como registrar uma ISR numCortex-M3

Cortex-M: o vetor de interrupções fica na memória do

processador a partir do endereço 0. basta armazenar a tabela com os endereços

das ISRs nesta região de memória.

230

Page 166: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Interrupções - ConceitosLatência:

tempo entre o pedido de interrupção (ativação dosinal IRQ) até o início da execução da ISR: HW: detecção, processamento no Cont. IRQ tempo de finalização da instrução corrente tempo que as IRQs estão desabilitadas outras ISR em execução (aninhamento x prioridade) no device driver no RTOS na aplicação

Tempo de Resposta (pior caso):Somar:

Pior caso da Latência Pior caso do tempo de execução da ISR.

231

Page 167: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ExceçõesQualquer solicitação para mudança do fluxo

normal de um programa. interrupção detecção de falha / erro (p.ex. acesso

desalinhado)

© Prof. Dr. Douglas Renaux

Page 168: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ExceçõesEstados

Inativo (inactive) = não ativo nem pendente Pendente (pending) = aguardando atendimento

(p.ex. pedido de interrupção – irq – deperiférico)

Ativo (active) = em atendimentopode haver mais de uma interrupção ematendimento (interrupções aninhadas – nested)

Ativo e Pendente = interrupção em atendimentoe outro pedido da mesma fonte está pendente

© Prof. Dr. Douglas Renaux

Page 169: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Tipos de ExceçãoReset – reinício da execução (modo Thread) (-3)NMI - prioridade -2HardFault – prioridade -1

falha genérica: representa todas as classes defalhas que não foram tratadas

SVC – causada pela instrução SVC (SupervisorCall)

PendSV – solicitação de serviço (p.ex.chaveamento de contexto)

SysTick – gerado pelo system timerIRQ – pedido de interrupção feito por periférico

© Prof. Dr. Douglas Renaux

Page 170: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Configurável: prioridade de 0 (default) a 3Prioridades: valor menor significa maior prioridadePRIMASK: pode mascarar as IRQ com prioridade configurável

© Prof. Dr. Douglas Renaux

Page 171: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

O LSb deve ser 1 indicando que a rotina de tratamento é em ThumbO IAR coloca o bit0 em 1 automaticamente para todos os labels criados

em Thumb© Prof. Dr. Douglas Renaux

Page 172: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

AtendimentoUm atendimento de exceção ocorre quando:

existe uma exceção pendente com prioridadesuficiente (*); e

o processador está em modo Thread; ou a exceção pendente é de prioridade maior que

a exceção sendo atendida (preempção)

(*) prioridade suficiente significa prioridade maior do que o limiteestabelecido no PRIMASK

© Prof. Dr. Douglas Renaux

Page 173: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Atendimento (2)Stacking – salva o estado

O SP está alinhado em double-wordse necessário pula um word antes de começar

o empilhamento

© Prof. Dr. Douglas Renaux

Page 174: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Atendimento (3)O processador lê do vector_table o endereço

do handler;LR := EXC_RETURN (ver próximo slide)após o stacking, a execução se dá a partir do

handler, a exceção passa ao status de ativaSe durante o stacking ocorreu outra exceção

de maior prioridade então esta é atendida(late-arriving exception)

© Prof. Dr. Douglas Renaux© Prof. Dr. Douglas Renaux

Page 175: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Atendimento (4)

© Prof. Dr. Douglas Renaux

Page 176: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Retorno de ExceçãoOcorre quando uma instrução escreve no PC

um dos valores de EXC_RETURNAs instruções que podem ser usadas para

retorno de exceção são POP e BX

© Prof. Dr. Douglas Renaux

Page 177: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Tratamento de FaltasTodas as faltas causam HardFaultTrava se a falta ocorre no handler da NMI ou HardFaultFaltas:

SVC BKPT fora de depuração (i.e. não conectado ao IAR) erro de acesso a memória (erro de barramento) em LD

ou ST tentativa de execução em área XN tentativa de execução causando erro de barramento erro de barramento em acesso ao vector_table tentativa de execução de instrução inválida tentativa de execução em modo ARM (T=0) LD ou ST desalinhado

© Prof. Dr. Douglas Renaux

Page 178: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Hard Faults

© Prof. Dr. Douglas Renaux

Page 179: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Módulo 8

ATPCS

© Prof. Dr. Douglas Renaux

Page 180: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ATPCSARM-Thumb Procedure Call Std

Passagem de parâmetros:- primeiros parâmetros em R0 .. R3

demais parâmetros pela pilha- retorno: R0 ou R1:R0

© Prof. Dr. Douglas Renaux

Page 181: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ATPCS – Tipos de Dados

Tipo Tamanho Tipo Tamanhochar 8 bits [ ] 32 bitsshort 16 bits struct ptr = 32 bitsint 32 bits float 32 bitsunsigned 32 bits double 64 bitslong 32 bits enum = intlong long 64 bits* 32 bits

© Prof. Dr. Douglas Renaux

Page 182: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

ATPCSQuem tem a obrigação de salvar o valor dos

registradores caso interesse manter estevalor após a chamada de uma função ?

- rotina chamada: deve salvar R4 – R11 antesde alterar

- R0 – R3,R12 podem ser livrementeutilizados pela rotina chamada

© Prof. Dr. Douglas Renaux

Page 183: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Código de Entrada e Saída deFunção

PUSH {R4-R7,LR}

…POP {R4-R7,LR}

MOV PC,LR

PUSH {R4-R7,LR}

…POP {R4-R7,PC}

© Prof. Dr. Douglas Renaux

Page 184: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Exercício – continuação MDC2) Como transformar em subrotina ?3) Como chamar a partir de outra rotina em

assembly ?4) Como chamar a partir de uma função em C ?

© Prof. Dr. Douglas Renaux

Page 185: EL68E Sistemas Embarcados - DAINFdouglas/EL68E_Cortex2015.pdf · Transistor count Date of introductio n Manufactu rer Process Area Intel 4004 2,300 1971 Intel 10 µm 12 mm² Intel

Exercício de AlinhamentoC:struct s {

char a;short b;char c;int d;

};

#pragma pack(2)#pragma pack() © Prof. Dr. Douglas Renaux