From be97a77be81d286b1ae90c1050da1c7c0477ea3f Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Thu, 3 Feb 2011 14:40:57 -0800 Subject: Capture typarams into obj, independent of body tydesc. --- src/comp/back/abi.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/comp/back') diff --git a/src/comp/back/abi.rs b/src/comp/back/abi.rs index db17b942..82a85a6c 100644 --- a/src/comp/back/abi.rs +++ b/src/comp/back/abi.rs @@ -44,7 +44,8 @@ const int obj_field_vtbl = 0; const int obj_field_box = 1; const int obj_body_elt_tydesc = 0; -const int obj_body_elt_fields = 1; +const int obj_body_elt_typarams = 1; +const int obj_body_elt_fields = 2; const int fn_field_code = 0; const int fn_field_box = 1; -- cgit v1.2.3 From 467a628ffaf41844a90e6664c2ecd481eef1dc85 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 8 Feb 2011 18:09:50 -0800 Subject: Add the single instruction required in activate glue to fix burning darwin tinderbox. And transplant 100 lines of comments from the ML code. --- src/comp/back/x86.rs | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-) (limited to 'src/comp/back') diff --git a/src/comp/back/x86.rs b/src/comp/back/x86.rs index ac52fca5..907cb32e 100644 --- a/src/comp/back/x86.rs +++ b/src/comp/back/x86.rs @@ -41,20 +41,117 @@ fn store_esp_to_runtime_sp() -> vec[str] { ret vec("movl %esp, " + wstr(abi.task_field_runtime_sp) + "(%ecx)"); } +/* + * This is a bit of glue-code. It should be emitted once per + * compilation unit. + * + * - save regs on C stack + * - align sp on a 16-byte boundary + * - save sp to task.runtime_sp (runtime_sp is thus always aligned) + * - load saved task sp (switch stack) + * - restore saved task regs + * - return to saved task pc + * + * Our incoming stack looks like this: + * + * *esp+4 = [arg1 ] = task ptr + * *esp = [retpc ] + */ + fn rust_activate_glue() -> vec[str] { ret vec("movl 4(%esp), %ecx # ecx = rust_task") + save_callee_saves() + store_esp_to_runtime_sp() + load_esp_from_rust_sp() - // This 'add' instruction is a bit surprising. - // See lengthy comment in boot/be/x86.ml activate_glue. + /* + * There are two paths we can arrive at this code from: + * + * + * 1. We are activating a task for the first time. When we switch + * into the task stack and 'ret' to its first instruction, we'll + * start doing whatever the first instruction says. Probably + * saving registers and starting to establish a frame. Harmless + * stuff, doesn't look at task->rust_sp again except when it + * clobbers it during a later upcall. + * + * + * 2. We are resuming a task that was descheduled by the yield glue + * below. When we switch into the task stack and 'ret', we'll be + * ret'ing to a very particular instruction: + * + * "esp <- task->rust_sp" + * + * this is the first instruction we 'ret' to after this glue, + * because it is the first instruction following *any* upcall, + * and the task we are activating was descheduled mid-upcall. + * + * Unfortunately for us, we have already restored esp from + * task->rust_sp and are about to eat the 5 words off the top of + * it. + * + * + * | ... | <-- where esp will be once we restore + ret, below, + * | retpc | and where we'd *like* task->rust_sp to wind up. + * | ebp | + * | edi | + * | esi | + * | ebx | <-- current task->rust_sp == current esp + * + * + * This is a problem. If we return to "esp <- task->rust_sp" it + * will push esp back down by 5 words. This manifests as a rust + * stack that grows by 5 words on each yield/reactivate. Not + * good. + * + * So what we do here is just adjust task->rust_sp up 5 words as + * well, to mirror the movement in esp we're about to + * perform. That way the "esp <- task->rust_sp" we 'ret' to below + * will be a no-op. Esp won't move, and the task's stack won't + * grow. + */ + vec("addl $20, " + wstr(abi.task_field_rust_sp) + "(%ecx)") + + /* + * In most cases, the function we're returning to (activating) + * will have saved any caller-saves before it yielded via upcalling, + * so no work to do here. With one exception: when we're initially + * activating, the task needs to be in the fastcall 2nd parameter + * expected by the rust main function. That's edx. + */ + + vec("mov %ecx, %edx") + + restore_callee_saves() + vec("ret"); } +/* More glue code, this time the 'bottom half' of yielding. + * + * We arrived here because an upcall decided to deschedule the + * running task. So the upcall's return address got patched to the + * first instruction of this glue code. + * + * When the upcall does 'ret' it will come here, and its esp will be + * pointing to the last argument pushed on the C stack before making + * the upcall: the 0th argument to the upcall, which is always the + * task ptr performing the upcall. That's where we take over. + * + * Our goal is to complete the descheduling + * + * - Switch over to the task stack temporarily. + * + * - Save the task's callee-saves onto the task stack. + * (the task is now 'descheduled', safe to set aside) + * + * - Switch *back* to the C stack. + * + * - Restore the C-stack callee-saves. + * + * - Return to the caller on the C stack that activated the task. + * + */ + fn rust_yield_glue() -> vec[str] { ret vec("movl 0(%esp), %ecx # ecx = rust_task") + load_esp_from_rust_sp() -- cgit v1.2.3 From af4d6ae76b05d4edb9d7074b971600a447c9c9a4 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 22 Feb 2011 16:37:01 -0800 Subject: Add ABI tagging to crates, adjust rustc output and runtime stack-frame setup so access to argv works. --- src/comp/back/abi.rs | 3 +++ src/comp/back/x86.rs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/comp/back') diff --git a/src/comp/back/abi.rs b/src/comp/back/abi.rs index 82a85a6c..f41f6e20 100644 --- a/src/comp/back/abi.rs +++ b/src/comp/back/abi.rs @@ -60,6 +60,9 @@ const int worst_case_glue_call_args = 7; const int n_upcall_glues = 7; +const int abi_x86_rustboot_cdecl = 1; +const int abi_x86_rustc_fastcall = 2; + fn memcpy_glue_name() -> str { ret "rust_memcpy_glue"; } diff --git a/src/comp/back/x86.rs b/src/comp/back/x86.rs index 907cb32e..10227df7 100644 --- a/src/comp/back/x86.rs +++ b/src/comp/back/x86.rs @@ -98,12 +98,12 @@ fn rust_activate_glue() -> vec[str] { * | esi | * | ebx | <-- current task->rust_sp == current esp * - * + * * This is a problem. If we return to "esp <- task->rust_sp" it * will push esp back down by 5 words. This manifests as a rust * stack that grows by 5 words on each yield/reactivate. Not * good. - * + * * So what we do here is just adjust task->rust_sp up 5 words as * well, to mirror the movement in esp we're about to * perform. That way the "esp <- task->rust_sp" we 'ret' to below -- cgit v1.2.3 From dddeba19d33a1aa2e7681ae84424dbe4d7b510b7 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 2 Mar 2011 16:42:09 -0800 Subject: Sketch out some more pieces of vec-append. --- src/comp/back/abi.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/comp/back') diff --git a/src/comp/back/abi.rs b/src/comp/back/abi.rs index f41f6e20..89d6b487 100644 --- a/src/comp/back/abi.rs +++ b/src/comp/back/abi.rs @@ -71,6 +71,10 @@ fn bzero_glue_name() -> str { ret "rust_bzero_glue"; } +fn vec_grow_glue_name() -> str { + ret "rust_vec_grow_glue"; +} + fn upcall_glue_name(int n) -> str { ret "rust_upcall_" + util.common.istr(n); } -- cgit v1.2.3 From 652cb484758a72811e16a574805ce60827daa153 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Thu, 3 Mar 2011 18:18:51 -0800 Subject: Assortment of additional work on vec-append. Not done yet. --- src/comp/back/abi.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/comp/back') diff --git a/src/comp/back/abi.rs b/src/comp/back/abi.rs index 89d6b487..dd058590 100644 --- a/src/comp/back/abi.rs +++ b/src/comp/back/abi.rs @@ -71,8 +71,8 @@ fn bzero_glue_name() -> str { ret "rust_bzero_glue"; } -fn vec_grow_glue_name() -> str { - ret "rust_vec_grow_glue"; +fn vec_append_glue_name() -> str { + ret "rust_vec_append_glue"; } fn upcall_glue_name(int n) -> str { -- cgit v1.2.3