about summary refs log tree commit diff
path: root/historical
diff options
context:
space:
mode:
Diffstat (limited to 'historical')
-rw-r--r--historical/describe-data.sed49
-rw-r--r--historical/describe-heap.sed11
-rw-r--r--historical/describe-redact.sed5
-rw-r--r--historical/exit-code.asm99
-rw-r--r--historical/exit-code.gnu.asm29
5 files changed, 193 insertions, 0 deletions
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/\<roll3\>/3roll/g
+s/\<unroll3\>/3unroll/g
+s/\<dup2\>/2dup/g
+s/\<drop2\>/2drop/g
+s/^zbranch\>/0branch/g
+s/\([^"]\)\<zbranch\>/\10branch/g
+s/\<eq\>/=/g
+s/\<ne\>/!=/g
+s/\<gt\>/>/g
+s/\<lt\>/</g
+s/\<ge\>/>=/g
+s/\<le\>/<=/g
+s/\([^a-z]\)-unsigned\>/\1unsigned/g
+s/\<divmod\>\([^-]\)/\/%\1/g
+s/\<mul\>\([^-]\)/*\1/g
+s/\<sub\>\([^-]\)/-\1/g
+s/\<add\>\([^-]\)/+\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/\([^-]\)\<cc-/\1:cc-/g
+s/^cc-/:cc-/g
+s/\<fetch\(8\|16\|32\|64\)\>/\1@/g
+s/\<store\(8\|16\|32\|64\)\>/\1!/g
+s/\<addstore\>/+!/g
+s/\<substore\>/-!/g
+s/\<fetch-value-stack\>/value@/g
+s/\<store-value-stack\>/value!/g
+s/\<fetch-control-stack\>/control@/g
+s/\<store-control-stack\>/control!/g
+s/\<fetch-entry-flags\>/entry-flags@/g
+s/\<store-entry-flags\>/entry-flags!/g
+s/\<fetch\>/@/g
+s/\<store\>/!/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
+