Debian Codegraph @

scheme/x86-64-repl.ss

raw
1 #!/usr/bin/env scheme-script
2
3
4 ;;; This is a debugging tool for developing the 64-bit
5 ;;; ikarus. It only works on Mac OS.
6
7 (import (ikarus))
8
9 (define stub1
10 '(#xcf #xfa #xed #xfe #x07 #x00 #x00 #x01
11 #x03 #x00 #x00 #x00 #x01 #x00 #x00 #x00
12 #x01 #x00 #x00 #x00 #x98 #x00 #x00 #x00
13 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00
14 #x19 #x00 #x00 #x00 #x98 #x00 #x00 #x00
15 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00
16 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00
17 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00
18 #x08 #x00 #x00 #x00 #x00 #x00 #x00 #x00
19 #xb8 #x00 #x00 #x00 #x00 #x00 #x00 #x00
20 #x08 #x00 #x00 #x00 #x00 #x00 #x00 #x00
21 #x07 #x00 #x00 #x00 #x07 #x00 #x00 #x00
22 #x01 #x00 #x00 #x00 #x00 #x00 #x00 #x00
23 #x5f #x5f #x74 #x65 #x78 #x74 #x00 #x00
24 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00
25 #x5f #x5f #x54 #x45 #x58 #x54 #x00 #x00
26 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00
27 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00
28 ))
29
30 (define stub2
31 '(#x08 #x00 #x00 #x00 #x00 #x00 #x00 #x00))
32
33 (define (mkstub2 len)
34 (bytevector->u8-list
35 (let ([v (make-bytevector 8)])
36 (bytevector-u64-set! v 0 len 'little)
37 v)))
38
39 (define stub3
40 '(#xb8 #x00 #x00 #x00 #x00 #x00 #x00 #x00
41 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00
42 #x00 #x04 #x00 #x80 #x00 #x00 #x00 #x00
43 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00
44 ))
45
46 (define (gen ls)
47 (let ([p (open-file-output-port "tmp.o" (file-options no-fail))])
48 (for-each
49 (lambda (b)
50 (put-u8 p b))
51 (append stub1 (mkstub2 (length ls)) stub3 ls))
52 (close-output-port p))
53 (system "otool -tv tmp.o"))
54
55 (printf "Trying a simple sequence ...\n")
56
57 (gen '(#x48 #xc7 #xc3 #x50 #x01 #x00 #x00 #xc3))
58
59 (printf "That should've printed the following: \n\
60 tmp.o: \n\
61 (__TEXT,__text) section\n\
62 0000000000000000 movq $0x00000150,%rbx\n\
63 0000000000000007 ret\n\n\
64 OK, now you can enter byte sequences like\n\
65 \x20; (72 199 195 80 1 0 0 195)\n\n")
66
67 (new-cafe gen)
68
69