1. Introduction

October 21, 2021 ยท View on GitHub

Table of Contents

1. Introduction

This specification is specific to 64bit Intel and AMD processors conforming to the amd64 specification. Future revisions of this specification may include ARM64 conforming to the aarch64 specification as well.

1.1. Reserved Values

NameDescription
REVZreserved zero
REVIreserved ignore

1.2. Document Revision

VersionDescription
Mk#1The initial version of this specification

1.3. Glossary

AbbreviationDescription
PPPhysical Processor
VMVirtual Machine
VPVirtual Processor
VSVirtual processor State
PPIDPhysical Processor Identifier
VMIDVirtual Machine Identifier
VPIDVirtual Processor Identifier
VSIDVirtual Processor State Identifier
OSOperating System
BIOSBasic Input/Output System
UEFIUnified Extensible Firmware Interface
SPAA System Physical Address (SPA) refers to a physical address as seen by the system without the addition of virtualization
GPAA Guest Physical Address (GPA) refers to a physical address as seen by a VM and requires a translation to convert to a SPA
GVAA Guest Virtual Address (GVA) refers to a virtual address as seen by a VM and requires a guest controlled translation to convert to a GPA
Page AlignedA region of memory whose address is divisible by 0x1000
PageA page aligned region of memory that is 0x1000 bytes in size

1.4. Constants, Structures, Enumerations, and Bit Fields

1.4.1. Handle Type

The bf_handle_t structure is an opaque structure containing the handle used by most of the syscalls in this specification.

struct: bf_handle_t

NameTypeOffsetSizeDescription
hndluint64_t0x08 bytesThe handle returned by bf_handle_op_open_handle

1.4.2. Register Type

Defines which register a syscall is requesting.

1.4.2.1. AMD

enum, uint64_t: bf_reg_t

NameValueDescription
bf_reg_t_unsupported0defines the unsupported register
bf_reg_t_rbx1defines the rbx register
bf_reg_t_rcx2defines the rcx register
bf_reg_t_rdx3defines the rdx register
bf_reg_t_rbp4defines the rbp register
bf_reg_t_rsi5defines the rsi register
bf_reg_t_rdi6defines the rdi register
bf_reg_t_r87defines the r8 register
bf_reg_t_r98defines the r9 register
bf_reg_t_r109defines the r10 register
bf_reg_t_r1110defines the r11 register
bf_reg_t_r1211defines the r12 register
bf_reg_t_r1312defines the r13 register
bf_reg_t_r1413defines the r14 register
bf_reg_t_r1514defines the r15 register
bf_reg_t_intercept_cr_read15defines the intercept_cr_read register
bf_reg_t_intercept_cr_write16defines the intercept_cr_write register
bf_reg_t_intercept_dr_read17defines the intercept_dr_read register
bf_reg_t_intercept_dr_write18defines the intercept_dr_write register
bf_reg_t_intercept_exception19defines the intercept_exception register
bf_reg_t_intercept_instruction120defines the intercept_instruction1 register
bf_reg_t_intercept_instruction221defines the intercept_instruction2 register
bf_reg_t_intercept_instruction322defines the intercept_instruction3 register
bf_reg_t_pause_filter_threshold23defines the pause_filter_threshold register
bf_reg_t_pause_filter_count24defines the pause_filter_count register
bf_reg_t_iopm_base_pa25defines the iopm_base_pa register
bf_reg_t_msrpm_base_pa26defines the msrpm_base_pa register
bf_reg_t_tsc_offset27defines the tsc_offset register
bf_reg_t_guest_asid28defines the guest_asid register
bf_reg_t_tlb_control29defines the tlb_control register
bf_reg_t_virtual_interrupt_a30defines the virtual_interrupt_a register
bf_reg_t_virtual_interrupt_b31defines the virtual_interrupt_b register
bf_reg_t_exitcode32defines the exitcode register
bf_reg_t_exitinfo133defines the exitinfo1 register
bf_reg_t_exitinfo234defines the exitinfo2 register
bf_reg_t_exitininfo35defines the exitininfo register
bf_reg_t_ctls136defines the ctls1 register
bf_reg_t_avic_apic_bar37defines the avic_apic_bar register
bf_reg_t_guest_pa_of_ghcb38defines the guest_pa_of_ghcb register
bf_reg_t_eventinj39defines the eventinj register
bf_reg_t_n_cr340defines the n_cr3 register
bf_reg_t_ctls241defines the ctls2 register
bf_reg_t_vmcb_clean_bits42defines the vmcb_clean_bits register
bf_reg_t_nrip43defines the nrip register
bf_reg_t_number_of_bytes_fetched44defines the number_of_bytes_fetched register
bf_reg_t_avic_apic_backing_page_ptr45defines the avic_apic_backing_page_ptr register
bf_reg_t_avic_logical_table_ptr46defines the avic_logical_table_ptr register
bf_reg_t_avic_physical_table_ptr47defines the avic_physical_table_ptr register
bf_reg_t_vmsa_ptr48defines the vmsa_ptr register
bf_reg_t_es_selector49defines the es_selector register
bf_reg_t_es_attrib50defines the es_attrib register
bf_reg_t_es_limit51defines the es_limit register
bf_reg_t_es_base52defines the es_base register
bf_reg_t_cs_selector53defines the cs_selector register
bf_reg_t_cs_attrib54defines the cs_attrib register
bf_reg_t_cs_limit55defines the cs_limit register
bf_reg_t_cs_base56defines the cs_base register
bf_reg_t_ss_selector57defines the ss_selector register
bf_reg_t_ss_attrib58defines the ss_attrib register
bf_reg_t_ss_limit59defines the ss_limit register
bf_reg_t_ss_base60defines the ss_base register
bf_reg_t_ds_selector61defines the ds_selector register
bf_reg_t_ds_attrib62defines the ds_attrib register
bf_reg_t_ds_limit63defines the ds_limit register
bf_reg_t_ds_base64defines the ds_base register
bf_reg_t_fs_selector65defines the fs_selector register
bf_reg_t_fs_attrib66defines the fs_attrib register
bf_reg_t_fs_limit67defines the fs_limit register
bf_reg_t_fs_base68defines the fs_base register
bf_reg_t_gs_selector69defines the gs_selector register
bf_reg_t_gs_attrib70defines the gs_attrib register
bf_reg_t_gs_limit71defines the gs_limit register
bf_reg_t_gs_base72defines the gs_base register
bf_reg_t_gdtr_selector73defines the gdtr_selector register
bf_reg_t_gdtr_attrib74defines the gdtr_attrib register
bf_reg_t_gdtr_limit75defines the gdtr_limit register
bf_reg_t_gdtr_base76defines the gdtr_base register
bf_reg_t_ldtr_selector77defines the ldtr_selector register
bf_reg_t_ldtr_attrib78defines the ldtr_attrib register
bf_reg_t_ldtr_limit79defines the ldtr_limit register
bf_reg_t_ldtr_base80defines the ldtr_base register
bf_reg_t_idtr_selector81defines the idtr_selector register
bf_reg_t_idtr_attrib82defines the idtr_attrib register
bf_reg_t_idtr_limit83defines the idtr_limit register
bf_reg_t_idtr_base84defines the idtr_base register
bf_reg_t_tr_selector85defines the tr_selector register
bf_reg_t_tr_attrib86defines the tr_attrib register
bf_reg_t_tr_limit87defines the tr_limit register
bf_reg_t_tr_base88defines the tr_base register
bf_reg_t_cpl89defines the cpl register
bf_reg_t_efer90defines the efer register
bf_reg_t_cr491defines the cr4 register
bf_reg_t_cr392defines the cr3 register
bf_reg_t_cr093defines the cr0 register
bf_reg_t_dr794defines the dr7 register
bf_reg_t_dr695defines the dr6 register
bf_reg_t_rflags96defines the rflags register
bf_reg_t_rip97defines the rip register
bf_reg_t_rsp98defines the rsp register
bf_reg_t_rax99defines the rax register
bf_reg_t_star100defines the star register
bf_reg_t_lstar101defines the lstar register
bf_reg_t_cstar102defines the cstar register
bf_reg_t_fmask103defines the fmask register
bf_reg_t_kernel_gs_base104defines the kernel_gs_base register
bf_reg_t_sysenter_cs105defines the sysenter_cs register
bf_reg_t_sysenter_esp106defines the sysenter_esp register
bf_reg_t_sysenter_eip107defines the sysenter_eip register
bf_reg_t_cr2108defines the cr2 register
bf_reg_t_pat109defines the pat register
bf_reg_t_dbgctl110defines the dbgctl register
bf_reg_t_br_from111defines the br_from register
bf_reg_t_br_to112defines the br_to register
bf_reg_t_lastexcpfrom113defines the lastexcpfrom register
bf_reg_t_lastexcpto114defines the lastexcpto register
bf_reg_t_cr8115defines the cr8 register
bf_reg_t_dr0116defines the dr0 register
bf_reg_t_dr1117defines the dr1 register
bf_reg_t_dr2118defines the dr2 register
bf_reg_t_dr3119defines the dr3 register
bf_reg_t_xcr0120defines the xcr0 register
bf_reg_t_invalid121defines the invalid register

