Sie sind auf Seite 1von 23

The GNU ARM Assembler

YoonMo Yeon
2007. 7. 5.
Contents

• Assembler’s Syntax
• Comments
• Symbol and Labels
• Code Sections and Section Directives

• Analysis of Cstartup.s
Comments

• C-style comments
• delimited by /* and */
• Single-line comments (target-dependent)
• @ ARM
• ; AMD29K, ARC, PA-RISC, picoJava,
PowerPC, M880x0
• ! Hitachi(H8 and SuperH), SPARC, Z8000
• | Motorola 680x0
• # Intel x86, i960, VAX, V850
Symbols and Labels

• Definition
• symbolname = value
• label:
• Period(‘.’)
• represents the current value of the location
counter
• label: syntax is identical to label=.
• . = . + 16
• . = 0x2000
Symbols and Labels

• Local label (not recommended)


• 7: b 5f a: b c
10: b 7f b: b d
5: b 10b c: b b
7: b 5b d: b c
• Re-defined and undefined labels
• re-define : the first definition overrides all
subsequent definitions
• undefine : assembler leaves linker to
determine the value of the symbol at link time
Code Sections

• Projects are dived into sections


• to ensure that specific pieces of code go into
the right area of memory
• particularly important in embedded systems
• different memory areas have different
characteristics (ROM, flash, RAM, fast on-chip
SRAM, etc.)
• Linker scripts cover more detail about this
later
Code Sections

• Default sections
• .text
• typically containing code and read-only data
• stored in read-only memory or write-protected
with MMU
• .data
• read/write variables
• .bss
• uninitialized variables
Section Directives

• .section name, ”flags”, type, @entsize

• flags
• a - allocatable
• w - writable
• x - executable
• M - mergeable
• S - contains zero-terminated strings
Section Directives

• type
• @progbits or @nobits

• entsize
• if flag M is specified, then the entsize must be
specified
• if flag S is specified, the section contains entsize
bytes long characters
• if flag S is not specified, the section contains
fixed entsize bytes long constants
Analysis of Cstartup.s

• .extern
• similar to C ‘extern’
directive
• .global
• can be referenced by
external modules
• .text
• indicates text section
• .code
• ARM instructions are
32bit(word)
Analysis of Cstartup.s

• .align boundary, fill, max-skip


• aligns the location counter to a 2boundary-byte
boundary
• fill – fill pattern
• if alignment would require more than max-
skip bytes of padding, no alignment is
performed
Analysis of Cstartup.s

• .set
• .equ
Analysis of Cstartup.s

• ARM Program Status Register


• 1 CPSR + 6 SPSR

• I(b7) : IRQ Disable


• F(b6 ) : FIQ Disable
• C(b4 ~ b0) : CPU mode
Analysis of Cstartup.s
Analysis of Cstartup.s

• Stack Setup
• load the end of stack

• change CPU mode to Undefined mode


and set its stack pointer

• move stack reference up by stack size


Analysis of Cstartup.s

• Repeat this process for each CPU mode


(Abort, FIQ, IRQ, Supervisor and System)

• After stack setup, call Cstartup in


supervisor mode
Analysis of Cstartup.s
Analysis of Cstartup.s
Analysis of Cstartup.s

• Start of main()

• Return point from main()


Analysis of Cstartup.s

• section boundaries
• defined in ld script

• begin/end
of .bss, .data, stack
Analysis of Cstartup.s

• Vector table
Analysis of Cstartup.s
End of Presentation

• Q&A

Das könnte Ihnen auch gefallen