diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..4700f8945b9a985020feca3c3f335c3d3cb26c74 --- /dev/null +++ b/LICENSE @@ -0,0 +1,12 @@ +Copyright (C) 2024, Mitja Felicijan + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 Binary files /dev/null and b/README.md differ diff --git a/c-asm/.clang-format b/c-asm/.clang-format new file mode 100644 index 0000000000000000000000000000000000000000..5f0e5858e8486f9ed0471951032c497a07a45ef1 --- /dev/null +++ b/c-asm/.clang-format @@ -0,0 +1,4 @@ +BasedOnStyle: Chromium +ColumnLimit: 120 +IndentWidth: 4 + diff --git a/c-asm/Makefile b/c-asm/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..907e50c3352a7c59c5202fab494bf4e74743e0f6 --- /dev/null +++ b/c-asm/Makefile @@ -0,0 +1,13 @@ +all: a.out + +sum.o: + as sum.s -o sum.o + +a.out: sum.o + gcc main.c sum.o + +clean: + -rm a.out *.o + +tags: + ctags -R * diff --git a/c-asm/main.c b/c-asm/main.c new file mode 100644 index 0000000000000000000000000000000000000000..56b9bc5cbf578107f348194e66fd1b69fcd13ab8 --- /dev/null +++ b/c-asm/main.c @@ -0,0 +1,11 @@ +#include + +int sum(int a, int b); + +int main() { + for (int i = 0; i < 10; ++i) { + printf("SUM of 5+%d is %d\n", i, sum(5, i)); + } + + return 0; +} diff --git a/c-asm/sum.s b/c-asm/sum.s new file mode 100644 index 0000000000000000000000000000000000000000..8b943b999927cdde6e1adddd76b1b9b7e2ea03f9 --- /dev/null +++ b/c-asm/sum.s @@ -0,0 +1,11 @@ +.intel_syntax noprefix + +.global sum + +.text + +sum: + add rdi, rsi + mov rax, rdi + ret + diff --git a/c-embed/.clang-format b/c-embed/.clang-format new file mode 100644 index 0000000000000000000000000000000000000000..5f0e5858e8486f9ed0471951032c497a07a45ef1 --- /dev/null +++ b/c-embed/.clang-format @@ -0,0 +1,4 @@ +BasedOnStyle: Chromium +ColumnLimit: 120 +IndentWidth: 4 + diff --git a/c-embed/Makefile b/c-embed/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..29e4f2d0159a0512b6650b7d48ad9c87bb057737 --- /dev/null +++ b/c-embed/Makefile @@ -0,0 +1,6 @@ +a.out: + xxd -i test.txt > test.h + gcc -Wall -Werror -Wpedantic main.c + +clean: + -rm a.out diff --git a/c-embed/main.c b/c-embed/main.c new file mode 100644 index 0000000000000000000000000000000000000000..c0d2f591e05177dc7700091be770944678ec10eb --- /dev/null +++ b/c-embed/main.c @@ -0,0 +1,19 @@ +#include + +#include "test.h" + +int main(void) { + printf("Testing embedding of files into binary.\n"); + + for (unsigned int i = 0; i < test_txt_len; i++) { + printf("%02x ", test_txt[i]); + } + printf("\n\n"); + + for (unsigned int i = 0; i < test_txt_len; i++) { + printf("%c", test_txt[i]); + } + printf("\n\n"); + + return 0; +} diff --git a/c-embed/test.h b/c-embed/test.h new file mode 100644 index 0000000000000000000000000000000000000000..cfdfa3a182039ef6cceae7d69378b46277394e0f --- /dev/null +++ b/c-embed/test.h @@ -0,0 +1,49 @@ +unsigned char test_txt[] = { + 0x54, 0x68, 0x65, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x72, 0x75, + 0x6c, 0x65, 0x20, 0x69, 0x73, 0x20, 0x74, 0x79, 0x70, 0x69, 0x63, 0x61, + 0x6c, 0x20, 0x6f, 0x66, 0x20, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x75, 0x6d, + 0x20, 0x70, 0x68, 0x79, 0x73, 0x69, 0x63, 0x73, 0x2e, 0x20, 0x49, 0x74, + 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x20, 0x66, 0x72, 0x6f, + 0x6d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x6f, 0x73, 0x74, 0x75, 0x6c, + 0x61, 0x74, 0x65, 0x20, 0x6f, 0x66, 0x0a, 0x75, 0x6e, 0x69, 0x74, 0x61, + 0x72, 0x79, 0x20, 0x65, 0x76, 0x6f, 0x6c, 0x75, 0x74, 0x69, 0x6f, 0x6e, + 0x2e, 0x20, 0x54, 0x68, 0x65, 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, + 0x20, 0x72, 0x75, 0x6c, 0x65, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x63, + 0x6c, 0x61, 0x73, 0x73, 0x69, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x75, 0x6c, + 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x64, 0x64, + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x0a, 0x70, 0x72, 0x6f, + 0x62, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x69, 0x65, 0x73, 0x2e, 0x20, + 0x49, 0x74, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x20, 0x66, + 0x72, 0x6f, 0x6d, 0x20, 0x64, 0x65, 0x63, 0x6f, 0x68, 0x65, 0x72, 0x65, + 0x6e, 0x63, 0x65, 0x20, 0x74, 0x68, 0x72, 0x6f, 0x75, 0x67, 0x68, 0x20, + 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, + 0x20, 0x57, 0x68, 0x65, 0x6e, 0x0a, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6d, + 0x65, 0x64, 0x69, 0x61, 0x74, 0x65, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, + 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x64, 0x2c, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6f, 0x62, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x64, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, + 0x69, 0x73, 0x20, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, + 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x61, 0x0a, 0x6d, 0x69, 0x78, 0x74, + 0x75, 0x72, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, + 0x73, 0x2e, 0x20, 0x54, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x69, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x75, 0x6c, 0x65, 0x20, 0x6f, 0x66, + 0x20, 0x61, 0x64, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, + 0x20, 0x70, 0x72, 0x6f, 0x62, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x69, + 0x65, 0x73, 0x20, 0x6d, 0x75, 0x73, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, + 0x20, 0x62, 0x65, 0x0a, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x64, 0x2e, + 0x20, 0x45, 0x6e, 0x74, 0x61, 0x6e, 0x67, 0x6c, 0x65, 0x6d, 0x65, 0x6e, + 0x74, 0x20, 0x62, 0x79, 0x20, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x75, 0x73, 0x20, 0x65, 0x78, + 0x70, 0x6c, 0x61, 0x69, 0x6e, 0x73, 0x20, 0x46, 0x65, 0x79, 0x6e, 0x6d, + 0x61, 0x6e, 0x27, 0x73, 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, + 0x72, 0x75, 0x6c, 0x65, 0x2e, 0x20, 0x54, 0x68, 0x69, 0x73, 0x0a, 0x65, + 0x78, 0x70, 0x6c, 0x61, 0x69, 0x6e, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, + 0x46, 0x65, 0x79, 0x6e, 0x6d, 0x61, 0x6e, 0x20, 0x52, 0x75, 0x6c, 0x65, + 0x73, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x63, 0x61, 0x6c, 0x63, 0x75, 0x6c, + 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x70, 0x72, 0x6f, 0x62, 0x61, 0x62, + 0x69, 0x6c, 0x69, 0x74, 0x69, 0x65, 0x73, 0x20, 0x69, 0x6e, 0x20, 0x71, + 0x75, 0x61, 0x6e, 0x74, 0x75, 0x6d, 0x20, 0x70, 0x68, 0x79, 0x73, 0x69, + 0x63, 0x73, 0x0a, 0x28, 0x46, 0x65, 0x79, 0x6e, 0x6d, 0x61, 0x6e, 0x20, + 0x31, 0x39, 0x36, 0x36, 0x29, 0x2e, 0x0a +}; +unsigned int test_txt_len = 547; diff --git a/c-embed/test.txt b/c-embed/test.txt new file mode 100644 index 0000000000000000000000000000000000000000..a3cac179a4aebeee77dd9032bcd85fc4e1795cfe --- /dev/null +++ b/c-embed/test.txt @@ -0,0 +1,8 @@ +The first rule is typical of quantum physics. It results from the postulate of +unitary evolution. The second rule is a classical rule of the addition of +probabilities. It results from decoherence through observation. When +intermediate states are observed, the observed system is represented by a +mixture of states. The classical rule of addition of probabilities must then be +applied. Entanglement by observation thus explains Feynman's second rule. This +explains the Feynman Rules for calculating probabilities in quantum physics +(Feynman 1966). diff --git a/c-signals/.clang-format b/c-signals/.clang-format new file mode 100644 index 0000000000000000000000000000000000000000..5f0e5858e8486f9ed0471951032c497a07a45ef1 --- /dev/null +++ b/c-signals/.clang-format @@ -0,0 +1,4 @@ +BasedOnStyle: Chromium +ColumnLimit: 120 +IndentWidth: 4 + diff --git a/c-signals/Makefile b/c-signals/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..afd71c3e7d9281f9d49601209f84496f094be05e --- /dev/null +++ b/c-signals/Makefile @@ -0,0 +1,5 @@ +a.out: + gcc -Wall -Werror -Wpedantic main.c + +clean: + -rm a.out diff --git a/c-signals/main.c b/c-signals/main.c new file mode 100644 index 0000000000000000000000000000000000000000..a471016279ed7dc73cedaa5b1fed545cbd98ceaa --- /dev/null +++ b/c-signals/main.c @@ -0,0 +1,21 @@ +#include +#include +#include +#include + +void handle_signal(int signal) { + printf("Signal received %d\n", signal); +} + +// use “kill -10 pidof a.out“ +// https://www.man7.org/linux/man-pages/man7/signal.7.html +int main(void) { + signal(SIGUSR1, handle_signal); + signal(SIGUSR2, handle_signal); + + printf("Waiting for signals...\n"); + for (;;) + sleep(1); + + return 0; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000000000000000000000000000000000000..ae3a692902c9607a4843c813ccb19001430d0746 --- /dev/null +++ b/shell.nix @@ -0,0 +1,9 @@ +{ pkgs ? import {} }: + pkgs.mkShell { + nativeBuildInputs = with pkgs.buildPackages; [ + binutils + gnumake + nasm + tinycc + ]; +}