Пример #1
0
void MemCard2::write(u32 p_socket, u32 p_name_va, u32 p_buf_va, u32 p_ofs, u32 p_size) {
  u32* buf = (u32*)VA2PA(p_buf_va + p_ofs);
  s8*  name = (s8*)VA2PA(p_name_va);
  u32  port = socket_[p_socket]->port;
  u32  slot = socket_[p_socket]->slot;
  assert(port < 2);
  assert(slot == 0);

  s8 path[1024];
  if (strchr(name, '/')) {
    // フルパスと見なす
    sprintf(path, "%s/memcard%d/%s",
      g_base_dir, slot + 1, name);
  } else {
    sprintf(path, "%s/memcard%d/%s/%s",
      g_base_dir, slot + 1, relative_dir_, name);
  }
  FILE* fp = fopen(path, "wb");
  if (fp) {
    size_t actual_size = fwrite(buf, 1, p_size, fp);
    fclose(fp);
    g_cpu->m_v0.d[0] = actual_size;
  } else {
    g_cpu->m_v0.d[0] = -1;
  }
  DBGOUT_CPU("%s succeeded! socket=%d buf=0x%08x, size=%d\n",
    __FUNCTION__, p_socket, p_buf_va, p_size);
}
Пример #2
0
void MemCard2::callMemCard2Rpc(u32 p_client_data_ptr, u32 p_fno,
                               u32 p_send_buf_ptr, u32 p_send_buf_size,
                               u32 p_recv_buf_ptr, u32 p_recv_buf_size) {
  u32* clidata = (u32*)VA2PA(p_client_data_ptr);
  u32* sendbuf = (u32*)VA2PA(p_send_buf_ptr);
  s32* recvbuf = (s32*)VA2PA(p_recv_buf_ptr);

  switch (p_fno) {
    case 0x80001301: { // dbc create socket
      Mc2SocketParam* param  = (Mc2SocketParam*)sendbuf;
      Mc2SocketInfo* mc2sock = new Mc2SocketInfo;
      mc2sock->port = param->port - 2;
      mc2sock->slot = param->slot;
      socket_.push_back(mc2sock);
      g_cpu->m_v0.d[0] = socket_.size();
      DBGOUT_CPU("Dbc create succeeded! sockno=%d option=%08x "
        "port=%d slot=%d name=%s\n", g_cpu->m_v0.d[0],
        param->option, param->port & 1, param->slot, param->name);
    } break;
    case 0x80001363: { // dbc init
      relative_dir_[0] = '\0';
      clearSocket();
      recvbuf[0] = 0x00000320;
      DBGOUT_CPU("Dbc init succeeded!\n");
    } break;
    case 0x8000131c: { // dbc send
      DBGOUT_CPU("Dbc send not supported!\n");
    } break;
    default:           // invalid
      DBGOUT_CPU("SifCallRpc Dbc(MemCd2) Invalid FunctionID!!\n");
      break;
  }
}
Пример #3
0
void LineEditDialog::handleInitDialogMsg(HWND p_dlg) {
  s8 str[1024];

  ModuleInfo* info = g_dbg->code_window()->GetCurModule();
  if (info == NULL) return;

  RECT rect;
  GetWindowRect(p_dlg, &rect);
  SetWindowPos(p_dlg, NULL, rect.left, rect.top - (rect.bottom - rect.top + 20), 0, 0, SWP_NOSIZE | SWP_NOZORDER);

  u32 va = info->addr() + g_dbg->code_window()->select() * 4;
  u32 opcode = *((u32*)VA2PA(va));

  sprintf(str, "%08x", opcode);
  SetDlgItemText(p_dlg, IDC_OPCODE, str);
  g_dbg->setFontToFixed(GetDlgItem(p_dlg, IDC_OPCODE));

  disasm_plain(va, opcode, str);
  SetDlgItemText(p_dlg, IDC_ASM, str);
  g_dbg->setFontToFixed(GetDlgItem(p_dlg, IDC_ASM));

  Comment* comment = g_dbg->find_comment(va);
  SetDlgItemText(p_dlg, IDC_COMMENT, comment ? comment->text() : "");

  Label* label = g_dbg->find_codelabel(va);
  SetDlgItemText(p_dlg, IDC_LABEL, label ? label->text() : "");

  SetFocus(GetDlgItem(p_dlg, IDC_LABEL));
}
Пример #4
0
void MemCard2::getinfo(u32 p_socket, u32 p_buf_va) {
  u32* buf  = (u32*)VA2PA(p_buf_va);
  u32  port = socket_[p_socket]->port;
  u32  slot = socket_[p_socket]->slot;
  assert(port < 2);
  assert(slot == 0);

  // メモリーカードが刺さっていない状況は用意しない
  // デバッグ等でどうしても必要な場合は以下のフラグをfalseにすること
  bool exist     = true;
  int  formatted = false;

  // memcard1ディレクトリが存在する場合、フォーマット済みとみなす
  s8 mcd_path[1024];
  sprintf(mcd_path, "%s/memcard%d", g_base_dir, port + 1);
  if (PathIsDirectory(mcd_path)) {
    formatted = true;
  }
  s32 result;
  u32 type;
  u32 free_size;
  if (exist && formatted) {
    // フォーマット済み
    result = 0x81019003;
    type = 2;
    free_size = getDiskFree();
  } else if (exist && formatted == false) {
    // 未フォーマット
    result = 0x8101002f;
    type = 2;
    free_size = 0;
  } else {
    // 未接続
    result = 0x81010013;
    type = 0;
    free_size = 0;
  }

  buf[0] = type;
  buf[2] = free_size;
  buf[1] = formatted;

  // 前回と同じなら result = 0 とする
  // これはMcSyncにて取得される
  if (get_info_last_state_[port].type   == type &&
      get_info_last_state_[port].free   == free_size &&
      get_info_last_state_[port].format == formatted) {
    result = 0;
  } else {
    // 現在の状態を保存する
    get_info_last_state_[port].type   = type;
    get_info_last_state_[port].free   = free_size;
    get_info_last_state_[port].format = formatted;
  }

  g_cpu->m_v0.d[0] = result;
  DBGOUT_CPU("%s succeeded! port=%d slot=%d mcd_path=%s result=%d\n",
    __FUNCTION__, port, slot, mcd_path, result);
}
Пример #5
0
void MemCard2::chdir(u32 p_socket, u32 p_name_va, u32 p_pwd_va) {
  s8*    name = (s8*)VA2PA(p_name_va);
  u32    port = socket_[p_socket]->port;
  u32    slot = socket_[p_socket]->slot;
  assert(port < 2);
  assert(slot == 0);

  if (p_pwd_va) {
    s8* pwd = (s8*)VA2PA(p_pwd_va);
    strcpy(pwd, relative_dir_);
  }

  strcpy(relative_dir_, name);

  g_cpu->m_v0.d[0] = 0x00000000;
  DBGOUT_CPU("%s succeeded! port=%d slot=%d path=%s\n",
    __FUNCTION__, port, slot, name);
}
Пример #6
0
static int CommonAES128(AES_ParamStruct *AESPara)
{
    DRVAESDMA_RESULT result = DRVAESDMA_OK;
    MS_U32 u32AESInBuf, u32AESOutBuf;
    UBOOT_TRACE("IN\n");
    if((AESPara->pChiperBuf == 0)||(AESPara->pPlainBuf == 0)||(AESPara->pKey == 0))
    {
        UBOOT_ERROR("The input parameters are not correct\n");    
        return DRVAESDMA_INVALID_PARAM;
    }

    flush_cache(AESPara->pChiperBuf, AESPara->u32Len);

    u32AESInBuf=VA2PA(AESPara->pChiperBuf);
    u32AESOutBuf=VA2PA(AESPara->pPlainBuf);
    MDrv_AESDMA_Init(0x00, 0x20000000, 2); // wait the AESDMA.a
    MDrv_AESDMA_Reset();
    MDrv_AESDMA_SelEng(AESPara->eMode, AESPara->bIsDecrypt);
    result=MDrv_AESDMA_SetFileInOut(u32AESInBuf, AESPara->u32Len, u32AESOutBuf, u32AESOutBuf+AESPara->u32Len-1);
    if (result == DRVAESDMA_MIU_ADDR_ERROR)
    {
        UBOOT_ERROR("CommonAES128 execte MDrv_AESDMA_SetFileInOut fail\n");
        return -1;
    }

    if(AESPara->eMode == E_DRVAESDMA_CIPHER_CBC)
    {
        MDrv_AESDMA_SetIV(AESPara->pIV);
    }
    if(AESPara->pKey!=NULL)
        MDrv_AESDMA_SetKey(AESPara->pKey);

    UBOOT_DEBUG("AESDMA Start\n");
    MDrv_AESDMA_Start(TRUE);
    UBOOT_DEBUG("AESDMA polling finish bits\n");    
    
    while ((MDrv_AESDMA_GetStatus() & BIT(16)) == 0);

    flush_cache(AESPara->pPlainBuf, AESPara->u32Len);
    UBOOT_TRACE("OK\n");
    return 0;
}
Пример #7
0
void MemCard2::mkdir(u32 p_socket, u32 p_name_va) {
  s8*    name = (s8*)VA2PA(p_name_va);
  u32    port = socket_[p_socket]->port;
  u32    slot = socket_[p_socket]->slot;
  assert(port < 2);
  assert(slot == 0);

  s8 path[1024];
  if (strchr(name, '/')) {
    // フルパスと見なす
    sprintf(path, "%s/memcard%d/%s",
      g_base_dir, slot + 1, name);
  } else {
    sprintf(path, "%s/memcard%d/%s/%s",
      g_base_dir, slot + 1, relative_dir_, name);
  }
  u32 result = 0x00000000;
  if (!CreateDirectory((LPCSTR)path, NULL)) {
    result = 0x81010000;
  }
  
  g_cpu->m_v0.d[0] = result;
  DBGOUT_CPU("%s succeeded! port=%d, name=%s\n", __FUNCTION__, port, name);
}
Пример #8
0
void MemCard2::getdir(u32 p_socket, u32 p_name_va, u32 p_ofs,
                      u32 p_maxent, u32 p_buf_va, u32 p_cnt_va) {
  s8*  name  = (s8*)VA2PA(p_name_va);
  u32* buf   = (u32*)VA2PA(p_buf_va);
  u32* count = (u32*)VA2PA(p_cnt_va);
  u32  port  = socket_[p_socket]->port;
  u32  slot  = socket_[p_socket]->slot;
  assert(port < 2);
  assert(slot == 0);

  s8 file_path[1024];
  sprintf(file_path, "%s/memcard%d/%s", g_base_dir, port + 1, name);

  s32 result = 0x00000000;
  Mc2GetDirEntry* ent_table = (Mc2GetDirEntry*)buf;
  WIN32_FIND_DATA  find_data;
  HANDLE hdl = FindFirstFile(file_path, &find_data);
  if (hdl == INVALID_HANDLE_VALUE) {
    result = 0x81010002;
  } else {
    BOOL succeeded;
    u32 file_cnt = 0;
    u32 ent_cnt = 0;
    do {
      if (file_cnt >= p_ofs) {
        strncpy(ent_table[ent_cnt].name, find_data.cFileName, 31);
        ent_table[ent_cnt].name[31] = '\0';

        ent_table[ent_cnt].size = find_data.nFileSizeLow;
        ent_table[ent_cnt].attr = 0x0087 |
          ((find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
             0x0020 : 0x0000);

        SYSTEMTIME systime;
        FileTimeToSystemTime(&find_data.ftCreationTime, &systime);
        ent_table[ent_cnt].create.year  = (u16)systime.wYear;
        ent_table[ent_cnt].create.month = (u8)systime.wMonth;
        ent_table[ent_cnt].create.day   = (u8)systime.wDay;
        ent_table[ent_cnt].create.hour  = (u8)systime.wHour;
        ent_table[ent_cnt].create.min   = (u8)systime.wMinute;
        ent_table[ent_cnt].create.sec   = (u8)systime.wSecond;

        FileTimeToSystemTime(&find_data.ftLastWriteTime, &systime);
        ent_table[ent_cnt].modify.year  = (u16)systime.wYear;
        ent_table[ent_cnt].modify.month = (u8)systime.wMonth;
        ent_table[ent_cnt].modify.day   = (u8)systime.wDay;
        ent_table[ent_cnt].modify.hour  = (u8)systime.wHour;
        ent_table[ent_cnt].modify.min   = (u8)systime.wMinute;
        ent_table[ent_cnt].modify.sec   = (u8)systime.wSecond;
        ent_cnt++;
      }
      file_cnt++;
      succeeded = FindNextFile(hdl, &find_data);
    } while (succeeded && ent_cnt < p_maxent);
    FindClose(hdl);
    *count = ent_cnt;
  }
  g_cpu->m_v0.d[0] = result;
  DBGOUT_CPU("%s succeeded! port=%d slot=%d ofs=%d maxent=%d "
    "name=%s result=%d\n", __FUNCTION__, port, slot,
    p_ofs, p_maxent, name, result);
}
Пример #9
0
int _CommonSHA(MS_U32 u32InBuf, MS_U32 u32OutBuf, MS_U32 u32Len)
{
    int ret = 0;
    unsigned int *pTempInBuf=NULL;
    unsigned int *pInBuf=NULL;
    unsigned int *pTempOutBuf=NULL;
    unsigned int *pOutBuf=NULL;
    DRVAESDMA_RESULT result = 0;
    UBOOT_TRACE("IN\n");
    UBOOT_DEBUG("u32InBuf=0x%x,u32OutBuf=0x%x,u32Len=0x%x\n",(unsigned int)u32InBuf,(unsigned int)u32OutBuf,(unsigned int)u32Len);

    //The input buffer of AESDMA must alignment 16 bytes. So we check the input buffer address first.
    //If the input buffer address doesn't alignment to 16 bytes. We allocate a local memory automatically.
    if((u32InBuf%AES_BUF_ALIGNMENT_SIZE)!=0)
    {
       UBOOT_DEBUG("input buffer doesn't alignment 16bytes\n");
       //The size of input buffer should include the size of scattergather table. This table is used for driver.
       // Now, driver creates a scattergather table after input buffer.
       // So, the input buffer should include the sacattergather table.
       #define INPUT_BUF_LENGTH (u32Len+AES_BUF_ALIGNMENT_SIZE+SACTTERGATHER_TABLE_SIZE)
       pTempInBuf=malloc(INPUT_BUF_LENGTH);
       if(pTempInBuf==NULL)
       {
            UBOOT_ERROR("malloc for tbuf fail\n");
            return -1;
       }
       memset(pTempInBuf,0,INPUT_BUF_LENGTH);
       pInBuf=(unsigned int *)((unsigned int)pTempInBuf+(AES_BUF_ALIGNMENT_SIZE-((unsigned int)pTempInBuf%AES_BUF_ALIGNMENT_SIZE)));
       memcpy((void *)pInBuf,(void *)u32InBuf,u32Len);
       #undef INPUT_BUF_LENGTH
    }
    else
    {
        pInBuf=(unsigned int *)u32InBuf;
    }

    //The output buffer of AESDMA must alignment 16 bytes. So we check the output buffer address first.
    //If the output buffer address doesn't alignment to 16 bytes. We allocate a local memory automatically.
    if((u32OutBuf%AES_BUF_ALIGNMENT_SIZE)!=0)
    {
       UBOOT_DEBUG("output buffer doesn't alignment 16bytes\n");
       #define OUTPUT_BUF_LENGTH (SHA256_DIGEST_SIZE+AES_BUF_ALIGNMENT_SIZE)
       pTempOutBuf=malloc(OUTPUT_BUF_LENGTH);
       if(pTempOutBuf==NULL)
       {
            if(pTempInBuf!=NULL)
            {
                free(pTempInBuf);
            }
            UBOOT_ERROR("malloc for tbuf fail\n");
            return -1;
       }
       memset(pTempOutBuf,0,OUTPUT_BUF_LENGTH);
       pOutBuf=(unsigned int *)((unsigned int)pTempOutBuf+(AES_BUF_ALIGNMENT_SIZE-((unsigned int)pTempOutBuf%AES_BUF_ALIGNMENT_SIZE)));
       #undef OUTPUT_BUF_LENGTH
    }
    else
    {
        pOutBuf=(unsigned int *)u32OutBuf;
    }

    flush_cache((MS_U32)pInBuf, u32Len);
    flush_cache((MS_U32)pOutBuf, SHA256_DIGEST_SIZE);
    Chip_Flush_Memory();
    ret = MDrv_AESDMA_Init(0x00, 0x20000000, 2); // wait the AESDMA.a
    if(DRVAESDMA_OK != ret)
    {
       UBOOT_ERROR("AESDAM Init ERROR:%d\n",ret);
       return -1;
    }
    result = MDrv_SHA_Calculate(E_DRVAESDMA_SHA256, (MS_U32)(VA2PA((MS_U32)pInBuf)), u32Len, (MS_U32)(VA2PA((MS_U32)pOutBuf)));// wait the AESDMA.a
    flush_cache((MS_U32)pOutBuf,SHA256_DIGEST_SIZE);
    if(result!=DRVAESDMA_OK)
    {
        if(pTempInBuf!=NULL)
        {
            free(pTempInBuf);
        }
        if(pTempOutBuf!=NULL)
        {

            free(pTempOutBuf);
        }
        UBOOT_TRACE("[FAIL]CommonSHA fail result=%d\n",(unsigned int)result);
        ret = -1;
    }
    else
    {
        if(pTempInBuf!=NULL)
        {
            free(pTempInBuf);
        }
        if(pTempOutBuf!=NULL)
        {
            UBOOT_DEBUG("copy data from pOutBuf to u32OutBuf\n");
            memcpy((void *)u32OutBuf,(void *)pOutBuf,SHA256_DIGEST_SIZE);
            free(pTempOutBuf);
        }
        ret=0;
        UBOOT_TRACE("OK\n");
    }

    return ret;
}
Пример #10
0
void LineEditDialog::handleOK(HWND p_dlg) {
  s8 str[1024];

  ModuleInfo* info = g_dbg->code_window()->GetCurModule();
  if (info == NULL) return;

  u32 va = info->addr() + g_dbg->code_window()->select() * 4;

  // オペコードを反映
  GetDlgItemText(p_dlg, IDC_OPCODE, str, 255);
  u32 opcode = strtoul(str, NULL, 16);
  if (*((u32*)VA2PA(va)) != opcode) {
    int cmd_id = g_dbg->command_id();
    // リコンパイルコードが破棄されるので一旦止める
    if (cmd_id != -1) {
      SendMessage(g_dbg->code_window()->dlg()->getHwnd(), WM_COMMAND, ID_DEBUG_PAUSE, 0);
    }

    PatchEntry* patch = g_dbg->findPatch(va, 4, false);

    if (patch) {
      patch->SetDisable();

      // パッチを更新
      patch->update(va - patch->va(), 4, reinterpret_cast<const s8*>(&opcode));

      patch->SetEnable();
    } else {
      // パッチを作成
      g_dbg->addPatch(new PatchEntry(va, 4, true, reinterpret_cast<const s8*>(&opcode)));
    }
    g_dbg->doStaticCodeAnalyze();

    // 再開
    if (cmd_id != -1) {
      SendMessage(g_dbg->code_window()->dlg()->getHwnd(), WM_COMMAND, cmd_id, 0);
    }
  }

  // コメントを反映
  GetDlgItemText(p_dlg, IDC_COMMENT, str, 255);
  str[255] = '\0';
  ds_util::strtrim(str);

  Comment* comment = g_dbg->find_comment(va);
  if (comment == NULL && str[0] != '\0') {
    // 新規追加
    g_dbg->add_comment(new Comment(g_dbg->get_current_ddb(), va, str));
  } else if (comment && str[0] != '\0') {
    // 更新
    comment->set_text(str);
  } else if (comment && str[0] == '\0') {
    // 削除
    int idx = g_dbg->get_comment_idx(comment->va());
    g_dbg->delete_comment(idx);
  }

  // ラベルを反映
  GetDlgItemText(p_dlg, IDC_LABEL, str, 255);
  str[255] = '\0';
  ds_util::strtrim(str);

  Label* label = g_dbg->find_codelabel(va);
  if (label == NULL && str[0] != '\0') {
    // 新規追加
    g_dbg->add_codelabel(new Label(g_dbg->get_current_ddb(), va, str));
  } else if (label && str[0] != '\0') {
    // 更新
    label->set_text(str);
  } else if (label && str[0] == '\0') {
    // 削除
    int idx = g_dbg->get_codelabel_idx(label->va());
    g_dbg->delete_codelabel(idx);
  }
  EndDialog(p_dlg, IDOK);
}