From cf1960dbbd490743029d8864172f6cf4d4d89fc6 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Thu, 26 Mar 2015 15:50:45 +0300 Subject: [PATCH] Support for 32-bit Linux in Jerry's libc. --- build/configs/toolchain_linux_i686.cmake | 19 ++++ jerry-libc/CMakeLists.txt | 4 + jerry-libc/target/linux/asm_x86.h | 109 ++++++++++++++--------- 3 files changed, 88 insertions(+), 44 deletions(-) create mode 100644 build/configs/toolchain_linux_i686.cmake diff --git a/build/configs/toolchain_linux_i686.cmake b/build/configs/toolchain_linux_i686.cmake new file mode 100644 index 000000000..2eabbc8da --- /dev/null +++ b/build/configs/toolchain_linux_i686.cmake @@ -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++) diff --git a/jerry-libc/CMakeLists.txt b/jerry-libc/CMakeLists.txt index 24ef95f7d..f384d926f 100644 --- a/jerry-libc/CMakeLists.txt +++ b/jerry-libc/CMakeLists.txt @@ -32,6 +32,8 @@ set(COMPILE_FLAGS_LIBC "${COMPILE_FLAGS_JERRY} ${C_FLAGS_JERRY}") set(DEFINES_LIBC_X86_64 __TARGET_HOST_x64) # ARMv7 set(DEFINES_LIBC_ARMV7 __TARGET_HOST_ARMv7) + # x86 + set(DEFINES_LIBC_X86 __TARGET_HOST_x86) # Platform-specific # Linux @@ -102,6 +104,8 @@ set(COMPILE_FLAGS_LIBC "${COMPILE_FLAGS_JERRY} ${C_FLAGS_JERRY}") set(DEFINES_LIBC ${DEFINES_LIBC} ${DEFINES_LIBC_X86_64}) elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l") set(DEFINES_LIBC ${DEFINES_LIBC} ${DEFINES_LIBC_ARMV7}) + elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") + set(DEFINES_LIBC ${DEFINES_LIBC} ${DEFINES_LIBC_X86}) else() message(FATAL_ERROR "Unsupported machine architecture") endif() diff --git a/jerry-libc/target/linux/asm_x86.h b/jerry-libc/target/linux/asm_x86.h index cf9815675..c4dcefcee 100644 --- a/jerry-libc/target/linux/asm_x86.h +++ b/jerry-libc/target/linux/asm_x86.h @@ -16,57 +16,78 @@ #ifndef 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 arg1 -> %rdi - * syscall - * mov %rax -> ret + * mov syscall_no -> %eax + * mov arg1 -> %ebx + * mov arg2 -> %ecx + * int $0x80 + * mov %eax -> ret */ -#define SYSCALL_1 (syscall_no, arg1, ret) \ - __asm ("syscall" \ - : "=a" (ret) \ - : "a" (syscall_no), "D" (arg1) \ - : "rcx", "r11"); +#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 -> %rax - * mov arg1 -> %rdi - * mov arg2 -> %rsi - * syscall - * mov %rax -> ret + * mov syscall_no -> %eax + * mov arg1 -> %ebx + * mov arg2 -> %ecx + * mov arg3 -> %edx + * int $0x80 + * mov %eax -> ret */ -#define SYSCALL_2 (syscall_no, arg1, arg2, ret) \ - __asm ("syscall" \ - : "=a" (ret) \ - : "a" (syscall_no), "D" (arg1), "S" (arg2) \ - : "rcx", "r11"); +#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; -/* - * 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: \ +#define _START \ + mov %esp, %eax; \ + add $4, %eax; \ + push %eax; \ + mov 0x4 (%esp), %eax; \ + push %eax; \ + \ + call main; \ + \ + push %eax; \ + call exit; \ + 1: \ jmp 1b #endif /* !ASM_X86_H */