xref: /haiku/src/kits/debugger/arch/x86/ArchitectureX86.h (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Copyright 2011-2015, Rene Gollent, rene@gollent.com.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef ARCHITECTURE_X86_H
7 #define ARCHITECTURE_X86_H
8 
9 
10 #include <Array.h>
11 
12 #include "Architecture.h"
13 #include "Register.h"
14 
15 
16 enum {
17 	X86_CPU_FEATURE_FLAG_NONE = 0,
18 	X86_CPU_FEATURE_FLAG_MMX = 1,
19 	X86_CPU_FEATURE_FLAG_SSE = 2
20 };
21 
22 
23 class SourceLanguage;
24 
25 
26 class ArchitectureX86 : public Architecture {
27 public:
28 								ArchitectureX86(TeamMemory* teamMemory);
29 	virtual						~ArchitectureX86();
30 
31 	virtual	status_t			Init();
32 
33 	virtual int32				StackGrowthDirection() const;
34 
35 	virtual	int32				CountRegisters() const;
36 	virtual	const Register*		Registers() const;
37 	virtual status_t			InitRegisterRules(CfaContext& context) const;
38 
39 	virtual	status_t			GetDwarfRegisterMaps(RegisterMap** _toDwarf,
40 									RegisterMap** _fromDwarf) const;
41 
42 	virtual	status_t			GetCpuFeatures(uint32& flags);
43 
44 	virtual	status_t			CreateCpuState(CpuState*& _state);
45 	virtual	status_t			CreateCpuState(const void* cpuStateData,
46 									size_t size, CpuState*& _state);
47 	virtual	status_t			CreateStackFrame(Image* image,
48 									FunctionDebugInfo* function,
49 									CpuState* cpuState, bool isTopFrame,
50 									StackFrame*& _previousFrame,
51 									CpuState*& _previousCpuState);
52 	virtual	void				UpdateStackFrameCpuState(
53 									const StackFrame* frame,
54 									Image* previousImage,
55 									FunctionDebugInfo* previousFunction,
56 									CpuState* previousCpuState);
57 
58 	virtual	status_t			ReadValueFromMemory(target_addr_t address,
59 									uint32 valueType, BVariant& _value) const;
60 	virtual	status_t			ReadValueFromMemory(target_addr_t addressSpace,
61 									target_addr_t address, uint32 valueType,
62 									BVariant& _value) const;
63 
64 	virtual	status_t			DisassembleCode(FunctionDebugInfo* function,
65 									const void* buffer, size_t bufferSize,
66 									DisassembledCode*& _sourceCode);
67 	virtual	status_t			GetStatement(FunctionDebugInfo* function,
68 									target_addr_t address,
69 									Statement*& _statement);
70 	virtual	status_t			GetInstructionInfo(target_addr_t address,
71 									InstructionInfo& _info, CpuState* state);
72 	virtual	status_t			ResolvePICFunctionAddress(
73 									target_addr_t instructionAddress,
74 									CpuState* state,
75 									target_addr_t& _targetAddress);
76 
77 	virtual	status_t			GetWatchpointDebugCapabilities(
78 									int32& _maxRegisterCount,
79 									int32& _maxBytesPerRegister,
80 									uint8& _watchpointCapabilityFlags);
81 
82 	virtual	status_t			GetReturnAddressLocation(
83 									StackFrame* frame, target_size_t valueSize,
84 									ValueLocation*& _location);
85 
86 
87 private:
88 			struct ToDwarfRegisterMap;
89 			struct FromDwarfRegisterMap;
90 
91 private:
92 			void				_AddRegister(int32 index, const char* name,
93 									uint32 bitSize, uint32 valueType,
94 									register_type type, bool calleePreserved);
95 			void				_AddIntegerRegister(int32 index,
96 									const char* name, uint32 valueType,
97 									register_type type, bool calleePreserved);
98 			void				_AddFPRegister(int32 index,
99 									const char* name);
100 			void				_AddSIMDRegister(int32 index,
101 									const char* name, uint32 byteSize);
102 			bool				_HasFunctionPrologue(
103 									FunctionDebugInfo* function) const;
104 
105 private:
106 			uint32				fFeatureFlags;
107 			Array<Register>		fRegisters;
108 			SourceLanguage*		fAssemblyLanguage;
109 			ToDwarfRegisterMap*	fToDwarfRegisterMap;
110 			FromDwarfRegisterMap* fFromDwarfRegisterMap;
111 };
112 
113 
114 #endif	// ARCHITECTURE_X86_H
115