Skip to content

Instantly share code, notes, and snippets.

@deomorxsy
deomorxsy / every-vm-tutorial-you-ever-studied-is-wrong.md
Created October 22, 2024 19:40 — forked from o11c/every-vm-tutorial-you-ever-studied-is-wrong.md
Every VM tutorial you ever studied is wrong (and other compiler/interpreter-related knowledge)

Note: this was originally several Reddit posts, chained and linked. But now that Reddit is dying I've finally moved them out. Sorry about the mess.


URL: https://www.reddit.com/r/ProgrammingLanguages/comments/up206c/stack_machines_for_compilers/i8ikupw/ Summary: stack-based vs register-based in general.

There are a wide variety of machines that can be described as "stack-based" or "register-based", but not all of them are practical. And there are a lot of other decisions that affect that practicality (do variables have names or only address/indexes? fixed-width or variable-width instructions? are you interpreting the bytecode (and if so, are you using machine stack frames?) or turning it into machine code? how many registers are there, and how many are special? how do you represent multiple types of variable? how many scopes are there(various kinds of global, local, member, ...)? how much effort/complexity can you afford to put into your machine? etc.)

  • a pure stack VM can only access the top elemen
@deomorxsy
deomorxsy / riscv.md
Created August 1, 2024 22:15 — forked from cb372/riscv.md
Writing an OS in Rust to run on RISC-V

(This is a translation of the original article in Japanese by moratorium08.)

(UPDATE (22/3/2019): Added some corrections provided by the original author.)

Writing your own OS to run on a handmade CPU is a pretty ambitious project, but I've managed to get it working pretty well so I'm going to write some notes about how I did it.

@deomorxsy
deomorxsy / setup-qus-rpi.md
Last active June 7, 2024 20:29
Debug a raspberry pi 3 model b v1.2 - raspberry pi 2015 on a 6.9.0-1-MANJARO LiveCD with qemu-user-static, binfmt_misc and chroot
sudo pacman -Sy yay lib32-ncurses ncurses tmux qemu-user-static qemu-user-static-binfmt neovim
setxkbmap -model abnt2 -layout br -variant abnt2

cat <<"EOF" > ~/.tmux.conf
## ~/.tmux.conf

## Use vim keybindings in copy mode
set-option -g mouse on
setw -g mode-keys vi

ELF Format Cheatsheet

Introduction

Executable and Linkable Format (ELF), is the default binary format on Linux-based systems.

ELF

Compilation

@deomorxsy
deomorxsy / ccr.sh
Created April 18, 2024 22:10
ccr: check container runtime. If podman exists, set the DOCKER_HOST variable to the Podman Service systemd's socket unit file, part of Podman API. Inspired by @/rhatdan's Podman in Action
#!/usr/bin/bash
#
# ccr: check container runtime
#
checker() {
exists_wgh=$(which podman 2>&1 | grep -o "no" | head -n 1)
exists_command=$(command -v podman &>/dev/null)
# bash square bracket eval to check for empty expanded variable in a string,
@deomorxsy
deomorxsy / slim-rust-oci.md
Last active April 15, 2024 14:24
on running slim rust (and calling wasm with wasm-bindgen) binaries inside OCI containers: common return messages

slim Rust+wasm OCI Containers: common error return messages

This post covers the outcome of a multi-stage Dockerfile for Rust, which handles the app artifact binary to the last layer, discarding the build layer.

  • High-level container runtime: Podman
  • Low-level container runtime: crun
  • Trunk with wasm-bidgen as dependency for a Yew project.

OCI Setup specs:

@deomorxsy
deomorxsy / gallery-cli.md
Created April 15, 2024 02:07
find all filetype png, sort by time, newest first, grep a pattern, filter the stream of its filename and pass the filename as stdin to the sxiv image viewer.
@deomorxsy
deomorxsy / virtual_storage.md
Last active April 8, 2024 05:25
storage virtualization handling for QEMU and others

Virtual Storage for QEMU

quick notes about the different ways to handle storage virtualization for QEMU

0. mknod

[31/03/2024 10:07] mknod can be used for creating block or character special files, such asdevice nodes (special directories). It is an alternative for the powerful dd command which could wipe your root system at runtime.

@deomorxsy
deomorxsy / jar.md
Last active April 7, 2024 19:46
handling jar compressed files

Handling jar compressed files

Quick notes about handling jars on the CLI in maven projects with java. Dependencies:

  • jar
  • unzip
  • mvn

generate jar passing the directory the pom.xml is located:

; mvn package -f ./server/
@deomorxsy
deomorxsy / update-git-fork.md
Last active March 6, 2024 00:33
commands to update the git repo fork from the upstream
# check the origin
git ls-remote --get-url origin

# add remote
## for configured SSH environments as remote connection:
git remote add upstream [email protected]:{user/org}/repo.git
## for for configured HTTPS environments as remote connection:
git remote add upstream https://github.com/{user/org}/repo.git