xieby1’s cheatsheet
General
符号
- ’🐁’仅在我的配置下可用,并不通用
Android
apktool
apktool d <APK_FILE>apt
proxy
# /etc/apt/apt.conf
Acquire::http::Proxy "http://10.90.50.122:8889";awk
print nth to last
Using awk to print all columns from the nth to the last
# Print all but the first column
awk '{$1=""; print substr($0,2)}' somefile
# Print all but the fisrt two columns
awk '{$1=$2=""; print substr($0,3)}' somefiledelimiter
awk -F'[, ]' '{print $1 " " $2}'sum column
awk '{sum+=$1} END {print sum}'bash
args length
$# # not include command
$ miao.sh wang # $# is 1args range
same to array
${@:3:2} # from position 3, length 2
${@:3} # from position 3, to lastcd last dir
参考bash手册关于cd的说明
# 等价于cd $OLDPATH
cd -commentable string concat
CMD=(
    "args"
    "${OTHER_ARGS[@]}"
)
eval "${CMD[@]}" # "${CMD[*]}"conditional constructs
if test-commands; then
  consequent-commands;
[elif more-test-commands; then
  more-consequents;]
[else alternate-consequents;]
fi- if its return 0,
- consequent-commands are executed
 
exit on fail
set -o errexitfunc src file
SO: find definition of bash func
shopt -s extdebug
declare -F <func>
shopt -u extdebughere document
COMMAND <<InputComesFromHERE
# ...
InputComesFromHEREparallel execution
N=4
for i in {a..z}; do
  (
    # do your stuff here
  ) &
  if [[ $(jobs -r -p | wc -l) -ge $N ]]; then
    wait -n
  fi
done
wait
echo all doneprint command
# see `help set`
set -x # turn on
set +x # turn offread file lines
while read line
do
    echo "$line"
done < filetest a var is num
How do I test if a variable is a number in Bash?
re='^[0-9]+$'
if [[ $yournumber =~ $re ]]
then
   echo "is a num!"
fitrace
set -o xtracebinfmt
i386
echo ':i386:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfa\xff\xff:/usr/local/bin/qemu-i386:' >/proc/sys/fs/binfmt_misc/registerqemu
sudo ./scripts/qemu-binfmt-conf.sh  --qemu-path /usr/local/bin/qemu-x86_64 --systemd x86_64x64
echo ':x64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00:\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-x86_64:' >/proc/sys/fs/binfmt_misc/registercmake
NOTED
cmake use CMakeCache.txt
If meet unexpected behavior,
clean all cmake generated files
compile_command.json
-DCMAKE_EXPORT_COMPILE_COMMANDS=1log
- CMakeFiles/CMakeError.log
- CMakeFiles/CMakeOutput.log
verbose
# 命令行
--log-level=VERBOSE
# 环境变量
export CMAKE_MESSAGE_LOG_LEVEL=VERBOSEcontainer
rootless podman not support NFS
See: * man podman * containers-storage.conf.5
Solution: save images in non-nfs FS
# $HOME/.config/containers/storage.conf
[storage]
driver = "overlay"
rootless_storage_path = "/tmp/xieby1/containers/storage"Then,
rm -rf $HOME/.local/share/containers/storage
podman system migratebuild show stdout
--progress=plainls containers
docker ps -asls imgs
docker images -aprune
docker system prunerm all-containers
docker ps -aq | xargs docker rmrm all-imgs
docker images -aq | xargs docker rmirm container
docker rm <containers>rm img
docker rmi <images>rm untagged-img
podman images | grep "^<none>" | awk '{print $3}' | xargs podman rmistop containers
docker stop <containers>build
podman build --network=host -t <tag>image mount
podman unshare
podman image mount <image>run
podman run --rm --network=host -it <image>debugger
--cap-add=SYS_PTRACEdd
extract bytes from file
https://stackoverflow.com/questions/1423346
Noted: dd only take decimal number, 0x prefix does not work.
dd skip=<start> count=<size> if=<input> of=<output> bs=1disk
dd
dd if=<INPUT/PATH> of=/dev/<OUTPUT> status=progressdisk usage
df -hfile folder-size
du -sBM * | sort -nfile
查看meta info,例如pdf,详细见man
exiftool -Title=<title> <file>
exiftool -Author=<author> <file>Detect file types with deep learning
https://github.com/google/magika
magikafiglet
example
http://www.figlet.org/examples.html
fonts
firefox
debug extension
- about:debugging
- This Firefox
- … Inspect
- top-right: Select an iframe as the currently targeted document
toolbox mode
- Developer Tools (F12)
- Settings (F1)
- Advanced Settings
- “Enable browser chrome and add-on debugging toolboxes”
- “Enable remote debugging”
 
 
- Advanced Settings
 
