Skip to content

core: Add context switching for ARM and MIPS #5333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 63 additions & 26 deletions src/libcore/rt/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,42 @@ extern {
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")]
struct Registers {
eax: u32, ebx: u32, ecx: u32, edx: u32,
ebp: u32, esi: u32, edi: u32, esp: u32,
cs: u16, ds: u16, ss: u16, es: u16, fs: u16, gs: u16,
eflags: u32, eip: u32
}

#[cfg(target_arch = "x86")]
fn new_regs() -> ~Registers {
~Registers {
eax: 0, ebx: 0, ecx: 0, edx: 0,
ebp: 0, esi: 0, edi: 0, esp: 0,
cs: 0, ds: 0, ss: 0, es: 0, fs: 0, gs: 0,
eflags: 0, eip: 0
}
}

#[cfg(target_arch = "x86")]
fn initialize_call_frame(regs: &mut Registers,
fptr: *c_void, arg: *c_void, sp: *mut uint) {

let sp = align_down(sp);
let sp = mut_offset(sp, -4); // XXX: -4 words? Needs this be done at all?

unsafe { *sp = arg as uint; }
let sp = mut_offset(sp, -1);
unsafe { *sp = 0; } // The final return address

regs.esp = sp as u32;
regs.eip = fptr as u32;

// Last base pointer on the stack is 0
regs.ebp = 0;
}

#[cfg(target_arch = "x86_64")]
type Registers = [uint * 22];

Expand Down Expand Up @@ -101,40 +136,42 @@ fn initialize_call_frame(regs: &mut Registers,
regs[RUSTRT_RBP] = 0;
}

#[cfg(target_arch = "x86")]
struct Registers {
eax: u32, ebx: u32, ecx: u32, edx: u32,
ebp: u32, esi: u32, edi: u32, esp: u32,
cs: u16, ds: u16, ss: u16, es: u16, fs: u16, gs: u16,
eflags: u32, eip: u32
}
#[cfg(target_arch = "arm")]
type Registers = [uint * 32];

#[cfg(target_arch = "x86")]
fn new_regs() -> ~Registers {
~Registers {
eax: 0, ebx: 0, ecx: 0, edx: 0,
ebp: 0, esi: 0, edi: 0, esp: 0,
cs: 0, ds: 0, ss: 0, es: 0, fs: 0, gs: 0,
eflags: 0, eip: 0
}
}
#[cfg(target_arch = "arm")]
fn new_regs() -> ~Registers { ~[0, .. 32] }

#[cfg(target_arch = "x86")]
#[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);

let sp = align_down(sp);
let sp = mut_offset(sp, -4); // XXX: -4 words? Needs this be done at all?
// The final return address. 0 indicates the bottom of the stack
unsafe { *sp = 0; }

unsafe { *sp = arg as uint; }
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);
unsafe { *sp = 0; } // The final return address

regs.esp = sp as u32;
regs.eip = fptr as u32;
// The final return address. 0 indicates the bottom of the stack
unsafe { *sp = 0; }

// Last base pointer on the stack is 0
regs.ebp = 0;
regs[4] = arg as uint;
regs[29] = sp as uint;
regs[31] = fptr as uint;
}

fn align_down(sp: *mut uint) -> *mut uint {
Expand Down
5 changes: 0 additions & 5 deletions src/libcore/rt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),+) => ( {
Expand Down