1.4.2.2. Intel

enum, uint64_t: bf_reg_t

NameValueDescription
BF_REG_T_UNSUPPORTED0defines the unsupported register
BF_REG_T_RAX1defines the rax register
BF_REG_T_RBX2defines the rbx register
BF_REG_T_RCX3defines the rcx register
BF_REG_T_RDX4defines the rdx register
BF_REG_T_RBP5defines the rbp register
BF_REG_T_RSI6defines the rsi register
BF_REG_T_RDI7defines the rdi register
BF_REG_T_R88defines the r8 register
BF_REG_T_R99defines the r9 register
BF_REG_T_R1010defines the r10 register
BF_REG_T_R1111defines the r11 register
BF_REG_T_R1212defines the r12 register
BF_REG_T_R1313defines the r13 register
BF_REG_T_R1414defines the r14 register
BF_REG_T_R1515defines the r15 register
BF_REG_T_CR216defines the cr2 register
BF_REG_T_DR617defines the dr6 register
BF_REG_T_STAR18defines the star register
BF_REG_T_LSTAR19defines the lstar register
BF_REG_T_CSTAR20defines the cstar register
BF_REG_T_FMASK21defines the fmask register
BF_REG_T_KERNEL_GS_BASE22defines the kernel_gs_base register
BF_REG_T_VIRTUAL_PROCESSOR_IDENTIFIER23defines the virtual_processor_identifier register
BF_REG_T_POSTED_INTERRUPT_NOTIFICATION_VECTOR24defines the posted_interrupt_notification_vector register
BF_REG_T_EPTP_INDEX25defines the eptp_index register
BF_REG_T_ES_SELECTOR26defines the es_selector register
BF_REG_T_CS_SELECTOR27defines the cs_selector register
BF_REG_T_SS_SELECTOR28defines the ss_selector register
BF_REG_T_DS_SELECTOR29defines the ds_selector register
BF_REG_T_FS_SELECTOR30defines the fs_selector register
BF_REG_T_GS_SELECTOR31defines the gs_selector register
BF_REG_T_LDTR_SELECTOR32defines the ldtr_selector register
BF_REG_T_TR_SELECTOR33defines the tr_selector register
BF_REG_T_INTERRUPT_STATUS34defines the interrupt_status register
BF_REG_T_PML_INDEX35defines the pml_index register
BF_REG_T_ADDRESS_OF_IO_BITMAP_A36defines the address_of_io_bitmap_a register
BF_REG_T_ADDRESS_OF_IO_BITMAP_B37defines the address_of_io_bitmap_b register
BF_REG_T_ADDRESS_OF_MSR_BITMAPS38defines the address_of_msr_bitmaps register
BF_REG_T_VMEXIT_MSR_STORE_ADDRESS39defines the vmexit_msr_store_address register
BF_REG_T_VMEXIT_MSR_LOAD_ADDRESS40defines the vmexit_msr_load_address register
BF_REG_T_VMENTRY_MSR_LOAD_ADDRESS41defines the vmentry_msr_load_address register
BF_REG_T_EXECUTIVE_VMCS_POINTER42defines the executive_vmcs_pointer register
BF_REG_T_PML_ADDRESS43defines the pml_address register
BF_REG_T_TSC_OFFSET44defines the tsc_offset register
BF_REG_T_VIRTUAL_APIC_ADDRESS45defines the virtual_apic_address register
BF_REG_T_APIC_ACCESS_ADDRESS46defines the apic_access_address register
BF_REG_T_POSTED_INTERRUPT_DESCRIPTOR_ADDRESS47defines the posted_interrupt_descriptor_address register
BF_REG_T_VM_FUNCTION_CONTROLS48defines the vm_function_controls register
BF_REG_T_EPT_POINTER49defines the ept_pointer register
BF_REG_T_EOI_EXIT_BITMAP050defines the eoi_exit_bitmap0 register
BF_REG_T_EOI_EXIT_BITMAP151defines the eoi_exit_bitmap1 register
BF_REG_T_EOI_EXIT_BITMAP252defines the eoi_exit_bitmap2 register
BF_REG_T_EOI_EXIT_BITMAP353defines the eoi_exit_bitmap3 register
BF_REG_T_EPTP_LIST_ADDRESS54defines the eptp_list_address register
BF_REG_T_VMREAD_BITMAP_ADDRESS55defines the vmread_bitmap_address register
BF_REG_T_VMWRITE_BITMAP_ADDRESS56defines the vmwrite_bitmap_address register
BF_REG_T_VIRT_EXCEPTION_INFORMATION_ADDRESS57defines the virt_exception_information_address register
BF_REG_T_XSS_EXITING_BITMAP58defines the xss_exiting_bitmap register
BF_REG_T_ENCLS_EXITING_BITMAP59defines the encls_exiting_bitmap register
BF_REG_T_SUB_PAGE_PERMISSION_TABLE_POINTER60defines the sub_page_permission_table_pointer register
BF_REG_T_TSC_MULTIPLIER61defines the tsc_multiplier register
BF_REG_T_PHYSICAL_ADDRESS62defines the physical_address register
BF_REG_T_VMCS_LINK_POINTER63defines the vmcs_link_pointer register
BF_REG_T_DEBUGCTL64defines the debugctl register
BF_REG_T_PAT65defines the pat register
BF_REG_T_EFER66defines the efer register
BF_REG_T_PERF_GLOBAL_CTRL67defines the perf_global_ctrl register
BF_REG_T_PDPTE068defines the pdpte0 register
BF_REG_T_PDPTE169defines the pdpte1 register
BF_REG_T_PDPTE270defines the pdpte2 register
BF_REG_T_PDPTE371defines the pdpte3 register
BF_REG_T_BNDCFGS72defines the bndcfgs register
BF_REG_T_RTIT_CTL73defines the rtit_ctl register
BF_REG_T_PIN_BASED_VM_EXECUTION_CTLS74defines the pin_based_vm_execution_ctls register
BF_REG_T_PRIMARY_PROC_BASED_VM_EXECUTION_CTLS75defines the primary_proc_based_vm_execution_ctls register
BF_REG_T_EXCEPTION_BITMAP76defines the exception_bitmap register
BF_REG_T_PAGE_FAULT_ERROR_CODE_MASK77defines the page_fault_error_code_mask register
BF_REG_T_PAGE_FAULT_ERROR_CODE_MATCH78defines the page_fault_error_code_match register
BF_REG_T_CR3_TARGET_COUNT79defines the cr3_target_count register
BF_REG_T_VMEXIT_CTLS80defines the vmexit_ctls register
BF_REG_T_VMEXIT_MSR_STORE_COUNT81defines the vmexit_msr_store_count register
BF_REG_T_VMEXIT_MSR_LOAD_COUNT82defines the vmexit_msr_load_count register
BF_REG_T_VMENTRY_CTLS83defines the vmentry_ctls register
BF_REG_T_VMENTRY_MSR_LOAD_COUNT84defines the vmentry_msr_load_count register
BF_REG_T_VMENTRY_INTERRUPT_INFORMATION_FIELD85defines the vmentry_interrupt_information_field register
BF_REG_T_VMENTRY_EXCEPTION_ERROR_CODE86defines the vmentry_exception_error_code register
BF_REG_T_VMENTRY_INSTRUCTION_LENGTH87defines the vmentry_instruction_length register
BF_REG_T_TPR_THRESHOLD88defines the tpr_threshold register
BF_REG_T_SECONDARY_PROC_BASED_VM_EXECUTION_CTLS89defines the secondary_proc_based_vm_execution_ctls register
BF_REG_T_PLE_GAP90defines the ple_gap register
BF_REG_T_PLE_WINDOW91defines the ple_window register
BF_REG_T_VM_INSTRUCTION_ERROR92defines the vm_instruction_error register
BF_REG_T_EXIT_REASON93defines the exit_reason register
BF_REG_T_VMEXIT_INTERRUPTION_INFORMATION94defines the vmexit_interruption_information register
BF_REG_T_VMEXIT_INTERRUPTION_ERROR_CODE95defines the vmexit_interruption_error_code register
BF_REG_T_IDT_VECTORING_INFORMATION_FIELD96defines the idt_vectoring_information_field register
BF_REG_T_IDT_VECTORING_ERROR_CODE97defines the idt_vectoring_error_code register
BF_REG_T_VMEXIT_INSTRUCTION_LENGTH98defines the vmexit_instruction_length register
BF_REG_T_VMEXIT_INSTRUCTION_INFORMATION99defines the vmexit_instruction_information register
BF_REG_T_ES_LIMIT100defines the es_limit register
BF_REG_T_CS_LIMIT101defines the cs_limit register
BF_REG_T_SS_LIMIT102defines the ss_limit register
BF_REG_T_DS_LIMIT103defines the ds_limit register
BF_REG_T_FS_LIMIT104defines the fs_limit register
BF_REG_T_GS_LIMIT105defines the gs_limit register
BF_REG_T_LDTR_LIMIT106defines the ldtr_limit register
BF_REG_T_TR_LIMIT107defines the tr_limit register
BF_REG_T_GDTR_LIMIT108defines the gdtr_limit register
BF_REG_T_IDTR_LIMIT109defines the idtr_limit register
BF_REG_T_ES_ATTRIB110defines the es_attrib register
BF_REG_T_CS_ATTRIB111defines the cs_attrib register
BF_REG_T_SS_ATTRIB112defines the ss_attrib register
BF_REG_T_DS_ATTRIB113defines the ds_attrib register
BF_REG_T_FS_ATTRIB114defines the fs_attrib register
BF_REG_T_GS_ATTRIB115defines the gs_attrib register
BF_REG_T_LDTR_ATTRIB116defines the ldtr_attrib register
BF_REG_T_TR_ATTRIB117defines the tr_attrib register
BF_REG_T_INTERRUPTIBILITY_STATE118defines the interruptibility_state register
BF_REG_T_ACTIVITY_STATE119defines the activity_state register
BF_REG_T_SMBASE120defines the smbase register
BF_REG_T_SYSENTER_CS121defines the sysenter_cs register
BF_REG_T_VMX_PREEMPTION_TIMER_VALUE122defines the vmx_preemption_timer_value register
BF_REG_T_CR0_GUEST_HOST_MASK123defines the cr0_guest_host_mask register
BF_REG_T_CR4_GUEST_HOST_MASK124defines the cr4_guest_host_mask register
BF_REG_T_CR0_READ_SHADOW125defines the cr0_read_shadow register
BF_REG_T_CR4_READ_SHADOW126defines the cr4_read_shadow register
BF_REG_T_CR3_TARGET_VALUE0127defines the cr3_target_value0 register
BF_REG_T_CR3_TARGET_VALUE1128defines the cr3_target_value1 register
BF_REG_T_CR3_TARGET_VALUE2129defines the cr3_target_value2 register
BF_REG_T_CR3_TARGET_VALUE3130defines the cr3_target_value3 register
BF_REG_T_EXIT_QUALIFICATION131defines the exit_qualification register
BF_REG_T_IO_RCX132defines the io_rcx register
BF_REG_T_IO_RSI133defines the io_rsi register
BF_REG_T_IO_RDI134defines the io_rdi register
BF_REG_T_IO_RIP135defines the io_rip register
BF_REG_T_LINEAR_ADDRESS136defines the linear_address register
BF_REG_T_CR0137defines the cr0 register
BF_REG_T_CR3138defines the cr3 register
BF_REG_T_CR4139defines the cr4 register
BF_REG_T_ES_BASE140defines the es_base register
BF_REG_T_CS_BASE141defines the cs_base register
BF_REG_T_SS_BASE142defines the ss_base register
BF_REG_T_DS_BASE143defines the ds_base register
BF_REG_T_FS_BASE144defines the fs_base register
BF_REG_T_GS_BASE145defines the gs_base register
BF_REG_T_LDTR_BASE146defines the ldtr_base register
BF_REG_T_TR_BASE147defines the tr_base register
BF_REG_T_GDTR_BASE148defines the gdtr_base register
BF_REG_T_IDTR_BASE149defines the idtr_base register
BF_REG_T_DR7150defines the dr7 register
BF_REG_T_RSP151defines the rsp register
BF_REG_T_RIP152defines the rip register
BF_REG_T_RFLAGS153defines the rflags register
BF_REG_T_PENDING_DEBUG_EXCEPTIONS154defines the pending_debug_exceptions register
BF_REG_T_SYSENTER_ESP155defines the sysenter_esp register
BF_REG_T_SYSENTER_EIP156defines the sysenter_eip register
BF_REG_T_CR8157defines the cr8 register
BF_REG_T_DR0158defines the dr0 register
BF_REG_T_DR1159defines the dr1 register
BF_REG_T_DR2160defines the dr2 register
BF_REG_T_DR3161defines the dr3 register
BF_REG_T_XCR0162defines the xcr0 register
BF_REG_T_INVALID163defines the invalid register

