<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://linux-kvm.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Eunice</id>
	<title>KVM - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://linux-kvm.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Eunice"/>
	<link rel="alternate" type="text/html" href="https://linux-kvm.org/page/Special:Contributions/Eunice"/>
	<updated>2026-04-22T00:35:34Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.5</generator>
	<entry>
		<id>https://linux-kvm.org/index.php?title=PowerPC_Hypercall_ABI&amp;diff=4507</id>
		<title>PowerPC Hypercall ABI</title>
		<link rel="alternate" type="text/html" href="https://linux-kvm.org/index.php?title=PowerPC_Hypercall_ABI&amp;diff=4507"/>
		<updated>2012-02-16T03:30:44Z</updated>

		<summary type="html">&lt;p&gt;Eunice: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Embedded Hypervisor ABI (draft) =&lt;br /&gt;
&lt;br /&gt;
The Embedded Hypervisor workgroup decided to use a BEAT style ABI.&lt;br /&gt;
&lt;br /&gt;
== Hypercall Instruction ==&lt;br /&gt;
&lt;br /&gt;
The hypercall instruction on legacy Book E implementations shall be the pattern 0x44000022 (SC with LEVEL=1).&lt;br /&gt;
&lt;br /&gt;
Programming Note: When running on implementations which implement the &amp;quot;embedded hypervisor&amp;quot; architecture, the guest or host may replace the guest hypercall instructions with the architecturally defined hypercall instruction at runtime.&lt;br /&gt;
&lt;br /&gt;
== Parameter Passing ==&lt;br /&gt;
&lt;br /&gt;
The hypercall number shall be contained in &#039;&#039;r11&#039;&#039; (like system calls in BEAT ABIs).&lt;br /&gt;
&lt;br /&gt;
Input parameters shall be contained in &#039;&#039;r3&#039;&#039; through &#039;&#039;r10&#039;&#039;, inclusive.&lt;br /&gt;
&lt;br /&gt;
Hypercalls shall return a success code and place this value in &#039;&#039;r3&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Further output parameters shall be contained in &#039;&#039;r4&#039;&#039; through &#039;&#039;r11&#039;&#039;, inclusive.&lt;br /&gt;
&lt;br /&gt;
If more data must be transferred in either direction in a single hypercall, that data must be placed into memory, and that must be specified by the hypercall API (the ABI does not define this behavior).&lt;br /&gt;
&lt;br /&gt;
=== Summary of Register Usage ===&lt;br /&gt;
&lt;br /&gt;
Contents of registers that are considered &amp;quot;Volatile&amp;quot; &#039;&#039;will not&#039;&#039; be preserved across a hypercall invocation:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
! Register &lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| r0 &lt;br /&gt;
| Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| r1-r2 &lt;br /&gt;
| Non-Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| r3 &lt;br /&gt;
| Volatile input parameter and return value &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| r4 - r10 &lt;br /&gt;
| Volatile input parameters and output values &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| r11 &lt;br /&gt;
| Hypercall Token and output value &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| r12 &lt;br /&gt;
| Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| r13 - r31 &lt;br /&gt;
| Non-Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| LR &lt;br /&gt;
| Non-Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| CTR &lt;br /&gt;
| Non-Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| XER &lt;br /&gt;
| Non-Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| CR2-CR4 Fields &lt;br /&gt;
| Non-Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| Remaining CR fields &lt;br /&gt;
| Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| Other Registers &lt;br /&gt;
| Non-Volatile &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Contents of registers that are considered &amp;quot;Non-Volatile&amp;quot; &#039;&#039;shall&#039;&#039; be preserved across hypercalls.&lt;br /&gt;
&lt;br /&gt;
/!\ The content of non-volatile registers must be completely preserved, regardless of the size the register and the state of the processor at the time of hypercall invocation. For example, all 64 bits of a 64-bit register must be preserved even if MSR[SF] or MSR[CM] specifies 32-bit mode.&lt;br /&gt;
&lt;br /&gt;
== TODO ==&lt;br /&gt;
&lt;br /&gt;
Endianness&lt;br /&gt;
&lt;br /&gt;
= Background =&lt;br /&gt;
&lt;br /&gt;
== Introduction to Hypervisor Calls ==&lt;br /&gt;
This page describes the existing hcall ABI defined by the various Hypervisors available for the PowerPC platform.&lt;br /&gt;
&lt;br /&gt;
Known Hypervisor `hcall()` ABIs are:&lt;br /&gt;
# PAPR ABI, as used by IBM PHYP Hypervisor and Xen on POWER&lt;br /&gt;
# BEAT ABI, as used by Toshiba CellEB&lt;br /&gt;
# PS3 ABI, as used by Sony PS3&lt;br /&gt;
&lt;br /&gt;
== The Hypervisor Call Mechanism ==&lt;br /&gt;
Calls to the hypervisor layer are performed by executing an instruction that causes an exception, in much the same way as a Unix System Call is performed.  The first argument is a token that designates that actual function to perform.  The remaining arguments and there interpretation is specific to the function of the `hcall()`.&lt;br /&gt;
&lt;br /&gt;
The `hcall` function depends on an instruction that can &amp;quot;trap&amp;quot; to the hypervisor to [http://www.vivaessays.com/buy-essay.html buy essays online].&lt;br /&gt;
Some chip implementations have a modified system call (LEVEL=1) that traps directly to the processor mode that the hypervisor runs in.  In the case where the there the processor does not have this special form it is suggest that the system call instruction is used where `r0` is `-1`.&lt;br /&gt;
&lt;br /&gt;
The definition for HSC is as follows:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 #ifdef SC_LEVEL&lt;br /&gt;
 #define HSC    .long 0x44000022  /* SC with LEVEL=1 */&lt;br /&gt;
 #elseif&lt;br /&gt;
 #define HSC    li r0,-1; sc&lt;br /&gt;
 #endif&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/!\ In order to safely use `r0` the `hcall` definition must have &#039;&#039;&#039;full binding&#039;&#039;&#039; and &#039;&#039;&#039;not&#039;&#039;&#039; be inlined.  This way the ABI shall guarantee the volatility of `r0`.&lt;br /&gt;
&lt;br /&gt;
=== C Language Calling Convention ===&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
	int hcall_func(unsigned long opcode, unsigned long ret[], unsigned long arg&amp;lt;n&amp;gt;, ...)&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/!\ Assumes that unsigned long contains the same number of bit as a `GPR`&lt;br /&gt;
&lt;br /&gt;
* `ret[]`, This is an array of return values that the `hcall_func()` gives back to the caller.&lt;br /&gt;
&lt;br /&gt;
* `arg&amp;lt;n&amp;gt;`, The input arguments where `n` is 1 thru 8.&lt;br /&gt;
&lt;br /&gt;
=== Example Usage ===&lt;br /&gt;
The following is a C function using a C language binding for an `hcall`&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 void&lt;br /&gt;
 example(unsigned long arg1, unsigned long arg2)&lt;br /&gt;
 {&lt;br /&gt;
        int rc;&lt;br /&gt;
        unsigned long results[2];&lt;br /&gt;
 &lt;br /&gt;
        rc = hcall_ex(results, arg1, arg2);&lt;br /&gt;
        if (rc != H_Success) {&lt;br /&gt;
                ... Failure Case ...&lt;br /&gt;
        }&lt;br /&gt;
        ... return values are in results array ...&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PAPR ABI ==&lt;br /&gt;
&lt;br /&gt;
The PAPR Spec is available thru [http://www.OutdoorFountains.com Outdoor Fountains] [http://seoph2.cafe24.com/wordpress SEO Blog Philippines] [http://power.org Power.org]. &lt;br /&gt;
&lt;br /&gt;
=== Inputs ===&lt;br /&gt;
The PAPR ABI expects when the call is placed requires the &#039;&#039;&#039;token&#039;&#039;&#039; for the specific `hcall` to be place in `r3`, the remaining parameters for the `hcall` occupy `r4` thru `r11`.&lt;br /&gt;
&lt;br /&gt;
=== Outputs ===&lt;br /&gt;
Upon completion of the `hcall`, a return code indicating status will be placed `r3` and subsequent registers `r4` thru `r11` will contain additional returned values if any.&lt;br /&gt;
&lt;br /&gt;
=== Volatile State ===&lt;br /&gt;
The native function calling ABI is respected with respect to non-volatiles and typically guarantees extra non-volatiles, specifically:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
! Register &lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| r0-r1 &lt;br /&gt;
| Non-Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| r3 &lt;br /&gt;
| Volatile parameter and return value for status &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| r4 - r11 &lt;br /&gt;
| Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| r12 &lt;br /&gt;
| Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| r13 - r31 &lt;br /&gt;
| Non-Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| LR &lt;br /&gt;
| Non-Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| CTR &lt;br /&gt;
| Non-Volatile &lt;br /&gt;
|&lt;br /&gt;
&lt;br /&gt;
| XER &lt;br /&gt;
| Non-Volatile &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| CR0-CR7 &lt;br /&gt;
| Non-Volatile &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
(!) Xen `hcall()s` that are not inherited from the PAPR continue to use `r3` for return code but use memory references for additional return information. :o&lt;br /&gt;
&lt;br /&gt;
=== Example Definition ===&lt;br /&gt;
&lt;br /&gt;
Example of creating a C callable function that perform an `hcall()` called `H_EX` for PowerPC 64 bit ELF ABI:&lt;br /&gt;
&lt;br /&gt;
==== hcall_ex_64.s ====&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        .align 3&lt;br /&gt;
        .globl hcall_ex&lt;br /&gt;
        # Insert ABI specific instruction to make symbol callable by C hcall_ex:&lt;br /&gt;
        std     r3,-8(1)   # r3 (array of values) stored in stack&lt;br /&gt;
        li      r3,H_EX    # load r3 with hypervisor code&lt;br /&gt;
        HSC                # Hypervisor Trap&lt;br /&gt;
        ld      r12,-8(1)  # reload array into r12&lt;br /&gt;
        cmpi    0,12,0     # only store return regs if array is non-NULL&lt;br /&gt;
        bne     ret2       # this hcall() only returns contents of r4,r5&lt;br /&gt;
        blr                # return no values&lt;br /&gt;
 &lt;br /&gt;
 ret8:   std r11,(7 * 8)(r12)&lt;br /&gt;
 ret7:   std r10,(6 * 8)(r12)&lt;br /&gt;
 ret6:   std r9,(5 * 8)(r12)&lt;br /&gt;
 ret5:   std r8,(4 * 8)(r12)&lt;br /&gt;
 ret4:   std r7,(3 * 8)(r12)&lt;br /&gt;
 ret3:   std r6,(2 * 8)(r12)&lt;br /&gt;
 ret2:   std r5,(1 * 8)(r12)&lt;br /&gt;
 ret1:   std r4,(0 * 8)(r12)&lt;br /&gt;
        blr&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(!) 32-bit variant of this function would use `lwz` and `stw`&lt;br /&gt;
/!\ `r11` on the hypervisor side will require to be placed in the stack when switching back to C, please see the PowerPC ELF ABI for details&lt;br /&gt;
&lt;br /&gt;
== BEAT ABI ==&lt;br /&gt;
The BEAT ABI is used by CellEB Hypervisor from Toshiba&lt;br /&gt;
&lt;br /&gt;
=== Inputs ===&lt;br /&gt;
The BEAT ABI expects when the call is placed requires the &#039;&#039;&#039;token&#039;&#039;&#039; for the specific `hcall` to be place in `r11`, the remaining parameters for the `hcall` occupy `r3` thru `r10`.&lt;br /&gt;
&lt;br /&gt;
=== Outputs ===&lt;br /&gt;
Upon completion of the `hcall`, a return code indicating status will be placed `r3` and subsequent registers `r4` thru `r11` will contain additional returned values if any.&lt;br /&gt;
&lt;br /&gt;
=== Volatile State ===&lt;br /&gt;
The native function calling ABI is respected with respect to non-volatiles and typically guarantees extra non-volatiles, specifically:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
! Register &lt;br /&gt;
! Description &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== PS3 ABI ==&lt;br /&gt;
The PS3 ABI is used by Playstation 3 Hypervisor from Sony&lt;br /&gt;
&lt;br /&gt;
=== Inputs ===&lt;br /&gt;
The BEAT ABI expects when the call is placed requires the &#039;&#039;&#039;token&#039;&#039;&#039; for the specific `hcall` to be place in `r11`, the remaining parameters for the `hcall` occupy `r3` thru `r10`.&lt;br /&gt;
&lt;br /&gt;
=== Outputs ===&lt;br /&gt;
Upon completion of the `hcall`, a return code indicating status will be placed `r3` and subsequent registers `r4` thru `r11` will contain additional returned values if any.&lt;br /&gt;
&lt;br /&gt;
=== Volatile State ===&lt;br /&gt;
The native function calling ABI is [https://www.cafe24.com/reseller/resellerCreate.html signup Cafe24] respected with respect to non-volatiles and typically guarantees extra non-volatiles, specifically:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
! Register &lt;br /&gt;
! Description &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Category:PowerPC]]&lt;/div&gt;</summary>
		<author><name>Eunice</name></author>
	</entry>
</feed>