1 #include "kvm/kvm.h" 2 3 #include "kvm/util.h" 4 5 #include <sys/types.h> 6 #include <sys/stat.h> 7 #include <stdbool.h> 8 #include <fcntl.h> 9 10 #define BIOS_SELECTOR 0xf000 11 #define BIOS_IP 0xfff0 12 #define BIOS_SP 0x8000 13 kvm__load_firmware(struct kvm * kvm,const char * firmware_filename)14bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename) 15 { 16 struct stat st; 17 void *p; 18 int fd; 19 int nr; 20 21 fd = open(firmware_filename, O_RDONLY); 22 if (fd < 0) 23 return false; 24 25 if (fstat(fd, &st)) 26 return false; 27 28 if (st.st_size > MB_FIRMWARE_BIOS_SIZE) 29 die("firmware image %s is too big to fit in memory (%Lu KB).\n", firmware_filename, (u64)(st.st_size / 1024)); 30 31 p = guest_flat_to_host(kvm, MB_FIRMWARE_BIOS_BEGIN); 32 33 while ((nr = read(fd, p, st.st_size)) > 0) 34 p += nr; 35 36 kvm->arch.boot_selector = BIOS_SELECTOR; 37 kvm->arch.boot_ip = BIOS_IP; 38 kvm->arch.boot_sp = BIOS_SP; 39 40 return true; 41 } 42