2005-04-08 17:01:17 +02:00
|
|
|
#ifndef REGISTERS_H
|
|
|
|
#define REGISTERS_H
|
|
|
|
|
2005-05-20 13:22:09 +02:00
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* i386 registers.
|
|
|
|
*
|
|
|
|
* This file defines data structures that allow easy access to i386
|
|
|
|
* register dumps.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "compiler.h" /* for doxygen */
|
2005-04-08 17:01:17 +02:00
|
|
|
#include "stdint.h"
|
|
|
|
|
2005-05-20 13:22:09 +02:00
|
|
|
/**
|
|
|
|
* A 16-bit general register.
|
|
|
|
*
|
|
|
|
* This type encapsulates a 16-bit register such as %ax, %bx, %cx,
|
|
|
|
* %dx, %si, %di, %bp or %sp.
|
|
|
|
*
|
|
|
|
*/
|
2005-04-08 17:01:17 +02:00
|
|
|
typedef union {
|
|
|
|
struct {
|
|
|
|
union {
|
|
|
|
uint8_t l;
|
|
|
|
uint8_t byte;
|
|
|
|
};
|
|
|
|
uint8_t h;
|
|
|
|
} PACKED;
|
|
|
|
uint16_t word;
|
|
|
|
} PACKED reg16_t;
|
|
|
|
|
2005-05-20 13:22:09 +02:00
|
|
|
/**
|
|
|
|
* A 32-bit general register.
|
|
|
|
*
|
|
|
|
* This type encapsulates a 32-bit register such as %eax, %ebx, %ecx,
|
|
|
|
* %edx, %esi, %edi, %ebp or %esp.
|
|
|
|
*
|
|
|
|
*/
|
2005-04-08 17:01:17 +02:00
|
|
|
typedef union {
|
2005-05-20 13:22:09 +02:00
|
|
|
struct {
|
|
|
|
union {
|
|
|
|
uint8_t l;
|
|
|
|
uint8_t byte;
|
|
|
|
};
|
|
|
|
uint8_t h;
|
|
|
|
} PACKED;
|
|
|
|
uint16_t word;
|
2005-04-08 17:01:17 +02:00
|
|
|
uint32_t dword;
|
|
|
|
} PACKED reg32_t;
|
|
|
|
|
2005-05-20 13:22:09 +02:00
|
|
|
/**
|
|
|
|
* A 32-bit general register dump.
|
|
|
|
*
|
|
|
|
* This is the data structure that is created on the stack by the @c
|
|
|
|
* pushal instruction, and can be read back using the @c popal
|
|
|
|
* instruction.
|
|
|
|
*
|
|
|
|
*/
|
2005-04-08 17:01:17 +02:00
|
|
|
struct i386_regs {
|
|
|
|
union {
|
|
|
|
uint16_t di;
|
|
|
|
uint32_t edi;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
uint16_t si;
|
|
|
|
uint32_t esi;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
uint16_t bp;
|
|
|
|
uint32_t ebp;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
uint16_t sp;
|
|
|
|
uint32_t esp;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
uint8_t bl;
|
|
|
|
uint8_t bh;
|
|
|
|
} PACKED;
|
|
|
|
uint16_t bx;
|
|
|
|
uint32_t ebx;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
uint8_t dl;
|
|
|
|
uint8_t dh;
|
|
|
|
} PACKED;
|
|
|
|
uint16_t dx;
|
|
|
|
uint32_t edx;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
uint8_t cl;
|
|
|
|
uint8_t ch;
|
|
|
|
} PACKED;
|
|
|
|
uint16_t cx;
|
|
|
|
uint32_t ecx;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
uint8_t al;
|
|
|
|
uint8_t ah;
|
|
|
|
} PACKED;
|
|
|
|
uint16_t ax;
|
|
|
|
uint32_t eax;
|
|
|
|
};
|
|
|
|
} PACKED;
|
|
|
|
|
2005-05-20 13:22:09 +02:00
|
|
|
/**
|
|
|
|
* A segment register dump.
|
|
|
|
*
|
|
|
|
* The i386 has no equivalent of the @c pushal or @c popal
|
|
|
|
* instructions for the segment registers. We adopt the convention of
|
|
|
|
* always using the sequences
|
|
|
|
*
|
|
|
|
* @code
|
|
|
|
*
|
|
|
|
* pushw %gs ; pushw %fs ; pushw %es ; pushw %ds ; pushw %ss ; pushw %cs
|
|
|
|
*
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* and
|
|
|
|
*
|
|
|
|
* @code
|
|
|
|
*
|
|
|
|
* addw $4, %sp ; popw %ds ; popw %es ; popw %fs ; popw %gs
|
|
|
|
*
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* This is the data structure that is created and read back by these
|
|
|
|
* instruction sequences.
|
|
|
|
*
|
|
|
|
*/
|
2005-04-08 17:01:17 +02:00
|
|
|
struct i386_seg_regs {
|
|
|
|
uint16_t cs;
|
|
|
|
uint16_t ss;
|
|
|
|
uint16_t ds;
|
|
|
|
uint16_t es;
|
|
|
|
uint16_t fs;
|
|
|
|
uint16_t gs;
|
|
|
|
} PACKED;
|
|
|
|
|
2005-05-20 13:22:09 +02:00
|
|
|
/**
|
|
|
|
* A full register dump.
|
|
|
|
*
|
|
|
|
* This data structure is created by the instructions
|
|
|
|
*
|
|
|
|
* @code
|
|
|
|
*
|
|
|
|
* pushfl
|
|
|
|
* pushal
|
|
|
|
* pushw %gs ; pushw %fs ; pushw %es ; pushw %ds ; pushw %ss ; pushw %cs
|
|
|
|
*
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* and can be read back using the instructions
|
|
|
|
*
|
|
|
|
* @code
|
|
|
|
*
|
|
|
|
* addw $4, %sp ; popw %ds ; popw %es ; popw %fs ; popw %gs
|
|
|
|
* popal
|
|
|
|
* popfl
|
|
|
|
*
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* prot_call() and kir_call() create this data structure on the stack
|
|
|
|
* and pass in a pointer to this structure.
|
|
|
|
*
|
|
|
|
*/
|
2005-04-08 17:01:17 +02:00
|
|
|
struct i386_all_regs {
|
2005-05-20 13:22:09 +02:00
|
|
|
struct i386_seg_regs segs;
|
|
|
|
struct i386_regs regs;
|
|
|
|
uint32_t flags;
|
2005-04-08 17:01:17 +02:00
|
|
|
} PACKED;
|
|
|
|
|
|
|
|
#endif /* REGISTERS_H */
|