1 /* Copyright (C) 2001-2017 Free Software Foundation, Inc.
2 Contributed by Hans-Peter Nilsson <hp@bitrange.com>
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
6 Free Software Foundation; either version 3, or (at your option) any
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.
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.
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/>. */
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.
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.
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
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
43 .data ! mmixal:= 8H LOC Data_Segment
47 .text ! mmixal:= 9H LOC 8B; LOC #100
50 % The __Stack_start symbol is provided by the link script.
51 stackpp OCTA __Stack_start
52 crtstxt OCTA _init % Assumed to be the lowest executed address.
53 OCTA __etext % Assumed to be beyond the highest executed address.
55 crtsdat OCTA dstart % Assumed to be the lowest accessed address.
56 OCTA _end % Assumed to be beyond the highest accessed address.
58 % "Main" is the magic symbol the simulator jumps to. We want to go
60 % We need to set rG explicitly to avoid hard-to-debug situations.
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.
82 ANDNL $2,#7ff % Align the start at a 2048-boundary.
99 % Initialize the stack pointer. It is supposedly made a global
100 % zero-initialized (allowed to change) register in crtn.S; we use the
107 #ifdef __MMIX_ABI_GNU__
108 % Copy argc and argv from their initial position to argument registers
113 % For the mmixware ABI, we need to move arguments. The return value will
122 % Provide the first part of _init and _fini. Save the return address on the
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
125 % functions or where they store rJ. We shouldn't get there, so die
126 % (TRAP Halt) if that happens.
128 .section .init,"ax",@progbits
137 % Register _fini to be executed as the last atexit function.
138 #ifdef __MMIX_ABI_GNU__
145 .section .fini,"ax",@progbits