-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support setjmp / longjmp in jerry-libc #194
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
630a1e8
Move architecture-depedendent libc internal headers to jerry-libc/arc…
ruben-ayrapetyan 3027715
Fix strncmp, fread and fwrite in jerry-libc.
ruben-ayrapetyan 6d6c913
Move random number generator from Math.random to jerry-libc, replace …
ruben-ayrapetyan f115f73
Switch unit tests to jerry-libc.
ruben-ayrapetyan b008867
Implement setjmp / longjmp in jerry-libc.
ruben-ayrapetyan de7b72d
Add configuration for ARMv7 softfloat build; update setjmp / longjmp …
ruben-ayrapetyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2015 Samsung Electronics Co., Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set(CMAKE_SYSTEM_NAME Linux) | ||
set(CMAKE_SYSTEM_PROCESSOR armv7l-el) | ||
|
||
set(CMAKE_C_COMPILER arm-linux-gnueabi-gcc) | ||
set(CMAKE_CXX_COMPILER arm-linux-gnueabi-g++) | ||
|
||
set(FLAGS_COMMON_ARCH -mlittle-endian -mthumb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/* 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. | ||
*/ | ||
|
||
#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}; | ||
|
||
/* | ||
* ldr argc ([sp + 0x0]) -> r0 | ||
* add argv (sp + 0x4) -> r1 | ||
* | ||
* bl main | ||
* | ||
* bl exit | ||
* | ||
* infinite loop | ||
*/ | ||
#define _START \ | ||
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. | ||
*/ | ||
#ifdef __TARGET_HOST_ARMv7_HARD_FLOAT | ||
# 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 /* !__TARGET_HOST_ARMv7_HARD_FLOAT */ | ||
# define _STORE_VFP_S16_S31_IF_HARD_FLOAT | ||
# define _LOAD_VFP_S16_S31_IF_HARD_FLOAT | ||
#endif /* !__TARGET_HOST_ARMv7_HARD_FLOAT */ | ||
|
||
/* | ||
* 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 */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Syscalls require to save all registers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't they? I would be grateful, if you would point to some accepted specification that describes system call-related requirements for saving register values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any documentation. But other libc implementations don't save them. The syscall implementation in the following link says: no registers are clobbered. I suspect the reason is avoid leaking information in registers for crackers.
https://chromium.googlesource.com/chromiumos/third_party/glibc-ports/+/factory-2460.B/sysdeps/unix/sysv/linux/arm/eabi/libc-do-syscall.S
I also checked the SWI implementation in the kernel. It starts with saving registers r0-r12
http://lxr.free-electrons.com/source/arch/arm/kernel/entry-common.S#L123
I seriously doubt that duplicating libc is a good idea. Systems with 1M ram does not run kernel, and we rely on their BSP. Systems with 16M ram has libc, and other applications (e.g. iot.js) will map it into the memory regardless of Jerry. So using libc is free from our perspective. Ultimately our duplicated libc just increase binary size. Maintenance is also difficult, and we cannot use optimizations (like register save skipping), because we want to be on the safe side. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case, we would oppose spending of several CPU cycles on each system call to possible reduce in code quality. As system call is relatively heavy operation, it seems to me that the optimization wouldn't somehow improve performance.
@zherczeg, thank you for sharing your view point. I think, it is better to continue the discussion in a 'discussion' issue, as it needs measurements and analysis for different platforms / configurations.