[RISC-V] Implement ThisPtrRetBufPrecode::Init (#91451)
authorDong-Heon Jung <clamp03@gmail.com>
Mon, 4 Sep 2023 00:47:49 +0000 (09:47 +0900)
committerGleb Balykov <g.balykov@samsung.com>
Fri, 15 Dec 2023 12:28:32 +0000 (15:28 +0300)
src/coreclr/vm/riscv64/cgencpu.h
src/coreclr/vm/riscv64/stubs.cpp

index 8ed6fbc..0d98092 100644 (file)
@@ -425,7 +425,7 @@ struct HijackArgs
 // Precode to shuffle this and retbuf for closed delegates over static methods with return buffer
 struct ThisPtrRetBufPrecode {
 
-    static const int Type = 0x2;
+    static const int Type = 0x93;
 
     UINT32  m_rgCode[6];
     TADDR   m_pTarget;
index 81e344f..baa7227 100644 (file)
@@ -476,7 +476,23 @@ void HelperMethodFrame::UpdateRegDisplay(const PREGDISPLAY pRD)
 #ifndef DACCESS_COMPILE
 void ThisPtrRetBufPrecode::Init(MethodDesc* pMD, LoaderAllocator *pLoaderAllocator)
 {
-    _ASSERTE(!"RISCV64: not implementation on riscv64!!!");
+    WRAPPER_NO_CONTRACT;
+
+    //Initially
+    //a0 -This ptr
+    //a1 -ReturnBuffer
+    m_rgCode[0] = 0x00050f93; // addi  t6, a0, 0x0
+    m_rgCode[1] = 0x00058513; // addi  a0, a1, 0x0
+    m_rgCode[2] = 0x000f8593; // addi  a1, t6, 0x0
+    m_rgCode[3] = 0x00000f97; // auipc t6, 0
+    m_rgCode[4] = 0x00cfbf83; // ld    t6, 12(t6)
+    m_rgCode[5] = 0x000f8067; // jalr  x0, 0(t6)
+
+    _ASSERTE((UINT32*)&m_pTarget == &m_rgCode[6]);
+    _ASSERTE(6 == ARRAY_SIZE(m_rgCode));
+
+    m_pTarget = GetPreStubEntryPoint();
+    m_pMethodDesc = (TADDR)pMD;
 }
 
 #endif // !DACCESS_COMPILE