- Settings (F1)
Ctrl + Alt + Shift + I
font
list
fc-list
fc-scangoogle-fonts
repo: GH: google/fonts/ofl/
search: fonts.google.com
grub
sudo grub-mkfont -s 36 -o /boot/grub/fonts/DejaVuSansMono.pf2 /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf
fc-list
vim /boot/grub/grub.cfgtty
otf2bdf -r 242 -p 36 /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf -o ~/Desktop/DejaVuSansMono.bdffreebsd
increase disk
Increase qcow2 2GB
qemu-img resize <.qcow2> +2GInside FreeBSD
camcontrol reporbe ada0
# find out index
gpart show
gpart resize -i <index> ada0
growfs /linuxulator
# edit /etc/rc.conf
linux_enable="YES"service linux startgcc
default -march
gcc -Q --help=targetnative -march
gcc -march=native -Q --help=targetinline asm
No clobber, may segment fault! Just an example.
#include <stdio.h>
int a = 10;
int b = 20;
int result;
int main(void)
{
   asm( "mov a, %eax\n\t"
        "mov b, %ebx\n\t"
        "add %ebx, %eax\n\t"
        "mov %eax, result");
   printf("the result is %d\n", result);
   return 0;
}extended inline asm
#include <stdio.h>
int a = 10;
int b = 20;
int result;
int main(void)
{
   asm( "mov a, %%eax\n\t"
        "mov b, %%ebx\n\t"
        "add %%ebx, %%eax\n\t"
        "mov %%eax, result"
        : /* no outputs*/
        : /* no inputs */
        : "eax", "ebx");
   printf("the result is %d\n", result);
   return 0;
}predefined macros
2012.SO: preprocessor defined macros
gcc -dM -E - < /dev/null
touch bla.c && gcc -dM -E bla.ctext segment addr
gcc -static -Wl,-Ttext=0x1000 <Args>gdb
frame
bt
frame <bt num>
info frame <bt num>
info localsgem5
terminology
Simulation Mode
- Full System (FS)
- Syscall Emulation (SE)
cache
- mshr: Miss Status Handle Register
- tgt: ?[TODO]
generate hh from py
# generate header from MyMemObject.py
scons build/ARM/params/MyMemObject.hhgenerate doxygen
output: src/doxygen/html
cd src
doxygenSE (syscall emu)
gem5.opt configs/example/se.py --cmd <CMD>git
create Repos/*
# can use git update then
git clone --mirror <URL>convert bare to mirror
git config remote.origin.fetch "+refs/*:refs/*" 
git config remote.origin.mirror trueremote branches
列举remote的分支
# 无需联网
git branch -r [-l <patthern>]
# 需要联网
git remote show <remote>
git ls-remote <remote>查找删除某行的commit
# 面对merge节点似乎有问题
git log -c -S'<string>' <file>
git log -c -G'<regex>' <file>
# 然后搜索
/<string>clone server-Codes
git clone git://10.90.50.99/<REPO>clone specific-tag
git clone -b <tag> --depth=1 <repo>rebase interactive
# root commit
git rebase -i --root
# non-root commit
git rebase -i <commits>server Codes
git daemon --base-path=/home/xieby1/Codes/ --export-allstatistics
git-quick-statscreate uncommit patch
git diff > <xxx.patch>visualization
# simplified
git log --all --decorate --oneline --graph --simplify-by-decoration
# full
git log --all --decorate --oneline --graphworktree
see man git-worktree
| main worktree | linked worktree | |
|---|---|---|
| bare repo | 0 | 0 | 
| normal repo (git init/clone) | 1 | 0 | 
| (git worktree cmds) | 1 | >=0 | 
worktree basics
# add a linked worktree in ../folder
git worktree add ../<folder> [<commit>]
# its ok to directly remove folder, then
git worktree prunegrep
only filename
Scanning each input file stops upon first match.
Therefore, it is fast!
grep -lheadscale tailscale
register
sudo docker exec headscale headscale -n <NETWORK> nodes register --key <KEY>reset login server
tailscale up --force-reauth --resetrm node
sudo docker exec -it headscale headscale nodes del -i <ID>exec cmd
sudo docker exec headscale headscale --helpclient register
sudo tailscale --socket <PATH> up --login-server <URL>[:PORT]html
detail
fold/collapse/expand
<details>
  <summary>Details</summary>
  miao
</details>span color
<span style="background: red; color: white; font-weight: bold;">time stamp
<div style="text-align:right; font-size:3em;">2022.04.12</div>icon design
- figma
- svgo
- edit
- stroke=“currentColor”
- move attrs to svg tag
 
image/picture
get dimension/size
identify <image>Inkscape
extract pdf
Poppler/Cairo import (Huge size)
<Ctrl><Shift>G # ungroup
! # invert selection
<Ctrl><Shift>R # resize canvas
Extensions->Text->Replace Fontjekyll
# first time run
nix-shell -p bundler --run "bundle install"
# serve
nix-shell -p bundler -p jekyll --run "bundle exec jekyll serve -H 0.0.0.0 -P 4000"libreoffice
edit/view mode
ctrl+shift+mLicenses
MIT
- 随意使用
- 保留该MIT许可
- 作者不负责
linux
nolibc (header only libc)
tools/include/nolibc/
编译
make defconfig && make版本号
include/config/kernel.release
make menuconfig: General setup -> Local version安装
make INSTALL_PATH=<path> install
make INSTALL_MOD_PATH=<path> modules_install生成源码跳转文件
# 需要先编译
./scripts/clang-tools/gen_compile_commands.py
make ARCH=x86 COMPILED_SOURCE=1 cscope内部结构
由nm生成,符号类型见man nm
- 内核暴露的符号/proc/kallsyms
- 或是由源码生成System.map
系统调用表sys_call_table
内核信息重定向
ref: dmesg output to tty
x86上不可靠:输出不全,几次就关闭了
tty # `who am i` may not output
cat /proc/kmsg > <stdio dev file>mod
show info about a mod
modinfo <mod>llvm
generate ll
clang -S -emit-llvm <file.c> -o <file.ll>generate bc
clang -c -emit-llvm <file.c> -o <file.bc>run ir
lli <file.ll/bc>make
terminology
# a rule
target … : prerequisites …
    recipe
    …all executables
EXECUTABLES=$(patsubst %.cpp, %, $(wildcard *.cpp))
all: ${EXECUTABLES}clean executables
SO: How do I execute each command in a list?
define \n
endef
$(foreach x,${EXECUTABLES},rm ${x}${\n})func wildcard
$(wildcard pictures/*.drawio)grouped targets
foo bar biz &: baz boz
        echo $^ > foo
        echo $^ > bar
        echo $^ > bizhash dep
include hashdeps.mk
combined.txt: $(call hash_deps,a.txt b.txt)
    echo "Concatenating files"
    cat $(call unhash_deps,$^) > $@implicit rule
%:%.c
    $(CC) $< -o $@grouped target
foo bar biz &: baz boz
        echo $^ > foo
        echo $^ > bar
        echo $^ > bizoptional deps
# wang is optional
miao: $(wildcard wang)
# wang% is optional
miao%: $(wildcard $$%wang)prerequisite
$< # first
$^ # all
$(word 2,$^) # secondtarget依赖树
make -nd <target> | make2graph
# makefile2graph <target>列出所有targets
remake --targetsvariable priority
TLDR: env < makefile < cli
- Variables
from the Environment
- Prioritize env: add -e
 
- Prioritize env: add 
- Overriding Variables
maven
proxy
https://maven.apache.org/guides/mini/guide-proxies.html
<settings>
  <proxies>
   <proxy>
      <id>example-proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.example.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
    </proxy>
  </proxies>
</settings>mdbook
build
同名md和html html优先
network
process traffic
sudo nethogsdns resolve
host <domain name>scan local
nmap 192.168.1.0/24raspberrypi ubuntu netplan
# /etc/netplan/50-cloud-init.yaml
network:
  version: 2
  wifis:
    renderer: networkd
    wlan0:
      access-points:
        <name>:
          password: <...>
          hidden: true
      dhcp4: true
      optional: trueocr
tesseract
# 列支持的语言
tesseract --list-langsocrmypdf
详细见ocrmypdf.md
ocr会将原pdf栅格化,
所以需要分离文本和图片
# 去除文本
gs -o notext.pdf -dFILTERTEXT \
-sDEVICE=pdfwrite <input.pdf>
# 运行ocr
ocrmypdf --force-ocr --output-type pdf \
-l $lang notext.pdf ocr.pdf
# 去除图片仅保留文本
gs -o textonly.pdf -dFILTERIMAGE \
-dFILTERVECTOR -sDEVICE=pdfwrite ocr.pdf
# 叠加文本
qpdf notext.pdf --overlay \
textonly.pdf -- <output.pdf>ocrmypdf & compress
ocrmypdf -O 3 --jpeg-quality 1 \
  --png-quality 1 --force-ocr \
  --output-type pdf -l chi_sim \
  in.pdf out.pdfobjdump
objdump binary
riscv64-unknown-linux-gnu-objdump -b binary -m riscv:rv64 --start-address=0x97b500 --stop-address=0x97b600 -D <file>pandoc
可用代码高亮
pandoc --list-highlight-languages打印默认模板
pandoc -D <FORMAT>print default styles
--print-default-data-file=templates/styles.htmlparallel
home (tilde)
write ‘~’ to file home
parallel --tag ssh {1} ls {2}/Codes ::: myloongson55 myloongson56 myloongson57 myloongson58 :::: ./homeparallel --tag ssh {1} ls \\~/Codes ::: myloongson55 myloongson56 myloongson57 myloongson58perl
man/doc
perldoc perlrunsed like rexeg lookbehind
perl -pe 's/(?<=foo)bar/test/g' file.txtpic
jpgs2pdf
convert input1.jpg input2.jpg input3.jpg output.pdfresize
convert input.xxx -resize 100x200\! output.xxxpkgs
apk
apk info -L <pkg>deb
dpkg-deb -c <package_name.deb>installed
dpkg-query -L <package_name>not installed
apt-file list <package_name>qemu
host net
10.0.2.2
smb
mount -t cifs -o user=miao%miao //10.0.2.4/qemu Host/system file disk
[qemu-sys] -m 16 -nographic -fda [file]qemu-src
tcg/
- tcg.c, tcg-op.c: generate tcg
- /: tcg => 
- tci.c: tcg => interpreting
- README: tcg syntax intro
qemu wrapper
quickemu
quickemu --display none --vm ~/Img/ubuntu-22.10.conf
# cat ~/Img/ubuntu-22.10/ubuntu-22.10.ports
ssh quickemuOSX-KVM
./OpenCore-Boot.shutm
ssh forward by useing emulated vlan
revealjs
align
SO: center child divs inside parent div
:::{style="display:inline-block; text-align:left;"}
things here are all
left aligned
!
:::chalkboard
del: clear current
backspace: clear all
c: note canva
b: chalkboard
d: download drawings
x: previous color
y: next color
right click: eraserright half crop image
fragments fade
| Name | Effect | 
|---|---|
| fade-out | Start visible, fade out | 
| fade-up | Slide up while fading in | 
| fade-down | Slide down while fading in | 
| fade-left | Slide left while fading in | 
| fade-right | Slide right while fading in | 
| fade-in-then-out | Fades in, then out on the next step | 
| fade-in-then-semi-out | Fades in, then to 50% on the next step | 
| semi-fade-out | Fade out to 50% | 
fragments highlight
| Name | Effect | 
|---|---|
| highlight-red | Turn text red | 
| highlight-green | Turn text green | 
| highlight-blue | Turn text blue | 
| highlight-current-red | Turn text red, then back to original on next step | 
| highlight-current-green | Turn text green, then back to original on next step | 
| highlight-current-blue | Turn text blue, then back to original on next step | 
fragments others
| Name | Effect | 
|---|---|
| grow | Scale up | 
| shrink | Scale down | 
| strike | Strike through | 
fragments order
<p class="fragment" data-fragment-index="3">Appears last</p>
<p class="fragment" data-fragment-index="1">Appears first</p>
<p class="fragment" data-fragment-index="2">Appears second</p>plotly
::: {style="width:1000px; height: 400px; display:inline-block; text-align:center;"}
:::: {style="transform: scale(2); transform-origin: left top;"}
``` {.include}
./plotly/bt_perf-mini.html
```
::::
:::print pdf
Append ?print-pdf to URL.
svg image
详细参考Tech/Mem/slides/images/order_summary.dot
svg里的image用相对svg的路径,前面不跟./
AI:插入网页要用object,不然不能显示
例如
dot编译需要加–filepath=path
toc style
<style>nav {...}<style>TODO: yaml_metadata_block
route
add
sudo route add -net 172.17.103.0 \
gw 10.90.50.254 \
netmask 255.255.255.0 \
metric 1000 \
dev enp9s0del
sudo route del -net 172.17.103.0 \
gw 10.90.50.254
netmask 255.255.255.0 \
dev enp9s0rust
installed targets
rustup show交叉编译
rustc --print target-list
rustup target add <TARGET>
cargo build --target=<TARGET> --releasescons
clean
scons -cscrcpy
otg mouse/keyboard
GH: barrier: Please make an Android client
# In this mode, adb (USB debugging) is not necessary
scrcpy --window-width 100 --window-height 100 --otg -s DEVICEIDsed
overview
- detailed document
- brief synopsis
- man sed
 
terminology
[addr]X[options]
[addr]{X1[options]; X2[options]; ...}regex
POSIX.2 BREs
recursive all files
- -print0- results separated by null char 
find . -type f -print0 | \
xargs -0 sed -i 's/.../.../g'if match
if match return 1
else return 0
sed '/<pattern>/Q 1'new line
sed -z 's/\nwang\nmiao\n//g'refer to match
sed 's/\(.*\)miao/\1wang/g'sixu
all
// command line:
//   dot -Tsvg -O sixu.dot
digraph {
// attributes
/// graph
rankdir=BT;
/// subgraph
newrank=true;
style=filled;
//// color name: https://graphviz.org/doc/info/colors.html
color=whitesmoke;
/// node
node[
shape=box,
style="filled, solid",
color=black,
fillcolor=white,
];
/// edge
edge[
minlen=1,
//weight=1,
// If false, the edge is not used in ranking the nodes.
//constraint=true,
];
}today
"22Apr12+" -> "22Apr12-" -> "22Apr12+";
subgraph cluster_22Apr12
{
x22Apr12_
}
{rank=same;
"22Apr12-";
x22Apr12_
}
{rank=same;
"22Apr12+";
}ssh
bind address
ssh -L <localPort>:<remoteURL>:<remotePort> -N -T <sshTarget>bind address (Browser proxy)
ssh -L 8890:localhost:8889 -N -T tso.rsp3
# then change switchyomega to SSH_L presetnixos x forward
ssh -Yswap
create swapfile
sudo fallocate -l 4G /swapfile
# optional
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfilesystemd unit
After/Before说明
man systemd.unitman pages
- systemd
- systemd.unit
- systemd.syntax
- systemd.service
user目录
man systemd.unit
~/.config/systemd/
service状态
systemctl --user status <service>
journalctl --user -u <service>
# follow mode
journalctl --user -f -u <service>service output
# sys
journalctl -f -u <service>
# user
journalctl --user -f -u <service>journal
journalctl -f | grep gnome-shell列举unit类
# 例如列出list
systemctl list-units --type targetsystemd unit examples
auto login
#Create the directory:
sudo mkdir /etc/systemd/system/getty@tty1.service.d
#Create file:
sudo vim /etc/systemd/system/getty@tty1.service.d/autologin.conf
#Insert:
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin YOURUSERNAMEHERE --noclear %I 38400 linuxauto swapon
[Unit]
Description=Swapon
[Install]
WantedBy=default.target multi-user.target
[Service]
ExecStart=swapon /swapfiletar
create directory
# NOTED: no ./ before dir !!!
tar czf bin.tar.gz <dir>tmux
auto start tmux
[[ $TERM != "screen" ]] && exec tmuxterminology
man tmux: Description
- session
- window
- pane = pseudo terminal (pty)
 
 
- window
Any number of tmux instances can
cnnect to the same session.
split
<C-b> " // vertical
<C-b> % // horizontalubuntu ssh login info
AU: Where does the System Information information come from on login by SSH?
run-parts /etc/update-motd.d/
# landscape-sysinfovideo
video compress
ffmpeg -i input.avi -c:v libx264 -crf 18 -preset veryslow -c:a copy out.mp4使用parallel
parallel -j2 ffmpeg -i {} -c:v libx264 -crf 18 -preset veryslow -c:a copy {.}.x264.18.mp4 ::: *.MP4wine
regedit
- Regedit
- Useful Registry Keys
- wine regedit /?
WSL
wslcompact
https://github.com/okibcn/wslcompact
shrink vdisk
wsl --shutdown
diskpart
select vdisk \
file="C:\Users\<User>\AppData\Local\ \
Packages\CanonicalGroupLimited.UbuntuonWindows... \
\LocalState\ext4.vhdx"
compact vdiskx11
restart server
Alt-F2
rXephyr
Xephyr :2 -resizeable  -dpi 48 -host-cursorDISPLAY=:2 <command>multiple DPI
xrandr --output DP-1 --scale-from 2880x1800
# Stop flicker
xrandr --output eDP-1 --scale 0.9999x0.9999x0vncserver
x0vncserver -password <PSWD> -securitytypes=none -geometry 800x600+0+480 -FrameRate 10xdg
xdg-mime
xdg-mime query filetype <file>
xdg-mime query default <type>yarn
add
yarn global add node_modulebin
yarn global binothers
alacritty search
C-S-f
Enter
S-Enterccls
clang
-I<PATH>
-D<VAR>crypt
perl -e "print crypt('wjxby','xb');"combine pdf
pdftk <file1.pdf …> cat output <output.pdf>
dgen-sdl
dgen <path>flame graph
https://github.com/brendangregg/FlameGraph
sudo perf record -g <cmd>
sudo perf script > out.perf
stackcollapse-perf.pl out.perf > out.folded
flamegraph.pl out.folded > out.svggnome autostart
mov desktop file to
~/.config/autostart/
gnome desktop spec
https://developer-old.gnome.org/desktop-entry-spec/
gnome dock new window
TODO: dash-to-dock? or original dock?
ctrl+super+<num>
gnome sound overamplifier
gsettings set org.gnome.desktop.sound allow-volume-above-100-percent trueinkscape embed image
convert 
inkscape --actions "org.inkscape.filter.embed-image" -o <output.svg> <input.svg>open desktop file
gtk-launch <xxx.desktop>gprof
# compile
gcc ... -gp
# run <file>
# show
gprof <file>kitty ssh
kitty +kitten ssh myserverkitty +kitten ssh -J jump_server destination_serverpkg-config
# 获取package的名字
pkg-config --list-all | grep <xxx>
# 获取c编译、链接参数
pkg-config --cflags --libs <pkg>pdftohtml
pdftotext -noframes -i -q -p -c <pdf>pdftosvg
inkscape \
  --without-gui \
  --file=input.pdf \
  --export-plain-svg=output.svgpdftotext
pdftotext -q <pdf>进程树
ps -jHg <pid> # 进程子树
pstree -psal <pid> # 完整树new user
adduser xieby1
usermod -aG sudo xieby1drawio no snapping
hold ctrl + shift
iconv
# 文本编码转换
iconv -f gb18030 -t utf-8 <output>pipe clipboard
 | xclip -selection clipboardclipboard rich text
- https://superuser.com/questions/912712/how-to-send-rich-text-to-the-clipboard-from-command-line
- https://superuser.com/questions/144185/getting-html-source-or-rich-text-from-the-x-clipboard
# html => rich text format
xclip -selection clipboard -o | xclip -t text/html
# rich text format => html
xclip -selection clipboard -o -t text/htmlshebang with arguments
SE: Multiple arguments in shebang
#!/usr/bin/env -S cmd arg1 arg2 ...sort first column
sort -s -n -k 1,1calibrate touchscreen
SO: Calibrate one touch one not
xinput --map-to-output $(xinput list --id-only "WingCoolTouch WingCoolTouch") DP-1Lang
C/CPP
clang-format config
clang-format -style=llvm -dump-config > .clang-formatclang-format on/off
// clang-format off
...
// clang-format onhtml/css
scale/zoom
TLDR: if no interaction use zoom, else use
scale + width + height
- SO: CSS transform not resizing
- MDN:
zoom
- recommand transform: scale(), but it does not affect the layout size
- firefox starting support in nightly (fuck ff)
 
- scale: 需要scale和width/height匹配
- zoom: plotly iteractive not work!
scale例子
用于plotly
::: {style="width:1000px; height: 400px; display:inline-block; text-align:center;"}
:::: {style="transform: scale(2); transform-origin: left top;"}
``` {.include}
./plotly/bt_perf-mini.html
```
::::
:::zoom例子
::: {style="zoom: 200%;"}
...
:::latex
unused bib
# no suffix .tex/.bib
checkcites Thesispython
debug script
import pdb
pdb.set_trace()object attr
dir()
vars()pyright ignore
<code needed to be ignored> # type: ignorepyright local conf
https://microsoft.github.io/pyright/#/configuration
# pyrightconfig.json
{
  reportGeneralTypeIssues = false,
}requirement syntax
requirements.txt
E.g.
requests [security] >= 2.8.1, == 2.8.* ; python_version < "2.7"python matpltlib
chinese support compromise
use rsvg-convert to convert
rcParams
svg
svg able to copy, support chinese
plt.rcParams["svg.fonttype"] = "none"verilog
assignment
2005.verilog_std.pdf
- continuous assign: 6.1
- wire net assign net = enable
 
- procedural assign: 6.2
- blocking assign: 9.2.2 - reg = 0
- nonblocking assign: 9.2.1 - initial begin reg <= 0 end
 
vim
buffer
list all
:buffers " or
:ls " or
:filesdelete
:bdeleteopen/edit
" tab key works
:buffer <name>builtin complete
help
:h compl-viminsert mode completoin
:h ins-completion
- Whole lines |i_CTRL-X_CTRL-L|
- keywords in the current file |i_CTRL-X_CTRL-N|
- keywords in ‘dictionary’ |i_CTRL-X_CTRL-K|
- keywords in ‘thesaurus’, thesaurus-style |i_CTRL-X_CTRL-T|
- keywords in the current and included files |i_CTRL-X_CTRL-I|
- tags |i_CTRL-X_CTRL-]|
- file names |i_CTRL-X_CTRL-F|
- definitions or macros |i_CTRL-X_CTRL-D|
- Vim command-line |i_CTRL-X_CTRL-V|
- User defined completion |i_CTRL-X_CTRL-U|
- omni completion |i_CTRL-X_CTRL-O|
- Spelling suggestions |i_CTRL-X_s|
- keywords in ‘complete’ |i_CTRL-N| |i_CTRL-P|
complete
nvim config
nix plugins
vim `which nvim`
set rtp^=/nix/store/...-vim-pack-direasy align
not ignore comment & str
:'<,'>EasyAlign /REGX/ {'ig':[]}left/right margin
:'<,'>EasyAlign /REGX/<l0
:'<,'>EasyAlign /REGX/>l0r0Misc
colors
Draw.IO color palette
| Fill | Border | 
|---|---|
| #F5F5F5 | #666666 | 
| #DAE8FC | #6C8EBF | 
| #D5E8D4 | #82B366 | 
| #FFE6CC | #D79B00 | 
| #FFF2CC | #D6B656 | 
| #F8CECC | #B85450 | 
| #E1D5E7 | #9673A6 | 
debug log
vim -V9myVim.logExplore (netrw)
; open current file's dir
:E[xplore]cd current (netrw)
:cd %Explore crash (netrw)
rm ~/.local/share/nvim/.netrwhistIncrease column
:h v_g_CTRL-A
c-v ; select block
g c-ainsert stdout
; insert below
:r!<cmd>
; insert above
:-r!<cmd>
; insert top
:0r!<cmd>lower/upper case
In select mode
u ; lower case
U ; upper casenetrw new file
# in netrw mode
%fold
" set
zf{motion} " :h motion.txt
" toggle
za
" range
:{range}fo[ld]highlight current line
:set cursorlinelist syntaxs
ls <$VIMRUNTIME>/syntax/markdown toc
:GenTocGFMmapped keys
":n/v/imap
:map
:h inexpopup window
🐁 <leader>[runtime folder
:echo $VIMRUNTIMEsplit调整
c-w _ ; max height
1c-w _ ;min height
c-w = ;same height
:on ; close others
c-w o ;same abovefiletype syntax bindings
<$VIMRUNTIME>/filetype.vim
scrollbind
:set scrollbind
:set noscrollbindset filetype (nvim)
it can control syntax and coc
set filetype=pythonset syntax
:set syntax=syntax
; set
:set syntax=html
; get
:set syntaxstatus line
set laststatus=2jumplist
:ju " 列出jumplist
<C-o> " 退
<C-i> " 进cscope
; cs querytype
🐁 <C-\>[sgdcteFia]重新加载
:!cscope -R
:cs resetmark
<leader>m " 标记/取消标记
{N}<leader>m " 给第N组添加标记词
{N}<leader>n " 取消第N组的标记
<leader>M " 显示标记颜色和标记词
🐁 <leader><F3> " 取消所有标记ale-fix
ale支持的fix位于
autoload/ale/fix/registry.vim
所有fixer的调用脚本位于
autoload/ale/fixers/
wrap line
; 🐁toggle
<F9>terminal mode
:h :terminal
# exit temrinal mode
<C-\><C-N>
# enter temrinal mode
ivar last edit
:verbose set shiftwidth?diff
diffthis
diff两个竖分buffers
; 分别在两个buffer里
:difft[his]
; 关闭,分别
:diffoffgitgutter-diff
let g:gitgutter_diff_base = ''
:GitGutterDiffOriggitsigns diff
" Diff against the index
:Gitsigns diffthis
" Diff against the last commit
:Gitsigns diffthis ~1diff obtain/put
" obtain
do
" put
dpgit
blame [# fugitive]
和git相同的略。fugitive的特性:
:Git blame " blame整个文件
:Gedit " 跳转光标下到对应的object(某个版本的某个文件)historic file [# fugitive]
Gedit <refname>
enter " opon
o " horizon open
O " new tab open
<num>gt " switch tag显示commit信息 [git-messenger]
<leader>gm " 在popup窗口显示commit信息plugins
nvim nix plugins
home-manager & nixpkgs srcs:
- /modules/programs/neovim.nix: pkgs.wrapNeovimUnstable … neovimConfig 
- pkgs/applications/editors/neovim/wrapper.nix: generatedWrapperArgs
packpath^=…
view `which nvim`
/packpath^=...AnsiEsc
:AnsiEscconfig-local
~/.local/share/nvim/config-local
:ConfigSource
:ConfigEdit
:ConfigTrust
:ConfigIgnoregit-wip
trigger every time :w,
or trigger manually
:call GitWipSave()lightspeed.nvim
s ; forward
S ; backwardtree-sitter update
GH Issue: query.lua query: error at position #759
:TSUpdatetree-sitter reinstall
:TSUninstall all
; exit vim
home-manager switch
vim
:TSUpdatecoc disable
:CocDisable
:CocEnablecoc disable diagnostic
:e reload file is neccessary
:let b:coc_diagnostic_disable=1
:esearch
by column
:h /\%c
\%23c   Matches in a specific column.
\%<23c  Matches before a specific column.
\%>23c  Matches after a specific column.
\%.c    Matches at the cursor column.
\%<.c   Matches before the cursor column.
\%>.c   Matches after the cursor column.visual block
change area
oprevious area
gvreplace
<c-v>
rvirtual edit
:set ve=allnix
binary cache
check existence 1
curl/wget https://xieby1.cachix.org/<pkg's nix store hash>.narinfocheck existence 2
nix path-info <path-to-pkg> --store https://xieby1.cachix.orgpaths
<nix channel url>/store-path.xz
e.g. https://mirror.tuna.tsinghua.edu.cn/nix-channels/nixos-21.11/store-paths.xz
query
refers to Discourse: Is it possible to query the binary cache?
nix path-info \
--store https://cache.nixos.org/ \
-f '<nixpkgs>' \
--argstr system x86_64-linux \
<pkgs-name>import/export
# import may need sudo
nix-store --import/--exportcopy
How to use a local directory as a nix binary cache?
nix copy --no-check-sigs \
--to <output/path> </nixstore/path>
nix-env -i <output/path>verify
nix-store --verify [--check-contents] [--repair]get closure paths
nix-store -qRcopy closure
sudo nix-copy-closure --from <user@ssh> <path>build
env
在builder执行前会设置环境变量:
NIX_BUILD_TOP
TMPDIR, TEMPDIR, TMP, TEMP
PATH=/path-not-set
HOME=/homeless-shelter
NIX_STORE=/nix/store
...remote-build
nix-build ... --builders "szopen1;szopen2"force remote-build
nix-build ... -j 0 --builders "szopen1;szopen2"channel
force update
nix-channel --option tarball-ttl 0 --update [<channel>]config (nix)
manual
man nix.confshow
nix show-configconfig (pkgs)
nixpkgs manual: Global configuration
nixos
/etc/nixosconfiguration.nix
{
  nixpkgs.config = {
    allowUnfree = true;
  };
}nix user
~/.config/nixpkgs/config.nix
{
  allowUnfree = true;
}env
query out path
nix-env -q --out-pathnix daemon
proxy
Nix manual: Proxy Environment Variables
# /etc/systemd/system/nix-daemon.service.d/overrides.conf
Environment="all_proxy=http://127.0.0.1:8889"
Environment="ftp_proxy=http://127.0.0.1:8889"
Environment="http_proxy=http://127.0.0.1:8889"
Environment="https_proxy=http://127.0.0.1:8889"
Environment="no_proxy=127.0.0.1,localhost,internal.domain"
Environment="rsync_proxy=http://127.0.0.1:8889"debug
setup
nix-shell
. $stdenv/setupnix-build
nix-build -K <drv>nix-build
nix-build '<nixpkgs>' -A xxxdependency
find referrers
nix-store --query --referrers <nix-path>find references
nix-store --query --references <nix-path>others
# all dependencies
nix-store --query --requisites </nix/store/path>
## or
nix-store --query -R </nix/store/path>
# nested tree
nix-store --query --tree </nix/store/path>
# only immediate dependencies
nix-store --query --references </nix/store/path>expr
eval
nix eval --expr "<EXPR>"folder
.desktop
~/.nix-profile/share/applications
garbage collect(gc)
sys garbage
sudo nix-collect-garbage -dusr garbage
nix-collect-garbage -dnix-env generations
nix-env --delete-generations 10dhome-manager generations
# list
home-manager generations
# clean generations beyond 1 day
home-manager expire-generations -1dayrm broken links
SO: delete all broken symbolic links
find -L . -name . -o -type d -prune -o -type l -exec rm {} +nix-build garbage
ls -l /nix/var/nix/gcroots/autofilter nix-build garbage
cd /nix/var/nix/gcroots/auto
for i in *; do if [[ $(readlink $i) =~ /result ]]; then echo $i; echo $(readlink $i); fi; donefilter direnv garbage
cd /nix/var/nix/gcroots/auto
for i in *; do if [[ $(readlink $i) =~ /.direnv/ ]]; then echo $i; echo $(readlink $i); fi; donedirenv garbage
ls -l /nix/var/nix/gcroots/per-user/<user>misc
build pkg
nix-build '<nixpkgs>' -A <pkg>cheatsheet
disable gcc hardening in drv
see: pkgs/stdenv/generic/make-derivation.nix
hardeningDisable = ["formt"];
hardeningDisable = ["all"];disable gcc hardening in shell
SE:
Disabling the security hardening options for a nix-shell
environment
export NIX_HARDENING_ENABLE=""nix direnv
echo "use nix" >> .envrc
direnv allowgnome extension
pkgs/desktops/gnome/extensions/extensions.json
nurl
nurl [OPTIONS] [URL] [REV]prefetch url
nix-prefetch-urlprefetch github
nix-prefetch-url --unpack \
https://github.com/<owner>/
<repo>/archive/<rev>.tar.gzprefetch sha256
nix-prefetch-url --unpacksha256
nix-hash --type sha256 \
--flat --base32 <file>size
# man nix3-path-info
# closure-size
nix path-info -Sh <path>show drv
nix derivation show <.drv>repl
pkgs = import <nixpkgs> {}old generations
sudo nix-env -p /nix/var/nix/profiles/system --list-generations
sudo nix-collect-garbage -d
# User Generations (Home-Manager)
nix-collect-garbage -dpath
nix-instantiate --eval -E "<path>"version
nix-version --hashnix-on-droid sshd
sshd-startoption
home-manager option
home-manager option <OPTION>nixos-option
nixos-option <OPTION>dependency
types
possible dependency types and examples
| D type | D’s host | D’s target | 
|---|---|---|
| build → * | build | (none) | 
| build → build | build | build | 
| build → host | build | host | 
| build → target | build | target | 
| host → * | host | (none) | 
| host → host | host | host | 
| host → target | host | target | 
| target → * | target | (none) | 
| target → target | target | target | 
examples
possible dependency types and examples
TODO: simplify
Suppose we are building g++ with a (build, host, target) platform triple of (foo, bar, baz). This means we are using a foo-machine to build a copy of g++ which will run on a bar-machine and emit binaries for the baz-machine.
- g++ links against the host platform’s glibc C library, which is a “host→ ” dependency with a triple of (bar, bar, ). Since it is a library, not a compiler, it has no “target”. 
- Since g++ is written in C, the gcc compiler used to compile it is a “build→ host” dependency of g++ with a triple of (foo, foo, bar). This compiler runs on the build platform and emits code for the host platform. 
- gcc links against the build platform’s glibc C library, which is a “build→ ” dependency with a triple of (foo, foo, ). Since it is a library, not a compiler, it has no “target”. 
- This gcc is itself compiled by an earlier copy of gcc. This earlier copy of gcc is a “build→ build” dependency of g++ with a triple of (foo, foo, foo). This “early gcc” runs on the build platform and emits code for the build platform. 
- g++ is bundled with libgcc, which includes a collection of target-machine routines for exception handling and software floating point emulation. libgcc would be a “target→ ” dependency with triple (foo, baz, ), because it consists of machine code which gets linked against the output of the compiler that we are building. It is a library, not a compiler, so it has no target of its own. 
- libgcc is written in C and compiled with gcc. The gcc that compiles it will be a “build→ target” dependency with triple (foo, foo, baz). It gets compiled and run at g++-build-time (on platform foo), but must emit code for the baz-platform. 
- g++ allows inline assembler code, so it depends on access to a copy of the gas assembler. This would be a “host→ target” dependency with triple (foo, bar, baz). 
- g++ (and gcc) include a library libgccjit.so, which wrap the compiler in a library to create a just-in-time compiler. In nixpkgs, this library is in the libgccjit package; if C++ required that programs have access to a JIT, g++ would need to add a “target→ target” dependency for libgccjit with triple (foo, baz, baz). This would ensure that the compiler ships with a copy of libgccjit which both executes on and generates code for the baz-platform. 
- If g++ itself linked against libgccjit.so (for example, to allow compile-time-evaluated C++ expressions), then the libgccjit package used to provide this functionality would be a “host→ host” dependency of g++: it is code which runs on the host and emits code for execution on the host. 
propagation
| host → target | attribute name | offset | 
|---|---|---|
| build –> build | depsBuildBuild | -1, -1 | 
| build –> host | nativeBuildInputs | -1, 0 | 
| build –> target | depsBuildTarget | -1, 1 | 
| host –> host | depsHostHost | 0, 0 | 
| host –> target | buildInputs | 0, 1 | 
| target –> target | depsTargetTarget | 1, 1 | 
func/lib
fetch
pkgs/build-support/fetch.*/
mkDerivation
pkgs/stdenv/generic/make-derivation.nix
.override 
- override {…}
- override arguments
 
