Skip to content

Instantly share code, notes, and snippets.

View ClarkThan's full-sized avatar
💤

Clark Than ClarkThan

💤
View GitHub Profile
# IDA (disassembler) and Hex-Rays (decompiler) plugin for Apple AMX
#
# WIP research. (This was edited to add more info after someone posted it to
# Hacker News. Click "Revisions" to see full changes.)
#
# Copyright (c) 2020 dougallj
# Based on Python port of VMX intrinsics plugin:
# Copyright (c) 2019 w4kfu - Synacktiv
@ClarkThan
ClarkThan / 1-cat-pdp7.s
Last active September 27, 2024 05:42 — forked from sinclairtarget/1-cat-pdp7.s
cat through the ages
" cat
lac 017777 i " Load accumulator (AC) with argument count
sad d4 " Skip next if we have more than 4 words of args
jmp nofiles " Otherwise, jump to nofiles
lac 017777 " Load AC with address of args
tad d1 " Increment AC by 1, past argument count
tad d4 " Increment AC by 4, now AC points to first real arg
dac name " Save arg pointer from AC into 'name'
@ClarkThan
ClarkThan / Stack.md
Created September 19, 2024 11:00 — forked from cpq/Stack.md
Why stack grows down

Why stack grows down

Any running process has several memory regions: code, read-only data, read-write data, et cetera. Some regions, such as code and read-only data, are static and do not change over time. Other regions are dynamic: they can expand and shrink. Usually there are two such regions: dynamic read-write data region, called heap, and a region called stack. Heap holds dynamic memory allocations, and stack is mostly used for keeping function frames.

Both stack and heap can grow. An OS doesn't know in advance whether stack or heap will be used predominantly. Therefore, an OS must layout these two memory regions in a way to guarantee maximum space for both. And here is the solution:

  1. Layout static memory regions at the edges of process's virtual memory
  2. Put heap and stack on edges too, and let them grow towards each other: one grows up, one grows down
@ClarkThan
ClarkThan / riscv.md
Created March 2, 2023 04:29 — 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.

@ClarkThan
ClarkThan / CoC.ml
Created February 27, 2023 03:16 — forked from hirrolot/CoC.ml
How to implement dependent types in 80 lines of code
type term =
| Lam of (term -> term)
| Pi of term * (term -> term)
| Appl of term * term
| Ann of term * term
| FreeVar of int
| Star
| Box
let unfurl lvl f = f (FreeVar lvl)
@ClarkThan
ClarkThan / binned_allocator.zig
Created February 3, 2023 04:37 — forked from silversquirl/.gitignore
A fast, simple allocator for Zig
const std = @import("std");
const builtin = @import("builtin");
pub const Config = struct {
/// Whether to synchronize usage of this allocator.
/// For actual thread safety, the backing allocator must also be thread safe.
thread_safe: bool = !builtin.single_threaded,
/// Whether to warn about leaked memory on deinit.
/// This reporting is extremely limited; for proper leak checking use GeneralPurposeAllocator.
@ClarkThan
ClarkThan / CoC.ml
Created December 13, 2022 09:24 — forked from hirrolot/CoC.ml
Barebones lambda cube in OCaml
type binder = Lam | Pi
(* The syntax of our calculus. Notice that types are represented in the same way
as terms, which is the essence of CoC. *)
type term =
| Var of string
| Appl of term * term
| Binder of binder * string * term * term
| Star
| Box
@ClarkThan
ClarkThan / lib.rs
Created August 7, 2022 08:25 — forked from Measter/lib.rs
Rust Perf Benchmark
#![feature(test)]
extern crate test;
#[cfg(test)]
mod tests {
use super::*;
use std::fs::{File};
use std::io::{BufWriter, Write, BufRead, BufReader};
#[bench]