About the SPEC file

This document discusses the spec file.


Overall Structure

The spec file is a file which contains various segment arrangement information used when linking object files. There is a specific format for this file, but since it is also processed by the C language pre-processor, the C command #define can be used as a constant declaration.

When sharing constant declarations, such as the header file for the C source program, etc., it is effective to discriminate them by defining the symbol '_LANGUAGE_C'. In other words, when run through the pre-processor as the header of a C source file, you would make it so that a conditional branching section was read in which _LANGUAGE_C was defined.

The spec file comprises a segment list and a wave list. Normally, it is configured so that the segments are defined and then the waves are defined, as follows.

Segment List section
Wave List section


Segment List

The segment list contains segments which are noted, sandwiched between `beginseg` and `endseg`. A sample segment is given below.

          beginseg
		name	"program"
		flags	BOOT OBJECT
		entry	mainproc
		stack	mainThreadStack + 0x1000
		include	"rotate.o"
	endseg

Information pertaining to the segment is listed between `beginseg` and `endseg`. The following kinds of statements can be used here.

  1. name

    This defines the name of the segment. This name is used when a segment is specified in wave data, and when indicating the names of variables for data concerning the segment in C programs. (Example: The start address for a segment called ABC would be _ABCSegmentStart.)

  2. address

    This indicates the (actual) start address for the OBJECT segment. Unlike `number`, `address` prioritizes the segments to be run by the CPU.

  3. after

    This indicates the (actual) start address for the OBJECT segment. This arranges the segment after the other segments specified by `after`.

  4. after max

    This arranges the segment after the larger of the addresses among the two segments.

  5. after min

    This arranges the segment after the smaller of the addresses among the two segments.

  6. include

    This specifies the file to be included in the segment. If the segment will trip the OBJECT flag, the file must be an ELF file.

  7. maxsite

    This lists the size limit for the segment.

  8. align

    This places the segment in a byte boundary array. The default is alignment on a 16-byte boundary.

  9. flags

    This indicates the various information in the segment as flags. OBJECT is configured as an ELF file object. RAW is all of the data which hasn't been interpreted by the processor. The segment that will trip the BOOT flag must be the first segment.

  10. number

    This indicates the (actual) start address of the OBJECT segment. Unlike `address`, `number` lists the segment number, and is for segments which are intended to prioritize access to the RSP.

  11. entry

    This is the symbol name of the function to which the right of next execution is shifted immediately after the rom image has read the gload command. The function is a void function, regardless of the argument.

  12. stack or symbol name + constant

    This indicates the start position of the stack address in the boot code.

Wave List

The wave list is a list in which the waves are noted, sandwiched between `beginwave` and `endwave`.

beginwave
	name	"rotate"
	include	"program"
	include	"static"
endwave

There are two types of statements in a wave list, shown below.

  1. name

    The name defined here will be used as the filename for the ELF object.

  2. include

    The specified segment will be included in the wave. The definition of the segment must be placed before of this.


Example

The following spec file is one for a program comprising two segments called the program segment and the static segment.

beginseg
	name	"program"
	flags	BOOT OBJECT
	entry	mainproc
	stack	mainThreadStack + 0x1000
	include	"rotate.o"
endseg

beginseg
	name	"static"
	flags	OBJECT
	number	1
	include	"square.o"
endseg

beginwave
	name	"rotate"
	include	"program"
	include	"static"
endwave

Since the BOOT flag is tripped by the first program segment, this becomes the boot segment. since the OBJECT flag has been tripped, this segment will read a relocatable ELF object. As indicated by include, rotate.o is the object that comprises the segment.

Since entry specifies mainproc, the right of execution shifts first to the void function mainproc(void) when the program is executed. As specified by the stack statement, the mainThreadStack address+0x1000 is the start address for the stack area.

Since the number of the static segment is 1, this No. 1 segment will be given priority for access from the RSP. This segment comprises the relocatable ELF object square.o.

The ELF object which is ultimately created will be called rotate and will consist of the program segment and the static segment.


Appendix

As its name implies, a pre-processor processes macros and constant definitions, etc. for languages in a mechanism (processor) that performs processing that should be executed before (pre) other certain processing.

It is referred to as a C object. As for ELF objects, ELF is an acronym for the Executable and Linking Format required during execution, and since object files of this format are structures which allow dynamic linking between ELF-compatible library files, the size of the object itself can be somewhat small.