X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FStgStartup.cmm;h=2f2a759c81b752b0f4c7f686b958ed82fb127f93;hb=876b4ef2093cb9c104db33c7db1200b941b6d079;hp=2d5d4d89415270204b8f8a00012bd18eb47d08cf;hpb=1621421619df6f19dce3b8cb29471e5d3c731acb;p=ghc-hetmet.git diff --git a/ghc/rts/StgStartup.cmm b/ghc/rts/StgStartup.cmm index 2d5d4d8..2f2a759 100644 --- a/ghc/rts/StgStartup.cmm +++ b/ghc/rts/StgStartup.cmm @@ -29,7 +29,7 @@ ASSERT(Sp != 0); \ ASSERT(SpLim != 0); \ ASSERT(HpLim != 0); \ - ASSERT(SpLim - RESERVED_STACK_WORDS <= Sp); \ + ASSERT(SpLim - WDS(RESERVED_STACK_WORDS) <= Sp); \ ASSERT(HpLim >= Hp); /* ----------------------------------------------------------------------------- @@ -92,8 +92,9 @@ INFO_TABLE_RET( stg_stop_thread, STOP_THREAD_WORDS, STOP_THREAD_BITMAP, SAVE_THREAD_STATE(); - /* R1 contains the return value of the thread */ - R1 = ThreadFinished; + /* The return code goes in BaseReg->rRet, and BaseReg is returned in R1 */ + StgRegTable_rRet(BaseReg) = ThreadFinished; + R1 = BaseReg; jump StgReturn; } @@ -102,6 +103,9 @@ INFO_TABLE_RET( stg_stop_thread, STOP_THREAD_WORDS, STOP_THREAD_BITMAP, Start a thread from the scheduler by returning to the address on the top of the stack. This is used for all entries to STG code from C land. + + On the way back, we (usually) pass through stg_returnToSched which saves + the thread's state away nicely. -------------------------------------------------------------------------- */ stg_returnToStackTop @@ -111,6 +115,34 @@ stg_returnToStackTop jump %ENTRY_CODE(Sp(0)); } +stg_returnToSched +{ + SAVE_THREAD_STATE(); + foreign "C" threadPaused(MyCapability() "ptr", CurrentTSO); + jump StgReturn; +} + +// A variant of stg_returntToSched that doesn't call threadPaused() on the +// current thread. This is used for switching from compiled execution to the +// interpreter, where calling threadPaused() on every switch would be too +// expensive. +stg_returnToSchedNotPaused +{ + SAVE_THREAD_STATE(); + jump StgReturn; +} + +// A variant of stg_returnToSched, but instead of returning directly to the +// scheduler, we jump to the code fragment pointed to by R2. This lets us +// perform some final actions after making the thread safe, such as unlocking +// the MVar on which we are about to block in SMP mode. +stg_returnToSchedButFirst +{ + SAVE_THREAD_STATE(); + foreign "C" threadPaused(MyCapability() "ptr", CurrentTSO); + jump R2; +} + /* ----------------------------------------------------------------------------- Strict IO application - performing an IO action and entering its result.