Newer
Older
AMI-Aptio-BIOS-Reversed / 117828F1-DA7D-4BC1-8B58-9A954FED5121 / GpioLib.c
@Ajax Dong Ajax Dong 2 days ago 14 KB Init
#include "117828F1-DA7D-4BC1-8B58-9A954FED5121.h"

// GpioLib.c - Extracted from 117828F1-DA7D-4BC1-8B58-9A954FED5121.c
// Functions: 5

// Function: RstGpioRead @ 0x7190 (0x11c bytes)
// Index: 188/906

__int16 __fastcall RstGpioRead(unsigned __int8 n12)
{
  if ( n12 <= 0xCu ) /*0x7198*/
  {
    if ( n12 == 12 ) /*0x719e*/
      return 53; /*0x722e*/
    if ( n12 > 6u ) /*0x71a7*/
    {
      switch ( n12 ) /*0x71f7*/
      {
        case 7u: /*0x71f7*/
          return 48; /*0x7228*/
        case 8u: /*0x71f7*/
          return 49; /*0x7222*/
        case 9u: /*0x71f7*/
          return 50; /*0x721c*/
        case 0xAu: /*0x71f7*/
          return 51; /*0x7216*/
        case 0xBu: /*0x71f7*/
          return 52; /*0x7210*/
      }
    }
    else
    {
      switch ( n12 ) /*0x71a9*/
      {
        case 6u: /*0x71a9*/
          return 47; /*0x71f3*/
        case 0u: /*0x71a9*/
          return 41; /*0x71ed*/
        case 1u: /*0x71a9*/
          return 42; /*0x71e7*/
        case 2u: /*0x71a9*/
          return 43; /*0x71e1*/
        case 3u: /*0x71a9*/
          return 44; /*0x71db*/
        case 4u: /*0x71a9*/
          return 45; /*0x71d5*/
        case 5u: /*0x71a9*/
          return 46; /*0x71cf*/
      }
    }
    return 0; /*0x71c6*/
  }
  if ( n12 <= 0x12u ) /*0x7232*/
  {
    switch ( n12 ) /*0x7234*/
    {
      case 0x12u: /*0x7234*/
        return 59; /*0x7270*/
      case 0xDu: /*0x7234*/
        return 54; /*0x726a*/
      case 0xEu: /*0x7234*/
        return 55; /*0x7264*/
      case 0xFu: /*0x7234*/
        return 56; /*0x725e*/
      case 0x10u: /*0x7234*/
        return 57; /*0x7258*/
      case 0x11u: /*0x7234*/
        return 58; /*0x7252*/
    }
    return 0; /*0x724d*/
  }
  switch ( n12 ) /*0x7274*/
  {
    case 0x13u: /*0x7274*/
      return 60; /*0x72a6*/
    case 0x14u: /*0x7274*/
      return 61; /*0x72a0*/
    case 0x15u: /*0x7274*/
      return 62; /*0x729a*/
    case 0x16u: /*0x7274*/
      return 63; /*0x7294*/
  }
  if ( n12 != 23 ) /*0x7288*/
    return 0; /*0x728d*/
  return 64; /*0x71cf*/
}


// Function: RstGpioWrite @ 0x72ac (0x240 bytes)
// Index: 189/906

