From e889b122cee2eb60cd1577c22560c8918b30d749 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Mon, 5 Oct 2026 01:58:58 -0700 Subject: move around a bunch of the files that aren't actually in use to better describe their status Force-Push: yes Change-Id: If5ef70b7872700ff36ef07f20aac1f3b991dff45 --- historical/describe-data.sed | 49 +++++++++++++++++++++ historical/describe-heap.sed | 11 +++++ historical/describe-redact.sed | 5 +++ historical/exit-code.asm | 99 ++++++++++++++++++++++++++++++++++++++++++ historical/exit-code.gnu.asm | 29 +++++++++++++ 5 files changed, 193 insertions(+) create mode 100644 historical/describe-data.sed create mode 100644 historical/describe-heap.sed create mode 100644 historical/describe-redact.sed create mode 100644 historical/exit-code.asm create mode 100644 historical/exit-code.gnu.asm (limited to 'historical') diff --git a/historical/describe-data.sed b/historical/describe-data.sed new file mode 100644 index 0000000..77f3d8e --- /dev/null +++ b/historical/describe-data.sed @@ -0,0 +1,49 @@ +# ./quine | sed -f describe-data.sed > data.txt + +:start +/0000000008/!d +/^0000000008/bmain +bstart + +:main +n + +s/_/-/g +s/\/3roll/g +s/\/3unroll/g +s/\/2dup/g +s/\/2drop/g +s/^zbranch\>/0branch/g +s/\([^"]\)\/\10branch/g +s/\/=/g +s/\/!=/g +s/\/>/g +s/\//>=/g +s/\/<=/g +s/\([^a-z]\)-unsigned\>/\1unsigned/g +s/\\([^-]\)/\/%\1/g +s/\\([^-]\)/*\1/g +s/\\([^-]\)/-\1/g +s/\\([^-]\)/+\1/g +s/\<\([er][acdb]x\)\>/:\1/g +s/\<\([er]\?\([sb]p\|[sd]i\)\)\>/:\1/g +s/\<\([acdb][lhx]\)\>/:\1/g +s/\<\(r[89]\|r1[0-5]\)\>/:\1/g +s/\([^-]\)\/\1@/g +s/\/\1!/g +s/\/+!/g +s/\/-!/g +s/\/value@/g +s/\/value!/g +s/\/control@/g +s/\/control!/g +s/\/entry-flags@/g +s/\/entry-flags!/g +s/\/@/g +s/\/!/g + +bmain + diff --git a/historical/describe-heap.sed b/historical/describe-heap.sed new file mode 100644 index 0000000..f21781b --- /dev/null +++ b/historical/describe-heap.sed @@ -0,0 +1,11 @@ +# ./quine | sed -f describe-heap.sed > heap.txt + +:main +/^0000000008/bdrop +n +bmain + +:drop +s/.*// +N +bdrop diff --git a/historical/describe-redact.sed b/historical/describe-redact.sed new file mode 100644 index 0000000..1303058 --- /dev/null +++ b/historical/describe-redact.sed @@ -0,0 +1,5 @@ +# Pipe either memory segment's output through this after the other script, +# to remove things that depend on exact addresses. + +/^[0-9a-f]\{16\}/d +s/^ lit [0-9]\+ exit$/ lit REDACTED exit/ diff --git a/historical/exit-code.asm b/historical/exit-code.asm new file mode 100644 index 0000000..498bfc4 --- /dev/null +++ b/historical/exit-code.asm @@ -0,0 +1,99 @@ +; fasmg exit-code.asm exit-code + +macro mov.d target, source + match =rax?, target + db 0x48, 0xC7, 0xC0 +; 48 eAX REX.W prefix +; (DEC is the 32-bit meaning, ignore it) +; eAX -> register identifier, +; width depends on operand +; REX.W -> set 64-bit operand mode +; c7 Grp 11^1A - MOV Ev, Iz +; immediate to register +; 1A -> bits 5,4,3 of ModR/M are opcode +; extension +; E -> modR/M byte to follow for operand +; v -> word of appropriate size +; I -> immediate data +; z -> 32-bit operand +; c0 ModR/M byte +; 0b11000000 +; 11 mod: always 11 +; 000 op/reg: Mov Ev, Iz +; 00x w absent +; 0 w (ignored) + dd source + else match =rdi, target + db 0x48, 0xC7, 0xC7 +; 7: 48 c7 c7 2a 00 00 00 mov $0x2a,%rdi +; 48 eAX REX.W prefix +; (DEC is the 32-bit meaning, ignore it) +; c7 Grp 11^1A - MOV Ev, Iz +; immediate to register +; 1A -> bits 5,4,3 of ModR/M are opcode +; extension +; Ev -> ModR/M to follow for 32-bit operand +; Iz -> Immediate data, 32-bits +; c7 ModR/M byte +; 0b11000111 +; 11 mod: always 11 +; 000 op/reg: Mov Ev, Iz +; 11x w present +; 1 w true; use EDI + dd source + end match +end macro + +macro syscall + db 0x0F, 0x05 +; 0f two-byte escape +; 05 syscall ^ o64 +end macro + + + + +org 0x08048000 + +elf_header: + db 0x7F, "ELF" + db 2 ; 64-bit + db 1 ; little-endian + db 1 ; ELF header format version 1 + db 0 ; System-V ABI + db 8 dup 0 ; (padding) + + dw 2 ; executable + dw 0x3E ; Intel x86-64 + dd 1 ; ELF format version + + dq _start ; entry point + dq program_header - $$ ; program header offset + dq 0 ; section header offset + dd 0 ; processor flags + dw elf_header_size + dw program_header_entry_size + dw 1 ; number of program header entries + dw 0 ; section header entry size + dw 0 ; number of section header entries + dw 0 ; section name string table index +elf_header_size = $ - elf_header + +program_header: + dd 1 ; "loadable" segment type + dd 0x05 ; read+execute permission + dq 0 ; offset in file + dq $$ ; virtual address + dq 0 ; (padding) + dq file_size ; size in file + dq file_size ; size in memory + dq 0 ; segment alignment +program_header_entry_size = $ - program_header + +_start: + mov.d rax, 60 + mov.d rdi, 42 + syscall + +file_size = $ - $$ + diff --git a/historical/exit-code.gnu.asm b/historical/exit-code.gnu.asm new file mode 100644 index 0000000..48b7e62 --- /dev/null +++ b/historical/exit-code.gnu.asm @@ -0,0 +1,29 @@ +/* + * This file was a very early example, written by consulting [1]. It was + * useful primarily to see how the GNU assembler handles these opcodes, to + * better understand the encoding. + * + * [1] https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html + * + * + * gcc -o exit-code -nostartfiles -nostdlib exit-code.gnu.asm && ./exit-code ; echo $? + * + * or + * + * as -o exit-code.o exit-code.gnu.asm && ld -s -o exit-code exit-code.o && ./exit-code; echo $? + * + * Can't use nasm, nasm is 32-bit only. + * + * Since you get a nice clean file, you can then do: + * + * objdump --disassemble exit-code + */ +.text + +.global _start + +_start: + mov $60, %eax + mov $42, %edi + syscall + -- cgit 1.4.1