Assembly Programming Manual
The XMOS assembly language supports the formation of objects in the
Executable and Linkable Format
(ELF)
with DWARF 3
debugging information.
Extensions to the ELF format are documented in the XMOS Application
Binary Interface
.
Lexical Conventions
There are six classes of tokens: symbol names, directives, constants,
operators, instruction mnemonics and other separators. Blanks, tabs,
formfeeds and comments are ignored except as they separate tokens.
Comments
The character # introduces a comment, which terminates with a
newline. Comments do not occur within string literals.
Symbol Names
A symbol name begins with a letter or with one of the characters
‘.‘, ‘_‘ or ‘$‘, followed by an optional sequence of letters,
digits, periods, underscores and dollar signs. Upper and lower case
letters are different.
Directives
A directive begins with ‘.‘ followed by one or more letters.
Directives instruct the assembler to perform some action (see Directives
).
Constants
A constant is either an integer number, a character constant or a string
literal.
- A binary integer is 0b or 0B followed by zero or more of the
digits 01. - An octal integer is 0 followed by zero or more of the digits
01234567. - A decimal integer is a non-zero digit followed by zero or more of the
digits 0123456789. - A hexadecimal integer is 0x or 0X followed by one or more of
the digits and letters 0123456789abcdefABCDEF. - A character constant is a sequence of characters surrounded by single
quotes. - A string literal is a sequence of characters surrounded by double
quotes.
The C escape sequences may be used to specify certain characters.
Sections and Relocations
Named ELF sections are specified using directives (see section, pushsection, popsection
).
In addition, there is a unique
unnamed “absolute” section and a unique unnamed “undefined” section. The
notation {secname X} refers to an “offset X into section secname.”
The values of symbols in the absolute section are unaffected by
relocations. For example, address {absolute 0} is “relocated” to
run-time address 0. The values of symbols in the undefined section are
not set.
The assembler keeps track of the current section. Initially the current
section is set to the text section. Directives can be used to change the
current section. Assembly instructions and directives which allocate
storage are emitted in the current section. For each section, the
assembler maintains a location counter which holds the current offset in
the section. The active location counter refers to the location
counter for the current section.
Symbols
Each symbol has exactly one name; each name in an assembly program
refers to exactly one symbol. A local symbol is any symbol beginning
with the characters “.L”. A local symbol may be discarded by the
linker when no longer required for linking.
Attributes
Each symbol has a value, an associated section and a binding. A
symbol is assigned a value using the set or linkset directives
(see set, linkset
), or through its use in a label (see Labels
).
The default binding of symbols in the undefined
section is global; for all other symbols the default binding is
local.
Labels
A label is a symbol name immediately followed by a colon (:). The
symbol’s value is set to the current value of the active location
counter. The symbol’s section is set to the current section. A symbol
name must not appear in more than one label.
Expressions
An expression specifies an address or value. The result of an expression
must be an absolute number or an offset into a particular section. An
expression is a constant expression if all of its symbols are defined
and it evaluates to a constant. An expression is a simple expression if
it is one of a constant expression, a symbol, or a symbol ± a constant.
An expression may be encoded in the ELF-extended expression section and
its value evaluated by the linker (see set, linkset
);
the encoding scheme is determined by the ABI. The syntax of an
expression is:
expression | ::= | unary-exp |
---|---|---|
| | expression infix-op unary-exp | |
| | unary-exp ? unary-exp $: unary-exp |
|
| | function-exp | |
unary-exp | ::= | argument |
| | prefix-op unary-exp | |
argument | ::= | symbol |
| | constant | |
| | ( expression ) |
|
function-exp | ::= | $overlay_region_ptr ( symbol ) |
| | $overlay_index ( symbol ) |
|
| | $overlay_physical_addr ( symbol ) |
|
| | $overlay_virtual_addr ( symbol ) |
|
| | $overlay_num_bytes ( symbol ) |
|
infix-op | ::= | one of |
+ - < > <= >= || << >> * $M $A & / |
||
prefix-op | ::= | one of |
- ~ $D |
||
Symbols are evaluated to {section x} where section is one of a
named section, the absolute section or the undefined section, and x is
a signed 2’s complement 32-bit integer.
Infix operators have the same precedence and behavior as C, and
operators with equal precedence are performed left to right. In
addition, the $M operator has lowest precedence, and the $A
operator has the highest precedence.
For the + and - operators, the set of valid operations and
results is given in the table below.
For the $D operator, the argument must be a symbol; the result is
1 if the symbol is defined and 0 otherwise.
Op |
Left Operand |
Right Operand |
Result |
---|---|---|---|
+ |
{section x} |
{absolute y} |
{section x+y} |
+ |
{absolute x} |
{section y} |
{section x+y} |
+ |
{absolute x} |
{absolute y} |
{absolute x+y} |
- |
{section x} |
{section y} |
{absolute x-y} |
- |
{section x} |
{absolute y} |
{section x-y} |
- |
{absolute x} |
{absolute y} |
{absolute x-y} |
The ? operator is used to select between symbols: if the first
operand is non-zero then the result is the second operand, otherwise the
result is the third operand.
The operators $overlay_region_ptr, $overlay_index,
$overlay_physical_addr, $overlay_virtual_addr and $overlay_num_bytes
can be used to query properties of the overlay containing the overlay roots
with the specified overlay key symbol (see Overlay Directives
).
The set of results of these operators is given in
the table below.
Operator |
Result |
---|---|
$overlay_region_ptr |
Virtual address of the overlay region containing the overlay. |
$overlay_index |
Index of the overlay in the overlay region. |
$overlay_physical_addr |
Physical address of the overlay. |
$overlay_virtual_addr |
Virtual (runtime) address of the overlay. |
$overlay_num_bytes |
Size of the overlay in bytes. |
For all other operators, both arguments must be absolute and the result
is absolute. The $M operator returns the maximum of the two operands
and the $A operator returns the value of the first operand aligned
to the second.
Wherever an absolute expression is required, if omitted then {absolute
0} is assumed.
Directives
Directives instruct the assembler to perform some action. The supported
directives are given in this section.
add_to_set
The add_to_set directive adds an expression to a set of expressions
associated with a key symbol. Its syntax is:
add-to-set-directive | ::= | .add_to_set symbol , expression |
---|---|---|
| | .add_to_set symbol , expression , symbol |
|
An optional predicate symbol may be specified as the 3rd argument. If this
argument is specified the expression will only be added to the set if the
predicate symbol is not eliminated from the linked object.
max_reduce, sum_reduce
The max_reduce directive computes the maximum of the values of the
expressions in a set. The sum_reduce directive computes the sum of the
values of the expressions in a set.
max-reduce-directive | ::= | .max_reduce symbol , symbol , expression
|
---|---|---|
sum-reduce-directive | ::= | .sum_reduce symbol , symbol , expression |
The first symbol is defined using the value computed by the directive.
The second symbol is the key symbol identifying the set of expressions (see
add_to_set
). The expression specifies the initial
value for the reduction operation.
align
The align directive pads the active location counter section to the
specified storage boundary. Its syntax is:
align-directive | ::= | .align expression |
---|---|---|
The expression must be a constant expression; its value must be a power
of 2. This value specifies the alignment required in bytes.
ascii, asciiz
The ascii directive assembles each string into consecutive
addresses. The asciiz directive is the same, except that each string
is followed by a null byte.
ascii-directive | ::= | .ascii string-list |
---|---|---|
| | .asciiz string-list |
|
string-list | ::= | string-list , string |
| | .asciiz string |
|
byte, short, int, long, word
These directives emit, for each expression, a number that at run-time is
the value of that expression. The byte order is determined by the
endianness of the target architecture. The size of numbers emitted with
the word directive is determined by the size of the natural word on the
target architecture. The size of the numbers emitted using the other
directives are determined by the sizes of corresponding types in the
ABI.
value-directive | ::= | value-size exp-list |
---|---|---|
value-size | ::= | .byte |
| | .short |
|
| | .int |
|
| | .long |
|
| | .word |
|
exp-list | ::= | exp-list , expression |
| | expression | |
file
The file directive has two forms.
file-directive | ::= | .file string |
---|---|---|
| | .file constant string |
|
When used with one argument, the file directive creates an ELF
symbol table entry with type STT_FILE and the specified string
value. This entry is guaranteed to be the first entry in the symbol
table.
When used with two arguments the file directive adds an entry to the
DWARF 3 .debug_line file names table. The first argument is a unique
positive integer to use as the index of the entry in the table. The
second argument is the name of the file.
loc
The .loc directive adds a row to the DWARF 3
.debug_line line number matrix.
loc-directive | ::= | constant constant constantopt |
---|---|---|
| | constant constant constant 〈loc-option〉* | |
loc-option | ::= | basic_block |
| | prologue_end |
|
| | epilogue_begin |
|
| | is_stmt constant |
|
| | isa constant |
|
The address register is set to active location counter. The first two
arguments set the file and line registers respectively. The optional
third argument sets the column register. Additional arguments set
further registers in the .debug_line state machine.
- basic_block
-
Sets basic_block to true.
- prologue_end
-
Sets prologue_end to true.
- epilogue_begin
-
Sets epilogue_begin to true.
- is_stmt
-
Sets is_stmt to the specified value, which must be 0 or 1.
- isa
-
Sets isa to the specified value.
weak
The weak directive sets the weak attribute on the specified symbol.
weak-directive | ::= | .weak symbol |
---|---|---|
globl, global, extern, locl, local
The globl directive makes the specified symbols visible to other
objects during linking. The extern directive specifies that the
symbol is defined in another object. The locl directive specifies a
symbol has local binding.
visibility | ::= | .globl |
---|---|---|
| | .extern |
|
| | .locl |
|
| | .global |
|
| | .extern |
|
| | .local |
|
vis-directive | ::= | visibility symbol |
| | visibility symbol , string |
|
If the optional string is provided, an SHT_TYPEINFO entry is created
in the ELF-extended type section which contains the symbol and an index
into the string table whose entry contains the specified string. (If the
string does not already exist in the string table, it is inserted.) The
meaning of this string is determined by the ABI.
The global and local directives are synonyms for the globl
and locl directives. They are provided for compatibility with other
assemblers.
globalresource
globalresource-directive | ::= | .globalresource expression , string |
---|---|---|
| | .globalresource expression , string , string |
|
The globalresource directive causes the assembler to add information to the
binary to indicate that there was a global port or clock declaration. The first
argument is the resource ID of the port. The second argument is the name of the
variable. The optional third argument is the tile the port was declared on. For
example:
.globalresource 0x10200, p, tile[0]
specifies that the port p was declared on tile[0] and initialized with the resource ID 0x10200.
typestring
The typestring adds an SHT_TYPEINFO entry in the ELF-extended type
section which contains the symbol and an index into the string table whose entry
contains the specified string. (If the string does not already exist in the
string table, it is inserted.) The meaning of this string is determined by the
ABI.
typestring-directive | ::= | .typestring symbol , string |
---|---|---|
ident, core, corerev
Each of these directives creates an ELF note section named
“.xmos_note.”
info-directive | ::= | .ident string |
---|---|---|
| | .core string |
|
| | .corerev string |
|
The contents of this section is a (name, type, value) triplet: the name
is xmos; the type is either IDENT, CORE or COREREV; and
the value is the specified string.
section, pushsection, popsection
The section directives change the current ELF section (see Sections and Relocations
).
section-directive | ::= | sec-or-push name |
---|---|---|
| | sec-or-push name , flags sec-typeopt |
|
| | .popsection |
|
sec-or-push | ::= | .section |
| | .pushsection |
|
flags | ::= | string |
sec-type | ::= | type |
| | type , flag-args |
|
type | ::= | @progbits |
| | @nobits |
|
flag-args | ::= | string |
The code following a section or pushsection directive is
assembled and appended to the named section. The optional flags may
contain any combination of the following characters.
a |
section is allocatable |
c |
section is placed in the global constant pool |
d |
section is placed in the global data region |
w |
section is writable |
x |
section is executable |
M |
section is mergeable |
S |
section contains zero terminated strings |
The optional type argument progbits specifies that the section
contains data; nobits specifies that it does not.
If the M symbol is specified as a flag, a type argument must be
specified and an integer must be provided as a flag-specific argument.
The flag-specific argument represents the entity size of data entries in
the section. For example:
.section .cp.const4, "M", @progbits, 4
Sections with the M flag but not S flag must contain fixed-size
constants, each flag-args bytes long. Sections with both the M and
S flags must contain zero-terminated strings, each character
flag-args bytes long. The linker may remove duplicates within sections
with the same name, entity size and flags.
Each section with the same name must have the same type and flags. The
section directive replaces the current section with the named
section. The pushsection directive pushes the current section onto
the top of a section stack and then replaces the current section with
the named section. The popsection directive replaces the current
section with the section on top of the section stack and then pops this
section from the stack.
text
The text directive changes the current ELF section to the .text
section. The section type and attributes are determined by the ABI.
text-directive | ::= | .text |
---|---|---|
set, linkset
A symbol is assigned a value using the set or linkset directive.
set-directive | ::= | set-type symbol , expression |
---|---|---|
set-type | ::= | .set |
| | .linkset |
|
The set directive defines the named symbol with the value of the
expression. The expression must be either a constant or a symbol: if the
expression is a constant, the symbol is defined in the absolute section;
if the expression is a symbol, the defined symbol inherits its section
information and other attributes from this symbol.
The linkset directive is the same, except that the expression is not
evaluated; instead one or more SHT_EXPR entries are created in the
ELF-extended expression section which together form a tree
representation of the expression.
Any symbol used in the assembly code may be a target of an SHT_EXPR
entry, in which case its value is computed by the linker by evaluating
the expression once values for all other symbols in the expression are
known. This may happen at any incremental link stage; once the value is
known, it is assigned to the symbol as with set and the expression entry
is eliminated from the linked object.
cc_top, cc_bottom
The cc_top and cc_bottom directives are used to mark the
beginning and end of elimination blocks.
cc-top-directive | ::= | .cc_top name , predicate |
---|---|---|
| | .cc_top name |
|
cc-directive | ::= | cc-top-directive |
| | .cc_bottom name |
|
name | ::= | symbol |
predicate | ::= | symbol |
cc_top and cc_bottom directives with the same name refer to the
same elimination block. An elimination block must have precisely one
cc_top directive and one cc_bottom directive. The top and bottom
of an elimination block must be in the same section. The elimination
block consists of the data and labels in this section between the
cc_top and cc_bottom directives. Elimination blocks must be
disjoint; it is illegal for elimination blocks to overlap.
An elimination block is retained in final executable if one of the following
is true:
- A label inside the elimination block is referenced from a location
outside an elimination block.- A label inside the elimination block is referenced from an elimination
block which is not eliminated- The predicate symbol is defined outside an elimination block or
is contained in an elimination block which is not eliminated.
If none of these conditions are true the elimination block is removed from
the final executable.
scheduling
The scheduling directive enables or disables instruction scheduling.
When scheduling is enabled, the assembler may reorder instructions to
minimize the number of FNOPs. The default scheduling mode is determined
by the command-line option -fschedule
.
scheduling-directive | ::= | .scheduling scheduling-mode |
---|---|---|
scheduling-mode | ::= | on |
| | off |
|
| | default |
|
issue_mode
The issue_mode directive changes the current issue mode assumed by the
assembler. See Instructions
for details of how the issue mode
affects how instructions are assembled.
issue-mode-directive | ::= | issue_mode issue-mode |
---|---|---|
issue-mode | ::= | single |
| | dual |
|
syntax
The syntax directive changes the current syntax mode. See
Instructions
for details of how assembly instructions
are specified in each mode.
syntax-directive | ::= | .syntax syntax |
---|---|---|
syntax | ::= | default |
| | architectural |
|
assert
assert-directive | ::= | .assert constant , symbol , string |
---|---|---|
The assert directive requires an assertion to be tested prior to
generating an executable object: the assertion fails if the symbol has a
non-zero value. If the constant is 0, a failure should be reported as a
warning; if the constant is 1, a failure should be reported as an error.
The string is a message for an assembler or linker to emit on failure.
Overlay Directives
The overlay directives control how code and data is partitioned into overlays
that are loaded on demand at runtime.
overlay-directive | ::= | .overlay_reference symbol , symbol |
---|---|---|
| | .overlay_root symbol , symbol |
|
| | .overlay_root symbol |
|
| | .overlay_subgraph_conflict sym-list |
|
sym-list | ::= | sym-list , symbol |
| | symbol | |
- The overlay_root directive specifies that the first symbol should be
treated as an overlay root. The optional second symbols specifies a overlay
key symbol. If no overlay key symbol is explictly specified the overlay root
symbol is used as the key symbol. Specifying the same overlay key symbol for
multiple overlay roots forces the overlay roots into the same overlay. - The overlay_reference directive specifies that linker should assume that
there is a reference from the first symbol to the second symbol when
it partitions the program into overlays. - The overlay_subgraph_conflict directive specifies that linker should not
place any code or data reachable from one the symbols into an overlay that is
mapped an overlay region that contains another overlay containing code or data
reachable from one of the other symbols.
Language Directives
The language directives create entries in the ELF-extended expression
section; the encoding is determined by the ABI.
xc-directive | ::= | globdir symbol , string |
---|---|---|
| | globdir symbol , symbol , range-args , string |
|
| | .globpassesref symbol , symbol , string |
|
| | .call symbol , symbol |
|
| | .par symbol , symbol , string |
|
range-args | ::= | expression , expression |
globdir | ::= | .globread |
| | .globwrite |
|
| | .parwrite |
|
| | .globpassesref |
|
For each directive, the string is an error message for the assembler or
linker to display on encountering an error attributed to the directive.
- call
-
Both symbols must have function type. This directive sets the property that
the first function may make a call to the second function. - par
-
Both symbols must have function type. This directive sets the property
that the first function is invoked in parallel with the second function. - globread
-
The first symbol must have function type and the second directive must
have object type. This directive sets the property that the function may
read the object. When a range is specified, the first expression is the
offset from the start of the variable in bytes of the address which is
read and the second expression is the size of the read in bytes. - globwrite
-
The first symbol must have function type and the second directive must
have object type. This directive sets the property that the function may
write the object. When a range is specified, the first expression is the
offset from the start of the variable in bytes of the address which is
written and the second expression is the size of the write in bytes. - parwrite
-
The first symbol must have function type and the second directive must have
object type. This directive set the property that the function is called in
an expression which writes to the object where the order of evalulation of
the write and the function call is undefined. When a range is specified, the
first expression is the offset from the start of the variable in bytes of
the address which is written and the second expression is the size of the
write in bytes. - globpassesref
-
The first symbol must have function type and the second directive must have
object type. This directive sets the property that the object may be passed
by reference to the function.
XMOS Timing Analyzer Directives
The XMOS Timing Analyzer directives add timing metadata to ELF sections.
xta-directive | ::= | .xtabranch exp-listopt |
---|---|---|
| | .xtaendpoint string , source-location |
|
| | .xtacall string , source-location |
|
| | .xtalabel string , source-location |
|
| | .xtathreadstart |
|
| | .xtathreadstop |
|
| | .xtaloop constant |
|
| | .xtacommand string , source-location |
|
source-location | ::= | string , string , constant |
The first string of a source location is the compilation directory. The
second string is the path to the file. The path may be specified as
either a relative path from the compilation directory or as an absolute
path. The third argument is the line number.
- xtabranch specifies a comma-separated list of locations that may
be branched to from the current location. - xtaendpoint marks the current location as an endpoint with the
specified label. - xtacall marks the current location as a function call with the
specified label. - xtalabel marks the current location using the specified label.
- xtathreadstart apecifies that a thread may be initialized to
start executing at the current location. - xtathreadstop specifies that a thread executing the instruction
at the current location will not execute any further instructions. - xtaloop specifies that the innermost loop containing the current
location executes the specified number of times. - xtacommand specifies an XTA command to be executed when analyzing
the executable.
uleb128, sleb128
The following directives emit, for each expression in the
comma-separated list of expressions, a value that encodes either an
unsigned or signed DWARF little-endian base 128 number.
leb-directive | ::= | .uleb128 exp-list |
---|---|---|
| | .sleb128 exp-list |
|
space, skip
The space directive emits a sequence of bytes, specified by the
first expression, each with the fill value specified by the second
expression. Both expressions must be constant expressions.
space-or-skip | ::= | .space |
---|---|---|
| | .skip |
|
space-directive | ::= | space-or-skip expression |
| | space-or-skip expression , expression |
|
The skip directive is a synonym for the space directive. It is
provided for compatibility with other assemblers.
type
The type directive specifies the type of a symbol to be either a
function symbol or an object symbol.
type-directive | ::= | .type symbol , symbol-type |
---|---|---|
symbol-type | ::= | @function |
| | @object |
|
size
The size directive specifies the size associated with a symbol.
size-directive | ::= | .size symbol , expression |
---|---|---|
jmptable, jmptable32
The jmptable and jmptable32 directives generate a table of
unconditional branch instructions. The target of each branch instruction
is the next label in the list. The size of the each branch instruction
is 16 bits for the jmptable directive and 32 bits for the
jmptable32 directive.
jmptable-directive | ::= | .jmptable jmptable-listopt |
---|---|---|
| | .jmptable32 jmptable-listopt |
|
jmptable-list | ::= | symbol |
| | jmptable-list symbol | |
Each symbol must be a label. A maximum of 32 labels maybe specified. If
the unconditional branch distance does not fit into a 16-bit branch
instruction, a branch is made to a trampoline at the end of the table,
which performs the branch to the target label.
Instructions
Assembly instructions are normally inserted into an ELF text section.
The syntax of an instruction is:
instruction | ::= | mnemonic instruction-argsopt |
---|---|---|
instruction-args | ::= | instruction-args , instruction-arg |
| | instruction-arg | |
instruction-arg | ::= | symbol [ expression ] |
| | symbol [ expression ] : symbol |
|
| | expression | |
To target the dual issue execution mode of xCORE-200 devices, instructions may
be put in bundles:
separator | ::= | newline |
---|---|---|
| | ; |
|
instruction-bundle | ::= | { 〈separator〉* bundle-contents 〈separator〉* } |
bundle-contents | ::= | instruction 〈separator〉+ instruction |
| | instruction | |
The current issue mode, as specifed by the issue_mode directive
(see issue_mode
), affects how the assembler assembles
instructions. Initially the current issue mode is single and instruction bundles
cannot be used. If the current issue mode is changed to dual then:
- Instruction bundles can be specified.
- 16-bit instructions not in an instruction bundle are implicitly
placed in an instruction bundle alongside a NOP instruction. - The encoding of some operands may change. For example the assembler
applies a different scaling factor to the immediate operand of relative
branch instructions to match the different scaling factor that the processor
uses at runtime when the instruction is executed in dual issue mode.
The order in which instructions are listed in an instruction bundle is not
significant. The assembler may reorder the instructions in the bundle to satisfy
architectural constraints.
The assembly instructions are summarized below using the default assembly
syntax. The architecture manual
documents the architectural
syntax of the instructions. The syntax directive is used to switch the syntax
mode.
The following notation is used:
bitp |
one of: 1, 2, 3, 4, 5, 6, 7, 8, 16, 24 and Assembly Programming Manual Read More » Add support for a new flash deviceTo support a new flash device, a configuration file must be written that The configuration file for the Numonyx 10, /* 1. libflash device ID */ 256, /* 2. Page size */ 512, /* 3. Number of pages */ 3, /* 4. Address size */ 4, /* 5. Clock divider */ 0x9f, /* 6. RDID cmd */ 0, /* 7. RDID dummy bytes */ 3, /* 8. RDID data size in bytes */ 0x202011, /* 9. RDID manufacturer ID */ 0xD8, /* 10. SE cmd */ 0, /* 11. SE full sector erase */ 0x06, /* 12. WREN cmd */ 0x04, /* 13. WRDI cmd */ PROT_TYPE_SR, /* 14. Protection type */ {{0x0c,0x0},{0,0}}, /* 15. SR protect and unprotect cmds */ 0x02, /* 16. PP cmd */ 0x0b, /* 17. READ cmd */ 1, /* 18. READ dummy bytes*/ SECTOR_LAYOUT_REGULAR, /* 19. Sector layout */ {32768,{0,{0}}}, /* 20. Sector sizes */ 0x05, /* 21. RDSR cmd*/ 0x01, /* 22. WRSR cmd */ 0x01, /* 23. WIP bit mask */ Libflash Device ID10, /* 1. libflash device ID */ This value is returned by libflash on a call to the function fl_getFlashType so that Page Size and Number of Pages10, /* 1. libflash device ID */ 256, /* 2. Page size */ These values specify the size of each page in bytes and the total number
Address Size3, /* 4. Address size */ This value specifies the number of bytes used to represent an address.
Clock Rate4, /* 5. Clock divider */ This value is used to determine the clock rate for interfacing with the The table below reproduces the part of the M25P10-A
In general, if the SPI device supports different clock rates for Read Device ID0x9f, /* 6. RDID cmd */ 0, /* 7. RDID dummy bytes */ 3, /* 8. RDID data size in bytes */ 0x202011, /* 9. RDID manufacturer ID */ Most flash devices have a hardware identifier that can be used to Table 4 on page 17 of M25P10-A datasheet
In general, if there is a choice of RDID commands then the JEDEC Sector Erase0xD8, /* 10. SE cmd */ 0, /* 11. SE full sector erase */ Most flash devices provide an instruction to erase all or part of a Table 4 on page 17 of M25P10-A datasheet
In this example the SE command erases all of the sector, so the SE data Write Enable/Disable0x06, /* 12. WREN cmd */ 0x04, /* 13. WRDI cmd */ Most flash devices provide instructions to enable and disable writes to Memory ProtectionPROT_TYPE_SR, /* 14. Protection type */ {{0x0c,0x0},{0,0}}, /* 15. SR protect and unprotect cmds */ Some flash devices provide additional protection of sectors when writes
The protection details are specified as part of a construction of the
If the device does not provide protection, all values should be set to Table 2 on page 13 of M25P10-A datasheet reproduce the parts of the M25P10-A datasheet that provide this information.
Programming Command0x02, /* 16. PP cmd */ Devices are programmed either a page at a time or a small number of Table 4 on page 17 of M25P10-A datasheet If page programming is not supported, this value is a concatenation of An example of a device without a PP command is the ESMT
The corresponding entry in the specification file is: 0x00|(0xad<<8)|(2<<16), /* No PP, have AAI for 2 bytes */ Read Data0x0b, /* 17. READ cmd */ 1, /* 18. READ dummy bytes*/ The sequence for reading data from a device is typically to issue a READ Table 4 on page 17 of M25P10-A datasheet Sector InformationSECTOR_LAYOUT_REGULAR, /* 19. Sector layout */ {32768,{0,{0}}}, /* 20. Sector sizes */ The first value specifies whether all sectors are the same size. The
On the M25P10-A datasheet, this can be found from the following
The sector sizes is specified as part of a construction: For irregular sector sizes,
The corresponding entry in the specification file is: SECTOR_LAYOUT_IRREGULAR, {0,{20,{4,4,5,6,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8}}}, Status Register Bits0x05, /* 21. RDSR cmd*/ 0x01, /* 22. WRSR cmd */ 0x01, /* 23. WIP bit mask */ Most flash devices provide instructions to read and write a status Table 4 on page 17 of M25P10-A datasheet Add Support to xTimeComposerA configuration file can be used with libflash or xflash. The example #include "platform.h" #include "flash.h" #include "flashlib.h" #include "stdio.h" #include "stdlib.h" fl_PortHolderStruct SPI = {PORT_SPI_MISO, PORT_SPI_SS, PORT_SPI_CLK, PORT_SPI_MOSI, XS1_CLKBLK_1}; fl_DeviceSpec myFlashDevices[] = { { #include "m25p10a" } }; int flash_access() { if (fl_connectToDevice(SPI, myFlashDevices, sizeof(myFlashDevices)/sizeof(fl_DeviceSpec)) != 0) { printf("No supported flash devices found.\n"); exit(1); } else { printf("Found custom flash device m25p10a.\n"); exit(0); } return 0; } int main() { // multicore main is required for xscope par { on stdcore[0] : flash_access(); } } The custom flash device must be specified in the XN file as follows: <ExternalDevices> <Device NodeId="0" Tile="0" Name="bootFlash" Class="SPIFlash" Type="M25P10A"> <Attribute Name="PORT_SPI_MISO" Value="PORT_SPI_MISO" /> <Attribute Name="PORT_SPI_SS" Value="PORT_SPI_SS" /> <Attribute Name="PORT_SPI_CLK" Value="PORT_SPI_CLK" /> <Attribute Name="PORT_SPI_MOSI" Value="PORT_SPI_MOSI" /> </Device> </ExternalDevices> To compile an image file that links to the lib flash library, and enter the following command: xcc main.xc -o prog.xe -target=target_with_custom_flash.xn -lflash To generate an image file in the xCORE flash format, which can be xflash prog.xe -o imgfile –spi-spec m25p10a XFLASH generates an image for the custom flash device, which it writes Select a Flash DeviceWhen selecting a flash device for use with an xCORE device, the following
DocumentationAdd support for a new flash device Read More » Safeguard IP and device authenticityxCORE devices contain on-chip one-time programmable (OTP) memory that can
Once the AES Module is programmed, the OTP security bits are blown,
The AES module provides a strong level of protection from casual The xCORE AES moduleThe xCORE AES Module authenticates and decrypts programs from SPI flash
The flash loader performs the following operations:
For multi-node systems, the AES Module is written to the OTP of one Develop with the AES module enabledYou can activate the AES Module at any time during development or device
In a production environment, you must protect the device to prevent the To program the AES Module into the xCORE device on your development and enter the following commands:
To encrypt your program and write it to flash memory, enter the command: xflash –id ID bin.xe –key keyfile To protect the xCORE device, preventing any further development, enter the command: xburn –id ID –target-file target.xn –disable-jtag –lock keyfile Production flash programming flowIn production manufacturing environments, the same program is typically To generate an encrypted image in the xCORE flash format, and enter the following command: xflash prog.xe -key keyfile -o image-file This image can be programmed directly into flash memory using a
The XN file must define an SPI flash device and specify the four ports Production OTP programming flowIn production manufacturing environments, the same keys are typically To generate an image that contains the AES Module and security keys to and enter the following commands:
The image contains the keys and must be kept secret. To write the AES Module and security bits to a device in a production
DocumentationSafeguard IP and device authenticity Read More » List of devices natively supported by libflashlibflash supports a wide range of flash devices available in the market.
DocumentationList of devices natively supported by libflash Read More » XBURN Command-Line ManualXBURN creates OTP images, and can program these images into the OTP memory of xCORE devices. Overall OptionsThe following options are used to specify the OTP image and security register contents.
Security Register OptionsThe following options are used to specify the contents of the OTP security register,
Target OptionsThe following options are used to specify the target hardware platform.
Programming OptionsBy default, XBURN writes the specified OTP images to the target platform.
DocumentationXBURN Command-Line Manual Read More » XSIM Command-Line ManualXSIM performs a cycle-based simulation of an XMOS Executable (XE) file. Overall Options
Warning Options
Tracing Options
Loopback Plugin OptionsThe XMOS Loopback plugin configures any two ports on the target platform
The plugin options are specified in pairs, one for each end of the xsim uart.xe –plugin LoopbackPort.dll ‘-port tile[0] XS1_PORT_1A 1 0 -port UART_TX 1 0’ xSCOPE Options
For example, the following will run xsim with xSCOPE enabled in offline mode: xsim app.xe –xscope “-offline xscope.xmt” For example, the following will run xsim with xSCOPE enabled in reatime mode: xsim app.xe –xscope “-realtime localhost:12345” XSIM Command-Line Manual Read More » Shift Register Expansion Of XS1 DevicesVERSION RELEASED COMMENTS DOWNLOAD 1.0 2011-05-12 PDF Shift Register Expansion Of XS1 Devices Read More » DFU loader for XMOS USB AUDIO devices
The DFU loader is a flash device firmware upgrade mechanism. To work correctly The firmware upgrade for XMOS USB devices implementation uses the USB standard Supported functionality:
You must use XMOS Development Tools version 10.4.1 (or later). The DFU device on Windows requires the Theyscon USB Audio 2.0 Windows driver
Installing the factory image to the deviceThe DFU device interface is enabled by default in the XMOS USB Audio framework #define DFU (1) Use the XMOS Development Tools to run the command:
This programs the factory default firmware image into the flash device. Creating the upgrade imageTo use the firmware upgrade mechanism you need to build a firmware upgrade
To generate the firmware upgrade image run the following command:
You should now have the file new_firmware.bin which contains the Related documentsFor further details of the DFU features included in the XMOS USB Audio and the Configuration Defines For further details on the use of XFLASH to create factory and upgrade firmware
Thesycon provide both GUI and CLI DFU tools, TUSBAudioDfu.exe and dfucons.exe The correct installation of the Thesycon driver and DFU tools exceeds Set up the image loaderRun the DFU console tool (dfucons.exe) from the Thesycon install folder,
To check the device has been detected, run the following command in the DFU
The console shows the DFU devices that have been detected. Download new firmwareTo program the new firmware run the command:
Note that once this is done the device restarts. The original factory default You can check the device has been updated by running the command:
This will display the device revision. Uploading existing firmware from the deviceYou can retrieve a firmware image from the device, providing an upgrade image is
The file currentfirmware.bin contains the latest upgrade image. This file is Reverting firmware to factory imageTo revert the device back to its factory (i.e XFLASH) installed state from the
The device will now be running, and only contain the factory firmware, which can Related documentsFor further details on the use of the Thesycon DFU tools please see
The XMOS DFU loader is provided as source as part of the XMOS USB Audio software Set up the image loader
Download new firmwareTo program the new firmware run the command:
Note that once this is done the device restarts. The original factory default Uploading existing firmware from the deviceYou can retrieve a firmware image from the device, providing an upgrade image is Run the command:
The file currentfirmware.bin contains the latest upgrade image. This file is Reverting firmware to factory imageTo revert the device back to its factory (i.e XFLASH) installed state from the
The device will now be running, and only contain the factory firmware.
The XMOS DFU loader is provided as source as part of the USB Audio The loader is compiled using libusb, the code for the loader is contained in the To build the loader a Makefile is provided, which can be run as follows:
This Makefile contains the following: all: g++ -g -o xmosdfu xmosdfu.cpp -I. -IOSX libusb-1.0.0.dylib -m32 DFU loader for XMOS USB AUDIO devices Read More » USB Bootloader Description and StandardsVERSION RELEASED COMMENTS DOWNLOAD 1.0 2010-09-15 PDF USB Bootloader Description and Standards Read More » XMOS USB Device (XUD) LibraryThis document details the XMOS USB Device (XUD) Library. This library This document describes the structure of the library, its basic use This document assumes familiarity with the XMOS xCORE architecture, the
The XUD library allows the implementation of both full-speed and For the L and G series the implementation requires the use of an Please note, G-series is not recommended for new designs. The library performs all the low-level I/O operations required to meet The XUD library runs in a single core with endpoint and application One channel is required per IN or OUT endpoint. Endpoint 0 (the control An example task diagram is shown in XUD Overview It is important to note that, for performance reasons, cores
The following list gives a brief description of the files that make up
The XUD library requires the resources described in the following Ports/PinsG/L-SeriesThe ports used for the physical connection to the external ULPI transceiver must
In addition some ports are used internally when the XUD library is in Please refer to the device datasheet for further information on which ports U-SeriesThe U-Series of devices have an integrated USB transceiver. Some ports
Core SpeedDue to I/O requirements, the library requires a guaranteed MIPS rate to This means that for an xCORE device running at 400MHz there should be no more This restriction is only a requirement on the tile on which the XUD_Manager is running. Clock BlocksG/L-SeriesThe XUD library uses one clock block (clock block 0) and configures this Since clock block 0 is the default for all ports when enabled it is U-SeriesThe XUD library uses two clock blocks (clock blocks 4 and 5). These are TimersThe XUD library allocates and uses four timers. MemoryThe XUD library requires about 9 Kbytes of memory, of which around 6 Kbytes
This section outlines the basic usage of XUD. Basic use is termed to XUD Core: XUD_Manager()This is the main XUD task that interfaces with the USB transceiver. This function should be called directly from the top-level par
Endpoint Type TableThe endpoint type table should take an array of XUD_EpType to inform XUD Note: endpoints can also be marked as disabled. Endpoints that are not used will NAK any traffic from the host. PwrConfigThe PwrConfig parameter to XUD_Manager() indicates if the device is bus or self-powered. Valid values for this parameter are XUD_PWR_SELF and XUD_PWR_BUS. When XUD_PWR_SELF is used, XUD_Manager() monitors the VBUS input for a valid voltage and reponds appropriately. The USB Specification states that the devices pull-ups must be disabled when a valid VBUS is not present. This is important when submitting a device for compliance testing since this is explicitly tested. If the device is bus-powered XUD_PWR_SELF can be used since is assumed that the device is not powered up when VBUS is not present and therefore no voltage monitoring is required. In this configuration the VBUS input to the device/PHY need not be present. XUD_PWR_BUS can be used in order to run on a self-powered board without provision for VBUS wiring to the PHY/device, but this is not advised. Endpoint Communication with XUD_Manager()Communication state between a core and the XUD library is encapsulated
All client calls communicating with the XUD library pass in this type.
Endpoint data is sent/received using three main functions, These assembly functions implement the low-level shared memory/channel These functions will automatically deal with any low-level complications required XUD_GetBuffer()
XUD_SetBuffer()
XUD_SetBuffer_EpMax()This function provides a similar function to XUD_SetBuffer function
XUD_DoGetRequest()
XUD_DoSetRequestStatus()
XUD_SetDevAddr()
XUD_SetStall()
XUD_SetStallByAddr()
XUD_ClearStall()
XUD_ClearStallByAddr()
Status ReportingStatus reporting on an endpoint can be enabled so that bus state is This means that endpoints are notified of USB bus resets (and This reset notification is important if an endpoint core is expecting Endpoint 0 therefore requires this functionality since it deals with This is also important for high-speed devices, since it is not After a reset notification has been received, the endpoint must call the XUD_ResetEndpoint()
SOF ChannelAn application can pass a channel-end to the c_sof parameter of USB Test ModesXUD supports the required test modes for USB Compliance testing. XUD accepts commands from the endpoint 0 channels (in or out) to signal which test mode
The passing other codes endpoints other than 0 to XUD_SetTestMode() could result in undefined As per the USB 2.0 Specification a power cycle or reboot is required to exit the test mode. XUD_SetTestMode()
Advanced usage is termed to mean the implementation of multiple endpoints in a single core as well as the addition of real-time processing to an endpoint core. The functions documented in Basic Usage such as XUD_SetBuffer() and XUD_GetBuffer() block until data has either been successfully sent or received to or from the host. For this reason it is not generally possible to handle multiple endpoints in a single core efficiently (or at all, depending on the protocols involved). The XUD library therefore provides functions to allow the separation of requesting to send/receive a packet and the notification of a successful transfer. This is based on the XC select statement language feature. General operation is as follows:
The available XUD_SetReady_ functions are listed below. XUD_SetReady_Out()
XUD_SetReady_In()
The following functions are also provided to ease integration with more complex buffering schemes than a single packet buffer. A example might be a circular-buffer for an audio stream. XUD_SetReady_OutPtr()
XUD_SetReady_InPtr()
Once an endpoint has been marked ready to send/receive by calling one of the above XUD_SetReady_ functions, an XC select statement can be used to handle notifications of a packet being sent/received from XUD_Manager(). These notifications are communicated via channels. For convenience, select handler functions are provided to handle events in the select statement. These are documented below. XUD_GetData_Select()
XUD_SetData_Select()
ExampleA simple example of the functionality described in this section is shown below: void ExampleEndpoint(chanend c_ep_out, chanend c_ep_in) { unsigned char rxBuffer[1024]; unsigned char txBuffer[] = {0, 1, 2, 3, 4}; int length, returnVal; XUD_ep ep_out = XUD_InitEp(c_ep_out); XUD_ep ep_in = XUD_InitEp(c_ep_in); /* Mark OUT endpoint as ready to receive */ XUD_SetReady_Out(ep_out, rxBuffer); XUD_SetReady_In(ep_in, txBuffer, 5); while(1) { select { case XUD_GetData_Select(c_ep_out, ep_out, length): /* Packet from host recieved */ for(int i = 0; i< length; i++) { /* Process packet... */ } /* Mark EP as ready again */ XUD_SetReady_Out(ep_out, rxBuffer); break; case XUD_SetData_Select(c_ep_in, ep_in, returnVal): /* Packet successfully sent to host */ /* Create new buffer */ for(int i = 0; i < 5; i++) { txBuffer[i]++; } /* Mark EP as ready again */ XUD_SetReady_In(ep_in, txBuffer, 5); break; } } } //:
The following documents provide further reading regarding programming USB devices on XMOS platforms:
Version history for this document.
XMOS USB Device (XUD) Library Read More » |