ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
_linker.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSÌ COM'È", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#include "../../ugbc.h"
36
37/****************************************************************************
38 * CODE SECTION
39 ****************************************************************************/
40
48void linker_setup( Environment * _environment ) {
49
50 if ( _environment->program.startingAddress < 0x2000 ) {
52 }
53
54 int size = _environment->frameBufferStart - _environment->program.startingAddress;
55
56 if ( size < 0 ) {
58 }
59
60 cfghead0("FEATURES {");
61 cfgline1("STARTADDRESS: default = $%4.4x;", _environment->program.startingAddress);
62 cfghead0("}");
63
64 cfghead0("SYMBOLS {");
65 cfghead0("}");
66
67 cfghead0("MEMORY {");
68 cfgline0("ZP: start = $0096, size = $007E, type = rw, define = yes;");
69 cfgline0("HEADER: start = $0000, size = $0006, file = %O;");
70 cfgline1("MAIN: start = %%S, size = $%4.4x, file = %%O;", size);
71 cfgline0("TRAILER: start = $0000, size = $0006, file = %O;");
72
73 MemoryArea * actual = _environment->memoryAreas;
74 while( actual ) {
75 if ( actual->type == MAT_RAM ) {
76 cfgline3("RAM%3.3x: file = \"\", start = $%4.4x, size = $%4.4x;", actual->id, (unsigned short)actual->start, (unsigned short)(actual->end - actual->start) );
77 }
78 actual = actual->next;
79 }
80
81 cfghead0("}");
82
83 cfghead0("FEATURES {");
84 cfgline0("CONDES: segment = INIT,");
85 cfgline0(" type = constructor,");
86 cfgline0(" label = __CONSTRUCTOR_TABLE__,");
87 cfgline0(" count = __CONSTRUCTOR_COUNT__;");
88 cfgline0("CONDES: segment = RODATA,");
89 cfgline0(" type = destructor,");
90 cfgline0(" label = __DESTRUCTOR_TABLE__,");
91 cfgline0(" count = __DESTRUCTOR_COUNT__;");
92 cfgline0("CONDES: type = interruptor,");
93 cfgline0(" segment = RODATA,");
94 cfgline0(" label = __INTERRUPTOR_TABLE__,");
95 cfgline0("count = __INTERRUPTOR_COUNT__;");
96 cfghead0("}");
97
98 cfghead0("SEGMENTS {");
99 cfgline0("EXEHDR: load = HEADER, type = ro;");
100 cfgline0("STARTUP: load = MAIN, type = ro, define = yes, optional = yes;");
101 cfgline0("LOWCODE: load = MAIN, type = ro, define = yes, optional = yes;");
102 cfgline0("INIT: load = MAIN, type = ro, optional = yes;");
103 cfgline0("CODE: load = MAIN, type = ro, define = yes;");
104 cfgline0("RODATA: load = MAIN, type = ro;");
105 cfgline0("DATA: load = MAIN, type = rw;");
106 cfgline0("ZPSAVE: load = MAIN, type = bss, define = yes, optional = yes;");
107 cfgline0("BSS: load = MAIN, type = bss, define = yes;");
108
109 actual = _environment->memoryAreas;
110 actual = _environment->memoryAreas;
111 while( actual ) {
112 if ( actual->type == MAT_RAM ) {
113 cfgline3("MA%3.3x: load = RAM%3.3x, type = overwrite, optional = yes, start = $%4.4x;", actual->id, actual->id, actual->start);
114 } else {
115 cfgline2("MA%3.3x: load = MAIN, type = overwrite, optional = yes, start = $%4.4x;", actual->id, actual->start);
116 }
117 actual = actual->next;
118 }
119 cfgline0("HEAP: load = MAIN, type = bss, optional = yes; # must sit just below stack");
120 cfgline0("ZEROPAGE: load = ZP, type = zp;");
121 cfgline0("AUTOSTRT: load = TRAILER, type = ro;");
122
123}
124
125
133void linker_cleanup( Environment * _environment ) {
134
135 cfghead0("}");
136
137}
void linker_setup(Environment *_environment)
Emit tail of linker's configuration file lines.
Definition _linker.c:48
void linker_cleanup(Environment *_environment)
Emit tail of linker's configuration file lines.
Definition _linker.c:133
int size
Definition _optimizer.c:678
Program program
Definition ugbc.h:3179
MemoryArea * memoryAreas
Definition ugbc.h:2689
int frameBufferStart
Definition ugbc.h:3111
int start
Definition ugbc.h:737
struct _MemoryArea * next
Definition ugbc.h:760
int id
Definition ugbc.h:732
MemoryAreaType type
Definition ugbc.h:757
int end
Definition ugbc.h:747
int startingAddress
Definition ugbc.h:2217
#define CRITICAL_INVALID_PROGRAM_START(a)
Definition ugbc.h:3742
@ MAT_RAM
Definition ugbc.h:726
#define cfgline0(s)
Definition ugbc.h:4273
struct _Environment Environment
Structure of compilation environment.
struct _MemoryArea MemoryArea
#define cfgline1(s, a)
Definition ugbc.h:4274
#define cfgline2(s, a, b)
Definition ugbc.h:4275
#define cfgline3(s, a, b, c)
Definition ugbc.h:4276
#define cfghead0(s)
Definition ugbc.h:4267