initial commit: a mess of assembly code
[fmap.git] / x86_64_sse2_x87 / pbf / blk / primblk / strtbl / text.s
blobc5b948fceabafa7357ab14949a5700e1167a12cd
1 ; vim: set filetype=fasm foldmethod=marker commentstring=;%s colorcolumn=101 :
2 strtbl: namespace strtbl
3 align_nops
4 init_once:
5 TRACE 'PBF:BLK:PRIMBLK:STRTBL:INIT_ONCE'
7 mov rbp, rsp
8 and rsp, not 0xf
10 xor edi, edi
11 mov rsi, idx.bytes_n
12 mov rdx, 0x1 or 0x2 ; PROT_READ | PROT_WRITE
13 mov r10, 0x20 or 0x02 ; MAP_ANONYMOUS | MAP_PRIVATE
14 xor r8d, r8d
15 xor r9d, r9d
16 mov rax, linux.mmap
17 syscall
18 cmp rax, linux.errno.last
19 jae .err_strtbl_idx_mmap_failed
20 mov [idx], rax
21 TRACE 'PBF:BLK:PRIMBLK:STRTBL:IDX:INIT_ONCE:string table index mmaped at %p', rax
22 stc ; return true
23 mov rsp, rbp
24 ret
25 .err_strtbl_idx_mmap_failed: ; in: rax = error code
26 mov rdi, 2 ; stderr
27 lea rsi, [idx.msg.mmap_failed]
28 mov rdx, rax
29 call qword [libc.dprintf]
30 clc ; return false
31 mov rsp, rbp
32 ret
33 ;---------------------------------------------------------------------------------------------------
34 ; we create an idx for fast look-up
35 ; scratch: rax rcx rdx
36 ; leaf code
37 ; from primblk
38 ;define primblk_p rbx
39 ;define primblk_p_finish r12
40 ;define primgrp_p r13
41 ;define primgrp_p_finish r14
42 ;define flags r15
43 define idx_start_p r8
44 define p r10
45 define p_finish rsi
46 ; local
47 define idx_p rdi
48 align_nops
49 parse:
50 mov idx_p, idx_start_p
51 .str_next:
52 cmp p, p_finish
53 je primblk.parse.next_key
54 inc p ; skip the msg field num/type since it is always num = 1/type = 2 namely 0x0a
55 mov [idx_p], p ; idx_p = ptr on current byte
56 varint_load rdx, p ; = str_sz
57 add p, rdx ; skip str
58 add idx_p, 8 ; points on next str ptr
59 jmp .str_next
60 ;---------------------------------------------------------------------------------------------------
61 ;purge primblk_p
62 ;purge primblk_p_finish
63 ;purge primgrp_p
64 ;purge primgrp_p_finish
65 ;purge flags
66 purge idx_start_p
67 purge p
68 purge p_finish
69 purge idx_p
70 end namespace ; strtbl