1/* Copyright (C) 2001, 2002 Free Software Foundation, Inc. 2 Contributed by Hans-Peter Nilsson <hp@bitrange.com> 3 4This file is free software; you can redistribute it and/or modify it 5under the terms of the GNU General Public License as published by the 6Free Software Foundation; either version 2, or (at your option) any 7later version. 8 9In addition to the permissions in the GNU General Public License, the 10Free Software Foundation gives you unlimited permission to link the 11compiled version of this file into combinations with other programs, 12and to distribute those combinations without any restriction coming 13from the use of this file. (The General Public License restrictions 14do apply in other respects; for example, they cover modification of 15the file, and distribution when not linked into a combine 16executable.) 17 18This file is distributed in the hope that it will be useful, but 19WITHOUT ANY WARRANTY; without even the implied warranty of 20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21General Public License for more details. 22 23You should have received a copy of the GNU General Public License 24along with this program; see the file COPYING. If not, write to 25the Free Software Foundation, 51 Franklin Street, Fifth Floor, 26Boston, MA 02110-1301, USA. */ 27 28% This is the crt0 equivalent for mmix-knuth-mmixware, for setting up 29% things for compiler-generated assembly-code and for setting up things 30% between where the simulator calls and main, and shutting things down on 31% the way back. There's an actual crt0.o elsewhere, but that's a dummy. 32 33% This file and the GCC output are supposed to be *reasonably* 34% mmixal-compatible to enable people to re-use output with Knuth's mmixal. 35% However, forward references are used more freely: we are using the 36% binutils tools. Users of mmixal beware; you will sometimes have to 37% re-order things or use temporary variables. 38 39% Users of mmixal will want to set up 8H and 9H to be .text and .data 40% respectively, so the compiler can switch between them pretending they're 41% segments. 42 43% This little treasure is here so the 32 lowest address bits of user data 44% will not be zero. Because of truncation, that would cause testcase 45% gcc.c-torture/execute/980701-1.c to incorrectly fail. 46 47 .data ! mmixal:= 8H LOC Data_Segment 48 .p2align 3 49 LOC @+(8-@)@7 50 OCTA 2009 51 52 .text ! mmixal:= 9H LOC 8B; LOC #100 53 .global Main 54 55% The __Stack_start symbol is provided by the link script. 56stackpp OCTA __Stack_start 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. 61Main SETL $255,32 62 PUT rG,$255 63 64% Initialize the stack pointer. It is supposedly made a global 65% zero-initialized (allowed to change) register in crtn.asm; we use the 66% explicit number. 67 GETA $255,stackpp 68 LDOU $254,$255,0 69 70% Make sure we get more than one mem, to simplify counting cycles. 71 LDBU $255,$1,0 72 LDBU $255,$1,1 73 74 PUSHJ $2,_init 75 76#ifdef __MMIX_ABI_GNU__ 77% Copy argc and argv from their initial position to argument registers 78% where necessary. 79 SET $231,$0 80 SET $232,$1 81#else 82% For the mmixware ABI, we need to move arguments. The return value will 83% appear in $0. 84 SET $2,$1 85 SET $1,$0 86#endif 87 88 PUSHJ $0,main 89 JMP exit 90 91% Provide the first part of _init and _fini. Save the return address on the 92% register stack. We eventually ignore the return address of these 93% PUSHJ:s, so it doesn't matter that whether .init and .fini code calls 94% functions or where they store rJ. We shouldn't get there, so die 95% (TRAP Halt) if that happens. 96 97 .section .init,"ax",@progbits 98 .global _init 99_init: 100 GET $0,:rJ 101 PUSHJ $1,0F 102 SETL $255,255 103 TRAP 0,0,0 1040H IS @ 105 106% Register _fini to be executed as the last atexit function. 107#ifdef __MMIX_ABI_GNU__ 108 GETA $231,_fini 109#else 110 GETA $1,_fini 111#endif 112 PUSHJ $0,atexit 113 114 .section .fini,"ax",@progbits 115 .global _fini 116_fini: 117 GET $0,:rJ 118 PUSHJ $1,0F 119 SETL $255,255 120 TRAP 0,0,0 1210H IS @ 122