1.4.3. Exit Type

Defines the exit type used by bf_control_op_exit

enum, uint64_t: bf_exit_status_t

NameValueDescription
bf_exit_status_t_success0Exit with a success code
bf_exit_status_t_failure1Exit with a failure code

1.4.4. Bootstrap Callback Handler Type

Defines the signature of the bootstrap callback handler

*typedef, void(bf_callback_handler_bootstrap_t)(uint16_t)

1.4.5. VMExit Callback Handler Type

Defines the signature of the VM exit callback handler

*typedef, void(bf_callback_handler_vmexit_t)(bsl::uint16_t, uint64_t)

1.4.6. Fast Fail Callback Handler Type

Defines the signature of the fast fail callback handler

*typedef, void(bf_callback_handler_fail_t)(uint64_t, uint64_t)

1.5. ID Constants

The following defines some ID constants.

const, uint16_t: BF_INVALID_ID

ValueDescription
0xFFFFDefines an invalid ID for an extension, VM, VP, VS and PP

const, uint16_t: BF_BS_PPID

ValueDescription
0x0Defines the bootstrap physical processor ID

const, uint16_t: BF_ROOT_VMID

ValueDescription
0x0Defines the root virtual machine ID

1.6. Endianness

This document only applies to 64bit Intel and AMD systems conforming to the amd64 architecture. As such, this document is limited to little endian.

1.7. Host PAT (Intel/AMD Only)

The host PAT has the following layout. Indexes marked as XX are reserved for future use.

const, uint64_t: BF_HOST_PAT

ValueDescription
0xXXXXXXXX00XXXX06Defines the host PAT value

2. Syscall Interface

The following section defines the syscall interface used by this specification, and therefore Bareflank.

Userspace can execute syscalls from 64bit mode.

2.2. Alignment Requirements

This specification does not support structure based inputs/outputs and therefore there are not alignment requirements.

2.3. Syscall Status Codes

Every syscall returns a bf_status_t to indicate the success or failure of a syscall after execution. The following defines the layout of bf_status_t:

