+my $host_arch; # FIXME: fix PVE::Tools::get_host_arch
+sub get_host_arch() {
+ $host_arch = (POSIX::uname())[4] if !$host_arch;
+ return $host_arch;
+}
+
+sub is_native($) {
+ my ($arch) = @_;
+ return get_host_arch() eq $arch;
+}
+
+my $default_machines = {
+ x86_64 => 'pc',
+ aarch64 => 'virt',
+};
+
+sub get_basic_machine_info {
+ my ($conf, $forcemachine) = @_;
+
+ my $arch = $conf->{arch} // get_host_arch();
+ my $machine = $forcemachine || $conf->{machine} || $default_machines->{$arch};
+ return ($arch, $machine);
+}
+
+sub get_ovmf_files($) {
+ my ($arch) = @_;
+
+ my $ovmf = $OVMF->{$arch}
+ or die "no OVMF images known for architecture '$arch'\n";
+
+ return @$ovmf;
+}
+
+my $Arch2Qemu = {
+ aarch64 => '/usr/bin/qemu-system-aarch64',
+ x86_64 => '/usr/bin/qemu-system-x86_64',
+};
+sub get_command_for_arch($) {
+ my ($arch) = @_;
+ return '/usr/bin/kvm' if is_native($arch);
+
+ my $cmd = $Arch2Qemu->{$arch}
+ or die "don't know how to emulate architecture '$arch'\n";
+ return $cmd;
+}
+
+sub get_cpu_options {
+ my ($conf, $arch, $kvm, $machine_type, $kvm_off, $kvmver, $winversion, $gpu_passthrough) = @_;
+
+ my $cpuFlags = [];
+ my $ostype = $conf->{ostype};
+
+ my $cpu = $kvm ? "kvm64" : "qemu64";
+ if ($arch eq 'aarch64') {
+ $cpu = 'cortex-a57';
+ }
+ if (my $cputype = $conf->{cpu}) {
+ my $cpuconf = PVE::JSONSchema::parse_property_string($cpu_fmt, $cputype)
+ or die "Cannot parse cpu description: $cputype\n";
+ $cpu = $cpuconf->{cputype};
+ $kvm_off = 1 if $cpuconf->{hidden};
+
+ if (defined(my $flags = $cpuconf->{flags})) {
+ push @$cpuFlags, split(";", $flags);
+ }
+ }
+
+ push @$cpuFlags , '+lahf_lm' if $cpu eq 'kvm64' && $arch eq 'x86_64';
+
+ push @$cpuFlags , '-x2apic'
+ if $conf->{ostype} && $conf->{ostype} eq 'solaris';
+
+ push @$cpuFlags, '+sep' if $cpu eq 'kvm64' || $cpu eq 'kvm32';
+
+ push @$cpuFlags, '-rdtscp' if $cpu =~ m/^Opteron/;
+
+ if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 3) && $arch eq 'x86_64') {
+
+ push @$cpuFlags , '+kvm_pv_unhalt' if $kvm;
+ push @$cpuFlags , '+kvm_pv_eoi' if $kvm;
+ }
+
+ add_hyperv_enlightenments($cpuFlags, $winversion, $machine_type, $kvmver, $conf->{bios}, $gpu_passthrough) if $kvm;
+
+ push @$cpuFlags, 'enforce' if $cpu ne 'host' && $kvm && $arch eq 'x86_64';
+
+ push @$cpuFlags, 'kvm=off' if $kvm_off;
+
+ if (my $cpu_vendor = $cpu_vendor_list->{$cpu}) {
+ push @$cpuFlags, "vendor=${cpu_vendor}"
+ if $cpu_vendor ne 'default';
+ } elsif ($arch ne 'aarch64') {
+ die "internal error"; # should not happen
+ }
+
+ $cpu .= "," . join(',', @$cpuFlags) if scalar(@$cpuFlags);
+
+ return ('-cpu', $cpu);
+}
+