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; ...@@ -3,9 +3,19 @@ extern crate gcc;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
fn main() { 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") 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"); .compile("libswap_stack.a");
} }
\ No newline at end of file
#[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; extern crate gcc;
#[cfg(target_os = "macos")] #[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
fn main() { fn main() {
gcc::compile_library("libgc_clib_x64.a", &["src/heap/gc/clib_x64.c"]); gcc::compile_library("libgc_clib_x64.a", &["src/heap/gc/clib_x64.c"]);
} }
\ No newline at end of file
// 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 <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
......
#include "asm_common.S.inc"
# swap_stack_to(new_sp: Address, entry: Address, old_sp_loc: Address) # swap_stack_to(new_sp: Address, entry: Address, old_sp_loc: Address)
# %rdi %rsi %rdx # %rdi %rsi %rdx
.globl _swap_to_mu_stack begin_func swap_to_mu_stack
_swap_to_mu_stack:
# -- on old stack -- # -- on old stack --
# C calling convention # C calling convention
pushq %rbp pushq %rbp
...@@ -46,11 +47,11 @@ _swap_to_mu_stack: ...@@ -46,11 +47,11 @@ _swap_to_mu_stack:
# push entry function and start it # push entry function and start it
pushq %rax pushq %rax
ret ret
end_func swap_to_mu_stack
# _swap_back_to_native_stack(sp_loc: Address) # _swap_back_to_native_stack(sp_loc: Address)
# %rdi # %rdi
.globl _muentry_swap_back_to_native_stack begin_func muentry_swap_back_to_native_stack
_muentry_swap_back_to_native_stack:
movq 0(%rdi), %rsp movq 0(%rdi), %rsp
popq %r15 popq %r15
...@@ -61,18 +62,18 @@ _muentry_swap_back_to_native_stack: ...@@ -61,18 +62,18 @@ _muentry_swap_back_to_native_stack:
popq %rbp popq %rbp
ret ret
end_func muentry_swap_back_to_native_stack
# _get_current_frame_rbp() -> Address # _get_current_frame_rbp() -> Address
.globl _get_current_frame_rbp begin_func get_current_frame_rbp
_get_current_frame_rbp:
movq %rbp, %rax movq %rbp, %rax
ret ret
end_func get_current_frame_rbp
# _exception_restore(dest: Address, callee_saved: *const Word, rsp: Address) -> ! # _exception_restore(dest: Address, callee_saved: *const Word, rsp: Address) -> !
# %rdi %rsi %rdx # %rdi %rsi %rdx
# callee_saved: [rbx, rbp, r12, r13, r14, r15] # callee_saved: [rbx, rbp, r12, r13, r14, r15]
.globl _exception_restore begin_func exception_restore
_exception_restore:
movq 0(%rsi), %rbx movq 0(%rsi), %rbx
movq 8(%rsi), %rbp movq 8(%rsi), %rbp
movq 16(%rsi),%r12 movq 16(%rsi),%r12
...@@ -82,3 +83,4 @@ _exception_restore: ...@@ -82,3 +83,4 @@ _exception_restore:
movq %rdx, %rsp movq %rdx, %rsp
jmpq *%rdi jmpq *%rdi
end_func exception_restore
...@@ -235,7 +235,7 @@ lazy_static! { ...@@ -235,7 +235,7 @@ lazy_static! {
} }
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
#[cfg(target_os = "macos")] #[cfg(any(target_os = "macos", target_os = "linux"))]
#[link(name = "runtime")] #[link(name = "runtime")]
extern "C" { extern "C" {
pub fn set_thread_local(thread: *mut MuThread); pub fn set_thread_local(thread: *mut MuThread);
...@@ -243,7 +243,7 @@ extern "C" { ...@@ -243,7 +243,7 @@ extern "C" {
} }
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
#[cfg(target_os = "macos")] #[cfg(any(target_os = "macos", target_os = "linux"))]
#[link(name = "swap_stack")] #[link(name = "swap_stack")]
extern "C" { extern "C" {
fn swap_to_mu_stack(new_sp: Address, entry: Address, old_sp_loc: Address); fn swap_to_mu_stack(new_sp: Address, entry: Address, old_sp_loc: Address);
...@@ -329,4 +329,4 @@ impl MuThread { ...@@ -329,4 +329,4 @@ impl MuThread {
pub struct MuPrimordialThread { pub struct MuPrimordialThread {
pub func_id: MuID, pub func_id: MuID,
pub args: Vec<Constant> pub args: Vec<Constant>
} }
\ No newline at end of file
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