source: trunk/sys/dietlibc/crt0.c @ 114

Last change on this file since 114 was 1, checked in by alain, 8 years ago

First import

File size: 2.2 KB
Line 
1/*
2   This file is part of ALMOS-SYS.
3 
4   ALMOS-SYS is free software; you can redistribute it and/or modify it
5   under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2 of the License, or
7   (at your option) any later version.
8 
9   ALMOS-SYS is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   General Public License for more details.
13 
14   You should have received a copy of the GNU General Public License
15   along with ALMOS-SYS; if not, write to the Free Software Foundation,
16   Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18   UPMC / LIP6 / SOC (c) 2009
19   Copyright Ghassan Almaless <ghassan.almaless@gmail.com>
20*/
21
22#include <stdlib.h>
23#include <sys/syscall.h>
24#include <cpu-syscall.h>
25#include <pthread.h>
26#include <gomp/omp-pv.h>
27
28char **environ;
29
30extern int main();
31extern void __heap_manager_init(void);
32
33extern unsigned int __bss_start;
34extern unsigned int __bss_end;
35
36static void __sigreturn(void)
37{
38  cpu_syscall(NULL,NULL,NULL,NULL,SYS_SIGRETURN);
39}
40
41void __attribute__ ((section (".init"))) _start(char **argv, char **envp)
42{
43  int retval;
44  int argc;
45  __pthread_tls_t tls;
46  struct __shared_s __default;
47  unsigned int *bss_end = &__bss_end;
48  unsigned int *bss_start = &__bss_start;
49 
50  CPU_SET_GP(bss_start);
51
52  environ = envp;
53
54  /* First of all, init tls */
55  __pthread_tls_init(&tls);
56  __pthread_tls_set(&tls,__PT_TLS_SHARED,&__default);
57  __default.mailbox = 0;
58  __default.tid = tls.attr.key;
59  /* ---------------------- */
60  __heap_manager_init();
61  __pthread_init();
62
63#ifdef HAVE_GOMP
64  initialize_env();
65  initialize_team();
66  initialize_critical();
67#endif
68 
69  for(argc=0; argv[argc] != NULL; argc++)
70  {
71#if 0
72    printf("LibC: argc %d, argv[%d]=%s\n", argc, argc, argv[argc]);
73    fflush(stdout);
74#endif
75  }
76
77  cpu_syscall(&__sigreturn,NULL,NULL,NULL, SYS_SET_SIGRETURN);
78  //pthread_exit((void *)main());
79  retval = main(argc, argv, envp);
80
81  fprintf(stderr, "LibC: main ended\n");
82
83#ifdef HAVE_GOMP
84  fprintf(stderr, "LibC: calling gomp tream_destructor\n");
85  team_destructor();
86#endif
87
88  exit(retval);
89}
Note: See TracBrowser for help on using the repository browser.