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)
# 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()
+65 -44
View File
@@ -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 */