// Copyright Advanced Micro Devices, Inc., or its affiliates. // SPDX-License-Identifier: MIT #include #include #include #include namespace rocRoller { CrashKernelGenerator::CrashKernelGenerator(ContextPtr context) : m_context(context) { } CrashKernelGenerator::~CrashKernelGenerator() = default; Generator CrashKernelGenerator::generateCrashSequence(AssertOpKind assertOpKind) { switch(assertOpKind) { case AssertOpKind::MemoryViolation: { auto context = m_context.lock(); co_yield writeToNullPtr(); co_yield Instruction::Wait( WaitCount::Zero(context->targetArchitecture(), "DEBUG: Wait after memory write")); } break; case AssertOpKind::STrap: co_yield sTrap(); break; case AssertOpKind::NoOp: Throw("Unexpected AssertOpKind::NoOp"); default: Throw("Unknown AssertOpKind"); } } Generator rocRoller::CrashKernelGenerator::writeToNullPtr() { auto context = m_context.lock(); auto invalidAddr = std::make_shared( context, Register::Type::Vector, DataType::Int64, 1); co_yield context->copier()->copy(invalidAddr, Register::Value::Literal(0L)); auto dummyData = std::make_shared( context, Register::Type::Vector, DataType::Int32, 1); co_yield context->copier()->copy(dummyData, Register::Value::Literal(42)); co_yield context->mem()->storeGlobal(invalidAddr, dummyData, /*offset*/ 0, /*numBytes*/ 4); } Generator CrashKernelGenerator::sTrap() { auto context = m_context.lock(); auto trapID = Register::Value::Literal(0x02); co_yield_(Instruction("s_trap", {}, {trapID}, {}, "")); } }