Initial poop
This commit is contained in:
commit
ca6dab46f1
3280 changed files with 3759 additions and 0 deletions
78
docs/programming/calling_conventions.md
Normal file
78
docs/programming/calling_conventions.md
Normal file
|
@ -0,0 +1,78 @@
|
|||
# Calling Conventions
|
||||
|
||||
## Cheatsheet
|
||||
|
||||
| Platform | Return Value | Parameter Registers | Additional Parameters | Stack Alignment | Scratch Registers | Preserved Registers | Call List |
|
||||
| -------------------------------------------------------------------- | ------------ | -------------------------- | -------------------------------------------------------------------------- | -------------------------------------------------------------------- | ----------------------------------------- | ------------------------------------------- | --------- |
|
||||
| System V i386 | eax, edx | none | stack (right to left)[1](https://wiki.osdev.org/Calling_Conventions#Note1) | | eax, ecx, edx | ebx, esi, edi, ebp, esp | ebp |
|
||||
| System V X86_64[2](https://wiki.osdev.org/Calling_Conventions#Note2) | rax, rdx | rdi, rsi, rdx, rcx, r8, r9 | stack (right to left)[1](https://wiki.osdev.org/Calling_Conventions#Note1) | 16-byte at call[3](https://wiki.osdev.org/Calling_Conventions#Note3) | rax, rdi, rsi, rdx, rcx, r8, r9, r10, r11 | rbx, rsp, rbp, r12, r13, r14, r15 | rbp |
|
||||
| Microsoft x64 | rax | rcx, rdx, r8, r9 | stack (right to left)[1](https://wiki.osdev.org/Calling_Conventions#Note1) | 16-byte at call[3](https://wiki.osdev.org/Calling_Conventions#Note3) | rax, rcx, rdx, r8, r9, r10, r11 | rbx, rdi, rsi, rsp, rbp, r12, r13, r14, r15 | rbp |
|
||||
| ARM (32-bit) | r0, r1 | r0, r1, r2, r3 | stack | 8 byte[4](https://wiki.osdev.org/Calling_Conventions#Note4) | r0, r1, r2, r3, r12 | r4, r5, r6, r7, r8, r9, r10, r11, r13, r14 | |
|
||||
|
||||
## System V i386
|
||||
|
||||
- Parametres are pushed to stack from right to left
|
||||
- Caller cleans the stack
|
||||
- Callee is free to modify parametres
|
||||
- Caller must not assume they stayed the same!
|
||||
- Scratch registers are `EAX`, `ECX` and `EDX`
|
||||
- Caller must preserve if needed
|
||||
- Function preserves `EBX`, `ESI`, `EDI` and `EBP`
|
||||
- Return value in `EAX`
|
||||
- If 64bit value: higher 32bits in `EDX`
|
||||
- Functions push `ebp` such that the caller-return-eip is 4 bytes above it, and set `ebp` to the address of the saved ebp.
|
||||
- Allows iterating through the existing stack frames.
|
||||
- Can be eliminated by specifying the -fomit-frame-pointer GCC option.
|
||||
|
||||
## CDECL
|
||||
|
||||
**Caller's responsibilities**
|
||||
- Push parameters in reverse order (last parameter pushed first)
|
||||
- Perform the call
|
||||
- Pop the parameters, use them, or simply increment `ESP` to remove them (stack clearing)
|
||||
- The return value is stored in `EAX`
|
||||
|
||||
**Callee's responsibilities (callee is the routine being called)**
|
||||
- Store caller's `EBP` on the stack
|
||||
- Save current `ESP` in `EBP`
|
||||
- Code, storing local data on the stack
|
||||
- For a fast exit load the old `ESP` from `EBP`, else pop local data elements
|
||||
- Pop the old `EBP` and return – store return value in `EAX`
|
||||
|
||||
**It looks like this in assembly (NASM)**
|
||||
``` nasm
|
||||
SECTION .text
|
||||
|
||||
caller:
|
||||
|
||||
; ...
|
||||
|
||||
; Caller responsibilities:
|
||||
PUSH 3 ; push the parameters in reverse order
|
||||
PUSH 2
|
||||
CALL callee ; perform the call
|
||||
ADD ESP, 8 ; stack cleaning (remove the 2 words)
|
||||
|
||||
; ... Use the return value in EAX ...
|
||||
|
||||
|
||||
callee:
|
||||
|
||||
; Callee responsibilities:
|
||||
PUSH EBP ; store caller's EBP
|
||||
MOV EBP, ESP ; save current stack pointer in EBP
|
||||
|
||||
; ... Code, store return value in EAX ...
|
||||
|
||||
; Callee responsibilities:
|
||||
MOV ESP, EBP ; remove an unknown number of local data elements
|
||||
POP EBP ; restore caller's EBP
|
||||
RET ; return
|
||||
```
|
||||
|
||||
## Sources
|
||||
- [https://wiki.osdev.org/Stack](https://wiki.osdev.org/Stack)
|
||||
- [https://wiki.osdev.org/Calling_Conventions](https://wiki.osdev.org/Calling_Conventions)
|
||||
- [https://wiki.osdev.org/System_V_ABI](https://wiki.osdev.org/System_V_ABI)
|
||||
|
||||
**TODO:** Check if SysV ABI and CDECL are really the same thing?
|
21
docs/programming/custom-default-editor.md
Normal file
21
docs/programming/custom-default-editor.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Custom default editor
|
||||
If you'd like to for example open #emacs with `-nw` you need to do some trickery.
|
||||
|
||||
Create a script to open the editor and set it executable
|
||||
``` sh title="/usr/local/bin/emacs-nw"
|
||||
#!/bin/sh
|
||||
emacs -nw "$@"
|
||||
```
|
||||
|
||||
Add the script to list of known editors (if using update-alternatives system) and set it default:
|
||||
``` console
|
||||
$ sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/emacs-nw 2;
|
||||
$ sudo update-alternatives --config editor;
|
||||
```
|
||||
|
||||
You may also set variables in `~/.bashrc` like so:
|
||||
``` sh title="~/.bashrc"
|
||||
export VISUAL="emacs"
|
||||
export EDITOR="emacs -nw"
|
||||
```
|
||||
|
24
docs/programming/go.md
Normal file
24
docs/programming/go.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
# GO!
|
||||
|
||||
On Debian 12 you should probably use GO from backports
|
||||
to get a newer version.
|
||||
Set up backports repo and get it with
|
||||
`sudo apt install -t bookworm-backports golang`
|
||||
|
||||
## Packaging DEB
|
||||
|
||||
- `sudo apt install git-buildpackage`
|
||||
- Create directory `./debian`
|
||||
- Create changelog with `dch --create`
|
||||
- `sudo apt install dh-golang`
|
||||
|
||||
Example rules:
|
||||
``` make
|
||||
#!/usr/bin/make -f
|
||||
# Uncomment this to turn on verbose mode.
|
||||
#export DH_VERBOSE=1
|
||||
%:
|
||||
dh $@ --builddirectory=_build
|
||||
```
|
||||
|
||||
Check out [Debian Go-Team Packaging](https://go-team.pages.debian.net/packaging.html)
|
16
docs/programming/rust/crosscompiling.md
Normal file
16
docs/programming/rust/crosscompiling.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Crosscompiling
|
||||
|
||||
## Linux to Windows
|
||||
|
||||
### Dependencies
|
||||
|
||||
``` console
|
||||
$ rustup target list
|
||||
$ rustup target add x86_64-pc-windows-gnu
|
||||
$ sudo apt install mingw-w64
|
||||
```
|
||||
|
||||
### Building
|
||||
``` console
|
||||
$ cargo build --release --target=x86_64-pc-windows-gnu
|
||||
```
|
3
docs/programming/rust/installing.md
Normal file
3
docs/programming/rust/installing.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Installing
|
||||
|
||||
I suggest using [rustup](https://rustup.rs) for this. It is being [packaged](https://packages.debian.org/trixie/rustup) in Debian 13 (Trixie) but meanwhile use `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` which sets up the default toolchain for you.
|
18
docs/programming/watchdir.md
Normal file
18
docs/programming/watchdir.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Watch directory for changes
|
||||
|
||||
Watching directory for changes can be useful for example let's say you have a markdown based knowledgebase and want to automagically rebuild statically served html-site. Like this one right here!
|
||||
|
||||
## Script
|
||||
|
||||
Use #bash and make a fancy scriptie using `inotify-tools`. This can be installed from debian repos using `sudo apt install inotify-tools`. For example this #mkdocs site uses following at the time of writing:
|
||||
|
||||
``` sh
|
||||
#!/bin/sh
|
||||
. bin/activate
|
||||
while true
|
||||
do
|
||||
mkdocs build
|
||||
inotifywait -r dokut
|
||||
done
|
||||
```
|
||||
Main takes here are the infinite loop that rebuilds docs and then waits for any change in directory (recursively) before looping again. Here would also be a good place to setup some `sleep`ing to ratelimit things or a more complex script to even wait no more changes are detected for some time...
|
Loading…
Add table
Add a link
Reference in a new issue