| 55 | ****************************************************************************/ |
| 56 | |
| 57 | void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb) |
| 58 | { |
| 59 | int ret; |
| 60 | |
| 61 | sinfo("Unblocking TCB=%p\n", tcb); |
| 62 | |
| 63 | /* Are we in an interrupt handler? */ |
| 64 | |
| 65 | if (up_interrupt_context()) |
| 66 | { |
| 67 | /* Yes, then we have to do things differently. |
| 68 | * Just copy the current_regs into the OLD rtcb. |
| 69 | */ |
| 70 | |
| 71 | sim_savestate(rtcb->xcp.regs); |
| 72 | |
| 73 | /* Then switch contexts */ |
| 74 | |
| 75 | sim_restorestate(tcb->xcp.regs); |
| 76 | |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | /* Copy the exception context into the TCB of the task that was |
| 81 | * previously active. if sim_saveusercontext returns a non-zero value, |
| 82 | * then this is really the previously running task restarting! |
| 83 | */ |
| 84 | |
| 85 | sim_saveusercontext(rtcb->xcp.regs, ret); |
| 86 | if (ret == 0) |
| 87 | { |
| 88 | sinfo("New Active Task TCB=%p\n", tcb); |
| 89 | |
| 90 | /* Update scheduler parameters */ |
| 91 | |
| 92 | nxsched_switch_context(rtcb, tcb); |
| 93 | |
| 94 | /* Restore the cpu lock */ |
| 95 | |
| 96 | restore_critical_section(tcb, this_cpu()); |
| 97 | |
| 98 | /* Record the new "running" task */ |
| 99 | |
| 100 | g_running_tasks[this_cpu()] = tcb; |
| 101 | |
| 102 | /* Then switch contexts */ |
| 103 | |
| 104 | sim_fullcontextrestore(tcb->xcp.regs); |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | #ifdef CONFIG_ENABLE_ALL_SIGNALS |
| 109 | /* The way that we handle signals in the simulation is kind of |
| 110 | * a kludge. This would be unsafe in a truly multi-threaded, |
| 111 | * interrupt driven environment. |
| 112 | */ |
| 113 | |
| 114 | sim_sigdeliver(); |
no test coverage detected