@@ -404,8 +404,18 @@ def cp(src, dest):
404
404
405
405
if platform .system () == 'Windows' :
406
406
limine_install = 'limine-install-win32.exe'
407
- elif platform .system () == 'Linux' or platform . system () == 'Darwin' :
407
+ elif platform .system () == 'Linux' :
408
408
limine_install = 'limine-install-linux-x86_64'
409
+ elif platform .system () == 'Darwin' :
410
+ limine_install = 'limine-install'
411
+ # Limine doesn't provide pre-built binaries, so we have to build from source
412
+ code , _ , limine_build_stderr = run_command (['make' , '-C' , limine_path ],
413
+ stdout = subprocess .PIPE ,
414
+ stderr = subprocess .PIPE )
415
+ if code != 0 :
416
+ print ('Failed to build `limine-install`' )
417
+ print (limine_build_stderr .decode ('utf8' ))
418
+ exit (1 )
409
419
410
420
limine_install = os .path .join (limine_path , limine_install )
411
421
@@ -445,23 +455,54 @@ def run_in_emulator(args, iso_path):
445
455
if is_kvm_available and not args .disable_kvm :
446
456
print ("Running with KVM acceleration enabled" )
447
457
448
- qemu_args += ['-enable-kvm' , '-cpu' ,
449
- 'host,+la57' if args .la57 else 'host' ]
458
+ if platform .system () == 'Darwin' :
459
+ qemu_args += ['-accel' , 'hvf' ]
460
+ else :
461
+ qemu_args += ['-enable-kvm' ]
462
+ qemu_args += ['-cpu' , 'host,+la57' if args .la57 else 'host' ]
450
463
else :
451
464
qemu_args += ["-cpu" , "qemu64,+la57" if args .la57 else "qemu64" ]
452
465
453
466
run_command (['qemu-system-x86_64' , * qemu_args ])
454
467
455
468
469
+ def get_sysctl (name : str ) -> str :
470
+ """
471
+ Shell out to sysctl(1)
472
+
473
+ Returns the value as a string.
474
+ Non-leaf nodes will return the value for each sub-node separated by newline characters.
475
+ """
476
+ status , stdout , stderr = run_command (["sysctl" , "-n" , name ],
477
+ stdout = subprocess .PIPE ,
478
+ stderr = subprocess .PIPE )
479
+ if status != 0 :
480
+ print ("`sysctl` failed: " , end = "" )
481
+ print (stderr .decode ())
482
+
483
+ return stdout .strip ().decode ()
484
+
485
+
456
486
def is_kvm_supported () -> bool :
457
487
"""
458
488
Returns True if KVM is supported on this machine
459
489
"""
460
490
461
- kvm_path = "/dev/kvm"
462
491
platform = sys .platform
463
492
493
+ if platform == "darwin" :
494
+ # Check for VMX support
495
+ cpu_features = get_sysctl ("machdep.cpu.features" )
496
+ vmx_support = "VMX" in cpu_features .split (' ' )
497
+
498
+ # Check for HVF support
499
+ hv_support = get_sysctl ("kern.hv_support" ) == "1"
500
+
501
+ return hv_support and vmx_support
502
+
464
503
if platform == "linux" :
504
+ kvm_path = "/dev/kvm"
505
+
465
506
# Check if the `/dev/kvm` device exists.
466
507
if not os .path .exists (kvm_path ):
467
508
return False
0 commit comments