/*
Copyright (C) 2006 Evan Teran
                   eteran@alum.rit.edu

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef STATE_20060715_H_
#define STATE_20060715_H_

#include "types.h"

class QString;

struct State {
public:
	State();

public:
	// only real rule for portability here is that all parts of the state
	// have to be the size of a BaseTypes::reg_t, if it is smaller, a
	// union is used to pad the space difference
	
	BaseTypes::reg_t ebx;
	BaseTypes::reg_t ecx;
	BaseTypes::reg_t edx;
	BaseTypes::reg_t esi;
	BaseTypes::reg_t edi;
	BaseTypes::reg_t ebp;
	BaseTypes::reg_t eax;
	BaseTypes::reg_t esp;
	union { BaseTypes::reg_t _cs; uint16_t cs; };
	union { BaseTypes::reg_t _ds; uint16_t ds; };
	union { BaseTypes::reg_t _es; uint16_t es; };
	union { BaseTypes::reg_t _fs; uint16_t fs; };
	union { BaseTypes::reg_t _gs; uint16_t gs; };
	union { BaseTypes::reg_t _ss; uint16_t ss; };
	union { BaseTypes::reg_t eip; uint16_t ip; };
	union { BaseTypes::reg_t eflags; uint16_t flags; };
	BaseTypes::reg_t orig_eax;

public:
	BaseTypes::reg_t value(const QString &reg) const;
	
	enum {
		EBX_FLAG	= (1 << 0),
		ECX_FLAG	= (1 << 1),
		EDX_FLAG	= (1 << 2),
		ESI_FLAG	= (1 << 3),
		EDI_FLAG	= (1 << 4),
		EBP_FLAG	= (1 << 5),
		EAX_FLAG	= (1 << 6),
		ESP_FLAG	= (1 << 7),
		EIP_FLAG	= (1 << 8),
		EFLAGS_FLAG	= (1 << 9),
		CS_FLAG		= (1 << 10),
		DS_FLAG		= (1 << 11),
		ES_FLAG		= (1 << 12),
		FS_FLAG		= (1 << 13),
		GS_FLAG		= (1 << 14),
		SS_FLAG		= (1 << 15),
		
		// groups, these catagories should remain as portable as possible
		GPR_FLAGS	= (EAX_FLAG | EBX_FLAG | ECX_FLAG | EDX_FLAG | ESI_FLAG | EDI_FLAG | EBP_FLAG | ESP_FLAG),
		IP_FLAGS	= (EIP_FLAG),
		SEG_FLAGS	= (CS_FLAG | DS_FLAG | ES_FLAG | FS_FLAG | GS_FLAG | SS_FLAG),
		ANY_FLAGS	= -1
	};
};

#endif