BitsNameDescription
63:48BF_STATUS_SIGContains 0x0000 on success, 0xDEAD on failure
47:16BF_STATUS_FLAGSContains the flags associated with the bf_status_t
15:0BF_STATUS_VALUEContains the value of the bf_status_t

BF_STATUS_VALUE defines success or which type of error occurred. BF_STATUS_FLAGS provides additional information about why the error occurred.

2.3.1. BF_STATUS_SUCCESS, VALUE=0

const, bf_status_t: BF_STATUS_SUCCESS

ValueDescription
0x0000000000000000Indicates the syscall returned successfully

2.3.2. BF_STATUS_FAILURE, VALUE=1

const, bf_status_t: BF_STATUS_FAILURE_UNKNOWN

ValueDescription
0xDEAD000000010001Indicates an unknown error occurred

const, bf_status_t: BF_STATUS_FAILURE_UNSUPPORTED

ValueDescription
0xDEAD000000020001Indicates the syscall is unsupported

const, bf_status_t: BF_STATUS_FAILURE_INVALID_HANDLE

ValueDescription
0xDEAD000000040001Indicates the provided handle is invalid

2.3.3. BF_STATUS_INVALID_PERM, VALUE=2

const, bf_status_t: BF_STATUS_INVALID_PERM_DENIED

ValueDescription
0xDEAD000000010002Indicates the policy engine denied the syscall

2.3.4. BF_STATUS_INVALID_PARAMS, VALUE=3

const, mv_status_t: MV_STATUS_INVALID_INPUT_REG0

ValueDescription
0xDEAD000000010003Indicates input reg0 is invalid

const, mv_status_t: MV_STATUS_INVALID_INPUT_REG1

ValueDescription
0xDEAD000000020003Indicates input reg1 is invalid

const, mv_status_t: MV_STATUS_INVALID_INPUT_REG2

ValueDescription
0xDEAD000000040003Indicates input reg2 is invalid

const, mv_status_t: MV_STATUS_INVALID_INPUT_REG3

ValueDescription
0xDEAD000000080003Indicates input reg3 is invalid

const, mv_status_t: MV_STATUS_INVALID_INPUT_REG4

ValueDescription
0xDEAD000000100003Indicates input reg4 is invalid

const, mv_status_t: MV_STATUS_INVALID_INPUT_REG5

ValueDescription
0xDEAD000000200003Indicates input reg5 is invalid

const, mv_status_t: MV_STATUS_INVALID_OUTPUT_REG0

ValueDescription
0xDEAD000000400003Indicates output reg0 is invalid

const, mv_status_t: MV_STATUS_INVALID_OUTPUT_REG1

ValueDescription
0xDEAD000000800003Indicates output reg1 is invalid

const, mv_status_t: MV_STATUS_INVALID_OUTPUT_REG2

ValueDescription
0xDEAD000001000003Indicates output reg2 is invalid

const, mv_status_t: MV_STATUS_INVALID_OUTPUT_REG3

ValueDescription
0xDEAD000002000003Indicates output reg3 is invalid

const, mv_status_t: MV_STATUS_INVALID_OUTPUT_REG4

ValueDescription
0xDEAD000004000003Indicates output reg4 is invalid

const, mv_status_t: MV_STATUS_INVALID_OUTPUT_REG5

ValueDescription
0xDEAD000008000003Indicates output reg5 is invalid

2.4. Syscall Inputs

Before software can execute a syscall, it must first open a handle to the syscall interface by executing the bf_handle_op_open_handle syscall. This handle must be provided as the first argument to each syscall in RDI (i.e., REG0) and can be released using the bf_handle_op_close_handle syscall.

RDI:

BitsNameDescription
63:0BF_HANDLEThe result of bf_handle_op_open_handle

Every syscall must provide information about the syscall by filling out RAX as follows:

RAX:

BitsNameDescription
63:48BF_SYSCALL_SIG0x6642 = "Bf"
47:32BF_SYSCALL_FLAGSContains the syscall's flags
31:16BF_SYSCALL_OPContains the syscall's opcode
15:0BF_SYSCALL_IDXContains the syscall's index

const, uint64_t: BF_SYSCALL_SIG_VAL

ValueDescription
0x6642000000000000Defines the BF_SYSCALL_SIG field for RAX

const, uint64_t: BF_HYPERCALL_SIG_MASK

ValueDescription
0xFFFF000000000000Defines a mask for BF_SYSCALL_SIG

const, uint64_t: BF_HYPERCALL_FLAGS_MASK

ValueDescription
0x0000FFFF00000000Defines a mask for BF_SYSCALL_FLAGS

const, uint64_t: BF_HYPERCALL_OPCODE_MASK

ValueDescription
0xFFFF0000FFFF0000Defines a mask for BF_SYSCALL_OP

const, uint64_t: BF_HYPERCALL_OPCODE_NOSIG_MASK

ValueDescription
0x00000000FFFF0000Defines a mask for BF_SYSCALL_OP (with no signature added)

const, uint64_t: BF_HYPERCALL_INDEX_MASK

ValueDescription
0x000000000000FFFFDefines a mask for BF_SYSCALL_IDX

BF_SYSCALL_SIG is used to ensure the syscall is, in fact, a Bareflank specific syscall. BF_SYSCALL_FLAGS is used to provide additional syscall options.

BF_SYSCALL_OP determines which opcode the syscall belongs to, logically grouping syscalls based on their function. BF_SYSCALL_OP is also used internally within the microkernel to dispatch the syscall to the proper handler. BF_SYSCALL_IDX, when combined with BF_SYSCALL_OP, uniquely identifies a specific syscall. This specification tightly packs the values assigned to both BF_SYSCALL_IDX and BF_SYSCALL_OP to ensure Bareflank (and variants) can use jump tables instead of branch logic.

The following defines the input registers for x64 based systems (i.e., x86_64 and amd64):

Arguments:

Register NameDescription
RDISet to the result of bf_handle_op_open_handle
RSIStores the value of REG1 (syscall specific)
RDXStores the value of REG2 (syscall specific)
R10Stores the value of REG3 (syscall specific)
R8Stores the value of REG4 (syscall specific)
R9Stores the value of REG5 (syscall specific)

All unused registers by any syscall are considered REVI.

2.5. Syscall Outputs

After executing a syscall, a bf_status_t is returned in RAX to indicate if the syscall succeeded or failed and why.

RAX:

BitsNameDescription
63:0BF_STATUSContains the value of bf_status_t

The following defines the output registers for x64 based systems (i.e., x86_64 and amd64):

Arguments:

Register NameDescription
RDIStores the value of REG0 (syscall specific)
RSIStores the value of REG1 (syscall specific)
RDXStores the value of REG2 (syscall specific)
R10Stores the value of REG3 (syscall specific)
R8Stores the value of REG4 (syscall specific)
R9Stores the value of REG5 (syscall specific)

2.6. Syscall Opcodes

The following sections define the different opcodes that are supported by this specification. Note that each opcode includes the syscall signature making it easier to validate if the syscall is supported or not.

2.6.1. Control Support

const, uint64_t: BF_CONTROL_OP_VAL

ValueDescription
0x6642000000000000Defines the syscall opcode for bf_control_op

const, uint64_t: BF_CONTROL_OP_NOSIG_VAL

ValueDescription
0x0000000000000000Defines the syscall opcode for bf_control_op (nosig)

2.6.2. Handle Support

const, uint64_t: BF_HANDLE_OP_VAL

ValueDescription
0x6642000000010000Defines the syscall opcode for bf_handle_op

const, uint64_t: BF_HANDLE_OP_NOSIG_VAL

ValueDescription
0x0000000000010000Defines the syscall opcode for bf_handle_op (nosig)

2.6.3. Debug Support

const, uint64_t: BF_DEBUG_OP_VAL

ValueDescription
0x6642000000020000Defines the syscall opcode for bf_debug_op

const, uint64_t: BF_DEBUG_OP_NOSIG_VAL

ValueDescription
0x00000000000020000Defines the syscall opcode for bf_debug_op (nosig)

