Commit 12887e4a authored by Kunshan Wang's avatar Kunshan Wang

Compiles for Linux

NOTE: Only fixed hand-written ASMs. Emitted ".s" files still have problems.
parent 54361cad
......@@ -3,9 +3,19 @@ extern crate gcc;
#[cfg(target_os = "macos")]
#[cfg(target_arch = "x86_64")]
fn main() {
gcc::compile_library("libruntime.a", &["src/runtime/runtime_x64_macos.c"]);
gcc::compile_library("libruntime.a", &["src/runtime/runtime_x64_sysv.c"]);
gcc::Config::new().flag("-O3")
.file("src/runtime/swap_stack_x64_macos.s")
.file("src/runtime/swap_stack_x64_sysv.S")
.compile("libswap_stack.a");
}
#[cfg(target_os = "linux")]
#[cfg(target_arch = "x86_64")]
fn main() {
gcc::compile_library("libruntime.a", &["src/runtime/runtime_x64_sysv.c"]);
gcc::Config::new().flag("-O3")
.file("src/runtime/swap_stack_x64_sysv.S")
.compile("libswap_stack.a");
}
extern crate gcc;
#[cfg(target_os = "macos")]
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_arch = "x86_64")]
fn main() {
gcc::compile_library("libgc_clib_x64.a", &["src/heap/gc/clib_x64.c"]);
......
// This file provides a template so that we can define functions in ASM and also
// let the symbols be recognised in both Linux and OSX
#if defined (__linux__)
#define CNAME(n) n
.macro begin_func n
.text
.globl CNAME(\n)
.type CNAME(\n),@function
.align 16
CNAME(\n):
.endm
.macro end_func n
.size CNAME(\n), .-CNAME(\n)
.endm
#elif defined (__APPLE__)
#define CNAME(n) _##n
.macro begin_func n
.text
.globl CNAME(\n)
.align 4
CNAME(\n):
.endm
.macro end_func n
.endm
#else
#error "Only Linux and OSX are supported."
#endif
; vim: ft=asm
#ifdef __linux__
// RTLD_DEFAULT is not defined in POSIX. Linux gcc does not define it unless
// _GNU_SOURCE is also defined.
#define _GNU_SOURCE
#endif // __linux__
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
......
#include "asm_common.S.inc"
# swap_stack_to(new_sp: Address, entry: Address, old_sp_loc: Address)
# %rdi %rsi %rdx
.globl _swap_to_mu_stack
_swap_to_mu_stack:
begin_func swap_to_mu_stack
# -- on old stack --
# C calling convention
pushq %rbp
......@@ -46,11 +47,11 @@ _swap_to_mu_stack:
# push entry function and start it
pushq %rax
ret
end_func swap_to_mu_stack
# _swap_back_to_native_stack(sp_loc: Address)
# %rdi
.globl _muentry_swap_back_to_native_stack
_muentry_swap_back_to_native_stack:
begin_func muentry_swap_back_to_native_stack
movq 0(%rdi), %rsp
popq %r15
......@@ -61,18 +62,18 @@ _muentry_swap_back_to_native_stack:
popq %rbp
ret
end_func muentry_swap_back_to_native_stack
# _get_current_frame_rbp() -> Address
.globl _get_current_frame_rbp
_get_current_frame_rbp:
begin_func get_current_frame_rbp
movq %rbp, %rax
ret
end_func get_current_frame_rbp
# _exception_restore(dest: Address, callee_saved: *const Word, rsp: Address) -> !
# %rdi %rsi %rdx
# callee_saved: [rbx, rbp, r12, r13, r14, r15]
.globl _exception_restore
_exception_restore:
begin_func exception_restore
movq 0(%rsi), %rbx
movq 8(%rsi), %rbp
movq 16(%rsi),%r12
......@@ -82,3 +83,4 @@ _exception_restore:
movq %rdx, %rsp
jmpq *%rdi
end_func exception_restore
......@@ -235,7 +235,7 @@ lazy_static! {
}
#[cfg(target_arch = "x86_64")]
#[cfg(target_os = "macos")]
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[link(name = "runtime")]
extern "C" {
pub fn set_thread_local(thread: *mut MuThread);
......@@ -243,7 +243,7 @@ extern "C" {
}
#[cfg(target_arch = "x86_64")]
#[cfg(target_os = "macos")]
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[link(name = "swap_stack")]
extern "C" {
fn swap_to_mu_stack(new_sp: Address, entry: Address, old_sp_loc: Address);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment