22
33Reference guide for built-in functions available when compiling OVSM to Solana sBPF bytecode.
44
5- ** Version:** 1.0.5
6- ** Last Updated:** 2025-11-25
5+ ** Version:** 1.0.7
6+ ** Last Updated:** 2025-11-27
77** Tested On:** Solana Devnet
88
99---
@@ -13,13 +13,15 @@ Reference guide for built-in functions available when compiling OVSM to Solana s
13131 . [ Overview] ( #overview )
14142 . [ Account Access Functions] ( #account-access-functions )
15153 . [ Memory Operations] ( #memory-operations )
16- 4 . [ Logging Syscalls] ( #logging-syscalls )
17- 5 . [ Control Flow] ( #control-flow )
18- 6 . [ Arithmetic Operations] ( #arithmetic-operations )
19- 7 . [ Comparison Operations] ( #comparison-operations )
20- 8 . [ Built-in Variables] ( #built-in-variables )
21- 9 . [ Complete Examples] ( #complete-examples )
22- 10 . [ Solana Account Memory Layout] ( #solana-account-memory-layout )
16+ 4 . [ Instruction Data] ( #instruction-data )
17+ 5 . [ Cross-Program Invocation (CPI)] ( #cross-program-invocation-cpi )
18+ 6 . [ Logging Syscalls] ( #logging-syscalls )
19+ 7 . [ Control Flow] ( #control-flow )
20+ 8 . [ Arithmetic Operations] ( #arithmetic-operations )
21+ 9 . [ Comparison Operations] ( #comparison-operations )
22+ 10 . [ Built-in Variables] ( #built-in-variables )
23+ 11 . [ Complete Examples] ( #complete-examples )
24+ 12 . [ Solana Account Memory Layout] ( #solana-account-memory-layout )
2325
2426---
2527
@@ -280,6 +282,131 @@ Low-level memory access for reading/writing account data.
280282
281283---
282284
285+ ## Instruction Data
286+
287+ Functions for accessing instruction data passed to your program.
288+
289+ ### ` instruction-data-len `
290+
291+ ** Signature:** ` (instruction-data-len) `
292+ ** Description:** Get the length of instruction data in bytes
293+ ** Returns:** u64 - Number of bytes of instruction data
294+ ** Tested:** ✅ Verified on devnet
295+
296+ ``` lisp
297+ ;; Check if we have enough instruction data
298+ (if (>= (instruction-data-len) 8)
299+ (sol_log_ "Got enough data")
300+ (sol_log_ "Need at least 8 bytes"))
301+ ```
302+
303+ ---
304+
305+ ### ` instruction-data-ptr `
306+
307+ ** Signature:** ` (instruction-data-ptr) `
308+ ** Description:** Get pointer to instruction data buffer
309+ ** Returns:** u64 - Pointer to instruction data
310+ ** Tested:** ✅ Verified on devnet
311+
312+ ``` lisp
313+ ;; Read first 8 bytes as u64 from instruction data
314+ (define amount (mem-load (instruction-data-ptr) 0))
315+ (sol_log_ "Amount from instruction:")
316+ (sol_log_64_ amount)
317+ ```
318+
319+ ---
320+
321+ ## Cross-Program Invocation (CPI)
322+
323+ Functions for calling other Solana programs from your OVSM program.
324+
325+ > ** Note:** CPI currently has a known issue with heap address loading. The functions compile and deploy correctly, but may fail at runtime due to register spilling of large constant addresses. This is being actively fixed.
326+
327+ ### ` system-transfer `
328+
329+ ** Signature:** ` (system-transfer src_idx dest_idx amount) `
330+ ** Description:** Transfer SOL from one account to another via System Program CPI
331+ ** Parameters:**
332+ - ` src_idx ` - Account index of source (must be signer)
333+ - ` dest_idx ` - Account index of destination
334+ - ` amount ` - Lamports to transfer
335+ ** Returns:** u64 - 0 on success, error code on failure
336+ ** Status:** ⚠️ Compiles but runtime issue pending fix
337+
338+ ``` lisp
339+ ;; Transfer 0.001 SOL from account 0 to account 1
340+ (define result (system-transfer 0 1 1000000))
341+ (if (= result 0)
342+ (sol_log_ "Transfer successful!")
343+ (sol_log_ "Transfer failed"))
344+ ```
345+
346+ ---
347+
348+ ### ` invoke `
349+
350+ ** Signature:** ` (invoke instruction-ptr account-infos-ptr num-accounts) `
351+ ** Description:** Low-level CPI for calling any program with custom instruction
352+ ** Parameters:**
353+ - ` instruction-ptr ` - Pointer to SolInstruction struct (40 bytes)
354+ - ` account-infos-ptr ` - Pointer to account infos array
355+ - ` num-accounts ` - Number of accounts
356+ ** Returns:** u64 - 0 on success, error code on failure
357+ ** Status:** ⚠️ Advanced use - requires manual struct building
358+
359+ ``` lisp
360+ ;; For advanced users who build their own instruction structures
361+ (define result (invoke instr-ptr accts-ptr 2))
362+ ```
363+
364+ ---
365+
366+ ### ` invoke-signed `
367+
368+ ** Signature:** ` (invoke-signed instr-ptr acct-infos-ptr num-accts signers-seeds-ptr num-signers) `
369+ ** Description:** PDA-signed CPI for program-derived address signing
370+ ** Parameters:**
371+ - ` instr-ptr ` - Pointer to SolInstruction struct
372+ - ` acct-infos-ptr ` - Pointer to account infos
373+ - ` num-accts ` - Number of accounts
374+ - ` signers-seeds-ptr ` - Pointer to signer seeds array
375+ - ` num-signers ` - Number of PDA signers
376+ ** Returns:** u64 - 0 on success, error code on failure
377+ ** Status:** ⚠️ Advanced use - requires PDA seed setup
378+
379+ ---
380+
381+ ### CPI Data Structures Reference
382+
383+ When building custom CPI instructions, use these memory layouts:
384+
385+ ** SolInstruction (40 bytes):**
386+ ```
387+ +0: u64 program_id_ptr ; Pointer to 32-byte program ID
388+ +8: u64 accounts_ptr ; Pointer to SolAccountMeta array
389+ +16: u64 account_len ; Number of accounts
390+ +24: u64 data_ptr ; Pointer to instruction data
391+ +32: u64 data_len ; Length of instruction data
392+ ```
393+
394+ ** SolAccountMeta (16 bytes):**
395+ ```
396+ +0: u64 pubkey_ptr ; Pointer to 32-byte pubkey
397+ +8: u8 is_writable ; 1 if writable, 0 otherwise
398+ +9: u8 is_signer ; 1 if signer, 0 otherwise
399+ +10: padding (6 bytes)
400+ ```
401+
402+ ** System Program Transfer Instruction Data (12 bytes):**
403+ ```
404+ +0: u32 instruction_index ; 2 for Transfer
405+ +4: u64 lamports ; Amount to transfer
406+ ```
407+
408+ ---
409+
283410## Logging Syscalls
284411
285412Functions for logging to Solana program logs.
0 commit comments