Git Product home page Git Product logo

nimkernel's Introduction

nimkernel

This is a small 32bit (i686) kernel written using the Nim programming language.

I have been wanting to do this for a while but it wasn't until people in the #nim IRC channel inquired about Nim OS dev and the rustboot kernel inspired me that I finally did it.

It doesn't do much, but it doesn't need to. Its purpose is to provide a starting point for anyone wishing to write an OS in Nim.

It still manages to do a little more than fill a screen with a certain color. Nimkernel implements:

  • A writeString function which shows a string on screen in a specified position.
  • A rainbow function which shows a string with a rainbow-like text foreground color differentiation in a specified position.
  • Some simple error handling by implementing Nim system.nim's panic function.
  • Support for 16 colors with a brilliant type safe API!

Note: The error at the bottom is intentional, it is used to show that the error handling works properly.

Setup

You are required to have:

  • QEMU
  • a C and asm cross-compiler for i686
  • Nim 1.6.0 or higher
  • nimble (*)

* You can always grab the nake library manually from here.

Linux

I have performed this setup on a Arch Linux machine, but all other distros should work too.

Building a cross compiler

For more information take a look at the OSDev article.

You will need to download the source of binutils and gcc.

First cd into a suitable directory in which you would like to download, unzip and build the cross compiler. Then perform the following actions:

$ wget https://ftp.gnu.org/gnu/binutils/binutils-2.37.tar.xz
$ tar -xJf binutils-2.37.tar.xz
$ cd binutils-2.37
$ mkdir build && cd build
$ ../configure --target=i686-elf --prefix=$HOME/cross-tools/ --with-sysroot --disable-nls --disable-werror
$ make -j$(nproc)
$ make install

You may then grab the GCC source and build it:

$ wget https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz
$ tar -xJf gcc-11.2.0.tar.xz
$ cd gcc-11.2.0
$ mkdir build && cd build
$ ../configure --target=i686-elf --prefix=$HOME/cross-tools/ --disable-nls --enable-languages=c --without-headers
$ make all-gcc -j$(nproc)
$ make all-target-libgcc -j$(nproc)
$ make install-gcc
$ make install-target-libgcc

You should then have a i686-elf-gcc and i686-elf-as executable in $HOME/cross-tools/bin/ or somewhere thereabouts. You should then add it to your PATH permanently or temporarily by doing:

export PATH=$PATH:$HOME/cross-tools/bin

Downloading cross compiler binaries

If for some reason you either can't or don't want to build your own toolchain you can grab binaries from https://github.com/lordmilko/i686-elf-tools/releases

Please note that these are a bit outdated but they are confirmed to work.

Nim setup

Follow the instructions in the Nim repo to bootstrap Nim and put it in your PATH.

Do the same for nimble and install nake by executing nimble install nake or alternatively just save nake into the root dir of this repo.

You can then compile the nakefile and therefore compile nimkernel:

$ nim c nakefile
$ ./nakefile run

This will automatically build and run the kernel using QEMU.

License

Nimkernel is licensed under the MIT license.

nimkernel's People

Contributors

corytodd avatar def- avatar dom96 avatar sudo-d4s3 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nimkernel's Issues

try switch --gcc.linkerexe

Hey @dom96, why not try --gcc.linkerexe, through this you might not need to list all *.o files passed to the compiler for linking, which means when you add some new modules, you can just run and there is no need to figure out all the compiled result just like writing a Makefile when using C. :-)

Actually, I have just written a kernel on riscv, which is highly inspired by your awesome proj. Thanks a lot :P

Below is the compile flags of my little kernel when building:

https://github.com/sslime336/nimkernel-riscv/blob/master/nakefile.nim#L69-L70

RaspberryPi conversion?

Could this project be adapted for the RaspberryPi?
What would be the needed steps to take to convert it?

Thanks

Doesn't compile (or run properly)

Probably this repo isn't maintained anymore, but doesn't compile because nimcache/stdlib_system.o and nimcache/stdlib_unsigned.o referenced in nakefile.nim are nowhere to be found.

I managed to make it work by linking all *.o files in nimcache, but QEMU gets stuck at boot.

Nice proof of concept though.

invalid instruction suffix

./nakefile run
/tmp/ccDbBZ4I.s: Assembler messages:
/tmp/ccDbBZ4I.s:51: Error: invalid instruction suffix for push' /tmp/ccDbBZ4I.s:56: Error: invalid instruction suffix for push'
/tmp/ccDbBZ4I.s:58: Error: invalid instruction suffix for push' /tmp/ccDbBZ4I.s:62: Error: invalid instruction suffix for pop'

nimkernel broken when use Clang with -d or -opt flags

Hello,

I had some experiment with you code, that was fun and thank for creating this example. I try to use Clang with you kernel with exact config you do, some function broken weirdly and loop QEMU BIOS when i use flag like -d:release or -opt:speed the kernel goes to that state, but it totally fine without any -d or -opt.

I trace the culprit belong to this line : https://github.com/ArjunRangga/nimkernel/blob/clang/ioutils.nim#L77 , when it invoked by kmain.

Here my code : https://github.com/ArjunRangga/nimkernel/tree/clang .

Do you had idea what happen ? or I miss something? Anyways, It pass compilation either with flags or not.

missing string.h

Not an issue, just a question.

I can build the nakefile but trying to run the nakefile generates an error stating that string.h cannot be found. I'm pretty sure my cross compiler is fine because I can build the bare bones sample from OS dev. Any ideas on what I'm missing?

I'm thinking it is related to this line in nim.cfg: --passc:"-w -I$lib -ffreestanding -O2 -Wall -Wextra"
What should $lib resolve to?

/build/path/nimkernel/nimcache/stdlib_system.c:12:20: fatal error: string.h: No such file or directory

Cannot run nakefile

Hey, ive run into an issue trying use the nakefile. the nakefile does compile, but when using the run task, it errors:
Linking....
$HOME/cross-tools/lib/gcc/i686-elf/11.2.0/../../../../i686-elf/bin/ld: cannot find nimcache/stdlib_system.nim.c.o: No such file or directory

The object file that its looking for is not in nimcache, but there is a file named @m..@[email protected]@[email protected]@[email protected] and its corresponding c file. I tried copying both files and renaming them to what the nakefile wants, and it sorta bypasses the error but throws a warning and then another error:
$HOME/cross-tools/lib/gcc/i686-elf/11.2.0/../../../../i686-elf/bin/ld: warning: section `.bss' type changed to PROGBITS
Done.
sh: 1: qemu-system-i386: not found

Isnt this file just a necessary file that the nim compiler generates? It doesn't seem to be doing much, just defining nim structures in c.

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.