Пример #1
0
u32 wrapWaitSynchronizationN(u32 nanoseconds1,u32 handles_ptr,u32 handles_count,u32 wait_all,u32 nanoseconds2,u32 out) // TODO: timeouts
{
    bool all_unlocked = true;

    for (u32 i = 0; i < handles_count; i++) {
        u32 handle = mem_Read32(handles_ptr + i * 4);
        handleinfo* hi = handle_Get(handle);

        if (hi == NULL) {
            arm11_SetR(1, i);
            ERROR("handle %08x not found.\n", handle);
            PAUSE();
#ifdef EXIT_ON_ERROR
            exit(1);
#endif
            return -1;
        }

        if (hi->type >= NUM_HANDLE_TYPES) {
            // This should never happen.
            ERROR("handle %08x has non-defined type.\n", handle);
            PAUSE();
            exit(1);
        }

        // Lookup actual callback in table.
        if (handle_types[hi->type].fnWaitSynchronization != NULL) {
            bool locked = false;

            handle_types[hi->type].fnWaitSynchronization(hi, &locked);

            if (!locked && !wait_all) {
                arm11_SetR(1, i);
                return 0;
            } else
                all_unlocked = false;

        } else {
            ERROR("WaitSynchronization undefined for handle-type \"%s\".\n",
                  handle_types[hi->type].name);
            PAUSE();
            arm11_SetR(1, i); //we just say this one is open
            return 0;
        }
    }

    if(wait_all && all_unlocked) {
        arm11_SetR(1, handles_count);
        return 0;
    }

    // Put thread in WAITING state if not all handles were unlocked.
    u32* wait_list = malloc(handles_count*4);
    mem_Read((u8 *) wait_list, handles_ptr, handles_count * 4);

    threads_SetCurrentThreadWaitList(wait_list, wait_all, handles_count);
    return 0;

}
Пример #2
0
u32 thread_SyncRequest(handleinfo* h, bool *locked)
{
    u32 cid = mem_Read32(arm11_ServiceBufferAddress() + 0x80);

    switch (cid) {
    default:
        break;
    }

    ERROR("STUBBED, cid=%08x\n", cid);
    arm11_Dump();
    PAUSE();
    return 0;
}
Пример #3
0
s32 svcGetResourceLimitCurrentValues()
{
    u32 values_ptr = arm11_R(0);
    u32 handleResourceLimit = arm11_R(1);
    u32 names_ptr = arm11_R(2);
    u32 nameCount = arm11_R(3);
    for (u32 i = 0; i < nameCount; i++) {
        u32 temp = mem_Read32(names_ptr + i*4);
        switch (temp) {
        case 1: //GetUsingMemorySize
            mem_Write32(values_ptr + i * 8, 0x0);
            mem_Write32(values_ptr + i * 8 + 4, 0x0);
            break;
        default:
            DEBUG("unknown ResourceLimitCurrentValues %08x",temp);
            break;
        }
    }
    return 0;
}
Пример #4
0
u32 svcControlMemory()
{
    u32 op    = arm11_R(0);
    u32 addr0 = arm11_R(1);
    u32 addr1 = arm11_R(2);
    u32 size  = arm11_R(3);
    u32 perm    = arm11_R(4);
    u32 outadr = mem_Read32(arm11_R(13));

    const char* ops;
    switch(op & 0xFF) {
    case 1:
        ops = "FREE";
        break;
    case 2:
        ops = "RESERVE";
        break;
    case 3:
        ops = "COMMIT";
        break;
    case 4:
        ops = "MAP";
        break;
    case 5:
        ops = "UNMAP";
        break;
    case 6:
        ops = "PROTECT";
        break;
    default:
        ops = "UNDEFINED";
        break;
    }

    const char* perms;
    switch(perm) {
    case 0:
        perms = "--";
        break;
    case 1:
        perms = "-R";
        break;
    case 2:
        perms = "W-";
        break;
    case 3:
        perms = "WR";
        break;
    case 0x10000000:
        perms = "DONTCARE";
        break;
    default:
        perms = "UNDEFINED";
    }

    DEBUG("op=%s %s (%x), addr0=%x, addr1=%x, size=%x, perm=%s (%x)\n",
          ops, op & CONTROL_GSP_FLAG ? "GSP" : "", op,
          addr0, addr1, size, perms, perm);
    PAUSE();

    if(addr0 & 0xFFF)
        return SVCERROR_ALIGN_ADDR;
    if(addr1 & 0xFFF)
        return SVCERROR_ALIGN_ADDR;
    if(size & 0xFFF)
        return SVCERROR_INVALID_SIZE;

    if(op == 0x10003) { // FFF680A4
        if(addr0 == 0) { // FFF680C4
            if(addr1 != 0)
                return SVCERROR_INVALID_PARAMS;
        } else if(size == 0) { // FFF680D0
            if(addr0 < 0x14000000)
                return SVCERROR_INVALID_PARAMS;
            if((addr0+size) >= 0x1C000000)
                return SVCERROR_INVALID_PARAMS;
            if(addr1 != 0)
                return SVCERROR_INVALID_PARAMS;
        } else {
            if(addr0 < 0x14000000)
                return SVCERROR_INVALID_PARAMS;
            if(addr0 >= 0x1C000000)
                return SVCERROR_INVALID_PARAMS;
            if(addr1 != 0)
                return SVCERROR_INVALID_PARAMS;
        }
    } else if(op == 1) {
        if(size == 0) { // FFF68110
            if(addr0 < 0x08000000) // FFF68130
                return SVCERROR_INVALID_PARAMS;
            if(addr0 <= 0x1C000000)
                return SVCERROR_INVALID_PARAMS;
        } else {
            if(addr0 < 0x08000000)
                return SVCERROR_INVALID_PARAMS;
            if((addr0+size) <= 0x1C000000)
                return SVCERROR_INVALID_PARAMS;
        }
    } else {
        if(size == 0) { // FFF68148
            if(addr0 < 0x08000000)
                return SVCERROR_INVALID_PARAMS;
            if(addr0 >= 0x14000000)
                return SVCERROR_INVALID_PARAMS;
        } else {
            if(addr0 < 0x08000000)
                return SVCERROR_INVALID_PARAMS;
            if((addr0+size) >= 0x14000000)
                return SVCERROR_INVALID_PARAMS;
        }

        if(op == 4 || op == 5) { // FFF680E8
            if(size == 0) {
                if(addr1 < 0x100000) // FFF681CC
                    return SVCERROR_INVALID_PARAMS;
                if(addr1 >= 0x14000000)
                    return SVCERROR_INVALID_PARAMS;
            }
            if(addr1 < 0x100000)
                return SVCERROR_INVALID_PARAMS;

            if((addr1+size) >= 0x14000000)
                return SVCERROR_INVALID_PARAMS;
        }
    }

    // ????
    switch(op & 0xff) {
    case 1:
    case 3:
    case 4:
    case 5:
    case 6:
        break;
    default:
        return SVCERROR_INVALID_OPERATION;
    }

    if(size == 0)
        return 0;

    //kprocess = *0xFFFF9004;
    //*(SP+0x10) = kprocess + 0x1c;

    // ???
    /*
    u32 flags = outaddr & 0xff;
    if(flags != 1) {
    if(perms != 0 && perms != 1 && perms != 2 && perms != 3)
        return SVCERROR_INVALID_OPERATION;
    }
    */

    /*if ((op&0xF) == 3) //COMMIT
    {
        arm11_SetR(1, addr0); // outaddr is in R1
        return mem_AddSegment(addr0, size, NULL);
    }*/

    /*if(op == 0x10003) {
        DEBUG("Mapping GSP heap..\n");
        arm11_SetR(1, 0x08000000); // outaddr is in R1
        return mem_AddSegment(0x08000000, size, NULL);
    }*/

    if ((op & 0xF) == 0x3 || (op & 0xF) == 0x0) { //COMMIT
        if ((op & 0x10000) == 0x10000) { //LINEAR
            if (size > 0x2000000) {
                //Console.WriteLine("out of linear mem");
                return 0xFFFFFFFF;
            }
        }
        if (addr0 != 0) {
            if ((op & 0x10000) == 0x10000) { //LINEAR
                addr0 = 0x08000000;
            }

            arm11_SetR(1, addr0); // outaddr is in R1
            return mem_AddSegment(addr0, size, NULL);
        } else {
            if ((op & 0x10000) == 0x10000) { //LINEAR
                addr0 = 0x14000000;
            }
            /*else
            {
                addr0 = mallocarm11(0x20000000, 0xFFFFF000, size);
            }*/
            arm11_SetR(1, addr0); // outaddr is in R1
            return mem_AddSegment(addr0, size, NULL);
        }
    }

    DEBUG("STUBBED!\n");
    PAUSE();

    /*
    // FFF6824C
    r11 = outaddr & 0xFFFFFF;
    is_ldr = GetKProcessID() == 1 ? 0xFFFFFFFF : 0;
    r2 = r2 & r11;
    if(r2 & 0xF00) {
    r2 = *(kprocess + 0xa0);
    r11 = (r11 & 0xFFFFF0FF) | (r2 & 0xF00);
    }
    if(flags == 3 && !is_ldr) {
    if(sub_FFF72828(*r10, 1, r5) == 0)
    return 0xC860180A;
    }
    s32 rc = sub_FFF741B4(*(SP+16), (returnval in r1) SP+12, r4, r6, r5, r11, r7);
    if(rc < 0) {
    //FFF682F8
    if(flags == 1)
    sub_FFF7A0E8(*r10, 1, r5);
    }
    if(flags == 3)
    sub_FFF7A0E8(*r10, 1, r5);
    */

    return -1;
}
Пример #5
0
u32 svcReplyAndReceive()
{

    s32 index = arm11_R(0);
    u32 handles = arm11_R(1);
    u32 handleCount = arm11_R(2);
    u32 replyTarget = arm11_R(3);
    DEBUG("svcReplyAndReceive %08x %08x %08x %08x\n", index, handles, handleCount, replyTarget);

#ifdef MODULE_SUPPORT
    for (u32 i = 0; i < handleCount; i++) {
        DEBUG("%08x\n", mem_Read32(handles+i*4));

        handleinfo* h = handle_Get(eventhandle);
        if (h == NULL) {
            PAUSE();
            return -1;
        }

        if (h->type == HANDLE_TYPE_SERVICE) {
            h->misc[0] |= HANDLE_SERV_STAT_WAITING;
            h->misc[1] = curprocesshandle;
            h->misc[2] = threads_GetCurrentThreadHandle();
        }
    }
#endif

    for (u32 i = 0; i < handleCount; i++) {
        DEBUG("%08x\n", mem_Read32(handles + i * 4));
    }
    /*wrapWaitSynchronizationN(0xFFFFFFFF, handles, handleCount, 0, 0xFFFFFFFF,0);



    //feed module data here
    switch (times) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
        RESP(0, 0x00160042);
        RESP(1, 0x0);
        RESP(2, 0x0);
        RESP(3, 0x12345);
        break;
    case 7:
        RESP(0, 0x00130042);
        RESP(1, 0x0);
        RESP(2, 0x0);
        RESP(3, handle_New(HANDLE_TYPE_EVENT, 0));
        break;
    default:
        RESP(0, 0x000C0000);
        break;
    }

    //feed end

    times++;*/

    arm11_SetR(1, 0);
    return 1;
}
Пример #6
0
u32 srv_SyncRequest()
{
    u32 cid = mem_Read32(arm11_ServiceBufferAddress() + 0x80);

    // Read command-id.
    switch(cid) {

    case 0x10002:
        DEBUG("srv_Initialize\n");

        // XXX: check +4, flags?
        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //no error
        PAUSE();
        return 0;

    case 0x20000:
        DEBUG("srv_GetProcSemaphore");

        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //no error
        mem_Write32(arm11_ServiceBufferAddress() + 0x88, 0); //done in sm 4.4
        mem_Write32(arm11_ServiceBufferAddress() + 0x8C, eventhandle);
        return 0;

        char names[9];
    case 0x000400C0:
        DEBUG("srv_UnRegisterService --todo--\n");

        // Read rest of command header
        mem_Read((u8*)&req, arm11_ServiceBufferAddress() + 0x84, sizeof(req));

        memcpy(names, req.name, 8);
        names[8] = '\0';

        DEBUG("name=%s, namelen=%u\n", names, req.name_len);

        return 0;

    case 0x00030100:
        DEBUG("srv_registerService\n");

        // Read rest of command header
        mem_Read((u8*)&req, arm11_ServiceBufferAddress() + 0x84, sizeof(req));

        memcpy(names, req.name, 8);
        names[8] = '\0';

        DEBUG("name=%s, namelen=%u, unk=0x%x\n", names, req.name_len,
            req.unk2);


        ownservice[ownservice_num].name = malloc(9);
        memcpy(ownservice[ownservice_num].name, req.name, 9);

        ownservice[ownservice_num].handle = handle_New(HANDLE_TYPE_SERVICE, SERVICE_DIRECT);

        handleinfo* hi = handle_Get(ownservice[ownservice_num].handle);
        if (hi == NULL) {
            ERROR("getting handle.\n");
            return 0x0;
        }
        hi->misc[0] = HANDLE_SERV_STAT_TAKEN; //init

        hi->misc_ptr[0] = malloc(0x200);

        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //no error
        mem_Write32(arm11_ServiceBufferAddress() + 0x8C, ownservice[ownservice_num].handle); //return handle
        ownservice_num++;
        return 0;

    case 0x50100:
        DEBUG("srv_GetServiceHandle\n");

        // Read rest of command header
        mem_Read((u8*)&req, arm11_ServiceBufferAddress() + 0x84, sizeof(req));

        memcpy(names, req.name, 8);
        names[8] = '\0';

        DEBUG("name=%s, namelen=%u, unk=0x%x\n", names, req.name_len,
              req.unk2);
        PAUSE();

        u32 i;

        bool overdr = false;
        for (u32 i = 0; i < overdrivnum; i++) {
            if (memcmp(req.name, *(overdrivnames + i), strnlen(*(overdrivnames + i), 8)) == 0)overdr = true;
        }
        if (!overdr) {
            for (u32 i = 0; i < ownservice_num; i++) {
                if (memcmp(req.name, ownservice[i].name, strnlen(ownservice[i].name, 8)) == 0) {

                    // Write result.
                    mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0);

                    // Write handle_out.
                    mem_Write32(arm11_ServiceBufferAddress() + 0x8C, ownservice[i].handle);

                    return 0;
                }
            }
        }
        for(i=0; i<ARRAY_SIZE(services); i++) {
            // Find service in list.
            if(memcmp(req.name, services[i].name, strnlen(services[i].name, 8)) == 0) {

                // Write result.
                mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0);

                // Write handle_out.
                mem_Write32(arm11_ServiceBufferAddress() + 0x8C, services[i].handle);

                return 0;
            }
        }

        ERROR("Unimplemented service: %s\n", req.name);
        arm11_Dump();
        exit(1);

    case 0x90040: // EnableNotificationType
        DEBUG("srv_EnableNotificationType\n");

        u32 type = mem_Read32(arm11_ServiceBufferAddress() + 0x84);
        DEBUG("STUBBED, type=%x\n", type);

        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0);
        return 0;

    case 0xa0040: // DisableNotificationType
        DEBUG("srv_DisableNotificationType\n");

        type = mem_Read32(arm11_ServiceBufferAddress() + 0x84);
        DEBUG("STUBBED, type=%x\n", type);

        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //no error
        return 0;

    case 0xB0000: // GetNotificationType
        DEBUG("srv_GetNotificationType\n");
        //mem_Dbugdump();
        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0); //worked
        mem_Write32(arm11_ServiceBufferAddress() + 0x88, 0); //type
        return 0;

    default:
        ERROR("Unimplemented command %08x in \"srv:\"\n", cid);
        arm11_Dump();
        mem_Write32(arm11_ServiceBufferAddress() + 0x84, 0xFFFFFFFF); //worked
        return 0;
        //exit(1);
    }

    return 0;
}
Пример #7
0
u32 svcWaitSynchronizationN() //todo timeout
{
    u32 *handelist;
    u32 nanoseconds1 = arm11_R(0);
    u32 handles = arm11_R(1);
    u32 handlecount = arm11_R(2);
    u32 waitAll = arm11_R(3);
    u32 nanoseconds2 = arm11_R(4);
    bool allunlockde = true;
    for (u32 i = 0; i < handlecount; i++)
    {
        u32 curhandel = mem_Read32(handles + i * 4);
        handleinfo* hi = handle_Get(curhandel);

        if (hi == NULL) {
            ERROR("handle %08x not found.\n", curhandel);
            PAUSE();
#ifdef exitonerror
            exit(1);
#else
            return 0;
#endif
        }

        if (hi->type >= NUM_HANDLE_TYPES) {
            // This should never happen.
            ERROR("handle %08x has non-defined type.\n", curhandel);
            PAUSE();
            exit(1);
        }

        u32 temp;
        bool locked = false;
        // Lookup actual callback in table.
        if (handle_types[hi->type].fnWaitSynchronization != NULL)
        {
            temp = handle_types[hi->type].fnWaitSynchronization(hi, &locked);
            if (!locked && waitAll == 0)
            {
                arm11_SetR(1,i);
                return 0;
            }
            else
            {
                allunlockde = false;
            }
        }
        else
        {
            ERROR("svcCloseHandle undefined for handle-type \"%s\".\n",
                handle_types[hi->type].name);
            PAUSE();
            return 0;
        }
    }
    if (waitAll && allunlockde)return 0;
    handelist = malloc(handlecount*4);
    mem_Read((u8*)handelist, handles, handlecount * 4);
    lockcpu(handelist, waitAll, handlecount);
    return 0;
}
Пример #8
0
Файл: srv.c Проект: 20150/3dmoo
u32 svcReplyAndReceive()
{

    s32 index = arm11_R(0);
    u32 handles = arm11_R(1);
    u32 handleCount = arm11_R(2);
    u32 replyTarget = arm11_R(3);
    DEBUG("svcReplyAndReceive %08x %08x %08x %08x\n", index, handles, handleCount, replyTarget);

    if (replyTarget) //respond
    {
        IPC_debugprint(arm11_ServiceBufferAddress() + 0x80);
        handleinfo* h2 = handle_Get(replyTarget);
        if (h2 == NULL) {
            ERROR("handle not there");
        }
        eventhandle = h2->misc[0];
        h2 = handle_Get(eventhandle);
        if (h2 == NULL) {
            ERROR("handle not there");
        }
        if (h2->misc[0] & HANDLE_SERV_STAT_SYNCING) {
            mem_Read(h2->misc_ptr[0], arm11_ServiceBufferAddress() + 0x80, 0x80); //todo 
            h2->misc[0] |= HANDLE_SERV_STAT_ACKING;
        }
    }

    for (u32 i = 0; i < handleCount; i++) {
        DEBUG("%08x\n", mem_Read32(handles + i * 4));
    }
    /*wrapWaitSynchronizationN(0xFFFFFFFF, handles, handleCount, 0, 0xFFFFFFFF,0);



    //feed module data here
    switch (times) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
        RESP(0, 0x00160042);
        RESP(1, 0x0);
        RESP(2, 0x0);
        RESP(3, 0x12345);
        break;
    case 7:
        RESP(0, 0x00130042);
        RESP(1, 0x0);
        RESP(2, 0x0);
        RESP(3, handle_New(HANDLE_TYPE_EVENT, 0));
        break;
    default:
        RESP(0, 0x000C0000);
        break;
    }*/

    //RESP(0, 0x00010800);

    //feed end

    times++;

    arm11_SetR(1, 0);

    return 0;
}