__int16 __fastcall RstGpioWrite(unsigned __int8 n24)
{
  if ( n24 <= 0x18u ) /*0x72b4*/
  {
    if ( n24 == 24 ) /*0x72ba*/
      return 89; /*0x73e2*/
    if ( n24 > 0xCu ) /*0x72c3*/
    {
      if ( n24 > 0x12u ) /*0x7361*/
      {
        switch ( n24 ) /*0x73a7*/
        {
          case 0x13u: /*0x73a7*/
            return 84; /*0x73dc*/
          case 0x14u: /*0x73a7*/
            return 85; /*0x73d6*/
          case 0x15u: /*0x73a7*/
            return 86; /*0x73d0*/
          case 0x16u: /*0x73a7*/
            return 87; /*0x73ca*/
          case 0x17u: /*0x73a7*/
            return 88; /*0x73c4*/
        }
      }
      else
      {
        switch ( n24 ) /*0x7363*/
        {
          case 0x12u: /*0x7363*/
            return 83; /*0x73a3*/
          case 0xDu: /*0x7363*/
            return 78; /*0x739d*/
          case 0xEu: /*0x7363*/
            return 79; /*0x7397*/
          case 0xFu: /*0x7363*/
            return 80; /*0x7391*/
          case 0x10u: /*0x7363*/
            return 81; /*0x738b*/
          case 0x11u: /*0x7363*/
            return 82; /*0x7385*/
        }
      }
    }
    else
    {
      if ( n24 == 12 ) /*0x72c9*/
        return 77; /*0x735d*/
      if ( n24 > 6u ) /*0x72d2*/
      {
        switch ( n24 ) /*0x7322*/
        {
          case 7u: /*0x7322*/
            return 72; /*0x7357*/
          case 8u: /*0x7322*/
            return 73; /*0x7351*/
          case 9u: /*0x7322*/
            return 74; /*0x734b*/
          case 0xAu: /*0x7322*/
            return 75; /*0x7345*/
          case 0xBu: /*0x7322*/
            return 76; /*0x733f*/
        }
      }
      else
      {
        switch ( n24 ) /*0x72d4*/
        {
          case 6u: /*0x72d4*/
            return 71; /*0x731e*/
          case 0u: /*0x72d4*/
            return 65; /*0x7318*/
          case 1u: /*0x72d4*/
            return 66; /*0x7312*/
          case 2u: /*0x72d4*/
            return 67; /*0x730c*/
          case 3u: /*0x72d4*/
            return 68; /*0x7306*/
          case 4u: /*0x72d4*/
            return 69; /*0x7300*/
          case 5u: /*0x72d4*/
            return 70; /*0x72fa*/
        }
      }
    }
    return 0; /*0x72f1*/
  }
  if ( n24 <= 0x24u ) /*0x73e6*/
  {
    if ( n24 == 36 ) /*0x73ec*/
      return 101; /*0x746e*/
    if ( n24 > 0x1Eu ) /*0x73f1*/
    {
      switch ( n24 ) /*0x7437*/
      {
        case 0x1Fu: /*0x7437*/
          return 96; /*0x7468*/
        case 0x20u: /*0x7437*/
          return 97; /*0x7462*/
        case 0x21u: /*0x7437*/
          return 98; /*0x745c*/
        case 0x22u: /*0x7437*/
          return 99; /*0x7456*/
        case 0x23u: /*0x7437*/
          return 100; /*0x7450*/
      }
    }
    else
    {
      switch ( n24 ) /*0x73f3*/
      {
        case 0x1Eu: /*0x73f3*/
          return 95; /*0x7433*/
        case 0x19u: /*0x73f3*/
          return 90; /*0x742d*/
        case 0x1Au: /*0x73f3*/
          return 91; /*0x7427*/
        case 0x1Bu: /*0x73f3*/
          return 92; /*0x7421*/
        case 0x1Cu: /*0x73f3*/
          return 93; /*0x741b*/
        case 0x1Du: /*0x73f3*/
          return 94; /*0x7415*/
      }
    }
    return 0; /*0x740c*/
  }
  if ( n24 <= 0x2Au ) /*0x7472*/
  {
    switch ( n24 ) /*0x7474*/
    {
      case '*': /*0x7474*/
        return 107; /*0x74b0*/
      case '%': /*0x7474*/
        return 102; /*0x74aa*/
      case '&': /*0x7474*/
        return 103; /*0x74a4*/
      case '\'': /*0x7474*/
        return 104; /*0x749e*/
      case '(': /*0x7474*/
        return 105; /*0x7498*/
      case ')': /*0x7474*/
        return 106; /*0x7492*/
    }
    return 0; /*0x748d*/
  }
  switch ( n24 ) /*0x74b4*/
  {
    case '+': /*0x74b4*/
      return 108; /*0x74e6*/
    case ',': /*0x74b4*/
      return 109; /*0x74e0*/
    case '-': /*0x74b4*/
      return 110; /*0x74da*/
    case '.': /*0x74b4*/
      return 111; /*0x74d4*/
  }
  if ( n24 != 47 ) /*0x74c8*/
    return 0; /*0x74cd*/
  return 112; /*0x72fa*/
}


// Function: RstGpioConfigure @ 0x74ec (0x1b2 bytes)
// Index: 190/906

__int16 __fastcall RstGpioConfigure(int n19)
{
  __int16 n9; // dx
  int v2; // ecx
  int v3; // ecx
  int v4; // ecx
  int v5; // ecx
  int v6; // ecx
  int v7; // ecx
  int v8; // ecx
  int v10; // ecx
  int v11; // ecx
  int v12; // ecx
  int v13; // ecx
  int v14; // ecx
  int v15; // ecx
  int v16; // ecx
  int v17; // ecx
  int v18; // ecx
  int v19; // ecx
  int v20; // ecx
  int v21; // ecx
  int v22; // ecx
  int v23; // ecx
  int v24; // ecx
  int v25; // ecx
  int v26; // ecx
  int v27; // ecx
  int v28; // ecx
  int v29; // ecx
  int v30; // ecx
  int v31; // ecx
  int v32; // ecx

  if ( n19 <= 19 ) /*0x74f5*/
  {
    if ( n19 == 19 ) /*0x74fb*/
      return 21; /*0x75d6*/
    n9 = 9; /*0x7501*/
    if ( n19 > 9 ) /*0x7507*/
    {
      v10 = n19 - 10; /*0x756e*/
      if ( !v10 ) /*0x7571*/
        return 12; /*0x75d0*/
      v11 = v10 - 1; /*0x7578*/
      if ( !v11 ) /*0x757a*/
        return 13; /*0x75ca*/
      v12 = v11 - 1; /*0x757c*/
      if ( !v12 ) /*0x757e*/
        return 14; /*0x75c4*/
      v13 = v12 - 1; /*0x7580*/
      if ( !v13 ) /*0x7582*/
        return 15; /*0x75be*/
      v14 = v13 - 1; /*0x7584*/
      if ( !v14 ) /*0x7586*/
        return 16; /*0x75b8*/
      v15 = v14 - 1; /*0x7588*/
      if ( !v15 ) /*0x758a*/
        return 17; /*0x75b2*/
      v16 = v15 - 1; /*0x758c*/
      if ( !v16 ) /*0x758e*/
        return 18; /*0x75ac*/
      v17 = v16 - 1; /*0x7590*/
      if ( !v17 ) /*0x7592*/
        return 19; /*0x75a6*/
      if ( v17 == 1 ) /*0x7596*/
        return 20; /*0x75a1*/
      return 40; /*0x7596*/
    }
    if ( n19 == 9 ) /*0x7509*/
      return 11; /*0x756d*/
    if ( !n19 ) /*0x750d*/
      return 2; /*0x7567*/
    v2 = n19 - 1; /*0x7512*/
    if ( !v2 ) /*0x7514*/
      return 3; /*0x7561*/
    v3 = v2 - 1; /*0x7516*/
    if ( !v3 ) /*0x7518*/
      return 4; /*0x755b*/
    v4 = v3 - 1; /*0x751a*/
    if ( !v4 ) /*0x751c*/
      return 5; /*0x7555*/
    v5 = v4 - 1; /*0x751e*/
    if ( !v5 ) /*0x7520*/
      return 6; /*0x754f*/
    v6 = v5 - 1; /*0x7522*/
    if ( !v6 ) /*0x7524*/
      return 7; /*0x7549*/
    v7 = v6 - 1; /*0x7526*/
    if ( !v7 ) /*0x7528*/
      return 8; /*0x7543*/
    v8 = v7 - 1; /*0x752a*/
    if ( v8 ) /*0x752c*/
    {
      if ( v8 == 1 ) /*0x7530*/
        return 10; /*0x7539*/
      return 40; /*0x7530*/
    }
    return n9; /*0x753d*/
  }
  n9 = 29; /*0x75d7*/
  if ( n19 <= 29 ) /*0x75de*/
  {
    if ( n19 == 29 ) /*0x75e0*/
      return 31; /*0x7641*/
    v18 = n19 - 20; /*0x75e2*/
    if ( !v18 ) /*0x75e5*/
      return 22; /*0x763b*/
    v19 = v18 - 1; /*0x75ea*/
    if ( !v19 ) /*0x75ec*/
      return 23; /*0x7635*/
    v20 = v19 - 1; /*0x75ee*/
    if ( !v20 ) /*0x75f0*/
      return 24; /*0x762f*/
    v21 = v20 - 1; /*0x75f2*/
    if ( !v21 ) /*0x75f4*/
      return 25; /*0x7629*/
    v22 = v21 - 1; /*0x75f6*/
    if ( !v22 ) /*0x75f8*/
      return 26; /*0x7623*/
    v23 = v22 - 1; /*0x75fa*/
    if ( !v23 ) /*0x75fc*/
      return 27; /*0x761d*/
    v24 = v23 - 1; /*0x75fe*/
    if ( !v24 ) /*0x7600*/
      return 28; /*0x7617*/
    v25 = v24 - 1; /*0x7602*/
    if ( v25 ) /*0x7604*/
    {
      if ( v25 == 1 ) /*0x760c*/
        return 30; /*0x7611*/
      return 40; /*0x760c*/
    }
    return n9; /*0x7604*/
  }
  v26 = n19 - 30; /*0x7642*/
  if ( !v26 ) /*0x7645*/
    return 32; /*0x7698*/
  v27 = v26 - 1; /*0x764c*/
  if ( !v27 ) /*0x764e*/
    return 33; /*0x7692*/
  v28 = v27 - 1; /*0x7650*/
  if ( !v28 ) /*0x7652*/
    return 34; /*0x768c*/
  v29 = v28 - 1; /*0x7654*/
  if ( !v29 ) /*0x7656*/
    return 35; /*0x7686*/
  v30 = v29 - 1; /*0x7658*/
  if ( !v30 ) /*0x765a*/
    return 36; /*0x7680*/
  v31 = v30 - 1; /*0x765c*/
  if ( !v31 ) /*0x765e*/
    return 37; /*0x767a*/
  v32 = v31 - 1; /*0x7660*/
  if ( !v32 ) /*0x7662*/
    return 38; /*0x7674*/
  if ( v32 != 1 ) /*0x7666*/
    return 40; /*0x766d*/
  return 39; /*0x7539*/
}


