做PA做到后面经常会有寄存器值出错的问题,无法排除个例,大多数情况下这种错都和之前实现的寄存器结构体有关,以下是我目前正确的寄存器结构体实现方法:
/* TODO: Re-organize the `CPU_state' structure to match the register * encoding scheme in i386 instruction format. For example, if we * access cpu.gpr[3]._16, we will get the `bx' register; if we access * cpu.gpr[1]._8[1], we will get the 'ch' register. Hint: Use `union'. * For more details about the register encoding scheme, see i386 manual. */
typedef struct {
union {
struct{
rtlreg_t eax;
rtlreg_t ecx;
rtlreg_t edx;
rtlreg_t ebx;
rtlreg_t esp;
rtlreg_t ebp;
rtlreg_t esi;
rtlreg_t edi;
};
union {
uint32_t _32;
uint16_t _16;
uint8_t _8[2];
}gpr[8]; };
vaddr_t eip;
union{
struct {
uint32_t CF:1;
unsigned : 5;
uint32_t ZF:1;
uint32_t SF:1;
unsigned : 1;
uint32_t IF:1;
unsigned : 1;
uint32_t OF:1;
unsigned : 20;
};
rtlreg_t value;
}eflags;
/* Do NOT change the order of the GPRs' definitions. */
/* In NEMU, rtlreg_t is exactly uint32_t. This makes RTL instructions * in PA2 able to directly access these registers. */ /*rtlreg_t eax, ecx, edx, ebx, esp, ebp, esi, edi;*/
/* vaddr_t eip;*/
} CPU_state;