Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Odin Kernel

(disclaimer: not actually a kernel)

A single-threaded 32-bit kernel-level program for the x86 architecture written in Odin, because why not.

Certainly Odin is better fitted to doing this than C++.

This project is set free under the Unlicense. Do with it as you wish, I only ask as a matter of courtesy (NOT legal requirement) that you credit me as appropriate.

Building & Running

(only instructions for Linux is provided)

NOTE: you have to have cross-compilation binaries for C installed at ~/opt/cross/bin to compile the kernel

Currently the Odin compiler does not by default support a freestanding x86 target. As such you'll have to patch the Odin compiler to get this project working.

See the heading "Patching the Odin compiler", and place your patched odin executable at ../Odin/odin.

You can build the kernel as follows:

$ ./build.sh

If you have QEMU installed you can run it as follows:

$ ./build.sh run                  # build and run
$ qemu-system-x86_64 -kernel myos # run only

You can also create a bootable ISO using grub-mkrescue by running the ./make_grub.sh script.

Patching the Odin compiler

Note that I have already applied these patches myself, you can also download my fork of Odin and switch to the i386 branch, but it is pretty much unmaintained so be warned. (It works on my laptop so I'm happy with it, if you experience issues you're on your own)

  1. Download the Odin compiler source into the same directory you downloaded this repo
  2. In Odin, open src/build_settings.cpp, and add the following code:
    • Around line 872:

      gb_global TargetMetrics target_freestanding_i386 = {
          TargetOs_freestanding,
          TargetArch_i386,
          4, 4, I386_MAX_ALIGNMENT, 16,
          str_lit("i386-unknown-elf"),
      };
      
    • Around line 940, after the entry for the freestanding_amd64_mingw target:

      { str_lit("freestanding_i386"), &target_freestanding_i386 },
      
  3. Build the compiler with ./build_odin.sh, and Voilà! you can now compile this project.

About

Playing around with kernel-level programming in Odin

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages