Changeset 2944 for trunk/kLdr/kLdr.c


Ignore:
Timestamp:
Jan 13, 2007, 4:55:40 PM (19 years ago)
Author:
bird
Message:

split up kLdrHlp.c and kLdr.c to make it more flexible (like using the module interpreters without the dynamic loader bit and similar).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/kLdr.c

    r2883 r2944  
    142142}
    143143
    144 
    145 /**
    146  * Compares arch+cpu some code was generated for with a arch+cpu for executing it
    147  * to see if it'll work out fine or not.
    148  *
    149  * @returns 0 if the code is compatible with the cpu.
    150  * @returns KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE if the arch+cpu isn't compatible with the code.
    151  * @param   enmCodeArch The architecture the code was generated for.
    152  * @param   enmCodeCpu  The cpu the code was generated for.
    153  * @param   enmArch     The architecture to run it on.
    154  * @param   enmCpu      The cpu to run it on.
    155  */
    156 int kLdrCompareCpus(KLDRARCH enmCodeArch, KLDRCPU enmCodeCpu, KLDRARCH enmArch, KLDRCPU enmCpu)
    157 {
    158     /*
    159      * Compare arch and cpu.
    160      */
    161     if (enmCodeArch != enmArch)
    162         return KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE;
    163 
    164     /* exact match is nice. */
    165     if (enmCodeCpu == enmCpu)
    166         return 0;
    167     switch (enmArch)
    168     {
    169         case KLDRARCH_X86_16:
    170             if (enmCpu < KLDRCPU_FIRST_X86_16 || enmCpu > KLDRCPU_LAST_X86_16)
    171                 return KLDR_ERR_INVALID_PARAMETER;
    172 
    173             /* intel? */
    174             if (enmCodeCpu <= KLDRCPU_CORE2_16)
    175             {
    176                 /* also intel? */
    177                 if (enmCpu <= KLDRCPU_CORE2_16)
    178                     return enmCodeCpu <= enmCpu ? 0 : KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE;
    179                 switch (enmCpu)
    180                 {
    181                     case KLDRCPU_K6_16:
    182                         return enmCodeCpu <= KLDRCPU_I586 ? 0 : KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE;
    183                     case KLDRCPU_K7_16:
    184                     case KLDRCPU_K8_16:
    185                     default:
    186                         return enmCodeCpu <= KLDRCPU_I686 ? 0 : KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE;
    187                 }
    188             }
    189             /* amd */
    190             return enmCpu >= KLDRCPU_K6_16 && enmCpu <= KLDRCPU_K8_16
    191                     ? 0 : KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE;
    192 
    193         case KLDRARCH_X86_32:
    194             if (enmCpu < KLDRCPU_FIRST_X86_32 || enmCpu > KLDRCPU_LAST_X86_32)
    195                 return KLDR_ERR_INVALID_PARAMETER;
    196 
    197             /* blend? */
    198             if (enmCodeCpu == KLDRCPU_X86_32_BLEND)
    199                 return 0;
    200 
    201             /* intel? */
    202             if (enmCodeCpu <= KLDRCPU_CORE2_32)
    203             {
    204                 /* also intel? */
    205                 if (enmCpu <= KLDRCPU_CORE2_32)
    206                     return enmCodeCpu <= enmCpu ? 0 : KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE;
    207                 switch (enmCpu)
    208                 {
    209                     case KLDRCPU_K6:
    210                         return enmCodeCpu <= KLDRCPU_I586 ? 0 : KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE;
    211                     case KLDRCPU_K7:
    212                     case KLDRCPU_K8_32:
    213                     default:
    214                         return enmCodeCpu <= KLDRCPU_I686 ? 0 : KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE;
    215                 }
    216             }
    217             /* amd */
    218             return enmCpu >= KLDRCPU_K6 && enmCpu <= KLDRCPU_K8_32
    219                     ? 0 : KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE;
    220 
    221         case KLDRARCH_AMD64:
    222             if (enmCpu < KLDRCPU_FIRST_AMD64 || enmCpu > KLDRCPU_LAST_AMD64)
    223                 return KLDR_ERR_INVALID_PARAMETER;
    224 
    225             /* blend? */
    226             if (enmCodeCpu == KLDRCPU_AMD64_BLEND)
    227                 return 0;
    228             /* this is simple for now. */
    229             return KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE;
    230 
    231         default:
    232             break;
    233     }
    234     return KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE;
    235 }
    236 
    237 
    238 /**
    239  * Gets the arch+cpu of the calling cpu.
    240  *
    241  * @param   penmArch    Where to store the cpu architecture.
    242  * @param   penmCpu     Where to store the cpu brand/model.
    243  */
    244 void kLdrGetArchCpu(PKLDRARCH penmArch, PKLDRCPU penmCpu)
    245 {
    246 #ifdef __AMD64__
    247     *penmArch = KLDRARCH_AMD64;
    248     *penmCpu = KLDRCPU_AMD64_BLEND; /** @todo check it using cpu. */
    249 
    250 #elif defined(__X86__)
    251     *penmArch = KLDRARCH_X86_32;
    252     *penmCpu = KLDRCPU_X86_32_BLEND; /** @todo check it using cpu. */
    253 
    254 #else
    255 # error "Port me"
    256 #endif
    257 }
Note: See TracChangeset for help on using the changeset viewer.