mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Get LIBC_MEM and LIBC_STDIO building with aarch64
This commit is contained in:
parent
ae0ee59614
commit
d04430f4ef
81 changed files with 440 additions and 1064 deletions
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
@ -26,7 +27,8 @@
|
|||
int __fflush_impl(FILE *f) {
|
||||
size_t i;
|
||||
ssize_t rc;
|
||||
free_s(&f->getln);
|
||||
free(f->getln);
|
||||
f->getln = 0;
|
||||
if (f->beg && !f->end && (f->iomode & O_ACCMODE) != O_RDONLY) {
|
||||
for (i = 0; i < f->beg; i += rc) {
|
||||
if ((rc = write(f->fd, f->buf + i, f->beg - i)) == -1) {
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
.bss
|
||||
.balign 8
|
||||
g_rando:
|
||||
.quad 0
|
||||
.endobj g_rando,globl
|
||||
.previous
|
||||
|
||||
.init.start 100,_init_g_rando
|
||||
movb $1,g_rando(%rip)
|
||||
.init.end 100,_init_g_rando
|
|
@ -1,7 +1,7 @@
|
|||
/*-*- 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 2020 Justine Alexandra Roberts Tunney │
|
||||
│ 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 │
|
||||
|
@ -16,12 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/lockxchg.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
// TODO(jart): delete
|
||||
|
||||
int fclose_s(FILE **fp) {
|
||||
FILE *f = NULL;
|
||||
return fclose(lockxchg(fp, &f));
|
||||
}
|
||||
uint64_t g_rando = 1;
|
|
@ -1,39 +0,0 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
.init.start 400,_init_stderr
|
||||
ezlea __stderr,ax
|
||||
push $_IOLBF
|
||||
pop (%rax) #→ f.fd
|
||||
push STDERR_FILENO
|
||||
pop 12(%rax)
|
||||
mov O_WRONLY,%edx
|
||||
mov %edx,4(%rax) #→ f.iomode
|
||||
lea 0x50(%rax),%rcx #← f.mem
|
||||
mov %rcx,0x18(%rax) #→ f.buf
|
||||
movl $BUFSIZ,0x20(%rax) #→ f.size
|
||||
movb $PTHREAD_MUTEX_RECURSIVE,0x38+4(%rax) #→ f.lock._type
|
||||
mov %rax,stderr(%rip)
|
||||
.init.end 400,_init_stderr,globl,hidden
|
|
@ -16,20 +16,27 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
STATIC_YOINK("_init_stderr");
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
||||
/**
|
||||
* Pointer to standard error stream.
|
||||
*/
|
||||
FILE *stderr;
|
||||
|
||||
_Hide FILE __stderr;
|
||||
static FILE __stderr;
|
||||
|
||||
static textstartup void __stderr_init() {
|
||||
__attribute__((__constructor__)) static void __stderr_init(void) {
|
||||
stderr = &__stderr;
|
||||
stderr->fd = STDERR_FILENO;
|
||||
stderr->bufmode = _IOLBF;
|
||||
stderr->iomode = O_WRONLY;
|
||||
stderr->buf = stderr->mem;
|
||||
stderr->size = sizeof(stderr->mem);
|
||||
((pthread_mutex_t *)stderr->lock)->_type = PTHREAD_MUTEX_RECURSIVE;
|
||||
__fflush_register(stderr);
|
||||
}
|
||||
|
||||
const void *const __stderr_ctor[] initarray = {__stderr_init};
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
.init.start 400,_init_stdin
|
||||
ezlea __stdin,ax
|
||||
mov O_RDONLY,%edx
|
||||
mov %edx,4(%rax) #→ f.iomode
|
||||
lea 0x50(%rax),%rcx #← f.mem
|
||||
mov %rcx,0x18(%rax) #→ f.buf
|
||||
movl $BUFSIZ,0x20(%rax) #→ f.size
|
||||
movb $PTHREAD_MUTEX_RECURSIVE,0x38+4(%rax) #→ f.lock._type
|
||||
mov %rax,stdin(%rip)
|
||||
.init.end 400,_init_stdin,globl,hidden
|
|
@ -16,20 +16,26 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
STATIC_YOINK("_init_stdin");
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
||||
/**
|
||||
* Pointer to standard input stream.
|
||||
*/
|
||||
FILE *stdin;
|
||||
|
||||
_Hide FILE __stdin;
|
||||
static FILE __stdin;
|
||||
|
||||
static textstartup void __stdin_init() {
|
||||
__attribute__((__constructor__)) static void __stdin_init(void) {
|
||||
stdin = &__stdin;
|
||||
stdin->fd = STDIN_FILENO;
|
||||
stdin->iomode = O_RDONLY;
|
||||
stdin->buf = stdin->mem;
|
||||
stdin->size = sizeof(stdin->mem);
|
||||
((pthread_mutex_t *)stdin->lock)->_type = PTHREAD_MUTEX_RECURSIVE;
|
||||
__fflush_register(stdin);
|
||||
}
|
||||
|
||||
const void *const __stdin_ctor[] initarray = {__stdin_init};
|
||||
|
|
|
@ -74,7 +74,6 @@ FILE *freopen(const char *, const char *, FILE *) paramsnonnull((2, 3));
|
|||
size_t fread(void *, size_t, size_t, FILE *) paramsnonnull((4));
|
||||
size_t fwrite(const void *, size_t, size_t, FILE *) paramsnonnull((4));
|
||||
int fclose(FILE *);
|
||||
int fclose_s(FILE **) paramsnonnull();
|
||||
int fseek(FILE *, long, int) paramsnonnull();
|
||||
long ftell(FILE *) paramsnonnull();
|
||||
int fseeko(FILE *, int64_t, int) paramsnonnull();
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ 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. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
.init.start 400,_init_stdout
|
||||
ezlea __stdout,ax
|
||||
push STDOUT_FILENO
|
||||
pop 0x0c(%rax) #→ f.fd
|
||||
mov O_WRONLY,%edx
|
||||
mov %edx,4(%rax) #→ f.iomode
|
||||
lea 0x50(%rax),%rcx #← f.mem
|
||||
mov %rcx,0x18(%rax) #→ f.buf
|
||||
movl $BUFSIZ,0x20(%rax) #→ f.size
|
||||
movb $PTHREAD_MUTEX_RECURSIVE,0x38+4(%rax) #→ f.lock._type
|
||||
mov %rax,stdout(%rip)
|
||||
.init.end 400,_init_stdout,globl,hidden
|
|
@ -18,23 +18,28 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/pushpop.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
STATIC_YOINK("_init_stdout");
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
||||
/**
|
||||
* Pointer to standard output stream.
|
||||
*/
|
||||
FILE *stdout;
|
||||
|
||||
_Hide FILE __stdout;
|
||||
static FILE __stdout;
|
||||
|
||||
__attribute__((__constructor__)) static void __stdout_init(void) {
|
||||
stdout = &__stdout;
|
||||
|
||||
stdout->fd = STDOUT_FILENO;
|
||||
stdout->iomode = O_WRONLY;
|
||||
stdout->buf = stdout->mem;
|
||||
stdout->size = sizeof(stdout->mem);
|
||||
((pthread_mutex_t *)stdout->lock)->_type = PTHREAD_MUTEX_RECURSIVE;
|
||||
|
||||
static textstartup void __stdout_init() {
|
||||
struct FILE *sf;
|
||||
sf = stdout;
|
||||
asm("" : "+r"(sf));
|
||||
/*
|
||||
* Unlike other C libraries we don't bother calling fstat() to check
|
||||
* if stdio is a character device and we instead choose to always line
|
||||
|
@ -43,8 +48,7 @@ static textstartup void __stdout_init() {
|
|||
* value latency more than throughput, and stdio isn't the best api
|
||||
* when the goal is throughput.
|
||||
*/
|
||||
sf->bufmode = _IOLBF;
|
||||
__fflush_register(sf);
|
||||
}
|
||||
stdout->bufmode = _IOLBF;
|
||||
|
||||
const void *const __stdout_ctor[] initarray = {__stdout_init};
|
||||
__fflush_register(stdout);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue