1|
2|   $Id: cprt21.as,v 1.1.2.5 2002/02/28 22:44:44 pierre Exp $
3|   This file is part of the Free Pascal run time library.
4|   Copyright (c) 1999-2000 by Michael Van Canneyt and Peter Vreman
5|   members of the Free Pascal development team.
6|
7|   See the file COPYING.FPC, included in this distribution,
8|   for details about the copyright.
9|
10|   This program is distributed in the hope that it will be useful,
11|   but WITHOUT ANY WARRANTY;without even the implied warranty of
12|   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13|
14|**********************************************************************}
15|
16| Linux ELF startup code for Free Pascal
17|
18
19        .file   "prt1.as"
20        .text
21        .globl  _start
22        .type   _start,@function
23_start:
24        /* First locate the start of the environment variables */
25        move.l    (%sp)+,%d3
26        move.l    %d0,%d4
27
28        move.l    %sp,%d1               /* Points to the arguments */
29        move.l    %d3,%d0
30        addq.l    #1,%d0
31        lsl.l     #2,%d0
32        add.l     %sp,%d0
33
34        move.l    %sp,%d7
35        and.l     #0xfffffff8,%d7        /* Align stack */
36        move.l    %d7,%sp
37
38        move.l    %d0,U_SYSLINUX_ENVP    /* Move the environment pointer */
39        move.l    %d3,U_SYSLINUX_ARGC    /* Move the argument counter    */
40        move.l    %d1,U_SYSLINUX_ARGV    /* Move the argument pointer    */
41
42        move.l   #0,%fp                  /* Zero frame pointer to end call stack */
43
44|
45|       Start of args for __libc_start_main
46|
47|
48        move.l   %d4,-(%sp)
49        move.l   %sp,-(%sp)
50        move.l   %a1,-(%sp)
51        pea.l    _fini_dummy
52        pea.l    _init_dummy
53        move.l   %d1,-(%sp)
54        move.l   %d3,-(%sp)
55        pea.l    main
56        jsr      __libc_start_main
57        trap     #0
58
59/* fake main routine which will be run from libc */
60main:
61        /* save return address */
62        move.l    (%sp)+,%d0
63        move.l    %d0,___fpc_ret
64        move.l    %d1,___fpc_ret_d1
65        move.l    %fp,___fpc_ret_fp
66        move.l    %d0,-(%sp)
67
68        /* start the program */
69        move.l   #0,%fp
70        jsr      PASCALMAIN
71
72        .globl _haltproc
73        .type _haltproc,@function
74_haltproc:
75        eor.l    %d0,%d0               /* load and save exitcode */
76        move.w   U_SYSLINUX_EXITCODE,%d0
77
78        move.l    ___fpc_ret,%d3         /* return to libc */
79        move.l    ___fpc_ret_fp,%fp
80        move.l    ___fpc_ret_d1,%d1
81        move.l    %d3,-(%sp)
82_init_dummy:
83_fini_dummy:
84        rts
85
86.data
87        .align  4
88
89        .globl  ___fpc_brk_addr         /* heap management */
90        .type   ___fpc_brk_addr,@object
91        .size   ___fpc_brk_addr,4
92___fpc_brk_addr:
93        .long   0
94
95___fpc_ret:                             /* return address to libc */
96        .long   0
97___fpc_ret_d1:
98        .long   0
99___fpc_ret_fp:
100        .long   0
101
102
103|
104| $Log: cprt21.as,v $
105| Revision 1.1.2.5  2002/02/28 22:44:44  pierre
106|  + add some comments
107|
108| Revision 1.1.2.4  2001/08/02 21:23:59  pierre
109|  * fix the args to __libc_start_main
110|
111| Revision 1.1.2.3  2001/07/30 20:05:07  pierre
112|  * fix a assembler syntax eror in last commit
113|
114| Revision 1.1.2.2  2001/07/30 16:18:53  pierre
115|  * converted from i386 code
116|
117| Revision 1.1.2.2  2001/06/04 18:04:32  peter
118|   * use own dummies for _init and _fini
119|
120| Revision 1.1.2.1  2001/02/14 22:18:45  pierre
121|  * fix Sebastian's problem with HeapTrace
122|
123| Revision 1.1  2000/07/13 06:30:55  michael
124| + Initial import
125|
126| Revision 1.3  2000/01/07 16:41:42  daniel
127|   * copyright 2000
128|
129| Revision 1.2  2000/01/07 16:32:28  daniel
130|   * copyright 2000 added
131|
132| Revision 1.1  1999/05/03 21:29:36  peter
133|   + glibc 2.1 support
134|
135| Revision 1.3  1998/11/04 10:16:25  peter
136|   + xorl fp,fp to indicate end of backtrace
137|
138| Revision 1.2  1998/10/14 21:28:46  peter
139|   * initialize fpu so sigfpe is finally generated for fpu errors
140|
141| Revision 1.1  1998/08/12 19:16:09  peter
142|   + loader including libc init and exit
143|
144|
145