- override (old: {…})
- override arguments
 
- overrideAttrs (old: {…})
- override attrs before mkDerivation
 
- overrideDerivation (old: {…})
- override attrs after mkDerivation
 
how override (old: {})?
# customisation.nix
makeOverridable = f:
  mirrorArgs (origArgs: result // {
   override = mirrorArgs (newArgs: makeOverridable f (overrideWith newArgs));
  })
override callable
=> (mirrorArgs (newArgs: makeOverridable f (overrideWith newArgs))) callable
=> (fArgs: makeOverridable f (overrideWith fArgs)) callable
=> makeOverridable f (overrideWith callable)
=> makeOverridable f ((newArgs: origArgs // (callable origArgs)))lang
indented string
''
  # escape ${
  ''${bash_var}
  # escape ''
  '''
''<path>, like <nixpkgs>, is
path
listed in env NIX_PATH
module
args
# foobar.nix
{lib, withFoo ? "bar", ...}:
{# ...}
# configuration.nix
args@{ ... }:
{imports = [(
  import ./foobar.nix (args // { withFoo = "baz"; })
)];}nixos
list build-generations
sudo nix-env -p /nix/var/nix/profiles/system --list-generationsnix-shell
build env
nix-shell '<nixpkgs>' -A <pkg>direnv
use nix <path>direnv fhs
if [[ -z "$IN_NIX_SHELL" ]]; then
  use nix <path>
fipatchShebangs
patchShebangs <path>non-interp shebang
Inspired by cursed.nix
My tests show, as long as there are arguments in nix-shell, the interp mode of nix-shell is not triggered!
Therefore, I change -v to --keep miao
Why it works?
#!/usr/bin/env -S nix-shell --keep miaopkg
nix bundle
20240308注:打包的gcc运行失败
nix-user-chroot: No such file or directory
# nix built-in
nix bundle nixpkgs#hello
nix bundle --expr '(import <nixpkgs> {}).hello'nix-bundle
20240308注:成功运行打包的gcc
# github 465 start
nix-bundle hello /bin/hellonix-tree
nix-tree </nix/store/path>not in nixpkgs
nix-shell -E "with import <nixpkgs> {}; callPackage ./default.nix {}"priority
lib.lowPrio <pkg>search file
nix-locate 'bin/hello'pkgs
python
pkgs/top-level/python-packages.nix
pkgs/development/python-modules/
pkgs/development/interpreters/python/mk-python-derivation.nixpython3 gi
pyobject3
tex live
pkgs/tools/typesetting/tex/texlive/pkgs.nixstatic
SO: How to produce static executable on NixOS?
pkgs.glibc.static
pkgs.zlib.staticrepl
help
:?open editor
:e <expr>home-manager
refers to nix repl home.nix config
hm = import <home-manager/modules> { configuration = ~/.config/home-manager/home.nix; pkgs = import <nixpkgs> {}; }sysconfig
sysconfig = (import <nixpkgs/nixos> {}).configUsage
musl libc
Support -static
nix-shell -p pkgsCross.musl64.stdenv.cc
x86_64-unknown-linux-musl-gcc -static hello.cstatic compile
Nix currently use musl-gcc
nix-shell -p pkgsStatic.stdenv.cc
x86_64-unknown-linux-musl-gcc -static hello.caarch64 cross
nix-shell -p pkgsCross.aarch64-multiplatform.stdenv.cc
aarch64-unknown-linux-gnu-gccSoC
AMBA
AMBA 2.0分类
2008.on-chip_comm_arch.pasricha.toc.pdf: 3.1.1 AMBA 2.0
- AHB: Advanced high performance bus
- 意思是连接对象时高性能的模块
 
- ASB: Advanced system bus
- AHB的子集,少了一些高级协议
 
- APB: Advanced peripheral bus
CHI
B1.3 Terminology 1
- Transaction: a single read/write operation【由Messages组成】
- Message: protocol layer terminology
- Request
- Data response
- Snoop request
- … 由packets组成
 
- Packet
- Flit
- Phit
B1.3 Terminology 2
- Requester: RN+HN+MN
- Completer: HN+MN+SN
B1.5.2 Cache State Model
- Valid, Invalid
- Unique, Shared
- Clean, Dirty
- Full, Partial, Empty
        Valid  Invalid
      ┌───────┬───────┐
    Unique Shared
      ┌───┬───┐
     ┌┌───┬───┬───────┐┐
     ││UC │SC │       ││Full
Clean│├───┼───┤       │┤
     ││UCE│-  │       ││Partial/Empty
     ├├───┼───┤   I   │┤
     ││UD │SD │       ││Full
Dirty│├───┼───┤       │┤
     ││UDP│-  │       ││Partial/Empty
     └└───┴───┴───────┘┘B1.6 Component naming
- RN (Request Node)
- RN-F (Fully Coherent Request Node)
- RN-D (IO Coherent Request Node with DVM support)
- RN-I (IO Coherent Request Node)
 
- HN (Home Node)
- HN-F (Fully Coherent Home Node)
- HN-I (IO coherent Home Node)
- MN (Miscellaneous Node): DVM
 
- SN (Subordinate Node)
- SN-F (Fully Subordinate Node)
- SN-I (IO coherent Subordinate Node)
 
         ┌─────┐┌─────┐┌─────┐
         │RN-F0││RN-F1││RN-F2│
         └──┬──┘└──┬──┘└──┬──┘
        ┌───┴──────┴──────┴───┐
        │ Interconnect ┌─────┐│
        │ (ICN)        │MN   ││
┌─────┐ │              └─────┘│
│RN-I ├─┤                     │
└─────┘ │┌─────┐┌─────┐┌─────┐│
        ││HN-I ││HN-F ││HN-F ││
        │└──┬──┘└──┬──┘└──┬──┘│
        │   │      └───┬──┘   │
        └───│──────────│──────┘
         ┌──┴──┐    ┌──┴──┐
         │SN-I │    │SN-F │
         └─────┘    └─────┘B2.1 Channel overview
                        Channel
┌──────────┐                              ┌───────────┐
│          ├──TXREQ─▶   ─REQ──   ──RXREQ─▶│           │
│Request   ├──TXDAT─▶   ─WDAT─   ──RXDAT─▶│Subordinate│
│Node      ├──TXRSP─▶   ─SRSP─            │Node       │
│channel   │◀─RXRSP─    ─CRSP─   ◀─RXRSP──┤channel    │
│desigation│◀─RXDAT─    ─RDAT─   ◀─RXDAT──┤desigation │
│          │◀─RXSNP─    ─SNP──            │           │
└──────────┘                              └───────────┘ISA
Arm
cond code
2021.armv8.pdf: C1.2.4: Table C1-1
| cond | Mnem | Mean(int) | Mean(flp) | Cond flags | 
|---|---|---|---|---|
| 0000 | EQ | == | == | Z==1 | 
| 0001 | NE | != | != or unordered | Z==0 | 
| 0010 | CS or HS | Carry set | >=, or unordered | C==1 | 
| 0011 | CC or LO | Carry clear | < | C==0 | 
| 0100 | MI | Minus, negative | < | N==1 | 
| 0101 | PL | Plus, positive or zero | >=, or unordered | N==0 | 
| 0110 | VS | Overflow | Unordered | V==1 | 
| 0111 | VC | No overflow | Ordered | V==0 | 
| 1000 | HI | Unsigned higher | >, or unordered | C==1&&Z==0 | 
| 1001 | LS | Unsigned lower or same | <= | !(C==1&&Z==0) | 
| 1010 | GE | Signed >= | >= | N==V | 
| 1011 | LT | Signed < | <, or unordered | N!=V | 
| 1100 | GT | Signed > | > | Z==0&&N==V | 
| 1101 | LE | Signed <= | <=, or unordered | !(Z==0&&N==V) | 
| 1110 | AL | Always | Always | Any | 
| 1111 | NV | Always | Always | Any | 
cond flags
2021.armv8.pdf: B1.2.2 2021.armv8.pdf: C5.2.9
// gdb: p cpsr # Current Program Status Register
// 6     333222       | N: Negative
// 3 ... 210987 ... 0 | Z: Zero
//  RES0  NZCV  RES0  | C: Carry (unsigned)
//                    | V: Overflow (signed)
//
mrs x1, NZCV // get NZCV
msr NZCV, x1 // set NZCVpage size (Manual)
2021.armv8.pdf:
- D5.2.7:
- granule & block size
 
- D5.5.6
- The Contiguous bit
 
page size (Linux)
arch/arm64/mm/hugetlbpage.c
| Page Size | CONT PTE | PMD | CONT PMD | PUD | 
|---|---|---|---|---|
| 4K | 64K | 2M | 32M | 1G | 
| 16K | 2M | 32M | 1G | |
| 64K | 2M | 512M | 16G | 
ldst align
2021.armv8.pdf
B2.5.2
- Load or Store of Single or Multiple regs
- Load/Store-Exclusive and Atomic insts
- Non-atomic Load-Acquire/Store-Release insts
Exception levels
| EL | Description | Typical | 
|---|---|---|
| EL0 | unprivileged execution | Applications | 
| EL1 | privileged execution | OS kernel | 
| EL2 | virtualization | Hypervisor | 
| EL3 | switching between Secure/Non-secure state | Secure monitor | 
addr
- normal: [x1]
- offset: [x1, #12]
- pre-index: [x1, #12]!// x1+=12, addr=x1
- post-index: [x1], #12// addr=x1, x1+=12
no cmov?
ptr auth
- 2017: LWN
- § Pointer authentication in AArch64 state
arm linux only use bottom 40 bits of a pointer
pointer[63:40] = PAC(pointer[39:40], key, modifier)
AUT(pointer[63:40], pointer[39:40], key, modifier)five separate keys:
- two for executable (instruction) pointers
- two for data pointers
- one generic pointers
ldtr, sttr
ldnp, stnp
ARMv8
Non-temporal load and store pair
Hint mem system no cache, typically in streaming data.
ldaxr, stxr
E.g. an atomic subtract
1f404:   ldaxr   w1, [x0]
1f408:   sub     w2, w1, #0x1
1f40c:   stxr    w3, w2, [x0]
1f410:   cbnz    w3, 1f404cannot be nested,
as each hardware thread supports only one monitor.
Privilege Levels
nVHE (none Virtualization Host Extensions)
| EL0 | Guest Apps                | Host Apps |
| EL1 | Guest OS                  | Host OS   |
| EL2 | Hypervisor                            |
| EL3 | Secure Monitor / Firmware             |VHE (Virtualization Host Extensions)
| EL0 | Guest Apps                | Host Apps |
| EL1 | Guest OS                  | -         |
| EL2 | Hypervisor + Host OS                  |
| EL3 | Secure Monitor / Firmware             |Virt
2019.armv8a_virt.pdf
- CPU
- 5 Trapping and emulation of instructions
- 6 Virtualizing exceptions
- Generic Interrupt Controller (GIC version >= 2)
 
- 7 Virtualizing the Generic Timers
 
- Mem
- 4 Stage2 translation
 
- IO
- 4.6 System Memory Management Units (SMMU, IOMMU)
 
riscv
base
2023.riscv-unpriv.pdf: Preface & TOC
Version 20191214, Revised 20230723
| Base | Description | Ver | Status | 
|---|---|---|---|
| RVWMO | 2.0 | Ratified | |
| RV32I | 2.1 | Ratified | |
| RV64I | 2.1 | Ratified | |
| RV32E | 2.0 | Ratified | |
| RV64E | 2.0 | Ratified | |
| RV128I | 1.7 | Draft | 
extensions
| Ext | Description | Ver | Status | 
|---|---|---|---|
| A | Atomic instructions | ||
| B | Bit manipulation | ||
| C | Compressed instructions | ||
| D | Double-precision floating-point | ||
| F | Single-precision floating-point | ||
| Q | Quad-precision floating-point | ||
| Zfh | Half-precision floating-point | ||
| Zfhmin | Minimal half-precision floating-point (subset of the Zfh) | ||
| Zfinx | Single-precision floating-point in x registers (GPRs) | ||
| Zdinx | Double-precision floating-point in x registers (GPRs) | ||
| Zhinx | Half-precision floating-point in x registers (GPRs) | ||
| Zhinxmin | Minimal half-precision floating-point in x registers (GPRs) | ||
| G | Shorthand for IMAFD extensions | ||
| H | Hypervisor extension | ||
| J | Dynamically translated languages | ||
| L | Decimal floating-point | ||
| M | Integer multiplication and division | ||
| N | User-level interrupts | ||
| P | Packed-SIMD instructions | ||
| S | Supervisor mode | ||
| T | Transactional memory | ||
| V | Vector operations | ||
| Zifencei | Instruction-fetch fence | ||
| Zihintntl | Non-temporal locality hints | ||
| Zihintpause | Pause hint | ||
| Zicsr | Control and status register (CSR) instructions | ||
| Zicntr | Base counters and timers | ||
| Zihpm | Hardware performance counters | ||
| Zimop | May-be-operations | ||
| Zam | Misaligned atomics | ||
| Ztso | Total store ordering | ||
| Zfa | Additional floating-point instructions | 
combination
| Combination | Extensions | 
|---|---|
| RV32G/RV64G | IMAFDZicsr_Zifencei | 
privilege modes
2024.riscv-priv.pdf: 19.1: Privilege Modes
| Virt | Privilege | Abbr | Name | 2Stage Trans | 
|---|---|---|---|---|
| 0 | U | U | User mode | Off | 
| 0 | S | HS | Hypervisor-extended supervisor mode | Off | 
| 0 | M | M | Machine Mode | Off | 
| 1 | U | VU | Virtual user mode | On | 
| 1 | S | VS | Virtual supervisor mode | On | 
regs
https://en.wikichip.org/wiki/risc-v/registers
- C col: 3-bit compressed encoding
- Last col: save by caller or callee
| C | Reg | ABI | Description | |
|---|---|---|---|---|
| - | x0 | zero | hardwired zero | - | 
| - | x1 | ra | return addr | r | 
| - | x2 | sp | stack pointer | e | 
| - | x3 | gp | global pointer | - | 
| - | x4 | tp | thread pointer | - | 
| - | x5-7 | t0-2 | temp reg 0-2 | r | 
| 0 | x8 | s0/fp | saved reg 0/frame pointer | e | 
| 1 | x9 | s1 | saved reg 1 | e | 
| 2-3 | x10-11 | a0-1 | func arg 0-1/ret val 0-1 | r | 
| 4-7 | x12-15 | a2-5 | func arg 2-7 | r | 
| - | x16-17 | a6-7 | func arg 6-7 | r | 
| - | x18-27 | s2-11 | saved reg 2-11 | e | 
| - | x28-31 | t3-t6 | temp reg 3-6 | r | 
imsic csrs
| *iselect | name | 
|---|---|
| 0x72 | eithreshold | 
| 0x80 | eip0 | 
| 0x81 | eip1 | 
| … | |
| 0xBF | eip63 | 
| 0xC0 | eie0 | 
| 0xC1 | eie1 | 
| … | |
| 0xFF | eie63 | 
imsic mem map
Memory region for an interrupt file
| off | size | name | 
|---|---|---|
| 0x00 | 4 | seteipnum_le | 
| 0x04 | 4 | seteipnum_be | 
Privilege Levels
|   | V=0 |                | V=1 |            |
| U | U   | Host Apps      | VU  | Guest Apps |
| S | HS  | Host OS        | VS  | Guest OS   |
| M | M   | Firmware (SBI) | -   | -          |Virt
- CPU
- H Extensions
- 2025.riscv-aia.pdf
 
- Mem
- H Extensions
 
- IO
- IOMMU: 2024.riscv-iommu.pdf
 
x86
Cache Parameters
2022.intel64_opt.pdf
搜索Cache Parameters可搜到各个架构的cache参数
caller/callee reg
x86_64-abi.pdf: Figure 3.4
x86-64-linux callee saved regs:
%rbx, %rbp, %r12-r15
conditinal code
2018.intel64.pdf: Volume 1: Appendix B: Table B-1
| CC | subcode | status | 
|---|---|---|
| O | 0000 | OF | 
| NO | 0001 | !OF | 
| C, B, NAE | 0010 | CF | 
| NB, AE | 0011 | !CF | 
| E, Z | 0100 | ZF | 
| NE, NZ | 0101 | !ZF | 
| BE, NA | 0110 | CF|ZF | 
| NBE, A | 0111 | !(CF|ZF) | 
| S | 1000 | SF | 
| NS | 1001 | !SF | 
| P, PE | 1010 | PF | 
| NP, PO | 1011 | !PF | 
| L, NGE | 1100 | SF!=OF | 
| NL, GE | 1101 | SF==OF | 
| LE, NG | 1110 | (SF!=OF)|ZF | 
| NLE, G | 1111 | !((SF!=OF)|ZF) | 
rflags/eflags
2020.amd64.pdf: 3.1.4
// 11           | Overflow  Direction
// 10..76.4.2.0 | Sign      Zero
// OD  SZ A P C | Auxiliary Parity
//              | Carry
pushf // get
popf  // setregs ext
2020.amd64.pdf: 3.1.2
- byte(8) & word(16) oprs not modify high 56 or 48 bits
- dword(32) oprs zero-extended to 64 bits.
legacy encode
2020.amd64.pdf: Figure 1-2
2018.intel64.pdf: Figure 2-1
| Name | B | Description | 
|---|---|---|
| Legacy Prefix | ≤5 | optional | 
| REX | 1 | 64-bit mode only | 
| Escape | 2 | optional | 
| Opcode | 1 | |
| ModRM | 1 | optional | 
| SIB | 1 | optional | 
| Displacement | ||
| Immediate | 
ext encode
2020.amd64.pdf: Figure 1-2
| Name | B | Description | 
|---|---|---|
| Legacy Prefix | ≤4 | optional | 
| VEX/XOP | 1 | |
| RXB.map+Select | 1 | not for VEX C5 | 
| W.vvvv.L.pp | 1 | not for VEX C5 | 
| R.vvvv.L.pp | 1 | for VEX C5 | 
| Opcode | 1 | |
| ModRM | 1 | optional | 
| SIB | 1 | optional | 
| Displacement | 1,2,4,8 | 8B Disp & 8B Imm mutual exclusive | 
| Immediate | 1,2,4,8 | 8B Disp & 8B Imm mutual exclusive | 
page size
2020.amd64.pdf: Table 5-1
- PAE: Physical-Address Extensions
- PSE: Page-Size Extensions
- PDPE:
- PDE
| Mode | PAE | PSE | PDPE.PS | PDE.PS | Page Size | Max VA | Max PA | 
|---|---|---|---|---|---|---|---|
| Long | 1 | - | 0 | 0 | 4KB | 64bit | 52bit | 
| Long | 1 | - | 0 | 1 | 2MB | 64bit | 52bit | 
| Long | 1 | - | 1 | - | 1GB | 64bit | 52bit | 
| Legacy | 1 | - | 0 | 0 | 4KB | 32bit | 52bit | 
| Legacy | 1 | - | 0 | 1 | 2MB | 32bit | 52bit | 
| Legacy | 0 | 0 | 0 | - | 4KB | 32bit | 32bit | 
| Legacy | 0 | 1 | 0 | 0 | 4kB | 32bit | 32bit | 
| Legacy | 0 | 1 | 0 | 1 | 4MB | 32bit | 40bit | 
mnemonic syntax
2020.amd64.pdf: Volume 3: 2.5.1
        ADDPD xmm1, xmm2/mem128
        ──┬── ──┬─  ───────┬───
Mnemonic ─┘     │          │
                └────────┐ │
First Source Operand    ─┘ │
and Destination Operand    │
                           │
Second Source Operand ─────┘opcode syntax
2020.amd64.pdf: Volume 3: 2.5.2
2018.intel64.pdf: Volume 2: 3.1.1.1
modrm
2020.amd64.pdf: Table 1-10
ModRM = mod[2] : reg[3] : r/m[3]
M: MMX, X: XMM, Y: YMM
| b | reg | r/m (mod=11b) | r/m (mod!=11b) | 
|---|---|---|---|
| 000 | rAX,M0,X0,Y0 | rAX,M0,X0,Y0 | [rAX] | 
| 001 | rCX,M1,X1,Y1 | rCX,M1,X1,Y1 | [rCX] | 
| 010 | rDX,M2,X2,Y2 | rDX,M2,X2,Y2 | [rDX] | 
| 011 | rBX,M3,X3,Y3 | rBX,M3,X3,Y3 | [rBX] | 
| 100 | AH,rSP,M4,X4,Y4 | AH,rSP,M4,X4,Y4 | SIB | 
| 101 | CH,rBP,M5,X5,Y5 | CH,rBP,M5,X5,Y5 | [rBP]* | 
| 110 | DH,rSI,M6,X6,Y6 | DH,rSI,M6,X6,Y6 | [rSI] | 
| 111 | BH,rDI,M7,X7,Y7 | BH,rDI,M7,X7,Y7 | [rDI] | 
sib
2020.amd64.pdf: Table 1-12
SIB = scale[2] : index[3] : base[3]
scale = 2^(SIB.scale)
| b | index | base | 
|---|---|---|
| 000 | [rAX] | [rAX] | 
| 001 | [rCX] | [rCX] | 
| 010 | [rDX] | [rDX] | 
| 011 | [rBX] | [rBX] | 
| 100 | (none)1 | [rSP] | 
| 101 | [rBP] | [rBP], (none)2 | 
| 110 | [rSI] | DH, [rSI] | 
| 111 | [rDI] | BH, [rDI] | 
mem opr
- Seg Selector: 16
- Offset (or Linear Addr): 32/64
mem opr: seg
2018.intel64.pdf: Table 3-5
Default Segment Selection
| Ref Type | Reg | Default Rule | 
|---|---|---|
| Inst | CS | All inst fetches | 
| Stack | SS | All pushes & pops | 
| Local Data | DS | All data, except relative to stack or string destination | 
| Destination Strings | ES | Destination string inst | 
mem opr: off
2018.intel64.pdf: Table 3-5
Offset =
  Base  + (Index * Scale) + Displacement
  +- -+   +- -+     +-+      +------+
  |eax|   |eax|     |1|      |None  |
  |ebx|   |ebx|     |2|      |8-bit |
  |ecx|   |ecx|     |4|      |16-bit|
  |edx| + |edx|  *  |8|   +  |32-bit|
  |esp|   |ebp|     | |      |      |
  |ebp|   |esi|     | |      |      |
  |esi|   |edi|     | |      |      |
  |edi|   |   |     | |      |      |
  +- -+   +---+     +-+      +------+seg regs
- 32-bit mode
- 6 seg regs, support seg limit
 
- 64-bit mode
- C/S/D/ES are ignored, base addr is 0
- FS: Thread Local Storage(TLS)
- GS: use freely by app
 
Read and write from user space
- syscall: arch_prctl()
- FSGSBASE inst family (introduced by Ivy Bridge)
Addressing
- compiler: __seg_fs,__seg_gs
- assembly: mov %fs:offset, %reg,mov %reg, %fs:offset
Privilege Levels (AMD)
2020.amd64.pdf: 15 Secure Virtual Machine
|      | Host Mode | Guest Mode |
| CPL3 | Host Apps | Guest Apps |
| CPL2 | -         | -          |
| CPL1 | -         | -          |
| CPL0 | Host OS   | Guest OS   |Privilege Levels (Intel)
2023.intel64.pdf: Chapter 24 Introduction to Virtual Machine Extensions
|      | Root Operation | Non-root Operation |
| CPL3 | Host Apps      | Guest Apps         |
| CPL2 | -              | -                  |
| CPL1 | -              | -                  |
| CPL0 | Host OS        | Guest OS           |Virt (AMD)
2020.amd64.pdf: 15 Secure Virtual Machine
TODO
- CPU
- Mem
- IO
Virt (Intel)
2023.intel64.pdf: Chapter 24 Introduction to Virtual Machine Extensions
TODO
- CPU
- Mem
- IO