OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [syn/] [components/] [sd_card/] [firmware/] [bsp/] [HAL/] [src/] [alt_main.c] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 alfik
/******************************************************************************
2
*                                                                             *
3
* License Agreement                                                           *
4
*                                                                             *
5
* Copyright (c) 2007 Altera Corporation, San Jose, California, USA.           *
6
* All rights reserved.                                                        *
7
*                                                                             *
8
* Permission is hereby granted, free of charge, to any person obtaining a     *
9
* copy of this software and associated documentation files (the "Software"),  *
10
* to deal in the Software without restriction, including without limitation   *
11
* the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
12
* and/or sell copies of the Software, and to permit persons to whom the       *
13
* Software is furnished to do so, subject to the following conditions:        *
14
*                                                                             *
15
* The above copyright notice and this permission notice shall be included in  *
16
* all copies or substantial portions of the Software.                         *
17
*                                                                             *
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
19
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
21
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
22
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
23
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
24
* DEALINGS IN THE SOFTWARE.                                                   *
25
*                                                                             *
26
* This agreement shall be governed in all respects by the laws of the State   *
27
* of California and by the laws of the United States of America.              *
28
*                                                                             *
29
* Altera does not recommend, suggest or require that this reference design    *
30
* file be used in conjunction or combination with any other product.          *
31
******************************************************************************/
32
 
33
#include <stdio.h>
34
#include <stdarg.h>
35
#include <string.h>
36
#include <fcntl.h>
37
#include <stdlib.h>
38
#include <unistd.h>
39
 
40
#include "sys/alt_dev.h"
41
#include "sys/alt_sys_init.h"
42
#include "sys/alt_irq.h"
43
#include "sys/alt_dev.h"
44
 
45
#include "os/alt_hooks.h"
46
 
47
#include "priv/alt_file.h"
48
#include "alt_types.h"
49
 
50
#include "system.h"
51
 
52
#include "sys/alt_log_printf.h"
53
 
54
extern void _do_ctors(void);
55
extern void _do_dtors(void);
56
 
57
/*
58
 * Standard arguments for main. By default, no arguments are passed to main.
59
 * However a device driver may choose to configure these arguments by calling
60
 * alt_set_args(). The expectation is that this facility will only be used by
61
 * the iclient/ihost utility.
62
 */
63
 
64
int    alt_argc = 0;
65
char** alt_argv = {NULL};
66
char** alt_envp = {NULL};
67
 
68
/*
69
 * Prototype for the entry point to the users application.
70
 */
71
 
72
extern int main (int, char **, char **);
73
 
74
/*
75
 * alt_main is the C entry point for the HAL. It is called by the assembler
76
 * startup code in the processor specific crt0.S. It is responsible for:
77
 * completing the C runtime configuration; configuring all the
78
 * devices/filesystems/components in the system; and call the entry point for
79
 * the users application, i.e. main().
80
 */
81
 
82
void alt_main (void)
83
{
84
#ifndef ALT_NO_EXIT    
85
  int result;
86
#endif
87
 
88
  /* ALT LOG - please see HAL/sys/alt_log_printf.h for details */
89
  ALT_LOG_PRINT_BOOT("[alt_main.c] Entering alt_main, calling alt_irq_init.\r\n");
90
  /* Initialize the interrupt controller. */
91
  alt_irq_init (NULL);
92
 
93
  /* Initialize the operating system */
94
  ALT_LOG_PRINT_BOOT("[alt_main.c] Done alt_irq_init, calling alt_os_init.\r\n");
95
  ALT_OS_INIT();
96
 
97
  /*
98
   * Initialize the semaphore used to control access to the file descriptor
99
   * list.
100
   */
101
 
102
  ALT_LOG_PRINT_BOOT("[alt_main.c] Done OS Init, calling alt_sem_create.\r\n");
103
  ALT_SEM_CREATE (&alt_fd_list_lock, 1);
104
 
105
  /* Initialize the device drivers/software components. */
106
  ALT_LOG_PRINT_BOOT("[alt_main.c] Calling alt_sys_init.\r\n");
107
  alt_sys_init();
108
  ALT_LOG_PRINT_BOOT("[alt_main.c] Done alt_sys_init.\r\n");
109
 
110
#if !defined(ALT_USE_DIRECT_DRIVERS) && (defined(ALT_STDIN_PRESENT) || defined(ALT_STDOUT_PRESENT) || defined(ALT_STDERR_PRESENT))
111
 
112
  /*
113
   * Redirect stdio to the apropriate devices now that the devices have
114
   * been initialized. This is only done if the user has requested these
115
   * devices be present (not equal to /dev/null) and if direct drivers
116
   * aren't being used.
117
   */
118
 
119
    ALT_LOG_PRINT_BOOT("[alt_main.c] Redirecting IO.\r\n");
120
    alt_io_redirect(ALT_STDOUT, ALT_STDIN, ALT_STDERR);
121
#endif
122
 
123
#ifndef ALT_NO_C_PLUS_PLUS
124
  /*
125
   * Call the C++ constructors
126
   */
127
 
128
  ALT_LOG_PRINT_BOOT("[alt_main.c] Calling C++ constructors.\r\n");
129
  _do_ctors ();
130
#endif /* ALT_NO_C_PLUS_PLUS */
131
 
132
#if !defined(ALT_NO_C_PLUS_PLUS) && !defined(ALT_NO_CLEAN_EXIT) && !defined(ALT_NO_EXIT)
133
  /*
134
   * Set the C++ destructors to be called at system shutdown. This is only done
135
   * if a clean exit has been requested (i.e. the exit() function has not been
136
   * redefined as _exit()). This is in the interest of reducing code footprint,
137
   * in that the atexit() overhead is removed when it's not needed.
138
   */
139
 
140
  ALT_LOG_PRINT_BOOT("[alt_main.c] Calling atexit.\r\n");
141
  atexit (_do_dtors);
142
#endif
143
 
144
  /*
145
   * Finally, call main(). The return code is then passed to a subsequent
146
   * call to exit() unless the application is never supposed to exit.
147
   */
148
 
149
  ALT_LOG_PRINT_BOOT("[alt_main.c] Calling main.\r\n");
150
 
151
#ifdef ALT_NO_EXIT
152
  main (alt_argc, alt_argv, alt_envp);
153
#else
154
  result = main (alt_argc, alt_argv, alt_envp);
155
  close(STDOUT_FILENO);
156
  exit (result);
157
#endif
158
 
159
  ALT_LOG_PRINT_BOOT("[alt_main.c] After main - we should not be here?.\r\n");
160
}
161
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.