Permalink
Browse files

Fixing hex dump tooling for doing memory dumps on compiler output

  • Loading branch information...
1 parent 4d5fd68 commit b46e7eb513154eb737847f0364967ea11a267b37 @cthulhuology committed Jun 27, 2012
Showing with 71 additions and 6 deletions.
  1. +1 −1 Makefile
  2. +10 −2 image.asm
  3. +3 −3 term.asm
  4. +30 −0 tools.asm
  5. +27 −0 vm.asm
View
@@ -3,7 +3,7 @@ all : firth image syscall.asm
syscall.asm : /usr/include/sys/syscall.h
cat /usr/include/sys/syscall.h | grep -v "old " | grep "^#define" | sed 's%#define%\%define%' | sed 's%SYS_%%' | sed 's%$$% + 0x2000000%' | tail -n +3 > syscall.asm
-image.bin : image.asm syscall.asm vm.asm term.asm
+image.bin : image.asm syscall.asm vm.asm term.asm tools.asm
yasm -f bin -o image.bin image.asm
image : image.bin
View
@@ -20,9 +20,17 @@ ORG 0
; Initialize VM
vm
-%include "term.asm"
-
+offset dump_test
+literal 10
+call dump
+quit
+%include "term.asm"
+%include "tools.asm"
__free_space:
dq 90,90,90,90,90,90,90,90
+
+dump_test:
+ dq 0xcafebabe, 0xdeadbeef, 0xfeedface, 0x1234, 0xffeeddaa
+ dq 0x12345678cafebabe, 0xdeadbeef, 0xfeedface, 0x1234, 0xffeeddaa
View
@@ -4,6 +4,7 @@
;; © 2012 David J Goehrig <dave@dloh.org>
;;
+
call clear
call read_keys
@@ -42,7 +43,7 @@ emit:
hexen:
mov r11,16
zero number,20
- mov rcx,20
+ mov rcx,16
.hexen:
xor rdx,rdx
idiv r11
@@ -52,8 +53,7 @@ hexen:
.lessthanten:
add rdx,48
mov byte [ r13 + number + rcx - 1],dl
- test rax,rax
- jz .done
+ test rcx,rcx
loopnz .hexen
.done:
show number,20
View
@@ -4,4 +4,34 @@
;; © 2012 David J Goehrig <dave@dloh.org>
;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; things necessary for bootstrapping the compiler
+;;
+
+jmp tools_end
+dump: ; address count dump
+ mov rcx,rax
+ mov rdx,0
+ drop
+ object
+.dump
+ fetchplus ; fetch data
+ push rcx ; save count
+ push rdx ; save citeration
+ call hexen ; hexdump cell
+ call space ; then print a space
+ pop rdx
+ add rdx,1
+ cmp rdx,4 ;
+ jl .continue
+ call eol
+ mov rdx,0
+.continue:
+ pop rcx ; recover the count
+ test rcx,rcx
+ loopnz .dump
+ call eol
+ ret
+;; fin
+tools_end:
View
@@ -50,6 +50,16 @@ _init:
; stack macros
%define nos rbp*8+r13+stack
+%macro rpush 0
+ push rax
+ drop
+%endmacro
+
+%macro rpop 0
+ dupe
+ pop rax
+%endmacro
+
%macro dupe 0
add rbp,1
and rbp,7
@@ -78,6 +88,11 @@ _init:
; Memory macros
+%macro object 0
+ mov rbx,rax
+ drop
+%endmacro
+
%macro zero 2 ; equiv to memset(addr,len,zero)
mov rcx,%2 ; bytes to zero out
.reset:
@@ -107,6 +122,12 @@ _init:
mov rax,[rax]
%endmacro
+%macro fetchplus 0
+ dupe
+ mov rax,[rbx]
+ lea rbx,[rbx+8]
+%endmacro
+
%macro storeaddr 1 ; store tos to an address
mov [r13 + %1],rax
drop
@@ -132,6 +153,12 @@ _init:
drop
%endmacro
+%macro storeplus 0
+ mov [rbx],rax
+ lea rbx,[rbx+8]
+ drop
+%endmacro
+
; Math macros
%macro addition 0
add rax,[nos]

0 comments on commit b46e7eb

Please sign in to comment.