2.6.4. Callback Support

const, uint64_t: BF_CALLBACK_OP_VAL

ValueDescription
0x6642000000030000Defines the syscall opcode for bf_callback_op

const, uint64_t: BF_CALLBACK_OP_NOSIG_VAL

ValueDescription
0x0000000000030000Defines the syscall opcode for bf_callback_op (nosig)

2.6.5. VM Support

const, uint64_t: BF_VM_OP_VAL

ValueDescription
0x6642000000040000Defines the syscall opcode for bf_vm_op

const, uint64_t: BF_VM_OP_NOSIG_VAL

ValueDescription
0x0000000000040000Defines the syscall opcode for bf_vm_op (nosig)

2.6.6. VP Support

const, uint64_t: BF_VP_OP_VAL

ValueDescription
0x6642000000050000Defines the syscall opcode for bf_vp_op

const, uint64_t: BF_VP_OP_NOSIG_VAL

ValueDescription
0x0000000000050000Defines the syscall opcode for bf_vp_op (nosig)

2.6.7. VS Support

const, uint64_t: BF_VS_OP_VAL

ValueDescription
0x6642000000060000Defines the syscall opcode for bf_vs_op

const, uint64_t: BF_VS_OP_NOSIG_VAL

ValueDescription
0x0000000000060000Defines the syscall opcode for bf_vs_op (nosig)

2.6.8. Intrinsic Support

const, uint64_t: BF_INTRINSIC_OP_VAL

ValueDescription
0x6642000000070000Defines the syscall opcode for bf_intrinsic_op

const, uint64_t: BF_INTRINSIC_OP_NOSIG_VAL

ValueDescription
0x0000000000070000Defines the syscall opcode for bf_intrinsic_op (nosig)

2.6.9. Mem Support

const, uint64_t: BF_MEM_OP_VAL

ValueDescription
0x6642000000080000Defines the syscall opcode for bf_mem_op

const, uint64_t: BF_MEM_OP_NOSIG_VAL

ValueDescription
0x0000000000080000Defines the syscall opcode for bf_mem_op (nosig)

2.7. Syscall Specification IDs

The following defines the specification IDs used when opening a handle. These provide software with a means to define which specification it implements. The version provided to the extension's entry point defines which version of this spec the microkernel supports. For example, if the provided version is 0x2, it means that it supports version #1 of this spec, in which case, an extension can open a handle with BF_SPEC_ID1_VAL. If the provided version is 0x6, it would mean that an extension could open a handle with BF_SPEC_ID1_VAL or BF_SPEC_ID2_VAL. Likewise, if the provided version is 0x4, it means that BF_SPEC_ID1_VAL is no longer supported, and the extension must open the handle with BF_SPEC_ID2_VAL.

const, uint32_t: BF_SPEC_ID1_VAL

ValueDescription
0x31236642Defines the ID for version #1 of this spec

const, uint32_t: BF_SPEC_ID1_MASK

ValueDescription
0x2Defines the mask for checking support for version #1 of this spec

const, uint32_t: BF_ALL_SPECS_SUPPORTED_VAL

ValueDescription
0x2Defines all versions supported

const, uint32_t: BF_INVALID_VERSION

ValueDescription
0x80000000Defines an invalid version

2.8. Thread Local Storage

The microkernel defines a "thread" the same way both Intel and AMD define a thread (i.e., a logical core). For example, some Intel CPUs have 4 cores and 8 threads when hyper-threading is enabled, or 4 cores and 4 threads when hyper-threading is disabled. Each logical core is given one "thread" and that thread always executes on that logical core. The microkernel defines these logical cores as physical processors (i.e., PP).

The layout of the TLS block provided to each extension uses a scheme similar to the ELF TLS specification, but with some modifications. Unlike the ELF TLS specification, each TLS block is limited to two pages. The lower half of the page is dedicated to "thread_local" storage. The upper half is defined by this specification, and provides access to registers shared between the microkernel and the extension to improve performance. For example, access to a VM's general purpose registers is available from the TLS block. Each TLS register defined by this specific is an offset into the upper half of the TLS block (which can be located using the fs segment register on Intel/AMD).

IMPORTANT: The general purpose registers are always accessible to an extension to read and write, but it is up to the extension to ensure the correct VS state is being modified. Accesses to the TLS block modifies the active VS only. For example, while an extension is executing its bootstrap handler, there is no active VS, in which case any reads/writes to the general purpose registers from the TLS block will be lost. When an extension is executing from a VMExit handler, reads/writes to the general purpose registers from the TLS block are made to the VS that generated the VMExit. If an extension then creates a VS, the only way to modify the general purpose registers for the newly created VS is through the read/write ABIs. Attempting to use the TLS block will modify the registers for the active VS, not the newly created VS. The only way to set a VS to "active" is to use the run ABI, which on success does not return, meaning the extension has to wait for a VMExit before the newly create VS's general purpose registers can be accessed from the TLS block.

Although this seems overly complicated, this optimization works well for the majority of the VMExits an extension will have to handle, especially the VMExits that execute frequently as most of the time an extension will only be modifying the general purpose registers for the active VS.

2.8.1. TLS Offsets

*consts, void : uint64_t

NameValueDescription
TLS_OFFSET_RAX0x800Ustores the offset for rax
TLS_OFFSET_RBX0x808Ustores the offset for rbx
TLS_OFFSET_RCX0x810Ustores the offset for rcx
TLS_OFFSET_RDX0x818Ustores the offset for rdx
TLS_OFFSET_RBP0x820Ustores the offset for rbp
TLS_OFFSET_RSI0x828Ustores the offset for rsi
TLS_OFFSET_RDI0x830Ustores the offset for rdi
TLS_OFFSET_R80x838Ustores the offset for r8
TLS_OFFSET_R90x840Ustores the offset for r9
TLS_OFFSET_R100x848Ustores the offset for r10
TLS_OFFSET_R110x850Ustores the offset for r11
TLS_OFFSET_R120x858Ustores the offset for r12
TLS_OFFSET_R130x860Ustores the offset for r13
TLS_OFFSET_R140x868Ustores the offset for r14
TLS_OFFSET_R150x870Ustores the offset for r15
TLS_OFFSET_ACTIVE_EXTID0xFF0Ustores the offset of the active extid
TLS_OFFSET_ACTIVE_VMID0xFF2Ustores the offset of the active vmid
TLS_OFFSET_ACTIVE_VPID0xFF4Ustores the offset of the active vpid
TLS_OFFSET_ACTIVE_VSID0xFF6Ustores the offset of the active vsid
TLS_OFFSET_ACTIVE_PPID0xFF8Ustores the offset of the active ppid
TLS_OFFSET_ONLINE_PPS0xFFAUstores the number of PPs that are online

2.9. Control Syscalls

2.9.1. bf_control_op_exit, OP=0x0, IDX=0x0

This syscall tells the microkernel to stop the execution of an extension, providing a means to fast fail.

const, uint64_t: BF_CONTROL_OP_EXIT_IDX_VAL

ValueDescription
0x0000000000000000Defines the index for bf_control_op_exit

2.9.2. bf_control_op_wait, OP=0x0, IDX=0x1

This syscall tells the microkernel that the extension would like to wait for a callback. This syscall is a blocking syscall that never returns and should be used to return from the _start function.

const, uint64_t: BF_CONTROL_OP_WAIT_IDX_VAL

ValueDescription
0x0000000000000001Defines the index for bf_control_op_wait

2.9.3. bf_control_op_again, OP=0x0, IDX=0x2

This syscall tells the microkernel that the extension would like to try again from a fast fail callback. This syscall is a blocking syscall that never returns and should be used to return from the fail_entry function.

const, uint64_t: BF_CONTROL_OP_AGAIN_IDX_VAL

ValueDescription
0x0000000000000002Defines the index for bf_control_op_again

2.10. Handle Syscalls

2.10.1. bf_handle_op_open_handle, OP=0x1, IDX=0x0

This syscall returns the handle that is required to execute the remaining syscalls.

Input:

Register NameBitsDescription
REG031:0The version of this spec that software supports
REG063:32REVI

