Refinement of project structure.
- components renaming and moving: - liballocator -> mem; - libcoreint -> vm; - libecmaobjects -> ecma/base; - libecmaoperations -> ecma/operations; - libecmabuiltins -> ecma/builtins; - libjsparser -> parser/js; - libintstructs -> parser/collections; - liboptimizer -> parser/js; - libperipherals -> ../plugins/lib_device_stm; - libruntime -> jrt; - generated.h now is created as intermediate during build; - benchmarks -> tests/benchmarks; - docs -> documentation; - demo-applications removed (loop_demo.js -> tests/blinky.js).
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/* Copyright 2014 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 ASM_ARM_H
|
||||
#define ASM_ARM_H
|
||||
|
||||
/*
|
||||
* 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};
|
||||
|
||||
#define _START \
|
||||
ldr r0, [sp, #0]; \
|
||||
add r1, sp, #4; \
|
||||
bl main; \
|
||||
\
|
||||
bl __exit; \
|
||||
1: \
|
||||
b 1b
|
||||
|
||||
#endif /* !ASM_ARM_H */
|
||||
@@ -0,0 +1,69 @@
|
||||
/* Copyright 2014 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 ASM_X64_H
|
||||
#define ASM_X64_H
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
#define _START \
|
||||
mov (%rsp), %rdi; \
|
||||
mov %rsp, %rsi; \
|
||||
add $8, %rsi; \
|
||||
callq main; \
|
||||
\
|
||||
mov %rax, %rdi; \
|
||||
callq __exit; \
|
||||
1: \
|
||||
jmp 1b
|
||||
|
||||
#endif /* !ASM_X64_H */
|
||||
@@ -0,0 +1,72 @@
|
||||
/* Copyright 2014 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 ASM_X86_H
|
||||
#define ASM_X86_H
|
||||
|
||||
FIXME(Implement x86 ABI);
|
||||
#error "Not implemented"
|
||||
|
||||
/*
|
||||
* mov syscall_no -> %rax
|
||||
* mov arg1 -> %rdi
|
||||
* syscall
|
||||
* mov %rax -> ret
|
||||
*/
|
||||
#define SYSCALL_1 (syscall_no, arg1, ret) \
|
||||
__asm ("syscall" \
|
||||
: "=a" (ret) \
|
||||
: "a" (syscall_no), "D" (arg1) \
|
||||
: "rcx", "r11");
|
||||
|
||||
/*
|
||||
* mov syscall_no -> %rax
|
||||
* mov arg1 -> %rdi
|
||||
* mov arg2 -> %rsi
|
||||
* syscall
|
||||
* mov %rax -> ret
|
||||
*/
|
||||
#define SYSCALL_2 (syscall_no, arg1, arg2, ret) \
|
||||
__asm ("syscall" \
|
||||
: "=a" (ret) \
|
||||
: "a" (syscall_no), "D" (arg1), "S" (arg2) \
|
||||
: "rcx", "r11");
|
||||
|
||||
/*
|
||||
* mov syscall_no -> %rax
|
||||
* mov arg1 -> %rdi
|
||||
* mov arg2 -> %rsi
|
||||
* mov arg3 -> %rdx
|
||||
* syscall
|
||||
* mov %rax -> ret
|
||||
*/
|
||||
#define SYSCALL_3 (syscall_no, arg1, arg2, arg3, ret) \
|
||||
__asm ("syscall" \
|
||||
: "=a" (ret) \
|
||||
: "a" (syscall_no), "D" (arg1), "S" (arg2), "d" (arg3) \
|
||||
: "rcx", "r11");
|
||||
|
||||
#define _START \
|
||||
mov (%rsp), %rdi; \
|
||||
mov %rsp, %rsi; \
|
||||
add $8, %rsi; \
|
||||
callq main; \
|
||||
\
|
||||
mov %rax, %rdi; \
|
||||
callq __exit; \
|
||||
1: \
|
||||
jmp 1b
|
||||
|
||||
#endif /* !ASM_X86_H */
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifdef __TARGET_HOST_x64
|
||||
# include "asm_x64.h"
|
||||
#elif defined (__TARGET_HOST_x86)
|
||||
# include "asm_x86.h"
|
||||
#elif defined (__TARGET_HOST_ARMv7)
|
||||
# include "asm_arm.h"
|
||||
#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 */
|
||||
|
||||
.global _start
|
||||
.type _start, %function
|
||||
_start:
|
||||
_START
|
||||
.size _start, . - _start
|
||||
|
||||
.global syscall_1_asm
|
||||
.type syscall_1_asm, %function
|
||||
syscall_1_asm:
|
||||
SYSCALL_1
|
||||
.size syscall_1_asm, . - syscall_1_asm
|
||||
|
||||
.global syscall_2_asm
|
||||
.type syscall_2_asm, %function
|
||||
syscall_2_asm:
|
||||
SYSCALL_2
|
||||
.size syscall_2_asm, . - syscall_2_asm
|
||||
|
||||
.global syscall_3_asm
|
||||
.type syscall_3_asm, %function
|
||||
syscall_3_asm:
|
||||
SYSCALL_3
|
||||
.size syscall_3_asm, . - syscall_3_asm
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#include "jrt.h"
|
||||
#include "jerry-libc.h"
|
||||
|
||||
/**
|
||||
* Handle failed assertion
|
||||
*/
|
||||
void __noreturn
|
||||
jerry_assert_fail (const char *assertion, /**< assertion condition string */
|
||||
const char *file, /**< file name */
|
||||
const char *function, /**< function name */
|
||||
const uint32_t line) /** line */
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
__printf ("ICE: Assertion '%s' failed at %s(%s):%u.\n",
|
||||
assertion, file, function, line);
|
||||
#else /* !JERRY_NDEBUG */
|
||||
(void) assertion;
|
||||
(void) file;
|
||||
(void) function;
|
||||
(void) line;
|
||||
#endif /* JERRY_NDEBUG */
|
||||
|
||||
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
|
||||
} /* jerry_assert_fail */
|
||||
|
||||
/**
|
||||
* Handle execution of control path that should be unreachable
|
||||
*/
|
||||
void __noreturn
|
||||
jerry_unreachable (const char *comment, /**< comment to unreachable mark if exists,
|
||||
NULL - otherwise */
|
||||
const char *file, /**< file name */
|
||||
const char *function, /**< function name */
|
||||
const uint32_t line) /**< line */
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
__printf ("ICE: Unreachable control path at %s(%s):%u was executed", file, function, line);
|
||||
#else /* !JERRY_NDEBUG */
|
||||
(void) file;
|
||||
(void) function;
|
||||
(void) line;
|
||||
#endif /* JERRY_NDEBUG */
|
||||
|
||||
if (comment != NULL)
|
||||
{
|
||||
__printf ("(%s)", comment);
|
||||
}
|
||||
__printf (".\n");
|
||||
|
||||
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
|
||||
} /* jerry_unreachable */
|
||||
|
||||
/**
|
||||
* Handle unimplemented case execution
|
||||
*/
|
||||
void __noreturn
|
||||
jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if exists,
|
||||
NULL - otherwise */
|
||||
const char *file, /**< file name */
|
||||
const char *function, /**< function name */
|
||||
const uint32_t line) /**< line */
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
__printf ("SORRY: Unimplemented case at %s(%s):%u was executed", file, function, line);
|
||||
#else /* !JERRY_NDEBUG */
|
||||
(void) file;
|
||||
(void) function;
|
||||
(void) line;
|
||||
#endif /* JERRY_NDEBUG */
|
||||
|
||||
if (comment != NULL)
|
||||
{
|
||||
__printf ("(%s)", comment);
|
||||
}
|
||||
__printf (".\n");
|
||||
|
||||
__exit (-ERR_UNIMPLEMENTED_CASE);
|
||||
} /* jerry_unimplemented */
|
||||
@@ -0,0 +1,400 @@
|
||||
/* 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 linux implementation
|
||||
*/
|
||||
|
||||
#include "jrt.h"
|
||||
#include "jerry-libc.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <sys/resource.h>
|
||||
|
||||
#ifdef __TARGET_HOST_x64
|
||||
# include "asm_x64.h"
|
||||
#elif defined (__TARGET_HOST_x86)
|
||||
# include "asm_x86.h"
|
||||
#elif defined (__TARGET_HOST_ARMv7)
|
||||
# include "asm_arm.h"
|
||||
#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 */
|
||||
|
||||
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
|
||||
|
||||
/**
|
||||
* 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)) \
|
||||
{ \
|
||||
__exit (-ERR_SYSCALL); \
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* System call with one argument.
|
||||
*
|
||||
* @return syscall's return value
|
||||
*/
|
||||
static __noinline long int
|
||||
syscall_1 (long int syscall_no, /**< syscall number */
|
||||
long int arg1) /**< argument */
|
||||
{
|
||||
long int ret = syscall_1_asm (syscall_no, arg1);
|
||||
|
||||
LIBC_EXIT_ON_ERROR(ret);
|
||||
|
||||
return ret;
|
||||
} /* syscall_1 */
|
||||
|
||||
/**
|
||||
* System call with two arguments.
|
||||
*
|
||||
* @return syscall's return value
|
||||
*/
|
||||
static __noinline long int
|
||||
syscall_2 (long int syscall_no, /**< syscall number */
|
||||
long int arg1, /**< first argument */
|
||||
long int arg2) /**< second argument */
|
||||
{
|
||||
long int ret = syscall_2_asm (syscall_no, arg1, arg2);
|
||||
|
||||
LIBC_EXIT_ON_ERROR(ret);
|
||||
|
||||
return ret;
|
||||
} /* syscall_2 */
|
||||
|
||||
/**
|
||||
* System call with three arguments.
|
||||
*
|
||||
* @return syscall's return value
|
||||
*/
|
||||
static __noinline long int
|
||||
syscall_3 (long int syscall_no, /**< syscall number */
|
||||
long int arg1, /**< first argument */
|
||||
long int arg2, /**< second argument */
|
||||
long int arg3) /**< third argument */
|
||||
{
|
||||
long int ret = syscall_3_asm (syscall_no, arg1, arg2, arg3);
|
||||
|
||||
LIBC_EXIT_ON_ERROR(ret);
|
||||
|
||||
return ret;
|
||||
} /* syscall_3 */
|
||||
|
||||
/** Output of character. Writes the character c, cast to an unsigned char, to stdout. */
|
||||
int
|
||||
__putchar (int c)
|
||||
{
|
||||
__fwrite (&c, 1, sizeof (char), LIBC_STDOUT);
|
||||
|
||||
return c;
|
||||
} /* __putchar */
|
||||
|
||||
/**
|
||||
* Exit - cause normal process termination with specified status code
|
||||
*/
|
||||
void __noreturn
|
||||
__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_exit_group, status);
|
||||
|
||||
while (true)
|
||||
{
|
||||
/* unreachable */
|
||||
}
|
||||
} /* __exit */
|
||||
|
||||
/**
|
||||
* fopen
|
||||
*
|
||||
* @return _FILE pointer - upon successful completion,
|
||||
* NULL - otherwise
|
||||
*/
|
||||
_FILE*
|
||||
__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;
|
||||
|
||||
JERRY_ASSERT(path != NULL && mode != NULL);
|
||||
JERRY_ASSERT(mode[1] == '+' || mode[1] == '\0');
|
||||
|
||||
switch (mode[0])
|
||||
{
|
||||
case 'r':
|
||||
{
|
||||
may_read = true;
|
||||
may_write = (mode[1] == '+');
|
||||
break;
|
||||
}
|
||||
case 'w':
|
||||
{
|
||||
may_write = true;
|
||||
truncate = true;
|
||||
create_if_not_exist = true;
|
||||
may_read = (mode[1] == '+');
|
||||
break;
|
||||
}
|
||||
case 'a':
|
||||
{
|
||||
may_write = true;
|
||||
position_at_end = true;
|
||||
create_if_not_exist = true;
|
||||
if (mode[1] == '+')
|
||||
{
|
||||
/* Not supported */
|
||||
JERRY_UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
JERRY_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 (__NR_open, (long int) path, flags, access);
|
||||
|
||||
return (void*) (uintptr_t) (ret);
|
||||
} /* __fopen */
|
||||
|
||||
/**
|
||||
* The rewind () function sets the file position indicator
|
||||
* for the stream pointed to by STREAM to the beginning of the file.
|
||||
*/
|
||||
void
|
||||
__rewind (_FILE *stream) /**< stream pointer */
|
||||
{
|
||||
syscall_3 (__NR_lseek, (long int) stream, 0, SEEK_SET);
|
||||
} /* __rewind */
|
||||
|
||||
/**
|
||||
* fclose
|
||||
*
|
||||
* @return 0 - upon successful completion,
|
||||
* non-zero value - otherwise.
|
||||
*/
|
||||
int
|
||||
__fclose (_FILE *fp) /**< stream pointer */
|
||||
{
|
||||
syscall_2 (__NR_close, (long int)fp, 0);
|
||||
|
||||
return 0;
|
||||
} /* __fclose */
|
||||
|
||||
/**
|
||||
* fseek
|
||||
*/
|
||||
int
|
||||
__fseek (_FILE * fp, /**< stream pointer */
|
||||
long offset, /**< offset */
|
||||
_whence_t 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);
|
||||
|
||||
return 0;
|
||||
} /* __fseek */
|
||||
|
||||
/**
|
||||
* ftell
|
||||
*/
|
||||
long
|
||||
__ftell (_FILE * fp) /**< stream pointer */
|
||||
{
|
||||
long int ret = syscall_3 (__NR_lseek, (long int)fp, 0, SEEK_CUR);
|
||||
|
||||
return ret;
|
||||
} /* __ftell */
|
||||
|
||||
/**
|
||||
* fread
|
||||
*
|
||||
* @return number of bytes read
|
||||
*/
|
||||
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 */
|
||||
{
|
||||
long int ret;
|
||||
size_t bytes_read = 0;
|
||||
|
||||
do
|
||||
{
|
||||
ret = syscall_3 (__NR_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;
|
||||
} /* __fread */
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
{
|
||||
size_t bytes_written = 0;
|
||||
|
||||
do
|
||||
{
|
||||
long int ret = syscall_3 (__NR_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;
|
||||
} /* __fwrite */
|
||||
|
||||
/**
|
||||
* Setup new memory limits
|
||||
*/
|
||||
void
|
||||
jrt_set_mem_limits (size_t data_size, /**< limit for data + bss + brk heap */
|
||||
size_t stack_size) /**< limit for stack */
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned long long rlim_cur;
|
||||
unsigned long long rlim_max;
|
||||
} data_limit = { data_size, data_size };
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned long long rlim_cur;
|
||||
unsigned long long rlim_max;
|
||||
} stack_limit = { stack_size, stack_size };
|
||||
|
||||
long int ret;
|
||||
|
||||
#ifdef __TARGET_HOST_x64
|
||||
ret = syscall_2 (__NR_setrlimit, RLIMIT_DATA, (intptr_t) &data_limit);
|
||||
JERRY_ASSERT (ret == 0);
|
||||
|
||||
ret = syscall_2 (__NR_setrlimit, RLIMIT_STACK, (intptr_t) &stack_limit);
|
||||
JERRY_ASSERT (ret == 0);
|
||||
#elif defined (__TARGET_HOST_ARMv7)
|
||||
ret = syscall_3 (__NR_prlimit64, 0, RLIMIT_DATA, (intptr_t) &data_limit);
|
||||
JERRY_ASSERT (ret == 0);
|
||||
|
||||
ret = syscall_3 (__NR_prlimit64, 0, RLIMIT_STACK, (intptr_t) &stack_limit);
|
||||
JERRY_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 */
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Runtime ABI for ARM architecture
|
||||
*/
|
||||
|
||||
/**
|
||||
* long long __aeabi_llsl(long long {r1, r0}, int {r2})
|
||||
*/
|
||||
.thumb_func
|
||||
.global __aeabi_llsl
|
||||
__aeabi_llsl:
|
||||
// if (r2 >= 64) goto 2f;
|
||||
cmp r2, #64
|
||||
bhs 2f
|
||||
|
||||
// if (r2 < 32) goto 1f;
|
||||
cmp r2, #32
|
||||
blo 1f
|
||||
|
||||
// r1 = (r0 << (r2 - 32));
|
||||
// r0 = 0;
|
||||
sub r2, #32
|
||||
mov r1, r0
|
||||
lsl r1, r2
|
||||
mov r0, #0
|
||||
|
||||
bx lr
|
||||
|
||||
1:
|
||||
// r1 <<= r2;
|
||||
lsl r1, r2
|
||||
|
||||
// r2 = 32 - r2;
|
||||
rsb r2, r2, #32
|
||||
|
||||
// r1 |= (r0 >> r2);
|
||||
mov r3, r0
|
||||
lsr r3, r2
|
||||
orr r1, r3
|
||||
|
||||
// r2 = 32 - r2;
|
||||
rsb r2, r2, #32
|
||||
|
||||
// r0 <<= r2;
|
||||
lsl r0, r2
|
||||
|
||||
bx lr
|
||||
|
||||
2:
|
||||
// r1 = 0;
|
||||
// r0 = 0;
|
||||
mov r1, #0
|
||||
mov r0, #0
|
||||
|
||||
bx lr
|
||||
|
||||
|
||||
/**
|
||||
* long long __aeabi_llsr(long long {r1, r0}, int {r2})
|
||||
*/
|
||||
.thumb_func
|
||||
.global __aeabi_llsr
|
||||
__aeabi_llsr:
|
||||
// if (r2 >= 64) goto 2f;
|
||||
cmp r2, #64
|
||||
bhs 2f
|
||||
|
||||
// if (r2 < 32) goto 1f;
|
||||
cmp r2, #32
|
||||
blo 1f
|
||||
|
||||
// r0 = (r1 >> (r2 - 32));
|
||||
// r1 = 0
|
||||
sub r2, #32
|
||||
mov r0, r1
|
||||
lsr r0, r2
|
||||
mov r1, #0
|
||||
|
||||
bx lr
|
||||
|
||||
1:
|
||||
// r0 >>= r2
|
||||
lsr r0, r2
|
||||
|
||||
// r0 |= r1 << (32 - r2)
|
||||
mov r3, r1
|
||||
rsb r2, r2, #32
|
||||
lsl r3, r3, r2
|
||||
orr r0, r3
|
||||
rsb r2, r2, #32
|
||||
|
||||
// r1 >>= r2
|
||||
lsr r1, r2
|
||||
|
||||
bx lr
|
||||
|
||||
2:
|
||||
// r1 = 0;
|
||||
// r0 = 0;
|
||||
mov r1, #0
|
||||
mov r0, #0
|
||||
|
||||
bx lr
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#include "jrt.h"
|
||||
#include "jerry-libc.h"
|
||||
|
||||
/**
|
||||
* Handle failed assertion
|
||||
*/
|
||||
void __noreturn
|
||||
jerry_assert_fail (const char *assertion __unused, /**< assertion condition string */
|
||||
const char *file __unused, /**< file name */
|
||||
const char *function __unused, /**< function name */
|
||||
const uint32_t line __unused) /** line */
|
||||
{
|
||||
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
|
||||
} /* jerry_assert_fail */
|
||||
|
||||
/**
|
||||
* Handle execution of control path that should be unreachable
|
||||
*/
|
||||
void __noreturn
|
||||
jerry_unreachable (const char *comment __unused, /**< comment to unreachable mark if exists,
|
||||
NULL - otherwise */
|
||||
const char *file __unused, /**< file name */
|
||||
const char *function __unused, /**< function name */
|
||||
const uint32_t line __unused) /**< line */
|
||||
{
|
||||
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
|
||||
} /* jerry_unreachable */
|
||||
|
||||
/**
|
||||
* Handle unimplemented case execution
|
||||
*/
|
||||
void __noreturn
|
||||
jerry_unimplemented (const char *comment __unused, /**< comment to unimplemented mark if exists,
|
||||
NULL - otherwise */
|
||||
const char *file __unused, /**< file name */
|
||||
const char *function __unused, /**< function name */
|
||||
const uint32_t line __unused) /**< line */
|
||||
{
|
||||
__exit (-ERR_UNIMPLEMENTED_CASE);
|
||||
} /* jerry_unimplemented */
|
||||
@@ -0,0 +1,59 @@
|
||||
/* Copyright 2014 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 STM32F3.", c);
|
||||
} /* __putchar */
|
||||
|
||||
/** exit - cause normal process termination */
|
||||
void __noreturn
|
||||
__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 STM32F3.", ptr, size, nmemb, stream);
|
||||
} /* __fwrite */
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Runtime ABI for ARM architecture
|
||||
*/
|
||||
|
||||
/**
|
||||
* long long __aeabi_llsl(long long {r1, r0}, int {r2})
|
||||
*/
|
||||
.thumb_func
|
||||
.global __aeabi_llsl
|
||||
__aeabi_llsl:
|
||||
// if (r2 >= 64) goto 2f;
|
||||
cmp r2, #64
|
||||
bhs 2f
|
||||
|
||||
// if (r2 < 32) goto 1f;
|
||||
cmp r2, #32
|
||||
blo 1f
|
||||
|
||||
// r1 = (r0 << (r2 - 32));
|
||||
// r0 = 0;
|
||||
sub r2, #32
|
||||
mov r1, r0
|
||||
lsl r1, r2
|
||||
mov r0, #0
|
||||
|
||||
bx lr
|
||||
|
||||
1:
|
||||
// r1 <<= r2;
|
||||
lsl r1, r2
|
||||
|
||||
// r2 = 32 - r2;
|
||||
rsb r2, r2, #32
|
||||
|
||||
// r1 |= (r0 >> r2);
|
||||
mov r3, r0
|
||||
lsr r3, r2
|
||||
orr r1, r3
|
||||
|
||||
// r2 = 32 - r2;
|
||||
rsb r2, r2, #32
|
||||
|
||||
// r0 <<= r2;
|
||||
lsl r0, r2
|
||||
|
||||
bx lr
|
||||
|
||||
2:
|
||||
// r1 = 0;
|
||||
// r0 = 0;
|
||||
mov r1, #0
|
||||
mov r0, #0
|
||||
|
||||
bx lr
|
||||
|
||||
|
||||
/**
|
||||
* long long __aeabi_llsr(long long {r1, r0}, int {r2})
|
||||
*/
|
||||
.thumb_func
|
||||
.global __aeabi_llsr
|
||||
__aeabi_llsr:
|
||||
// if (r2 >= 64) goto 2f;
|
||||
cmp r2, #64
|
||||
bhs 2f
|
||||
|
||||
// if (r2 < 32) goto 1f;
|
||||
cmp r2, #32
|
||||
blo 1f
|
||||
|
||||
// r0 = (r1 >> (r2 - 32));
|
||||
// r1 = 0
|
||||
sub r2, #32
|
||||
mov r0, r1
|
||||
lsr r0, r2
|
||||
mov r1, #0
|
||||
|
||||
bx lr
|
||||
|
||||
1:
|
||||
// r0 >>= r2
|
||||
lsr r0, r2
|
||||
|
||||
// r0 |= r1 << (32 - r2)
|
||||
mov r3, r1
|
||||
rsb r2, r2, #32
|
||||
lsl r3, r3, r2
|
||||
orr r0, r3
|
||||
rsb r2, r2, #32
|
||||
|
||||
// r1 >>= r2
|
||||
lsr r1, r2
|
||||
|
||||
bx lr
|
||||
|
||||
2:
|
||||
// r1 = 0;
|
||||
// r0 = 0;
|
||||
mov r1, #0
|
||||
mov r0, #0
|
||||
|
||||
bx lr
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#include "jrt.h"
|
||||
#include "jerry-libc.h"
|
||||
|
||||
/**
|
||||
* Handle failed assertion
|
||||
*/
|
||||
void __noreturn
|
||||
jerry_assert_fail (const char *assertion __unused, /**< assertion condition string */
|
||||
const char *file __unused, /**< file name */
|
||||
const char *function __unused, /**< function name */
|
||||
const uint32_t line __unused) /** line */
|
||||
{
|
||||
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
|
||||
} /* jerry_assert_fail */
|
||||
|
||||
/**
|
||||
* Handle execution of control path that should be unreachable
|
||||
*/
|
||||
void __noreturn
|
||||
jerry_unreachable (const char *comment __unused, /**< comment to unreachable mark if exists,
|
||||
NULL - otherwise */
|
||||
const char *file __unused, /**< file name */
|
||||
const char *function __unused, /**< function name */
|
||||
const uint32_t line __unused) /**< line */
|
||||
{
|
||||
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
|
||||
} /* jerry_unreachable */
|
||||
|
||||
/**
|
||||
* Handle unimplemented case execution
|
||||
*/
|
||||
void __noreturn
|
||||
jerry_unimplemented (const char *comment __unused, /**< comment to unimplemented mark if exists,
|
||||
NULL - otherwise */
|
||||
const char *file __unused, /**< file name */
|
||||
const char *function __unused, /**< function name */
|
||||
const uint32_t line __unused) /**< line */
|
||||
{
|
||||
__exit (-ERR_UNIMPLEMENTED_CASE);
|
||||
} /* jerry_unimplemented */
|
||||
@@ -0,0 +1,59 @@
|
||||
/* Copyright 2014 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
|
||||
__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 */
|
||||
|
||||
Reference in New Issue
Block a user