Git Product home page Git Product logo

zeldaos.x86_64's Introduction

ZeldaOS.x86_64

The 64bit version of ZeldaOS which is still written in C&GAS from scratch for study use. Its main goal this time is to support SMP and virtualization. it's able to run a game: tetris inside guest OS asciicast

how to build and run it?

It's handy to run the demo within the root of the repository on a nested-virtualization enabled Linux host(how to enable it?):

#KVM='--enable-kvm --cpu host' ZELDA64=/path/to/repo CC=gcc-4.8 make run

to clean the build, run:

#KVM='--enable-kvm --cpu host' ZELDA64=/path/to/repo CC=gcc-4.8 make clean

Features Inventory

Arch:x86_64 features

  • running in 64-bit long mode
  • SMP boot orchestration.
  • 64-bit IDT management
  • 64-bit segmentation/GDT management
  • Inter-processors Interrupt(IPI) management

Memory features

  • Customed physical memory detection
  • Level 4 paging(2MB pages and 4K pages)

Devices features

  • Basic 16-color video buffer managment
  • APIC(Advanced PIC) management(LAPIC and IOAPIC)
  • Basic serial port output management

Kernel features

  • cusomized bootloader(only support legacy BIOS boot)
  • PXE boot supported with https://github.com/goupaz/pxeboot
  • Synchronization primitives: spinlock...
  • Processor-local storage and per-cpu framework.
  • Kernel PANIC.

VM Monitor

  • Basic vmx mode switch(realmode, protected mode and 64-bit long mode)
  • Memory virtualization(with Intel VT-x EPT mechanism)
  • APIC virtualization(in progress)
  • IO emulation(PIO and MMIO)
  • IO devices(serial port, video and keyboard), details can be found from wiki
  • SMP virtualization(in progress)

screenshot of the demononstration.

The Game: Tetris running as guest OS: image of green window

ZeldaOS64 provides a normal video window to display some runtime information(TBC): image of green window

