sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

osSpTaskLoadGo.c (2451B)


      1 #include "libultra_internal.h"
      2 #include "PR/rcp.h"
      3 #include <macros.h>
      4 
      5 #define _osVirtualToPhysical(ptr)                                                                      \
      6     if (ptr != NULL) {                                                                                 \
      7         ptr = (void *) osVirtualToPhysical(ptr);                                                       \
      8     }
      9 
     10 FORCE_BSS OSTask tmpTask;
     11 
     12 OSTask *_VirtualToPhysicalTask(OSTask *task) {
     13     OSTask *physicalTask;
     14     physicalTask = &tmpTask;
     15     bcopy(task, physicalTask, sizeof(OSTask));
     16     _osVirtualToPhysical(physicalTask->t.ucode);
     17     _osVirtualToPhysical(physicalTask->t.ucode_data);
     18     _osVirtualToPhysical(physicalTask->t.dram_stack);
     19     _osVirtualToPhysical(physicalTask->t.output_buff);
     20     _osVirtualToPhysical(physicalTask->t.output_buff_size);
     21     _osVirtualToPhysical(physicalTask->t.data_ptr);
     22     _osVirtualToPhysical(physicalTask->t.yield_data_ptr);
     23     return physicalTask;
     24 }
     25 
     26 void osSpTaskLoad(OSTask *task) {
     27     OSTask *physicalTask;
     28     physicalTask = _VirtualToPhysicalTask(task);
     29     if (physicalTask->t.flags & M_TASK_FLAG0) {
     30         physicalTask->t.ucode_data = physicalTask->t.yield_data_ptr;
     31         physicalTask->t.ucode_data_size = physicalTask->t.yield_data_size;
     32         task->t.flags &= ~M_TASK_FLAG0;
     33 #if defined(VERSION_SH) || defined(VERSION_CN)
     34         if (physicalTask->t.flags & M_TASK_FLAG2) {
     35             physicalTask->t.ucode = (u64 *) IO_READ((uintptr_t)task->t.yield_data_ptr + 0xBFC);
     36         }
     37 #endif
     38     }
     39     osWritebackDCache(physicalTask, sizeof(OSTask));
     40     __osSpSetStatus(SPSTATUS_CLEAR_SIGNAL0 | SPSTATUS_CLEAR_SIGNAL1 | SPSTATUS_CLEAR_SIGNAL2
     41                     | SPSTATUS_SET_INTR_ON_BREAK);
     42     while (__osSpSetPc((void *) SP_IMEM_START) == -1) {
     43         ;
     44     }
     45     while (__osSpRawStartDma(1, (void *) (SP_IMEM_START - sizeof(*physicalTask)), physicalTask,
     46                              sizeof(OSTask))
     47            == -1) {
     48         ;
     49     }
     50     while (__osSpDeviceBusy()) {
     51         ;
     52     }
     53     while (__osSpRawStartDma(1, (void *) SP_IMEM_START, physicalTask->t.ucode_boot,
     54                              physicalTask->t.ucode_boot_size)
     55            == -1) {
     56         ;
     57     }
     58 }
     59 
     60 void osSpTaskStartGo(UNUSED OSTask *task) {
     61     while (__osSpDeviceBusy()) {
     62         ;
     63     }
     64     __osSpSetStatus(SPSTATUS_SET_INTR_ON_BREAK | SPSTATUS_CLEAR_SSTEP | SPSTATUS_CLEAR_BROKE
     65                     | SPSTATUS_CLEAR_HALT);
     66 }