| 1 | #include <basis/seadRawPrint.h> |
|---|---|
| 2 | #include <mc/seadCoreInfo.h> |
| 3 | |
| 4 | namespace sead |
| 5 | { |
| 6 | u32 CoreInfo::sNumCores = 1; |
| 7 | u32 CoreInfo::sPlatformCoreId[32]{}; |
| 8 | CoreId CoreInfo::sCoreIdFromPlatformCoreIdTable[32]{}; |
| 9 | #ifdef NNSDK |
| 10 | nn::os::TlsSlot CoreInfo::sCoreNumberTlsSlot{}; |
| 11 | #endif |
| 12 | |
| 13 | namespace |
| 14 | { |
| 15 | // Force a static constructor to be emitted to initialize CoreInfo. |
| 16 | struct CoreInfoInitializer |
| 17 | { |
| 18 | CoreInfoInitializer() { CoreInfo::configure(); } |
| 19 | }; |
| 20 | // IMPORTANT: this must be located after sCoreIdFromPlatformCoreIdTable to get the correct |
| 21 | // initialization order. |
| 22 | static CoreInfoInitializer sInitializer; |
| 23 | } // namespace |
| 24 | |
| 25 | u32 CoreIdMask::countOnBits() const |
| 26 | { |
| 27 | u32 x = mMask; |
| 28 | x = (x & 0x55555555) + ((x >> 1) & 0x55555555); |
| 29 | x = (x & 0x33333333) + ((x >> 2) & 0x33333333); |
| 30 | x = (x & 0x07070707) + ((x >> 4) & 0x07070707); |
| 31 | x = (x & 0x000F000F) + ((x >> 8) & 0x000F000F); |
| 32 | x = (x & 0x1F) + (x >> 16); |
| 33 | return x; |
| 34 | } |
| 35 | |
| 36 | void CoreInfo::configure() |
| 37 | { |
| 38 | #ifdef NNSDK |
| 39 | sNumCores = 3; |
| 40 | sPlatformCoreId[0] = 0; |
| 41 | sPlatformCoreId[1] = 1; |
| 42 | sPlatformCoreId[2] = 2; |
| 43 | |
| 44 | SEAD_ASSERT(nn::os::GetCurrentCoreNumber() == 0); |
| 45 | const auto alloc_result = nn::os::AllocateTlsSlot(slot_out: &sCoreNumberTlsSlot, nullptr); |
| 46 | SEAD_ASSERT(alloc_result.IsSuccess()); |
| 47 | |
| 48 | for (u32 i = 0; i != sNumCores; ++i) |
| 49 | { |
| 50 | const u32 id = sPlatformCoreId[i]; |
| 51 | sCoreIdFromPlatformCoreIdTable[id] = i; |
| 52 | } |
| 53 | #else |
| 54 | #error "Unknown platform" |
| 55 | #endif |
| 56 | } |
| 57 | |
| 58 | void CoreInfo::dump() |
| 59 | { |
| 60 | system::Print(format: "* num cores %d\n", sNumCores); |
| 61 | for (u32 i = 0; i < sNumCores; ++i) |
| 62 | { |
| 63 | system::Print(format: " [%d] : %s : PlatformCoreId=%d\n", i, i == 0 ? "Main": "Sub ", |
| 64 | sPlatformCoreId[i]); |
| 65 | } |
| 66 | system::Print(format: "all mask : %x\n", u32(getMaskAll())); |
| 67 | system::Print(format: "all sub mask : %x\n", u32(getMaskSubAll())); |
| 68 | } |
| 69 | |
| 70 | u32 CoreInfo::getPlatformMask(CoreId id) |
| 71 | { |
| 72 | return 1 << getPlatformCoreId(id); |
| 73 | } |
| 74 | |
| 75 | } // namespace sead |
| 76 |