1 |
12 |
jlechner |
/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
|
2 |
|
|
Contributed by Hans-Peter Nilsson
|
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
|
6 |
|
|
Free Software Foundation; either version 2, or (at your option) any
|
7 |
|
|
later version.
|
8 |
|
|
|
9 |
|
|
In addition to the permissions in the GNU General Public License, the
|
10 |
|
|
Free Software Foundation gives you unlimited permission to link the
|
11 |
|
|
compiled version of this file into combinations with other programs,
|
12 |
|
|
and to distribute those combinations without any restriction coming
|
13 |
|
|
from the use of this file. (The General Public License restrictions
|
14 |
|
|
do apply in other respects; for example, they cover modification of
|
15 |
|
|
the file, and distribution when not linked into a combine
|
16 |
|
|
executable.)
|
17 |
|
|
|
18 |
|
|
This file is distributed in the hope that it will be useful, but
|
19 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
21 |
|
|
General Public License for more details.
|
22 |
|
|
|
23 |
|
|
You should have received a copy of the GNU General Public License
|
24 |
|
|
along with this program; see the file COPYING. If not, write to
|
25 |
|
|
the Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
26 |
|
|
Boston, 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.
|
56 |
|
|
stackpp 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.
|
61 |
|
|
Main 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
|
104 |
|
|
0H 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
|
121 |
|
|
0H IS @
|