// Function: RstGetControllerInfo @ 0x76a0 (0xeb bytes)
// Index: 191/906

EFI_STRING __fastcall RstGetControllerInfo(CHAR16 *Destination, __int64 a2, void *HiiHandle)
{
  unsigned __int8 n12; // r10
  EFI_STRING_ID StringId; // di
  unsigned __int16 v7; // r9
  const CHAR8 *StringToLanguage; // rax
  unsigned __int16 v9; // ax
  __int64 v10; // rax
  _WORD i[24]; // [rsp+30h] [rbp-168h] BYREF
  CHAR8 Language[304]; // [rsp+60h] [rbp-138h] BYREF

  RstGpioConfigure(*((_DWORD *)Destination + 35)); /*0x76c1*/
  StringId = RstGpioRead(n12); /*0x76dc*/
  StringToLanguage = (const CHAR8 *)HiiGetStringToLanguage(HiiHandle, v7, 0); /*0x76df*/
  HiiGetString(HiiHandle, StringId, StringToLanguage); /*0x76f0*/
  MemZero(i, 0, 34); /*0x7700*/
  MemZero(Language, 0, 300); /*0x7712*/
  sub_872C(i, 0x11u, (_BYTE *)Destination + 4); /*0x7725*/
  v9 = RstGpioConfigure(*((_DWORD *)Destination + 35)); /*0x7730*/
  v10 = HiiGetStringToLanguage(HiiHandle, v9, 0); /*0x773e*/
  HiiCfgArrayGet(Language, 0x12Cu, (unsigned __int8 *)L"%s, %s", i, v10); /*0x775e*/
  return HiiGetString(HiiHandle, StringId, Language); /*0x7786*/
}


// Function: RstProcessForm @ 0x7a34 (0x23a bytes)
// Index: 195/906

