github.com/MerlinKodo/gvisor@v0.0.0-20231110090155-957f62ecf90e/pkg/sentry/platform/kvm/kvm_arm64.go (about)

     1  // Copyright 2019 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  //go:build arm64
    16  // +build arm64
    17  
    18  package kvm
    19  
    20  import (
    21  	"github.com/MerlinKodo/gvisor/pkg/ring0"
    22  	"github.com/MerlinKodo/gvisor/pkg/sentry/arch"
    23  )
    24  
    25  type kvmOneReg struct {
    26  	id   uint64
    27  	addr uint64
    28  }
    29  
    30  // arm64HypercallMMIOBase is MMIO base address used to dispatch hypercalls.
    31  var arm64HypercallMMIOBase uintptr
    32  
    33  const KVM_NR_SPSR = 5
    34  
    35  type userFpsimdState struct {
    36  	vregs    [64]uint64
    37  	fpsr     uint32
    38  	fpcr     uint32
    39  	reserved [2]uint32
    40  }
    41  
    42  type userRegs struct {
    43  	Regs    arch.Registers
    44  	sp_el1  uint64
    45  	elr_el1 uint64
    46  	spsr    [KVM_NR_SPSR]uint64
    47  	fpRegs  userFpsimdState
    48  }
    49  
    50  type exception struct {
    51  	sErrPending    uint8
    52  	sErrHasEsr     uint8
    53  	extDabtPending uint8
    54  	pad            [5]uint8
    55  	sErrEsr        uint64
    56  }
    57  
    58  type kvmVcpuEvents struct {
    59  	exception
    60  	rsvd [12]uint32
    61  }
    62  
    63  // updateGlobalOnce does global initialization. It has to be called only once.
    64  func updateGlobalOnce(fd int) error {
    65  	err := updateSystemValues(int(fd))
    66  	ring0.Init()
    67  	physicalInit()
    68  	return err
    69  }