21ba43a1fb746663493ec546750f0853c45e655b
[platform/upstream/iotjs.git] / targets / nuttx-stm32f4 / app / iotjs_main.cxx
1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 /****************************************************************************
17  *   Copyright (C) 2013 Gregory Nutt. All rights reserved.
18  *   Author: Gregory Nutt <gnutt@nuttx.org>
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions
22  * are met:
23  *
24  * 1. Redistributions of source code must retain the above copyright
25  *    notice, this list of conditions and the following disclaimer.
26  * 2. Redistributions in binary form must reproduce the above copyright
27  *    notice, this list of conditions and the following disclaimer in
28  *    the documentation and/or other materials provided with the
29  *    distribution.
30  * 3. Neither the name NuttX nor the names of its contributors may be
31  *    used to endorse or promote products derived from this software
32  *    without specific prior written permission.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
37  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
38  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
39  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
40  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
41  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
42  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
44  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
45  * POSSIBILITY OF SUCH DAMAGE.
46  *
47  ****************************************************************************/
48
49 /****************************************************************************
50  * Included Files
51  ****************************************************************************/
52
53 #include <nuttx/config.h>
54 #include <nuttx/arch.h>
55
56 #include <stdio.h>
57 #include <setjmp.h>
58
59 #ifdef CONFIG_IOTJS
60 # if !defined(CONFIG_HAVE_CXX) || !defined(CONFIG_HAVE_CXXINITIALIZE)
61 #   error Need CONFIG_HAVE_CXX and CONFIG_HAVE_CXXINITIALIZE
62 # endif
63 #endif
64
65 /****************************************************************************
66  * Public Functions
67  ****************************************************************************/
68
69 /**
70  * Compiler built-in setjmp function.
71  *
72  * @return 0 when called the first time
73  *         1 when returns from a longjmp call
74  */
75
76 int
77 setjmp (jmp_buf buf)
78 {
79     return __builtin_setjmp (buf);
80 } /* setjmp */
81
82 /**
83  * Compiler built-in longjmp function.
84  *
85  * Note:
86  *   ignores value argument
87  */
88
89 void
90 longjmp (jmp_buf buf, int value)
91 {
92     /* Must be called with 1. */
93     __builtin_longjmp (buf, 1);
94 } /* longjmp */
95
96 extern "C" int iotjs_entry(int argc, char *argv[]);
97 extern "C" int tuv_cleanup(void);
98
99 #ifdef CONFIG_BUILD_KERNEL
100 extern "C" int main(int argc, FAR char *argv[])
101 #else
102 extern "C" int iotjs_main(int argc, char *argv[])
103 #endif
104 {
105   int ret = 0;
106   up_cxxinitialize();
107   ret = iotjs_entry(argc, argv);
108   tuv_cleanup();
109   return ret;
110 }