cosmopolitan/libc/nexgen32e/cescapec.S

130 lines
3.9 KiB
ArmAsm

/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify │
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License. │
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of │
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "ape/relocations.h"
#include "libc/macros.h"
/ Escapes byte for string literal.
/
/ This turns stuff like (char)0xFF into \0377. The returned
/ string is word-encoded, e.g. '\\'|'0'<<010|'3'<<020|etc.
/
/ @param dil contains byte to escape
/ @see libc/nexgen32e/cescapec.c
cescapec:
movzbl %dil,%edi
lea -7(%rdi),%ecx
cmp $85,%cl
ja 1f
mov $'\\,%eax
movzbl %cl,%ecx
jmp *cescapectab(,%rcx,8)
.Lanchorpoint:
.LBEL: mov $'a',%ah
ret
.LBS: mov $'b',%ah
ret
.LHT: mov $'t',%ah
ret
.LLF: mov $'n',%ah
ret
.LVT: mov $'v',%ah
ret
.LFF: mov $'f',%ah
ret
.LCR: mov $'r',%ah
ret
.LDQ: mov $'\"',%ah
ret
.LSQ: mov $'\'',%ah
ret
.LBSL: mov $'\\',%ah
ret
#ifdef __STRICT_ANSI__
.LQM: mov $'?',%ah
ret
#else
.LQM:
#endif
1: mov %edi,%eax
lea -0x20(%rax),%ecx
cmp $0x5E,%ecx
ja 2f
ret
2: and $-64,%eax
mov %edi,%ecx
and $56,%ecx
shl $13,%ecx
and $7,%edi
shl $24,%edi
or %ecx,%edi
lea (%rdi,%rax,4),%eax
add $'0<<030|'0<<020|'0<<010|'\\,%eax
ret
.endfn cescapec,globl
.initro 300,_init_cescapec
cescapectab.ro:
.byte 1,.LBEL-.Lanchorpoint
.byte 1,.LBS-.Lanchorpoint
.byte 1,.LHT-.Lanchorpoint
.byte 1,.LLF-.Lanchorpoint
.byte 1,.LVT-.Lanchorpoint
.byte 1,.LFF-.Lanchorpoint
.byte 1,.LCR-.Lanchorpoint
.byte '\"-'\r-1,1b-.Lanchorpoint
.byte 1,.LDQ-.Lanchorpoint
.byte '\'-'\"-1,1b-.Lanchorpoint
.byte 1,.LSQ-.Lanchorpoint
.byte '?-'\'-1,1b-.Lanchorpoint
.byte 1,.LQM-.Lanchorpoint
.byte '\\-'?-1,1b-.Lanchorpoint
.byte 1,.LBSL-.Lanchorpoint
.equ .Lcescapectab.ro.size,.-cescapectab.ro
.org 8 - .Lcescapectab.ro.size % 8 + .
.endobj cescapectab.ro,globl,hidden
.previous
.initbss 300,_init_cescapec
cescapectab:
.rept '\\-7+1
.quad 0
.endr
.endobj cescapectab
.previous
.init.start 300,_init_cescapec
ezlea .Lanchorpoint,dx
mov $.Lcescapectab.ro.size/2,%ch
0: xor %eax,%eax
lodsb
mov %al,%cl
lodsb
add %rdx,%rax
1: stosq
dec %cl
jnz 1b
dec %ch
jnz 0b
.if .Lcescapectab.ro.size % 8
add $(8-.Lcescapectab.ro.size%8),%rsi
.endif
.init.end 300,_init_cescapec
.source __FILE__