From 18faf6ae040541c5e301a712f12bb92542fccf82 Mon Sep 17 00:00:00 2001 From: Mike Leach Date: Thu, 17 Dec 2020 15:08:36 +0000 Subject: opencsd: ete: Handle NSE bit in ETE for PE that have FEAT_RME FEAT_RME (realms) adds a NSE bit to context packets to add security states root and realm. This adds support for this new bit. Assumes that the NSE bit is guaranteed to RAZ for any device that does not have the feature. Signed-off-by: Mike Leach --- decoder/include/opencsd/etmv4/trc_pkt_elem_etmv4i.h | 5 +++-- decoder/include/opencsd/etmv4/trc_pkt_types_etmv4.h | 1 + decoder/include/opencsd/ocsd_if_types.h | 6 ++++-- decoder/source/etmv4/trc_pkt_decode_etmv4i.cpp | 5 ++++- decoder/source/etmv4/trc_pkt_proc_etmv4i.cpp | 2 +- decoder/source/trc_gen_elem.cpp | 9 ++++++++- 6 files changed, 21 insertions(+), 7 deletions(-) (limited to 'decoder') diff --git a/decoder/include/opencsd/etmv4/trc_pkt_elem_etmv4i.h b/decoder/include/opencsd/etmv4/trc_pkt_elem_etmv4i.h index 8ee7087..22f39d9 100644 --- a/decoder/include/opencsd/etmv4/trc_pkt_elem_etmv4i.h +++ b/decoder/include/opencsd/etmv4/trc_pkt_elem_etmv4i.h @@ -145,7 +145,7 @@ public: void setCondRF3(const uint16_t tokens); void setCondRF4(const uint8_t token); - void setContextInfo(const bool update, const uint8_t EL = 0, const uint8_t NS = 0, const uint8_t SF = 0); + void setContextInfo(const bool update, const uint8_t EL = 0, const uint8_t NS = 0, const uint8_t SF = 0, const uint8_t NSE = 0); void setContextVMID(const uint32_t VMID); void setContextCID(const uint32_t CID); @@ -416,7 +416,7 @@ inline void EtmV4ITrcPacket::setCondRF4(const uint8_t token) cond_result.f2f4_token = token; } -inline void EtmV4ITrcPacket::setContextInfo(const bool update, const uint8_t EL, const uint8_t NS, const uint8_t SF) +inline void EtmV4ITrcPacket::setContextInfo(const bool update, const uint8_t EL, const uint8_t NS, const uint8_t SF, const uint8_t NSE) { pkt_valid.bits.context_valid = 1; if(update) @@ -425,6 +425,7 @@ inline void EtmV4ITrcPacket::setContextInfo(const bool update, const uint8_t EL, context.EL = EL; context.NS = NS; context.SF = SF; + context.NSE = NSE; } } diff --git a/decoder/include/opencsd/etmv4/trc_pkt_types_etmv4.h b/decoder/include/opencsd/etmv4/trc_pkt_types_etmv4.h index dd241a0..38963d1 100644 --- a/decoder/include/opencsd/etmv4/trc_pkt_types_etmv4.h +++ b/decoder/include/opencsd/etmv4/trc_pkt_types_etmv4.h @@ -184,6 +184,7 @@ typedef struct _etmv4_context_t { uint32_t updated:1; //!< updated this context packet (otherwise same as last time) uint32_t updated_c:1; //!< updated CtxtID uint32_t updated_v:1; //!< updated VMID + uint32_t NSE:1; //!< PE FEAT_RME: root / realm indicator }; uint32_t ctxtID; //!< Current ctxtID uint32_t VMID; //!< current VMID diff --git a/decoder/include/opencsd/ocsd_if_types.h b/decoder/include/opencsd/ocsd_if_types.h index 5628fec..f5ff6ac 100644 --- a/decoder/include/opencsd/ocsd_if_types.h +++ b/decoder/include/opencsd/ocsd_if_types.h @@ -338,8 +338,10 @@ typedef enum _ocsd_isa */ typedef enum _ocsd_sec_level { - ocsd_sec_secure, /**< Core is in secure state */ - ocsd_sec_nonsecure /**< Core is in non-secure state */ + ocsd_sec_secure, /**< Core is in secure state */ + ocsd_sec_nonsecure, /**< Core is in non-secure state */ + ocsd_sec_root, /**< PE FEAT_RME: Core is in root state. */ + ocsd_sec_realm, /**< PE FEAT_RME: Core is in realm state. */ } ocsd_sec_level ; /** Exception level type diff --git a/decoder/source/etmv4/trc_pkt_decode_etmv4i.cpp b/decoder/source/etmv4/trc_pkt_decode_etmv4i.cpp index 87f7f43..a9b059a 100644 --- a/decoder/source/etmv4/trc_pkt_decode_etmv4i.cpp +++ b/decoder/source/etmv4/trc_pkt_decode_etmv4i.cpp @@ -1872,7 +1872,10 @@ void TrcPktDecodeEtmV4I::updateContext(TrcStackElemCtxt *pCtxtElem, OcsdTraceEle m_is_64bit = (ctxt.SF != 0); elem.context.bits64 = ctxt.SF; m_is_secure = (ctxt.NS == 0); - elem.context.security_level = ctxt.NS ? ocsd_sec_nonsecure : ocsd_sec_secure; + if (ctxt.NSE) + elem.context.security_level = ctxt.NS ? ocsd_sec_realm : ocsd_sec_root; + else + elem.context.security_level = ctxt.NS ? ocsd_sec_nonsecure : ocsd_sec_secure; elem.context.exception_level = (ocsd_ex_level)ctxt.EL; elem.context.el_valid = 1; if(ctxt.updated_c) diff --git a/decoder/source/etmv4/trc_pkt_proc_etmv4i.cpp b/decoder/source/etmv4/trc_pkt_proc_etmv4i.cpp index 07b372c..0abb605 100644 --- a/decoder/source/etmv4/trc_pkt_proc_etmv4i.cpp +++ b/decoder/source/etmv4/trc_pkt_proc_etmv4i.cpp @@ -872,7 +872,7 @@ void TrcPktProcEtmV4I::extractAndSetContextInfo(const std::vector &buff // on input, buffer index points at the info byte - always present uint8_t infoByte = m_currPacketData[st_idx]; - m_curr_packet.setContextInfo(true, (infoByte & 0x3), (infoByte >> 5) & 0x1, (infoByte >> 4) & 0x1); + m_curr_packet.setContextInfo(true, (infoByte & 0x3), (infoByte >> 5) & 0x1, (infoByte >> 4) & 0x1, (infoByte >> 3) & 0x1); // see if there are VMID and CID bytes, and how many. int nVMID_bytes = ((infoByte & 0x40) == 0x40) ? (m_config.vmidSize()/8) : 0; diff --git a/decoder/source/trc_gen_elem.cpp b/decoder/source/trc_gen_elem.cpp index 4c09945..b2e6772 100644 --- a/decoder/source/trc_gen_elem.cpp +++ b/decoder/source/trc_gen_elem.cpp @@ -171,7 +171,14 @@ void OcsdTraceElement::toString(std::string &str) const { oss << "EL" << std::dec << (int)(context.exception_level); } - oss << (context.security_level == ocsd_sec_secure ? "S; " : "N; ") << (context.bits64 ? "64-bit; " : "32-bit; "); + switch (context.security_level) + { + case ocsd_sec_secure: oss << "S; "; break; + case ocsd_sec_nonsecure: oss << "N; "; break; + case ocsd_sec_root: oss << "Root; "; break; + case ocsd_sec_realm: oss << "Realm; "; break; + } + oss << (context.bits64 ? "64-bit; " : "32-bit; "); if(context.vmid_valid) oss << "VMID=0x" << std::hex << context.vmid << "; "; if(context.ctxt_id_valid) -- cgit v1.2.3