Skip to content

Instantly share code, notes, and snippets.

View dramforever's full-sized avatar
🖤
dramming

dram dramforever

🖤
dramming
  • Scarlet Devil Mansion, Gensokyo
View GitHub Profile
use core::{
fmt,
ops::{Range, RangeInclusive},
};
/// A non-empty range of `usize` values
///
/// Like [`RangeInclusive`], `Region` can repesent any `usize` range, even those
/// that contain `usize::MAX`.
#[derive(Clone, Copy, PartialEq, Eq)]
\ https://www.cs.utexas.edu/users/EWD/transcriptions/EWD00xx/EWD28.html
: indvar create 0 , ['] @ ,
does> dup cell+ @ execute ;
: :=
>body
dup -rot ! \ Store value
cell+ ['] @ swap ! ; \ Make literal indvar
#include <stdio.h>
#include <stdlib.h>
#define DECL_STATE \
[[maybe_unused]] const struct word *const *ip, \
[[maybe_unused]] size_t *sp, \
[[maybe_unused]] const struct word *const **rsp
#define STATE ip, sp, rsp
struct word {
@dramforever
dramforever / _info.md
Last active April 6, 2023 16:16
How much RISC-V instruction space do we have left?

If you really want to use this janky code:

$ git clone https://github.com/riscv/riscv-opcodes
$ # You need like a patch to fix extension handling... might submit PR in a bit
$ python3 parse.py rv_* rv64_*
$ yaml2json < instr_dict.yaml > instr_dict.json # Sorry
$ python3 free-space.py
// QEMU emulator version 7.2.0
// qemu-system-riscv64 -M virt,aia=aplic-imsic,aia-guests=2,aclint=true,dumpdtb=dtb.dtb -smp 2
#include <dt-bindings/interrupt-controller/irq.h>
/dts-v1/;
/ {
compatible = "riscv-virtio";
model = "riscv-virtio,qemu";
@dramforever
dramforever / drawfb.c
Created February 15, 2023 07:15
Playing around with /dev/fb0
#define _GNU_SOURCE
#include <fcntl.h>
#include <linux/fb.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
int main() {
&gpio {
pinctrl-names = "default";
pinctrl-0 = <&gpiojtag_pins>;
gpiojtag_pins: gpiojtag-0 {
input-pins {
pinmux =
<GPIOMUX(1, GPO_LOW, GPO_DISABLE, GPI_CPU_JTAG_TCK)>,
<GPIOMUX(2, GPO_LOW, GPO_DISABLE, GPI_CPU_JTAG_TDI)>,
<GPIOMUX(3, GPO_LOW, GPO_DISABLE, GPI_CPU_JTAG_TMS)>;
@dramforever
dramforever / clkgen.txt
Last active July 13, 2022 18:30
(Partially) undocumented JH7100 registers found in headers
Register: clk_cpundbus_root_ctrl_REG_ADDR
Address: CLKGEN_BASE_ADDR + 0x0
31 24 16 8 0
| | | | |
[------<>------------------------]
'-------------------------- [25:24] (rw) clk_cpundbus_root_src
Register: clk_dla_root_ctrl_REG_ADDR
@dramforever
dramforever / Makefile
Last active March 3, 2022 09:06
Stack trace
CFLAGS += -fno-omit-frame-pointer -funwind-tables
LDFLAGS += -lunwind
.PHONY: all
all: stack-trace
.PHONY: clean
clean:
rm stack-trace
@dramforever
dramforever / nixenv.zsh
Last active March 14, 2024 17:45
nixenv
declare -A nixenv_paths
nadd() {
setopt local_options err_return pipefail
local out out_paths
for installable in "$@"; do
local with_outputs="$installable^*"
if [[ "$installable" = *"^"* ]]; then
with_outputs="$installable"
fi