xref: /netbsd-src/external/bsd/elftosb/dist/common/Operation.h (revision 993229b6fea628ff8b1fa09146c80b0cfb2768eb)
1*993229b6Sjkunz /*
2*993229b6Sjkunz  * File:	Operation.h
3*993229b6Sjkunz  *
4*993229b6Sjkunz  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5*993229b6Sjkunz  * See included license file for license details.
6*993229b6Sjkunz  */
7*993229b6Sjkunz #if !defined(_Operation_h_)
8*993229b6Sjkunz #define _Operation_h_
9*993229b6Sjkunz 
10*993229b6Sjkunz #include "stdafx.h"
11*993229b6Sjkunz #include <vector>
12*993229b6Sjkunz #include "DataSource.h"
13*993229b6Sjkunz #include "DataTarget.h"
14*993229b6Sjkunz #include "smart_ptr.h"
15*993229b6Sjkunz 
16*993229b6Sjkunz namespace elftosb
17*993229b6Sjkunz {
18*993229b6Sjkunz 
19*993229b6Sjkunz /*!
20*993229b6Sjkunz  * \brief Abstract base class for all boot operations.
21*993229b6Sjkunz  */
22*993229b6Sjkunz class Operation
23*993229b6Sjkunz {
24*993229b6Sjkunz public:
Operation()25*993229b6Sjkunz 	Operation() {}
~Operation()26*993229b6Sjkunz 	virtual ~Operation() {}
27*993229b6Sjkunz };
28*993229b6Sjkunz 
29*993229b6Sjkunz /*!
30*993229b6Sjkunz  * \brief Load data into memory operation.
31*993229b6Sjkunz  */
32*993229b6Sjkunz class LoadOperation : public Operation
33*993229b6Sjkunz {
34*993229b6Sjkunz public:
LoadOperation()35*993229b6Sjkunz 	LoadOperation() : Operation(), m_source(), m_target() {}
36*993229b6Sjkunz 
37*993229b6Sjkunz 	void setSource(DataSource * source);
getSource()38*993229b6Sjkunz 	inline DataSource * getSource() { return m_source; }
39*993229b6Sjkunz 
40*993229b6Sjkunz 	void setTarget(DataTarget * target);
getTarget()41*993229b6Sjkunz 	inline DataTarget * getTarget() { return m_target; }
42*993229b6Sjkunz 
setDCDLoad(bool isDCD)43*993229b6Sjkunz 	inline void setDCDLoad(bool isDCD) { m_isDCDLoad = isDCD; }
isDCDLoad()44*993229b6Sjkunz 	inline bool isDCDLoad() const { return m_isDCDLoad; }
45*993229b6Sjkunz 
46*993229b6Sjkunz protected:
47*993229b6Sjkunz 	smart_ptr<DataSource> m_source;
48*993229b6Sjkunz 	smart_ptr<DataTarget> m_target;
49*993229b6Sjkunz 	bool m_isDCDLoad;
50*993229b6Sjkunz };
51*993229b6Sjkunz 
52*993229b6Sjkunz /*!
53*993229b6Sjkunz  * \brief Operation to execute code at a certain address.
54*993229b6Sjkunz  */
55*993229b6Sjkunz class ExecuteOperation : public Operation
56*993229b6Sjkunz {
57*993229b6Sjkunz public:
58*993229b6Sjkunz 	enum execute_type_t
59*993229b6Sjkunz 	{
60*993229b6Sjkunz 		kJump,
61*993229b6Sjkunz 		kCall
62*993229b6Sjkunz 	};
63*993229b6Sjkunz 
64*993229b6Sjkunz public:
ExecuteOperation()65*993229b6Sjkunz 	ExecuteOperation() : Operation(), m_target(), m_argument(0), m_type(kCall), m_isHAB(false) {}
66*993229b6Sjkunz 
setTarget(DataTarget * target)67*993229b6Sjkunz 	inline void setTarget(DataTarget * target) { m_target = target; }
getTarget()68*993229b6Sjkunz 	inline DataTarget * getTarget() { return m_target; }
69*993229b6Sjkunz 
setArgument(uint32_t arg)70*993229b6Sjkunz 	inline void setArgument(uint32_t arg) { m_argument = arg; }
getArgument()71*993229b6Sjkunz 	inline uint32_t getArgument() { return m_argument; }
72*993229b6Sjkunz 
setExecuteType(execute_type_t type)73*993229b6Sjkunz 	inline void setExecuteType(execute_type_t type) { m_type = type; }
getExecuteType()74*993229b6Sjkunz 	inline execute_type_t getExecuteType() { return m_type; }
75*993229b6Sjkunz 
setIsHAB(bool isHAB)76*993229b6Sjkunz 	inline void setIsHAB(bool isHAB) { m_isHAB = isHAB; }
isHAB()77*993229b6Sjkunz 	inline bool isHAB() const { return m_isHAB; }
78*993229b6Sjkunz 
79*993229b6Sjkunz protected:
80*993229b6Sjkunz 	smart_ptr<DataTarget> m_target;
81*993229b6Sjkunz 	uint32_t m_argument;
82*993229b6Sjkunz 	execute_type_t m_type;
83*993229b6Sjkunz 	bool m_isHAB;
84*993229b6Sjkunz };
85*993229b6Sjkunz 
86*993229b6Sjkunz /*!
87*993229b6Sjkunz  * \brief Authenticate with HAB and execute the entry point.
88*993229b6Sjkunz  */
89*993229b6Sjkunz class HABExecuteOperation : public ExecuteOperation
90*993229b6Sjkunz {
91*993229b6Sjkunz public:
HABExecuteOperation()92*993229b6Sjkunz 	HABExecuteOperation() : ExecuteOperation() {}
93*993229b6Sjkunz };
94*993229b6Sjkunz 
95*993229b6Sjkunz /*!
96*993229b6Sjkunz  * \brief Operation to switch boot modes.
97*993229b6Sjkunz  */
98*993229b6Sjkunz class BootModeOperation : public Operation
99*993229b6Sjkunz {
100*993229b6Sjkunz public:
BootModeOperation()101*993229b6Sjkunz 	BootModeOperation() : Operation() {}
102*993229b6Sjkunz 
setBootMode(uint32_t mode)103*993229b6Sjkunz 	inline void setBootMode(uint32_t mode) { m_bootMode = mode; }
getBootMode()104*993229b6Sjkunz 	inline uint32_t getBootMode() const { return m_bootMode; }
105*993229b6Sjkunz 
106*993229b6Sjkunz protected:
107*993229b6Sjkunz 	uint32_t m_bootMode;	//!< The new boot mode value.
108*993229b6Sjkunz };
109*993229b6Sjkunz 
110*993229b6Sjkunz /*!
111*993229b6Sjkunz  * \brief Ordered sequence of operations.
112*993229b6Sjkunz  *
113*993229b6Sjkunz  * The operation objects owned by the sequence are \e not deleted when the
114*993229b6Sjkunz  * sequence is destroyed. The owner of the sequence must manually delete
115*993229b6Sjkunz  * the operation objects.
116*993229b6Sjkunz  */
117*993229b6Sjkunz class OperationSequence
118*993229b6Sjkunz {
119*993229b6Sjkunz public:
120*993229b6Sjkunz 	typedef std::vector<Operation*> operation_list_t;	//!< Type for a list of operation objects.
121*993229b6Sjkunz 	typedef operation_list_t::iterator iterator_t;	//!< Iterator over operations.
122*993229b6Sjkunz 	typedef operation_list_t::const_iterator const_iterator_t;	//!< Const iterator over operations.
123*993229b6Sjkunz 
124*993229b6Sjkunz public:
125*993229b6Sjkunz 	//! \brief Default constructor.
OperationSequence()126*993229b6Sjkunz 	OperationSequence() {}
127*993229b6Sjkunz 
128*993229b6Sjkunz 	//! \brief Constructor. Makes a one-element sequence from \a soleElement.
OperationSequence(Operation * soleElement)129*993229b6Sjkunz 	OperationSequence(Operation * soleElement) { m_operations.push_back(soleElement); }
130*993229b6Sjkunz 
131*993229b6Sjkunz 	//! \brief Destructor.
132*993229b6Sjkunz 	virtual ~OperationSequence();
133*993229b6Sjkunz 
134*993229b6Sjkunz 	//! \name Iterators
135*993229b6Sjkunz 	//@{
begin()136*993229b6Sjkunz 	inline iterator_t begin() { return m_operations.begin(); }
begin()137*993229b6Sjkunz 	inline const_iterator_t begin() const { return m_operations.begin(); }
end()138*993229b6Sjkunz 	inline iterator_t end() { return m_operations.end(); }
end()139*993229b6Sjkunz 	inline const_iterator_t end() const { return m_operations.end(); }
140*993229b6Sjkunz 	//@}
141*993229b6Sjkunz 
142*993229b6Sjkunz 	inline Operation * operator [] (unsigned index) const { return m_operations[index]; }
143*993229b6Sjkunz 
144*993229b6Sjkunz 	//! \name Status
145*993229b6Sjkunz 	//@{
146*993229b6Sjkunz 	//! \brief Returns the number of operations in the sequence.
getCount()147*993229b6Sjkunz 	inline unsigned getCount() const { return m_operations.size(); }
148*993229b6Sjkunz 	//@}
149*993229b6Sjkunz 
150*993229b6Sjkunz 	//! \name Operations
151*993229b6Sjkunz 	//@{
152*993229b6Sjkunz 	//! \brief Append one operation object to the sequence.
append(Operation * op)153*993229b6Sjkunz 	inline void append(Operation * op) { m_operations.push_back(op); }
154*993229b6Sjkunz 
155*993229b6Sjkunz 	//! \brief Append the contents of \a other onto this sequence.
156*993229b6Sjkunz 	void append(const OperationSequence * other);
157*993229b6Sjkunz 
158*993229b6Sjkunz 	//! \brief Appends \a other onto this sequence.
159*993229b6Sjkunz 	OperationSequence & operator += (const OperationSequence * other) { append(other); return *this; }
160*993229b6Sjkunz 	//@}
161*993229b6Sjkunz 
162*993229b6Sjkunz protected:
163*993229b6Sjkunz 	operation_list_t m_operations;	//!< The list of operations.
164*993229b6Sjkunz };
165*993229b6Sjkunz 
166*993229b6Sjkunz }; // namespace elftosb
167*993229b6Sjkunz 
168*993229b6Sjkunz #endif // _Operation_h_
169