1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  14  * Use is subject to license terms.
  15  */
  16         
  17 /* Copyright 2016, Richard Lowe. */
  18 
  19 #include <sys/asm_linkage.h>
  20 #include <sys/stack.h>
  21 
  22         .file   "mach-crt1.s"
  23 
  24         .global _start_crt
  25 
  26 #if defined(__sparcv9)
  27 #define EB_MAX_SIZE     128
  28 #else
  29 #define EB_MAX_SIZE     64
  30 #endif
  31 
  32 ENTRY_NP(_start)
  33         /*
  34          * On entry, the stack is:
  35          *
  36          * .-----------------------.   <--- %sp
  37          * |                       |
  38          * |        Window         |
  39          * |                       |
  40          * |-----------------------|
  41          * |        argc           |
  42          * |-----------------------|
  43          * |        argv[0]        |
  44          * |        argv[1]        |
  45          * |        argv[2]        |
  46          * |        argv[3]        |
  47          * |        ...            |
  48          * |     argv[argc - 1]    |
  49          * |-----------------------|
  50          * |          NULL         |
  51          * |-----------------------|
  52          * |        envp[0]        |
  53          * |        envp[1]        |
  54          * |        envp[2]        |
  55          * |        envp[3]        |
  56          * |         ...           |
  57          * |        envp[N]        |
  58          * |-----------------------|
  59          * |          NULL         |
  60          * .-----------------------.
  61          *
  62          * and an exit handler from the linker is in %g1
  63          */
  64         clr     %fp             ! don't trace the stack past this point 
  65 
  66         add     %sp, WINDOWSIZE + STACK_BIAS, %l0       ! address of argc
  67 
  68         ! allocate a minimally sized frame, and align ourselves
  69         add     %sp, -SA(MINFRAME - EB_MAX_SIZE), %sp
  70 
  71         ldn     [%l0], %o0                      ! argc
  72         add     %l0, CPTRSIZE, %o1      ! argv
  73         call    _start_crt
  74             mov %g1, %o2                        ! exit_handler in delay slot
  75 SET_SIZE(_start)