about summary refs log tree commit diff stats
path: root/069allocate.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-05-25 19:26:18 -0700
committerKartik Agaram <vc@akkartik.com>2020-05-25 19:26:18 -0700
commit3b5b19df66c0de4f916ba00298c6e000fc69de71 (patch)
treed9dbf680c2bf2df45de3be3f11b44069c3715166 /069allocate.subx
parentd796318101775f9150af5d5f3bca61cdf31c41fa (diff)
downloadmu-3b5b19df66c0de4f916ba00298c6e000fc69de71.tar.gz
6406 - primitive 'copy-handle'
Diffstat (limited to '069allocate.subx')
-rw-r--r--069allocate.subx23
1 files changed, 23 insertions, 0 deletions
diff --git a/069allocate.subx b/069allocate.subx
index 0c75ece0..c65a369e 100644
--- a/069allocate.subx
+++ b/069allocate.subx
@@ -489,6 +489,29 @@ $handle-equal?:end:
     5d/pop-to-ebp
     c3/return
 
+copy-handle:  # src: handle, dest: (addr handle)
+    # . prologue
+    55/push-ebp
+    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
+    # . save registers
+    50/push-eax
+    51/push-ecx
+    # ecx = dest
+    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x10/disp8      .                 # copy *(ebp+16) to ecx
+    # *dest = src
+    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   8/disp8         .                 # copy *(ebp+8) to eax
+    89/copy                         0/mod/indirect  1/rm32/ecx    .           .             .           0/r32/eax   .               .                 # copy eax to *ecx
+    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           0/r32/eax   0xc/disp8       .                 # copy *(ebp+12) to eax
+    89/copy                         1/mod/*+disp8   1/rm32/ecx    .           .             .           0/r32/eax   4/disp8         .                 # copy eax to *(ecx+4)
+$copy-handle:end:
+    # . restore registers
+    59/pop-to-ecx
+    58/pop-to-eax
+    # . epilogue
+    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
+    5d/pop-to-ebp
+    c3/return
+
 # helper: create a nested allocation descriptor (useful for tests)
 allocate-region:  # ad: (addr allocation-descriptor), n: int, out: (addr handle allocation-descriptor)
     # . prologue