~yerinalexey/scalc-os

Stack-based calculator that runs in ring 0
Implement memory load/store operations
Pass --no-undefined to the linker
kmain: fix invalid label

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~yerinalexey/scalc-os
read/write
git@git.sr.ht:~yerinalexey/scalc-os

You can also use your local clone with git send-email.

#scalc-os

What if we replace all big kernels and userspace with just a calculator? This should be enough.

Screenshot of a QEMU window with scalc-os doing simple operations

This project takes a lot of inspiration from scalc, hence the name. It implements only the surface functionality though - decimal integers and +, -, /, *, % operations plus additional commands:

  • . - print last value in the stack
  • d - drop last value from the stack
  • s - swap last two values
  • c - push a copy of the last value
  • m<character> - save last value to a named variable
  • l<character> - push the value of a named variable

Interactions are done through the default input device, in case of most systems, that would be serial. Entering a number to push it onto the stack works as expected, but the number has to be followed with any character to mark its ending.

#Running in QEMU

Throughout the build, a cross-compiler will be used. If one is not configured already, it's recommended to use riscv64-linux-musl from musl.cc. If anything else is used, make sure to set $CROSS_COMPILE to reflect that.

Also - POSIX dd, parted and mtools are needed to build the disk image.

$ make

Or:
$ make CROSS_COMPILE=riscv64-other-prefix-

To run it, a u-Boot build is necessary (by default, looked up in ../u-boot), see official QEMU instructions for more info.

$ make run

Default u-Boot configuration does not work correctly and isn't going to boot the image. So, press any key to pause startup and enter boot shell, then run:

=> virtio scan
=> load virtio 0:1 $kernel_addr_r /efi/boot/bootriscv64.efi
=> bootefi $kernel_addr_r

To not type this out every time, go to u-Boot source directory and run make menuconfig. In the menu, go into "Boot options", tick "Enable a default value for bootcmd" and set "bootcmd value" to virtio scan; load virtio 0:1 $kernel_addr_r /efi/boot/bootriscv64.efi; bootefi $kernel_addr_r. After that, save the configuration and rebuild u-Boot.