metalsvm/libgloss/crt0.asm
stefan 27e1aee7ef - add missing files
- update of the configure example



git-svn-id: http://svn.lfbs.rwth-aachen.de/svn/scc/trunk/MetalSVM@98 315a16e6-25f9-4109-90ae-ca3045a26c18
2010-08-17 10:25:50 +00:00

75 lines
1.7 KiB
NASM

;
; Copyright 2010 Stefan Lankes, Chair for Operating Systems,
; RWTH Aachen University
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; This file is part of metalsvm.
[BITS 32]
SECTION .data
cmdline DB "cmdline", 0
argv DD 0, 0
SECTION .text
global _start
extern main
extern __do_global_dtors
extern __do_global_ctors
extern hardware_init_hook
extern software_init_hook
extern atexit
extern exit
_start:
; call init hooks, if any exists
lea eax, [hardware_init_hook]
cmp eax, 0
je L1
call eax
L1:
lea eax, [software_init_hook]
cmp eax, 0
je L2
call eax
L2:
; register a function to be called at normal process termination
push __do_global_dtors
call atexit
pop eax
; call init function
call __do_global_ctors
; build argc/argv pair and then push
; them onto the stack...
mov [argv+0], DWORD cmdline
mov eax, [esp+4]
mov [argv+4], eax
push argv
push 2
; call the user's function
call main
; remove argc/argv pair
add esp, 8
; call exit from the C library so atexit gets called, and the
; C++ destructors get run. This calls our exit routine below
; when it's done.
; call "exit"
push eax
call exit
; endless loop
jmp $