void __fastcall RstProcessForm(RST_PRIVATE_DATA *Private)
{
  _DWORD *v1; // rdx
  void *HiiHandle_1; // r8
  void *HiiHandle; // r14
  _DWORD *v4; // rsi
  unsigned int v6; // eax
  __int64 v7; // r13
  unsigned __int8 n0x18; // di
  unsigned __int64 v9; // rbx
  __int64 v10; // rdx
  __int64 v11; // r8
  __int16 v12; // ax
  __int64 v13; // r8
  unsigned __int8 n24; // di
  unsigned __int64 v15; // rbx
  unsigned __int8 v16; // bp
  __int64 v17; // r8
  __int16 v18; // ax
  __int64 v19; // r8
  CHAR16 Source[70]; // [rsp+20h] [rbp-1F8h] BYREF
  int n21; // [rsp+ACh] [rbp-16Ch]
  CHAR16 Destination[72]; // [rsp+110h] [rbp-108h] BYREF
  int n5; // [rsp+1A0h] [rbp-78h]

  HiiHandle = HiiHandle_1; /*0x7a54*/
  v4 = v1; /*0x7a57*/
  if ( !sub_B120() ) /*0x7a5d*/
  {
    *v4 = 0; /*0x7a67*/
    return; /*0x7a69*/
  }
  v6 = sub_B334(); /*0x7a6e*/
  LOBYTE(v7) = 0; /*0x7a73*/
  n0x18 = 0; /*0x7a76*/
  v9 = v6; /*0x7a79*/
  if ( v6 ) /*0x7a80*/
  {
    while ( 1 ) /*0x7a86*/
    {
      if ( (v9 & 1) == 0 ) /*0x7a89*/
        goto LABEL_13; /*0x7a89*/
      if ( !(unsigned int)RstHelper_c8a8(n0x18, (__int64)Source) ) /*0x7a97*/
        break; /*0x7a97*/
LABEL_14:
      if ( !v9 ) /*0x7b4c*/
        goto LABEL_15; /*0x7b4c*/
    }
    if ( n21 != 21 && (n21 <= 23 || n21 > 25 && (n21 <= 31 || n21 > 36)) ) /*0x7aca*/
    {
      *v4 = 3; /*0x7acc*/
      if ( Private ) /*0x7ad5*/
      {
        StrnCpy(Destination, Source, 0xA8u); /*0x7aea*/
        LOBYTE(v10) = n0x18; /*0x7afa*/
        RstGetControllerInfo(Destination, v10, HiiHandle); /*0x7afd*/
        v11 = 3LL * (unsigned __int8)v7; /*0x7b0a*/
        *((_QWORD *)Private->Vtable + v11 + 2) = 0; /*0x7b11*/
        *((_QWORD *)Private->Vtable + v11) = HiiHandle; /*0x7b1b*/
        v12 = RstGpioRead(n0x18); /*0x7b1f*/
        *((_WORD *)Private->Vtable + 4 * v13 + 4) = v12; /*0x7b28*/
        v7 = (unsigned __int8)(v7 + 1); /*0x7b35*/
        *((_QWORD *)Private->Vtable + 3 * v7) = 0; /*0x7b3e*/
      }
    }
LABEL_13:
    v9 >>= 1; /*0x7b43*/
    ++n0x18; /*0x7b46*/
    goto LABEL_14; /*0x7b46*/
  }
LABEL_15:
  n24 = 0; /*0x7b52*/
  v15 = sub_B1C4(0); /*0x7b5c*/
  if ( v15 ) /*0x7b62*/
  {
    v16 = v7 + 1; /*0x7b68*/
    while ( 1 ) /*0x7b6c*/
    {
      if ( (v15 & 1) == 0 ) /*0x7b6f*/
        goto LABEL_28; /*0x7b6f*/
      if ( !(unsigned int)RstHelper_ce6c(n24, (__int64)Destination) ) /*0x7b81*/
        break; /*0x7b81*/
LABEL_29:
      if ( !v15 ) /*0x7c46*/
        return; /*0x7c46*/
    }
    if ( n5 && n5 != 5 && (n5 <= 6 || n5 > 9 && n5 != 13 && (n5 <= 17 || n5 > 19)) ) /*0x7bc5*/
    {
      *v4 = 3; /*0x7bc7*/
      if ( Private ) /*0x7bd0*/
      {
        StrnCpy(Source, Destination, 0xF0u); /*0x7be5*/
        RstLanguageHandler(Source, n24, HiiHandle); /*0x7bf5*/
        v17 = 3LL * (unsigned __int8)v7; /*0x7c02*/
        *((_QWORD *)Private->Vtable + v17 + 2) = 0; /*0x7c09*/
        *((_QWORD *)Private->Vtable + v17) = HiiHandle; /*0x7c13*/
        v18 = RstGpioWrite(n24); /*0x7c17*/
        *((_WORD *)Private->Vtable + 4 * v19 + 4) = v18; /*0x7c20*/
        LOBYTE(v7) = v7 + 1; /*0x7c2a*/
        *((_QWORD *)Private->Vtable + 3 * v16++) = 0; /*0x7c35*/
      }
    }
LABEL_28:
    v15 >>= 1; /*0x7c3d*/
    ++n24; /*0x7c40*/
    goto LABEL_29; /*0x7c40*/
  }
}