OpenCores
URL https://opencores.org/ocsvn/forwardcom/forwardcom/trunk

Subversion Repositories forwardcom

[/] [forwardcom/] [libraries/] [startup.as] - Blame information for rev 113

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 112 Agner
/*********************************  startup.as  *******************************
2
* Author:        Agner Fog
3
* date created:  2018-03-22
4
* Last modified: 2018-03-22
5
* Version:       1.00
6
* Project:       ForwardCom library libc.li
7
* Description:   startup: program initialization
8
* C declaration: void _entry_point(int argc, char *argv[], char *envp[])
9
*
10
* This is the default startup code for ForwardCom programs.
11
* It will be linked into a program if there is no definition of __entry_point elsewhere.
12
* It will do the following:
13
* 1. call any constructor event handlers
14
* 2. call _main
15
* 3. call any destructor event handlers
16
* 4. exit with the return code from _main
17
*
18
* Copyright 2018 GNU General Public License http://www.gnu.org/licenses
19
*****************************************************************************/
20
 
21
// define event IDs
22
%EVT_CONSTRUCT = 1           // call static constructors and initialization procedures before calling main
23
%EVT_DESTRUCT  = 2           // call static destructors and clean up after return from main
24
 
25
code section execute align = 4
26
 
27
extern _main: function reguse = 0xFFFFFFFF,0xFFFFFFFF
28
extern _raise_event: function
29
 
30
// execution starts here:
31
__entry_point function public reguse = 0xFFFFFFFF,0xFFFFFFFF
32
 
33
// parameters to main: int argc, char *argv[], char *envp[]
34
int64 r16 = r0
35
int64 r17 = r1
36
int64 r18 = r2
37
 
38
// call any constructors before main
39
int64 r0 = EVT_CONSTRUCT << 32                   // constructor event
40
call _raise_event                                // call event handlers for constructors
41
 
42
// restore the parameters to main
43
int64 r0 = r16
44
int64 r1 = r17
45
int64 r2 = r18
46
 
47
// call main, the user program
48
call _main
49
int64 r16 = r0                                   // save the return value
50
 
51
// call destructors after main
52
int64 r0 = EVT_DESTRUCT << 32                    // destructor event
53
call _raise_event                                // call event handlers for destructors
54
 
55
int64 r0 = r16                                   // return value from main to the operating system
56
sys_call(1, 0x10)                                // system call exit
57
filler                                           // make sure execution stops if the system call returns for some reason
58
 
59
__entry_point end
60
 
61
code end

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.