Changeset 3585 for trunk/kStuff/include


Ignore:
Timestamp:
Sep 3, 2007, 3:18:26 AM (18 years ago)
Author:
bird
Message:

Cpu / architecture cleanup...

Location:
trunk/kStuff/include/k
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/kStuff/include/k/kDefs.h

    r3583 r3585  
    119119 * These are the value that the K_ARCH \#define can take.
    120120 *@{ */
     121/** Unknown CPU architecture. */
     122#define K_ARCH_UNKNOWN          ( 0 )
    121123/** Clone or Intel 16-bit x86. */
    122124#define K_ARCH_X86_16           ( 1 | K_ARCH_BIT_16 | K_ARCH_END_LITTLE)
     
    151153/** @} */
    152154
     155
    153156/** @def K_ARCH
    154157 * The value of this \#define indicates which architecture we're targetting.
     
    184187# endif
    185188#endif
     189
     190/** @def K_ARCH_IS_VALID
     191 * Check if the architecture identifier is valid.
     192 * @param   arch            The K_ARCH_* define to examin.
     193 */
     194#define K_ARCH_IS_VALID(arch)   (   (   ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_8 \
     195                                     || ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_16 \
     196                                     || ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_32 \
     197                                     || ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_64 \
     198                                     || ((arch) & K_ARCH_BIT_MASK) == K_ARCH_BIT_128) \
     199                                 && \
     200                                    (   ((arch) & K_ARCH_END_MASK) == K_ARCH_END_LITTLE \
     201                                     || ((arch) & K_ARCH_END_MASK) == K_ARCH_END_BIG \
     202                                     || ((arch) & K_ARCH_END_MASK) == K_ARCH_END_BI) \
     203                                 && \
     204                                    (   ((arch) & ~(K_ARCH_BIT_MASK | K_ARCH_END_MASK)) >= K_ARCH_UNKNOWN \
     205                                     && ((arch) & ~(K_ARCH_BIT_MASK | K_ARCH_END_MASK)) < K_ARCH_MAX) \
     206                                )
    186207
    187208/** @def K_ARCH_BITS_EX
  • trunk/kStuff/include/k/kErrors.h

    r3579 r3585  
    11/* $Id$ */
    22/** @file
    3  *
    43 * kErrors - Status Codes.
    5  *
    6  * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
    7  *
     4 */
     5
     6/*
     7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
    88 *
    99 * This file is part of kStuff.
    1010 *
    11  * kStuff is free software; you can redistribute it and/or modify
    12  * it under the terms of the GNU Lesser General Public License as published
    13  * by the Free Software Foundation; either version 2 of the License, or
    14  * (at your option) any later version.
     11 * kStuff is free software; you can redistribute it and/or
     12 * modify it under the terms of the GNU Lesser General Public
     13 * License as published by the Free Software Foundation; either
     14 * version 2.1 of the License, or (at your option) any later version.
    1515 *
    1616 * kStuff is distributed in the hope that it will be useful,
    1717 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19  * GNU Lesser General Public License for more details.
    20  *
    21  * You should have received a copy of the GNU Lesser General Public License
    22  * along with kStuff; if not, write to the Free Software
    23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     19 * Lesser General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU Lesser General Public
     22 * License along with kStuff; if not, write to the Free Software
     23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    2424 *
    2525 */
     
    8383/** @} */
    8484
    85 
    8685/** @name   kDbg Specific
    8786 * @{
     
    117116 * @{
    118117 */
     118/** The base of the kLdr specific status codes. */
    119119#define KLDR_ERR_BASE                                   (KRDR_ERR_BASE + 3)
    120120
     
    166166/** Failed to allocate the main stack. */
    167167#define KLDR_ERR_MAIN_STACK_ALLOC_FAILED                (KLDR_ERR_BASE + 20)
    168 /** The specified ARCH+CPU isn't compatible with image. */
    169 #define KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE                (KLDR_ERR_BASE + 21)
    170168/** Symbol not found. */
    171 #define KLDR_ERR_SYMBOL_NOT_FOUND                       (KLDR_ERR_BASE + 22)
     169#define KLDR_ERR_SYMBOL_NOT_FOUND                       (KLDR_ERR_BASE + 21)
    172170/** A forward symbol was encountered but the caller didn't provide any means to resolve it. */
    173 #define KLDR_ERR_FORWARDER_SYMBOL                       (KLDR_ERR_BASE + 23)
     171#define KLDR_ERR_FORWARDER_SYMBOL                       (KLDR_ERR_BASE + 22)
    174172/** Encountered a bad fixup. */
    175 #define KLDR_ERR_BAD_FIXUP                              (KLDR_ERR_BASE + 24)
     173#define KLDR_ERR_BAD_FIXUP                              (KLDR_ERR_BASE + 23)
    176174/** The import ordinal was out of bounds. */
    177 #define KLDR_ERR_IMPORT_ORDINAL_OUT_OF_BOUNDS           (KLDR_ERR_BASE + 25)
     175#define KLDR_ERR_IMPORT_ORDINAL_OUT_OF_BOUNDS           (KLDR_ERR_BASE + 24)
    178176/** A forwarder chain was too long. */
    179 #define KLDR_ERR_TOO_LONG_FORWARDER_CHAIN               (KLDR_ERR_BASE + 26)
     177#define KLDR_ERR_TOO_LONG_FORWARDER_CHAIN               (KLDR_ERR_BASE + 25)
    180178/** The module has no debug info. */
    181 #define KLDR_ERR_NO_DEBUG_INFO                          (KLDR_ERR_BASE + 27)
     179#define KLDR_ERR_NO_DEBUG_INFO                          (KLDR_ERR_BASE + 26)
    182180/** The module is already mapped.
    183181 * kLdrModMap() can only be called once (without kLdrModUnmap() in between). */
    184 #define KLDR_ERR_ALREADY_MAPPED                         (KLDR_ERR_BASE + 28)
     182#define KLDR_ERR_ALREADY_MAPPED                         (KLDR_ERR_BASE + 27)
    185183/** The module was not mapped.
    186184 * kLdrModUnmap() should not called without being preceeded by a kLdrModMap(). */
    187 #define KLDR_ERR_NOT_MAPPED                             (KLDR_ERR_BASE + 29)
     185#define KLDR_ERR_NOT_MAPPED                             (KLDR_ERR_BASE + 28)
    188186/** Couldn't fit the address value into the field. Typically a relocation kind of error. */
    189 #define KLDR_ERR_ADDRESS_OVERFLOW                       (KLDR_ERR_BASE + 30)
     187#define KLDR_ERR_ADDRESS_OVERFLOW                       (KLDR_ERR_BASE + 29)
    190188/** Couldn't fit a calculated size value into the native size type of the host. */
    191 #define KLDR_ERR_SIZE_OVERFLOW                          (KLDR_ERR_BASE + 31)
     189#define KLDR_ERR_SIZE_OVERFLOW                          (KLDR_ERR_BASE + 30)
    192190/** Thread attach failed. */
    193 #define KLDR_ERR_THREAD_ATTACH_FAILED                   (KLDR_ERR_BASE + 32)
     191#define KLDR_ERR_THREAD_ATTACH_FAILED                   (KLDR_ERR_BASE + 31)
    194192/** The module wasn't a DLL or object file. */
    195 #define KLDR_ERR_NOT_DLL                                (KLDR_ERR_BASE + 33)
     193#define KLDR_ERR_NOT_DLL                                (KLDR_ERR_BASE + 32)
    196194/** The module wasn't an EXE. */
    197 #define KLDR_ERR_NOT_EXE                                (KLDR_ERR_BASE + 34)
     195#define KLDR_ERR_NOT_EXE                                (KLDR_ERR_BASE + 33)
    198196/** Not implemented yet. */
    199 #define KLDR_ERR_TODO                                   (KLDR_ERR_BASE + 35)
     197#define KLDR_ERR_TODO                                   (KLDR_ERR_BASE + 34)
    200198/** @} */
    201199
     
    203201 * @{
    204202 */
    205 #define KLDR_ERR_PE_BASE                                (KLDR_ERR_BASE + 36)
     203/** The base of the kLdrModPE specific status codes. */
     204#define KLDR_ERR_PE_BASE                                (KLDR_ERR_BASE + 35)
    206205/** The machine isn't supported by the interpreter. */
    207206#define KLDR_ERR_PE_UNSUPPORTED_MACHINE                 (KLDR_ERR_PE_BASE + 0)
     
    225224 * @{
    226225 */
     226/** The base of the kLdrModLX specific status codes. */
    227227#define KLDR_ERR_LX_BASE                                (KLDR_ERR_PE_BASE + 8)
    228228/** validation of LX header failed. */
     
    255255 * @{
    256256 */
     257/** The base of the kLdrModMachO specific status codes. */
    257258#define KLDR_ERR_MACHO_BASE                             (KLDR_ERR_LX_BASE + 12)
    258259/** Only native endian Mach-O files are supported. */
     
    290291/** @} */
    291292
     293/** @name kCpu Specific
     294 * @{
     295 */
     296/** The base of the kCpu specific status codes. */
     297#define KCPU_ERR_BASE                                   (KLDR_ERR_MACHO_BASE + 16)
     298/** The specified ARCH+CPU pairs aren't compatible. */
     299#define KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE                (KCPU_ERR_BASE + 0)
     300/** @} */
    292301
    293302/** End of the valid status codes. */
    294 #define KERR_END                                        (KLDR_ERR_MACHO_BASE + 16)
     303#define KERR_END                                        (KCPU_ERR_BASE + 1)
    295304/** @}*/
    296305
    297306#endif
     307
  • trunk/kStuff/include/k/kLdr.h

    r3579 r3585  
    3737#include <k/kDefs.h>
    3838#include <k/kTypes.h>
     39#include <k/kCpus.h>
    3940
    4041
     
    166167/** @defgroup grp_kLdrMod   kLdrMod - The executable image intepreter
    167168 * @{ */
    168 
    169 /**
    170  * CPU Architecture.
    171  * @todo Double check the non intel architectures.
    172  */
    173 typedef enum KLDRARCH
    174 {
    175     /** The usual invalid one. */
    176     KLDRARCH_INVALID = 0,
    177     /** Clone or Intel 16-bit x86. */
    178     KLDRARCH_X86_16,
    179     /** Clone or Intel 32-bit x86. */
    180     KLDRARCH_X86_32,
    181     /** AMD64 (including clones). */
    182     KLDRARCH_AMD64,
    183     /** Itanic (64-bit). */
    184     KLDRARCH_IA64,
    185     /** ALPHA (64-bit). */
    186     KLDRARCH_ALPHA,
    187     /** ALPHA limited to 32-bit. */
    188     KLDRARCH_ALPHA_32,
    189     /** 32-bit ARM. */
    190     KLDRARCH_ARM_32,
    191     /** 64-bit ARM. */
    192     KLDRARCH_ARM_64,
    193     /** 32-bit MIPS. */
    194     KLDRARCH_MIPS_32,
    195     /** 64-bit MIPS. */
    196     KLDRARCH_MIPS_64,
    197     /** 32-bit PowerPC. */
    198     KLDRARCH_POWERPC_32,
    199     /** 64-bit PowerPC. */
    200     KLDRARCH_POWERPC_64,
    201     /** 32-bit SPARC. */
    202     KLDRARCH_SPARC_32,
    203     /** 64-bit SPARC. */
    204     KLDRARCH_SPARC_64,
    205     /** The end of the valid architecture values (exclusive). */
    206     KLDRARCH_END,
    207     /** Hack to blow the type up to 32-bit. */
    208     KLDRARCH_32BIT_HACK = 0x7fffffff
    209 } KLDRARCH;
    210 /** Pointer to a CPU architecture type. */
    211 typedef KLDRARCH *PKLDRARCH;
    212 
    213 /**
    214  * CPU models.
    215  */
    216 typedef enum KLDRCPU
    217 {
    218     /** The usual invalid cpu. */
    219     KLDRCPU_INVALID = 0,
    220     /** @name KLDRARCH_X86_16
    221      * @{ */
    222     KLDRCPU_I8086,
    223     KLDRCPU_I8088,
    224     KLDRCPU_I80186,
    225     KLDRCPU_I80286,
    226     KLDRCPU_I386_16,
    227     KLDRCPU_I486_16,
    228     KLDRCPU_I486SX_16,
    229     KLDRCPU_I586_16,
    230     KLDRCPU_I686_16,
    231     KLDRCPU_P4_16,
    232     KLDRCPU_CORE2_16,
    233     KLDRCPU_K6_16,
    234     KLDRCPU_K7_16,
    235     KLDRCPU_K8_16,
    236     KLDRCPU_FIRST_X86_16 = KLDRCPU_I8086,
    237     KLDRCPU_LAST_X86_16 = KLDRCPU_K8_16,
    238     /** @} */
    239 
    240     /** @name KLDRARCH_X86_32
    241      * @{ */
    242     KLDRCPU_X86_32_BLEND,
    243     KLDRCPU_I386,
    244     KLDRCPU_I486,
    245     KLDRCPU_I486SX,
    246     KLDRCPU_I586,
    247     KLDRCPU_I686,
    248     KLDRCPU_P4,
    249     KLDRCPU_CORE2_32,
    250     KLDRCPU_K6,
    251     KLDRCPU_K7,
    252     KLDRCPU_K8_32,
    253     KLDRCPU_FIRST_X86_32 = KLDRCPU_I386,
    254     KLDRCPU_LAST_X86_32 = KLDRCPU_K8_32,
    255     /** @} */
    256 
    257     /** @name KLDRARCH_AMD64
    258      * @{ */
    259     KLDRCPU_AMD64_BLEND,
    260     KLDRCPU_K8,
    261     KLDRCPU_P4_64,
    262     KLDRCPU_CORE2,
    263     KLDRCPU_FIRST_AMD64 = KLDRCPU_K8,
    264     KLDRCPU_LAST_AMD64 = KLDRCPU_CORE2,
    265     /** @} */
    266 
    267     /** The end of the valid cpu values (exclusive). */
    268     KLDRCPU_END,
    269     /** Hack to blow the type up to 32-bit. */
    270     KLDRCPU_32BIT_HACK = 0x7fffffff
    271 } KLDRCPU;
    272 /** Pointer to a CPU type. */
    273 typedef KLDRCPU *PKLDRCPU;
    274 
    275 void kLdrGetArchCpu(PKLDRARCH penmArch, PKLDRCPU penmCpu);
    276 int kLdrCompareCpus(KLDRARCH enmCodeArch, KLDRCPU enmCodeCpu, KLDRARCH enmArch, KLDRCPU enmCpu);
    277 
    278169
    279170/**
     
    486377    /** The type of module. */
    487378    KLDRTYPE            enmType;
    488     /** The architecture this module was built for. */
    489     KLDRARCH            enmArch;
     379    /** The CPU architecture this module was built for. */
     380    KCPUARCH            enmArch;
    490381    /** The minium cpu this module was built for.
    491382     * This might not be accurate, so use kLdrModCanExecuteOn() to check. */
    492     KLDRARCH            enmCpu;
     383    KCPU                enmCpu;
    493384    /** The endian used by the module. */
    494385    KLDRENDIAN          enmEndian;
     
    704595int     kLdrModGetImport(PKLDRMOD pMod, const void *pvBits, KU32 iImport, char *pszName, KSIZE cchName);
    705596KI32    kLdrModNumberOfImports(PKLDRMOD pMod, const void *pvBits);
    706 int     kLdrModCanExecuteOn(PKLDRMOD pMod, const void *pvBits, KLDRARCH enmArch, KLDRCPU enmCpu);
     597int     kLdrModCanExecuteOn(PKLDRMOD pMod, const void *pvBits, KCPUARCH enmArch, KCPU enmCpu);
    707598int     kLdrModGetStackInfo(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo);
    708599int     kLdrModQueryMainEntrypoint(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRADDR pMainEPAddress);
     
    783674    KI32 (* pfnNumberOfImports)(PKLDRMOD pMod, const void *pvBits);
    784675    /** @copydoc kLdrModCanExecuteOn */
    785     int (* pfnCanExecuteOn)(PKLDRMOD pMod, const void *pvBits, KLDRARCH enmArch, KLDRCPU enmCpu);
     676    int (* pfnCanExecuteOn)(PKLDRMOD pMod, const void *pvBits, KCPUARCH enmArch, KCPU enmCpu);
    786677    /** @copydoc kLdrModGetStackInfo */
    787678    int (* pfnGetStackInfo)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo);
Note: See TracChangeset for help on using the changeset viewer.