Output:

Register NameBitsDescription
REG063:0The value to set REG0 to for most other syscalls

const, uint64_t: BF_HANDLE_OP_OPEN_HANDLE_IDX_VAL

ValueDescription
0x0000000000000000Defines the index for bf_handle_op_open_handle

const, uint64_t: BF_INVALID_HANDLE

ValueDescription
0xFFFFFFFFFFFFFFFFDefines an invalid handle

2.10.2. bf_handle_op_close_handle, OP=0x1, IDX=0x1

This syscall closes a previously opened handle.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle

const, uint64_t: BF_HANDLE_OP_CLOSE_HANDLE_IDX_VAL

ValueDescription
0x0000000000000001Defines the index for bf_handle_op_close_handle

2.11. Debug Syscalls

2.11.1. bf_debug_op_out, OP=0x2, IDX=0x0

This syscall tells the microkernel to output RDI and RSI to the console device the microkernel is currently using for debugging.

Input:

Register NameBitsDescription
REG063:0The first value to output to the microkernel's console
REG163:0The second value to output to the microkernel's console

const, uint64_t: BF_DEBUG_OP_OUT_IDX_VAL

ValueDescription
0x0000000000000000Defines the index for bf_debug_op_out

2.11.2. bf_debug_op_dump_vm, OP=0x2, IDX=0x1

This syscall tells the microkernel to output a VM's state to the console device the microkernel is currently using for debugging.

Input:

Register NameBitsDescription
REG063:0The ID of the VM's state to output

const, uint64_t: BF_DEBUG_OP_DUMP_VM_IDX_VAL

ValueDescription
0x0000000000000001Defines the index for bf_debug_op_dump_vm

2.11.3. bf_debug_op_dump_vp, OP=0x2, IDX=0x2

This syscall tells the microkernel to output a VP's state to the console device the microkernel is currently using for debugging.

Input:

Register NameBitsDescription
REG063:0The ID of the VP's state to output

const, uint64_t: BF_DEBUG_OP_DUMP_VP_IDX_VAL

ValueDescription
0x0000000000000002Defines the index for bf_debug_op_dump_vp

2.11.4. bf_debug_op_dump_vs, OP=0x2, IDX=0x3

This syscall tells the microkernel to output a VS's state to the console device the microkernel is currently using for debugging.

Input:

Register NameBitsDescription
REG063:0The ID of the VS's state to output

const, uint64_t: BF_DEBUG_OP_DUMP_VS_IDX_VAL

ValueDescription
0x0000000000000003Defines the index for bf_debug_op_dump_vs

2.11.5. bf_debug_op_dump_vmexit_log, OP=0x2, IDX=0x4

This syscall tells the microkernel to output the VMExit log. The VMExit log is a chronological log of the "X" number of exits that have occurred on a specific physical processor.

Input:

Register NameBitsDescription
REG063:0The PPID of the PP to dump the log from

const, uint64_t: BF_DEBUG_OP_DUMP_VMEXIT_LOG_IDX_VAL

ValueDescription
0x0000000000000003Defines the index for bf_debug_op_dump_vmexit_log

2.11.6. bf_debug_op_write_c, OP=0x2, IDX=0x5

This syscall tells the microkernel to output a provided character to the microkernel's console.

Input:

Register NameBitsDescription
REG07:0The character to output
REG063:8REVI

const, uint64_t: BF_DEBUG_OP_WRITE_C_IDX_VAL

ValueDescription
0x0000000000000005Defines the index for bf_debug_op_write_c

2.11.7. bf_debug_op_write_str, OP=0x2, IDX=0x6

This syscall tells the microkernel to output a provided string to the microkernel's console.

Input:

Register NameBitsDescription
REG063:0The virtual address of a null terminated string to output

const, uint64_t: BF_DEBUG_OP_WRITE_STR_IDX_VAL

ValueDescription
0x0000000000000006Defines the index for bf_debug_op_write_str

2.11.8. bf_debug_op_dump_ext, OP=0x2, IDX=0x7

This syscall tells the microkernel to output an extension's state to the console device the microkernel is currently using for debugging.

Input:

Register NameBitsDescription
REG063:0The EXTID of the extensions's state to output

const, uint64_t: BF_DEBUG_OP_DUMP_EXT_IDX_VAL

ValueDescription
0x0000000000000007Defines the index for bf_debug_op_dump_ext

2.11.9. bf_debug_op_dump_page_pool, OP=0x2, IDX=0x8

This syscall tells the microkernel to output the page pool's stats to the console device the microkernel is currently using for debugging.

const, uint64_t: BF_DEBUG_OP_DUMP_PAGE_POOL_IDX_VAL

ValueDescription
0x0000000000000008Defines the index for bf_debug_op_dump_page_pool

2.11.10. bf_debug_op_dump_huge_pool, OP=0x2, IDX=0x9

This syscall tells the microkernel to output the huge pool's stats to the console device the microkernel is currently using for debugging.

const, uint64_t: BF_DEBUG_OP_DUMP_HUGE_POOL_IDX_VAL

ValueDescription
0x0000000000000009Defines the index for bf_debug_op_dump_huge_pool

2.12. Callback Syscalls

2.12.1. bf_callback_op_register_bootstrap, OP=0x3, IDX=0x0

This syscall tells the microkernel that the extension would like to receive callbacks for bootstrap events.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG163:0Set to the virtual address of the callback

const, uint64_t: BF_CALLBACK_OP_REGISTER_BOOTSTRAP_IDX_VAL

ValueDescription
0x0000000000000000Defines the index for bf_callback_op_register_bootstrap

2.12.2. bf_callback_op_register_vmexit, OP=0x3, IDX=0x1

This syscall tells the microkernel that the extension would like to receive callbacks for VM exits.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG163:0Set to the virtual address of the callback

const, uint64_t: BF_CALLBACK_OP_REGISTER_VMEXIT_IDX_VAL

ValueDescription
0x0000000000000001Defines the index for bf_callback_op_register_vmexit

2.12.3. bf_callback_op_register_fail, OP=0x3, IDX=0x2

This syscall tells the microkernel that the extension would like to receive callbacks for fast fail events. If a fast fail event occurs, something terrible has happened, and the extension must take action, or the physical processor will halt.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG163:0Set to the virtual address of the callback

const, uint64_t: BF_CALLBACK_OP_REGISTER_FAIL_IDX_VAL

ValueDescription
0x0000000000000002Defines the index for bf_callback_op_register_fail

2.13. Virtual Machine Syscalls

A Virtual Machine or VM virtually represents a physical computer. Although the microkernel has an internal representation of a VM, it doesn't understand what a VM is outside of resource management, and it is up to the extension to define what a VM is and how it should operate.

One important resource within the microkernel that changes when a VM changes is the direct map each extension is given. When a VM changes, the direct map an extension uses to access physical memory also changes.

2.13.1. bf_vm_op_create_vm, OP=0x4, IDX=0x0

This syscall tells the microkernel to create a VM and return its ID.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle

Output:

Register NameBitsDescription
REG015:0The resulting VMID of the newly created VM
REG063:16REVI

const, uint64_t: BF_VM_OP_CREATE_VM_IDX_VAL

ValueDescription
0x0000000000000000Defines the index for bf_vm_op_create_vm

2.13.2. bf_vm_op_destroy_vm, OP=0x4, IDX=0x1

This syscall tells the microkernel to destroy a VM given an ID.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VM to destroy
REG163:16REVI

const, uint64_t: BF_VM_OP_DESTROY_VM_IDX_VAL

ValueDescription
0x0000000000000001Defines the index for bf_vm_op_destroy_vm

2.13.3. bf_vm_op_map_direct, OP=0x4, IDX=0x2

This syscall tells the microkernel to map a physical address into the VM's direct map. This is the same as directly accessing the direct map with the difference being that software can provide a physical address and receive the precalculated virtual address.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VM to map the physical address to
REG163:16REVI
REG212:0REV0
REG263:12The physical address to map

Output:

Register NameBitsDescription
REG012:0REV0
REG063:12The resulting virtual address of the map

