Support for 32-bit Linux in Jerry's libc.

This commit is contained in:
Ruben Ayrapetyan
2015-03-26 15:50:45 +03:00
parent 6b0b669c14
commit cf1960dbbd
3 changed files with 88 additions and 44 deletions
+19
View File
@@ -0,0 +1,19 @@
# 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 x86)
set(CMAKE_C_COMPILER i686-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER i686-linux-gnu-g++)
+4
View File
@@ -32,6 +32,8 @@ set(COMPILE_FLAGS_LIBC "${COMPILE_FLAGS_JERRY} ${C_FLAGS_JERRY}")
set(DEFINES_LIBC_X86_64 __TARGET_HOST_x64) set(DEFINES_LIBC_X86_64 __TARGET_HOST_x64)
# ARMv7 # ARMv7
set(DEFINES_LIBC_ARMV7 __TARGET_HOST_ARMv7) set(DEFINES_LIBC_ARMV7 __TARGET_HOST_ARMv7)
# x86
set(DEFINES_LIBC_X86 __TARGET_HOST_x86)
# Platform-specific # Platform-specific
# Linux # Linux
@@ -102,6 +104,8 @@ set(COMPILE_FLAGS_LIBC "${COMPILE_FLAGS_JERRY} ${C_FLAGS_JERRY}")
set(DEFINES_LIBC ${DEFINES_LIBC} ${DEFINES_LIBC_X86_64}) set(DEFINES_LIBC ${DEFINES_LIBC} ${DEFINES_LIBC_X86_64})
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l")
set(DEFINES_LIBC ${DEFINES_LIBC} ${DEFINES_LIBC_ARMV7}) set(DEFINES_LIBC ${DEFINES_LIBC} ${DEFINES_LIBC_ARMV7})
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
set(DEFINES_LIBC ${DEFINES_LIBC} ${DEFINES_LIBC_X86})
else() else()
message(FATAL_ERROR "Unsupported machine architecture") message(FATAL_ERROR "Unsupported machine architecture")
endif() endif()
+65 -44
View File
@@ -16,57 +16,78 @@
#ifndef ASM_X86_H #ifndef ASM_X86_H
#define ASM_X86_H #define ASM_X86_H
FIXME(Implement x86 ABI); /*
#error "Not implemented" * 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 -> %rax * mov syscall_no -> %eax
* mov arg1 -> %rdi * mov arg1 -> %ebx
* syscall * mov arg2 -> %ecx
* mov %rax -> ret * int $0x80
* mov %eax -> ret
*/ */
#define SYSCALL_1 (syscall_no, arg1, ret) \ #define SYSCALL_2 \
__asm ("syscall" \ push %edi; \
: "=a" (ret) \ push %esi; \
: "a" (syscall_no), "D" (arg1) \ push %ebx; \
: "rcx", "r11"); mov 0x10 (%esp), %eax; \
mov 0x14 (%esp), %ebx; \
mov 0x18 (%esp), %ecx; \
int $0x80; \
pop %ebx; \
pop %esi; \
pop %edi; \
ret;
/* /*
* mov syscall_no -> %rax * mov syscall_no -> %eax
* mov arg1 -> %rdi * mov arg1 -> %ebx
* mov arg2 -> %rsi * mov arg2 -> %ecx
* syscall * mov arg3 -> %edx
* mov %rax -> ret * int $0x80
* mov %eax -> ret
*/ */
#define SYSCALL_2 (syscall_no, arg1, arg2, ret) \ #define SYSCALL_3 \
__asm ("syscall" \ push %edi; \
: "=a" (ret) \ push %esi; \
: "a" (syscall_no), "D" (arg1), "S" (arg2) \ push %ebx; \
: "rcx", "r11"); 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;
/* #define _START \
* mov syscall_no -> %rax mov %esp, %eax; \
* mov arg1 -> %rdi add $4, %eax; \
* mov arg2 -> %rsi push %eax; \
* mov arg3 -> %rdx mov 0x4 (%esp), %eax; \
* syscall push %eax; \
* mov %rax -> ret \
*/ call main; \
#define SYSCALL_3 (syscall_no, arg1, arg2, arg3, ret) \ \
__asm ("syscall" \ push %eax; \
: "=a" (ret) \ call exit; \
: "a" (syscall_no), "D" (arg1), "S" (arg2), "d" (arg3) \ 1: \
: "rcx", "r11");
#define _START \
mov (%rsp), %rdi; \
mov %rsp, %rsi; \
add $8, %rsi; \
callq main; \
\
mov %rax, %rdi; \
callq exit; \
1: \
jmp 1b jmp 1b
#endif /* !ASM_X86_H */ #endif /* !ASM_X86_H */