Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
software:deep:dev:crosscompiler:linker32 [2014-02-10 13:19] – graf | software:deep:dev:crosscompiler:linker32 [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== Linker32 ====== | ||
- | The linker32 is written for 32 bit platforms. The linker performs various tasks like: | ||
- | * Place code in the memory | ||
- | * Create type descriptors and constant blocks | ||
- | * Create system table | ||
- | * Create target image | ||
- | ===== Initialization ===== | ||
- | As a first step the linker must be initialized with the method //init()//. What happens is: | ||
- | * Determine size of // | ||
- | * Search segments for the system table | ||
- | * Delete previous target image | ||
- | |||
- | ===== Create Constant Block ===== | ||
- | Each class has a constant block. Certain interfaces need a reduced constant block and arrays just need a type descriptor, see [[.: | ||
- | * Header (base, size, ...) | ||
- | * Global pointer list | ||
- | * Type descriptor | ||
- | * String pool | ||
- | * Constant pool | ||
- | * Checksum | ||
- | [{{ .: | ||
- | The //const pool// contains values of type //float// and //double// which are not placed directly into the code. After all elements are added the // | ||
- | When the system ist starting up, the [[..: | ||
- | |||
- | In the compiler the constant block is modeled as linked list of '' | ||
- | * **'' | ||
- | * **'' | ||
- | * **'' | ||
- | * **'' | ||
- | * **'' | ||
- | * **'' | ||
- | |||
- | ==== Type Descriptor ==== | ||
- | The structure and purpose of the [[Type Descriptor]] is described separately. | ||
- | |||
- | ==== String pool ==== | ||
- | The string pool holds the constant strings of a class. They are stored as follows (also see [[strings|Strings]]: | ||
- | [ tag ] | ||
- | [ stringClassAddress ] | ||
- | [ Object | ||
- | [ nofChars | ||
- | [ chars ] | ||
- | [ ⋮ ] | ||
- | The characters of the string are stored in 2-Byte-Unicode. | ||
- | |||
- | ==== Constant Pool ==== | ||
- | The constant pool holds the constants of a class. Currently we only store there floating point numbers (//float// and // | ||
- | |||
- | **Example: | ||
- | [40490FDB] 3.1415927 (float) | ||
- | [401921FB] 6.283185307179586 (double) | ||
- | [54442D18] | ||
- | |||
- | |||
- | ===== Calculate Size and Offsets ===== | ||
- | [{{ .: | ||
- | Before the memory map can be fixed, a couple sizes and offsets must be calculated for each class: | ||
- | * '' | ||
- | * '' | ||
- | |||
- | ===== Create System Table ===== | ||
- | The linker assembles a system table for the whole system. This table must be loaded to a prefixed address in the target system and holds information for the [[..: | ||
- | - The system runs from the flash | ||
- | - The system runs from the RAM. | ||
- | - The base system is in the flash. Further classes are later loaded into the RAM. This case needs two system tables. The flash holds a system table which contains only classes which are present in the flash. The system table in the RAM must hold all classes. IMPORTANT This feature is not implemented yet IMPORTANT | ||
- | |||
- | In the compiler the system table is modeled as list. as elements it uses the same blocks as for the constant block. Additionally '' | ||
- | |||
- | The structure of the system table is: | ||
- | [{{ .: | ||
- | |||
- | First, the class constructor of the class kernel must be found. For this, the class name of the kernel is fetched from the configuration and the method //< | ||
- | |||
- | The references to the constant blocks are assembled as follows. First come the classes with class constructors. These classes are already sorted in correct order as described in [[class_initialization]]. Classes without initialization follow afterwards. Arrays and interfaces have no constant block and are not listed. The exception to this rule are interfaces with class constructor, | ||
- | |||
- | ===== Fix Memory Map ===== | ||
- | [{{ .: | ||
- | In this step the code is placed in the memory, as well as the class variables and the constants. First, each class is assigned a memory segment for the code ('' | ||
- | Now, the base address of each used segment can be determined. \\ | ||
- | IMPORTANT System methods with offsets given by the configuration must be placed in their appropriate segments. This leads to holes. Such holes could be eliminated by a more efficient allocation, which is currently not done. | ||
- | |||
- | ===== Calculate Absolute Addresses ===== | ||
- | First, the addresses of static fields are fixed. For this the linker traverses the list '' | ||
- | |||
- | ===== Refresh Constant Block ===== | ||
- | After calculating absolute addresses the constant block has to be refreshed. | ||
- | |||
- | ===== Create Global Constant Table ===== | ||
- | This table holds constants which do not belong to a specific class. To give an example: Certain constants are needed to convert an //int// to a //float//. | ||
- | |||
- | ===== Create Target Image ===== | ||
- | Finally, the target image is put together. For each method of each class and for each constant block (one for each class, array or interface) a target segment is created and inserted into a list. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Verwendung von index, offset und address der Klasse Item ===== | ||
- | Die Felder //index//, //offset// und //address// der Klasse '' | ||
- | |||
- | **Bemerkung: | ||
- | |||
- | ==== Klassen [Class] ==== | ||
- | * //index//: Wird verwendet, um Interfaces für Interfacemethoden zu nummerieren. | ||
- | * //offset//: Wird nicht verwendet, ist immer -1. | ||
- | * // | ||
- | |||
- | ==== Arrays [Array] ==== | ||
- | * //index//: Wird nicht verwendet, ist immer -1. | ||
- | * //offset//: Offset des Typdescriptors im Segment. | ||
- | * // | ||
- | |||
- | ==== Methoden [Method] ==== | ||
- | * //index//: Bei Instanzmethoden der Index der Methode in der Methodentabelle (beginnend bei 0). Bei Klassenmethoden ist //index// immer -1. -> Wird vom CFR gesetzt. | ||
- | * //offset//: Byteoffset der Methode ausgehend von der Startadresse des Codes der Klasse. | ||
- | * // | ||
- | |||
- | ==== Felder [DataItem] ==== | ||
- | <box right 30% | IMPORTANT Konstante Referenzen> | ||
- | **Achtung: | ||
- | |||
- | **Beispiel: | ||
- | static final Object o = new Object(); | ||
- | </ | ||
- | - **Klassen-Felder [DataItem]: | ||
- | - Konstante Felder [NamedConst]: | ||
- | * //index//: Wird nicht verwendet, ist immer -1; | ||
- | * //offset//: Wird nicht verwendet, ist immer -1; | ||
- | * // | ||
- | - Nicht konstante Felder [DataItem]: | ||
- | * //index//: Wird nicht verwendet, ist immer -1. | ||
- | * //offset//: Byteoffset des Feldes (beginnend bei 0 für das erste Feld). | ||
- | * // | ||
- | - **Instanz-Felder [DataItem]: | ||
- | * //index//: Wird nicht verwendet, ist immer -1; | ||
- | * //offset//: Byteoffset des Feldes beginnend bei 0 (inkl. Berücksichtung der Felder der Oberklassen). | ||
- | * // | ||
- | |||
- | ==== Konstanten [Constant] ==== | ||
- | - **Zahlen [StdConstant]: | ||
- | * //index//: Wenn die Konstante vom Typ //float// oder //double// ist, ist //index// der Index der Konstante im Konstantenpool. Ansonsten immer -1; | ||
- | * //offset//: Wenn die Konstante vom Typ //float// oder //double// ist, ist //offset// der Byteoffset der Konstante im Konstantenpool. Ansonsten immer -1; | ||
- | * // | ||
- | - **Stings [StringLiteral]: | ||
- | * //index//: Wenn es sich bei der Konstante um einen String handelt, so wird in //index// der Index des Strings im Stringpool abgelegt. | ||
- | * //offset//: Wenn es sich bei der Konstante um einen String handelt, so wird in //offset// der Byteoffset des Strings im Stringpool abgelegt. | ||
- | * // |