diff --git a/.travis.yml b/.travis.yml index 7bd6a9f83..56bd0f46b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ matrix: - env: - JOBNAME="Linux/x86 (cpointer-32bit) Build & Correctness Tests" - - OPTS="--quiet --jerry-tests --jerry-test-suite --buildoptions=--jerry-libc=off,--compile-flag=-m32,--cpointer-32bit=on" + - OPTS="--quiet --jerry-tests --jerry-test-suite --buildoptions=--compile-flag=-m32,--cpointer-32bit=on" addons: apt: packages: [gcc-multilib] @@ -76,7 +76,7 @@ matrix: - env: - JOBNAME="ASAN Tests" - - OPTS="--quiet --jerry-tests --jerry-test-suite --skip-list=parser-oom.js --buildoptions=--compile-flag=-fsanitize=address,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--compile-flag=-O2,--debug,--jerry-libc=off,--system-allocator=on,--linker-flag=-fuse-ld=gold" + - OPTS="--quiet --jerry-tests --jerry-test-suite --skip-list=parser-oom.js --buildoptions=--compile-flag=-fsanitize=address,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--compile-flag=-O2,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold" - ASAN_OPTIONS=detect_stack_use_after_return=1:check_initialization_order=true:strict_init_order=true - TIMEOUT=600 compiler: gcc-5 @@ -87,7 +87,7 @@ matrix: - env: - JOBNAME="UBSAN Tests" - - OPTS="--quiet --jerry-tests --jerry-test-suite --skip-list=parser-oom.js --buildoptions=--compile-flag=-fsanitize=undefined,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--debug,--jerry-libc=off,--system-allocator=on,--linker-flag=-fuse-ld=gold" + - OPTS="--quiet --jerry-tests --jerry-test-suite --skip-list=parser-oom.js --buildoptions=--compile-flag=-fsanitize=undefined,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold" - UBSAN_OPTIONS=print_stacktrace=1 - TIMEOUT=600 compiler: gcc-5 diff --git a/CMakeLists.txt b/CMakeLists.txt index 6255daad6..c3713916d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ # limitations under the License. cmake_minimum_required (VERSION 2.8.12) -project (Jerry C ASM) +project (Jerry C) # Determining platform set(PLATFORM "${CMAKE_SYSTEM_NAME}") @@ -47,7 +47,6 @@ set(JERRY_CMDLINE_TEST OFF CACHE BOOL "Build jerry test command line tool?" set(JERRY_CMDLINE_SNAPSHOT OFF CACHE BOOL "Build jerry snapshot command line tool?") set(JERRY_PORT_DEFAULT ON CACHE BOOL "Build default jerry port implementation?") set(JERRY_EXT ON CACHE BOOL "Build jerry-ext?") -set(JERRY_LIBC ON CACHE BOOL "Build and use jerry-libc?") set(JERRY_LIBM ON CACHE BOOL "Build and use jerry-libm?") set(UNITTESTS OFF CACHE BOOL "Build unit tests?") set(DOCTESTS OFF CACHE BOOL "Build doc tests?") @@ -74,12 +73,10 @@ if(JERRY_CMDLINE OR DOCTESTS) endif() if("${PLATFORM}" STREQUAL "DARWIN") - set(JERRY_LIBC OFF) set(JERRY_LIBM OFF) set(ENABLE_LTO OFF) set(ENABLE_STRIP OFF) - set(JERRY_LIBC_MESSAGE " (FORCED BY PLATFORM)") set(JERRY_LIBM_MESSAGE " (FORCED BY PLATFORM)") set(ENABLE_LTO_MESSAGE " (FORCED BY PLATFORM)") set(ENABLE_STRIP_MESSAGE " (FORCED BY PLATFORM)") @@ -92,11 +89,9 @@ if(USING_TI) endif() if(USING_MSVC) - set(JERRY_LIBC OFF) set(JERRY_LIBM OFF) set(ENABLE_STRIP OFF) - set(JERRY_LIBC_MESSAGE " (FORCED BY COMPILER)") set(JERRY_LIBM_MESSAGE " (FORCED BY COMPILER)") set(ENABLE_STRIP_MESSAGE " (FORCED BY COMPILER)") endif() @@ -114,7 +109,6 @@ message(STATUS "JERRY_CMDLINE_TEST " ${JERRY_CMDLINE_TEST}) message(STATUS "JERRY_CMDLINE_SNAPSHOT " ${JERRY_CMDLINE_SNAPSHOT}) message(STATUS "JERRY_PORT_DEFAULT " ${JERRY_PORT_DEFAULT} ${JERRY_PORT_DEFAULT_MESSAGE}) message(STATUS "JERRY_EXT " ${JERRY_EXT} ${JERRY_EXT_MESSAGE}) -message(STATUS "JERRY_LIBC " ${JERRY_LIBC} ${JERRY_LIBC_MESSAGE}) message(STATUS "JERRY_LIBM " ${JERRY_LIBM} ${JERRY_LIBM_MESSAGE}) message(STATUS "UNITTESTS " ${UNITTESTS}) message(STATUS "DOCTESTS " ${DOCTESTS}) @@ -223,21 +217,12 @@ endif() # External compiler & linker flags if(DEFINED EXTERNAL_COMPILE_FLAGS) jerry_add_compile_flags(${EXTERNAL_COMPILE_FLAGS}) - jerry_add_flags(CMAKE_ASM_FLAGS "${EXTERNAL_COMPILE_FLAGS}") endif() if(DEFINED EXTERNAL_LINKER_FLAGS) jerry_add_link_flags(${EXTERNAL_LINKER_FLAGS}) endif() -# Jerry's libc -if(JERRY_LIBC) - # Turn off linking to compiler's default libc, in case jerry-libc is used - jerry_add_link_flags(-nostdlib) - - add_subdirectory(jerry-libc) -endif() - # Jerry's libm if(JERRY_LIBM) add_subdirectory(jerry-libm) diff --git a/docs/01.GETTING-STARTED.md b/docs/01.GETTING-STARTED.md index 3ff2ff36e..d1c593fb9 100644 --- a/docs/01.GETTING-STARTED.md +++ b/docs/01.GETTING-STARTED.md @@ -53,20 +53,20 @@ python tools/build.py --profile=es5.1|es2015-subset|minimal See also the related [README.md](https://github.com/jerryscript-project/jerryscript/blob/master/jerry-core/profiles/README.md). -**Use (jerry, compiler-default, external) libc** +**Use (compiler-default, external) libc** -The default libc is jerry-libc, but you can use compiler-default libc or an external libc: +The default libc is the compiler-default libc but you can use an external libc as well: - compiler-default libc: ```bash -python tools/build.py --jerry-libc=off +python tools/build.py ``` - external libc: ```bash -python tools/build.py --jerry-libc=off --compile-flag="-nostdlib -I/path/to/ext-libc/include" --link-lib="ext-c" +python tools/build.py --compile-flag="-nostdlib -I/path/to/ext-libc/include" --link-lib="ext-c" ``` **Add toolchain file** @@ -86,7 +86,7 @@ python tools/build.py --toolchain=cmake/toolchain_linux_armv7l.cmake **Use system memory allocator** ```bash -python tools/build.py --system-allocator=on --jerry-libc=off +python tools/build.py --system-allocator=on ``` *Note*: System allocator is only supported on 32 bit systems. diff --git a/docs/07.DEBUGGER.md b/docs/07.DEBUGGER.md index b55e75e22..5049a4f12 100644 --- a/docs/07.DEBUGGER.md +++ b/docs/07.DEBUGGER.md @@ -13,13 +13,11 @@ development environments. The following arguments must be passed to `tools/build.py`: -`--jerry-debugger=on --jerry-libc=off` +`--jerry-debugger=on` The transport layer of the communication protocol is pluggable. At the moment, a WebSocket-based implementation is provided as a JerryScript extension, which transmits messages over TCP/IP networks. -This implementation requires a socket API which is not yet -supported by jerry-libc so the standard libc is used instead. If necessary/implemented, any reliable stream or datagram based protocol can be used for transmitting debugger messages. diff --git a/jerry-core/CMakeLists.txt b/jerry-core/CMakeLists.txt index 70423afcd..fdec1c297 100644 --- a/jerry-core/CMakeLists.txt +++ b/jerry-core/CMakeLists.txt @@ -210,10 +210,6 @@ endif() # Enable debugger if(FEATURE_DEBUGGER) - if(JERRY_LIBC) - message(FATAL_ERROR "This configuration is not supported. Please build against your system libc to enable the JerryScript debugger.") - endif() - set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_DEBUGGER) endif() @@ -241,10 +237,6 @@ else() message(FATAL_ERROR "Profile file: '${FEATURE_PROFILE}' doesn't exist!") endif() -if(JERRY_LIBC AND FEATURE_SYSTEM_ALLOCATOR) - MESSAGE(FATAL_ERROR "This configuration is not supported. Please build against your system libc to enable the system allocator.") -endif() - # RegExp strict mode if(FEATURE_REGEXP_STRICT_MODE) set(DEFINES_JERRY ${DEFINES_JERRY} ENABLE_REGEXP_STRICT_MODE) @@ -295,10 +287,6 @@ if(JERRY_LIBM) target_link_libraries(${JERRY_CORE_NAME} jerry-libm) endif() -if(JERRY_LIBC) - target_link_libraries(${JERRY_CORE_NAME} jerry-libc) -endif() - separate_arguments(EXTERNAL_LINK_LIBS) foreach(EXT_LIB ${EXTERNAL_LINK_LIBS}) target_link_libraries(${JERRY_CORE_NAME} ${EXT_LIB}) diff --git a/jerry-libc/CMakeLists.txt b/jerry-libc/CMakeLists.txt deleted file mode 100644 index 71be07103..000000000 --- a/jerry-libc/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright JS Foundation and other contributors, http://js.foundation -# -# 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) -set(JERRY_LIBC_NAME jerry-libc) -project (${JERRY_LIBC_NAME} C ASM) - -# Checks the optional features -# Enable init/fini arrays -if(FEATURE_INIT_FINI) - set(DEFINES_LIBC ${DEFINES_LIBC} ENABLE_INIT_FINI) -endif() - -# Include directories -set(INCLUDE_LIBC "${CMAKE_CURRENT_SOURCE_DIR}") - -# Sources -file(GLOB SOURCE_LIBC *.c) - -# Platform-specific -# Linux -if(DEFINED PLATFORM AND ((PLATFORM STREQUAL "LINUX") OR (PLATFORM STREQUAL "DARWIN"))) - file(GLOB TARGET_SPECIFIC_LIBC_SOURCE target/posix/*.c target/posix/*.S) -endif() - -add_library(${JERRY_LIBC_NAME} ${SOURCE_LIBC} ${TARGET_SPECIFIC_LIBC_SOURCE}) - -target_compile_definitions(${JERRY_LIBC_NAME} PRIVATE ${DEFINES_LIBC}) -target_include_directories(${JERRY_LIBC_NAME} PRIVATE ${INCLUDE_LIBC}) -target_include_directories(${JERRY_LIBC_NAME} SYSTEM PUBLIC "${CMAKE_SOURCE_DIR}/jerry-libc/include") -target_link_libraries(${JERRY_LIBC_NAME} -lgcc) - -install(TARGETS ${JERRY_LIBC_NAME} DESTINATION lib) -install(DIRECTORY ${INCLUDE_LIBC}/include/ DESTINATION include/jerry-libc) diff --git a/jerry-libc/arch/arm-v7.h b/jerry-libc/arch/arm-v7.h deleted file mode 100644 index eb665a644..000000000 --- a/jerry-libc/arch/arm-v7.h +++ /dev/null @@ -1,192 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 ASM_ARM_H -#define ASM_ARM_H - -/* - * mov syscall_no (%r0) -> %r7 - * svc #0 - */ -#define SYSCALL_0 \ - push {r4-r12, lr}; \ - \ - mov r7, r0; \ - \ - svc #0; \ - \ - pop {r4-r12, pc}; - -/* - * mov syscall_no (%r0) -> %r7 - * mov arg1 (%r1) -> %r0 - * svc #0 - */ -#define SYSCALL_1 \ - push {r4-r12, lr}; \ - \ - mov r7, r0; \ - mov r0, r1; \ - \ - svc #0; \ - \ - pop {r4-r12, pc}; - -/* - * mov syscall_no (%r0) -> %r7 - * mov arg1 (%r1) -> %r0 - * mov arg2 (%r2) -> %r1 - * svc #0 - */ -#define SYSCALL_2 \ - push {r4-r12, lr}; \ - \ - mov r7, r0; \ - mov r0, r1; \ - mov r1, r2; \ - \ - svc #0; \ - \ - pop {r4-r12, pc}; - -/* - * mov syscall_no (%r0) -> %r7 - * mov arg1 (%r1) -> %r0 - * mov arg2 (%r2) -> %r1 - * mov arg3 (%r3) -> %r2 - * svc #0 - */ -#define SYSCALL_3 \ - push {r4-r12, lr}; \ - \ - mov r7, r0; \ - mov r0, r1; \ - mov r1, r2; \ - mov r2, r3; \ - \ - svc #0; \ - \ - pop {r4-r12, pc}; - -#ifdef ENABLE_INIT_FINI -/* - * bl libc_init_array - */ -#define _INIT \ - bl libc_init_array; -#else /* !ENABLE_INIT_FINI */ -#define _INIT -#endif /* ENABLE_INIT_FINI */ - -/* - * bl libc_init_array - * - * ldr argc ([sp + 0x0]) -> r0 - * add argv (sp + 0x4) -> r1 - * bl main - * - * bl exit - * - * infinite loop - */ -#define _START \ - _INIT; \ - \ - ldr r0, [sp, #0]; \ - add r1, sp, #4; \ - bl main; \ - \ - bl exit; \ - 1: \ - b 1b; - -/** - * If hard-float mode: - * store s16-s31 vfp registers to buffer, pointed with r0 register, - * and increase the register on size of stored data. - */ -#if defined (__VFP_FP__) && !defined (__SOFTFP__) -# define _STORE_VFP_S16_S31_IF_HARD_FLOAT \ - vstm r0!, {s16 - s31}; -# define _LOAD_VFP_S16_S31_IF_HARD_FLOAT \ - vldm r0!, {s16 - s31}; -#else /* !__VFP_FP__ || __SOFTFP__ */ -# define _STORE_VFP_S16_S31_IF_HARD_FLOAT -# define _LOAD_VFP_S16_S31_IF_HARD_FLOAT -#endif /* __VFP_FP__ && !__SOFTFP__ */ - -/* - * setjmp - * - * According to procedure call standard for the ARM architecture, the following - * registers are callee-saved, and so need to be stored in context: - * - r4 - r11 - * - sp - * - s16 - s31 - * - * Also, we should store: - * - lr - * - * stmia {r4-r11, sp, lr} -> jmp_buf_0 (r0)! - * - * If hard-float build - * vstm {s16-s31} -> jmp_buf_32 (r0)! - * - * mov r0, #0 - * - * bx lr - */ -#define _SETJMP \ - stmia r0!, {r4 - r11, sp, lr}; \ - \ - _STORE_VFP_S16_S31_IF_HARD_FLOAT \ - \ - mov r0, #0; \ - \ - bx lr; - -/* - * longjmp - * - * See also: - * _SETJMP - * - * ldmia jmp_buf_0 (r0)! -> {r4-r11, sp, lr} - * - * If hard-float build - * vldm jmp_buf_32 (r0)! -> {s16-s31} - * - * mov r1 -> r0 - * cmp r0, #0 - * bne 1f - * mov #1 -> r0 - * 1: - * - * bx lr - */ -#define _LONGJMP \ - ldmia r0!, {r4 - r11, sp, lr}; \ - \ - _LOAD_VFP_S16_S31_IF_HARD_FLOAT \ - \ - mov r0, r1; \ - cmp r0, #0; \ - bne 1f; \ - mov r0, #1; \ - 1: \ - \ - bx lr; - -#endif /* !ASM_ARM_H */ diff --git a/jerry-libc/arch/x86-32.h b/jerry-libc/arch/x86-32.h deleted file mode 100644 index c674f4a92..000000000 --- a/jerry-libc/arch/x86-32.h +++ /dev/null @@ -1,227 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 ASM_X86_H -#define ASM_X86_H - -/* - * mov syscall_no -> %eax - * int $0x80 - * mov %eax -> ret - */ -#define SYSCALL_0 \ - push %edi; \ - push %esi; \ - push %ebx; \ - mov 0x10 (%esp), %eax; \ - int $0x80; \ - pop %ebx; \ - pop %esi; \ - pop %edi; \ - ret; - -/* - * mov syscall_no -> %eax - * mov arg1 -> %ebx - * int $0x80 - * mov %eax -> ret - */ -#define SYSCALL_1 \ - push %edi; \ - push %esi; \ - push %ebx; \ - mov 0x10 (%esp), %eax; \ - mov 0x14 (%esp), %ebx; \ - int $0x80; \ - pop %ebx; \ - pop %esi; \ - pop %edi; \ - ret; - -/* - * mov syscall_no -> %eax - * mov arg1 -> %ebx - * mov arg2 -> %ecx - * int $0x80 - * mov %eax -> ret - */ -#define SYSCALL_2 \ - push %edi; \ - push %esi; \ - push %ebx; \ - mov 0x10 (%esp), %eax; \ - mov 0x14 (%esp), %ebx; \ - mov 0x18 (%esp), %ecx; \ - int $0x80; \ - pop %ebx; \ - pop %esi; \ - pop %edi; \ - ret; - -/* - * mov syscall_no -> %eax - * mov arg1 -> %ebx - * mov arg2 -> %ecx - * mov arg3 -> %edx - * int $0x80 - * mov %eax -> ret - */ -#define SYSCALL_3 \ - push %edi; \ - push %esi; \ - push %ebx; \ - mov 0x10 (%esp), %eax; \ - mov 0x14 (%esp), %ebx; \ - mov 0x18 (%esp), %ecx; \ - mov 0x1c (%esp), %edx; \ - int $0x80; \ - pop %ebx; \ - pop %esi; \ - pop %edi; \ - ret; - -#ifdef ENABLE_INIT_FINI -/* - * call libc_init_array - */ -#define _INIT \ - call libc_init_array; -#else /* !ENABLE_INIT_FINI */ -#define _INIT -#endif /* ENABLE_INIT_FINI */ - -/* - * call libc_init_array - * - * push argv (%esp + 4) - * push argc ([%esp + 0x4]) - * - * call main - * - * push main_ret (%eax) - * call exit - * - * infinite loop - */ -#define _START \ - _INIT; \ - \ - mov %esp, %eax; \ - add $4, %eax; \ - push %eax; \ - mov 0x4 (%esp), %eax; \ - push %eax; \ - \ - call main; \ - \ - push %eax; \ - call exit; \ - \ - 1: \ - jmp 1b; - -/* - * setjmp - * - * According to x86_32 System V ABI, the following registers are - * callee-saved, and so need to be stored in context: - * - %ebx - * - %esp - * - %ebp - * - %esi - * - %edi - * - x87 control word - * - * Also, we should store: - * - return address (to jump to upon longjmp) - * - * mov return_address ([%esp]) -> %eax - * - * mov env ([%esp + 0x4]) -> %edx - * - * mov %ebx -> jmp_buf_0 ([%edx + 0x0]) - * mov %esp -> jmp_buf_4 ([%edx + 0x4]) - * mov %ebp -> jmp_buf_8 ([%edx + 0x8]) - * mov %esi -> jmp_buf_12 ([%edx + 0xc]) - * mov %edi -> jmp_buf_16 ([%edx + 0x10]) - * mov %eax -> jmp_buf_20 ([%edx + 0x14]) - * fnstcw -> jmp_buf_24 ([%edx + 0x18]) - * - * ret - */ -#define _SETJMP \ - mov (%esp), %eax; \ - mov 0x4 (%esp), %edx; \ - \ - mov %ebx, 0x00 (%edx); \ - mov %esp, 0x04 (%edx); \ - mov %ebp, 0x08 (%edx); \ - mov %esi, 0x0c (%edx); \ - mov %edi, 0x10 (%edx); \ - mov %eax, 0x14 (%edx); \ - fnstcw 0x18 (%edx); \ - \ - xor %eax, %eax; \ - \ - ret - -/* - * longjmp - * - * See also: - * _SETJMP - * - * mov env ([%esp + 0x4]) -> %edx - * mov val ([%esp + 0x8]) -> %eax - * - * mov jmp_buf_0 ([%edx + 0x0]) -> %ebx - * mov jmp_buf_4 ([%edx + 0x8]) -> %esp - * mov jmp_buf_8 ([%edx + 0x10]) -> %ebp - * mov jmp_buf_12 ([%edx + 0x18]) -> %esi - * mov jmp_buf_16 ([%edx + 0x20]) -> %edi - * mov jmp_buf_20 ([%edx + 0x28]) -> %ecx - * fldcw jmp_buf_24 ([%edx + 0x30]) - * - * mov return_address (%ecx) -> ([%esp]) - * - * cmp (%eax), 0x0 - * jnz 1f - * xor %eax, %eax - * 1: - * - * ret - */ -#define _LONGJMP \ - mov 0x4 (%esp), %edx; \ - mov 0x8 (%esp), %eax; \ - \ - mov 0x0 (%edx), %ebx; \ - mov 0x4 (%edx), %esp; \ - mov 0x8 (%edx), %ebp; \ - mov 0xc (%edx), %esi; \ - mov 0x10 (%edx), %edi; \ - mov 0x14 (%edx), %ecx; \ - fldcw 0x18 (%edx); \ - \ - mov %ecx, (%esp); \ - \ - test %eax, %eax; \ - jnz 1f; \ - xor %eax, %eax; \ - 1: \ - \ - ret - -#endif /* !ASM_X86_H */ diff --git a/jerry-libc/arch/x86-64.h b/jerry-libc/arch/x86-64.h deleted file mode 100644 index 5a35d021b..000000000 --- a/jerry-libc/arch/x86-64.h +++ /dev/null @@ -1,202 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 ASM_X64_H -#define ASM_X64_H - -/* - * mov syscall_no (%rdi) -> %rax - * syscall - */ -#define SYSCALL_0 \ - mov %rdi, %rax; \ - syscall; \ - ret; - -/* - * mov syscall_no (%rdi) -> %rax - * mov arg1 (%rsi) -> %rdi - * syscall - */ -#define SYSCALL_1 \ - mov %rdi, %rax; \ - mov %rsi, %rdi; \ - syscall; \ - ret; - -/* - * mov syscall_no (%rdi) -> %rax - * mov arg1 (%rsi) -> %rdi - * mov arg2 (%rdx) -> %rsi - * syscall - */ -#define SYSCALL_2 \ - mov %rdi, %rax; \ - mov %rsi, %rdi; \ - mov %rdx, %rsi; \ - syscall; \ - ret; - -/* - * mov syscall_no (%rdi) -> %rax - * mov arg1 (%rsi) -> %rdi - * mov arg2 (%rdx) -> %rsi - * mov arg3 (%rcx) -> %rdx - * syscall - */ -#define SYSCALL_3 \ - mov %rdi, %rax; \ - mov %rsi, %rdi; \ - mov %rdx, %rsi; \ - mov %rcx, %rdx; \ - syscall; \ - ret; - -#ifdef ENABLE_INIT_FINI -/* - * call libc_init_array - */ -#define _INIT \ - call libc_init_array; -#else /* !ENABLE_INIT_FINI */ -#define _INIT -#endif /* ENABLE_INIT_FINI */ - -/* - * call libc_init_array - * - * mov argc ([%rsp]) -> %rdi - * mov argv (%rsp + 0x8) -> %rsi - * - * call main - * - * mov main_ret (%rax) -> %rdi - * call exit - * - * infinite loop - */ -#define _START \ - _INIT; \ - \ - mov (%rsp), %rdi; \ - mov %rsp, %rsi; \ - add $8, %rsi; \ - callq main; \ - \ - mov %rax, %rdi; \ - callq exit; \ - 1: \ - jmp 1b; - -/* - * setjmp - * - * According to x86_64 System V ABI, the following registers are - * callee-saved, and so need to be stored in context: - * - %rbp - * - %rbx - * - %r12 - * - %r13 - * - %r14 - * - %r15 - * - x87 control word - * - * Also, we should store: - * - %rsp (stack pointer) - * - return address (to jump to upon longjmp) - * - * mov return_address ([%rsp]) -> %rax - * - * mov %rsp -> jmp_buf_0 ([%rdi + 0x0]) - * mov %rax -> jmp_buf_8 ([%rdi + 0x8]) - * mov %rbp -> jmp_buf_16 ([%rdi + 0x10]) - * mov %rbx -> jmp_buf_24 ([%rdi + 0x18]) - * mov %r12 -> jmp_buf_32 ([%rdi + 0x20]) - * mov %r13 -> jmp_buf_40 ([%rdi + 0x28]) - * mov %r14 -> jmp_buf_48 ([%rdi + 0x30]) - * mov %r15 -> jmp_buf_56 ([%rdi + 0x38]) - * fnstcw -> jmp_buf_64 ([%rdi + 0x40]) - * - * ret - */ -#define _SETJMP \ - mov (%rsp), %rax; \ - \ - mov %rsp, 0x00(%rdi); \ - mov %rax, 0x08(%rdi); \ - mov %rbp, 0x10(%rdi); \ - mov %rbx, 0x18(%rdi); \ - mov %r12, 0x20(%rdi); \ - mov %r13, 0x28(%rdi); \ - mov %r14, 0x30(%rdi); \ - mov %r15, 0x38(%rdi); \ - fnstcw 0x40(%rdi); \ - \ - xor %rax, %rax; \ - \ - ret; - -/* - * longjmp - * - * See also: - * _SETJMP - * - * mov jmp_buf_0 ([%rdi + 0x0]) -> %rsp - * mov jmp_buf_8 ([%rdi + 0x8]) -> %rax - * mov jmp_buf_16 ([%rdi + 0x10]) -> %rbp - * mov jmp_buf_24 ([%rdi + 0x18]) -> %rbx - * mov jmp_buf_32 ([%rdi + 0x20]) -> %r12 - * mov jmp_buf_40 ([%rdi + 0x28]) -> %r13 - * mov jmp_buf_48 ([%rdi + 0x30]) -> %r14 - * mov jmp_buf_56 ([%rdi + 0x38]) -> %r15 - * fldcw jmp_buf_64 ([%rdi + 0x40]) - * - * mov return_address (%rax) -> ([%rsp]) - * - * mov val (%rsi) -> %rax - * - * test (%rax), (%rax) - * jnz 1f - * mov $1, %rax - * 1: - * - * ret - */ -#define _LONGJMP \ - mov 0x00(%rdi), %rsp; \ - mov 0x08(%rdi), %rax; \ - mov 0x10(%rdi), %rbp; \ - mov 0x18(%rdi), %rbx; \ - mov 0x20(%rdi), %r12; \ - mov 0x28(%rdi), %r13; \ - mov 0x30(%rdi), %r14; \ - mov 0x38(%rdi), %r15; \ - fldcw 0x40(%rdi); \ - \ - mov %rax, (%rsp); \ - \ - mov %rsi, %rax; \ - \ - test %rax, %rax; \ - jnz 1f; \ - mov $1, %rax; \ - 1: \ - \ - ret - - - -#endif /* !ASM_X64_H */ diff --git a/jerry-libc/include/assert.h b/jerry-libc/include/assert.h deleted file mode 100644 index 8e4384967..000000000 --- a/jerry-libc/include/assert.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 JERRY_LIBC_ASSERT_H -#define JERRY_LIBC_ASSERT_H - -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -#ifndef NDEBUG -#define assert(x) \ - do \ - { \ - if (!(x)) \ - { \ - fprintf (stderr, "%s:%d: %s: Assertion `%s' failed.", __FILE__, __LINE__, __func__, #x); \ - abort (); \ - } \ - } while (0) -#else /* NDEBUG */ -#define assert(x) ((void) 0) -#endif /* !NDEBUG */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRY_LIBC_ASSERT_H */ diff --git a/jerry-libc/include/setjmp.h b/jerry-libc/include/setjmp.h deleted file mode 100644 index ce5961c9b..000000000 --- a/jerry-libc/include/setjmp.h +++ /dev/null @@ -1,64 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 JERRY_LIBC_SETJMP_H -#define JERRY_LIBC_SETJMP_H - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** - * Storage for context, used for nonlocal goto - * - * x86_64 (8 * 8 + 2 bytes): - * 0x00 - %rsp - * 0x08 - return address - * 0x10 - %rbp - * 0x18 - %rbx - * 0x20 - %r12 - * 0x28 - %r13 - * 0x30 - %r14 - * 0x38 - %r15 - * 0x40 - x87 control word - * - * x86_32 (6 * 4 + 2 bytes): - * - %ebx - * - %esp - * - %ebp - * - %esi - * - %edi - * - return address (to jump to upon longjmp) - * - x87 control word - * - * ARMv7 (10 * 4 + 16 * 4 bytes): - * - r4 - r11, sp, lr - * - s16 - s31 (if hardfp enabled) - * - * See also: - * setjmp, longjmp - */ -typedef uint64_t jmp_buf[14]; - -int setjmp (jmp_buf env); -void longjmp (jmp_buf env, int val); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRY_LIBC_SETJMP_H */ diff --git a/jerry-libc/include/stdio.h b/jerry-libc/include/stdio.h deleted file mode 100644 index 9ff331e94..000000000 --- a/jerry-libc/include/stdio.h +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 JERRY_LIBC_STDIO_H -#define JERRY_LIBC_STDIO_H - -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** - * File descriptor type - */ -typedef void FILE; - -/** - * Standard file descriptors - */ -extern FILE *stdin; -extern FILE *stdout; -extern FILE *stderr; - -/** - * I/O routines - */ -int vfprintf (FILE *stream, const char *format, va_list ap); -FILE *fopen (const char *path, const char *mode); -int fclose (FILE *fp); -size_t fread (void *ptr, size_t size, size_t nmemb, FILE *stream); -size_t fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream); -int printf (const char *format, ...); -int fprintf (FILE *stream, const char *format, ...); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRY_LIBC_STDIO_H */ diff --git a/jerry-libc/include/stdlib.h b/jerry-libc/include/stdlib.h deleted file mode 100644 index 4682af8d5..000000000 --- a/jerry-libc/include/stdlib.h +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 JERRY_LIBC_STDLIB_H -#define JERRY_LIBC_STDLIB_H - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** - * Maximum integer that could be returned by random number generator - * - * See also: - * rand - */ -#define RAND_MAX (0x7fffffffu) - -void __attribute__ ((noreturn)) exit (int); -void __attribute__ ((noreturn)) abort (void); -int rand (void); -void srand (unsigned int); -long int strtol (const char *, char **, int); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRY_LIBC_STDLIB_H */ diff --git a/jerry-libc/include/string.h b/jerry-libc/include/string.h deleted file mode 100644 index 057654070..000000000 --- a/jerry-libc/include/string.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 JERRY_LIBC_STRING_H -#define JERRY_LIBC_STRING_H - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -void *memcpy (void *dest, const void *src, size_t n); -void *memset (void *s, int c, size_t n); -void *memmove (void *dest, const void *src, size_t n); -int memcmp (const void *s1, const void *s2, size_t n); -int strcmp (const char *s1, const char *s2); -int strncmp (const char *s1, const char *s2, size_t n); -char *strncpy (char *dest, const char *src, size_t n); -size_t strlen (const char *s); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRY_LIBC_STRING_H */ diff --git a/jerry-libc/include/sys/time.h b/jerry-libc/include/sys/time.h deleted file mode 100644 index a20cba0aa..000000000 --- a/jerry-libc/include/sys/time.h +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 JERRY_LIBC_TIME_H -#define JERRY_LIBC_TIME_H - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -/** - * Time value structure - */ -struct timeval -{ - unsigned long tv_sec; /**< seconds */ - unsigned long tv_usec; /**< microseconds */ -}; - -/** - * Timezone structure - */ -struct timezone -{ - int tz_minuteswest; /**< minutes west of Greenwich */ - int tz_dsttime; /**< type of DST correction */ -}; - -int gettimeofday (void *tp, void *tzp); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* !JERRY_LIBC_TIME_H */ diff --git a/jerry-libc/jerry-libc-defs.h b/jerry-libc/jerry-libc-defs.h deleted file mode 100644 index 3a61a9361..000000000 --- a/jerry-libc/jerry-libc-defs.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 -#include -#include - -/** - * Attributes - */ -#define __attr_unused___ __attribute__((unused)) -#define __attr_used___ __attribute__((used)) -#define __attr_noreturn___ __attribute__((noreturn)) -#define __attr_noinline___ __attribute__((noinline)) -#define __attr_weak___ __attribute__((weak)) - -#ifdef ENABLE_INIT_FINI -void libc_init_array (void); -void libc_fini_array (void); -#endif /* ENABLE_INIT_FINI */ - -#endif /* !DEFS_H */ diff --git a/jerry-libc/jerry-libc-init.c b/jerry-libc/jerry-libc-init.c deleted file mode 100644 index 3d346662f..000000000 --- a/jerry-libc/jerry-libc-init.c +++ /dev/null @@ -1,98 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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. - * - * This file is based on work under the following copyright and permission - * notice: - * - * Copyright (C) 2004 CodeSourcery, LLC - * - * Permission to use, copy, modify, and distribute this file - * for any purpose is hereby granted without fee, provided that - * the above copyright notice and this notice appears in all - * copies. - * - * This file is distributed WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - */ - -#include "jerry-libc-defs.h" - -#ifdef ENABLE_INIT_FINI - -/* These magic symbols are provided by the linker. */ -typedef void (*libc_init_fn_t) (void); - -extern libc_init_fn_t __preinit_array_start[] __attr_weak___; -extern libc_init_fn_t __preinit_array_end[] __attr_weak___; -extern libc_init_fn_t __init_array_start[] __attr_weak___; -extern libc_init_fn_t __init_array_end[] __attr_weak___; -extern libc_init_fn_t __fini_array_start[] __attr_weak___; -extern libc_init_fn_t __fini_array_end[] __attr_weak___; -extern void _init (void); -extern void _fini (void); - - -/** - * No-op default _init. - */ -void __attr_weak___ -_init (void) -{ -} /* _init */ - -/** - * No-op default _fini. - */ -void __attr_weak___ -_fini (void) -{ -} /* _fini */ - -/** - * Iterate over all the init routines. - */ -void -libc_init_array (void) -{ - size_t count = (size_t) (__preinit_array_end - __preinit_array_start); - for (size_t i = 0; i < count; i++) - { - __preinit_array_start[i] (); - } - - _init (); - - count = (size_t) (__init_array_end - __init_array_start); - for (size_t i = 0; i < count; i++) - { - __init_array_start[i] (); - } -} /* libc_init_array */ - -/** - * Run all the cleanup routines. - */ -void -libc_fini_array (void) -{ - size_t count = (size_t) (__fini_array_end - __fini_array_start); - for (size_t i = count; i > 0; i--) - { - __fini_array_start[i - 1] (); - } - - _fini (); -} /* libc_fini_array */ - -#endif /* ENABLE_INIT_FINI */ diff --git a/jerry-libc/jerry-libc-printf.c b/jerry-libc/jerry-libc-printf.c deleted file mode 100644 index a7868398d..000000000 --- a/jerry-libc/jerry-libc-printf.c +++ /dev/null @@ -1,756 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 printf implementation - */ - -#include -#include -#include -#include - -#include "jerry-libc-defs.h" - -/** - * printf's length type - */ -typedef enum -{ - LIBC_PRINTF_ARG_LENGTH_TYPE_NONE, /**< (none) */ - LIBC_PRINTF_ARG_LENGTH_TYPE_HH, /**< hh */ - LIBC_PRINTF_ARG_LENGTH_TYPE_H, /**< h */ - LIBC_PRINTF_ARG_LENGTH_TYPE_L, /**< l */ - LIBC_PRINTF_ARG_LENGTH_TYPE_LL, /**< ll */ - LIBC_PRINTF_ARG_LENGTH_TYPE_J, /**< j */ - LIBC_PRINTF_ARG_LENGTH_TYPE_Z, /**< z */ - LIBC_PRINTF_ARG_LENGTH_TYPE_T, /**< t */ - LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL /**< L */ -} libc_printf_arg_length_type_t; - -/** - * printf's flags mask - */ -typedef uint8_t libc_printf_arg_flags_mask_t; - -/** - * Left justification of field's contents - */ -#define LIBC_PRINTF_ARG_FLAG_LEFT_JUSTIFY (1 << 0) - -/** - * Force print of number's sign - */ -#define LIBC_PRINTF_ARG_FLAG_PRINT_SIGN (1 << 1) - -/** - * If no sign is printed, print space before value - */ -#define LIBC_PRINTF_ARG_FLAG_SPACE (1 << 2) - -/** - * For o, x, X preceed value with 0, 0x or 0X for non-zero values. - */ -#define LIBC_PRINTF_ARG_FLAG_SHARP (1 << 3) - -/** - * Left-pad field with zeroes instead of spaces - */ -#define LIBC_PRINTF_ARG_FLAG_ZERO_PADDING (1 << 4) - -/** - * printf helper function that outputs a char - */ -static void -libc_printf_putchar (FILE *stream, /**< stream pointer */ - char character) /**< character */ -{ - fwrite (&character, 1, sizeof (character), stream); -} /* libc_printf_putchar */ - -/** - * printf helper function that outputs justified string - */ -static void -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) */ - bool is_zero_padding) /**< left-pad with zeroes (true) or spaces (false) */ -{ - const size_t str_length = strlen (string_p); - - size_t outputted_length = 0; - - if (!is_left_justify) - { - char padding_char = is_zero_padding ? '0' : ' '; - - while (outputted_length + str_length < width) - { - libc_printf_putchar (stream, padding_char); - outputted_length++; - } - } - - fwrite (string_p, 1, str_length * sizeof (*string_p), stream); - outputted_length += str_length; - - if (is_left_justify) - { - while (outputted_length < width) - { - libc_printf_putchar (stream, ' '); - outputted_length++; - } - } -} /* libc_printf_justified_string_output */ - -/** - * printf helper function that converts unsigned integer to string - * - * @return start of the string representation (within the output string buffer - * but not necessarily at its start) - */ -static char * -libc_printf_uint_to_string (uintmax_t value, /**< integer value */ - char *buffer_p, /**< buffer for output string */ - size_t buffer_size, /**< buffer size */ - const char *alphabet, /**< alphabet used for digits */ - uint32_t radix) /**< radix */ -{ - char *str_buffer_end = buffer_p + buffer_size; - char *str_p = str_buffer_end; - *--str_p = '\0'; - - assert (radix >= 2); - - if ((radix & (radix - 1)) != 0) - { - /* - * Radix is not power of 2. Only 32-bit numbers are supported in this mode. - */ - assert ((value >> 32) == 0); - - uint32_t value_lo = (uint32_t) value; - - while (value_lo != 0) - { - assert (str_p != buffer_p); - - *--str_p = alphabet[ value_lo % radix ]; - value_lo /= radix; - } - } - else - { - uint32_t shift = 0; - while (!(radix & (1u << shift))) - { - shift++; - - assert (shift <= 32); - } - - uint32_t value_lo = (uint32_t) value; - uint32_t value_hi = (uint32_t) (value >> 32); - - while (value_lo != 0 - || value_hi != 0) - { - assert (str_p != buffer_p); - - *--str_p = alphabet[ value_lo & (radix - 1) ]; - value_lo >>= shift; - value_lo += (value_hi & (radix - 1)) << (32 - shift); - value_hi >>= shift; - } - } - - if (*str_p == '\0') - { - *--str_p = '0'; - } - - assert (str_p >= buffer_p && str_p < str_buffer_end); - - return str_p; -} /* libc_printf_uint_to_string */ - -/** - * printf helper function that prints d and i arguments - * - * @return updated va_list - */ -static void -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 */ -{ - assert ((flags & LIBC_PRINTF_ARG_FLAG_SHARP) == 0); - - bool is_signed = true; - uintmax_t value = 0; - - /* true - positive, false - negative */ - bool sign = true; - const size_t bits_in_byte = 8; - const uintmax_t value_sign_mask = ((uintmax_t) 1) << (sizeof (value) * bits_in_byte - 1); - - switch (length) - { - case LIBC_PRINTF_ARG_LENGTH_TYPE_NONE: - case LIBC_PRINTF_ARG_LENGTH_TYPE_HH: /* char is promoted to int */ - case LIBC_PRINTF_ARG_LENGTH_TYPE_H: /* short int is promoted to int */ - { - value = (uintmax_t) va_arg (*args_list_p, int); - break; - } - - case LIBC_PRINTF_ARG_LENGTH_TYPE_L: - { - value = (uintmax_t) va_arg (*args_list_p, long int); - break; - } - - case LIBC_PRINTF_ARG_LENGTH_TYPE_LL: - { - value = (uintmax_t) va_arg (*args_list_p, long long int); - break; - } - - case LIBC_PRINTF_ARG_LENGTH_TYPE_J: - { - value = (uintmax_t) va_arg (*args_list_p, intmax_t); - break; - } - - case LIBC_PRINTF_ARG_LENGTH_TYPE_Z: - { - is_signed = false; - value = (uintmax_t) va_arg (*args_list_p, size_t); - break; - } - - case LIBC_PRINTF_ARG_LENGTH_TYPE_T: - { - is_signed = false; - value = (uintmax_t) va_arg (*args_list_p, ptrdiff_t); - break; - } - - case LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL: - { - assert (false && "unsupported length field L"); - } - } - - if (is_signed) - { - sign = ((value & value_sign_mask) == 0); - - if (!sign) - { - value = (uintmax_t) (-value); - } - } - - char str_buffer[ 32 ]; - char *string_p = libc_printf_uint_to_string (value, - str_buffer, - sizeof (str_buffer), - "0123456789", - 10); - - if (!sign - || (flags & LIBC_PRINTF_ARG_FLAG_PRINT_SIGN)) - { - assert (string_p > str_buffer); - *--string_p = (sign ? '+' : '-'); - } - else if (flags & LIBC_PRINTF_ARG_FLAG_SPACE) - { - /* no sign and space flag, printing one space */ - - libc_printf_putchar (stream, ' '); - if (width > 0) - { - width--; - } - } - - libc_printf_justified_string_output (stream, - string_p, - width, - flags & LIBC_PRINTF_ARG_FLAG_LEFT_JUSTIFY, - flags & LIBC_PRINTF_ARG_FLAG_ZERO_PADDING); -} /* libc_printf_write_d_i */ - -/** - * printf helper function that prints d and i arguments - * - * @return updated va_list - */ -static void -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 */ - libc_printf_arg_length_type_t length, /**< field's length type */ - uint32_t width) /**< minimum field width to output */ -{ - uintmax_t value; - - switch (length) - { - case LIBC_PRINTF_ARG_LENGTH_TYPE_NONE: - case LIBC_PRINTF_ARG_LENGTH_TYPE_HH: /* char is promoted to int */ - case LIBC_PRINTF_ARG_LENGTH_TYPE_H: /* short int is promoted to int */ - { - value = (uintmax_t) va_arg (*args_list_p, unsigned int); - break; - } - - case LIBC_PRINTF_ARG_LENGTH_TYPE_L: - { - value = (uintmax_t) va_arg (*args_list_p, unsigned long int); - break; - } - - case LIBC_PRINTF_ARG_LENGTH_TYPE_LL: - { - value = (uintmax_t) va_arg (*args_list_p, unsigned long long int); - break; - } - - case LIBC_PRINTF_ARG_LENGTH_TYPE_J: - { - value = (uintmax_t) va_arg (*args_list_p, uintmax_t); - break; - } - - case LIBC_PRINTF_ARG_LENGTH_TYPE_Z: - { - value = (uintmax_t) va_arg (*args_list_p, size_t); - break; - } - - case LIBC_PRINTF_ARG_LENGTH_TYPE_T: - { - value = (uintmax_t) va_arg (*args_list_p, ptrdiff_t); - break; - } - - case LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL: - { - assert (false && "unsupported length field L"); - return; - } - - default: - { - assert (false && "unexpected length field"); - return; - } - } - - if (flags & LIBC_PRINTF_ARG_FLAG_SHARP) - { - if (value != 0 && specifier != 'u') - { - libc_printf_putchar (stream, '0'); - - if (specifier == 'x') - { - libc_printf_putchar (stream, 'x'); - } - else if (specifier == 'X') - { - libc_printf_putchar (stream, 'X'); - } - else - { - assert (specifier == 'o'); - } - } - } - - uint32_t radix; - const char *alphabet; - - switch (specifier) - { - case 'u': - { - alphabet = "0123456789"; - radix = 10; - break; - } - - case 'o': - { - alphabet = "01234567"; - radix = 8; - break; - } - - case 'x': - { - alphabet = "0123456789abcdef"; - radix = 16; - break; - } - - case 'X': - { - alphabet = "0123456789ABCDEF"; - radix = 16; - break; - } - - default: - { - assert (false && "unexpected type field"); - return; - } - } - - char str_buffer[ 32 ]; - const char *string_p = libc_printf_uint_to_string (value, - str_buffer, - sizeof (str_buffer), - alphabet, - radix); - - if (flags & LIBC_PRINTF_ARG_FLAG_PRINT_SIGN) - { - /* printing sign */ - - libc_printf_putchar (stream, '+'); - if (width > 0) - { - width--; - } - } - else if (flags & LIBC_PRINTF_ARG_FLAG_SPACE) - { - /* no sign and space flag, printing one space */ - - libc_printf_putchar (stream, ' '); - if (width > 0) - { - width--; - } - } - - libc_printf_justified_string_output (stream, - string_p, - width, - flags & LIBC_PRINTF_ARG_FLAG_LEFT_JUSTIFY, - flags & LIBC_PRINTF_ARG_FLAG_ZERO_PADDING); -} /* libc_printf_write_u_o_x_X */ - -/** - * vfprintf - * - * @return number of characters printed - */ -int __attr_weak___ -vfprintf (FILE *stream, /**< stream pointer */ - const char *format, /**< format string */ - va_list args) /**< arguments */ -{ - va_list args_copy; - - va_copy (args_copy, args); - - const char *format_iter_p = format; - - while (*format_iter_p) - { - if (*format_iter_p != '%') - { - libc_printf_putchar (stream, *format_iter_p); - } - else - { - libc_printf_arg_flags_mask_t flags = 0; - uint32_t width = 0; - libc_printf_arg_length_type_t length = LIBC_PRINTF_ARG_LENGTH_TYPE_NONE; - - while (true) - { - format_iter_p++; - - if (*format_iter_p == '-') - { - flags |= LIBC_PRINTF_ARG_FLAG_LEFT_JUSTIFY; - } - else if (*format_iter_p == '+') - { - flags |= LIBC_PRINTF_ARG_FLAG_PRINT_SIGN; - } - else if (*format_iter_p == ' ') - { - flags |= LIBC_PRINTF_ARG_FLAG_SPACE; - } - else if (*format_iter_p == '#') - { - flags |= LIBC_PRINTF_ARG_FLAG_SHARP; - } - else if (*format_iter_p == '0') - { - flags |= LIBC_PRINTF_ARG_FLAG_ZERO_PADDING; - } - else - { - break; - } - } - - if (*format_iter_p == '*') - { - assert (false && "unsupported width field *"); - } - - /* If there is a number, recognize it as field width. */ - while (*format_iter_p >= '0' && *format_iter_p <= '9') - { - width = width * 10u + (uint32_t) (*format_iter_p - '0'); - - format_iter_p++; - } - - if (*format_iter_p == '.') - { - assert (false && "unsupported precision field"); - } - - switch (*format_iter_p) - { - case 'h': - { - format_iter_p++; - if (*format_iter_p == 'h') - { - format_iter_p++; - - length = LIBC_PRINTF_ARG_LENGTH_TYPE_HH; - } - else - { - length = LIBC_PRINTF_ARG_LENGTH_TYPE_H; - } - break; - } - - case 'l': - { - format_iter_p++; - if (*format_iter_p == 'l') - { - format_iter_p++; - - length = LIBC_PRINTF_ARG_LENGTH_TYPE_LL; - } - else - { - length = LIBC_PRINTF_ARG_LENGTH_TYPE_L; - } - break; - } - - case 'j': - { - format_iter_p++; - length = LIBC_PRINTF_ARG_LENGTH_TYPE_J; - break; - } - - case 'z': - { - format_iter_p++; - length = LIBC_PRINTF_ARG_LENGTH_TYPE_Z; - break; - } - - case 't': - { - format_iter_p++; - length = LIBC_PRINTF_ARG_LENGTH_TYPE_T; - break; - } - - case 'L': - { - format_iter_p++; - length = LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL; - break; - } - } - - switch (*format_iter_p) - { - case 'd': - case 'i': - { - libc_printf_write_d_i (stream, &args_copy, flags, length, width); - break; - } - - case 'u': - case 'o': - case 'x': - case 'X': - { - libc_printf_write_u_o_x_X (stream, *format_iter_p, &args_copy, flags, length, width); - break; - } - - case 'f': - case 'F': - case 'e': - case 'E': - case 'g': - case 'G': - case 'a': - case 'A': - { - assert (false && "unsupported double type field"); - break; - } - - case 'c': - { - if (length & LIBC_PRINTF_ARG_LENGTH_TYPE_L) - { - assert (false && "unsupported length field L"); - } - else - { - char str[2] = - { - (char) va_arg (args_copy, int), /* char is promoted to int */ - '\0' - }; - - libc_printf_justified_string_output (stream, - str, - width, - flags & LIBC_PRINTF_ARG_FLAG_LEFT_JUSTIFY, - flags & LIBC_PRINTF_ARG_FLAG_ZERO_PADDING); - } - break; - } - - case 's': - { - if (length & LIBC_PRINTF_ARG_LENGTH_TYPE_L) - { - assert (false && "unsupported length field L"); - } - else - { - char *str_p = va_arg (args_copy, char *); - - libc_printf_justified_string_output (stream, - str_p, - width, - flags & LIBC_PRINTF_ARG_FLAG_LEFT_JUSTIFY, - flags & LIBC_PRINTF_ARG_FLAG_ZERO_PADDING); - } - break; - } - - case 'p': - { - va_list args_copy2; - va_copy (args_copy2, args_copy); - void *value = va_arg (args_copy2, void *); - va_end (args_copy2); - - if (value == NULL) - { - printf ("(nil)"); - } - else - { - libc_printf_write_u_o_x_X (stream, - 'x', - &args_copy, - flags | LIBC_PRINTF_ARG_FLAG_SHARP, - LIBC_PRINTF_ARG_LENGTH_TYPE_Z, - width); - } - break; - } - - case 'n': - { - assert (false && "unsupported type field n"); - } - } - } - - format_iter_p++; - } - - va_end (args_copy); - - return 0; -} /* vfprintf */ - -/** - * fprintf - * - * @return number of characters printed - */ -int __attr_weak___ -fprintf (FILE *stream, /**< stream pointer */ - const char *format, /**< format string */ - ...) /**< parameters' values */ -{ - va_list args; - - va_start (args, format); - - int ret = vfprintf (stream, format, args); - - va_end (args); - - return ret; -} /* fprintf */ - -/** - * printf - * - * @return number of characters printed - */ -int __attr_weak___ -printf (const char *format, /**< format string */ - ...) /**< parameters' values */ -{ - va_list args; - - va_start (args, format); - - int ret = vfprintf (stdout, format, args); - - va_end (args); - - return ret; -} /* printf */ diff --git a/jerry-libc/jerry-libc.c b/jerry-libc/jerry-libc.c deleted file mode 100644 index 45c44c3e7..000000000 --- a/jerry-libc/jerry-libc.c +++ /dev/null @@ -1,384 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 common functions implementation - */ - -#include -#include -#include -#include - -#include "jerry-libc-defs.h" - -/** - * State of pseudo-random number generator - */ -static uint32_t libc_random_gen_state[4] = { 1455997910, 1999515274, 1234451287, 1949149569 }; - -/** - * Standard file descriptors - */ -FILE *stdin = (FILE *) 0; -FILE *stdout = (FILE *) 1; -FILE *stderr = (FILE *) 2; - -#ifdef __GNUC__ -/* - * Making GCC not to replace: - * - memcpy -> call to memcpy; - * - 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) -CALL_PRAGMA (GCC optimize ("-fno-tree-loop-distribute-patterns")) -#endif /* __GNUC__ */ - -/** - * memset - * - * @return @a s - */ -void * __attr_weak___ __attr_used___ -memset (void *s, /**< area to set values in */ - int c, /**< value to set */ - size_t n) /**< area size */ -{ - uint8_t *area_p = (uint8_t *) s; - while (n--) - { - *area_p++ = (uint8_t) c; - } - - return s; -} /* memset */ - -/** - * memcmp - * - * @return 0, if areas are equal; - * <0, if first area's content is lexicographically less, than second area's content; - * >0, otherwise - */ -int __attr_weak___ -memcmp (const void *s1, /**< first area */ - const void *s2, /**< second area */ - size_t n) /**< area size */ -{ - const uint8_t *area1_p = (uint8_t *) s1, *area2_p = (uint8_t *) s2; - while (n--) - { - int diff = ((int) *area1_p++) - ((int) *area2_p++); - if (diff) - { - return diff; - } - } - - return 0; -} /* memcmp */ - -/** - * memcpy - * - * @return the dest pointer's value - */ -void * __attr_weak___ __attr_used___ -memcpy (void *s1, /**< destination */ - const void *s2, /**< source */ - size_t n) /**< bytes number */ -{ - uint8_t *dst_p = (uint8_t *) s1; - const uint8_t *src_p = (const uint8_t *) s2; - - /* Aligned fast case. */ - if (n >= 4 && !(((uintptr_t) s1) & 0x3) && !(((uintptr_t) s2) & 0x3)) - { - size_t chunks = (n >> 2); - uint32_t *u32_dst_p = (uint32_t *) dst_p; - const uint32_t *u32_src_p = (const uint32_t *) src_p; - - do - { - *u32_dst_p++ = *u32_src_p++; - } - while (--chunks); - - n &= 0x3; - dst_p = (uint8_t *) u32_dst_p; - src_p = (const uint8_t *) u32_src_p; - } - - while (n--) - { - *dst_p++ = *src_p++; - } - - return s1; -} /* memcpy */ - -/** - * memmove - * - * @return the dest pointer's value - */ -void * __attr_weak___ __attr_used___ -memmove (void *s1, /**< destination */ - const void *s2, /**< source */ - size_t n) /**< bytes number */ -{ - uint8_t *dest_p; - const uint8_t *src_p; - - if (s1 < s2) - { /* from begin to end */ - dest_p = (uint8_t *) s1; - src_p = (const uint8_t *) s2; - - while (n--) - { - *dest_p++ = *src_p++; - } - } - else if (s1 > s2) - { /* from end to begin */ - dest_p = ((uint8_t *) s1) + n - 1; - src_p = ((const uint8_t *) s2) + n - 1; - - while (n--) - { - *dest_p-- = *src_p--; - } - } - - return s1; -} /* memmove */ - -#ifdef __GNUC__ -CALL_PRAGMA (GCC pop_options) -CALL_PRAGMA (GCC diagnostic pop) -#endif /* __GNUC__ */ - -/** - * Compare two strings. - * - * @return an integer less than, equal to, or greater than zero if s1 is found, respectively, - * to be less than, to match, or be greater than s2. - */ -int __attr_weak___ -strcmp (const char *s1, /**< first string */ - const char *s2) /**< second string */ -{ - while (1) - { - int c1 = (unsigned char) *s1++; - int c2 = (unsigned char) *s2++; - int diff = c1 - c2; - - if (!c1 || diff) - { - return diff; - } - } -} /* strcmp */ - -/** - * Compare two strings. - * - * @return an integer less than, equal to, or greater than zero if the first n character of s1 is found, respectively, - * to be less than, to match, or be greater than the first n character of s2. - */ -int __attr_weak___ -strncmp (const char *s1, /**< first string */ - const char *s2, /**< second string */ - size_t n) /**< maximum number of characters to compare */ -{ - while (n--) - { - int c1 = (unsigned char) *s1++; - int c2 = (unsigned char) *s2++; - int diff = c1 - c2; - - if (!c1 || diff) - { - return diff; - } - } - - return 0; -} /* strncmp */ - -/** - * Copy a string. At most n bytes of src are copied. - * - * Note: - * 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 * __attr_weak___ __attr_used___ -strncpy (char *dest, /**< destination string */ - const char *src, /**< source string */ - size_t n) /**< maximum number of characters to copy */ -{ - while (n--) - { - char c = *src++; - *dest++ = c; - - if (!c) - { - break; - } - } - - return dest; -} /* strncpy */ - -/** - * Calculate the length of a string. - * - * @return the length. - */ -size_t __attr_weak___ -strlen (const char *s) /**< string */ -{ - size_t i = 0; - while (s[i]) - { - i++; - } - - return i; -} /* strlen */ - -/** - * Generate pseudo-random integer - * - * Note: - * The function implements George Marsaglia's XorShift random number generator - * - * @return integer in range [0; RAND_MAX] - */ -int __attr_weak___ -rand (void) -{ - uint32_t intermediate = libc_random_gen_state[0] ^ (libc_random_gen_state[0] << 11); - intermediate ^= intermediate >> 8; - - libc_random_gen_state[0] = libc_random_gen_state[1]; - libc_random_gen_state[1] = libc_random_gen_state[2]; - libc_random_gen_state[2] = libc_random_gen_state[3]; - - libc_random_gen_state[3] ^= libc_random_gen_state[3] >> 19; - libc_random_gen_state[3] ^= intermediate; - - return (int) (libc_random_gen_state[3] % (RAND_MAX + 1)); -} /* rand */ - -/** - * Initialize pseudo-random number generator with the specified seed value - */ -void __attr_weak___ -srand (unsigned int seed) /**< new seed */ -{ - libc_random_gen_state[0] = (uint32_t) ((seed * 14316555781) - + (seed * 1183186591) - + (seed * 622729787) - + (seed * 338294347)); - - libc_random_gen_state[1] = 842502087; - libc_random_gen_state[2] = 3579807591; - libc_random_gen_state[3] = 273326509; -} /* srand */ - -/** - * Convert a string to a long integer. - * - * The function first discards leading whitespace characters. Then takes an - * optional sign followed by as many digits as possible and interprets them as a - * numerical value. Additional characters after those that form the number are - * ignored. - * - * Note: - * If base is not 10, the behaviour is undefined. - * If the value read is out-of-range, the behaviour is undefined. - * The implementation never sets errno. - * - * @return the integer value of str. - */ -long int __attr_weak___ -strtol (const char *nptr, /**< string representation of an integer number */ - char **endptr, /**< [out] the address of the first non-number character */ - int base) /**< numerical base or radix (MUST be 10) */ -{ - assert (base == 10); - (void) base; /* Unused. */ - - const char *str = nptr; - - /* Skip leading whitespaces. */ - while (*str == ' ' || *str == '\t' || *str == '\r' || *str == '\n') - { - str++; - } - - bool digits = false; - bool positive = true; - long int num = 0; - - /* Process optional sign. */ - if (*str == '-') - { - positive = false; - str++; - } - else if (*str == '+') - { - str++; - } - - /* Process base-10 digits. */ - while (*str >= '0' && *str <= '9') - { - num = num * 10 + (*str - '0'); - digits = true; - str++; - } - - /* Set endptr and return result*/ - if (digits) - { - if (endptr) - { - *endptr = (char *) str; - } - return positive ? num : -num; - } - else - { - if (endptr) - { - *endptr = (char *) nptr; - } - return 0L; - } -} /* strtol */ diff --git a/jerry-libc/target/posix/jerry-asm.S b/jerry-libc/target/posix/jerry-asm.S deleted file mode 100644 index 9deb0b137..000000000 --- a/jerry-libc/target/posix/jerry-asm.S +++ /dev/null @@ -1,91 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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. - */ - -#if defined (__x86_64__) -#include "arch/x86-64.h" -#elif defined (__i386__) -#include "arch/x86-32.h" -#elif defined (__ARM_ARCH_7A__) -#include "arch/arm-v7.h" -#else /* !__x86_64__ && !__i386__ && !__ARM_ARCH_7A__ */ -#error "Unsupported architecture" -#endif /* __x86_64__ */ - -#if defined (__linux__) -.macro func _name -.global \_name -.type \_name, %function -\_name: -.endm -.macro endfunc _name -.size \_name, .-\_name -.endm -#elif defined (__APPLE__) && defined (__MACH__) -.macro func _name -.global \_name -\_name: -.endm -.macro endfunc _name -.endm -#else /* !__linux && !(__APPLE__ && __MACH__) */ -#error "Unsupported OS" -#endif /* __linux__ */ - -func _start - _START -endfunc _start - -func syscall_0 - SYSCALL_0 -endfunc syscall_0 - -func syscall_1 - SYSCALL_1 -endfunc syscall_1 - -func syscall_2 - SYSCALL_2 -endfunc syscall_2 - -func syscall_3 - SYSCALL_3 -endfunc syscall_3 - -/** - * setjmp (jmp_buf env) - * - * See also: - * longjmp - * - * @return 0 - if returns from direct call, - * nonzero - if returns after longjmp. - */ -func setjmp - _SETJMP -endfunc setjmp - -/** - * longjmp (jmp_buf env, int val) - * - * Note: - * if val is not 0, then it would be returned from setjmp, - * otherwise - 0 would be returned. - * - * See also: - * setjmp - */ -func longjmp - _LONGJMP -endfunc longjmp diff --git a/jerry-libc/target/posix/jerry-libc-target.c b/jerry-libc/target/posix/jerry-libc-target.c deleted file mode 100644 index 4fb7e0102..000000000 --- a/jerry-libc/target/posix/jerry-libc-target.c +++ /dev/null @@ -1,288 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 posix implementation - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined (__linux__) -#define SYSCALL_NO(NAME) __NR_ ## NAME -#elif defined (__APPLE__) && defined (__MACH__) -#define SYS_exit_group SYS_exit -#define SYSCALL_NO(NAME) SYS_ ## NAME -#else /* !__linux && !(__APPLE__ && __MACH__) */ -#error "Unsupported OS" -#endif /* __linux__ */ - -#include "jerry-libc-defs.h" - -long int syscall_0 (long int syscall_no); -long int syscall_1 (long int syscall_no, long int arg1); -long int syscall_2 (long int syscall_no, long int arg1, long int arg2); -long int syscall_3 (long int syscall_no, long int arg1, long int arg2, long int arg3); - -/** - * Exit - cause normal process termination with specified status code - */ -void __attr_weak___ __attr_noreturn___ __attr_used___ -exit (int status) /**< status code */ -{ -#ifdef ENABLE_INIT_FINI - libc_fini_array (); -#endif /* ENABLE_INIT_FINI */ - - syscall_1 (SYSCALL_NO (close), (long int) stdin); - syscall_1 (SYSCALL_NO (close), (long int) stdout); - syscall_1 (SYSCALL_NO (close), (long int) stderr); - - syscall_1 (SYSCALL_NO (exit_group), status); - - while (true) - { - /* unreachable */ - } -} /* exit */ - -/** - * Abort current process, producing an abnormal program termination. - * The function raises the SIGABRT signal. - */ -void __attr_weak___ __attr_noreturn___ __attr_used___ -abort (void) -{ - syscall_1 (SYSCALL_NO (close), (long int) stdin); - syscall_1 (SYSCALL_NO (close), (long int) stdout); - syscall_1 (SYSCALL_NO (close), (long int) stderr); - - raise (SIGABRT); - - while (true) - { - /* unreachable */ - } -} /* abort */ - -/** - * Send a signal to the current process. - * - * @return 0 - upon successful completion, - * non-zero value - otherwise. - */ -int __attr_weak___ __attr_used___ -raise (int sig) /**< signal number */ -{ - return (int) syscall_2 (SYSCALL_NO (kill), syscall_0 (SYSCALL_NO (getpid)), sig); -} /* raise */ - -/** - * fopen - * - * @return FILE pointer - upon successful completion, - * NULL - otherwise. - */ -FILE * __attr_weak___ -fopen (const char *path, /**< file path */ - const char *mode) /**< file open mode */ -{ - bool may_read = false; - bool may_write = false; - bool truncate = false; - bool create_if_not_exist = false; - bool position_at_end = false; - int modifier_position = 1; - - assert (path != NULL && mode != NULL); - assert (mode[1] == '\0' - || (mode[1] == '+' && mode[2] == '\0') - || (mode[1] == 'b' && mode[2] == '\0') - || (mode[1] == 'b' && mode[2] == '+' && mode[3] == '\0')); - - if (mode[1] == 'b') - { - modifier_position = 2; - } - - switch (mode[0]) - { - case 'r': - { - may_read = true; - may_write = (mode[modifier_position] == '+'); - break; - } - case 'w': - { - may_write = true; - truncate = true; - create_if_not_exist = true; - may_read = (mode[modifier_position] == '+'); - break; - } - case 'a': - { - may_write = true; - position_at_end = true; - create_if_not_exist = true; - if (mode[modifier_position] == '+') - { - assert (false && "unsupported mode a+"); - } - break; - } - default: - { - assert (false && "unsupported mode"); - } - } - - int flags = 0; - int access = S_IRUSR | S_IWUSR; - if (may_read && !may_write) - { - flags = O_RDONLY; - } - else if (!may_read && may_write) - { - flags = O_WRONLY; - } - else - { - assert (may_read && may_write); - - flags = O_RDWR; - } - - if (truncate) - { - flags |= O_TRUNC; - } - - if (create_if_not_exist) - { - flags |= O_CREAT; - } - - if (position_at_end) - { - flags |= O_APPEND; - } - - long int ret = syscall_3 (SYSCALL_NO (open), (long int) path, flags, access); - - return ((ret < 0) ? NULL : (void *) (uintptr_t) (ret)); -} /* fopen */ - -/** - * fclose - * - * @return 0 - upon successful completion, - * non-zero value - otherwise. - */ -int __attr_weak___ -fclose (FILE *fp) /**< stream pointer */ -{ - syscall_2 (SYSCALL_NO (close), (long int) fp, 0); - - return 0; -} /* fclose */ - -/** - * fread - * - * @return number of elements read - */ -size_t __attr_weak___ -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 */ -{ - long int ret; - size_t bytes_read = 0; - - if (size == 0) - { - return 0; - } - - do - { - ret = syscall_3 (SYSCALL_NO (read), - (long int) stream, - (long int) ((uint8_t *) ptr + bytes_read), - (long int) (size * nmemb - bytes_read)); - - bytes_read += (size_t) ret; - } - while (bytes_read != size * nmemb && ret != 0); - - return bytes_read / size; -} /* fread */ - -/** - * fwrite - * - * @return number of elements written - */ -size_t __attr_weak___ -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 bytes_written = 0; - - if (size == 0) - { - return 0; - } - - do - { - long int ret = syscall_3 (SYSCALL_NO (write), - (long int) stream, - (long int) ((uint8_t *) ptr + bytes_written), - (long int) (size * nmemb - bytes_written)); - - bytes_written += (size_t) ret; - } - while (bytes_written != size * nmemb); - - return bytes_written / size; -} /* fwrite */ - -/** - * This function can get the time as well as a timezone. - * - * @return 0 if success, -1 otherwise - */ -int __attr_weak___ -gettimeofday (void *tp, /**< struct timeval */ - void *tzp) /**< struct timezone */ -{ - return (int) syscall_2 (SYSCALL_NO (gettimeofday), (long int) tp, (long int) tzp); -} /* gettimeofday */ diff --git a/jerry-main/CMakeLists.txt b/jerry-main/CMakeLists.txt index ed1d73f33..4b24ef587 100644 --- a/jerry-main/CMakeLists.txt +++ b/jerry-main/CMakeLists.txt @@ -54,10 +54,6 @@ macro(jerry_create_executable JERRY_NAME) install(TARGETS ${JERRY_NAME} DESTINATION bin) endmacro() -if(JERRY_LIBC AND FEATURE_EXTERNAL_CONTEXT) - MESSAGE(FATAL_ERROR "This configuration is not supported for jerry-main. Please build against your system libc to enable the external context.") -endif() - # Jerry standalones if(JERRY_CMDLINE) jerry_create_executable("jerry" "main-unix.c" "cli.c") diff --git a/targets/esp8266/Makefile.esp8266 b/targets/esp8266/Makefile.esp8266 index 804192c13..34dcf71eb 100644 --- a/targets/esp8266/Makefile.esp8266 +++ b/targets/esp8266/Makefile.esp8266 @@ -50,7 +50,6 @@ jerry: -DCMAKE_C_COMPILER_WORKS=TRUE \ -DENABLE_LTO=OFF \ -DENABLE_ALL_IN_ONE=ON \ - -DJERRY_LIBC=OFF \ -DJERRY_CMDLINE=OFF \ -DEXTERNAL_COMPILE_FLAGS="$(ESP_CFLAGS)" \ -DMEM_HEAP_SIZE_KB=$(JERRYHEAP) diff --git a/targets/mbedos5/template-mbedignore.txt b/targets/mbedos5/template-mbedignore.txt index 6b979c98f..f6c45e65f 100644 --- a/targets/mbedos5/template-mbedignore.txt +++ b/targets/mbedos5/template-mbedignore.txt @@ -1,6 +1,5 @@ cmake/* docs/* -jerry-libc/* jerry-libm/* jerry-main/* jerry-port/default/default-date.c diff --git a/targets/nuttx-stm32f4/Makefile.travis b/targets/nuttx-stm32f4/Makefile.travis index 1e2c23b6e..c6aa8813c 100644 --- a/targets/nuttx-stm32f4/Makefile.travis +++ b/targets/nuttx-stm32f4/Makefile.travis @@ -51,7 +51,7 @@ install: install-apt-get-deps install-noapt # Build JerryScript. script-build-jerryscript: - tools/build.py --clean --toolchain cmake/toolchain_mcu_stm32f4.cmake --profile=es2015-subset --jerry-cmdline OFF --jerry-libc OFF --lto OFF --jerry-libm ON --all-in-one ON --mem-heap 70 --compile-flag='--sysroot=../nuttx' + tools/build.py --clean --toolchain cmake/toolchain_mcu_stm32f4.cmake --profile=es2015-subset --jerry-cmdline OFF --lto OFF --jerry-libm ON --all-in-one ON --mem-heap 70 --compile-flag='--sysroot=../nuttx' # Link in the NuttX JerryScript target directory under the NuttX apps tree. script-add-jerryscript-app: diff --git a/targets/nuttx-stm32f4/README.md b/targets/nuttx-stm32f4/README.md index 84dfd8454..879845c33 100644 --- a/targets/nuttx-stm32f4/README.md +++ b/targets/nuttx-stm32f4/README.md @@ -41,7 +41,6 @@ jerryscript/tools/build.py \ --clean \ --lto=OFF \ --jerry-cmdline=OFF \ - --jerry-libc=OFF \ --jerry-libm=ON \ --all-in-one=ON \ --mem-heap=70 \ diff --git a/targets/openwrt/readme.md b/targets/openwrt/readme.md index 28fb08cb3..f51bbc080 100644 --- a/targets/openwrt/readme.md +++ b/targets/openwrt/readme.md @@ -87,13 +87,9 @@ Please check if the `STAGING_DIR` is configured correctly and that the toolchain ``` $ ./tools/build.py --toolchain cmake/toolchain_openwrt_mips.cmake \ - --jerry-libc OFF \ --lto OFF ``` -Currenlty the JerryScript libc does not supports the mips platform, that's why the `--jerry-libc OFF` argument -is passed during build. - ### 2. Copy the binary After a successful build the `build/bin/jerry` binary file can be copied to the target device. diff --git a/targets/particle/Makefile.particle b/targets/particle/Makefile.particle index 7c5cea8ee..30b1a8e8a 100644 --- a/targets/particle/Makefile.particle +++ b/targets/particle/Makefile.particle @@ -45,7 +45,6 @@ jerrycore: -DCMAKE_C_COMPILER_WORKS=TRUE \ -DENABLE_LTO=ON \ -DENABLE_ALL_IN_ONE=OFF \ - -DJERRY_LIBC=OFF \ -DJERRY_LIBM=OFF \ -DJERRY_CMDLINE=OFF \ -DFEATURE_PROFILE=minimal \ diff --git a/targets/riot-stm32f4/Makefile.riot b/targets/riot-stm32f4/Makefile.riot index 81d9392a0..bc4246745 100644 --- a/targets/riot-stm32f4/Makefile.riot +++ b/targets/riot-stm32f4/Makefile.riot @@ -35,7 +35,6 @@ libjerry: -DCMAKE_C_COMPILER_WORKS=TRUE \ -DENABLE_LTO=OFF \ -DENABLE_ALL_IN_ONE=OFF \ - -DJERRY_LIBC=OFF \ -DJERRY_LIBM=OFF \ -DJERRY_CMDLINE=OFF \ -DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \ diff --git a/targets/tizenrt-artik053/Makefile.tizenrt b/targets/tizenrt-artik053/Makefile.tizenrt index a1a1f9237..eaa3406ee 100644 --- a/targets/tizenrt-artik053/Makefile.tizenrt +++ b/targets/tizenrt-artik053/Makefile.tizenrt @@ -25,7 +25,6 @@ libjerry: cmake -B$(BUILD_DIR) -H./ \ -DENABLE_LTO=OFF \ -DENABLE_ALL_IN_ONE=OFF \ - -DJERRY_LIBC=OFF \ -DJERRY_CMDLINE=OFF \ -DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \ -DMEM_HEAP_SIZE_KB=$(JERRYHEAP) \ diff --git a/targets/tizenrt-artik053/README.md b/targets/tizenrt-artik053/README.md index 32e5dd1b5..ab9107cf8 100644 --- a/targets/tizenrt-artik053/README.md +++ b/targets/tizenrt-artik053/README.md @@ -10,7 +10,7 @@ If you are in a hurry, run following commands: ``` $ sudo apt-add-repository -y "ppa:team-gcc-arm-embedded/ppa" -$ sudo apt-get update +$ sudo apt-get update $ sudo apt-get install gcc-arm-embedded $ git clone https://github.com/jerryscript-project/jerryscript.git jerryscript $ cd jerryscript @@ -87,7 +87,6 @@ jerryscript/tools/build.py \ --clean \ --lto=OFF \ --jerry-cmdline=OFF \ - --jerry-libc=OFF \ --all-in-one=OFF \ --mem-heap=70 \ --profile=es2015-subset \ @@ -151,4 +150,4 @@ Without argument it prints: TASH>>jerry No input files, running a hello world demo: Hello World from JerryScript -``` \ No newline at end of file +``` diff --git a/targets/zephyr/Makefile.zephyr b/targets/zephyr/Makefile.zephyr index 01f5b6f82..69b3ab47e 100644 --- a/targets/zephyr/Makefile.zephyr +++ b/targets/zephyr/Makefile.zephyr @@ -83,7 +83,6 @@ endif -DCMAKE_C_COMPILER_WORKS=TRUE \ -DENABLE_LTO=OFF \ -DENABLE_ALL_IN_ONE=OFF \ - -DJERRY_LIBC=OFF \ -DJERRY_CMDLINE=OFF \ -DFEATURE_PROFILE=$(JERRYPROFILE) \ -DFEATURE_ERROR_MESSAGES=ON \ diff --git a/tests/unit-libm/CMakeLists.txt b/tests/unit-libm/CMakeLists.txt index c96696b72..026a563a0 100644 --- a/tests/unit-libm/CMakeLists.txt +++ b/tests/unit-libm/CMakeLists.txt @@ -30,9 +30,6 @@ foreach(SOURCE_UNIT_TEST_MAIN ${SOURCE_UNIT_TEST_MAIN_MODULES}) set_property(TARGET ${TARGET_NAME} PROPERTY RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests") target_link_libraries(${TARGET_NAME} jerry-libm) - if(JERRY_LIBC) - target_link_libraries(${TARGET_NAME} jerry-libc) - endif() add_dependencies(unittests-libm ${TARGET_NAME}) endforeach() diff --git a/tools/build.py b/tools/build.py index 666ff84a6..cc6816d1e 100755 --- a/tools/build.py +++ b/tools/build.py @@ -92,8 +92,6 @@ def get_arguments(): help=devhelp('build test version of the jerry command line tool (%(choices)s)')) compgrp.add_argument('--jerry-ext', metavar='X', choices=['ON', 'OFF'], type=str.upper, help='build jerry-ext (%(choices)s)') - compgrp.add_argument('--jerry-libc', metavar='X', choices=['ON', 'OFF'], type=str.upper, - help='build and use jerry-libc (%(choices)s)') compgrp.add_argument('--jerry-libm', metavar='X', choices=['ON', 'OFF'], type=str.upper, help='build and use jerry-libm (%(choices)s)') compgrp.add_argument('--jerry-port-default', metavar='X', choices=['ON', 'OFF'], type=str.upper, @@ -178,7 +176,6 @@ def generate_build_options(arguments): build_options_append('JERRY_CMDLINE_SNAPSHOT', arguments.jerry_cmdline_snapshot) build_options_append('JERRY_CMDLINE_TEST', arguments.jerry_cmdline_test) build_options_append('JERRY_EXT', arguments.jerry_ext) - build_options_append('JERRY_LIBC', arguments.jerry_libc) build_options_append('JERRY_LIBM', arguments.jerry_libm) build_options_append('JERRY_PORT_DEFAULT', arguments.jerry_port_default) build_options_append('UNITTESTS', arguments.unittests) diff --git a/tools/check-cppcheck.sh b/tools/check-cppcheck.sh index 524664a99..8da40d501 100755 --- a/tools/check-cppcheck.sh +++ b/tools/check-cppcheck.sh @@ -25,12 +25,11 @@ fi JERRY_CORE_DIRS=`find jerry-core -type d` JERRY_EXT_DIRS=`find jerry-ext -type d` JERRY_PORT_DIRS=`find jerry-port -type d` -JERRY_LIBC_DIRS=`find jerry-libc -type d` JERRY_LIBM_DIRS=`find jerry-libm -type d` INCLUDE_DIRS=() -for DIR in $JERRY_CORE_DIRS $JERRY_EXT_DIRS $JERRY_PORT_DIRS $JERRY_LIBC_DIRS $JERRY_LIBM_DIRS +for DIR in $JERRY_CORE_DIRS $JERRY_EXT_DIRS $JERRY_PORT_DIRS $JERRY_LIBM_DIRS do INCLUDE_DIRS=("${INCLUDE_DIRS[@]}" "-I$DIR") done @@ -44,4 +43,4 @@ cppcheck -j$CPPCHECK_JOBS --force \ --exitcode-suppressions=tools/cppcheck/suppressions-list \ --suppressions-list=tools/cppcheck/suppressions-list \ "${INCLUDE_DIRS[@]}" \ - jerry-core jerry-ext jerry-port jerry-libc jerry-libm jerry-main tests/unit-* + jerry-core jerry-ext jerry-port jerry-libm jerry-main tests/unit-* diff --git a/tools/check-license.py b/tools/check-license.py index 21c7f7847..46e934630 100755 --- a/tools/check-license.py +++ b/tools/check-license.py @@ -42,7 +42,6 @@ INCLUDE_DIRS = [ 'cmake', 'jerry-core', 'jerry-ext', - 'jerry-libc', 'jerry-libm', 'jerry-main', 'jerry-port', diff --git a/tools/check-sonarqube.sh b/tools/check-sonarqube.sh index dd1fca1d8..5bba89f72 100755 --- a/tools/check-sonarqube.sh +++ b/tools/check-sonarqube.sh @@ -23,7 +23,6 @@ then ./tools/build.py --error-messages=on \ --jerry-cmdline-snapshot=on \ --jerry-debugger=on \ - --jerry-libc=off \ --line-info=on \ --mem-stats=on \ --profile=es2015-subset \ @@ -38,7 +37,6 @@ else ./tools/build.py --error-messages=on \ --jerry-cmdline-snapshot=on \ --jerry-debugger=on \ - --jerry-libc=off \ --line-info=on \ --mem-stats=on \ --profile=es2015-subset \ diff --git a/tools/check-vera.sh b/tools/check-vera.sh index e83754589..0b26806de 100755 --- a/tools/check-vera.sh +++ b/tools/check-vera.sh @@ -17,7 +17,6 @@ JERRY_CORE_FILES=`find ./jerry-core -name "*.c" -or -name "*.h"` JERRY_EXT_FILES=`find ./jerry-ext -name "*.c" -or -name "*.h"` JERRY_PORT_FILES=`find ./jerry-port -name "*.c" -or -name "*.h"` -JERRY_LIBC_FILES=`find ./jerry-libc -name "*.c" -or -name "*.h"` JERRY_LIBM_FILES=`find ./jerry-libm -name "*.c" -or -name "*.h"` JERRY_MAIN_FILES=`find ./jerry-main -name "*.c" -or -name "*.h"` UNIT_TEST_FILES=`find ./tests/unit-* -name "*.c" -or -name "*.h"` @@ -29,4 +28,4 @@ fi vera++ -r tools/vera++ -p jerry \ -e --no-duplicate \ - $MANUAL_CHECK_FILES $JERRY_CORE_FILES $JERRY_EXT_FILES $JERRY_PORT_FILES $JERRY_LIBC_FILES $JERRY_LIBM_FILES $JERRY_MAIN_FILES $UNIT_TEST_FILES + $MANUAL_CHECK_FILES $JERRY_CORE_FILES $JERRY_EXT_FILES $JERRY_PORT_FILES $JERRY_LIBM_FILES $JERRY_MAIN_FILES $UNIT_TEST_FILES diff --git a/tools/cppcheck/suppressions-list b/tools/cppcheck/suppressions-list index af0a3cebf..ea48aec21 100644 --- a/tools/cppcheck/suppressions-list +++ b/tools/cppcheck/suppressions-list @@ -1,5 +1,4 @@ wrongmathcall:tests/unit-libm/test-libm.inc.h variableScope:jerry-libm/*.c invalidPointerCast:jerry-libm/*.c -arithOperationsOnVoidPointer:jerry-libc/*.c commaSeparatedReturn:* diff --git a/tools/run-tests.py b/tools/run-tests.py index 099a01793..be2469ca0 100755 --- a/tools/run-tests.py +++ b/tools/run-tests.py @@ -75,7 +75,7 @@ JERRY_TESTS_OPTIONS = [ Options('jerry_tests-es5.1-debug-cpointer_32bit', OPTIONS_PROFILE_ES51 + OPTIONS_DEBUG + ['--cpointer-32bit=on', '--mem-heap=1024']), Options('jerry_tests-es5.1-debug-external_context', - OPTIONS_PROFILE_ES51 + OPTIONS_DEBUG + ['--jerry-libc=off', '--external-context=on']), + OPTIONS_PROFILE_ES51 + OPTIONS_DEBUG + ['--external-context=on']), Options('jerry_tests-es2015_subset-debug', OPTIONS_PROFILE_ES2015 + OPTIONS_DEBUG), ] @@ -111,7 +111,7 @@ TEST262_TEST_SUITE_OPTIONS = [ # Test options for jerry-debugger DEBUGGER_TEST_OPTIONS = [ Options('jerry_debugger_tests', - ['--debug', '--jerry-debugger=on', '--jerry-libc=off']) + ['--debug', '--jerry-debugger=on']) ] # Test options for buildoption-test @@ -132,14 +132,12 @@ JERRY_BUILDOPTIONS = [ ['--show-opcodes=on']), Options('buildoption_test-show_regexp_opcodes', ['--show-regexp-opcodes=on']), - Options('buildoption_test-compiler_default_libc', - ['--jerry-libc=off']), Options('buildoption_test-cpointer_32bit', - ['--jerry-libc=off', '--compile-flag=-m32', '--cpointer-32bit=on', '--system-allocator=on']), + ['--compile-flag=-m32', '--cpointer-32bit=on', '--system-allocator=on']), Options('buildoption_test-external_context', - ['--jerry-libc=off', '--external-context=on']), + ['--external-context=on']), Options('buildoption_test-shared_libs', - ['--jerry-libc=off', '--shared-libs=on']), + ['--shared-libs=on']), Options('buildoption_test-cmdline_test', ['--jerry-cmdline-test=on']), Options('buildoption_test-cmdline_snapshot',