summary refs log tree commit diff
path: root/quine.asm
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-04-28 21:44:26 -0700
committerIrene Knapp <ireneista@irenes.space>2026-04-28 21:44:26 -0700
commit4334c11d934cd41f3804820515ff70edac291553 (patch)
tree5d89aa866d380135df14fc9f0a5e0e6ef0a29dc8 /quine.asm
parent5a98d4630c961306d49ee88596c92968e85969e0 (diff)
implement sys-read; rename show-hex* to hexdump*
it's easier to remember that way

Force-Push: yes
Change-Id: I205a49a03209c882eab80db7296d502bfcb206d9
Diffstat (limited to 'quine.asm')
-rw-r--r--quine.asm68
1 files changed, 59 insertions, 9 deletions
diff --git a/quine.asm b/quine.asm
index fb1a8f2..4e30307 100644
--- a/quine.asm
+++ b/quine.asm
@@ -2584,6 +2584,20 @@ cold_start:
   dq rsi, pop_reg64
   dq pack_next, lit, 8, packalign, early_here_store
 
+ ; This was "sys_read".
+  dq litstring, "sys-read", 0, early_create, early_self_codeword
+  dq early_here, fetch
+  dq rcx, pop_reg64
+  dq rdx, pop_reg64
+  dq rsi, push_reg64
+  dq lit, 0, rax, mov_reg64_imm64
+  dq lit, 0, rdi, mov_reg64_imm64
+  dq rcx, rsi, mov_reg64_reg64
+  dq syscall
+  dq rsi, pop_reg64
+  dq rax, push_reg64
+  dq pack_next, lit, 8, packalign, early_here_store
+
   ;   This one has the honor of being the first word written in Forth. To do
   ; that, it needs to be able to look up the words we've defined so far, to
   ; reference them. We have a valid dictionary data structure, and early_find
@@ -8612,6 +8626,20 @@ defword sys_write, 0
   next
 
 
+defword sys_read, 0
+  dq $ + 8
+  pop.qreg rcx                   ; address from stack
+  pop.qreg rdx                   ; length from stack, passed directly
+  push.qreg rsi                  ; save rsi
+  mov.qreg.qimm rax, 0           ; syscall number
+  mov.qreg.qimm rdi, 0           ; file descriptor
+  mov.qreg.qreg rsi, rcx         ; pass address
+  syscall
+  pop.qreg rsi                   ; restore rsi
+  push.qreg rax                  ; return length
+  next
+
+
 ;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; I/O conveniences ;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;
@@ -11299,6 +11327,7 @@ defword boot_source, 0x40
   dq ": is-docol-itself                                               "
   dq "  entry-to-name s"" docol"" stringcmp 0 = ;                       "
 
+
   ;   The word named "docol" has the job of returning the value that gets used
   ; as the actual codeword. We make the assumption that, if so, the codeword
   ; will point somewhere near the entry header; we allow for the possibility
@@ -11335,7 +11364,7 @@ defword boot_source, 0x40
   dq "  { dup word-heading next-newer-entry } while drop ;            "
 
   ; (content end, content start, label start)
-  dq ": show-hex-row                                                  "
+  dq ": hexdump-row                                                   "
   dq "  2 indent dup .hex32 dup 4 unroll                              "
   dq "  0 { dup 16 > }                                                "
   dq "  { dup 7 & 0 = { space } if space                              "
@@ -11345,23 +11374,46 @@ defword boot_source, 0x40
   dq "  newline 5 ndrop ;                                             "
 
   ; (end, start)
-  dq ": show-hex-between                                              "
+  dq ": hexdump-between                                               "
   dq "  dup 16 1- invert &                                            "
   dq "  { dup 3 pick > }                                              "
-  dq "  { 3dup show-hex-row 16 + } while 3 ndrop ;                    "
+  dq "  { 3dup hexdump-row 16 + } while 3 ndrop ;                     "
+
+  ; (start, length)
+  dq ": hexdump-from swap dup 3unroll + swap hexdump-between ;        "
+
+  ; (start)
+  dq ": hexdump 64 hexdump-from ;                                     "
 
   dq ": describe-hex                                                  "
   dq "  dup word-heading                                              "
   dq "  dup guess-entry-end swap entry-to-execution-token             "
-  dq "  show-hex-between ;                                            "
+  dq "  hexdump-between ;                                             "
+
+  dq ": is-codeword                                                   "
+  dq "  dup is-in-heap { drop 0 exit } unless                         "
+  dq "  dup containing-entry dup { 2drop 0 exit } unless              "
+  dq "  entry-to-execution-token = ;                                  "
+
+  dq ": describe-docol                                                "
+  dq "  dup word-heading                                              "
+  dq "  dup guess-entry-end swap entry-to-execution-token 8 +         "
+  dq "  { 2dup < }                                                    "
+  dq "  { space dup @ dup is-codeword                                 "
+  dq "    { execution-token-to-entry entry-to-name emitstring }       "
+  dq "    { . } if-else                                               "
+  dq "    8 + } while newline ;                                       "
 
   dq ": describe                                                      "
-  dq "  describe-hex ;                                                "
+  dq "  dup is-docol-word                                             "
+  dq "  { describe-docol } { describe-hex } if-else ;                 "
 
   dq ": describe-all                                                  "
   dq "  oldest-entry { dup }                                          "
   dq "  { dup describe next-newer-entry } while drop ;                "
 
+  dq ": bye 0 sys-exit ;                                              "
+
   ;dq ": foo 5 { dup }                                                 "
   ;dq "  { 4 indent 97 value@ emitstring drop newline 1- }             "
   ;dq "  while drop ; foo                                              "
@@ -11384,8 +11436,6 @@ defword boot_source, 0x40
 
   ; TODO define ( ... ) comments
   ; TODO define constant (double-check variable)
-  ; TODO consider defining "value" and "to"
-  ; TODO consider defining "id"
   ; TODO consider defining is-hidden and is-immediate
   ; TODO define ?
   ; TODO define allot and cells
@@ -11394,13 +11444,13 @@ defword boot_source, 0x40
   ; TODO control stack trace
   ; TODO make an interactive debugger
   ; TODO argc argv envp etc
-  ; TODO consider "bye" and "unused"
+  ; TODO consider "unused" and some replacement for "brk"
   ; TODO consider file API
   ; TODO consider ";asm" or something
   ; TODO consider a welcome message
 
   ; If we get to this point, clean up and leave.
-  dq "0 sys-exit                                                      "
+  dq "bye                                                             "
   dq 0