also we have pretty beautiful screen of death(like BSOD from Microsoft Windows, It's derived from VMware ESXi vmkernel: Purple Screen of Death:PSOD)

sreen of death

the output of serial port is streamed like: output of serial port

zeldaos.x86_64's People

Contributors

chillancezen avatar prettykernel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

zeldaos.x86_64's Issues

inline function ‘cpu’ declared but never defined

I have faced issue below:
sh# make
[CC] x86_64/processor_local_storage.c
In file included from x86_64/processor_local_storage.c:9:0:
./x86_64/include/lapic.h:87:17: error: inline function ‘cpu’ declared but never defined [-Werror]

License is missing

"Copyright" strings are present in the source, but I found no project's License.
For those interested to reuse your code, it would be nice to have it present.

In the case you have not decided which one to choose yet and should you like permissive approach (vs copyleft one), I offer you to consider the Blue Oak Model License announced by a lawyer a year ago:
https://writing.kemitchell.com/2019/03/09/Deprecation-Notice.html

Author also responds to some of the doubts here:
https://news.ycombinator.com/item?id=19347797

FEATURE Control MSR lock flag

Hi Jie, When I was trying boot to bare metal machine with PXE, But I got issue "!(eax & VMXON_LOCK_FLAG) failed". According to Intel manual Feature control msr lock flag is cleared when logical processor is reset.

VMXON is also controlled by the IA32_FEATURE_CONTROL MSR (MSR address 3AH). This MSR is cleared to zero when a logical processor is reset. ... Bit 0 is the lock bit. If this bit is clear, VMXON causes a general-protection exception. If the lock bit is set, WRMSR to this MSR causes a general-protection exception; the MSR cannot be modified until a power-up reset condition. System BIOS can use this bit to provide a setup option for BIOS to disable support for VMX. To enable VMX support in a platform, BIOS must set bit 1, bit 2, or both (see below), as well as the lock bit.
I wonder is it firmware depended issue?

Full log:

[info] vm_monitor/vmx_misc.c:37 cpu feature:vmx supported
[info] vm_monitor/vmx_misc.c:67 EAX LOCK 5
[assert] vm_monitor/vmx_misc.c:72 !(eax & VMXON_LOCK_FLAG) failed
[info] x86_64/panic.c:71 cpu:0, idt.base:0x257000 idt.size:0xfff
[info] x86_64/panic.c:73 tr:0x450028, gdt.base:0x211038 gdt.size:0x427
[info] x86_64/panic.c:75 fs.base:0x0, gs.base:0x0 efer:0x500
[info] x86_64/panic.c:77 cr4:0x20, cr3:0x845c000, cr2:0x0, cr0:0x80000011
[info] x86_64/panic.c:110     frame #0 <205106>
[info] x86_64/panic.c:110     frame #1 <20657e>
[info] x86_64/panic.c:110     frame #2 <20069e>
[info] x86_64/panic.c:110     frame #3 <20086f>
[info] x86_64/panic.c:110     frame #4 <200044>


Capture

BTW: I've loaded kernel successfully to bare metal machine with PXE :).

QEMU TCG doesn't support VMX

ZeldaOS is used QEMU TCG as accelerator but TCG doesn't support VMX. That's why I've changed accelerator as enable-kvm.
Issue for TCG:
warning: TCG doesn't support requested feature: CPUID.01H:ECX.vmx [bit 5]
warning: TCG doesn't support requested feature: CPUID.01H:ECX.vmx [bit 5]
warning: TCG doesn't support requested feature: CPUID.01H:ECX.vmx [bit 5]
warning: TCG doesn't support requested feature: CPUID.01H:ECX.vmx [bit 5]

Command line:
qemu-system-x86_64 -enable-kvm -cpu host,-kvm_pv_eoi,-kvm_steal_time,-kvm_asyncpf,-kvmclock,+vmx -drive file=Zelda64.img,if=ide -smp 4 -m 1024 -serial stdio -monitor null -nographic

could ZeldaOS fit on a floppy?

Even today the floppies are still being used, for example - as virtual floppies inside the coreboot open source BIOS. Just imagine: your wonderful OS could be a part of someone's BIOS build! (for coreboot supported motherboard, maybe you have or could get one - see https://www.coreboot.org/Supported_Motherboards )

@chillancezen , If you already have a coreboot-supported motherboard, or a real chance to get one, - wouldn't it be cool to be able to launch your own OS straight from the BIOS chip? ;) With one simple command its possible to add any floppy to coreboot BIOS build - and then you see it as a boot entry! Multiple floppies could be added this way (as long as you have enough space left inside the BIOS flash chip, luckily LZMA compression could be used for the stored floppies to reduce their occupied size)

Settings for Guest HLT bitmap

I've configured CPU_BASED_VM_EXEC_CONTROL bitmap for handling hlt instruction to exit to host state. But it didn't worked correctly. I expected interrupt handler when executing vm_exit_handler procedure. Do you have any idea about that?


.section .text
.code64

.global vm_exit_handler
.global halting


halting:
	hlt


vm_exit_handler:

    int $0x45
    hlt


void trampoline(void){
    __asm__("hlt");
}


static void
initialize_vmcs_guest_state(struct vmcs_blob *vm)
{
#define _(encoding, value) {                                                   \
    ASSERT(vmx_write((encoding), (value)) == ERROR_OK);                        \
    ASSERT(vmx_read((encoding)) == (value));                                   \
}
    unsigned long val;
    val = read_msr(MSR_IA32_VMX_PROCBASED_CTLS);
    val |= CPU_BASED_HLT_EXITING;
    _(CPU_BASED_VM_EXEC_CONTROL, (uint32_t)val);
    _(GUEST_RIP, (uint64_t)&halting);

    _(VMCS_LINK_POINTER, -1UL);
#undef _
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.