This section is about the internals of the msp430.asm module. It may be interesting for developers that work on this module or who are interested in using the functions the module provides in their own code.
The file format of .o4 files is a bit unusual. It actually contains something that could be labeled as (specialized) Forth code. So the linker is some sort of Forth interpreter. This has the advantage that the object files can be debugged without any special tools, just a text editor. It also makes the format quite universal; it could produce binaries for all sorts of CPUs (single special case: the directive JMP is MSP430 specific).
A list of supported words can be found in the following document:
For more details also take a look at the sources of ld.py.
MCU memory definitions can be provided in a file with Forth like syntax.
A list of supported words can be found in the following document:
For more details also take a look at the sources of mcu_definition_parser.py.
This module implements the MSP430(X) assembler. When the module is executed (e.g. using python -m msp430.asm.as), it acts as a command line tool.
Parameters: |
|
---|
Create an instance of the assembler.
Parameters: |
|
---|
This method takes assembler source and transforms it to object code that can be forwarded to the linker.
This module implements the linker. When the module is executed (e.g. using python -m msp430.asm.ld), it acts as a command line tool.
Parameters: |
|
---|---|
Raises KeyError: | |
when no segment with given name is found |
Easy access to subsegment by name.
Parameters: |
|
---|
Sort list of subsegments either by order of definition or by order of start address.
Clear data. Recursively with all subsegments. Segments are not removed, just their data.
Get the number of data bytes contained in the segment.
Compare function that allows to sort segments by their start_address.
Compare function that allows to sort segments by their start_address.
Parameters: |
|
---|
Output segment and subsegments.
Modify start- and end_address of segment to fit the data that it contains. Recursively applied to the tree of segments. Typically called with address=None.
Parameters: |
|
---|
Write one byte.
Parameters: |
|
---|
Write two bytes. Order in memory depends on endianness of segment.
Parameters: |
|
---|
Write four bytes. Order in memory depends on endianness of segment.
Parameters: |
|
---|
Initialize a linker instance. The given instructions are essentially what is read from a .o4 file as sequence of words.
Parameters: |
|
---|
This sets the memory map used for linking. See mcu_definition_parser for a way to load this description.
Called before writing the final output. In case the memory map contains segments that mirror the contents of other segments, they are updated. This is typically used for .data_init which contains the initial values that are copied by startup code to the .data segment in RAM.
Run the linkers 1st pass. It iterates through the instructions and places the data into segments.
Run the linkers 2nd pass. It iterates through the instructions and finds all the labels and saves their position.
Run the linkers 3rd pass. It iterates through the instructions and creates the final binary with all known labels set to their target address.
This module implements the preprocessor. When the module is executed (e.g. using python -m msp430.asm.cpp), it acts as a command line tool.
Given an iterator for lines, yield lines. It joins consecutive lines with the continuation marker (\\) to a single line.
This object is used by the preprocessor to write out the preprocessed text. It adds notes in the form #line <line> "<filename>". These notes are used by the assembler to know where a source line originally came from (as preprocessed text may contain additional lines etc.)
Parameters: |
|
---|
Parameters: |
|
---|
Parameters: |
|
---|
This runs the preprocessor over the given input.
Exception object raised when errors during preprocessing occur.
This module implements the disassembler. When the module is executed (e.g. using python -m msp430.asm.disassemble), it acts as a command line tool.
Parameters: |
|
---|
Initialize the disassembler with data.
Parameters: |
|
---|
Run the disassembler, result is written to output.
This module implements the an RPN calculator. The calculator can be tested by executing the module (e.g. using python -m msp430.asm.rpn).
This class is used to wrap words so that their source location can be tracked. This is useful for error messages.
Parameters: |
|
---|
Create new instance with a word that was read from given location.
An RPN calculator. It provides a data stack and implements a number of basic operations (arithmetical and stack)
Parameters: |
|
---|
Interpret a sequence of words given by the iterator next_word.
Create an generator for Word, all annotated with the given information.
Parameters: |
|
---|
Create a generator for annotated Word in string (splitlines() is used).
Parameters: |
|
---|
Create a generator for annotated Word read from file given by name.
Parameters: |
|
---|---|
Returns: | A Python function. |
Return a wrapper - a function that evaluates the given RPN code when called. This can be used to insert functions implemented as RPN into the name space.
Function decorator used to tag methods that will be visible in the RPN built-in name space.
Parameters: |
|
---|---|
Returns: | The top element from the stack |
Evaluate sequence of words.
Parameters: |
|
---|---|
Returns: | A python function that executes code when called. |
Create a Python function that will execute given code when called. All parameters given to the Python function will be placed on the stack and the top of stack will be returned.
Run an interactive loop. Can be used as calculator.
This module implements a parser for a file format describing the peripherals and their bits of a MCU. The module can be executed (e.g. using python -m msp430.asm.peripherals) to test definition files.
This class implements the parser and keeps the result. It inherits from RPN.
Parameters: |
|
---|---|
Returns: | instance of SymbolDefinitions |
Load definitions from a file of given name.
Parameters: |
|
---|---|
Returns: | instance of SymbolDefinitions |
This tries to load internal data (using pkgutil).
Exception object used for errors in the definition file.
This module implements the a parser for files describing the memory map of a CPU. The module can be executed (e.g. using python -m msp430.asm.mcu_definition_parser) to test definition files.
This class implements the parser and keeps the result. It inherits from msp430.asm.rpn.RPN. Loaded definitions may contain the memory maps of many MCUs and also partial maps (that may depend on each other).
Parameters: |
|
---|---|
Returns: | instance of MCUDefintitions |
Returns: | instance of MCUDefintitions |
---|
Load internal list. The default list is included in msp430/asm/definitions/msp430-mcu-list.txt
Parameters: |
|
---|---|
Returns: | Dictionary with recursively expanded memory map. |
Return the memory map of a specific MCU. If the definition depends on others, it is expanded so that a single, complete description is returned.
This module implements a converter that can translate infix (arithmetical) notation to postfix notation (RPN). It is used by the preprocessor and assembler when evaluating expressions.
Parameters: |
|
---|---|
Returns: | A string with the expression in postfix notation. |
Parameters: |
|
---|---|
Returns: | A dictionary mapping operators to priorities. |
Input will look like this:
default_precedence_list = [
# lowest precedence
['or'],
['and'],
['not'],
['<', '<=', '>', '>=', '==', '!='],
['|', '^', '&'],
['<<', '>>'],
['+', '-'],
['*', '/', '%'],
['~', 'neg', '0 +'],
['(', ')'],
# highest precedence
]