]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | /* Copyright (C) 2001-2022 Free Software Foundation, Inc. |
bcf684c7 HPN |
2 | Contributed by Hans-Peter Nilsson <hp@bitrange.com> |
3 | ||
4 | This file is free software; you can redistribute it and/or modify it | |
5 | under the terms of the GNU General Public License as published by the | |
748086b7 | 6 | Free Software Foundation; either version 3, or (at your option) any |
bcf684c7 HPN |
7 | later version. |
8 | ||
bcf684c7 HPN |
9 | This file is distributed in the hope that it will be useful, but |
10 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | General Public License for more details. | |
13 | ||
748086b7 JJ |
14 | Under Section 7 of GPL version 3, you are granted additional |
15 | permissions described in the GCC Runtime Library Exception, version | |
16 | 3.1, as published by the Free Software Foundation. | |
17 | ||
18 | You should have received a copy of the GNU General Public License and | |
19 | a copy of the GCC Runtime Library Exception along with this program; | |
20 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
21 | <http://www.gnu.org/licenses/>. */ | |
bcf684c7 | 22 | |
231008e5 HPN |
23 | % This is the crt0 equivalent for mmix-knuth-mmixware, for setting up |
24 | % things for compiler-generated assembly-code and for setting up things | |
25 | % between where the simulator calls and main, and shutting things down on | |
26 | % the way back. There's an actual crt0.o elsewhere, but that's a dummy. | |
bcf684c7 HPN |
27 | |
28 | % This file and the GCC output are supposed to be *reasonably* | |
29 | % mmixal-compatible to enable people to re-use output with Knuth's mmixal. | |
30 | % However, forward references are used more freely: we are using the | |
31 | % binutils tools. Users of mmixal beware; you will sometimes have to | |
32 | % re-order things or use temporary variables. | |
33 | ||
34 | % Users of mmixal will want to set up 8H and 9H to be .text and .data | |
35 | % respectively, so the compiler can switch between them pretending they're | |
36 | % segments. | |
37 | ||
8a740f07 HPN |
38 | % This little treasure (some contents) is required so the 32 lowest |
39 | % address bits of user data will not be zero. Because of truncation, | |
40 | % that would cause testcase gcc.c-torture/execute/980701-1.c to | |
41 | % incorrectly fail. | |
231008e5 | 42 | |
bcf684c7 HPN |
43 | .data ! mmixal:= 8H LOC Data_Segment |
44 | .p2align 3 | |
8a740f07 | 45 | dstart OCTA 2009 |
bcf684c7 HPN |
46 | |
47 | .text ! mmixal:= 9H LOC 8B; LOC #100 | |
48 | .global Main | |
49 | ||
50 | % The __Stack_start symbol is provided by the link script. | |
51 | stackpp OCTA __Stack_start | |
8a740f07 HPN |
52 | crtstxt OCTA _init % Assumed to be the lowest executed address. |
53 | OCTA __etext % Assumed to be beyond the highest executed address. | |
54 | ||
55 | crtsdat OCTA dstart % Assumed to be the lowest accessed address. | |
56 | OCTA _end % Assumed to be beyond the highest accessed address. | |
bcf684c7 HPN |
57 | |
58 | % "Main" is the magic symbol the simulator jumps to. We want to go | |
59 | % on to "main". | |
60 | % We need to set rG explicitly to avoid hard-to-debug situations. | |
61 | Main SETL $255,32 | |
62 | PUT rG,$255 | |
63 | ||
8a740f07 HPN |
64 | % Make sure we have valid memory for addresses in .text and .data (and |
65 | % .bss, but we include this in .data), for the benefit of mmo-using | |
66 | % simulators that require validation of addresses for which contents | |
67 | % is not present. Due to its implicit-zero nature, zeros in contents | |
68 | % may be left out in the mmo format, but we don't know the boundaries | |
69 | % of those zero-chunks; for mmo files from binutils, they correspond | |
70 | % to the beginning and end of sections in objects before linking. We | |
71 | % validate the contents by executing PRELD (0; one byte) on each | |
72 | % 2048-byte-boundary of our .text .data, and we assume this size | |
73 | % matches the magic lowest-denominator chunk-size for all | |
74 | % validation-requiring simulators. The effect of the PRELD (any size) | |
75 | % is assumed to be the same as initial loading of the contents, as | |
76 | % long as the PRELD happens before the first PUSHJ/PUSHGO. If it | |
77 | % happens after that, we'll need to distinguish between | |
78 | % access-for-execution and read/write access. | |
79 | ||
80 | GETA $255,crtstxt | |
81 | LDOU $2,$255,0 | |
82 | ANDNL $2,#7ff % Align the start at a 2048-boundary. | |
83 | LDOU $3,$255,8 | |
84 | SETL $4,2048 | |
85 | 0H PRELD 0,$2,0 | |
86 | ADDU $2,$2,$4 | |
87 | CMP $255,$2,$3 | |
88 | BN $255,0B | |
89 | ||
90 | GETA $255,crtsdat | |
91 | LDOU $2,$255,0 | |
92 | ANDNL $2,#7ff | |
93 | LDOU $3,$255,8 | |
94 | 0H PRELD 0,$2,0 | |
95 | ADDU $2,$2,$4 | |
96 | CMP $255,$2,$3 | |
97 | BN $255,0B | |
98 | ||
bcf684c7 | 99 | % Initialize the stack pointer. It is supposedly made a global |
5f73c6cc | 100 | % zero-initialized (allowed to change) register in crtn.S; we use the |
bcf684c7 HPN |
101 | % explicit number. |
102 | GETA $255,stackpp | |
103 | LDOU $254,$255,0 | |
104 | ||
bcf684c7 HPN |
105 | PUSHJ $2,_init |
106 | ||
107 | #ifdef __MMIX_ABI_GNU__ | |
108 | % Copy argc and argv from their initial position to argument registers | |
109 | % where necessary. | |
231008e5 HPN |
110 | SET $231,$0 |
111 | SET $232,$1 | |
bcf684c7 HPN |
112 | #else |
113 | % For the mmixware ABI, we need to move arguments. The return value will | |
114 | % appear in $0. | |
115 | SET $2,$1 | |
116 | SET $1,$0 | |
117 | #endif | |
118 | ||
119 | PUSHJ $0,main | |
120 | JMP exit | |
121 | ||
231008e5 | 122 | % Provide the first part of _init and _fini. Save the return address on the |
bcf684c7 HPN |
123 | % register stack. We eventually ignore the return address of these |
124 | % PUSHJ:s, so it doesn't matter that whether .init and .fini code calls | |
107a4b41 | 125 | % functions or where they store rJ. We shouldn't get there, so die |
231008e5 | 126 | % (TRAP Halt) if that happens. |
bcf684c7 HPN |
127 | |
128 | .section .init,"ax",@progbits | |
129 | .global _init | |
130 | _init: | |
131 | GET $0,:rJ | |
132 | PUSHJ $1,0F | |
133 | SETL $255,255 | |
134 | TRAP 0,0,0 | |
135 | 0H IS @ | |
136 | ||
8f840f57 HPN |
137 | % Register _fini to be executed as the last atexit function. |
138 | #ifdef __MMIX_ABI_GNU__ | |
139 | GETA $231,_fini | |
140 | #else | |
141 | GETA $1,_fini | |
142 | #endif | |
143 | PUSHJ $0,atexit | |
144 | ||
bcf684c7 HPN |
145 | .section .fini,"ax",@progbits |
146 | .global _fini | |
147 | _fini: | |
148 | GET $0,:rJ | |
149 | PUSHJ $1,0F | |
150 | SETL $255,255 | |
151 | TRAP 0,0,0 | |
152 | 0H IS @ |