diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2008-08-03 15:35:43 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2008-08-03 15:35:43 (GMT) |
commit | 1249cf6e2c0ed87e1c593e488beedbbfe153ff00 (patch) | |
tree | 0a92b85df9dabe76b34810071e0c1def906311da /src/arch/x86/operand.c | |
parent | f0b80c6ab55ede4f8ab8ede757f1f8951512affa (diff) |
Read registers from the ModR/M encoding.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@13 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/x86/operand.c')
-rw-r--r-- | src/arch/x86/operand.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/arch/x86/operand.c b/src/arch/x86/operand.c index 4b8eef8..3eaefd2 100644 --- a/src/arch/x86/operand.c +++ b/src/arch/x86/operand.c @@ -183,6 +183,65 @@ asm_x86_operand *x86_create_reg1632_operand(uint8_t data, bool is_reg32, uint8_t /****************************************************************************** * * +* Paramètres : data = donnée à analyser. * +* is_reg32 = indique si le registre est un registre 32 bits. * +* first = indique la partie du ModR/M à traiter. * +* * +* Description : Crée une opérande renvoyant vers un registre 16 ou 32 bits. * +* * +* Retour : Opérande mise en place ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +asm_x86_operand *x86_create_reg1632_operand_from_modrm(uint8_t data, bool is_reg32, bool first) +{ + asm_x86_operand *result; /* Registre à retourner */ + uint8_t reg; /* Transcription du registre */ + X8616bRegister reg16; /* Registre 16 bits */ + X8632bRegister reg32; /* Registre 32 bits */ + + if (first) reg = data & 0x07; + else reg = (data & 0x38) >> 3; + + if (is_reg32) + switch (reg) + { + case 0 ... 7: + reg32 = (X8632bRegister)reg; + break; + default: + return NULL; + break; + } + + else + switch (reg) + { + case 0 ... 7: + reg16 = (X8616bRegister)reg; + break; + default: + return NULL; + break; + } + + result = create_new_x86_operand(); + + ASM_OPERAND(result)->type = AOT_REG; + ASM_OPERAND(result)->size = (is_reg32 ? AOS_32_BITS : AOS_16_BITS); + + if (is_reg32) result->x86_value.reg32 = reg32; + else result->x86_value.reg16 = reg16; + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : operand = instruction à traiter. * * buffer = tampon de sortie mis à disposition. [OUT] * * len = taille de ce tampon. * |