void Skedule() { UINTN i; thread_list * oldThread; BOOLEAN CouldSkedule ; CouldSkedule = __sync_bool_compare_and_swap (&Inschedule, 0, 1); if(CouldSkedule == 0) return; //pebp(); oldThread = sys.current; if(oldThread->thread.status == STATUS_DEAD){ remove_thread(); //switchto(); LongJump(& sys.current->thread.sig_context, 1); } free_dead_stack(); sys.current = getNext(sys.current); if(oldThread == sys.current) return; i = SetJump(&oldThread->thread.sig_context); if( i == 0) { //EnableInterrupt (); gBS->RestoreTPL(TPL_APPLICATION); LongJump(& sys.current->thread.sig_context, 1); } __sync_bool_compare_and_swap (&Inschedule, 1, 0); //pebp(); // Print(L"Haha, I am resuming\n"); //while(1); }
/** Transfers control to a function starting with a new stack. Transfers control to the function specified by EntryPoint using the new stack specified by NewStack and passing in the parameters specified by Context1 and by Context1 and Context2. Context1 and Context2 are optional and may be NULL. The function EntryPoint must never return. Marker will be ignored on IA-32, x64, and EBC. IPF CPUs expect one additional parameter of type VOID * that specifies the new backing store pointer. If EntryPoint is NULL, then ASSERT(). If NewStack is NULL, then ASSERT(). @param EntryPoint A pointer to function to call with the new stack. @param Context1 A pointer to the context to pass into the EntryPoint function. @param Context2 A pointer to the context to pass into the EntryPoint function. @param NewStack A pointer to the new stack to use for the EntryPoint function. @param Marker VA_LIST marker for the variable argument list. **/ VOID EFIAPI InternalSwitchStack ( IN SWITCH_STACK_ENTRY_POINT EntryPoint, IN VOID *Context1, OPTIONAL IN VOID *Context2, OPTIONAL IN VOID *NewStack, IN VA_LIST Marker ) { BASE_LIBRARY_JUMP_BUFFER JumpBuffer; // // Stack should be aligned with CPU_STACK_ALIGNMENT // ASSERT (((UINTN)NewStack & (CPU_STACK_ALIGNMENT - 1)) == 0); JumpBuffer.Eip = (UINTN)EntryPoint; JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*); JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2); ((VOID**)JumpBuffer.Esp)[1] = Context1; ((VOID**)JumpBuffer.Esp)[2] = Context2; LongJump (&JumpBuffer, (UINTN)-1); }
/** Transfers control to a function starting with a new stack. Transfers control to the function specified by EntryPoint using the new stack specified by NewStack and passing in the parameters specified by Context1 and Context2. Context1 and Context2 are optional and may be NULL. The function EntryPoint must never return. If EntryPoint is NULL, then ASSERT(). If NewStack is NULL, then ASSERT(). @param EntryPoint A pointer to function to call with the new stack. @param Context1 A pointer to the context to pass into the EntryPoint function. @param Context2 A pointer to the context to pass into the EntryPoint function. @param NewStack A pointer to the new stack to use for the EntryPoint function. @param NewBsp A pointer to the new BSP for the EntryPoint on IPF. It's Reserved on other architectures. **/ VOID EFIAPI PeiSwitchStacks ( IN SWITCH_STACK_ENTRY_POINT EntryPoint, IN VOID *Context1, OPTIONAL IN VOID *Context2, OPTIONAL IN VOID *Context3, OPTIONAL IN VOID *NewStack ) { BASE_LIBRARY_JUMP_BUFFER JumpBuffer; ASSERT (EntryPoint != NULL); ASSERT (NewStack != NULL); // // Stack should be aligned with CPU_STACK_ALIGNMENT // ASSERT (((UINTN)NewStack & (CPU_STACK_ALIGNMENT - 1)) == 0); JumpBuffer.Eip = (UINTN)EntryPoint; JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*); JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2) + sizeof(Context3); ((VOID**)JumpBuffer.Esp)[1] = Context1; ((VOID**)JumpBuffer.Esp)[2] = Context2; ((VOID**)JumpBuffer.Esp)[3] = Context3; LongJump (&JumpBuffer, (UINTN)-1); // // InternalSwitchStack () will never return // ASSERT (FALSE); }
/** This function is guest entrypoint during initialization. **/ VOID GuestEntrypoint ( VOID ) { DEBUG ((EFI_D_INFO, "(FRM) !!!Entry Guest!!!\n")); LongJump (&mGuestJumpBuffer, (UINTN)-1); }
/** Transfers control to a function starting with a new stack. Transfers control to the function specified by EntryPoint using the new stack specified by NewStack and passing in the parameters specified by Context1 and Context2. Context1 and Context2 are optional and may be NULL. The function EntryPoint must never return. Marker will be ignored on IA-32, x64, and EBC. IPF CPUs expect one additional parameter of type VOID * that specifies the new backing store pointer. If EntryPoint is NULL, then ASSERT(). If NewStack is NULL, then ASSERT(). @param EntryPoint A pointer to function to call with the new stack. @param Context1 A pointer to the context to pass into the EntryPoint function. @param Context2 A pointer to the context to pass into the EntryPoint function. @param NewStack A pointer to the new stack to use for the EntryPoint function. @param Marker VA_LIST marker for the variable argument list. **/ VOID EFIAPI InternalSwitchStack ( IN SWITCH_STACK_ENTRY_POINT EntryPoint, IN VOID *Context1, OPTIONAL IN VOID *Context2, OPTIONAL IN VOID *NewStack, IN VA_LIST Marker ) { BASE_LIBRARY_JUMP_BUFFER JumpBuffer; JumpBuffer.Eip = (UINTN)EntryPoint; JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*); JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2); ((VOID**)JumpBuffer.Esp)[1] = Context1; ((VOID**)JumpBuffer.Esp)[2] = Context2; LongJump (&JumpBuffer, (UINTN)-1); }
/** Transfers control to a function starting with a new stack. Transfers control to the function specified by EntryPoint using the new stack specified by NewStack and passing in the parameters specified by Context1 and Context2. Context1 and Context2 are optional and may be NULL. The function EntryPoint must never return. Marker will be ignored on IA-32, x64, and EBC. IPF CPUs expect one additional parameter of type VOID * that specifies the new backing store pointer. If EntryPoint is NULL, then ASSERT(). If NewStack is NULL, then ASSERT(). @param EntryPoint A pointer to function to call with the new stack. @param Context1 A pointer to the context to pass into the EntryPoint function. @param Context2 A pointer to the context to pass into the EntryPoint function. @param NewStack A pointer to the new stack to use for the EntryPoint function. @param Marker VA_LIST marker for the variable argument list. **/ VOID EFIAPI InternalSwitchStack ( IN SWITCH_STACK_ENTRY_POINT EntryPoint, IN VOID *Context1, OPTIONAL IN VOID *Context2, OPTIONAL IN VOID *NewStack, IN VA_LIST Marker ) { BASE_LIBRARY_JUMP_BUFFER JumpBuffer; DEBUG ((EFI_D_INFO, "RISC-V InternalSwitchStack Entry:%x Context1:%x Context2:%x NewStack%x\n", \ EntryPoint, Context1, Context2, NewStack)); JumpBuffer.RA = (UINTN)EntryPoint; JumpBuffer.SP = (UINTN)NewStack - sizeof (VOID *); JumpBuffer.S0 = (UINT64)(UINTN)Context1; JumpBuffer.S1 = (UINT64)(UINTN)Context2; LongJump (&JumpBuffer, (UINTN)-1); ASSERT(FALSE); }
void switchto( ) { LongJump(& sys.current->thread.sig_context, 1); }