fubarnetes / bhyve-multiboot Goto Github PK
View Code? Open in Web Editor NEWWIP: Multiboot bootloader for bhyve
License: BSD 3-Clause "New" or "Revised" License
WIP: Multiboot bootloader for bhyve
License: BSD 3-Clause "New" or "Revised" License
At the moment the coverage isn't really working. This is most likely an issue with clang / llvm-cov.
Instead of using fopen(3)
, fseek(3)
, ftell(3)
, fclose(3)
and fileno(3)
, use
callbacks->open(void *arg, const char *filename, void **h_return);
callbacks->close(void *arg, void *h);
callbacks->read(void *arg, void *h, void *dst, size_t size, size_t *resid_return);
callbacks->seek(void *arg, void *h, uint64_t offset, int whence);
callbacks->stat(void *arg, void *h, int *mode_return, int *uid_return, int *gid_return, uint64_t *size_return);
The following code to get the file size will have to be rewritten using stat(2)
to get the file size.
Lines 428 to 431 in f0d394f
bhyveload's copyin cannot copy into highmem, and will just wrap around when trying to:
bhyve-multiboot/tests/mock/bhyveload.c
Line 323 in 2cab4f7
We have to make sure this doesn't happen (e.g. by ELF files that have segments in highmem). This may only be an issue using 64 bit ELFs, see #5.
See Section 3.1.1 of the spec and fabianfreyer@e952761 for reference
Lines 186 to 190 in ff5a9bc
mbi->mem_lower
and mbi->mem_upper
and set bit 0 of mbi->flags
.mbi->mmap_addr
to it, set mbi->mmap_length
, and set bit 6 of mbi->flags
.mbi->flags
is cleared, as specified:
If bit 1 in the ‘flags’ word is set, then the ‘boot_device’ field is valid, and indicates which bios disk device the boot loader loaded the OS image from. If the OS image was not loaded from a bios disk, then this field must not be present (bit 3 must be clear).
cmdline
is given, copy it into the hypervisor, and set mbi->cmdline and set bit 2 of mbi->flags.modules
are given, parse their command-line specification and load them:
mbi->mods_addr
to it and set mbi->mods_count
mbi->flags
. copy the bootloader name into the guest and point mbi->boot_loader_name
to it.userboot.h
as stubs, and dlopen(3)
libmultiboot.so.Currently, the allocator doesn't use any memory map and assumes all memory is usable.
Getting the memory map early would help #4.
Lines 186 to 190 in ff5a9bc
For the bhyve memory map, see grub2-bhyve's implementation:
/*
* bhyve is going to return the following memory segments
*
* 0 - 640K - usable
* 640K- 1MB - vga hole, BIOS, not usable.
* 1MB - lomem - usable
* lomem - 4G - not usable
* 4G - himem - usable [optional if himem != 0]
*/
bhyve_info.nsegs = 2;
bhyve_info.segs = bhyve_mm;
bhyve_mm[0].start = 0x0;
bhyve_mm[0].end = 640*1024; /* 640K */
bhyve_mm[0].type = GRUB_MEMORY_AVAILABLE;
bhyve_mm[1].start = 1024*1024;
bhyve_mm[1].end = (memsz > lomemsz) ? lomemsz : memsz;
bhyve_mm[1].type = GRUB_MEMORY_AVAILABLE;
if (memsz > lomemsz) {
bhyve_info.nsegs++;
bhyve_mm[2].start = 4*GB;
bhyve_mm[2].end = (memsz - lomemsz) + bhyve_mm[2].start;
bhyve_mm[2].type = GRUB_MEMORY_AVAILABLE;
}
An easy fix might just be:
MIN_ALLOC_ADDRESS
to the start of the 1 MiB - Lowmem segmentlomem
to 4 GiB to reserve itThe tests load_aout_direct
and load_elf_direct
only check the return values of the load functions:
bhyve-multiboot/tests/test-multiboot.c
Lines 214 to 228 in 63cc3d7
bhyve-multiboot/tests/test-multiboot.c
Lines 302 to 306 in 63cc3d7
Instead they should also verify that copyin
actually copied something. Probably the best idea is to
lowmem_buffer
and highmem_buffer
pointers from mock_bhyveload.c
We need a corpus of test kernels to test with. There's a few options we could go with here:
Non-functional kernels:
Functional test kernels:
grub-core/tests/boot/kernel-${ARCH}.S
, and can be built using make multiboot.elf
and make multiboot2.elf
, respectively. These are licensed under the GPL though, not sure if they can simply be incorporated.If bit 0 of the multiboot header flags indicates the kernel requests the to be loaded at a 4k-aligned offset. In this case, use allocate_aligned
instead of allocate
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.