const, uint64_t: BF_VM_OP_MAP_DIRECT_IDX_VAL

ValueDescription
0x0000000000000002Defines the index for bf_vm_op_map_direct

2.13.4. bf_vm_op_unmap_direct, OP=0x4, IDX=0x3

This syscall tells the microkernel to unmap a previously mapped virtual address in the direct map. Unlike bf_vm_op_unmap_direct_broadcast, this syscall does not flush the TLB on any other PP, meaning this unmap is local to the PP the call is made on. Attempting to unmap a virtual address from the direct map that has been accessed on any other PP other than the PP this syscall is executed on will result in undefined behavior. This syscall is designed to support mapping and then immediately unmapping a physical address on a single PP during a single VMExit. It can also be used to map on a PP and then use unmap on the same PP during multiple VMExits, but special care must be taken to ensure no other PP can access the map, otherwise UB will occur.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VM to unmap the virtual address from
REG163:16REVI
REG212:0REV0
REG263:12The virtual address to unmap

const, uint64_t: BF_VM_OP_UNMAP_DIRECT_IDX_VAL

ValueDescription
0x0000000000000003Defines the index for bf_vm_op_unmap_direct

2.13.5. bf_vm_op_unmap_direct_broadcast, OP=0x4, IDX=0x4

This syscall tells the microkernel to unmap a previously mapped virtual address in the direct map. Unlike bf_vm_op_unmap_direct, this syscall performs a broadcast TLB flush which means it can be safely used on all direct mapped addresses. The downside of using this function is that it can be a lot slower than bf_vm_op_unmap_direct, especially on systems with a lot of PPs.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VM to unmap the virtual address from
REG163:16REVI
REG212:0REV0
REG263:12The virtual address to unmap

const, uint64_t: BF_VM_OP_UNMAP_DIRECT_REMOTE_IDX_VAL

ValueDescription
0x0000000000000004Defines the index for bf_vm_op_unmap_direct_broadcast

2.13.6. bf_vm_op_tlb_flush, OP=0x4, IDX=0x5

Given the ID of a VM, invalidates the VM's TLB on the PP that this is executed on.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VM to invalidate
REG163:16REVI

const, uint64_t: BF_VM_OP_TLB_FLUSH_IDX_VAL

ValueDescription
0x0000000000000005Defines the index for bf_vm_op_tlb_flush

2.14. Virtual Processor Syscalls

A Virtual Processor or VP virtually represents a PP. Although the microkernel has an internal representation of a VP, it doesn't understand what a VP is outside of resource management, and it is up to the extension to define what a VP is and how it should operate.

2.14.1. bf_vp_op_create_vp, OP=0x5, IDX=0x0

This syscall tells the microkernel to create a VP given the ID of the VM the VP will be assigned to. Upon success, this syscall returns the ID of the newly created VP.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VM to assign the newly created VP to
REG163:16REVI

Output:

Register NameBitsDescription
REG015:0The resulting VPID of the newly created VP
REG063:16REVI

const, uint64_t: BF_VP_OP_CREATE_VP_IDX_VAL

ValueDescription
0x0000000000000000Defines the index for bf_vp_op_create_vp

2.14.2. bf_vp_op_destroy_vp, OP=0x5, IDX=0x1

This syscall tells the microkernel to destroy a VP given an ID.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VP to destroy
REG163:16REVI

const, uint64_t: BF_VP_OP_DESTROY_VP_IDX_VAL

ValueDescription
0x0000000000000001Defines the index for bf_vp_op_destroy_vp

2.15. Virtual Processor State Syscalls

A Virtual Processor State or VS virtually represents a PP's state. Most operations performed by an extension will be through a VS. When a VS is created, it is assigned to a VP and PP. To change the PP, a VS must be migrated.

2.15.1. bf_vs_op_create_vs, OP=0x6, IDX=0x0

This syscall tells the microkernel to create a VS given the IDs of the VP and PP the VS will be assigned to. Upon success, this syscall returns the ID of the newly created VS.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VP to assign the newly created VS to
REG163:16REVI
REG215:0The ID of the PP to assign the newly created VS to
REG263:16REVI

Output:

Register NameBitsDescription
REG015:0The resulting VSID of the newly created VS
REG063:16REVI

const, uint64_t: BF_VS_OP_CREATE_VS_IDX_VAL

ValueDescription
0x0000000000000000Defines the index for bf_vs_op_create_vs

2.15.2. bf_vs_op_destroy_vs, OP=0x6, IDX=0x1

This syscall tells the microkernel to destroy a VS given an ID.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VS to destroy
REG163:16REVI

const, uint64_t: BF_VS_OP_DESTROY_VS_IDX_VAL

ValueDescription
0x0000000000000001Defines the index for bf_vs_op_destroy_vs

2.15.3. bf_vs_op_init_as_root, OP=0x6, IDX=0x2

This syscall tells the microkernel to initialize a VS using the root VP state provided by the loader using the current PPID.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VS to initialize
REG163:16REVI

const, uint64_t: BF_VS_OP_INIT_AS_ROOT_IDX_VAL

ValueDescription
0x0000000000000002Defines the index for bf_vs_op_init_as_root

2.15.4. bf_vs_op_read, OP=0x6, IDX=0x3

Reads a CPU register from the VS given a bf_reg_t. Note that the bf_reg_t is architecture-specific.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VS to read from
REG163:16REVI
REG263:0A bf_reg_t defining which register to read

Output:

Register NameBitsDescription
REG063:0The resulting value

const, uint64_t: BF_VS_OP_READ_IDX_VAL

ValueDescription
0x0000000000000003Defines the index for bf_vs_op_read

2.15.5. bf_vs_op_write, OP=0x6, IDX=0x4

Writes to a CPU register in the VS given a bf_reg_t and the value to write. Note that the bf_reg_t is architecture-specific.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VS to write to
REG163:16REVI
REG263:0A bf_reg_t defining which register to write to
REG363:0The value to write to the requested register

const, uint64_t: BF_VS_OP_WRITE_IDX_VAL

ValueDescription
0x0000000000000004Defines the index for bf_vs_op_write

2.15.6. bf_vs_op_run, OP=0x6, IDX=0x5

Executes a VS given the ID of the VM, VP and VS to execute. The VS must be assigned to the provided VP and the provided VP must be assigned to the provided VM. The VP and VS must not be executing on any other PP, and the VS must be assigned to the PP this syscall is executed on. Upon success, this syscall will not return.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VM to run
REG163:16REVI
REG215:0The ID of the VP to run
REG263:16REVI
REG315:0The ID of the VS to run
REG363:16REVI

const, uint64_t: BF_VS_OP_RUN_IDX_VAL

ValueDescription
0x0000000000000005Defines the index for bf_vs_op_run

2.15.7. bf_vs_op_run_current, OP=0x6, IDX=0x6

bf_vs_op_run_current tells the microkernel to execute the currently active VS, VP and VM.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle

const, uint64_t: BF_VS_OP_RUN_CURRENT_IDX_VAL

ValueDescription
0x0000000000000006Defines the index for bf_vs_op_run_current

2.15.8. bf_vs_op_advance_ip_and_run_impl, OP=0x6, IDX=0x7

Advances the IP and executes a VS given the ID of the VM, VP and VS to execute. The VS must be assigned to the provided VP and the provided VP must be assigned to the provided VM. The VP and VS must not be executing on any other PP, and the VS must be assigned to the PP this syscall is executed on. Upon success, this syscall will not return.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VS advance the IP in
REG163:16REVI

const, uint64_t: BF_VS_OP_ADVANCE_IP_AND_RUN_IDX_VAL

ValueDescription
0x0000000000000007Defines the index for bf_vs_op_advance_ip_and_run_impl

2.15.9. bf_vs_op_advance_ip_and_run_current, OP=0x6, IDX=0x8

bf_vs_op_advance_ip_and_run_current tells the microkernel to advance the IP of and execute the currently active VS, VP and VM.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle

const, uint64_t: BF_VS_OP_ADVANCE_IP_AND_RUN_CURRENT_IDX_VAL

