Correct placement of arguments and environment on stack.

int main(int argc, char *argv[])

style main function works now on Codezero/POSIX.
This commit is contained in:
Bahadir Balban
2009-10-07 19:17:24 +03:00
parent 8a55a80c23
commit 96cd0949b6
11 changed files with 147 additions and 215 deletions

View File

@@ -9,7 +9,7 @@ sys.path.append('../../../../')
from config.lib import *
from tools.pyelf.lmanext import *
src = [Glob('*.c') + Glob('test_exec.S') + Glob('src/*.c') + Glob('src/arch/arm/*.c')]
src = [Glob('*.c') + Glob('test_exec.S') + Glob('src/*.[Sc]') + Glob('src/arch/arm/*.c')]
asm_string = \
'''
@@ -34,7 +34,7 @@ env = environment.Clone()
test_exec_env = environment.Clone()
test_exec_env.Append(LIBS = ['posix', 'c-userspace'])
test_exec_env.Append(LINKFLAGS = ['-T' + "test0/include/test_exec_linker.lds", '-u_start'])
test_exec_env.Append(LINKFLAGS = '-T' + "test0/include/test_exec_linker.lds")
test_exec_env.Append(CPPFLAGS = ' -D__USERSPACE__')
test_exec_env.Replace(PROGSUFFIX = '')
test_exec_src = Glob('src/test_exec/*.[cS]')
@@ -44,7 +44,7 @@ test_exec_asm = Command('test_exec.S', test_exec, generate_incbin_asm)
Depends(test_exec, test_exec_objs)
env.Append(LIBS = ['posix', 'c-userspace'])
env.Append(LINKFLAGS = ['-T' + lma_lds[0].path, '-u_start'])
env.Append(LINKFLAGS = '-T' + lma_lds[0].path)
env.Append(CPPFLAGS = ' -D__USERSPACE__')
env.Replace(PROGSUFFIX = '')
objs = env.Object(src + test_exec_asm)
@@ -75,6 +75,9 @@ elf_wrap_env.Append(LINKFLAGS = '-T' + elf_wrapped_lds[0].path)
elf_wrap_objs = elf_wrap_env.Object(elf_wrapped_asm)
test0_elf_elf = elf_wrap_env.Program('test0_elf.elf', elf_wrap_objs)
# So that everytime test0 is built, elf_wrap_objs
# gets built (even though elf_wrapped_asm remains the same
Depends(elf_wrap_objs, test0)
Depends(test0, lma_lds)
Depends(test0, test_exec)
Depends(lma_lds, previmage)

View File

@@ -8,15 +8,27 @@
#include <l4lib/init.h>
#include <l4lib/utcb.h>
#include <posix_init.h> /* Initialisers for posix library */
#include <stdlib.h>
void main(void);
int main(int argc, char *argv[]);
void __container_init(void)
int __container_init(int argc, char **argv)
{
void *envp = &argv[argc + 1];
char *pagerval;
if ((char *)envp == *argv)
envp = &argv[argc];
__libposix_init(envp);
pagerval = getenv("pagerid");
printf("Pager id: %s\n", pagerval);
/* Generic L4 thread initialisation */
__l4_init();
/* Entry to main */
main();
return main(argc, argv);
}

View File

@@ -1,7 +1,6 @@
#ifndef __LIBPOSIX_INIT_H__
#define __LIBPOSIX_INIT_H__
void libposix_init(void);
void posix_service_init(void);
int __libposix_init(void *envp);
#endif /* __LIBPOSIX_INIT_H__ */

View File

@@ -25,7 +25,7 @@ void wait_pager(l4id_t partner)
pid_t parent_of_all;
void main(void)
int main(int argc, char *argv[])
{
printf("\n%s: Started with thread id %d\n", __TASKNAME__, getpid());

View File

@@ -1,93 +1,23 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
* Copyright (C) 2009 Bahadir Balban
*/
#ifdef __thumb__
#define bl blx
#endif
/*
* We expect initial stack state:
*
* (low) |->argc|argv[0]|argv[1]|...|argv[argc] = 0|envp[0]|...|NULL| (high)
*
*/
.section .text.head
.code 32
.section .text.head
.global _start;
.align;
_start:
ldr sp, =__stack
bl platform_init
mov fp, #0 @ Clear frame pointer
mov lr, #0 @ Clear link register
ldmfd sp!, {r0} @ Argc value in r0
mov r1, sp @ Ptr to argv in r1
bl __container_init
1:
b 1b