2 * \file ocsd_pe_context.h
3 * \brief OpenCSD : Wrapper class for PE context
5 * \copyright Copyright (c) 2016, ARM Limited. All Rights Reserved.
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * 3. Neither the name of the copyright holder nor the names of its contributors
20 * may be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef ARM_OCSD_PE_CONTEXT_H_INCLUDED
35 #define ARM_OCSD_PE_CONTEXT_H_INCLUDED
37 #include "opencsd/ocsd_if_types.h"
39 /*! @class OcsdPeContext
40 * @brief Handler for the ocsd_pe_context structure.
42 * Reads and writes structure values, enforcing interaction rules between values
49 OcsdPeContext(const ocsd_pe_context *context);
52 OcsdPeContext &operator =(const OcsdPeContext &ctxt);
53 OcsdPeContext &operator =(const ocsd_pe_context *context);
57 void setSecLevel(const ocsd_sec_level sl) { m_context.security_level = sl; };
58 void setEL(const ocsd_ex_level el) { m_context.exception_level = el; m_context.el_valid = el > ocsd_EL_unknown ? 1 : 0; };
59 void setCtxtID(const uint32_t id) { m_context.context_id = id; m_context.ctxt_id_valid = 1; };
60 void setVMID(const uint32_t id) { m_context.vmid = id; m_context.vmid_valid = 1; };
61 void set64bit(const bool is64bit) { m_context.bits64 = is64bit ? 1 : 0; };
63 const ocsd_sec_level getSecLevel() const { return m_context.security_level; };
64 const ocsd_ex_level getEL() const { return m_context.exception_level; };
65 const bool ELvalid() const { return (m_context.el_valid == 1); };
66 const uint32_t getCtxtID() const { return (m_context.ctxt_id_valid == 1) ? m_context.context_id : 0; };
67 const bool ctxtIDvalid() const { return (m_context.ctxt_id_valid == 1); };
68 const uint32_t getVMID() const { return (m_context.vmid_valid == 1) ? m_context.vmid : 0; };
69 const bool VMIDvalid() const { return (m_context.vmid_valid == 1); };
71 // only allow an immutable copy of the structure out to C-API land.
72 operator const ocsd_pe_context &() const { return m_context; };
75 ocsd_pe_context m_context;
78 inline OcsdPeContext::OcsdPeContext()
83 inline OcsdPeContext::OcsdPeContext(const ocsd_pe_context *context)
88 inline void OcsdPeContext::resetCtxt()
90 // initialise the context
92 m_context.context_id = 0;
93 m_context.ctxt_id_valid = 0;
94 m_context.el_valid = 0;
95 m_context.exception_level = ocsd_EL_unknown;
96 m_context.security_level = ocsd_sec_secure;
98 m_context.vmid_valid = 0;
101 inline OcsdPeContext & OcsdPeContext::operator =(const OcsdPeContext &ctxt)
107 inline OcsdPeContext & OcsdPeContext::operator =(const ocsd_pe_context *context)
109 m_context = *context;
114 #endif // ARM_OCSD_PE_CONTEXT_H_INCLUDED
116 /* End of File ocsd_pe_context.h */