core: Add context switching for ARM and MIPS
ARM definitely compiles
This commit is contained in:
parent
48cb9a8ac0
commit
e28d4b3516
@ -65,42 +65,6 @@ pub impl Context {
|
||||
fn swap_registers(out_regs: *mut Registers, in_regs: *Registers);
|
||||
}
|
||||
|
||||
// Definitions of these registers are in rt/arch/x86_64/regs.h
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
type Registers = [uint * 22];
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
fn new_regs() -> ~Registers { ~[0, .. 22] }
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
fn initialize_call_frame(regs: &mut Registers,
|
||||
fptr: *c_void, arg: *c_void, sp: *mut uint) {
|
||||
|
||||
// Redefinitions from regs.h
|
||||
const RUSTRT_ARG0: uint = 3;
|
||||
const RUSTRT_RSP: uint = 1;
|
||||
const RUSTRT_IP: uint = 8;
|
||||
const RUSTRT_RBP: uint = 2;
|
||||
|
||||
let sp = align_down(sp);
|
||||
let sp = mut_offset(sp, -1);
|
||||
|
||||
// The final return address. 0 indicates the bottom of the stack
|
||||
unsafe { *sp = 0; }
|
||||
|
||||
rtdebug!("creating call frame");
|
||||
rtdebug!("fptr %x", fptr as uint);
|
||||
rtdebug!("arg %x", arg as uint);
|
||||
rtdebug!("sp %x", sp as uint);
|
||||
|
||||
regs[RUSTRT_ARG0] = arg as uint;
|
||||
regs[RUSTRT_RSP] = sp as uint;
|
||||
regs[RUSTRT_IP] = fptr as uint;
|
||||
|
||||
// Last base pointer on the stack should be 0
|
||||
regs[RUSTRT_RBP] = 0;
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86")]
|
||||
struct Registers {
|
||||
eax: u32, ebx: u32, ecx: u32, edx: u32,
|
||||
@ -137,6 +101,79 @@ fn initialize_call_frame(regs: &mut Registers,
|
||||
regs.ebp = 0;
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
type Registers = [uint * 22];
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
fn new_regs() -> ~Registers { ~[0, .. 22] }
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
fn initialize_call_frame(regs: &mut Registers,
|
||||
fptr: *c_void, arg: *c_void, sp: *mut uint) {
|
||||
|
||||
// Redefinitions from regs.h
|
||||
const RUSTRT_ARG0: uint = 3;
|
||||
const RUSTRT_RSP: uint = 1;
|
||||
const RUSTRT_IP: uint = 8;
|
||||
const RUSTRT_RBP: uint = 2;
|
||||
|
||||
let sp = align_down(sp);
|
||||
let sp = mut_offset(sp, -1);
|
||||
|
||||
// The final return address. 0 indicates the bottom of the stack
|
||||
unsafe { *sp = 0; }
|
||||
|
||||
rtdebug!("creating call frame");
|
||||
rtdebug!("fptr %x", fptr as uint);
|
||||
rtdebug!("arg %x", arg as uint);
|
||||
rtdebug!("sp %x", sp as uint);
|
||||
|
||||
regs[RUSTRT_ARG0] = arg as uint;
|
||||
regs[RUSTRT_RSP] = sp as uint;
|
||||
regs[RUSTRT_IP] = fptr as uint;
|
||||
|
||||
// Last base pointer on the stack should be 0
|
||||
regs[RUSTRT_RBP] = 0;
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "arm")]
|
||||
type Registers = [uint * 32];
|
||||
|
||||
#[cfg(target_arch = "arm")]
|
||||
fn new_regs() -> ~Registers { ~[0, .. 32] }
|
||||
|
||||
#[cfg(target_arch = "arm")]
|
||||
fn initialize_call_frame(regs: &mut Registers,
|
||||
fptr: *c_void, arg: *c_void, sp: *mut uint) {
|
||||
let sp = mut_offset(sp, -1);
|
||||
|
||||
// The final return address. 0 indicates the bottom of the stack
|
||||
unsafe { *sp = 0; }
|
||||
|
||||
regs[0] = arg as uint; // r0
|
||||
regs[13] = sp as uint; // #53 sp, r13
|
||||
regs[14] = fptr as uint; // #60 pc, r15 --> lr
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "mips")]
|
||||
type Registers = [uint * 32];
|
||||
|
||||
#[cfg(target_arch = "mips")]
|
||||
fn new_regs() -> ~Registers { ~[0, .. 32] }
|
||||
|
||||
#[cfg(target_arch = "mips")]
|
||||
fn initialize_call_frame(regs: &mut Registers,
|
||||
fptr: *c_void, arg: *c_void, sp: *mut uint) {
|
||||
let sp = mut_offset(sp, -1);
|
||||
|
||||
// The final return address. 0 indicates the bottom of the stack
|
||||
unsafe { *sp = 0; }
|
||||
|
||||
regs[4] = arg as uint;
|
||||
regs[29] = sp as uint;
|
||||
regs[31] = fptr as uint;
|
||||
}
|
||||
|
||||
fn align_down(sp: *mut uint) -> *mut uint {
|
||||
unsafe {
|
||||
let sp = transmute::<*mut uint, uint>(sp);
|
||||
|
@ -8,11 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// XXX: Missing some implementation for other architectures
|
||||
#[cfg(target_os = "linux")];
|
||||
#[cfg(target_os = "mac")];
|
||||
#[cfg(target_os = "win32")];
|
||||
|
||||
// Some basic logging
|
||||
macro_rules! rtdebug (
|
||||
($( $arg:expr),+) => ( {
|
||||
|
Loading…
Reference in New Issue
Block a user