Jerry is now split to several components: core, libc, plugins.

The components are build independently and then are linked with main module corresponding to target platform.
Core is supposed to be platform-independent, while libc and plugins are dependent on specific architecture / platform.

The commit disables unit tests building and running during precommit.
That is supposed to be fixed in a subsequent commit.

Also, the commit disables building and running valgrind targets during precommit.
Build is supposed to be turned on by an option that should be introduced later.
Valgrind-checked runs are supposed to be performed in asynchronous mode.
This commit is contained in:
Ruben Ayrapetyan
2015-02-13 21:29:02 +03:00
parent 62a3ac93d9
commit 43ea53b1d7
84 changed files with 1345 additions and 1116 deletions
+151
View File
@@ -0,0 +1,151 @@
# Copyright 2015 Samsung Electronics Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required (VERSION 2.8.12)
project (Jerry_LibC C ASM)
# Compiler / linker flags
set(COMPILE_FLAGS_LIBC "${COMPILE_FLAGS_JERRY} ${C_FLAGS_JERRY}")
# Definitions
set(DEFINES_LIBC )
# Debug
set(DEFINES_LIBC_DEBUG )
# Release
set(DEFINES_LIBC_RELEASE LIBC_NDEBUG)
# Architecture-specific
# x86_64
set(DEFINES_LIBC_X86_64 __TARGET_HOST_x64)
# ARMv7
set(DEFINES_LIBC_ARMV7 __TARGET_HOST_ARMv7)
# Platform-specific
# Linux
set(DEFINES_LIBC_LINUX __TARGET_HOST)
# MCU
set(DEFINES_LIBC_MCU __TARGET_MCU)
# stm32f3
set(DEFINES_LIBC_MCU_STM32F3 __TARGET_MCU_STM32F3)
# stm32f4
set(DEFINES_LIBC_MCU_STM32F4 __TARGET_MCU_STM32F4)
# Include directories
set(INCLUDE_LIBC .)
# Platform-specific
# Linux
set(INCLUDE_LIBC_LINUX target/linux)
# MCU
# STM32F3
set(INCLUDE_LIBC_MCU_STM32F3 target/stm32f3)
# STM32F4
set(INCLUDE_LIBC_MCU_STM32F4 target/stm32f4)
# Third-party
# Platform-specific
# Linux
set(INCLUDE_THIRD_PARTY_LINUX )
# MCU
# STM32F3
set(INCLUDE_THIRD_PARTY_MCU_STM32F3
${CMAKE_SOURCE_DIR}/third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/CMSIS/Device/ST/STM32F30x/Include
${CMAKE_SOURCE_DIR}/third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/CMSIS/Include)
# STM32F4
set(INCLUDE_THIRD_PARTY_MCU_STM32F4
${CMAKE_SOURCE_DIR}/third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Include
${CMAKE_SOURCE_DIR}/third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/Include)
# Sources
file(GLOB SOURCE_LIBC *.c)
# Platform-specific
# Linux
file(GLOB SOURCE_LIBC_LINUX target/linux/*.c target/linux/*.S)
# MCU
# stm32f3
file(GLOB SOURCE_LIBC_MCU_STM32F3 target/mcu-stubs/*.c target/mcu-stubs/*.S)
# stm32f4
file(GLOB SOURCE_LIBC_MCU_STM32F4 target/mcu-stubs/*.c target/mcu-stubs/*.S)
# Third-party
# Platform-specific
# MCU
# stm32f3
set(SOURCE_THIRD_PARTY_MCU_STM32F3
${CMAKE_SOURCE_DIR}/third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/CMSIS/Device/ST/STM32F30x/Source/Templates/system_stm32f30x.c
${CMAKE_SOURCE_DIR}/third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/CMSIS/Device/ST/STM32F30x/Source/Templates/gcc_ride7/startup_stm32f30x.s)
# stm32f4
set(SOURCE_THIRD_PARTY_MCU_STM32F4
${CMAKE_SOURCE_DIR}/third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c
${CMAKE_SOURCE_DIR}/third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f4xx.s)
# Architecture-specific configuration
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set(DEFINES_LIBC ${DEFINES_LIBC} ${DEFINES_LIBC_X86_64})
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l")
set(DEFINES_LIBC ${DEFINES_LIBC} ${DEFINES_LIBC_ARMV7})
else()
message(FATAL_ERROR "Unsupported machine architecture")
endif()
# Platform-specific configuration
set(DEFINES_LIBC ${DEFINES_LIBC} ${DEFINES_LIBC_${PLATFORM}})
# Targets declaration
string(TOLOWER ${PLATFORM_EXT} PLATFORM_L)
set(TARGET_NAME jerry-libc.${PLATFORM_L})
function(declare_targets_for_build_mode BUILD_MODE)
set(TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}}.${TARGET_NAME})
set(DEFINES_LIBC ${DEFINES_LIBC} ${DEFINES_LIBC_${BUILD_MODE}})
set(INCLUDE_LIBC ${INCLUDE_LIBC} ${INCLUDE_LIBC_${PLATFORM_EXT}})
function(declare_target_with_modifiers ) # modifiers are passed in ARGN implicit argument
foreach(MODIFIER ${ARGN})
set(TARGET_NAME ${TARGET_NAME}${MODIFIER_SUFFIX_${MODIFIER}})
endforeach()
# Jerry
add_library(${TARGET_NAME}.lib STATIC ${SOURCE_LIBC} ${SOURCE_LIBC_${PLATFORM_EXT}})
set_property(TARGET ${TARGET_NAME}.lib
PROPERTY COMPILE_FLAGS "${COMPILE_FLAGS_LIBC} ${FLAGS_COMMON_${BUILD_MODE}}")
target_compile_definitions(${TARGET_NAME}.lib PRIVATE ${DEFINES_LIBC})
target_include_directories(${TARGET_NAME}.lib PRIVATE ${INCLUDE_LIBC})
# Third-party MCU library
if(DEFINED SOURCE_THIRD_PARTY_${PLATFORM_EXT})
add_library(${TARGET_NAME}.third_party.lib STATIC ${SOURCE_THIRD_PARTY_${PLATFORM_EXT}})
set_property(TARGET ${TARGET_NAME}.third_party.lib
PROPERTY COMPILE_FLAGS "${FLAGS_COMMON_${BUILD_MODE}}")
target_include_directories(${TARGET_NAME}.third_party.lib PRIVATE ${INCLUDE_THIRD_PARTY_${PLATFORM_EXT}})
target_link_libraries(${TARGET_NAME}.lib ${TARGET_NAME}.third_party.lib)
endif()
endfunction()
foreach(MODIFIERS_LIST ${MODIFIERS_LISTS})
separate_arguments(MODIFIERS_LIST)
declare_target_with_modifiers(${MODIFIERS_LIST})
endforeach()
endfunction()
foreach(BUILD_MODE ${BUILD_MODES})
declare_targets_for_build_mode(${BUILD_MODE})
endforeach()
+117
View File
@@ -0,0 +1,117 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DEFS_H
#define DEFS_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
/**
* Attributes
*/
#define __attr_unused___ __attribute__((unused))
#define __attr_used___ __attribute__((used))
#define __attr_noreturn___ __attribute__((noreturn))
#define __attr_noinline___ __attribute__((noinline))
/**
* Constants
*/
#define LIBC_FATAL_ERROR_EXIT_CODE (2)
/**
* Assertions
*/
extern void __attr_noreturn___
libc_fatal (const char *msg,
const char *file_name,
const char *function_name,
const int line_number);
#ifndef LIBC_NDEBUG
# define LIBC_ASSERT(x) do { if (__builtin_expect (!(x), 0)) { \
libc_fatal (#x, __FILE__, __FUNCTION__, __LINE__); } } while (0)
# define LIBC_UNREACHABLE() \
do \
{ \
libc_fatal ("Code is unreachable", __FILE__, __FUNCTION__, __LINE__); \
} while (0)
#else /* !LIBC_NDEBUG */
# define LIBC_ASSERT(x) do { if (false) { (void)(x); } } while (0)
# define LIBC_UNREACHABLE() \
do \
{ \
libc_fatal (NULL, NULL, NULL, 0); \
} while (0)
#endif /* !LIBC_NDEBUG */
/**
* Stubs declaration
*/
/**
* Unreachable stubs for routines that are never called,
* but referenced from third-party libraries.
*/
#define LIBC_UNREACHABLE_STUB_FOR(...) \
__attr_used___ __VA_ARGS__ \
{ \
LIBC_UNREACHABLE (); \
}
/**
* Libc redefinitions
*/
/* Ensuring no macro implementation of variables / functions are in effect */
#undef vfprintf
#undef fprintf
#undef printf
#undef isspace
#undef isalpha
#undef islower
#undef isupper
#undef isdigit
#undef isxdigit
#undef memset
#undef memcmp
#undef memcpy
#undef memmove
#undef strcmp
#undef strncmp
#undef strncpy
#undef strlen
#undef putchar
#undef puts
#undef exit
#undef fopen
#undef rewind
#undef fclose
#undef fseek
#undef ftell
#undef fread
#undef fwrite
#undef stdin
#undef stdout
#undef stderr
extern FILE* stdin;
extern FILE* stdout;
extern FILE* stderr;
#endif /* !DEFS_H */
+44
View File
@@ -0,0 +1,44 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Jerry libc's fatal errors handlers
*/
#include <stdio.h>
#include "jerry-libc-defs.h"
/**
* Fatal error handler
*
* Arguments may be NULL. If so, they are ignored.
*/
void __attr_noreturn___
libc_fatal (const char *msg, /**< fatal error description */
const char *file_name, /**< file name */
const char *function_name, /**< function name */
const int line_number) /**< line number */
{
if (msg != NULL
&& file_name != NULL
&& function_name != NULL)
{
printf("Assertion '%s' failed at %s (%s:%u).\n",
msg, function_name, file_name, line_number);
}
exit (LIBC_FATAL_ERROR_EXIT_CODE);
} /* libc_fatal */
@@ -17,10 +17,11 @@
* Jerry printf implementation
*/
#include "jrt.h"
#include "jerry-libc.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "jerry-libc-defs.h"
/**
* printf's length type
@@ -72,7 +73,7 @@ typedef uint8_t libc_printf_arg_flags_mask_t;
* printf helper function that outputs a char
*/
static void
libc_printf_putchar (_FILE *stream, /**< stream pointer */
libc_printf_putchar (FILE *stream, /**< stream pointer */
char character) /**< character */
{
fwrite (&character, 1, sizeof (character), stream);
@@ -82,7 +83,7 @@ libc_printf_putchar (_FILE *stream, /**< stream pointer */
* printf helper function that outputs justified string
*/
static void
libc_printf_justified_string_output (_FILE *stream, /**< stream pointer */
libc_printf_justified_string_output (FILE *stream, /**< stream pointer */
const char *string_p, /**< string */
size_t width, /**< minimum field width */
bool is_left_justify, /**< justify to left (true) or right (false) */
@@ -130,20 +131,20 @@ libc_printf_uint_to_string (uintmax_t value, /**< integer value */
char *str_p = str_buffer_end;
*--str_p = '\0';
JERRY_ASSERT(radix >= 2);
LIBC_ASSERT(radix >= 2);
if ((radix & (radix - 1)) != 0)
{
/*
* Radix is not power of 2. Only 32-bit numbers are supported in this mode.
*/
JERRY_ASSERT((value >> 32) == 0);
LIBC_ASSERT((value >> 32) == 0);
uint32_t value_lo = (uint32_t) value;
while (value_lo != 0)
{
JERRY_ASSERT (str_p != buffer_p);
LIBC_ASSERT (str_p != buffer_p);
*--str_p = alphabet[ value_lo % radix ];
value_lo /= radix;
@@ -156,7 +157,7 @@ libc_printf_uint_to_string (uintmax_t value, /**< integer value */
{
shift++;
JERRY_ASSERT(shift <= 32);
LIBC_ASSERT(shift <= 32);
}
uint32_t value_lo = (uint32_t) value;
@@ -165,7 +166,7 @@ libc_printf_uint_to_string (uintmax_t value, /**< integer value */
while (value_lo != 0
|| value_hi != 0)
{
JERRY_ASSERT (str_p != buffer_p);
LIBC_ASSERT (str_p != buffer_p);
*--str_p = alphabet[ value_lo & (radix - 1) ];
value_lo >>= shift;
@@ -179,7 +180,7 @@ libc_printf_uint_to_string (uintmax_t value, /**< integer value */
*--str_p = '0';
}
JERRY_ASSERT(str_p >= buffer_p && str_p < str_buffer_end);
LIBC_ASSERT(str_p >= buffer_p && str_p < str_buffer_end);
return str_p;
} /* libc_printf_uint_to_string */
@@ -190,20 +191,21 @@ libc_printf_uint_to_string (uintmax_t value, /**< integer value */
* @return updated va_list
*/
static void
libc_printf_write_d_i (_FILE *stream, /**< stream pointer */
libc_printf_write_d_i (FILE *stream, /**< stream pointer */
va_list* args_list_p, /**< args' list */
libc_printf_arg_flags_mask_t flags, /**< field's flags */
libc_printf_arg_length_type_t length, /**< field's length type */
uint32_t width) /**< minimum field width to output */
{
JERRY_ASSERT((flags & LIBC_PRINTF_ARG_FLAG_SHARP) == 0);
LIBC_ASSERT((flags & LIBC_PRINTF_ARG_FLAG_SHARP) == 0);
bool is_signed = true;
uintmax_t value = 0;
/* true - positive, false - negative */
bool sign = true;
const uintmax_t value_sign_mask = ((uintmax_t)1) << (sizeof (value) * JERRY_BITSINBYTE - 1);
const size_t bits_in_byte = 8;
const uintmax_t value_sign_mask = ((uintmax_t)1) << (sizeof (value) * bits_in_byte - 1);
switch (length)
{
@@ -259,7 +261,7 @@ libc_printf_write_d_i (_FILE *stream, /**< stream pointer */
case LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL:
{
JERRY_UNREACHABLE();
LIBC_UNREACHABLE();
}
}
@@ -283,7 +285,7 @@ libc_printf_write_d_i (_FILE *stream, /**< stream pointer */
if (!sign
|| (flags & LIBC_PRINTF_ARG_FLAG_PRINT_SIGN))
{
JERRY_ASSERT (string_p > str_buffer);
LIBC_ASSERT (string_p > str_buffer);
*--string_p = (sign ? '+' : '-');
}
else if (flags & LIBC_PRINTF_ARG_FLAG_SPACE)
@@ -310,7 +312,7 @@ libc_printf_write_d_i (_FILE *stream, /**< stream pointer */
* @return updated va_list
*/
static void
libc_printf_write_u_o_x_X(_FILE *stream, /**< stream pointer */
libc_printf_write_u_o_x_X(FILE *stream, /**< stream pointer */
char specifier, /**< specifier (u, o, x, X) */
va_list* args_list_p, /**< args' list */
libc_printf_arg_flags_mask_t flags, /**< field's flags */
@@ -371,7 +373,7 @@ libc_printf_write_u_o_x_X(_FILE *stream, /**< stream pointer */
case LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL:
{
JERRY_UNREACHABLE();
LIBC_UNREACHABLE();
}
}
@@ -391,7 +393,7 @@ libc_printf_write_u_o_x_X(_FILE *stream, /**< stream pointer */
}
else
{
JERRY_ASSERT(specifier == 'o');
LIBC_ASSERT(specifier == 'o');
}
}
}
@@ -431,7 +433,7 @@ libc_printf_write_u_o_x_X(_FILE *stream, /**< stream pointer */
default:
{
JERRY_UNREACHABLE();
LIBC_UNREACHABLE();
}
}
@@ -475,10 +477,10 @@ libc_printf_write_u_o_x_X(_FILE *stream, /**< stream pointer */
*
* @return number of characters printed
*/
static int
vfprintf (_FILE *stream, /**< stream pointer */
const char *format, /**< format string */
va_list args) /**< arguments */
int
vfprintf (FILE *stream, /**< stream pointer */
const char *format, /**< format string */
va_list args) /**< arguments */
{
va_list args_copy;
@@ -531,7 +533,7 @@ vfprintf (_FILE *stream, /**< stream pointer */
if (*format_iter_p == '*')
{
/* Not supported */
JERRY_UNREACHABLE ();
LIBC_UNREACHABLE ();
}
// If there is a number, recognize it as field width
@@ -545,7 +547,7 @@ vfprintf (_FILE *stream, /**< stream pointer */
if (*format_iter_p == '.')
{
/* Not supported */
JERRY_UNREACHABLE ();
LIBC_UNREACHABLE ();
}
switch (*format_iter_p)
@@ -639,7 +641,7 @@ vfprintf (_FILE *stream, /**< stream pointer */
case 'A':
{
/* Not supported */
JERRY_UNREACHABLE ();
LIBC_UNREACHABLE ();
break;
}
@@ -648,7 +650,7 @@ vfprintf (_FILE *stream, /**< stream pointer */
if (length & LIBC_PRINTF_ARG_LENGTH_TYPE_L)
{
/* Not supported */
JERRY_UNREACHABLE ();
LIBC_UNREACHABLE ();
}
else
{
@@ -672,7 +674,7 @@ vfprintf (_FILE *stream, /**< stream pointer */
if (length & LIBC_PRINTF_ARG_LENGTH_TYPE_L)
{
/* Not supported */
JERRY_UNREACHABLE ();
LIBC_UNREACHABLE ();
}
else
{
@@ -713,7 +715,7 @@ vfprintf (_FILE *stream, /**< stream pointer */
case 'n':
{
/* Not supported */
JERRY_UNREACHABLE ();
LIBC_UNREACHABLE ();
break;
}
}
@@ -733,9 +735,9 @@ vfprintf (_FILE *stream, /**< stream pointer */
* @return number of characters printed
*/
int
fprintf (_FILE *stream, /**< stream pointer */
const char *format, /**< format string */
...) /**< parameters' values */
fprintf (FILE *stream, /**< stream pointer */
const char *format, /**< format string */
...) /**< parameters' values */
{
va_list args;
@@ -755,13 +757,13 @@ fprintf (_FILE *stream, /**< stream pointer */
*/
int
printf (const char *format, /**< format string */
...) /**< parameters' values */
...) /**< parameters' values */
{
va_list args;
va_start (args, format);
int ret = vfprintf (LIBC_STDOUT, format, args);
int ret = vfprintf (stdout, format, args);
va_end (args);
@@ -17,23 +17,21 @@
* Jerry libc's common functions implementation
*/
#include "jerry-libc.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "jerry-libc-defs.h"
/**
* Unreachable stubs for routines that are never called,
* but referenced from third-party libraries.
* Standard file descriptors
*/
#define JRT_UNREACHABLE_STUB_FOR(...) \
extern "C" __VA_ARGS__; \
__used __VA_ARGS__ \
{ \
JERRY_UNREACHABLE (); \
}
FILE *stdin = (FILE*) 0;
FILE *stdout = (FILE*) 1;
FILE *stderr = (FILE*) 2;
JRT_UNREACHABLE_STUB_FOR(void abort (void))
JRT_UNREACHABLE_STUB_FOR(int raise (int sig_no __unused))
#undef JRT_UNREACHABLE_STUB_FOR
LIBC_UNREACHABLE_STUB_FOR(void abort (void))
#ifdef __GNUC__
/*
@@ -42,6 +40,8 @@ JRT_UNREACHABLE_STUB_FOR(int raise (int sig_no __unused))
* - memset -> call to memset;
* - memmove -> call to memmove.
*/
#define CALL_PRAGMA(x) _Pragma (#x)
CALL_PRAGMA(GCC diagnostic push)
CALL_PRAGMA(GCC diagnostic ignored "-Wpragmas")
CALL_PRAGMA(GCC push_options)
@@ -53,7 +53,7 @@ CALL_PRAGMA(GCC optimize ("-fno-tree-loop-distribute-patterns"))
*
* @return @s
*/
void*
void* __attr_used___ // FIXME
memset (void *s, /**< area to set values in */
int c, /**< value to set */
size_t n) /**< area size */
@@ -119,7 +119,7 @@ memcpy (void *s1, /**< destination */
*
* @return the dest pointer's value
*/
void *
void * __attr_used___ // FIXME
memmove (void *s1, /**< destination */
const void *s2, /**< source */
size_t n) /**< bytes number */
@@ -233,7 +233,7 @@ strncmp (const char *s1, const char *s2, size_t n)
/** Copy a string. At most n bytes of src are copied. Warning: If there is no
null byte among the first n bytes of src, the string placed in dest will not be null-terminated.
@return a pointer to the destination string dest. */
char *
char * __attr_used___ // FIXME
strncpy (char *dest, const char *src, size_t n)
{
size_t i;
-86
View File
@@ -1,86 +0,0 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Jerry libc declarations
*/
#ifndef JERRY_LIBC_H
#define JERRY_LIBC_H
#include "jrt.h"
typedef void _FILE;
/**
* stdin file descriptor
*/
#define LIBC_STDIN (_FILE*)0
/**
* stdout file descriptor
*/
#define LIBC_STDOUT (_FILE*)1
/**
* stderr file descriptor
*/
#define LIBC_STDERR (_FILE*)2
extern void* memset (void *s, int c, size_t n);
extern int memcmp (const void *s1, const void *s2, size_t n);
extern void* memcpy (void *s1, const void *s2, size_t n);
extern void* memmove (void *dest, const void *src, size_t n);
extern int printf (const char *format, ...);
extern int putchar (int);
extern "C" void __noreturn exit (int);
extern int strcmp (const char *, const char *);
extern int strncmp (const char *, const char *, size_t);
extern char* strncpy (char *, const char *, size_t);
extern float __strtof (const char *, char **);
extern size_t strlen (const char *);
extern int isspace (int);
extern int isupper (int);
extern int islower (int);
extern int isalpha (int);
extern int isdigit (int);
extern int isxdigit (int);
/**
* 'whence' argument of fseek that identifies position
* the 'offset' argument is added to.
*/
typedef enum
{
__SEEK_SET, /**< relative to begin of file */
__SEEK_CUR, /**< relative to current position */
__SEEK_END /**< relative to end of file */
} _whence_t;
extern _FILE* fopen (const char *, const char *);
extern int fclose (_FILE *);
extern int fseek (_FILE *, long offset, _whence_t);
extern long ftell (_FILE *);
extern void rewind (_FILE *);
extern size_t fread (void *, size_t, size_t, _FILE *);
extern size_t fwrite (const void *, size_t, size_t, _FILE *);
extern int fprintf (_FILE *, const char *, ...);
extern void jrt_set_mem_limits (size_t data_size, size_t stack_size);
#define HUGE_VAL (1e37f)
#endif /* JERRY_LIBC_H */
@@ -17,12 +17,17 @@
* Jerry libc platform-specific functions linux implementation
*/
#include "jrt.h"
#include "jerry-libc.h"
#include <ctype.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syscall.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef __TARGET_HOST_x64
# include "asm_x64.h"
@@ -33,46 +38,33 @@
#else /* !__TARGET_HOST_x64 && !__TARGET_HOST_x86 && !__TARGET_HOST_ARMv7 */
# error "!__TARGET_HOST_x64 && !__TARGET_HOST_x86 && !__TARGET_HOST_ARMv7 "
#endif /* !__TARGET_HOST_x64 && !__TARGET_HOST_x86 && !__TARGET_HOST_ARMv7 */
#include "jerry-libc-defs.h"
FIXME(Rename __unused)
#undef __unused
#include <syscall.h>
#include <sys/stat.h>
#include <fcntl.h>
FIXME (/* Include linux/fs.h */)
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
LIBC_UNREACHABLE_STUB_FOR(int raise (int sig_no __attr_unused___))
/**
* Exit program with ERR_SYSCALL if syscall_ret_val is negative
*/
#define LIBC_EXIT_ON_ERROR(syscall_ret_val) \
if (unlikely ((syscall_ret_val) < 0)) \
if ((syscall_ret_val) < 0) \
{ \
jerry_fatal (ERR_SYSCALL); \
libc_fatal ("Syscall successful", __FILE__, __FUNCTION__, __LINE__); \
}
static long int syscall_1 (long int syscall_no, long int arg1);
static long int syscall_2 (long int syscall_no, long int arg1, long int arg2);
static long int syscall_3 (long int syscall_no, long int arg1, long int arg2, long int arg3);
extern "C"
{
extern long int syscall_1_asm (long int syscall_no, long int arg1);
extern long int syscall_2_asm (long int syscall_no, long int arg1, long int arg2);
extern long int syscall_3_asm (long int syscall_no, long int arg1, long int arg2, long int arg3);
}
extern long int syscall_1_asm (long int syscall_no, long int arg1);
extern long int syscall_2_asm (long int syscall_no, long int arg1, long int arg2);
extern long int syscall_3_asm (long int syscall_no, long int arg1, long int arg2, long int arg3);
/**
* System call with one argument.
*
* @return syscall's return value
*/
static __noinline long int
static __attr_noinline___ long int
syscall_1 (long int syscall_no, /**< syscall number */
long int arg1) /**< argument */
{
@@ -88,7 +80,7 @@ syscall_1 (long int syscall_no, /**< syscall number */
*
* @return syscall's return value
*/
static __noinline long int
static __attr_noinline___ long int
syscall_2 (long int syscall_no, /**< syscall number */
long int arg1, /**< first argument */
long int arg2) /**< second argument */
@@ -105,7 +97,7 @@ syscall_2 (long int syscall_no, /**< syscall number */
*
* @return syscall's return value
*/
static __noinline long int
static __attr_noinline___ long int
syscall_3 (long int syscall_no, /**< syscall number */
long int arg1, /**< first argument */
long int arg2, /**< second argument */
@@ -122,20 +114,36 @@ syscall_3 (long int syscall_no, /**< syscall number */
int
putchar (int c)
{
fwrite (&c, 1, sizeof (char), LIBC_STDOUT);
fwrite (&c, 1, sizeof (char), stdout);
return c;
} /* putchar */
/**
* Output specified string
*/
int
puts(const char *s) /**< string to print */
{
while (*s)
{
putchar (*s);
s++;
}
return 0;
} /* puts */
/**
* Exit - cause normal process termination with specified status code
*/
void __noreturn __used
void __attr_noreturn___ __attr_used___
exit (int status) /**< status code */
{
syscall_1 (__NR_close, (long int)LIBC_STDIN);
syscall_1 (__NR_close, (long int)LIBC_STDOUT);
syscall_1 (__NR_close, (long int)LIBC_STDERR);
syscall_1 (__NR_close, (long int)stdin);
syscall_1 (__NR_close, (long int)stdout);
syscall_1 (__NR_close, (long int)stderr);
syscall_1 (__NR_exit_group, status);
@@ -148,12 +156,12 @@ exit (int status) /**< status code */
/**
* fopen
*
* @return _FILE pointer - upon successful completion,
* @return FILE pointer - upon successful completion,
* NULL - otherwise
*/
_FILE*
FILE*
fopen (const char *path, /**< file path */
const char *mode) /**< file open mode */
const char *mode) /**< file open mode */
{
bool may_read = false;
bool may_write = false;
@@ -161,8 +169,8 @@ fopen (const char *path, /**< file path */
bool create_if_not_exist = false;
bool position_at_end = false;
JERRY_ASSERT(path != NULL && mode != NULL);
JERRY_ASSERT(mode[1] == '+' || mode[1] == '\0');
LIBC_ASSERT(path != NULL && mode != NULL);
LIBC_ASSERT(mode[1] == '+' || mode[1] == '\0');
switch (mode[0])
{
@@ -188,13 +196,13 @@ fopen (const char *path, /**< file path */
if (mode[1] == '+')
{
/* Not supported */
JERRY_UNREACHABLE();
LIBC_UNREACHABLE();
}
break;
}
default:
{
JERRY_UNREACHABLE();
LIBC_UNREACHABLE();
}
}
@@ -210,7 +218,7 @@ fopen (const char *path, /**< file path */
}
else
{
JERRY_ASSERT(may_read && may_write);
LIBC_ASSERT(may_read && may_write);
flags = O_RDWR;
}
@@ -240,7 +248,7 @@ fopen (const char *path, /**< file path */
* for the stream pointed to by STREAM to the beginning of the file.
*/
void
rewind (_FILE *stream) /**< stream pointer */
rewind (FILE *stream) /**< stream pointer */
{
syscall_3 (__NR_lseek, (long int) stream, 0, SEEK_SET);
} /* rewind */
@@ -252,7 +260,7 @@ rewind (_FILE *stream) /**< stream pointer */
* non-zero value - otherwise.
*/
int
fclose (_FILE *fp) /**< stream pointer */
fclose (FILE *fp) /**< stream pointer */
{
syscall_2 (__NR_close, (long int)fp, 0);
@@ -263,32 +271,12 @@ fclose (_FILE *fp) /**< stream pointer */
* fseek
*/
int
fseek (_FILE * fp, /**< stream pointer */
long offset, /**< offset */
_whence_t whence) /**< specifies position type
to add offset to */
fseek (FILE * fp, /**< stream pointer */
long offset, /**< offset */
int whence) /**< specifies position type
* to add offset to */
{
int whence_real = SEEK_CUR;
switch (whence)
{
case __SEEK_SET:
{
whence_real = SEEK_SET;
break;
}
case __SEEK_CUR:
{
whence_real = SEEK_CUR;
break;
}
case __SEEK_END:
{
whence_real = SEEK_END;
break;
}
}
syscall_3 (__NR_lseek, (long int)fp, offset, whence_real);
syscall_3 (__NR_lseek, (long int)fp, offset, whence);
return 0;
} /* fseek */
@@ -297,7 +285,7 @@ fseek (_FILE * fp, /**< stream pointer */
* ftell
*/
long
ftell (_FILE * fp) /**< stream pointer */
ftell (FILE * fp) /**< stream pointer */
{
long int ret = syscall_3 (__NR_lseek, (long int)fp, 0, SEEK_CUR);
@@ -311,9 +299,9 @@ ftell (_FILE * fp) /**< stream pointer */
*/
size_t
fread (void *ptr, /**< address of buffer to read to */
size_t size, /**< size of elements to read */
size_t nmemb, /**< number of elements to read */
_FILE *stream) /**< stream pointer */
size_t size, /**< size of elements to read */
size_t nmemb, /**< number of elements to read */
FILE *stream) /**< stream pointer */
{
long int ret;
size_t bytes_read = 0;
@@ -339,9 +327,9 @@ fread (void *ptr, /**< address of buffer to read to */
*/
size_t
fwrite (const void *ptr, /**< data to write */
size_t size, /**< size of elements to write */
size_t nmemb, /**< number of elements */
_FILE *stream) /**< stream pointer */
size_t size, /**< size of elements to write */
size_t nmemb, /**< number of elements */
FILE *stream) /**< stream pointer */
{
size_t bytes_written = 0;
@@ -359,6 +347,8 @@ fwrite (const void *ptr, /**< data to write */
return bytes_written;
} /* fwrite */
// FIXME
#if 0
/**
* Setup new memory limits
*/
@@ -382,19 +372,20 @@ jrt_set_mem_limits (size_t data_size, /**< limit for data + bss + brk heap */
#ifdef __TARGET_HOST_x64
ret = syscall_2 (__NR_setrlimit, RLIMIT_DATA, (intptr_t) &data_limit);
JERRY_ASSERT (ret == 0);
LIBC_ASSERT (ret == 0);
ret = syscall_2 (__NR_setrlimit, RLIMIT_STACK, (intptr_t) &stack_limit);
JERRY_ASSERT (ret == 0);
LIBC_ASSERT (ret == 0);
#elif defined (__TARGET_HOST_ARMv7)
ret = syscall_3 (__NR_prlimit64, 0, RLIMIT_DATA, (intptr_t) &data_limit);
JERRY_ASSERT (ret == 0);
LIBC_ASSERT (ret == 0);
ret = syscall_3 (__NR_prlimit64, 0, RLIMIT_STACK, (intptr_t) &stack_limit);
JERRY_ASSERT (ret == 0);
LIBC_ASSERT (ret == 0);
#elif defined (__TARGET_HOST_x86)
# error "__TARGET_HOST_x86 case is not implemented"
#else /* !__TARGET_HOST_x64 && !__TARGET_HOST_ARMv7 && !__TARGET_HOST_x86 */
# error "!__TARGET_HOST_x64 && !__TARGET_HOST_ARMv7 && !__TARGET_HOST_x86"
#endif /* !__TARGET_HOST_x64 && !__TARGET_HOST_ARMv7 && !__TARGET_HOST_x86 */
} /* jrt_set_mem_limits */
#endif // FIXME
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright 2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,27 +17,22 @@
* Jerry libc platform-specific functions stm32f4 implementation
*/
#include "jerry-libc.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
extern void __noreturn exit (int status);
#include "jerry-libc-defs.h"
/** Output of character. Writes the character c, cast to an unsigned char, to stdout. */
int
putchar (int c)
putchar (int c __attr_unused___)
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS("putchar is not implemented for STM32F3.", c);
return 1;
} /* putchar */
/** exit - cause normal process termination */
void __noreturn __used
exit (int status __unused)
void __attr_noreturn___ __attr_used___
exit (int status __attr_unused___)
{
/**
* TODO: Blink LEDs? status -> binary -> LEDs?
*/
while (true)
{
}
@@ -49,11 +44,11 @@ exit (int status __unused)
* @return number of bytes written
*/
size_t
fwrite (const void *ptr, /**< data to write */
size_t size, /**< size of elements to write */
size_t nmemb, /**< number of elements */
_FILE *stream) /**< stream pointer */
fwrite (const void *ptr __attr_unused___, /**< data to write */
size_t size, /**< size of elements to write */
size_t nmemb, /**< number of elements */
FILE *stream __attr_unused___) /**< stream pointer */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS("fwrite is not implemented for STM32F3.", ptr, size, nmemb, stream);
return size * nmemb;
} /* fwrite */
-59
View File
@@ -1,59 +0,0 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Jerry libc platform-specific functions stm32f4 implementation
*/
#include "jerry-libc.h"
#include <stdarg.h>
extern void __noreturn exit (int status);
/** Output of character. Writes the character c, cast to an unsigned char, to stdout. */
int
putchar (int c)
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS("putchar is not implemented for STM32F4.", c);
} /* putchar */
/** exit - cause normal process termination */
void __noreturn __used
exit (int status __unused)
{
/**
* TODO: Blink LEDs? status -> binary -> LEDs?
*/
while (true)
{
}
} /* exit */
/**
* fwrite
*
* @return number of bytes written
*/
size_t
fwrite (const void *ptr, /**< data to write */
size_t size, /**< size of elements to write */
size_t nmemb, /**< number of elements */
_FILE *stream) /**< stream pointer */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS("fwrite is not implemented for STM32F4.", ptr, size, nmemb, stream);
} /* fwrite */