Changes for 4.5.0 snapshot
[newlib-cygwin.git] / libgloss / i960 / crt0.c
blob45d7891f72dfa0f6287c01e931c25e7fe1b146ec
1 extern int main(int argc, char **argv, char **envp);
2 extern int brk (void *value);
4 extern char bss_start;
5 extern char end;
7 char *__env[1] = {0};
8 char **environ = __env;
10 #define ENABLE_TRACE_MASK 1
12 __inline static void
13 enable_tracing (void)
15 register int mask = ENABLE_TRACE_MASK;
16 __asm__ volatile ("modpc %0,%0,%0"
18 : "d" (mask));
21 #define STACK_ALIGN 64
23 __inline static void
24 set_stack (void* ptr)
26 ptr = (void *)(((int)ptr + STACK_ALIGN - 1) & ~(STACK_ALIGN - 1));
27 /* SP must be 64 bytes larger than FP at start. */
28 __asm__ volatile ("mov %0,sp"
30 : "d" (ptr+STACK_ALIGN));
31 __asm__ volatile ("mov %0,fp"
33 : "d" (ptr));
36 __inline static void
37 init_Cregs (void)
39 /* set register values gcc like */
40 register unsigned int mask0=0x3b001000;
41 register unsigned int mask1=0x00009107;
42 __asm__ volatile ("mov %0,g14"
43 : /* no output */
44 : "I" (0)); /* gnu structure pointer */
45 __asm__ volatile ("modac %1,%0,%0"
46 : /* no output */
47 : "d" (mask0),
48 "d" (mask1)); /* fpu control kb */
51 void
52 _start(void)
54 char *p;
56 enable_tracing ();
57 set_stack (&end);
58 init_Cregs ();
59 /* The stack grows upwards, so this makes the heap start after a 256K
60 stack area. PlumHall known to fail with less than 73K of stack. */
61 brk (&end+0x40000);
62 /* clear bss */
63 memset (&bss_start, 0, &end - &bss_start);
64 main(0, 0, 0);
65 exit(0);