mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-05 02:38:31 +00:00
Clean up some code
- Use good ELF technique in cosmo_dlopen() - Make strerror() conform more to other libc impls - Introduce __clear_cache() and use it in cosmo_dlopen() - Remove libc/fmt/fmt.h header (trying to kill off LIBC_FMT)
This commit is contained in:
parent
7010a8081e
commit
68c7c9c1e0
244 changed files with 378 additions and 588 deletions
37
libc/intrin/__clear_cache.c
Normal file
37
libc/intrin/__clear_cache.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
|
||||
void __clear_cache2(const void *base, const void *end) {
|
||||
#ifdef __aarch64__
|
||||
int icache, dcache;
|
||||
const char *p, *pe = end;
|
||||
static unsigned int ctr_el0 = 0;
|
||||
if (!ctr_el0) asm volatile("mrs\t%0,ctr_el0" : "=r"(ctr_el0));
|
||||
icache = 4 << (ctr_el0 & 15);
|
||||
dcache = 4 << ((ctr_el0 >> 16) & 15);
|
||||
for (p = (const char *)((uintptr_t)base & -dcache); p < pe; p += dcache) {
|
||||
asm volatile("dc\tcvau,%0" : : "r"(p) : "memory");
|
||||
}
|
||||
asm volatile("dsb\tish" ::: "memory");
|
||||
for (p = (const char *)((uintptr_t)base & -icache); p < pe; p += icache) {
|
||||
asm volatile("ic\tivau,%0" : : "r"(p) : "memory");
|
||||
}
|
||||
asm volatile("dsb\tish\nisb" ::: "memory");
|
||||
#endif
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue