/*
* Copyright (c) 1999-2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
* Source License Version 1.1 (the "License"). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
* The Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#if __ppc__ && __DYNAMIC__
//
// Force stub section next to __text section to minimize chance that
// a bl to a stub will be out of range.
//
.text
.symbol_stub
.picsymbol_stub
#endif
/*
* C runtime startup for ppc, ppc64, i386, x86_64
*
* Kernel sets up stack frame to look like:
*
* :
* | STRING AREA |
* +-------------+
* | 0 |
* +-------------+
* | exec_path | extra "apple" parameters start after NULL terminating env array
* +-------------+
* | 0 |
* +-------------+
* | env[n] |
* +-------------+
* :
* :
* +-------------+
* | env[0] |
* +-------------+
* | 0 |
* +-------------+
* | arg[argc-1] |
* +-------------+
* :
* :
* +-------------+
* | arg[0] |
* +-------------+
* | argc | argc is always 4 bytes long, even in 64-bit architectures
* +-------------+ <- sp
*
* Where arg[i] and env[i] point into the STRING AREA
*/
.text
.globl start
.align 2
#if __ppc__
start: mr r26,r1 clrrwi r1,r1,5 stw r0,0(r1) lwz r3,0(r26) addi r27,r3,1 add r5,r4,r27 trap
#if __ppc64__
start: mr r26,r1 clrrdi r1,r1,5 std r0,0(r1) lwz r3,0(r26) addi r27,r3,1 add r5,r4,r27 trap
#if __i386__
start: pushl $0 # push a zero for debugger end of frames marker
movl %esp,%ebp # pointer to base of kernel frame
andl $-16,%esp # force SSE alignment
subl $16,%esp # room for new argc, argv, & envp, SSE aligned
movl 4(%ebp),%ebx # pickup argc in %ebx
movl %ebx,0(%esp) # argc to reserved stack word
lea 8(%ebp),%ecx # addr of arg[0], argv, into %ecx
movl %ecx,4(%esp) # argv to reserved stack word
addl $1,%ebx # argc + 1 for zero word
sall $2,%ebx # * sizeof(char *)
addl %ecx,%ebx # addr of env[0], envp, into %ebx
movl %ebx,8(%esp) # envp to reserved stack word
call __start # call _start(argc, argv, envp)
hlt # should never return
#endif // __i386__
#if __x86_64__
start: pushq $0 # push a zero for debugger end of frames marker
movq %rsp,%rbp # pointer to base of kernel frame
andq $-16,%rsp # force SSE alignment
movq 8(%rbp),%rdi # put argc in %rdi
leaq 16(%rbp),%rsi # addr of arg[0], argv, into %rsi
movl %edi,%edx # copy argc into %rdx
addl $1,%edx # argc + 1 for zero word
sall $3,%edx # * sizeof(char *)
addq %rsi,%rdx # addr of env[0], envp, into %rdx
call __start # call _start(argc, argv, envp)
hlt # should never return
#endif // __x86_64__
// This code has be written to allow dead code stripping
.subsections_via_symbols