'From Squeak5.3 of 12 May 2022 [latest update: #19481] on 31 July 2022 at 3:49:31 pm'!

!FFICallbackThunk methodsFor: 'private-instance initalization' stamp: 'KenD 7/31/2022 15:09'!
initializeRiscV64
	"Initialize the receiver with a __ccall thunk.  The thunk calls thunkEntry in the Alien/IA32ABI plugin,
	 whose source is in platforms/Cross/plugins/IA32ABI/riscv64abicc.c.  thunkEntry is the entry point
	 for Callbacks. The objective of the thunk is to call thunkEntry with all arguments to the call of the
	 thunk (registers and stack) as well as a pointer to the thunk itself.  thunkEntry is as follows:
	
		long long
		thunkEntry(long x0, long x1, long x2, long x3,
				       long x4, long x5, long x6, long x7,
				       double d0, double d1, double d2, double d3,
				       double d4, double d5, double d6, double d7,
				       void *thunkpPlus20, sqIntptr_t *stackp)

	thunkEntry then collects the various arguments 
	(thunk, integer register arguments, floating-point register arguments, stack pointer) 
	in a VMCallbackContext and invokes the callback via invokeCallbackContext:."
"
  0 :	00000297        auipc	t0,0x0    Current PC = self codeAddress (start)
  4 :	1101               	addi	sp,sp,-32   reserve 4 stack slots (1 for alignment)
  6 :	e806                sd		ra,16(sp)	push Return Address
  8 :	e416                sd		t0,8(sp)	push self codeAddress
  a :	e00a                sd		sp,0(sp)	push current Stack Pointer
  c :	02828313        t1,	t0,0x28	start+0x28 is address of &entryThunk
 10:	00033383        ld		t2,0(t1)	get &entryThunk in register
 14 :	9382               	jalr		t2			Call entryThunk()
 16 :	60c2                	ld		ra,16(sp)	Restore saved Return Address
 18 :	6105               	addi	sp,sp,32	Restore Stack Pointer
 20 :	8082               	ret					Return to Mamma
 22 :	0001               	noop				--keep prefetch happy-- 
 24 : 0001				noop
 ... 
 28:   <@entryThunk>
" 
	  "NB: upper & lower instructions swapped"
	self unsignedLongLongAt:  1 put: 16rE806110100000297.  "16r0"
	self unsignedLongLongAt:  9 put: 16r02828313E00AE416.  "16r8"
	self unsignedLongLongAt: 17 put: 16r60C2938200033383. "16r10"
	self unsignedLongLongAt: 25 put: 16r0001000180826105. "16r18"
	self unsignedLongLongAt: 33 put: 16r0001000100010001. 
	self unsignedLongLongAt: 41 put: self primThunkEntryAddress.

	self

	"self newCCall"! !
