1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2011-2016, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef ARCHITECTURE_H
7#define ARCHITECTURE_H
8
9
10#include <ByteOrder.h>
11#include <OS.h>
12
13#include <Referenceable.h>
14#include <Variant.h>
15
16#include "ReturnValueInfo.h"
17#include "Types.h"
18
19
20class CfaContext;
21class CpuState;
22class DisassembledCode;
23class FunctionDebugInfo;
24class Image;
25class ImageDebugInfoProvider;
26class InstructionInfo;
27class Register;
28class RegisterMap;
29class StackFrame;
30class StackTrace;
31class Statement;
32class Team;
33class TeamMemory;
34class ValueLocation;
35
36
37enum {
38	STACK_GROWTH_DIRECTION_POSITIVE = 0,
39	STACK_GROWTH_DIRECTION_NEGATIVE
40};
41
42
43enum {
44	WATCHPOINT_CAPABILITY_FLAG_READ = 1,
45	WATCHPOINT_CAPABILITY_FLAG_WRITE = 2,
46	WATCHPOINT_CAPABILITY_FLAG_READ_WRITE = 4
47};
48
49
50class Architecture : public BReferenceable {
51public:
52								Architecture(TeamMemory* teamMemory,
53									uint8 addressSize,
54									size_t debugCpuStateSize,
55									bool bigEndian);
56
57	virtual						~Architecture();
58
59	virtual	status_t			Init();
60
61	inline	uint8				AddressSize() const		{ return fAddressSize; }
62	inline	size_t				DebugCpuStateSize() const
63									{ return fDebugCpuStateSize; }
64
65	inline	bool				IsBigEndian() const		{ return fBigEndian; }
66	inline	bool				IsHostEndian() const;
67
68	virtual int32				StackGrowthDirection() const = 0;
69
70	virtual	int32				CountRegisters() const = 0;
71	virtual	const Register*		Registers() const = 0;
72	virtual status_t			InitRegisterRules(CfaContext& context) const;
73
74	virtual	status_t			GetDwarfRegisterMaps(RegisterMap** _toDwarf,
75									RegisterMap** _fromDwarf) const = 0;
76										// returns references
77
78	virtual	status_t			GetCpuFeatures(uint32& flags) = 0;
79
80	virtual	status_t			CreateCpuState(CpuState*& _state) = 0;
81	virtual	status_t			CreateCpuState(const void* cpuStateData,
82									size_t size, CpuState*& _state) = 0;
83	virtual	status_t			CreateStackFrame(Image* image,
84									FunctionDebugInfo* function,
85									CpuState* cpuState, bool isTopFrame,
86									StackFrame*& _frame,
87									CpuState*& _previousCpuState) = 0;
88										// returns reference to previous frame
89										// and CPU state; returned CPU state
90										// can be NULL
91	virtual	void				UpdateStackFrameCpuState(
92									const StackFrame* frame,
93									Image* previousImage,
94									FunctionDebugInfo* previousFunction,
95									CpuState* previousCpuState) = 0;
96										// Called after a CreateStackFrame()
97										// with the image/function corresponding
98										// to the CPU state.
99
100	virtual	status_t			ReadValueFromMemory(target_addr_t address,
101									uint32 valueType, BVariant& _value) const
102										= 0;
103	virtual	status_t			ReadValueFromMemory(target_addr_t addressSpace,
104									target_addr_t address, uint32 valueType,
105									BVariant& _value) const = 0;
106
107	virtual	status_t			DisassembleCode(FunctionDebugInfo* function,
108									const void* buffer, size_t bufferSize,
109									DisassembledCode*& _sourceCode) = 0;
110	virtual	status_t			GetStatement(FunctionDebugInfo* function,
111									target_addr_t address,
112									Statement*& _statement) = 0;
113	virtual	status_t			GetInstructionInfo(target_addr_t address,
114									InstructionInfo& _info,
115									CpuState* state) = 0;
116	virtual	status_t			ResolvePICFunctionAddress(target_addr_t
117									instructionAddress,
118									CpuState* state,
119									target_addr_t& _targetAddress) = 0;
120
121			status_t			CreateStackTrace(Team* team,
122									ImageDebugInfoProvider* imageInfoProvider,
123									CpuState* cpuState,
124									StackTrace*& _stackTrace,
125									ReturnValueInfoList* returnValueInfos,
126									int32 maxStackDepth = -1,
127									bool useExistingTrace = false,
128									bool getFullFrameInfo = true);
129										// team is not locked
130
131	virtual	status_t			GetWatchpointDebugCapabilities(
132									int32& _maxRegisterCount,
133									int32& _maxBytesPerRegister,
134									uint8& _watchpointCapabilityFlags) = 0;
135
136	virtual	status_t			GetReturnAddressLocation(
137									StackFrame* frame, target_size_t valueSize,
138									ValueLocation*& _location) = 0;
139
140
141protected:
142			TeamMemory*			fTeamMemory;
143			uint8				fAddressSize;
144			size_t				fDebugCpuStateSize;
145			bool				fBigEndian;
146};
147
148
149bool
150Architecture::IsHostEndian() const
151{
152	return fBigEndian == (B_HOST_IS_BENDIAN != 0);
153}
154
155
156#endif	// ARCHITECTURE_H
157