URL
https://opencores.org/ocsvn/forwardcom/forwardcom/trunk
Subversion Repositories forwardcom
[/] [forwardcom/] [libraries/] [startup.as] - Rev 112
Compare with Previous | Blame | View Log
/********************************* startup.as ******************************** Author: Agner Fog* date created: 2018-03-22* Last modified: 2018-03-22* Version: 1.00* Project: ForwardCom library libc.li* Description: startup: program initialization* C declaration: void _entry_point(int argc, char *argv[], char *envp[])** This is the default startup code for ForwardCom programs.* It will be linked into a program if there is no definition of __entry_point elsewhere.* It will do the following:* 1. call any constructor event handlers* 2. call _main* 3. call any destructor event handlers* 4. exit with the return code from _main** Copyright 2018 GNU General Public License http://www.gnu.org/licenses*****************************************************************************/// define event IDs%EVT_CONSTRUCT = 1 // call static constructors and initialization procedures before calling main%EVT_DESTRUCT = 2 // call static destructors and clean up after return from maincode section execute align = 4extern _main: function reguse = 0xFFFFFFFF,0xFFFFFFFFextern _raise_event: function// execution starts here:__entry_point function public reguse = 0xFFFFFFFF,0xFFFFFFFF// parameters to main: int argc, char *argv[], char *envp[]int64 r16 = r0int64 r17 = r1int64 r18 = r2// call any constructors before mainint64 r0 = EVT_CONSTRUCT << 32 // constructor eventcall _raise_event // call event handlers for constructors// restore the parameters to mainint64 r0 = r16int64 r1 = r17int64 r2 = r18// call main, the user programcall _mainint64 r16 = r0 // save the return value// call destructors after mainint64 r0 = EVT_DESTRUCT << 32 // destructor eventcall _raise_event // call event handlers for destructorsint64 r0 = r16 // return value from main to the operating systemsys_call(1, 0x10) // system call exitfiller // make sure execution stops if the system call returns for some reason__entry_point endcode end
