VPOS is an operating system designed (primarily for fun) with the end goal of creating an OS from scratch. We hope to eventually implement advanced features such as native shared library linking support, a GUI interface, etc. with minimal support from existing tutorials, so we can arrive at our own solutions and, hopefully, learn a lot about the methodology and issues which arise through this development.
The original version of this repo can be found at BestVG/VPOS. For the moment, BestVG is working on other projects, so to ensure his repo stays true to his vision for the project, I will be making changes here for the forseeable future.
We are working on migrating the built live-image file to be a functional FAT-32 partition. At the moment, is arranged as follows:
1st sector (loaded to 0x7C00
): boot_section (Contains some FAT-32 metadata; ends with word 0xaa55
)
2nd sector: FS_INFO sector (More FAT-32 metadata)
(dynamic) (loaded to 0x1000
): kernel code (Note: due to the dynamic nature of kernel code, the following sections may not fall exactly on sector boundaries)
Next 2 sectors (1024 bytes): Reserved for the stack
Next 10 sectors (5120 bytes): Reserved for malloc (heap)
After this, any remaining space in the sector is padded with 0x00
Memory Map (Will be loaded from BIOS into 0x500
)
Page Tables (Will be generated at 0x100000
)
At the moment, the process for booting the OS is as follows:
- Begin Program
- Jump over FAT_32 metadata
- Setup a small stack (
ss = 0x07e0
sp = 0x1200
) - Load the kernel from disk (to
0x1000
) - Enable
A20 line
- Jump to kernel
- Make sure CPU supports all required features (See Feature Checks)
- Load the memory map from BIOS (into
0x8000
) (Seeint 0x15, eax=0xE820
) - Load GDT
- Enable protected mode in
cr0
- Set all segment registers (besides CS) to the data segment
- Update the 32-bit stack pointer to use the stack defined in the kernel
- Enable Physical Address Extensions (PAE) in
cr4
- Generate page tables (starting at
0x100000
) - Store page table location in
cr3
- Enable long mode in
EFER_MSR
- Enable paging in
cr0
- Jump to 64-bit kernel code
- Reset 64-bit stack pointer to the kernel stack
- Jump to kernel_main
- Check that the CPU supports
cpuid
by changing the CPUID bit inEFLAGS
- Check that the CPU's vendor id matches "
AuthenticAMD
" or "GenuineIntel
" (eax = 0x00
should return valid values inebx
edx
andecx
) - Check that the
cpuid
instruction supports all of theleaves
required to check the remaining features (eax = 0x00
should returneax >= 0x01
, andeax=0x80000000
should returneax >= 0x80000001
) - Check that long mode is supported (
eax = 0x80000001
should returnedx & 0x20000000 = 0x20000000
) - Check that model specific registers are supported (
eax = 0x1
should returnedx & 0x00000020 = 0x00000020
) - Check that all required paging features are supported (PSE, PAE, PAT, and PSE36) (
eax = 0x1
should returnedx & 0x00030048 = 0x00030048
) - Check that APIC is supported (
eax = 0x1
should returnedx & 0x0000200 = 0x0000200
)
If any of the above checks fail, the user will be notified and given the option to ignore the error (at risk).
The Makefile
contains the following targets
build
: Builds the bin/live-image
binary which contains the compiled OS
clean
: Deletes the bin
directory, effectively removing the binaries from all previous builds
rebuild
: Runs clean
followed by a build
run
: Attempts to build and run the live-image
using QEMU
debug
: Attempts to build and run the live-image
using QEMU with guest_errors
logging enabled to log.txt
disk
: Builds the live-image
and packages it in bin/disk.vdi
run-vbox
: Builds bin/disk.vdi
and attempts to start a VPOS
vm in VirtualBox. (This assumes that a vm named VPOS
is already configured in VirtualBox)
*.mem
: Connects to a running VirtualBox machine and dumps the memory to the requested file