Commit d09fdd8b authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano

added an init function so you can initilise a shared-library boot image

parent 9d12f03a
......@@ -239,7 +239,7 @@ pub fn link_dylib_with_extra_srcs(
for src in srcs {
ret.push(PathBuf::from(src));
}
ret.push(get_path_under_zebu("src/runtime/init.c"));
ret.push(get_path_for_mu_context(vm));
ret
......
// Copyright 2017 The Australian National University
//
// 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.
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#include <assert.h>
extern void* vm;
extern void* RODAL_END;
extern void mu_init(void*, void*);
extern uint32_t mu_retval;
extern void* STRUCT_TAG_MAP;
extern void* HYBRID_TAG_MAP;
extern void* STRUCT_TAG_MAP_LOC;
extern void* HYBRID_TAG_MAP_LOC;
void init() {
STRUCT_TAG_MAP_LOC = &STRUCT_TAG_MAP;
HYBRID_TAG_MAP_LOC = &HYBRID_TAG_MAP;
mu_init(&RODAL_END, &vm);
}
......@@ -290,12 +290,20 @@ pub static mut LAST_TIME: c_ulong = 0;
/// from C For RTMu, we start the primordial thread with the default system attr
/// The client can modify this afterwards
#[no_mangle]
pub extern "C" fn mu_main(
pub extern "C" fn mu_init(
edata: *const (),
dumped_vm: *mut Arc<VM>,
argc: c_int,
argv: *const *const c_char
) {
let vm = init_runtime(edata, dumped_vm);
// convert the current thread into a mu one
unsafe { thread::MuThread::current_thread_as_mu_thread(Address::zero(), vm); }
}
fn init_runtime(
edata: *const (),
dumped_vm: *mut Arc<VM>,
) -> Arc<VM> {
VM::start_logging_env();
debug!("mu_main() started...");
......@@ -308,13 +316,21 @@ pub extern "C" fn mu_main(
rodal::Address::from_ptr(edata)
)
};
let vm = VM::resume_vm(dumped_vm);
VM::resume_vm(dumped_vm)
// trace!(
// "VM deserialization took {} milli-seconds",
// now.elapsed().as_micros()
// );
}
#[no_mangle]
pub extern "C" fn mu_main(
edata: *const (),
dumped_vm: *mut Arc<VM>,
argc: c_int,
argv: *const *const c_char
) {
let vm = init_runtime(edata, dumped_vm);
// find the primordial function as an entry
let primordial = vm.primordial().read().unwrap();
if primordial.is_none() {
......
# Copyright 2017 The Australian National University
#
# 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.
from util import execute, compile_bundle, load_bundle, get_function;
import pytest;
import ctypes;
def test_new():
lib = load_bundle(
"""
.typedef i64 = int<64>
.funcdef test_new<(i64)->(i64)>
{
entry(<i64> arg):
obj = NEW <i64>
iobj = GETIREF <i64> obj
STORE <i64> iobj arg
res = LOAD <i64> iobj
RET res
}
""", "test_new");
get_function(lib.init, [], None)() # call init function
func = get_function(lib.test_new, [ctypes.c_int64], ctypes.c_int64)
assert(func(10) == 10)
def test_new_future():
lib = load_bundle(
"""
.typedef i64 = int<64>
.global future <i64>
.funcdef test_new_thread<(i64)->()>
{
entry(<i64> arg):
obj = NEW <i64>
iobj = GETIREF <i64> obj
STORE <i64> iobj arg
res = LOAD <i64> iobj
STORE SEQ_CST <i64> future res // store result into future
COMMINST uvm.thread_exit()
}
.funcdef test_new <(i64)->(i64)>
{
entry(<i64>arg):
STORE SEQ_CST <i64> future <i64>0 // store value indicating future is not read
s = COMMINST uvm.new_stack<[(i64)->()]>(test_new_thread)
t = NEWTHREAD s PASS_VALUES<i64>(arg)
BRANCH wait1()
wait1():
future_val = LOAD SEQ_CST <i64> future
test_result = NE <i64> future_val <i64>0
BRANCH2 test_result done(future_val) wait2()
wait2(): // this trivial block is a workaround for a bug in Zebu
BRANCH wait1()
done(<i64> res):
RET res
}
""", "test_new_future");
get_function(lib.init, [], None)() # call init function
func = get_function(lib.test_new, [ctypes.c_int64], ctypes.c_int64)
assert(func(10) == 10)
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