468 lines
8.2 KiB
Plaintext
468 lines
8.2 KiB
Plaintext
; @panic: +0
|
|
; mov rax, 60 (exit)
|
|
b8 3c 00 00 00
|
|
; mov rdi, 1 (exit code)
|
|
bf 01 00 00 00
|
|
; syscall
|
|
0f 05
|
|
;
|
|
; @die: +12
|
|
; mov rax, 60 (exit)
|
|
b8 3c 00 00 00
|
|
; mov rdi, 0 (exit
|
|
bf 00 00 00 00
|
|
; syscall
|
|
0f 05
|
|
;
|
|
; @fasthash_exit: +24
|
|
; ret
|
|
c3
|
|
; @fasthash: +25
|
|
; mov rax, 0x811c9dc5 (FNV offset basis)
|
|
b8 c5 9d 1c 81
|
|
; @fasthash_loop: +30
|
|
; test rsi, rsi
|
|
48 85 f6
|
|
; jz 'fasthash_exit (+39)
|
|
0f 84 f1 ff ff ff
|
|
; movzx ecx, byte [rdi]
|
|
0f b6 0f
|
|
; xor eax, ecx
|
|
31 c8
|
|
; imul eax, eax, 0x1000193 (FNV prime)
|
|
69 c0 93 01 00 01
|
|
; inc rdi
|
|
48 ff c7
|
|
; dec rsi
|
|
48 ff ce
|
|
; jmp 'fasthash_loop (+61)
|
|
e9 e1 ff ff ff
|
|
;
|
|
; @push_lbl: +61
|
|
; mov eax, [r15+0x6000]
|
|
41 8b 87 00 60 00 00
|
|
; cmp eax, 0x154
|
|
3d 54 01 00 00
|
|
; jge 'panic (+79)
|
|
0f 8d b1 ff ff ff
|
|
; lea edx, [rax + rax*2]
|
|
8d 14 40
|
|
; shl rdx, 2
|
|
48 c1 e2 02
|
|
; push rdx
|
|
52
|
|
; call 'fasthash (+92)
|
|
e8 bd ff ff ff
|
|
; pop rdx
|
|
5a
|
|
; lea rdi, [r15+0x5010]
|
|
49 8d bf 10 50 00 00
|
|
; mov qword [rdi+rdx], rax
|
|
48 89 04 17
|
|
; mov eax, dword [r15+0x500c]
|
|
41 8b 87 0c 50 00 00
|
|
; mov dword [rdi+rdx+8], eax
|
|
89 44 17 08
|
|
; inc dword [r15+0x6000]
|
|
41 ff 87 00 60 00 00
|
|
; ret
|
|
c3
|
|
;
|
|
; @find_lbl_not_found: (+123)
|
|
; call 'panic (+128)
|
|
e8 80 ff ff ff
|
|
; @find_lbl_found: (+128)
|
|
; mov eax, dword [rdx+8]
|
|
8b 42 08
|
|
; ret
|
|
c3
|
|
; @find_lbl: +132
|
|
; call 'fasthash (+137)
|
|
e8 90 ff ff ff
|
|
; lea rdx, [r15+0x5010]
|
|
49 8d 97 10 50 00 00
|
|
; mov edx, dword [r15+0x6000]
|
|
41 8b 9f 00 60 00 00
|
|
; @find_lbl_loop: (+151)
|
|
; test rbx, rbx
|
|
48 85 db
|
|
; jz 'find_lbl_not_found (+160)
|
|
0f 84 db ff ff ff
|
|
; dec rbx
|
|
48 ff cb
|
|
; cmp [rdx], rax
|
|
48 39 02
|
|
; jz 'find_lbl_found (+172)
|
|
0f 84 d4 ff ff ff
|
|
; add rdx, 0xc
|
|
48 83 c2 0c
|
|
; jmp 'find_lbl_loop (+181)
|
|
e9 e2 ff ff ff
|
|
;
|
|
; @wrt_stdout: (+181)
|
|
; mov rax, 1 (sys_write)
|
|
b8 01 00 00 00
|
|
; mov rdi, 1 (stdout)
|
|
bf 01 00 00 00
|
|
; lea rsi, [r15+0x1000]
|
|
49 8d b7 00 10 00 00
|
|
; mov edx, dword [r15+0x5004]
|
|
41 8b 97 04 50 00 00
|
|
; syscall
|
|
0f 05
|
|
; mov dword [r15+0x5004], 0
|
|
41 c7 87 04 50 00 00 00 00 00 00
|
|
; ret
|
|
c3
|
|
;
|
|
; @_start_lbl: (+219)
|
|
5f 73 74 61 72 74 00
|
|
; @die_jmp_start: (+226)
|
|
; lea rdi, [rip+@_start_lbl] (+233)
|
|
48 8d 3d f2 ff ff ff
|
|
; mov esi, 6
|
|
be 06 00 00 00
|
|
; call 'find_lbl (+243)
|
|
e8 91 ff ff ff
|
|
; add dword [r15+0x500c], 5
|
|
41 83 87 0c 50 00 00 05
|
|
; sub eax, dword [r15+0x500c]
|
|
41 2b 87 0c 50 00 00
|
|
; mov edi, dword [r15+0x5004]
|
|
41 8b bf 04 50 00 00
|
|
; lea rdi, [r15+rdi*1+0x1000]
|
|
49 8d bc 3f 00 10 00 00
|
|
; mov byte [rdi], 0xe9
|
|
c6 07 e9
|
|
; mov dword [rdi+1], eax
|
|
89 47 01
|
|
; add dword [r15+0x5004], 5
|
|
41 83 87 04 50 00 00 05
|
|
; call 'wrt_stdout (+292)
|
|
e8 91 ff ff ff
|
|
; call 'die (+297)
|
|
e8 e3 fe ff ff
|
|
;
|
|
; @rd_stdin: (+297)
|
|
; mov rax, 0 (sys_read)
|
|
b8 00 00 00 00
|
|
; mov rdi, 0 (stdin)
|
|
bf 00 00 00 00
|
|
; mov rsi, r15
|
|
4c 89 fe
|
|
; mov rdx, 0x1000
|
|
ba 00 10 00 00
|
|
; syscall
|
|
0f 05
|
|
; test rax, rax
|
|
85 c0
|
|
; jle 'die_jmp_start (+325)
|
|
0f 8e 9d ff ff ff
|
|
; mov dword [r15+0x5008], eax
|
|
41 89 87 08 50 00 00
|
|
; mov dword [r15+0x5000], 0
|
|
41 c7 87 00 50 00 00 00 00 00 00
|
|
; ret
|
|
c3
|
|
;
|
|
; @rd_buf_end: (+344)
|
|
; mov edx, dword [r15+0x5000]
|
|
41 8b 97 00 50 00 00
|
|
; xor rax, rax
|
|
48 31 c0
|
|
; mov al, byte [rdi+rdx]
|
|
41 8a 04 17
|
|
; inc dword [r15+0x5000]
|
|
41 ff 87 00 50 00 00
|
|
; ret
|
|
c3
|
|
; @rd_buf: (+366)
|
|
; mov eax, dword [r15+0x5000]
|
|
41 8b 87 00 50 00 00
|
|
; cmp eax, dword [r15+0x5008]
|
|
41 3b 87 08 50 00 00
|
|
; jl 'rd_buf_end (+386)
|
|
0f 8c d6 ff ff ff
|
|
; call 'wrt_stdout (+391)
|
|
e8 2e ff ff ff
|
|
; call 'rd_stdin (+396)
|
|
e8 9d ff ff ff
|
|
; jmp 'rd_buf_end (+401)
|
|
e9 c7 ff ff ff
|
|
;
|
|
;
|
|
; @skip_line_read: (+401)
|
|
; call 'rd_buf (+406)
|
|
e8 d8 ff ff ff
|
|
; @skip_line: (+406)
|
|
; cmp al, 0xa (newline)
|
|
3c 0a
|
|
; jnz 'skip_line_read (+414)
|
|
0f 85 f3 ff ff ff
|
|
; call 'rd_buf (+419)
|
|
e8 cb ff ff ff
|
|
; ret
|
|
c3
|
|
;
|
|
; @skip_whitespace_read: (+420)
|
|
; call 'rd_buf (+425)
|
|
e8 c5 ff ff ff
|
|
; @skip_whitespace: (+425)
|
|
; cmp al, 0x20 (space)
|
|
3c 20
|
|
; jz 'skip_whitespace_read (+433)
|
|
0f 84 f3 ff ff ff
|
|
; cmp al, 0xa (newline)
|
|
3c 0a
|
|
; jz 'skip_whitespace_read (+441)
|
|
0f 84 eb ff ff ff
|
|
; cmp al, 0x9 (tab)
|
|
3c 09
|
|
; jz 'skip_whitespace_read (+449)
|
|
0f 84 e3 ff ff ff
|
|
; ret
|
|
c3
|
|
;
|
|
; @skip_comment_ret: (+450)
|
|
; ret
|
|
c3
|
|
; @skip_comment: (+451)
|
|
; cmp al, 0x3b (semicolon)
|
|
3c 3b
|
|
; jnz 'skip_comment_ret (+459)
|
|
0f 85 f7 ff ff ff
|
|
; call 'skip_line (+464)
|
|
e8 c6 ff ff ff
|
|
; ret
|
|
c3
|
|
;
|
|
; @get_next_token_skip: (+465)
|
|
; call 'skip_whitespace (+470)
|
|
e8 d3 ff ff ff
|
|
; call 'skip_comment (+475)
|
|
e8 e8 ff ff ff
|
|
; @get_next_token: (+475)
|
|
; cmp al, 0x3b (semicolon)
|
|
3c 3b
|
|
; jz 'get_next_token_skip (+483)
|
|
0f 84 ee ff ff ff
|
|
; cmp al, 0xa (newline)
|
|
3c 0a
|
|
; jz 'get_next_token_skip (+491)
|
|
0f 84 e6 ff ff ff
|
|
; cmp al, 0x20 (space)
|
|
3c 20
|
|
; jz 'get_next_token_skip (+499)
|
|
0f 84 de ff ff ff
|
|
; cmp al, 0x9 (tab)
|
|
3c 09
|
|
; jz 'get_next_token_skip (+507)
|
|
0f 84 d6 ff ff ff
|
|
; ret
|
|
c3
|
|
;
|
|
; @invalid_hex: (+508)
|
|
; call 'panic (+513)
|
|
e8 ff fd ff ff
|
|
; @is_digit: (+513)
|
|
; sub al, 0x30 (digit '0')
|
|
2c 30
|
|
; ret
|
|
c3
|
|
; @is_low_alpha: (+516)
|
|
; sub al, 0x57 (letter 'a' - 10)
|
|
2c 57
|
|
; ret
|
|
c3
|
|
; @is_up_alpha: (+519)
|
|
; sub al, 0x37 (letter 'A' - 10)
|
|
2c 37
|
|
; ret
|
|
c3
|
|
; @char_to_u4: (+522)
|
|
; cmp al, 0x30 (digit '0')
|
|
3c 30
|
|
; jb 'invalid_hex (+530)
|
|
0f 82 ea ff ff ff
|
|
; cmp al, 0x39 (digit '9')
|
|
3c 39
|
|
; jbe 'is_digit (+538)
|
|
0f 86 e7 ff ff ff
|
|
; cmp al, 0x41 (letter 'A')
|
|
3c 41
|
|
; jb 'invalid_hex (+546)
|
|
0f 82 da ff ff ff
|
|
; cmp al, 0x46 (letter 'F')
|
|
3c 46
|
|
; jbe 'is_up_alpha (+554)
|
|
0f 86 dd ff ff ff
|
|
; cmp al, 0x61 (letter 'a')
|
|
3c 61
|
|
; jb 'invalid_hex (+562)
|
|
0f 82 ca ff ff ff
|
|
; cmp al, 0x66 (letter 'f')
|
|
3c 66
|
|
; jbe 'is_low_alpha (+570)
|
|
0f 86 ca ff ff ff
|
|
; jmp 'invalid_hex (+575)
|
|
e9 bd ff ff ff
|
|
;
|
|
; @octet: (+575)
|
|
; sub rsp, 8
|
|
48 83 ec 08
|
|
; call 'char_to_u4 (+584)
|
|
e8 ca ff ff ff
|
|
; mov byte [rsp], al
|
|
88 04 24
|
|
; call 'rd_buf (+592)
|
|
e8 1e ff ff ff
|
|
; call 'char_to_u4 (+597)
|
|
e8 b5 ff ff ff
|
|
; mov bl, byte [rsp]
|
|
8a 1c 24
|
|
; shl bl, 4
|
|
c0 e3 04
|
|
; or al, bl
|
|
08 d8
|
|
; mov edi, dword [r15+0x5004]
|
|
41 8b bf 04 50 00 00
|
|
; lea rdx, [r15+0x1000]
|
|
49 8d 97 00 10 00 00
|
|
; mov byte [rdi+rdx], al
|
|
88 04 17
|
|
; inc dword [r15+0x5004]
|
|
41 ff 87 04 50 00 00
|
|
; inc dword [r15+0x500c]
|
|
41 ff 87 0c 50 00 00
|
|
; add rsp, 8
|
|
48 83 c4 08
|
|
; ret
|
|
c3
|
|
;
|
|
; @label_ref_ret: (+641)
|
|
; lea rdi, [r15+0x6004]
|
|
49 8d bf 04 60 00 00
|
|
; call 'find_lbl (+653)
|
|
e8 f7 fd ff ff
|
|
; add dword [r15+0x500c], 4
|
|
41 83 87 0c 50 00 00 04
|
|
; sub eax, dword [r15+0x500c]
|
|
41 2b 87 0c 50 00 00
|
|
; mov edi, dword [r15+0x5004]
|
|
41 8b bf 04 50 00 00
|
|
; mov dword [r15+rdi*1+0x1000], eax
|
|
41 89 84 3f 00 10 00 00
|
|
; add dword [r15+0x5004], 4
|
|
41 83 87 04 50 00 00 04
|
|
; ret
|
|
c3
|
|
; @not_label_ref: (+692)
|
|
; call 'octet (+697)
|
|
e8 86 ff ff ff
|
|
; ret
|
|
c3
|
|
; @label_ref: (+698)
|
|
; cmp al, 0x27 (single quote)
|
|
3c 27
|
|
; jnz 'not_label_ref (+706)
|
|
0f 85 f2 ff ff ff
|
|
; xor rsi, rsi
|
|
48 31 f6
|
|
; @label_ref_loop: (+709)
|
|
; push rsi
|
|
56
|
|
; call 'rd_buf (+715)
|
|
e8 a3 fe ff ff
|
|
; pop rsi
|
|
5e
|
|
; lea rdi, [r15+0x6004]
|
|
49 8d bf 04 60 00 00
|
|
; cmp al, 0x20 (space)
|
|
3c 20
|
|
; jz 'label_ref_ret (+731)
|
|
0f 84 a6 ff ff ff
|
|
; cmp al, 0x9 (tab)
|
|
3c 09
|
|
; jz 'label_ref_ret (+739)
|
|
0f 84 9e ff ff ff
|
|
; cmp al, 0xa (newline)
|
|
3c 0a
|
|
; jz 'label_ref_ret (+747)
|
|
0f 84 96 ff ff ff
|
|
; mov byte [rdi+rsi*1], al
|
|
88 04 37
|
|
; inc rsi
|
|
48 ff c6
|
|
; jmp 'label_ref_loop (+758)
|
|
e9 cf ff ff ff
|
|
;
|
|
; @label_ret: (+758)
|
|
; lea rdi, [r15+0x6004]
|
|
49 8d bf 04 60 00 00
|
|
; call 'push_lbl (+770)
|
|
e8 3b fd ff ff
|
|
; ret
|
|
c3
|
|
; @not_label: (+771)
|
|
; call 'label_ref (+776)
|
|
e8 b2 ff ff ff
|
|
; ret
|
|
c3
|
|
; @label: (+777)
|
|
; cmp al, 0x40 (at sign)
|
|
3c 40
|
|
; jnz 'not_label (+785)
|
|
0f 85 f2 ff ff ff
|
|
; xor rsi, rsi
|
|
48 31 f6
|
|
; @label_loop: (+788)
|
|
; push rsi
|
|
56
|
|
; call 'rd_buf (+794)
|
|
e8 54 fe ff ff
|
|
; pop rsi
|
|
5e
|
|
; lea rdi, [r15+0x6004]
|
|
49 8d bf 04 60 00 00
|
|
; cmp al, 0x3a (colon)
|
|
3c 3a
|
|
; jz 'label_ret (+810)
|
|
0f 84 cc ff ff ff
|
|
; mov byte [rdi+rsi*1], al
|
|
88 04 37
|
|
; inc rsi
|
|
48 ff c6
|
|
; jmp 'label_loop (+821)
|
|
e9 df ff ff ff
|
|
;
|
|
; @_start: (+821)
|
|
; push rbp
|
|
55
|
|
; mov rbp, rsp
|
|
48 89 e5
|
|
; sub rsp, 0x8000
|
|
48 81 ec 00 80 00 00
|
|
; mov r15, rsp
|
|
49 89 e7
|
|
; mov dword [r15+0x6000], 0
|
|
41 c7 87 00 60 00 00 00 00 00 00
|
|
; mov dword [r15+0x500c], 0
|
|
41 c7 87 0c 50 00 00 00 00 00 00
|
|
; mov dword [r15+0x5008], 0
|
|
41 c7 87 08 50 00 00 00 00 00 00
|
|
; mov dword [r15+0x5004], 0
|
|
41 c7 87 04 50 00 00 00 00 00 00
|
|
; mov dword [r15+0x5000], 0
|
|
41 c7 87 00 50 00 00 00 00 00 00
|
|
; @main_loop:
|
|
; call 'rd_buf (+895)
|
|
e8 ef fd ff ff
|
|
; call 'get_next_token (+900)
|
|
e8 57 fe ff ff
|
|
; call 'label (+905)
|
|
e8 80 ff ff ff
|
|
; jmp 'main_loop (+910)
|
|
e9 ec ff ff ff
|
|
; jmp 'main
|
|
e9 a2 ff ff ff
|
|
; end |