ValueDescription
0x0000000000000008Defines the index for bf_vs_op_advance_ip_and_run_current

2.15.10. bf_vs_op_promote, OP=0x6, IDX=0x9

bf_vs_op_promote tells the microkernel to promote the requested VS. bf_vs_op_promote will stop the hypervisor on the physical processor and replace its state with the state in the given VS. Note that this syscall only returns on error.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VS to promote
REG163:16REVI

const, uint64_t: BF_VS_OP_PROMOTE_IDX_VAL

ValueDescription
0x0000000000000009Defines the index for bf_vs_op_promote

2.15.11. bf_vs_op_clear, OP=0x6, IDX=0xA

bf_vs_op_clear tells the microkernel to clear the VS's hardware cache, if one exists. How this is used depends entirely on the hardware and is associated with AMD's VMCB Clean Bits, and Intel's VMClear instruction. See the associated documentation for more details. On AMD, this ABI clears the entire VMCB. For more fine grained control, use the write ABIs to manually modify the VMCB.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VS to clear
REG163:16REVI

const, uint64_t: BF_VS_OP_CLEAR_IDX_VAL

ValueDescription
0x000000000000000ADefines the index for bf_vs_op_clear

2.15.12. bf_vs_op_migrate, OP=0x6, IDX=0xB

Migrates a VS to the provided PP. The VS must not be active.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VS to migrate
REG163:16REVI
REG115:0The ID of the PP to migrate the VS to
REG163:16REVI

const, uint64_t: BF_VS_OP_MIGRATE_IDX_VAL

ValueDescription
0x000000000000000BDefines the index for bf_vs_op_migrate

2.15.13. bf_vs_op_set_active, OP=0x6, IDX=0xC

Sets the active VM, VP and VS to the provided VM, VP and VS.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VM to set active
REG163:16REVI
REG215:0The ID of the VP to set active
REG263:16REVI
REG315:0The ID of the VS to set active
REG363:16REVI

const, uint64_t: BF_VS_OP_SET_ACTIVE_IDX_VAL

ValueDescription
0x000000000000000CDefines the index for bf_vs_op_set_active

2.15.14. bf_vs_op_advance_ip_and_set_active, OP=0x6, IDX=0xD

Advances the IP of the current VS and then sets the active VM, VP and VS to the provided VM, VP and VS.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VM to set active
REG163:16REVI
REG215:0The ID of the VP to set active
REG263:16REVI
REG315:0The ID of the VS to set active
REG363:16REVI

const, uint64_t: BF_VS_OP_ADVANCE_IP_AND_SET_ACTIVE_IDX_VAL

ValueDescription
0x000000000000000DDefines the index for bf_vs_op_advance_ip_and_set_active

2.15.15. bf_vs_op_tlb_flush, OP=0x6, IDX=0xE

Given the ID of a VS, invalidates a TLB entry for a given GLA on the PP that this is executed on.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG115:0The ID of the VS to invalidate
REG163:16REVI
REG263:0The GLA to invalidate

const, uint64_t: BF_VS_OP_TLB_FLUSH_IDX_VAL

ValueDescription
0x000000000000000EDefines the index for bf_vs_op_tlb_flush

2.16. Intrinsic Syscalls

2.16.1. bf_intrinsic_op_rdmsr, OP=0x7, IDX=0x0

Reads an MSR directly from the CPU given the address of the MSR to read. Note that this is specific to Intel/AMD only. Also note that not all MSRs can be written to, and which MSRs that can be written to is up to the microkernel's internal policy as well as which architecture the hypervisor is running on.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG131:0The address of the MSR to read
REG163:32REVI

Output:

Register NameBitsDescription
REG063:0The resulting value

const, uint64_t: BF_INTRINSIC_OP_RDMSR_IDX_VAL

ValueDescription
0x0000000000000000Defines the index for bf_intrinsic_op_rdmsr

2.16.2. bf_intrinsic_op_wrmsr, OP=0x7, IDX=0x1

Writes to an MSR directly from the CPU given the address of the MSR to write and the value to write. Note that this is specific to Intel/AMD only. Also note that not all MSRs can be written to, and which MSRs that can be written to is up to the microkernel's internal policy as well as which architecture the hypervisor is running on.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG131:0The address of the MSR to write to
REG163:32REVI
REG263:0The value to write to the requested MSR

const, uint64_t: BF_INTRINSIC_OP_WRMSR_IDX_VAL

ValueDescription
0x0000000000000001Defines the index for bf_intrinsic_op_wrmsr

2.17. Mem Syscalls

Each extension has access to several different memory pools:

  • The page pool (used for allocating pages)
  • The huge pool (used for allocating physically contiguous pages)
  • TLS (used for thread-local storage)
  • The direct map

The page pool provides a means to allocate a page.

The huge pool provides a method for allocating physically contiguous memory. This pool is small and platform-dependent (as in less than a megabyte total). It should be noted that some microkernels may choose not to implement bf_mem_op_free_huge which is optional.

Thread-Local Storage (TLS) memory (typically allocated using thread_local) provides per-physical processor storage. The amount of TLS available to an extension is 1 page per physical processor.

The direct map provides an extension with a means to access any physical address by accessing the direct map region of the virtual address space (depends on the hypervisor's configuration). By default, on Intel/AMD with 4-level paging, this region starts at 0x0000600000000000, but it can be changed using CMake. An extension can access any physical address by simply adding 0x0000600000000000 to the physical address and dereferencing the resulting value. When a VM is destroyed, all physical memory maps associated with that VM will be removed. The direct map is also where page and huge page allocations are mapped, providing an extension with a simple means for performing a virtual address to physical address (and vice versa) translations.

2.17.1. bf_mem_op_alloc_page, OP=0x8, IDX=0x0

bf_mem_op_alloc_page allocates a page, and maps this page into the direct map of the VM.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle

Output:

Register NameBitsDescription
REG063:0The virtual address of the resulting page
REG163:0The physical address of the resulting page

const, uint64_t: BF_MEM_OP_ALLOC_PAGE_IDX_VAL

ValueDescription
0x0000000000000000Defines the index for bf_mem_op_alloc_page

2.17.2. bf_mem_op_free_page, OP=0x8, IDX=0x1

Frees a page previously allocated by bf_mem_op_alloc_page. This operation is optional and not all microkernels may implement it.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG163:0The virtual address of the page to free

Output:

Register NameBitsDescription

const, uint64_t: BF_MEM_OP_FREE_PAGE_IDX_VAL

ValueDescription
0x0000000000000001Defines the index for bf_mem_op_free_page

2.17.3. bf_mem_op_alloc_huge, OP=0x8, IDX=0x2

bf_mem_op_alloc_huge allocates a physically contiguous block of memory. When allocating a page, the extension should keep in mind the following:

  • The total memory available to allocate from this pool is extremely limited. This should only be used when absolutely needed, and extensions should not expect more than 1 MB (might be less) of total memory available.
  • Memory allocated from the huge pool might be allocated using different schemes. For example, the microkernel might allocate in increments of a page, or it might use a buddy allocator that would allocate in multiples of 2. If the allocation size doesn't match the algorithm, internal fragmentation could occur, further limiting the total number of allocations this pool can support.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG163:0The total number of bytes to allocate

Output:

Register NameBitsDescription
REG063:0The virtual address of the resulting memory
REG163:0The physical address of the resulting memory

const, uint64_t: BF_MEM_OP_ALLOC_HUGE_IDX_VAL

ValueDescription
0x0000000000000002Defines the index for bf_mem_op_alloc_huge

2.17.4. bf_mem_op_free_huge, OP=0x8, IDX=0x3

Frees memory previously allocated by bf_mem_op_alloc_huge. This operation is optional and not all microkernels may implement it.

Input:

Register NameBitsDescription
REG063:0Set to the result of bf_handle_op_open_handle
REG163:0The virtual address of the memory to free

Output:

Register NameBitsDescription

const, uint64_t: BF_MEM_OP_FREE_HUGE_IDX_VAL

ValueDescription
0x0000000000000003Defines the index for bf_mem_op_free_huge