mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-12 01:08:00 +00:00
Make progress towards aarch64 build
This commit is contained in:
parent
08ff26c817
commit
ca2860947f
15428 changed files with 25694 additions and 23138 deletions
2
Makefile
2
Makefile
|
@ -126,6 +126,7 @@ include third_party/zlib/zlib.mk # │
|
||||||
include third_party/double-conversion/dc.mk # │
|
include third_party/double-conversion/dc.mk # │
|
||||||
include libc/elf/elf.mk # │
|
include libc/elf/elf.mk # │
|
||||||
include ape/ape.mk # │
|
include ape/ape.mk # │
|
||||||
|
include libc/aarch64/aarch64.mk # │
|
||||||
include libc/fmt/fmt.mk # │
|
include libc/fmt/fmt.mk # │
|
||||||
include libc/vga/vga.mk #─┘
|
include libc/vga/vga.mk #─┘
|
||||||
include libc/calls/calls.mk #─┐
|
include libc/calls/calls.mk #─┐
|
||||||
|
@ -200,6 +201,7 @@ include tool/build/emucrt/emucrt.mk
|
||||||
include tool/build/emubin/emubin.mk
|
include tool/build/emubin/emubin.mk
|
||||||
include tool/build/build.mk
|
include tool/build/build.mk
|
||||||
include tool/curl/curl.mk
|
include tool/curl/curl.mk
|
||||||
|
include third_party/qemu/qemu.mk
|
||||||
include examples/examples.mk
|
include examples/examples.mk
|
||||||
include examples/pyapp/pyapp.mk
|
include examples/pyapp/pyapp.mk
|
||||||
include examples/pylife/pylife.mk
|
include examples/pylife/pylife.mk
|
||||||
|
|
34
ape/ape.S
34
ape/ape.S
|
@ -47,17 +47,17 @@
|
||||||
#define USE_SYMBOL_HACK 1
|
#define USE_SYMBOL_HACK 1
|
||||||
|
|
||||||
.section .text,"ax",@progbits
|
.section .text,"ax",@progbits
|
||||||
.align __SIZEOF_POINTER__
|
.balign __SIZEOF_POINTER__
|
||||||
.previous
|
.previous
|
||||||
.section .rodata,"a",@progbits
|
.section .rodata,"a",@progbits
|
||||||
.align __SIZEOF_POINTER__
|
.balign __SIZEOF_POINTER__
|
||||||
__ro: .endobj __ro,globl,hidden # ←for gdb readability
|
__ro: .endobj __ro,globl,hidden # ←for gdb readability
|
||||||
.previous
|
.previous
|
||||||
.section .data,"aw",@progbits
|
.section .data,"aw",@progbits
|
||||||
.align __SIZEOF_POINTER__
|
.balign __SIZEOF_POINTER__
|
||||||
.previous
|
.previous
|
||||||
.section .bss,"aw",@nobits
|
.section .bss,"aw",@nobits
|
||||||
.align __SIZEOF_POINTER__
|
.balign __SIZEOF_POINTER__
|
||||||
.previous
|
.previous
|
||||||
.section .rodata.str1.1,"a",@progbits
|
.section .rodata.str1.1,"a",@progbits
|
||||||
cstr: .endobj cstr,globl,hidden # ←for gdb readability
|
cstr: .endobj cstr,globl,hidden # ←for gdb readability
|
||||||
|
@ -179,7 +179,7 @@ ape_mz:
|
||||||
.byte 1 # 6: elf v1.o
|
.byte 1 # 6: elf v1.o
|
||||||
.byte ELFOSABI_FREEBSD # 7: FreeBSD
|
.byte ELFOSABI_FREEBSD # 7: FreeBSD
|
||||||
.byte 0 # 8: os/abi ver.
|
.byte 0 # 8: os/abi ver.
|
||||||
.align 8,0 # 9: padding
|
.balign 8,0 # 9: padding
|
||||||
.short ET_EXEC # 10: εxεcµταblε
|
.short ET_EXEC # 10: εxεcµταblε
|
||||||
.short EM_NEXGEN32E # 12: NexGen32e
|
.short EM_NEXGEN32E # 12: NexGen32e
|
||||||
.long 1 # 14: elf v1.o
|
.long 1 # 14: elf v1.o
|
||||||
|
@ -780,11 +780,11 @@ emush: .ascii "\n@\n#'\"\n"
|
||||||
.endobj emush
|
.endobj emush
|
||||||
#ifdef APE_LOADER
|
#ifdef APE_LOADER
|
||||||
.section .ape.loader,"a",@progbits
|
.section .ape.loader,"a",@progbits
|
||||||
.align 64
|
.balign 64
|
||||||
ape_loader:
|
ape_loader:
|
||||||
.incbin APE_LOADER
|
.incbin APE_LOADER
|
||||||
.endobj ape_loader,globl
|
.endobj ape_loader,globl
|
||||||
.align 64
|
.balign 64
|
||||||
ape_loader_end:
|
ape_loader_end:
|
||||||
nop
|
nop
|
||||||
.endobj ape_loader_end,globl
|
.endobj ape_loader_end,globl
|
||||||
|
@ -858,7 +858,7 @@ openbsd.ident:
|
||||||
.long 4f-3f
|
.long 4f-3f
|
||||||
.long 1
|
.long 1
|
||||||
1: .asciz "OpenBSD"
|
1: .asciz "OpenBSD"
|
||||||
2: .align 4
|
2: .balign 4
|
||||||
3: .long 0
|
3: .long 0
|
||||||
4: .size openbsd.ident,.-openbsd.ident
|
4: .size openbsd.ident,.-openbsd.ident
|
||||||
.type openbsd.ident,@object
|
.type openbsd.ident,@object
|
||||||
|
@ -872,7 +872,7 @@ netbsd.ident:
|
||||||
.long 4f-3f
|
.long 4f-3f
|
||||||
.long 1
|
.long 1
|
||||||
1: .asciz "NetBSD"
|
1: .asciz "NetBSD"
|
||||||
2: .align 4
|
2: .balign 4
|
||||||
3: .long 901000000
|
3: .long 901000000
|
||||||
4: .size netbsd.ident,.-netbsd.ident
|
4: .size netbsd.ident,.-netbsd.ident
|
||||||
.type netbsd.ident,@object
|
.type netbsd.ident,@object
|
||||||
|
@ -912,7 +912,7 @@ netbsd.ident:
|
||||||
|
|
||||||
#if SupportsXnu()
|
#if SupportsXnu()
|
||||||
.section .macho,"a",@progbits
|
.section .macho,"a",@progbits
|
||||||
.align __SIZEOF_POINTER__
|
.balign __SIZEOF_POINTER__
|
||||||
|
|
||||||
ape_macho:
|
ape_macho:
|
||||||
.long 0xFEEDFACE+1
|
.long 0xFEEDFACE+1
|
||||||
|
@ -1095,7 +1095,7 @@ PEIMPS = 0b11000000000000000000000001000000
|
||||||
#if SupportsWindows() || SupportsMetal()
|
#if SupportsWindows() || SupportsMetal()
|
||||||
|
|
||||||
.section .pe.header,"a",@progbits
|
.section .pe.header,"a",@progbits
|
||||||
.align __SIZEOF_POINTER__
|
.balign __SIZEOF_POINTER__
|
||||||
ape_pe: .ascin "PE",4
|
ape_pe: .ascin "PE",4
|
||||||
.short kNtImageFileMachineNexgen32e
|
.short kNtImageFileMachineNexgen32e
|
||||||
.stub ape_pe_shnum,short # NumberOfSections
|
.stub ape_pe_shnum,short # NumberOfSections
|
||||||
|
@ -1198,7 +1198,7 @@ ape_idata_idtend:
|
||||||
.previous
|
.previous
|
||||||
|
|
||||||
.section .piro.data.sort.metal_gdt,"aw",@progbits
|
.section .piro.data.sort.metal_gdt,"aw",@progbits
|
||||||
.align 8
|
.balign 8
|
||||||
_gdt:
|
_gdt:
|
||||||
// ┌G:granularity (1 → limit *= 0x1000)
|
// ┌G:granularity (1 → limit *= 0x1000)
|
||||||
// │┌D/B:default operation size (0 = 16|64bit, 1 = 32-bit)
|
// │┌D/B:default operation size (0 = 16|64bit, 1 = 32-bit)
|
||||||
|
@ -1289,7 +1289,7 @@ sconf: .short 1843200/*hz*/ / 16/*wut*/ / 9600/*baud*/
|
||||||
.endobj sconf,global,hidden
|
.endobj sconf,global,hidden
|
||||||
|
|
||||||
// Global Descriptor Table
|
// Global Descriptor Table
|
||||||
.align 8
|
.balign 8
|
||||||
_gdtrlo:
|
_gdtrlo:
|
||||||
.short 2f-_gdtlo-1 # table byte length
|
.short 2f-_gdtlo-1 # table byte length
|
||||||
.long REAL(_gdtlo) # table address (base memory space)
|
.long REAL(_gdtlo) # table address (base memory space)
|
||||||
|
@ -1298,7 +1298,7 @@ _gdtr:
|
||||||
.short _gdt_end-_gdt-1 # table byte length
|
.short _gdt_end-_gdt-1 # table byte length
|
||||||
.quad _gdt # table address (final virtual space)
|
.quad _gdt # table address (final virtual space)
|
||||||
.endobj _gdtr,global,hidden
|
.endobj _gdtr,global,hidden
|
||||||
.align 8
|
.balign 8
|
||||||
// Partial GDT with descriptors for switching to unreal mode or long mode.
|
// Partial GDT with descriptors for switching to unreal mode or long mode.
|
||||||
_gdtlo = .-GDT_LEGACY_DATA
|
_gdtlo = .-GDT_LEGACY_DATA
|
||||||
.quad 0b0000000011001111100100100000000000000000000000001111111111111111 #32
|
.quad 0b0000000011001111100100100000000000000000000000001111111111111111 #32
|
||||||
|
@ -1715,7 +1715,7 @@ long: movabs $BANE+PHYSICAL(0f),%rax
|
||||||
#define GRUB_CHECKSUM(FLAGS) (-(GRUB_MAGIC + (FLAGS)) & 0xffffffff)
|
#define GRUB_CHECKSUM(FLAGS) (-(GRUB_MAGIC + (FLAGS)) & 0xffffffff)
|
||||||
|
|
||||||
// Grub Header.
|
// Grub Header.
|
||||||
.align 4
|
.balign 4
|
||||||
ape_grub:
|
ape_grub:
|
||||||
.long GRUB_MAGIC # Magic
|
.long GRUB_MAGIC # Magic
|
||||||
.long GRUB_AOUT # Flags
|
.long GRUB_AOUT # Flags
|
||||||
|
@ -1730,7 +1730,7 @@ ape_grub:
|
||||||
// Grub Entrypoint.
|
// Grub Entrypoint.
|
||||||
// Takes CPU out of legacy mode and jumps to normal entrypoint.
|
// Takes CPU out of legacy mode and jumps to normal entrypoint.
|
||||||
// @noreturn
|
// @noreturn
|
||||||
.align 4
|
.balign 4
|
||||||
ape_grub_entry:
|
ape_grub_entry:
|
||||||
.code32
|
.code32
|
||||||
// cmp $GRUB_EAX,%eax
|
// cmp $GRUB_EAX,%eax
|
||||||
|
@ -1874,7 +1874,7 @@ ape_pad_text:
|
||||||
.type ape_pad_privileged,@object
|
.type ape_pad_privileged,@object
|
||||||
.hidden ape_pad_privileged
|
.hidden ape_pad_privileged
|
||||||
ape_pad_privileged:
|
ape_pad_privileged:
|
||||||
.align 4096
|
.balign 4096
|
||||||
.previous
|
.previous
|
||||||
|
|
||||||
.section .ape.pad.rodata,"a",@progbits
|
.section .ape.pad.rodata,"a",@progbits
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
// @see ape/ape.lds
|
// @see ape/ape.lds
|
||||||
// @see winimp
|
// @see winimp
|
||||||
.macro .imp dll:req fn:req actual:req hint
|
.macro .imp dll:req fn:req actual:req hint
|
||||||
|
#ifdef __x86_64__
|
||||||
.dll "\dll"
|
.dll "\dll"
|
||||||
.section ".piro.data.sort.iat.2.\dll\().2.\actual","aw",@progbits
|
.section ".piro.data.sort.iat.2.\dll\().2.\actual","aw",@progbits
|
||||||
.type \fn,@object
|
.type \fn,@object
|
||||||
|
@ -49,18 +50,28 @@
|
||||||
.previous
|
.previous
|
||||||
.section ".idata.ro.hnt.\dll\().2.\actual","a",@progbits
|
.section ".idata.ro.hnt.\dll\().2.\actual","a",@progbits
|
||||||
"\dll\().\actual":
|
"\dll\().\actual":
|
||||||
.ifnb \hint # hint i.e. guess function ordinal
|
.ifnb \hint // hint i.e. guess function ordinal
|
||||||
.short \hint
|
.short \hint
|
||||||
.else
|
.else
|
||||||
.short 0
|
.short 0
|
||||||
.endif
|
.endif
|
||||||
.asciz "\actual"
|
.asciz "\actual"
|
||||||
.align 2 # documented requirement
|
.align 2 // documented requirement
|
||||||
.globl "\dll\().\actual"
|
.globl "\dll\().\actual"
|
||||||
.hidden "\dll\().\actual"
|
.hidden "\dll\().\actual"
|
||||||
.type "\dll\().\actual",@object
|
.type "\dll\().\actual",@object
|
||||||
.size "\dll\().\actual",.-"\dll\().\actual"
|
.size "\dll\().\actual",.-"\dll\().\actual"
|
||||||
.previous
|
.previous
|
||||||
|
#else
|
||||||
|
.section ".text.nt.\actual","ax",@progbits
|
||||||
|
.globl "\actual"
|
||||||
|
"\actual":
|
||||||
|
ret
|
||||||
|
.section ".data.nt.\actual","aw",@progbits
|
||||||
|
.globl "\fn"
|
||||||
|
.balign 8
|
||||||
|
"\fn": .quad "\actual"
|
||||||
|
#endif
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
// Defines DLL import.
|
// Defines DLL import.
|
||||||
|
@ -68,11 +79,11 @@
|
||||||
.macro .dll name:req
|
.macro .dll name:req
|
||||||
.section ".idata.ro.idt.2.\name","aG",@progbits,"\name",comdat
|
.section ".idata.ro.idt.2.\name","aG",@progbits,"\name",comdat
|
||||||
.equ ".Lidata.idt.\name",.
|
.equ ".Lidata.idt.\name",.
|
||||||
.long RVA("idata.ilt.\name") # ImportLookupTable
|
.long RVA("idata.ilt.\name") // ImportLookupTable
|
||||||
.long 0 # TimeDateStamp
|
.long 0 // TimeDateStamp
|
||||||
.long 0 # ForwarderChain
|
.long 0 // ForwarderChain
|
||||||
.long RVA(".Lidata.str.\name") # DllNameRva
|
.long RVA(".Lidata.str.\name") // DllNameRva
|
||||||
.long RVA("idata.iat.\name") # ImportAddressTable
|
.long RVA("idata.iat.\name") // ImportAddressTable
|
||||||
.type ".Lidata.idt.\name",@object
|
.type ".Lidata.idt.\name",@object
|
||||||
.size ".Lidata.idt.\name",.-".Lidata.idt.\name"
|
.size ".Lidata.idt.\name",.-".Lidata.idt.\name"
|
||||||
.previous
|
.previous
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
// APE Loader Executable Structure
|
// APE Loader Executable Structure
|
||||||
// Linux, FreeBSD, NetBSD, OpenBSD
|
// Linux, FreeBSD, NetBSD, OpenBSD
|
||||||
|
|
||||||
.align 8
|
.balign 8
|
||||||
ehdr: .ascii "\177ELF"
|
ehdr: .ascii "\177ELF"
|
||||||
.byte ELFCLASS64
|
.byte ELFCLASS64
|
||||||
.byte ELFDATA2LSB
|
.byte ELFDATA2LSB
|
||||||
|
@ -47,7 +47,7 @@ ehdr: .ascii "\177ELF"
|
||||||
.word 0 # e_shstrndx
|
.word 0 # e_shstrndx
|
||||||
.endobj ehdr,globl
|
.endobj ehdr,globl
|
||||||
|
|
||||||
.align 8
|
.balign 8
|
||||||
phdrs: .long PT_LOAD # p_type
|
phdrs: .long PT_LOAD # p_type
|
||||||
.long PF_R|PF_X # p_flags
|
.long PF_R|PF_X # p_flags
|
||||||
.quad 0 # p_offset
|
.quad 0 # p_offset
|
||||||
|
@ -89,18 +89,18 @@ note: .long 2f-1f
|
||||||
.long 4f-3f
|
.long 4f-3f
|
||||||
.long 1
|
.long 1
|
||||||
1: .asciz "OpenBSD"
|
1: .asciz "OpenBSD"
|
||||||
2: .align 4
|
2: .balign 4
|
||||||
3: .long 0
|
3: .long 0
|
||||||
4: .long 2f-1f
|
4: .long 2f-1f
|
||||||
.long 4f-3f
|
.long 4f-3f
|
||||||
.long 1
|
.long 1
|
||||||
1: .asciz "NetBSD"
|
1: .asciz "NetBSD"
|
||||||
2: .align 4
|
2: .balign 4
|
||||||
3: .long 901000000
|
3: .long 901000000
|
||||||
4: .endobj note
|
4: .endobj note
|
||||||
notesize = . - note
|
notesize = . - note
|
||||||
|
|
||||||
.align 64,0 # for ape.S dd
|
.balign 64,0 # for ape.S dd
|
||||||
.org 0x180 # for ape.S dd
|
.org 0x180 # for ape.S dd
|
||||||
|
|
||||||
// APE Loader XNU Header
|
// APE Loader XNU Header
|
||||||
|
@ -197,7 +197,7 @@ macho: .long 0xFEEDFACE+1
|
||||||
60:
|
60:
|
||||||
.endobj macho
|
.endobj macho
|
||||||
|
|
||||||
.align 64,0 # for ape.S dd
|
.balign 64,0 # for ape.S dd
|
||||||
.org 0x400 # for ape.S dd
|
.org 0x400 # for ape.S dd
|
||||||
|
|
||||||
// Ape Loader Entrpoint
|
// Ape Loader Entrpoint
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
// APE Loader Executable Structure for XNU
|
// APE Loader Executable Structure for XNU
|
||||||
|
|
||||||
.align 4096
|
.balign 4096
|
||||||
macho: .long 0xFEEDFACE+1
|
macho: .long 0xFEEDFACE+1
|
||||||
.long MAC_CPU_NEXGEN32E
|
.long MAC_CPU_NEXGEN32E
|
||||||
.long MAC_CPU_NEXGEN32E_ALL
|
.long MAC_CPU_NEXGEN32E_ALL
|
||||||
|
@ -112,7 +112,7 @@ macho: .long 0xFEEDFACE+1
|
||||||
60:
|
60:
|
||||||
.endobj macho,globl
|
.endobj macho,globl
|
||||||
|
|
||||||
.align 64
|
.balign 64
|
||||||
_start:
|
_start:
|
||||||
|
|
||||||
// Hack for detecting M1 Rosetta environment.
|
// Hack for detecting M1 Rosetta environment.
|
||||||
|
|
|
@ -74,11 +74,12 @@ IGNORE := $(shell $(MKDIR) o/tmp)
|
||||||
|
|
||||||
ifneq ("$(wildcard o/third_party/gcc/bin/x86_64-pc-linux-gnu-*)","")
|
ifneq ("$(wildcard o/third_party/gcc/bin/x86_64-pc-linux-gnu-*)","")
|
||||||
PREFIX = o/third_party/gcc/bin/x86_64-pc-linux-gnu-
|
PREFIX = o/third_party/gcc/bin/x86_64-pc-linux-gnu-
|
||||||
PREFIX_AARCH64 = o/third_party/gcc/bin/aarch64-pc-linux-gnu-
|
|
||||||
else
|
else
|
||||||
IGNORE := $(shell build/bootstrap/unbundle.com)
|
IGNORE := $(shell build/bootstrap/unbundle.com)
|
||||||
PREFIX = o/third_party/gcc/bin/x86_64-linux-musl-
|
PREFIX = o/third_party/gcc/bin/x86_64-linux-musl-
|
||||||
PREFIX_AARCH64 = o/third_party/gcc/bin/aarch64-linux-musl-
|
endif
|
||||||
|
ifeq ($(MODE), aarch64)
|
||||||
|
PREFIX = o/third_party/gcc/bin/aarch64-linux-musl-
|
||||||
endif
|
endif
|
||||||
|
|
||||||
AS = $(PREFIX)as
|
AS = $(PREFIX)as
|
||||||
|
@ -93,18 +94,6 @@ OBJCOPY = $(PREFIX)objcopy
|
||||||
OBJDUMP = $(PREFIX)objdump
|
OBJDUMP = $(PREFIX)objdump
|
||||||
ADDR2LINE = $(PWD)/$(PREFIX)addr2line
|
ADDR2LINE = $(PWD)/$(PREFIX)addr2line
|
||||||
|
|
||||||
AS_AARCH64 = $(PREFIX_AARCH64)as
|
|
||||||
CC_AARCH64 = $(PREFIX_AARCH64)gcc
|
|
||||||
CXX_AARCH64 = $(PREFIX_AARCH64)g++
|
|
||||||
CXXFILT_AARCH64 = $(PREFIX_AARCH64)c++filt
|
|
||||||
LD_AARCH64 = $(PREFIX_AARCH64)ld.bfd
|
|
||||||
NM_AARCH64 = $(PREFIX_AARCH64)nm
|
|
||||||
GCC_AARCH64 = $(PREFIX_AARCH64)gcc
|
|
||||||
STRIP_AARCH64 = $(PREFIX_AARCH64)strip
|
|
||||||
OBJCOPY_AARCH64 = $(PREFIX_AARCH64)objcopy
|
|
||||||
OBJDUMP_AARCH64 = $(PREFIX_AARCH64)objdump
|
|
||||||
ADDR2LINE_AARCH64 = $(PWD)/$(PREFIX_AARCH64)addr2line
|
|
||||||
|
|
||||||
export ADDR2LINE
|
export ADDR2LINE
|
||||||
export LC_ALL
|
export LC_ALL
|
||||||
export MKDIR
|
export MKDIR
|
||||||
|
@ -118,6 +107,10 @@ else
|
||||||
TMPSAFE = $(TMPDIR)/
|
TMPSAFE = $(TMPDIR)/
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq ($(MODE), aarch64)
|
||||||
|
MNO_FENTRY = -mno-fentry
|
||||||
|
endif
|
||||||
|
|
||||||
FTRACE = \
|
FTRACE = \
|
||||||
-pg
|
-pg
|
||||||
|
|
||||||
|
@ -131,7 +124,7 @@ SANITIZER = \
|
||||||
-fsanitize=address
|
-fsanitize=address
|
||||||
|
|
||||||
NO_MAGIC = \
|
NO_MAGIC = \
|
||||||
-mno-fentry \
|
$(MNO_FENTRY) \
|
||||||
-fno-stack-protector \
|
-fno-stack-protector \
|
||||||
-fwrapv \
|
-fwrapv \
|
||||||
-fno-sanitize=all
|
-fno-sanitize=all
|
||||||
|
@ -342,14 +335,10 @@ OBJECTIFY.greg.c = \
|
||||||
-fno-optimize-sibling-calls \
|
-fno-optimize-sibling-calls \
|
||||||
-fno-sanitize=all \
|
-fno-sanitize=all \
|
||||||
-ffreestanding \
|
-ffreestanding \
|
||||||
|
$(MNO_FENTRY) \
|
||||||
-fwrapv \
|
-fwrapv \
|
||||||
-c
|
-c
|
||||||
|
|
||||||
ifneq ($(MODE), aarch64)
|
|
||||||
OBJECTIFY.greg.c += \
|
|
||||||
-mno-fentry
|
|
||||||
endif
|
|
||||||
|
|
||||||
OBJECTIFY.ansi.c = $(CC) $(OBJECTIFY.c.flags) -ansi -Wextra -Werror -pedantic-errors -c
|
OBJECTIFY.ansi.c = $(CC) $(OBJECTIFY.c.flags) -ansi -Wextra -Werror -pedantic-errors -c
|
||||||
OBJECTIFY.c99.c = $(CC) $(OBJECTIFY.c.flags) -std=c99 -Wextra -Werror -pedantic-errors -c
|
OBJECTIFY.c99.c = $(CC) $(OBJECTIFY.c.flags) -std=c99 -Wextra -Werror -pedantic-errors -c
|
||||||
OBJECTIFY.c11.c = $(CC) $(OBJECTIFY.c.flags) -std=c11 -Wextra -Werror -pedantic-errors -c
|
OBJECTIFY.c11.c = $(CC) $(OBJECTIFY.c.flags) -std=c11 -Wextra -Werror -pedantic-errors -c
|
||||||
|
@ -386,7 +375,7 @@ OBJECTIFY.ncabi.c = \
|
||||||
$(OBJECTIFY.c.flags) \
|
$(OBJECTIFY.c.flags) \
|
||||||
-mno-sse \
|
-mno-sse \
|
||||||
-mfpmath=387 \
|
-mfpmath=387 \
|
||||||
-mno-fentry \
|
$(MNO_FENTRY) \
|
||||||
-fno-stack-protector \
|
-fno-stack-protector \
|
||||||
-fno-instrument-functions \
|
-fno-instrument-functions \
|
||||||
-fno-optimize-sibling-calls \
|
-fno-optimize-sibling-calls \
|
||||||
|
@ -405,7 +394,7 @@ OBJECTIFY.ncabi.c = \
|
||||||
OBJECTIFY.initabi.c = \
|
OBJECTIFY.initabi.c = \
|
||||||
$(GCC) \
|
$(GCC) \
|
||||||
$(OBJECTIFY.c.flags) \
|
$(OBJECTIFY.c.flags) \
|
||||||
-mno-fentry \
|
$(MNO_FENTRY) \
|
||||||
-fno-stack-protector \
|
-fno-stack-protector \
|
||||||
-fno-instrument-functions \
|
-fno-instrument-functions \
|
||||||
-fno-optimize-sibling-calls \
|
-fno-optimize-sibling-calls \
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
for last; do true; done
|
for last; do true; done
|
||||||
if grep aarch64 "$last" >/dev/null 2>&1; then
|
if printf '%s\n' "$last" | grep aarch64 >/dev/null 2>&1; then
|
||||||
exec o/third_party/gcc/bin/aarch64-linux-musl-objdump "$@"
|
exec o/third_party/gcc/bin/aarch64-linux-musl-objdump "$@"
|
||||||
else
|
else
|
||||||
exec o/third_party/gcc/bin/x86_64-linux-musl-objdump "$@"
|
exec o/third_party/gcc/bin/x86_64-linux-musl-objdump "$@"
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.align 16
|
.balign 16
|
||||||
|
|
||||||
// Mixes audio.
|
// Mixes audio.
|
||||||
//
|
//
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
#include "dsp/mpeg/idct.h"
|
#include "dsp/mpeg/idct.h"
|
||||||
#include "dsp/mpeg/mpeg.h"
|
#include "dsp/mpeg/mpeg.h"
|
||||||
#include "dsp/mpeg/video.h"
|
#include "dsp/mpeg/video.h"
|
||||||
#include "libc/intrin/initializer.internal.h"
|
|
||||||
#include "libc/fmt/conv.h"
|
#include "libc/fmt/conv.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "dsp/tty/itoa8.h"
|
#include "dsp/tty/itoa8.h"
|
||||||
#include "libc/intrin/bits.h"
|
#include "libc/intrin/bits.h"
|
||||||
#include "libc/intrin/initializer.internal.h"
|
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
struct Itoa8 kItoa8;
|
struct Itoa8 kItoa8;
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
#include "dsp/core/core.h"
|
#include "dsp/core/core.h"
|
||||||
#include "dsp/tty/quant.h"
|
#include "dsp/tty/quant.h"
|
||||||
#include "libc/assert.h"
|
#include "libc/assert.h"
|
||||||
#include "libc/intrin/initializer.internal.h"
|
|
||||||
#include "libc/limits.h"
|
#include "libc/limits.h"
|
||||||
#include "libc/log/log.h"
|
#include "libc/log/log.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "dsp/tty/internal.h"
|
#include "dsp/tty/internal.h"
|
||||||
#include "dsp/tty/quant.h"
|
#include "dsp/tty/quant.h"
|
||||||
#include "libc/intrin/initializer.internal.h"
|
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
|
|
14
libc/aarch64/aarch64.mk
Normal file
14
libc/aarch64/aarch64.mk
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
|
||||||
|
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
|
||||||
|
|
||||||
|
o/$(MODE)/libc/aarch64/%.o: libc/aarch64/%.S
|
||||||
|
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||||
|
|
||||||
|
o/$(MODE)/libc/aarch64/start.o: \
|
||||||
|
libc/aarch64/start.c \
|
||||||
|
libc/runtime/runtime.h
|
||||||
|
|
||||||
|
o/$(MODE)/libc/aarch64: \
|
||||||
|
o/$(MODE)/libc/aarch64/crt.o \
|
||||||
|
o/$(MODE)/libc/aarch64/fenv.o \
|
||||||
|
o/$(MODE)/libc/aarch64/start.o
|
53
libc/aarch64/crt.S
Normal file
53
libc/aarch64/crt.S
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/*-*- 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 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. │
|
||||||
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
|
||||||
|
.globl _start
|
||||||
|
.type _start,%function
|
||||||
|
_start: mov x29,#0
|
||||||
|
mov x30,#0
|
||||||
|
mov x0,sp
|
||||||
|
and sp,x0,#-16
|
||||||
|
b _start_c
|
||||||
|
.size _start,.-_start
|
||||||
|
|
||||||
|
.section .initprologue
|
||||||
|
.global _init
|
||||||
|
.type _init,%function
|
||||||
|
_init: stp x29,x30,[sp,-16]!
|
||||||
|
mov x29,sp
|
||||||
|
.previous/*
|
||||||
|
...
|
||||||
|
decentralized content
|
||||||
|
...
|
||||||
|
*/.section .initepilogue
|
||||||
|
ldp x29,x30,[sp],#16
|
||||||
|
ret
|
||||||
|
|
||||||
|
.section .finiprologue
|
||||||
|
.global _fini
|
||||||
|
.type _fini,%function
|
||||||
|
_fini: stp x29,x30,[sp,-16]!
|
||||||
|
mov x29,sp
|
||||||
|
.previous/*
|
||||||
|
...
|
||||||
|
decentralized content
|
||||||
|
...
|
||||||
|
*/.section .finiepilogue
|
||||||
|
ldp x29,x30,[sp],#16
|
||||||
|
ret
|
67
libc/aarch64/fenv.S
Normal file
67
libc/aarch64/fenv.S
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
.global fegetround
|
||||||
|
.type fegetround,%function
|
||||||
|
fegetround:
|
||||||
|
mrs x0,fpcr
|
||||||
|
and w0,w0,#0xc00000
|
||||||
|
ret
|
||||||
|
|
||||||
|
.global __fesetround
|
||||||
|
.hidden __fesetround
|
||||||
|
.type __fesetround,%function
|
||||||
|
__fesetround:
|
||||||
|
mrs x1,fpcr
|
||||||
|
bic w1,w1,#0xc00000
|
||||||
|
orr w1,w1,w0
|
||||||
|
msr fpcr,x1
|
||||||
|
mov w0,#0
|
||||||
|
ret
|
||||||
|
|
||||||
|
.global fetestexcept
|
||||||
|
.type fetestexcept,%function
|
||||||
|
fetestexcept:
|
||||||
|
and w0,w0,#0x1f
|
||||||
|
mrs x1,fpsr
|
||||||
|
and w0,w0,w1
|
||||||
|
ret
|
||||||
|
|
||||||
|
.global feclearexcept
|
||||||
|
.type feclearexcept,%function
|
||||||
|
feclearexcept:
|
||||||
|
and w0,w0,#0x1f
|
||||||
|
mrs x1,fpsr
|
||||||
|
bic w1,w1,w0
|
||||||
|
msr fpsr,x1
|
||||||
|
mov w0,#0
|
||||||
|
ret
|
||||||
|
|
||||||
|
.global feraiseexcept
|
||||||
|
.type feraiseexcept,%function
|
||||||
|
feraiseexcept:
|
||||||
|
and w0,w0,#0x1f
|
||||||
|
mrs x1,fpsr
|
||||||
|
orr w1,w1,w0
|
||||||
|
msr fpsr,x1
|
||||||
|
mov w0,#0
|
||||||
|
ret
|
||||||
|
|
||||||
|
.global fegetenv
|
||||||
|
.type fegetenv,%function
|
||||||
|
fegetenv:
|
||||||
|
mrs x1,fpcr
|
||||||
|
mrs x2,fpsr
|
||||||
|
stp w1,w2,[x0]
|
||||||
|
mov w0,#0
|
||||||
|
ret
|
||||||
|
|
||||||
|
.global fesetenv
|
||||||
|
.type fesetenv,%function
|
||||||
|
fesetenv:
|
||||||
|
mov x1,#0
|
||||||
|
mov x2,#0
|
||||||
|
cmn x0,#1
|
||||||
|
b.eq 1f
|
||||||
|
ldp w1,w2,[x0]
|
||||||
|
1: msr fpcr,x1
|
||||||
|
msr fpsr,x2
|
||||||
|
mov w0,#0
|
||||||
|
ret
|
56
libc/aarch64/start.c
Normal file
56
libc/aarch64/start.c
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/*-*- 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. │
|
||||||
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
||||||
|
int main(int, char **, char **);
|
||||||
|
|
||||||
|
int __argc;
|
||||||
|
char **__argv;
|
||||||
|
char **__envp;
|
||||||
|
char **environ;
|
||||||
|
|
||||||
|
static inline long sys_set_tid_address(int *t) {
|
||||||
|
register int64_t __r0 asm("x0") = (int64_t)t;
|
||||||
|
register int64_t __res_x0 asm("x0");
|
||||||
|
int64_t __res;
|
||||||
|
asm volatile("mov x8, %1\n"
|
||||||
|
"svc 0x0\n"
|
||||||
|
: "=r"(__res_x0)
|
||||||
|
: "i"(96), "r"(__r0)
|
||||||
|
: "x8", "memory");
|
||||||
|
return __res_x0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _start_c(long *sp) {
|
||||||
|
int argc;
|
||||||
|
char **argv, **envp;
|
||||||
|
unsigned long *auxv;
|
||||||
|
argc = *sp;
|
||||||
|
argv = (char **)(sp + 1);
|
||||||
|
envp = (char **)(sp + 1 + argc + 1);
|
||||||
|
auxv = (unsigned long *)(sp + 1 + argc + 1);
|
||||||
|
for (;;) {
|
||||||
|
if (!*auxv++) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
__auxv = auxv;
|
||||||
|
environ = envp;
|
||||||
|
exit(main(argc, argv, envp));
|
||||||
|
}
|
|
@ -23,7 +23,6 @@
|
||||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/intrin/bits.h"
|
#include "libc/intrin/bits.h"
|
||||||
#include "libc/intrin/initializer.internal.h"
|
|
||||||
#include "libc/intrin/safemacros.internal.h"
|
#include "libc/intrin/safemacros.internal.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include "libc/calls/struct/timespec.h"
|
#include "libc/calls/struct/timespec.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/intrin/bits.h"
|
#include "libc/intrin/bits.h"
|
||||||
#include "libc/intrin/initializer.internal.h"
|
|
||||||
#include "libc/intrin/safemacros.internal.h"
|
#include "libc/intrin/safemacros.internal.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
|
|
|
@ -106,7 +106,11 @@
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
extern const int __hostos;
|
extern const int __hostos;
|
||||||
|
#else
|
||||||
|
#define __hostos _HOSTLINUX
|
||||||
|
#endif
|
||||||
|
|
||||||
bool IsWsl1(void);
|
bool IsWsl1(void);
|
||||||
|
|
||||||
|
|
|
@ -578,11 +578,15 @@ typedef struct {
|
||||||
#define autotype(x) typeof(x)
|
#define autotype(x) typeof(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
#if __GNUC__ >= 7 || __has_attribute(__no_caller_saved_registers__)
|
#if __GNUC__ >= 7 || __has_attribute(__no_caller_saved_registers__)
|
||||||
#define nocallersavedregisters __attribute__((__no_caller_saved_registers__))
|
#define nocallersavedregisters __attribute__((__no_caller_saved_registers__))
|
||||||
#else
|
#else
|
||||||
#define nocallersavedregisters "need modern compiler"
|
#define nocallersavedregisters "need modern compiler"
|
||||||
#endif
|
#endif
|
||||||
|
#else
|
||||||
|
#define nocallersavedregisters
|
||||||
|
#endif
|
||||||
|
|
||||||
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
|
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
|
||||||
__has_attribute(__no_sanitize_address__)
|
__has_attribute(__no_sanitize_address__)
|
||||||
|
@ -608,11 +612,15 @@ typedef struct {
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
#define notpossible \
|
#define notpossible \
|
||||||
do { \
|
do { \
|
||||||
asm("nop\n\tud2\n\tnop"); \
|
asm("nop\n\tud2\n\tnop"); \
|
||||||
unreachable; \
|
unreachable; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
#else
|
||||||
|
#define notpossible __builtin_trap()
|
||||||
|
#endif
|
||||||
|
|
||||||
#define donothing \
|
#define donothing \
|
||||||
do { \
|
do { \
|
||||||
|
@ -667,7 +675,7 @@ typedef struct {
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __llvm__
|
#if defined(__x86_64__) && !defined(__llvm__)
|
||||||
#define initarray _Section(".init_array,\"a\",@init_array #")
|
#define initarray _Section(".init_array,\"a\",@init_array #")
|
||||||
#else
|
#else
|
||||||
#define initarray _Section(".init_array")
|
#define initarray _Section(".init_array")
|
||||||
|
@ -773,8 +781,12 @@ typedef struct {
|
||||||
#endif /* -w */
|
#endif /* -w */
|
||||||
|
|
||||||
#ifndef __STRICT_ANSI__
|
#ifndef __STRICT_ANSI__
|
||||||
|
#ifdef __x86_64__
|
||||||
#define DebugBreak() asm("int3")
|
#define DebugBreak() asm("int3")
|
||||||
#else
|
#else
|
||||||
|
#define DebugBreak() __builtin_trap()
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
#define DebugBreak() (void)0
|
#define DebugBreak() (void)0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -810,14 +822,14 @@ typedef struct {
|
||||||
#define EXPROPRIATE(EXPRESSION) (EXPRESSION)
|
#define EXPROPRIATE(EXPRESSION) (EXPRESSION)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__)
|
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__) && defined(__x86_64__)
|
||||||
#define YOINK(SYMBOL) \
|
#define YOINK(SYMBOL) \
|
||||||
asm(".section .yoink\n\tnopl\t%a0\n\t.previous" : : "X"(SYMBOL))
|
asm(".section .yoink\n\tnopl\t%a0\n\t.previous" : : "X"(SYMBOL))
|
||||||
#else
|
#else
|
||||||
#define YOINK(SYMBOL) (void)0
|
#define YOINK(SYMBOL) (void)0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__)
|
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__) && defined(__x86_64__)
|
||||||
#define STATIC_YOINK(SYMBOLSTR) \
|
#define STATIC_YOINK(SYMBOLSTR) \
|
||||||
asm(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
|
asm(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
.privileged
|
||||||
.alignfunc
|
.balignfunc
|
||||||
|
|
||||||
// Returns 𝑥+𝑦, aborting on overflow.
|
// Returns 𝑥+𝑦, aborting on overflow.
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
.privileged
|
||||||
.alignfunc
|
.balignfunc
|
||||||
|
|
||||||
// Returns 𝑥+𝑦, aborting on overflow.
|
// Returns 𝑥+𝑦, aborting on overflow.
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
.privileged
|
||||||
.alignfunc
|
.balignfunc
|
||||||
|
|
||||||
// Returns 𝑥+𝑦, aborting on overflow.
|
// Returns 𝑥+𝑦, aborting on overflow.
|
||||||
//
|
//
|
||||||
|
|
|
@ -9,6 +9,7 @@ int _bsfll(long long) pureconst;
|
||||||
int _bsf128(uintmax_t) pureconst;
|
int _bsf128(uintmax_t) pureconst;
|
||||||
|
|
||||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||||
|
#ifdef __x86_64__
|
||||||
#define _bsf(u) \
|
#define _bsf(u) \
|
||||||
({ \
|
({ \
|
||||||
unsigned BiTs; \
|
unsigned BiTs; \
|
||||||
|
@ -22,6 +23,11 @@ int _bsf128(uintmax_t) pureconst;
|
||||||
(unsigned)BiTs; \
|
(unsigned)BiTs; \
|
||||||
})
|
})
|
||||||
#define _bsfll(u) _bsfl(u)
|
#define _bsfll(u) _bsfl(u)
|
||||||
|
#else
|
||||||
|
#define _bsf(x) __builtin_ctz(x)
|
||||||
|
#define _bsfl(x) __builtin_ctzl(x)
|
||||||
|
#define _bsfll(x) __builtin_ctzll(x)
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
|
|
|
@ -7,7 +7,8 @@ int _bsr(int) pureconst;
|
||||||
int _bsrl(long) pureconst;
|
int _bsrl(long) pureconst;
|
||||||
int _bsrll(long long) pureconst;
|
int _bsrll(long long) pureconst;
|
||||||
|
|
||||||
#if defined(__GNUC__) && defined(__x86_64__) && !defined(__STRICT_ANSI__)
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||||
|
#ifdef __x86_64__
|
||||||
int _bsr128(uint128_t) pureconst;
|
int _bsr128(uint128_t) pureconst;
|
||||||
#define _bsr(u) \
|
#define _bsr(u) \
|
||||||
({ \
|
({ \
|
||||||
|
@ -22,6 +23,11 @@ int _bsr128(uint128_t) pureconst;
|
||||||
(unsigned)BiTs; \
|
(unsigned)BiTs; \
|
||||||
})
|
})
|
||||||
#define _bsrll(u) _bsrl(u)
|
#define _bsrll(u) _bsrl(u)
|
||||||
|
#else
|
||||||
|
#define _bsr(x) (__builtin_clz(x) ^ (sizeof(int) * CHAR_BIT - 1))
|
||||||
|
#define _bsrl(x) (__builtin_clzl(x) ^ (sizeof(long) * CHAR_BIT - 1))
|
||||||
|
#define _bsrll(x) (__builtin_clzll(x) ^ (sizeof(long long) * CHAR_BIT - 1))
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
|
|
|
@ -43,6 +43,7 @@ static dontinline antiquity void bzero_sse(char *p, size_t n) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
microarchitecture("avx") static void bzero_avx(char *p, size_t n) {
|
microarchitecture("avx") static void bzero_avx(char *p, size_t n) {
|
||||||
xmm_t v = {0};
|
xmm_t v = {0};
|
||||||
if (IsAsan()) __asan_verify(p, n);
|
if (IsAsan()) __asan_verify(p, n);
|
||||||
|
@ -73,6 +74,7 @@ microarchitecture("avx") static void bzero_avx(char *p, size_t n) {
|
||||||
*(xmm_t *)p = v;
|
*(xmm_t *)p = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets memory to zero.
|
* Sets memory to zero.
|
||||||
|
@ -134,7 +136,11 @@ void bzero(void *p, size_t n) {
|
||||||
char *b;
|
char *b;
|
||||||
uint64_t x;
|
uint64_t x;
|
||||||
b = p;
|
b = p;
|
||||||
|
#ifdef __x86_64__
|
||||||
asm("xorl\t%k0,%k0" : "=r"(x));
|
asm("xorl\t%k0,%k0" : "=r"(x));
|
||||||
|
#else
|
||||||
|
x = 0;
|
||||||
|
#endif
|
||||||
if (n <= 16) {
|
if (n <= 16) {
|
||||||
if (n >= 8) {
|
if (n >= 8) {
|
||||||
__builtin_memcpy(b, &x, 8);
|
__builtin_memcpy(b, &x, 8);
|
||||||
|
@ -148,11 +154,13 @@ void bzero(void *p, size_t n) {
|
||||||
b[--n] = x;
|
b[--n] = x;
|
||||||
} while (n);
|
} while (n);
|
||||||
}
|
}
|
||||||
|
#ifdef __x86_64__
|
||||||
} else if (IsTiny()) {
|
} else if (IsTiny()) {
|
||||||
asm("rep stosb" : "+D"(b), "+c"(n), "=m"(*(char(*)[n])b) : "a"(0));
|
asm("rep stosb" : "+D"(b), "+c"(n), "=m"(*(char(*)[n])b) : "a"(0));
|
||||||
return;
|
return;
|
||||||
} else if (X86_HAVE(AVX)) {
|
} else if (X86_HAVE(AVX)) {
|
||||||
bzero_avx(b, n);
|
bzero_avx(b, n);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
bzero_sse(b, n);
|
bzero_sse(b, n);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__x86__)
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86__)
|
||||||
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
|
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
|
||||||
({ \
|
({ \
|
||||||
bool DidIt; \
|
bool DidIt; \
|
||||||
|
|
|
@ -40,6 +40,7 @@ size_t _countbits(const void *a, size_t n) {
|
||||||
p = a;
|
p = a;
|
||||||
e = p + n;
|
e = p + n;
|
||||||
if (!IsTiny()) {
|
if (!IsTiny()) {
|
||||||
|
#ifdef __x86_64__
|
||||||
if (X86_HAVE(POPCNT)) {
|
if (X86_HAVE(POPCNT)) {
|
||||||
while (p + sizeof(long) * 4 <= e) {
|
while (p + sizeof(long) * 4 <= e) {
|
||||||
__builtin_memcpy(&Ai, p + 000, sizeof(long));
|
__builtin_memcpy(&Ai, p + 000, sizeof(long));
|
||||||
|
@ -60,6 +61,7 @@ size_t _countbits(const void *a, size_t n) {
|
||||||
t += Ao;
|
t += Ao;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
#endif
|
||||||
while (p + 8 <= e) {
|
while (p + 8 <= e) {
|
||||||
__builtin_memcpy(&x, p, 8);
|
__builtin_memcpy(&x, p, 8);
|
||||||
x = x - ((x >> 1) & 0x5555555555555555);
|
x = x - ((x >> 1) & 0x5555555555555555);
|
||||||
|
@ -71,7 +73,9 @@ size_t _countbits(const void *a, size_t n) {
|
||||||
t += x;
|
t += x;
|
||||||
p += 8;
|
p += 8;
|
||||||
}
|
}
|
||||||
|
#ifdef __x86_64__
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
while (p < e) {
|
while (p < e) {
|
||||||
b = *p++ & 255;
|
b = *p++ & 255;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/consts/prot.h"
|
#include "libc/sysv/consts/prot.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
#define MAP_ANONYMOUS_linux 0x00000020
|
#define MAP_ANONYMOUS_linux 0x00000020
|
||||||
#define MAP_FIXED_linux 0x00000010
|
#define MAP_FIXED_linux 0x00000010
|
||||||
|
@ -109,3 +110,5 @@ noasan struct DirectMap sys_mmap_metal(void *vaddr, size_t size, int prot,
|
||||||
res.maphandle = -1;
|
res.maphandle = -1;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
privileged wontreturn void _Exit(int exitcode) {
|
privileged wontreturn void _Exit(int exitcode) {
|
||||||
int i;
|
int i;
|
||||||
STRACE("_Exit(%d)", exitcode);
|
STRACE("_Exit(%d)", exitcode);
|
||||||
|
#ifdef __x86_64__
|
||||||
if (!IsWindows() && !IsMetal()) {
|
if (!IsWindows() && !IsMetal()) {
|
||||||
// On Linux _Exit1 (exit) must be called in pledge("") mode. If we
|
// On Linux _Exit1 (exit) must be called in pledge("") mode. If we
|
||||||
// call _Exit (exit_group) when we haven't used pledge("stdio") then
|
// call _Exit (exit_group) when we haven't used pledge("stdio") then
|
||||||
|
@ -64,4 +65,13 @@ privileged wontreturn void _Exit(int exitcode) {
|
||||||
"cli\n\t"
|
"cli\n\t"
|
||||||
"lidt\t(%rsp)");
|
"lidt\t(%rsp)");
|
||||||
for (;;) asm("ud2");
|
for (;;) asm("ud2");
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
register long x0 asm("x0") = exitcode;
|
||||||
|
asm volatile("mov\tx8,%1\n"
|
||||||
|
"svc\t0"
|
||||||
|
: /* no outputs */
|
||||||
|
: "i"(94), "r"(x0)
|
||||||
|
: "x8", "memory");
|
||||||
|
notpossible;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ __msabi extern typeof(ExitThread) *const __imp_ExitThread;
|
||||||
* @noreturn
|
* @noreturn
|
||||||
*/
|
*/
|
||||||
privileged wontreturn void _Exit1(int rc) {
|
privileged wontreturn void _Exit1(int rc) {
|
||||||
|
#ifdef __x86_64__
|
||||||
char cf;
|
char cf;
|
||||||
int ax, dx, di, si;
|
int ax, dx, di, si;
|
||||||
if (!IsWindows() && !IsMetal()) {
|
if (!IsWindows() && !IsMetal()) {
|
||||||
|
@ -72,4 +73,13 @@ privileged wontreturn void _Exit1(int rc) {
|
||||||
unreachable;
|
unreachable;
|
||||||
}
|
}
|
||||||
notpossible;
|
notpossible;
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
register long r0 asm("x0") = rc;
|
||||||
|
asm volatile("mov\tx8,%1\n"
|
||||||
|
"svc\t0"
|
||||||
|
: /* no outputs */
|
||||||
|
: "i"(93), "r"(r0)
|
||||||
|
: "x8", "memory");
|
||||||
|
notpossible;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ void *_wrfsbase(void *);
|
||||||
void *_wrgsbase(void *);
|
void *_wrgsbase(void *);
|
||||||
int _have_fsgsbase(void);
|
int _have_fsgsbase(void);
|
||||||
|
|
||||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
|
||||||
#define _rdfsbase() \
|
#define _rdfsbase() \
|
||||||
({ \
|
({ \
|
||||||
void *_p; \
|
void *_p; \
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
void GetCpuidBrand(char s[13], uint32_t leaf) {
|
void GetCpuidBrand(char s[13], uint32_t leaf) {
|
||||||
int ax, cx;
|
int ax, cx;
|
||||||
|
@ -32,3 +33,5 @@ void GetCpuidBrand(char s[13], uint32_t leaf) {
|
||||||
: "rdx");
|
: "rdx");
|
||||||
s[12] = 0;
|
s[12] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
#include "libc/intrin/fsgsbase.h"
|
#include "libc/intrin/fsgsbase.h"
|
||||||
#include "libc/nexgen32e/x86feature.h"
|
#include "libc/nexgen32e/x86feature.h"
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if FSGSBASE ISA can be used.
|
* Returns true if FSGSBASE ISA can be used.
|
||||||
|
@ -61,3 +62,5 @@ privileged int _have_fsgsbase(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
#ifndef COSMOPOLITAN_LIBC_BITS_INITIALIZER_H_
|
|
||||||
#define COSMOPOLITAN_LIBC_BITS_INITIALIZER_H_
|
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
||||||
|
|
||||||
/* TODO: DELETE */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Teleports code fragment inside _init().
|
|
||||||
*/
|
|
||||||
#ifndef INITIALIZER
|
|
||||||
#define INITIALIZER(PRI, NAME, CODE) \
|
|
||||||
asm(".section .init." #PRI "." #NAME ",\"ax\",@progbits\n\t" \
|
|
||||||
"call\t" #NAME "\n\t" \
|
|
||||||
".previous"); \
|
|
||||||
textstartup optimizesize void NAME(char *rdi, const char *rsi) { \
|
|
||||||
CODE; \
|
|
||||||
asm volatile("" : /* no outputs */ : "D"(rdi), "S"(rsi)); \
|
|
||||||
}
|
|
||||||
#endif /* INITIALIZER */
|
|
||||||
|
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
||||||
#endif /* COSMOPOLITAN_LIBC_BITS_INITIALIZER_H_ */
|
|
|
@ -89,7 +89,7 @@ o/$(MODE)/libc/intrin/kprintf.greg.o: private \
|
||||||
-fpie \
|
-fpie \
|
||||||
-fwrapv \
|
-fwrapv \
|
||||||
-x-no-pg \
|
-x-no-pg \
|
||||||
-mno-fentry \
|
$(MNO_FENTRY) \
|
||||||
-ffreestanding \
|
-ffreestanding \
|
||||||
-fno-sanitize=all \
|
-fno-sanitize=all \
|
||||||
-fno-stack-protector
|
-fno-stack-protector
|
||||||
|
@ -105,7 +105,7 @@ o/$(MODE)/libc/intrin/_spinlock_debug_4.o: private \
|
||||||
OVERRIDE_CFLAGS += \
|
OVERRIDE_CFLAGS += \
|
||||||
-fwrapv \
|
-fwrapv \
|
||||||
-x-no-pg \
|
-x-no-pg \
|
||||||
-mno-fentry \
|
$(MNO_FENTRY) \
|
||||||
-ffreestanding \
|
-ffreestanding \
|
||||||
-fno-sanitize=all \
|
-fno-sanitize=all \
|
||||||
-mgeneral-regs-only \
|
-mgeneral-regs-only \
|
||||||
|
@ -186,6 +186,10 @@ o/$(MODE)/libc/intrin/memmove.o: private \
|
||||||
OVERRIDE_CFLAGS += \
|
OVERRIDE_CFLAGS += \
|
||||||
-fpie
|
-fpie
|
||||||
|
|
||||||
|
# these assembly files are safe to build on aarch64
|
||||||
|
o/$(MODE)/libc/intrin/kclocknames.o: libc/intrin/kclocknames.S
|
||||||
|
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||||
|
|
||||||
LIBC_INTRIN_LIBS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)))
|
LIBC_INTRIN_LIBS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)))
|
||||||
LIBC_INTRIN_HDRS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)_HDRS))
|
LIBC_INTRIN_HDRS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)_HDRS))
|
||||||
LIBC_INTRIN_INCS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)_INCS))
|
LIBC_INTRIN_INCS = $(foreach x,$(LIBC_INTRIN_ARTIFACTS),$($(x)_INCS))
|
||||||
|
|
|
@ -28,18 +28,18 @@
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.section .rodata,"a",@progbits
|
.section .rodata,"a",@progbits
|
||||||
.align 4
|
.balign 4
|
||||||
.underrun
|
.underrun
|
||||||
kClockNames:
|
kClockNames:
|
||||||
.e CLOCK_REALTIME,"REALTIME"
|
.e CLOCK_REALTIME,"REALTIME"
|
||||||
.e CLOCK_REALTIME_FAST,"REALTIME_FAST" # order matters
|
.e CLOCK_REALTIME_FAST,"REALTIME_FAST" // order matters
|
||||||
.e CLOCK_REALTIME_PRECISE,"REALTIME_PRECISE" # order matters
|
.e CLOCK_REALTIME_PRECISE,"REALTIME_PRECISE" // order matters
|
||||||
.e CLOCK_REALTIME_COARSE,"REALTIME_COARSE" # order matters
|
.e CLOCK_REALTIME_COARSE,"REALTIME_COARSE" // order matters
|
||||||
.e CLOCK_MONOTONIC,"MONOTONIC"
|
.e CLOCK_MONOTONIC,"MONOTONIC"
|
||||||
.e CLOCK_MONOTONIC_FAST,"MONOTONIC_FAST" # order matters
|
.e CLOCK_MONOTONIC_FAST,"MONOTONIC_FAST" // order matters
|
||||||
.e CLOCK_MONOTONIC_RAW,"MONOTONIC_RAW" # order matters
|
.e CLOCK_MONOTONIC_RAW,"MONOTONIC_RAW" // order matters
|
||||||
.e CLOCK_MONOTONIC_PRECISE,"MONOTONIC_PRECISE" # order matters
|
.e CLOCK_MONOTONIC_PRECISE,"MONOTONIC_PRECISE" // order matters
|
||||||
.e CLOCK_MONOTONIC_COARSE,"MONOTONIC_COARSE" # order matters
|
.e CLOCK_MONOTONIC_COARSE,"MONOTONIC_COARSE" // order matters
|
||||||
.e CLOCK_PROCESS_CPUTIME_ID,"PROCESS_CPUTIME_ID"
|
.e CLOCK_PROCESS_CPUTIME_ID,"PROCESS_CPUTIME_ID"
|
||||||
.e CLOCK_THREAD_CPUTIME_ID,"THREAD_CPUTIME_ID"
|
.e CLOCK_THREAD_CPUTIME_ID,"THREAD_CPUTIME_ID"
|
||||||
.e CLOCK_TAI,"TAI"
|
.e CLOCK_TAI,"TAI"
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
// @see libc/sysv/dos2errno.sh for the numbers
|
// @see libc/sysv/dos2errno.sh for the numbers
|
||||||
|
|
||||||
.section .sort.rodata.dos2errno.1,"a",@progbits
|
.section .sort.rodata.dos2errno.1,"a",@progbits
|
||||||
.align 8
|
.balign 8
|
||||||
kDos2Errno:/*
|
kDos2Errno:/*
|
||||||
...decentralized content...
|
...decentralized content...
|
||||||
*/.endobj kDos2Errno,globl
|
*/.endobj kDos2Errno,globl
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata
|
||||||
.align 4
|
.balign 4
|
||||||
.underrun
|
.underrun
|
||||||
kErrnoDocs:
|
kErrnoDocs:
|
||||||
.e EINVAL,"Invalid argument"
|
.e EINVAL,"Invalid argument"
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata
|
||||||
.align 4
|
.balign 4
|
||||||
.underrun
|
.underrun
|
||||||
kErrnoNames:
|
kErrnoNames:
|
||||||
.e EINVAL
|
.e EINVAL
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.section .rodata,"a",@progbits
|
.section .rodata,"a",@progbits
|
||||||
.align 4
|
.balign 4
|
||||||
.underrun
|
.underrun
|
||||||
kFcntlCmds:
|
kFcntlCmds:
|
||||||
.e F_GETFD,"GETFD"
|
.e F_GETFD,"GETFD"
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata
|
||||||
.align 4
|
.balign 4
|
||||||
.underrun
|
.underrun
|
||||||
kIpOptnames:
|
kIpOptnames:
|
||||||
.e IP_TOS,"TOS" # int
|
.e IP_TOS,"TOS" # int
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata
|
||||||
.align 4
|
.balign 4
|
||||||
.underrun
|
.underrun
|
||||||
kOpenFlags:
|
kOpenFlags:
|
||||||
.e O_RDWR,"RDWR" // order matters
|
.e O_RDWR,"RDWR" // order matters
|
||||||
|
|
|
@ -165,6 +165,7 @@ privileged bool kisdangerous(const void *p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
privileged static void klog(const char *b, size_t n) {
|
privileged static void klog(const char *b, size_t n) {
|
||||||
|
#ifdef __x86_64__
|
||||||
int e;
|
int e;
|
||||||
bool cf;
|
bool cf;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -196,6 +197,17 @@ privileged static void klog(const char *b, size_t n) {
|
||||||
: "0"(__NR_write), "1"(2), "2"(b), "3"(n)
|
: "0"(__NR_write), "1"(2), "2"(b), "3"(n)
|
||||||
: "rcx", "r8", "r9", "r10", "r11", "memory", "cc");
|
: "rcx", "r8", "r9", "r10", "r11", "memory", "cc");
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
register long r0 asm("x0") = (long)2;
|
||||||
|
register long r1 asm("x1") = (long)b;
|
||||||
|
register long r2 asm("x2") = (long)n;
|
||||||
|
register long res_x0 asm("x0");
|
||||||
|
asm volatile("mov\tx8,%1\n"
|
||||||
|
"svc\t0"
|
||||||
|
: "=r"(res_x0)
|
||||||
|
: "i"(64), "r"(r0), "r"(r1), "r"(r2)
|
||||||
|
: "x8", "memory");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
privileged static size_t kformat(char *b, size_t n, const char *fmt,
|
privileged static size_t kformat(char *b, size_t n, const char *fmt,
|
||||||
|
@ -798,7 +810,6 @@ privileged size_t kvsnprintf(char *b, size_t n, const char *fmt, va_list v) {
|
||||||
privileged void kvprintf(const char *fmt, va_list v) {
|
privileged void kvprintf(const char *fmt, va_list v) {
|
||||||
size_t n;
|
size_t n;
|
||||||
char b[4000];
|
char b[4000];
|
||||||
if (!v) return;
|
|
||||||
n = kformat(b, sizeof(b), fmt, v);
|
n = kformat(b, sizeof(b), fmt, v);
|
||||||
klog(b, MIN(n, sizeof(b) - 1));
|
klog(b, MIN(n, sizeof(b) - 1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata
|
||||||
.align 4
|
.balign 4
|
||||||
.underrun
|
.underrun
|
||||||
kRlimitNames:
|
kRlimitNames:
|
||||||
.e RLIMIT_AS,"AS"
|
.e RLIMIT_AS,"AS"
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata
|
||||||
.align 4
|
.balign 4
|
||||||
.underrun
|
.underrun
|
||||||
kSignalNames:
|
kSignalNames:
|
||||||
.e SIGHUP,"SIGHUP"
|
.e SIGHUP,"SIGHUP"
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata
|
||||||
.align 4
|
.balign 4
|
||||||
.underrun
|
.underrun
|
||||||
kSockOptnames:
|
kSockOptnames:
|
||||||
.e SO_DEBUG,"DEBUG" # bool32
|
.e SO_DEBUG,"DEBUG" # bool32
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.section .rodata
|
.section .rodata
|
||||||
.align 4
|
.balign 4
|
||||||
.underrun
|
.underrun
|
||||||
kTcpOptnames:
|
kTcpOptnames:
|
||||||
.e TCP_NODELAY,"NODELAY" # bool32
|
.e TCP_NODELAY,"NODELAY" # bool32
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
.globl _leaky_start,_leaky_end
|
.globl _leaky_start,_leaky_end
|
||||||
.hidden _leaky_start,_leaky_end
|
.hidden _leaky_start,_leaky_end
|
||||||
.byte 0
|
.byte 0
|
||||||
.align __SIZEOF_POINTER__
|
.balign __SIZEOF_POINTER__
|
||||||
.underrun
|
.underrun
|
||||||
_leaky_start:
|
_leaky_start:
|
||||||
.previous/*
|
.previous/*
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
|
/* TODO(jart): DELETE */
|
||||||
|
|
||||||
intptr_t lockxchg(void *, void *, size_t);
|
intptr_t lockxchg(void *, void *, size_t);
|
||||||
|
|
||||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
|
||||||
/**
|
/**
|
||||||
* Exchanges *MEMORY into *LOCALVAR w/ one operation.
|
* Exchanges *MEMORY into *LOCALVAR w/ one operation.
|
||||||
*
|
*
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
|
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
static dontinline antiquity int memcmp_sse(const unsigned char *p,
|
static dontinline antiquity int memcmp_sse(const unsigned char *p,
|
||||||
const unsigned char *q, size_t n) {
|
const unsigned char *q, size_t n) {
|
||||||
unsigned u;
|
unsigned u;
|
||||||
|
@ -99,6 +101,8 @@ microarchitecture("avx") static int memcmp_avx(const unsigned char *p,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares memory byte by byte.
|
* Compares memory byte by byte.
|
||||||
*
|
*
|
||||||
|
@ -136,6 +140,7 @@ int memcmp(const void *a, const void *b, size_t n) {
|
||||||
const unsigned char *p, *q;
|
const unsigned char *p, *q;
|
||||||
if ((p = a) == (q = b) || !n) return 0;
|
if ((p = a) == (q = b) || !n) return 0;
|
||||||
if ((c = *p - *q)) return c;
|
if ((c = *p - *q)) return c;
|
||||||
|
#ifdef __x86_64__
|
||||||
if (!IsTiny()) {
|
if (!IsTiny()) {
|
||||||
if (n <= 16) {
|
if (n <= 16) {
|
||||||
if (n >= 8) {
|
if (n >= 8) {
|
||||||
|
@ -187,6 +192,7 @@ int memcmp(const void *a, const void *b, size_t n) {
|
||||||
return memcmp_sse(p, q, n);
|
return memcmp_sse(p, q, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif /* __x86_64__ */
|
||||||
for (; n; ++p, ++q, --n) {
|
for (; n; ++p, ++q, --n) {
|
||||||
if ((c = *p - *q)) {
|
if ((c = *p - *q)) {
|
||||||
return c;
|
return c;
|
||||||
|
|
|
@ -93,6 +93,8 @@ void *memmove(void *dst, const void *src, size_t n) {
|
||||||
xmm_t v, w, x, y, V, W, X, Y, wut;
|
xmm_t v, w, x, y, V, W, X, Y, wut;
|
||||||
d = dst;
|
d = dst;
|
||||||
s = src;
|
s = src;
|
||||||
|
|
||||||
|
#ifdef __x86__
|
||||||
if (IsTiny()) {
|
if (IsTiny()) {
|
||||||
uint16_t w1, w2;
|
uint16_t w1, w2;
|
||||||
uint32_t l1, l2;
|
uint32_t l1, l2;
|
||||||
|
@ -133,6 +135,8 @@ void *memmove(void *dst, const void *src, size_t n) {
|
||||||
}
|
}
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 0:
|
case 0:
|
||||||
return d;
|
return d;
|
||||||
|
@ -208,6 +212,8 @@ void *memmove(void *dst, const void *src, size_t n) {
|
||||||
return d;
|
return d;
|
||||||
default:
|
default:
|
||||||
if (d == s) return d;
|
if (d == s) return d;
|
||||||
|
|
||||||
|
#ifdef __x86__
|
||||||
if (n < kHalfCache3 || !kHalfCache3) {
|
if (n < kHalfCache3 || !kHalfCache3) {
|
||||||
if (d > s) {
|
if (d > s) {
|
||||||
if (IsAsan() || n < 900 || !X86_HAVE(ERMS)) {
|
if (IsAsan() || n < 900 || !X86_HAVE(ERMS)) {
|
||||||
|
@ -280,6 +286,31 @@ void *memmove(void *dst, const void *src, size_t n) {
|
||||||
}
|
}
|
||||||
asm("sfence");
|
asm("sfence");
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
if (d > s) {
|
||||||
|
do {
|
||||||
|
n -= 32;
|
||||||
|
v = *(const xmm_t *)(s + n);
|
||||||
|
w = *(const xmm_t *)(s + n + 16);
|
||||||
|
*(xmm_t *)(d + n) = v;
|
||||||
|
*(xmm_t *)(d + n + 16) = w;
|
||||||
|
} while (n >= 32);
|
||||||
|
} else {
|
||||||
|
i = 0;
|
||||||
|
do {
|
||||||
|
v = *(const xmm_t *)(s + i);
|
||||||
|
w = *(const xmm_t *)(s + i + 16);
|
||||||
|
*(xmm_t *)(d + i) = v;
|
||||||
|
*(xmm_t *)(d + i + 16) = w;
|
||||||
|
} while ((i += 32) + 32 <= n);
|
||||||
|
d += i;
|
||||||
|
s += i;
|
||||||
|
n -= i;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
if (n) {
|
if (n) {
|
||||||
if (n >= 16) {
|
if (n >= 16) {
|
||||||
v = *(const xmm_t *)s;
|
v = *(const xmm_t *)s;
|
||||||
|
@ -305,6 +336,7 @@ void *memmove(void *dst, const void *src, size_t n) {
|
||||||
*d = *s;
|
*d = *s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ static dontinline antiquity void *memset_sse(char *p, char c, size_t n) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
microarchitecture("avx") static void *memset_avx(char *p, char c, size_t n) {
|
microarchitecture("avx") static void *memset_avx(char *p, char c, size_t n) {
|
||||||
char *t;
|
char *t;
|
||||||
xmm_t v = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
|
xmm_t v = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
|
||||||
|
@ -76,6 +77,7 @@ microarchitecture("avx") static void *memset_avx(char *p, char c, size_t n) {
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets memory.
|
* Sets memory.
|
||||||
|
@ -155,11 +157,13 @@ void *memset(void *p, int c, size_t n) {
|
||||||
} while (n);
|
} while (n);
|
||||||
}
|
}
|
||||||
return b;
|
return b;
|
||||||
|
#ifdef __x86_64__
|
||||||
} else if (IsTiny()) {
|
} else if (IsTiny()) {
|
||||||
asm("rep stosb" : "+D"(b), "+c"(n), "=m"(*(char(*)[n])b) : "0"(p), "a"(c));
|
asm("rep stosb" : "+D"(b), "+c"(n), "=m"(*(char(*)[n])b) : "0"(p), "a"(c));
|
||||||
return p;
|
return p;
|
||||||
} else if (X86_HAVE(AVX)) {
|
} else if (X86_HAVE(AVX)) {
|
||||||
return memset_avx(b, c, n);
|
return memset_avx(b, c, n);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
return memset_sse(b, c, n);
|
return memset_sse(b, c, n);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "libc/runtime/metalprintf.internal.h"
|
#include "libc/runtime/metalprintf.internal.h"
|
||||||
#include "libc/runtime/pc.internal.h"
|
#include "libc/runtime/pc.internal.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
#define INVERT(x) (BANE + PHYSICAL(x))
|
#define INVERT(x) (BANE + PHYSICAL(x))
|
||||||
#define NOPAGE ((uint64_t)-1)
|
#define NOPAGE ((uint64_t)-1)
|
||||||
|
@ -313,3 +314,5 @@ noasan textreal void __reclaim_boot_pages(struct mman *mm, uint64_t skip_start,
|
||||||
}
|
}
|
||||||
mm->frp = p;
|
mm->frp = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
|
@ -6,7 +6,7 @@ COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
void mpsadbw(uint16_t[8], const uint8_t[16], const uint8_t[16], uint8_t);
|
void mpsadbw(uint16_t[8], const uint8_t[16], const uint8_t[16], uint8_t);
|
||||||
|
|
||||||
#ifndef __STRICT_ANSI__
|
#if defined(__x86_64__) && !defined(__STRICT_ANSI__)
|
||||||
__intrin_xmm_t __mpsadbws(__intrin_xmm_t, __intrin_xmm_t);
|
__intrin_xmm_t __mpsadbws(__intrin_xmm_t, __intrin_xmm_t);
|
||||||
#define mpsadbw(C, B, A, I) \
|
#define mpsadbw(C, B, A, I) \
|
||||||
do { \
|
do { \
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
//
|
//
|
||||||
// @note needs sse4 cf. core c. 2006 cf. bulldozer c. 2011
|
// @note needs sse4 cf. core c. 2006 cf. bulldozer c. 2011
|
||||||
// @see mpsadbw()
|
// @see mpsadbw()
|
||||||
.align 8
|
.balign 8
|
||||||
__mpsadbws:
|
__mpsadbws:
|
||||||
i = 0
|
i = 0
|
||||||
.rept 8
|
.rept 8
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
.privileged
|
||||||
.alignfunc
|
.balignfunc
|
||||||
|
|
||||||
// Returns 𝑥*𝑦, aborting on overflow.
|
// Returns 𝑥*𝑦, aborting on overflow.
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
.privileged
|
||||||
.alignfunc
|
.balignfunc
|
||||||
|
|
||||||
// Returns 𝑥*𝑦, aborting on overflow.
|
// Returns 𝑥*𝑦, aborting on overflow.
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
.privileged
|
||||||
.alignfunc
|
.balignfunc
|
||||||
|
|
||||||
// Returns 𝑥*𝑦, aborting on overflow.
|
// Returns 𝑥*𝑦, aborting on overflow.
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
.privileged
|
||||||
.alignfunc
|
.balignfunc
|
||||||
|
|
||||||
// Returns -𝑥, aborting on overflow (two's complement bane).
|
// Returns -𝑥, aborting on overflow (two's complement bane).
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
.privileged
|
||||||
.alignfunc
|
.balignfunc
|
||||||
|
|
||||||
// Returns -𝑥, aborting on overflow (two's complement bane).
|
// Returns -𝑥, aborting on overflow (two's complement bane).
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
.privileged
|
||||||
.alignfunc
|
.balignfunc
|
||||||
|
|
||||||
// Returns -𝑥, aborting on overflow.
|
// Returns -𝑥, aborting on overflow.
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#ifndef COSMOPOLITAN_LIBC_INTRIN_NOPL_H_
|
#ifndef COSMOPOLITAN_LIBC_INTRIN_NOPL_H_
|
||||||
#define COSMOPOLITAN_LIBC_INTRIN_NOPL_H_
|
#define COSMOPOLITAN_LIBC_INTRIN_NOPL_H_
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0) && defined(__GNUC__) && \
|
#if !(__ASSEMBLER__ + __LINKER__ + 0) && defined(__x86_64__) && \
|
||||||
!defined(__llvm__) && !defined(__chibicc__) && !defined(__STRICT_ANSI__)
|
defined(__GNUC__) && !defined(__llvm__) && !defined(__chibicc__) && \
|
||||||
|
!defined(__STRICT_ANSI__)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileoverview Turns CALLs into NOPs that are fixupable at runtime.
|
* @fileoverview Turns CALLs into NOPs that are fixupable at runtime.
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/nt/struct/teb.h"
|
#include "libc/nt/struct/teb.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns New Technology version, e.g.
|
* Returns New Technology version, e.g.
|
||||||
|
@ -29,3 +30,5 @@
|
||||||
textwindows noasan int NtGetVersion(void) {
|
textwindows noasan int NtGetVersion(void) {
|
||||||
return (NtGetPeb()->OSMajorVersion & 0xff) << 8 | NtGetPeb()->OSMinorVersion;
|
return (NtGetPeb()->OSMajorVersion & 0xff) << 8 | NtGetPeb()->OSMinorVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
|
@ -7,7 +7,7 @@ COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
void palignr(void *, const void *, const void *, unsigned long);
|
void palignr(void *, const void *, const void *, unsigned long);
|
||||||
|
|
||||||
#if !defined(__STRICT_ANSI__) && !defined(__chibicc__)
|
#if !defined(__STRICT_ANSI__) && !defined(__chibicc__) && defined(__x86_64__)
|
||||||
__intrin_xmm_t __palignrs(__intrin_xmm_t, __intrin_xmm_t);
|
__intrin_xmm_t __palignrs(__intrin_xmm_t, __intrin_xmm_t);
|
||||||
#define palignr(C, B, A, I) \
|
#define palignr(C, B, A, I) \
|
||||||
do { \
|
do { \
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
//
|
//
|
||||||
// @note needs ssse3 cf. prescott c. 2004 cf. bulldozer c. 2011
|
// @note needs ssse3 cf. prescott c. 2004 cf. bulldozer c. 2011
|
||||||
// @see palignr()
|
// @see palignr()
|
||||||
.align 8
|
.balign 8
|
||||||
__palignrs:
|
__palignrs:
|
||||||
palignr $0,%xmm1,%xmm0
|
palignr $0,%xmm1,%xmm0
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -7,7 +7,7 @@ COSMOPOLITAN_C_START_
|
||||||
size_t _countbits(const void *, size_t);
|
size_t _countbits(const void *, size_t);
|
||||||
unsigned long popcnt(unsigned long) pureconst;
|
unsigned long popcnt(unsigned long) pureconst;
|
||||||
|
|
||||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
|
||||||
#define popcnt(X) \
|
#define popcnt(X) \
|
||||||
(__builtin_constant_p(X) ? __builtin_popcountll(X) : ({ \
|
(__builtin_constant_p(X) ? __builtin_popcountll(X) : ({ \
|
||||||
unsigned long PoP = (X); \
|
unsigned long PoP = (X); \
|
||||||
|
@ -18,6 +18,8 @@ unsigned long popcnt(unsigned long) pureconst;
|
||||||
} \
|
} \
|
||||||
PoP; \
|
PoP; \
|
||||||
}))
|
}))
|
||||||
|
#else
|
||||||
|
#define popcnt(x) __builtin_popcountll(x)
|
||||||
#endif /* GNUC && !ANSI */
|
#endif /* GNUC && !ANSI */
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
|
|
|
@ -6,7 +6,7 @@ COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
void pslldq(uint8_t[16], const uint8_t[16], unsigned long);
|
void pslldq(uint8_t[16], const uint8_t[16], unsigned long);
|
||||||
|
|
||||||
#ifndef __STRICT_ANSI__
|
#if defined(__x86_64__) && !defined(__STRICT_ANSI__)
|
||||||
__intrin_xmm_t __pslldqs(__intrin_xmm_t);
|
__intrin_xmm_t __pslldqs(__intrin_xmm_t);
|
||||||
#define pslldq(B, A, I) \
|
#define pslldq(B, A, I) \
|
||||||
do { \
|
do { \
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
|
|
||||||
// Jump table for pslldq() with non-constexpr immediate parameter.
|
// Jump table for pslldq() with non-constexpr immediate parameter.
|
||||||
.align 8
|
.balign 8
|
||||||
__pslldqs:
|
__pslldqs:
|
||||||
pslldq $0,%xmm0
|
pslldq $0,%xmm0
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -6,7 +6,7 @@ COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
void psrldq(uint8_t[16], const uint8_t[16], unsigned long);
|
void psrldq(uint8_t[16], const uint8_t[16], unsigned long);
|
||||||
|
|
||||||
#ifndef __STRICT_ANSI__
|
#if defined(__x86_64__) && !defined(__STRICT_ANSI__)
|
||||||
__intrin_xmm_t __psrldqs(__intrin_xmm_t);
|
__intrin_xmm_t __psrldqs(__intrin_xmm_t);
|
||||||
#define psrldq(B, A, I) \
|
#define psrldq(B, A, I) \
|
||||||
do { \
|
do { \
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
|
|
||||||
// Jump table for psrldq() with non-constexpr immediate parameter.
|
// Jump table for psrldq() with non-constexpr immediate parameter.
|
||||||
.align 8
|
.balign 8
|
||||||
__psrldqs:
|
__psrldqs:
|
||||||
psrldq $0,%xmm0
|
psrldq $0,%xmm0
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
|
|
||||||
#if !defined(__GNUC__) || defined(__STRICT_ANSI__)
|
#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__)
|
||||||
#define pushpop(x) (x)
|
#define pushpop(x) (x)
|
||||||
#else
|
#else
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
})
|
})
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(__GNUC__) || defined(__STRICT_ANSI__)
|
#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__)
|
||||||
#define pushmov(d, x) (*(d) = (x))
|
#define pushmov(d, x) (*(d) = (x))
|
||||||
#else
|
#else
|
||||||
#define pushmov(d, x) \
|
#define pushmov(d, x) \
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/intrin/fsgsbase.h"
|
#include "libc/intrin/fsgsbase.h"
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads `%fs` base address.
|
* Reads `%fs` base address.
|
||||||
|
@ -26,3 +27,5 @@
|
||||||
void *(_rdfsbase)(void) {
|
void *(_rdfsbase)(void) {
|
||||||
return _rdfsbase();
|
return _rdfsbase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/intrin/fsgsbase.h"
|
#include "libc/intrin/fsgsbase.h"
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads `%gs` base address.
|
* Reads `%gs` base address.
|
||||||
|
@ -26,3 +27,5 @@
|
||||||
void *(_rdgsbase)(void) {
|
void *(_rdgsbase)(void) {
|
||||||
return _rdgsbase();
|
return _rdgsbase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
|
@ -18,13 +18,13 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
|
|
||||||
.align 8
|
.balign 8
|
||||||
shufpdjt:
|
shufpdjt:
|
||||||
i=0
|
i=0
|
||||||
.rept 256
|
.rept 256
|
||||||
shufpd $i,%xmm1,%xmm0
|
shufpd $i,%xmm1,%xmm0
|
||||||
ret
|
ret
|
||||||
.align 8
|
.balign 8
|
||||||
i=i+1
|
i=i+1
|
||||||
.endr
|
.endr
|
||||||
.endfn shufpdjt,globl
|
.endfn shufpdjt,globl
|
||||||
|
|
|
@ -18,13 +18,13 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
|
|
||||||
.align 8
|
.balign 8
|
||||||
shufpsjt:
|
shufpsjt:
|
||||||
i=0
|
i=0
|
||||||
.rept 256
|
.rept 256
|
||||||
shufps $i,%xmm1,%xmm0
|
shufps $i,%xmm1,%xmm0
|
||||||
ret
|
ret
|
||||||
.align 8
|
.balign 8
|
||||||
i=i+1
|
i=i+1
|
||||||
.endr
|
.endr
|
||||||
.endfn shufpsjt,globl
|
.endfn shufpsjt,globl
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
typedef char xmm_u __attribute__((__vector_size__(16), __aligned__(1)));
|
typedef char xmm_u __attribute__((__vector_size__(16), __aligned__(1)));
|
||||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
static inline noasan size_t stpcpy_sse2(char *d, const char *s, size_t i) {
|
static inline noasan size_t stpcpy_sse2(char *d, const char *s, size_t i) {
|
||||||
xmm_t v, z = {0};
|
xmm_t v, z = {0};
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -34,6 +35,7 @@ static inline noasan size_t stpcpy_sse2(char *d, const char *s, size_t i) {
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies bytes from 𝑠 to 𝑑 until a NUL is encountered.
|
* Copies bytes from 𝑠 to 𝑑 until a NUL is encountered.
|
||||||
|
@ -45,13 +47,15 @@ static inline noasan size_t stpcpy_sse2(char *d, const char *s, size_t i) {
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
*/
|
*/
|
||||||
char *stpcpy(char *d, const char *s) {
|
char *stpcpy(char *d, const char *s) {
|
||||||
size_t i;
|
size_t i = 0;
|
||||||
for (i = 0; (uintptr_t)(s + i) & 15; ++i) {
|
#ifdef __x86_64__
|
||||||
|
for (; (uintptr_t)(s + i) & 15; ++i) {
|
||||||
if (!(d[i] = s[i])) {
|
if (!(d[i] = s[i])) {
|
||||||
return d + i;
|
return d + i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i = stpcpy_sse2(d, s, i);
|
i = stpcpy_sse2(d, s, i);
|
||||||
|
#endif
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (!(d[i] = s[i])) {
|
if (!(d[i] = s[i])) {
|
||||||
return d + i;
|
return d + i;
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
typedef char xmm_u __attribute__((__vector_size__(16), __aligned__(1)));
|
typedef char xmm_u __attribute__((__vector_size__(16), __aligned__(1)));
|
||||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
static inline noasan size_t strcpy_sse2(char *d, const char *s, size_t i) {
|
static inline noasan size_t strcpy_sse2(char *d, const char *s, size_t i) {
|
||||||
xmm_t v, z = {0};
|
xmm_t v, z = {0};
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -34,6 +35,7 @@ static inline noasan size_t strcpy_sse2(char *d, const char *s, size_t i) {
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies bytes from 𝑠 to 𝑑 until a NUL is encountered.
|
* Copies bytes from 𝑠 to 𝑑 until a NUL is encountered.
|
||||||
|
@ -45,13 +47,15 @@ static inline noasan size_t strcpy_sse2(char *d, const char *s, size_t i) {
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
*/
|
*/
|
||||||
char *strcpy(char *d, const char *s) {
|
char *strcpy(char *d, const char *s) {
|
||||||
size_t i;
|
size_t i = 0;
|
||||||
for (i = 0; (uintptr_t)(s + i) & 15; ++i) {
|
#ifdef __x86_64__
|
||||||
|
for (; (uintptr_t)(s + i) & 15; ++i) {
|
||||||
if (!(d[i] = s[i])) {
|
if (!(d[i] = s[i])) {
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i = strcpy_sse2(d, s, i);
|
i = strcpy_sse2(d, s, i);
|
||||||
|
#endif
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (!(d[i] = s[i])) {
|
if (!(d[i] = s[i])) {
|
||||||
return d;
|
return d;
|
||||||
|
|
|
@ -30,6 +30,7 @@ typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
*/
|
*/
|
||||||
noasan size_t strlen(const char *s) {
|
noasan size_t strlen(const char *s) {
|
||||||
|
#ifdef __x86_64__
|
||||||
size_t n;
|
size_t n;
|
||||||
xmm_t z = {0};
|
xmm_t z = {0};
|
||||||
unsigned m, k = (uintptr_t)s & 15;
|
unsigned m, k = (uintptr_t)s & 15;
|
||||||
|
@ -39,4 +40,9 @@ noasan size_t strlen(const char *s) {
|
||||||
while (!m) m = __builtin_ia32_pmovmskb128(*++p == z);
|
while (!m) m = __builtin_ia32_pmovmskb128(*++p == z);
|
||||||
n = (const char *)p + __builtin_ctzl(m) - s;
|
n = (const char *)p + __builtin_ctzl(m) - s;
|
||||||
return n;
|
return n;
|
||||||
|
#else
|
||||||
|
size_t n = 0;
|
||||||
|
while (*s++) ++n;
|
||||||
|
return n;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
.privileged
|
||||||
.alignfunc
|
.balignfunc
|
||||||
|
|
||||||
// Returns 𝑥-𝑦, aborting on overflow.
|
// Returns 𝑥-𝑦, aborting on overflow.
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
.privileged
|
||||||
.alignfunc
|
.balignfunc
|
||||||
|
|
||||||
// Returns 𝑥-𝑦, aborting on overflow.
|
// Returns 𝑥-𝑦, aborting on overflow.
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
.privileged
|
.privileged
|
||||||
.alignfunc
|
.balignfunc
|
||||||
|
|
||||||
// Returns 𝑥-𝑦, aborting on overflow.
|
// Returns 𝑥-𝑦, aborting on overflow.
|
||||||
//
|
//
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
__msabi extern typeof(GetCurrentThreadId) *const __imp_GetCurrentThreadId;
|
__msabi extern typeof(GetCurrentThreadId) *const __imp_GetCurrentThreadId;
|
||||||
|
|
||||||
privileged int sys_gettid(void) {
|
privileged int sys_gettid(void) {
|
||||||
|
#ifdef __x86_64__
|
||||||
int tid;
|
int tid;
|
||||||
int64_t wut;
|
int64_t wut;
|
||||||
if (IsWindows()) {
|
if (IsWindows()) {
|
||||||
|
@ -61,4 +62,13 @@ privileged int sys_gettid(void) {
|
||||||
tid = __pid;
|
tid = __pid;
|
||||||
}
|
}
|
||||||
return tid;
|
return tid;
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
register long res_x0 asm("x0");
|
||||||
|
asm volatile("mov\tx8,%1\n"
|
||||||
|
"svc\t0"
|
||||||
|
: "=r"(res_x0)
|
||||||
|
: "i"(178)
|
||||||
|
: "x8", "memory");
|
||||||
|
return res_x0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ __syscall__:
|
||||||
.endfn __syscall__,globl,hidden
|
.endfn __syscall__,globl,hidden
|
||||||
|
|
||||||
.bss
|
.bss
|
||||||
.align 8
|
.balign 8
|
||||||
.Lrcx: .quad 0 # clobbered by syscall
|
.Lrcx: .quad 0 # clobbered by syscall
|
||||||
.Lrdi: .quad 0 # just in case
|
.Lrdi: .quad 0 # just in case
|
||||||
.Lrsi: .quad 0 # just in case
|
.Lrsi: .quad 0 # just in case
|
||||||
|
|
|
@ -45,7 +45,7 @@ _tpenc: .leafprologue
|
||||||
.endfn _tpenc,globl
|
.endfn _tpenc,globl
|
||||||
|
|
||||||
.rodata
|
.rodata
|
||||||
.align 4
|
.balign 4
|
||||||
.underrun
|
.underrun
|
||||||
kTpenc: .rept 4 # MSB≤10 (0x7FF)
|
kTpenc: .rept 4 # MSB≤10 (0x7FF)
|
||||||
.byte 1,0b11000000 # len,mark
|
.byte 1,0b11000000 # len,mark
|
||||||
|
|
|
@ -4,10 +4,11 @@
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
#ifndef __STRICT_ANSI__
|
#ifndef __STRICT_ANSI__
|
||||||
|
|
||||||
#define _weaken(symbol) \
|
#define _weaken(symbol) \
|
||||||
({ \
|
({ \
|
||||||
asm(".weak\t" #symbol); \
|
typeof(&symbol) _p = &symbol; \
|
||||||
&symbol; \
|
asm(".weak\t" #symbol : "+r"(_p)); \
|
||||||
|
_p; \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define _strongaddr(symbolstr) \
|
#define _strongaddr(symbolstr) \
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/intrin/fsgsbase.h"
|
#include "libc/intrin/fsgsbase.h"
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes `%fs` base address.
|
* Changes `%fs` base address.
|
||||||
|
@ -26,3 +27,5 @@
|
||||||
void *(_wrfsbase)(void *p) {
|
void *(_wrfsbase)(void *p) {
|
||||||
return _wrfsbase(p);
|
return _wrfsbase(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __x86_64__ */
|
||||||
|
|
|
@ -67,10 +67,10 @@ noinstrument noasan int PrintBacktraceUsingSymbols(int fd,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
addr = frame->addr;
|
addr = frame->addr;
|
||||||
if (addr == _weakaddr("__gc")) {
|
if (addr == (intptr_t)_weaken(__gc)) {
|
||||||
do {
|
do {
|
||||||
--gi;
|
--gi;
|
||||||
} while ((addr = garbage->p[gi].ret) == _weakaddr("__gc"));
|
} while ((addr = garbage->p[gi].ret) == (intptr_t)_weaken(__gc));
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* we subtract one to handle the case of noreturn functions with a
|
* we subtract one to handle the case of noreturn functions with a
|
||||||
|
|
|
@ -21,14 +21,14 @@
|
||||||
.yoink countbranch_report
|
.yoink countbranch_report
|
||||||
|
|
||||||
.section .sort.data.countbranch.1,"a",@progbits
|
.section .sort.data.countbranch.1,"a",@progbits
|
||||||
.align 8
|
.balign 8
|
||||||
.underrun
|
.underrun
|
||||||
.globl countbranch_data
|
.globl countbranch_data
|
||||||
countbranch_data:
|
countbranch_data:
|
||||||
.previous
|
.previous
|
||||||
|
|
||||||
.section .sort.data.countbranch.3,"a",@progbits
|
.section .sort.data.countbranch.3,"a",@progbits
|
||||||
.align 8
|
.balign 8
|
||||||
.rept 5
|
.rept 5
|
||||||
.quad -1
|
.quad -1
|
||||||
.endr
|
.endr
|
||||||
|
|
|
@ -22,14 +22,14 @@
|
||||||
.yoink countexpr_report
|
.yoink countexpr_report
|
||||||
|
|
||||||
.section .sort.data.countexpr.1,"a",@progbits
|
.section .sort.data.countexpr.1,"a",@progbits
|
||||||
.align 8
|
.balign 8
|
||||||
.globl countexpr_data
|
.globl countexpr_data
|
||||||
.underrun
|
.underrun
|
||||||
countexpr_data:
|
countexpr_data:
|
||||||
.previous
|
.previous
|
||||||
|
|
||||||
.section .sort.data.countexpr.3,"a",@progbits
|
.section .sort.data.countexpr.3,"a",@progbits
|
||||||
.align 8
|
.balign 8
|
||||||
.quad 0
|
.quad 0
|
||||||
.overrun
|
.overrun
|
||||||
.previous
|
.previous
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef COSMOPOLITAN_LIBC_LOG_GDB_H_
|
#ifndef COSMOPOLITAN_LIBC_LOG_GDB_H_
|
||||||
#define COSMOPOLITAN_LIBC_LOG_GDB_H_
|
#define COSMOPOLITAN_LIBC_LOG_GDB_H_
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
|
#include "libc/calls/struct/rusage.h"
|
||||||
#include "libc/calls/wait4.h"
|
#include "libc/calls/wait4.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/sysv/consts/nr.h"
|
#include "libc/sysv/consts/nr.h"
|
||||||
|
@ -41,6 +42,7 @@ int AttachDebugger(intptr_t);
|
||||||
Pid; \
|
Pid; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
#define __inline_wait4(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE) \
|
#define __inline_wait4(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE) \
|
||||||
({ \
|
({ \
|
||||||
int64_t WaAx; \
|
int64_t WaAx; \
|
||||||
|
@ -56,6 +58,9 @@ int AttachDebugger(intptr_t);
|
||||||
} \
|
} \
|
||||||
WaAx; \
|
WaAx; \
|
||||||
})
|
})
|
||||||
|
#else
|
||||||
|
#define __inline_wait4 wait4
|
||||||
|
#endif
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
|
|
|
@ -17,6 +17,15 @@ forceinline long __sysv_exit(long rc) {
|
||||||
: "=a"(ax)
|
: "=a"(ax)
|
||||||
: "0"(__NR_exit_group), "D"(rc)
|
: "0"(__NR_exit_group), "D"(rc)
|
||||||
: "memory", "cc");
|
: "memory", "cc");
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
register long r0 asm("x0") = rc;
|
||||||
|
register long res_x0 asm("x0");
|
||||||
|
asm volatile("mov\tx8,%1\n"
|
||||||
|
"svc\t0"
|
||||||
|
: "=r"(res_x0)
|
||||||
|
: "i"(94), "r"(r0)
|
||||||
|
: "x8", "memory");
|
||||||
|
ax = res_x0;
|
||||||
#else
|
#else
|
||||||
ax = syscall(__NR_exit_group, rc);
|
ax = syscall(__NR_exit_group, rc);
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,6 +39,15 @@ forceinline int __sysv_close(long fd) {
|
||||||
: "=a"(ax)
|
: "=a"(ax)
|
||||||
: "0"(__NR_close), "D"(fd)
|
: "0"(__NR_close), "D"(fd)
|
||||||
: "rdx", "memory", "cc");
|
: "rdx", "memory", "cc");
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
register long r0 asm("x0") = fd;
|
||||||
|
register long res_x0 asm("x0");
|
||||||
|
asm volatile("mov\tx8,%1\n"
|
||||||
|
"svc\t0"
|
||||||
|
: "=r"(res_x0)
|
||||||
|
: "i"(57), "r"(r0)
|
||||||
|
: "x8", "memory");
|
||||||
|
ax = res_x0;
|
||||||
#else
|
#else
|
||||||
ax = syscall(__NR_close, fd);
|
ax = syscall(__NR_close, fd);
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,6 +61,18 @@ forceinline int __sysv_open(const char *path, long flags, long mode) {
|
||||||
: "=a"(ax), "=d"(dx)
|
: "=a"(ax), "=d"(dx)
|
||||||
: "0"(__NR_open), "D"(path), "S"(flags), "1"(mode)
|
: "0"(__NR_open), "D"(path), "S"(flags), "1"(mode)
|
||||||
: "memory", "cc");
|
: "memory", "cc");
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
register long r0 asm("x0") = -100;
|
||||||
|
register long r1 asm("x1") = (long)path;
|
||||||
|
register long r2 asm("x2") = (long)flags;
|
||||||
|
register long r3 asm("x3") = (long)mode;
|
||||||
|
register long res_x0 asm("x0");
|
||||||
|
asm volatile("mov\tx8,%1\n"
|
||||||
|
"svc\t0"
|
||||||
|
: "=r"(res_x0)
|
||||||
|
: "i"(56), "r"(r0), "r"(r1), "r"(r2), "r"(r3)
|
||||||
|
: "x8", "memory");
|
||||||
|
ax = res_x0;
|
||||||
#else
|
#else
|
||||||
ax = syscall(__NR_open, path, flags, mode);
|
ax = syscall(__NR_open, path, flags, mode);
|
||||||
#endif
|
#endif
|
||||||
|
@ -56,6 +86,17 @@ forceinline long __sysv_read(long fd, void *data, unsigned long size) {
|
||||||
: "=a"(ax), "=d"(dx)
|
: "=a"(ax), "=d"(dx)
|
||||||
: "0"(__NR_read), "D"(fd), "S"(data), "1"(size)
|
: "0"(__NR_read), "D"(fd), "S"(data), "1"(size)
|
||||||
: "memory", "cc");
|
: "memory", "cc");
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
register long r0 asm("x0") = (long)fd;
|
||||||
|
register long r1 asm("x1") = (long)data;
|
||||||
|
register long r2 asm("x2") = (long)size;
|
||||||
|
register long res_x0 asm("x0");
|
||||||
|
asm volatile("mov\tx8,%1\n"
|
||||||
|
"svc\t0"
|
||||||
|
: "=r"(res_x0)
|
||||||
|
: "i"(63), "r"(r0), "r"(r1), "r"(r2)
|
||||||
|
: "x8", "memory");
|
||||||
|
ax = res_x0;
|
||||||
#else
|
#else
|
||||||
ax = syscall(__NR_read, fd, data, size);
|
ax = syscall(__NR_read, fd, data, size);
|
||||||
#endif
|
#endif
|
||||||
|
@ -69,6 +110,17 @@ forceinline long __sysv_write(long fd, const void *data, unsigned long size) {
|
||||||
: "=a"(ax), "=d"(dx)
|
: "=a"(ax), "=d"(dx)
|
||||||
: "0"(__NR_write), "D"(fd), "S"(data), "1"(size)
|
: "0"(__NR_write), "D"(fd), "S"(data), "1"(size)
|
||||||
: "memory", "cc");
|
: "memory", "cc");
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
register long r0 asm("x0") = (long)fd;
|
||||||
|
register long r1 asm("x1") = (long)data;
|
||||||
|
register long r2 asm("x2") = (long)size;
|
||||||
|
register long res_x0 asm("x0");
|
||||||
|
asm volatile("mov\tx8,%1\n"
|
||||||
|
"svc\t0"
|
||||||
|
: "=r"(res_x0)
|
||||||
|
: "i"(64), "r"(r0), "r"(r1), "r"(r2)
|
||||||
|
: "x8", "memory");
|
||||||
|
ax = res_x0;
|
||||||
#else
|
#else
|
||||||
ax = syscall(__NR_write, fd, data, size);
|
ax = syscall(__NR_write, fd, data, size);
|
||||||
#endif
|
#endif
|
||||||
|
@ -82,6 +134,17 @@ forceinline long __sysv_mprotect(void *addr, size_t size, long prot) {
|
||||||
: "=a"(ax), "=d"(dx)
|
: "=a"(ax), "=d"(dx)
|
||||||
: "0"(__NR_mprotect), "D"(addr), "S"(size), "1"(prot)
|
: "0"(__NR_mprotect), "D"(addr), "S"(size), "1"(prot)
|
||||||
: "memory", "cc");
|
: "memory", "cc");
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
register long r0 asm("x0") = (long)addr;
|
||||||
|
register long r1 asm("x1") = (long)size;
|
||||||
|
register long r2 asm("x2") = (long)prot;
|
||||||
|
register long res_x0 asm("x0");
|
||||||
|
asm volatile("mov\tx8,%1\n"
|
||||||
|
"svc\t0"
|
||||||
|
: "=r"(res_x0)
|
||||||
|
: "i"(226), "r"(r0), "r"(r1), "r"(r2)
|
||||||
|
: "x8", "memory");
|
||||||
|
ax = res_x0;
|
||||||
#else
|
#else
|
||||||
ax = syscall(__NR_mprotect, addr, size, prot);
|
ax = syscall(__NR_mprotect, addr, size, prot);
|
||||||
#endif
|
#endif
|
||||||
|
@ -95,6 +158,14 @@ forceinline int __sysv_getpid(void) {
|
||||||
: "=a"(ax)
|
: "=a"(ax)
|
||||||
: "0"(__NR_getpid)
|
: "0"(__NR_getpid)
|
||||||
: "rdx", "memory", "cc");
|
: "rdx", "memory", "cc");
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
register long res_x0 asm("x0");
|
||||||
|
asm volatile("mov\tx8,%1\n"
|
||||||
|
"svc\t0"
|
||||||
|
: "=r"(res_x0)
|
||||||
|
: "i"(172)
|
||||||
|
: "x8", "memory");
|
||||||
|
ax = res_x0;
|
||||||
#else
|
#else
|
||||||
ax = syscall(__NR_getpid);
|
ax = syscall(__NR_getpid);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -210,7 +210,7 @@ void _log_exit(int) wontreturn;
|
||||||
|
|
||||||
#define ARGS unsigned, const char *, int, FILE *, const char *
|
#define ARGS unsigned, const char *, int, FILE *, const char *
|
||||||
#define ATTR paramsnonnull((5)) printfesque(5)
|
#define ATTR paramsnonnull((5)) printfesque(5)
|
||||||
#define ATTRV paramsnonnull((5, 6))
|
#define ATTRV paramsnonnull((5))
|
||||||
void flogf(ARGS, ...) ATTR libcesque;
|
void flogf(ARGS, ...) ATTR libcesque;
|
||||||
void vflogf(ARGS, va_list) ATTRV libcesque;
|
void vflogf(ARGS, va_list) ATTRV libcesque;
|
||||||
void fverbosef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
|
void fverbosef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
|
||||||
|
|
26
libc/log/logfile.c
Normal file
26
libc/log/logfile.c
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/*-*- 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 │
|
||||||
|
│ │
|
||||||
|
│ 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/log/log.h"
|
||||||
|
#include "libc/stdio/stdio.h"
|
||||||
|
|
||||||
|
FILE *__log_file;
|
||||||
|
|
||||||
|
__attribute__((__constructor__)) static void init(void) {
|
||||||
|
__log_file = stderr;
|
||||||
|
}
|
|
@ -1,24 +0,0 @@
|
||||||
/*-*- 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 │
|
|
||||||
│ │
|
|
||||||
│ 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/intrin/initializer.internal.h"
|
|
||||||
#include "libc/stdio/stdio.h"
|
|
||||||
|
|
||||||
FILE *__log_file;
|
|
||||||
|
|
||||||
INITIALIZER(401, _init_log_file, (__log_file = stderr));
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
|
|
||||||
.bss
|
.bss
|
||||||
.align 4
|
.balign 4
|
||||||
__log_level:
|
__log_level:
|
||||||
.long 0
|
.long 0
|
||||||
.endobj __log_level,globl
|
.endobj __log_level,globl
|
||||||
|
|
|
@ -13,20 +13,20 @@
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
|
|
||||||
#define IS2POW(X) (!((X) & ((X)-1)))
|
#define IS2POW(X) (!((X) & ((X)-1)))
|
||||||
#define ROUNDUP(X, K) (((X) + (K)-1) & -(K))
|
#define ROUNDUP(X, K) (((X) + (K)-1) & -(K))
|
||||||
#define ROUNDDOWN(X, K) ((X) & -(K))
|
#define ROUNDDOWN(X, K) ((X) & -(K))
|
||||||
#ifndef __ASSEMBLER__
|
#ifndef __ASSEMBLER__
|
||||||
#define ABS(X) ((X) >= 0 ? (X) : -(X))
|
#define ABS(X) ((X) >= 0 ? (X) : -(X))
|
||||||
#define MIN(X, Y) ((Y) > (X) ? (X) : (Y))
|
#define MIN(X, Y) ((Y) > (X) ? (X) : (Y))
|
||||||
#define MAX(X, Y) ((Y) < (X) ? (X) : (Y))
|
#define MAX(X, Y) ((Y) < (X) ? (X) : (Y))
|
||||||
#else
|
#else
|
||||||
// The GNU assembler does not grok the ?: ternary operator; furthermore,
|
// The GNU assembler does not grok the ?: ternary operator; furthermore,
|
||||||
// boolean expressions yield -1 and 0 for "true" and "false", not 1 and 0.
|
// boolean expressions yield -1 and 0 for "true" and "false", not 1 and 0.
|
||||||
#define __MAPBOOL(P) (!!(P) / (!!(P) + !(P)))
|
#define __MAPBOOL(P) (!!(P) / (!!(P) + !(P)))
|
||||||
#define __IFELSE(P, X, Y) (__MAPBOOL(P) * (X) + __MAPBOOL(!(P)) * (Y))
|
#define __IFELSE(P, X, Y) (__MAPBOOL(P) * (X) + __MAPBOOL(!(P)) * (Y))
|
||||||
#define MIN(X, Y) (__IFELSE((Y) > (X), (X), (Y)))
|
#define MIN(X, Y) (__IFELSE((Y) > (X), (X), (Y)))
|
||||||
#define MAX(X, Y) (__IFELSE((Y) < (X), (X), (Y)))
|
#define MAX(X, Y) (__IFELSE((Y) < (X), (X), (Y)))
|
||||||
#endif
|
#endif
|
||||||
#define PASTE(A, B) __PASTE(A, B)
|
#define PASTE(A, B) __PASTE(A, B)
|
||||||
#define STRINGIFY(A) __STRINGIFY(A)
|
#define STRINGIFY(A) __STRINGIFY(A)
|
||||||
|
@ -43,9 +43,31 @@
|
||||||
#ifdef __ASSEMBLER__
|
#ifdef __ASSEMBLER__
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
#if __MNO_VZEROUPPER__ + 0
|
// Ends function definition.
|
||||||
#define vzeroupper
|
// @cost saves 1-3 lines of code
|
||||||
#endif
|
.macro .endfn name:req bnd vis
|
||||||
|
.size "\name",.-"\name"
|
||||||
|
.type "\name",@function
|
||||||
|
.ifnb \bnd
|
||||||
|
.\bnd "\name"
|
||||||
|
.endif
|
||||||
|
.ifnb \vis
|
||||||
|
.\vis "\name"
|
||||||
|
.endif
|
||||||
|
.endm
|
||||||
|
|
||||||
|
// Ends variable definition.
|
||||||
|
// @cost saves 1-3 lines of code
|
||||||
|
.macro .endobj name:req bnd vis
|
||||||
|
.size "\name",.-"\name"
|
||||||
|
.type "\name",@object
|
||||||
|
.ifnb \bnd
|
||||||
|
.\bnd "\name"
|
||||||
|
.endif
|
||||||
|
.ifnb \vis
|
||||||
|
.\vis "\name"
|
||||||
|
.endif
|
||||||
|
.endm
|
||||||
|
|
||||||
// Shorthand notation for widely-acknowledged sections.
|
// Shorthand notation for widely-acknowledged sections.
|
||||||
.macro .rodata
|
.macro .rodata
|
||||||
|
@ -77,7 +99,7 @@
|
||||||
.endm
|
.endm
|
||||||
.macro .text.modernity
|
.macro .text.modernity
|
||||||
.section .text.modernity,"ax",@progbits
|
.section .text.modernity,"ax",@progbits
|
||||||
.align 16
|
.balign 16
|
||||||
.endm
|
.endm
|
||||||
.macro .text.antiquity
|
.macro .text.antiquity
|
||||||
.section .text.antiquity,"ax",@progbits
|
.section .text.antiquity,"ax",@progbits
|
||||||
|
@ -95,6 +117,51 @@
|
||||||
.section .text.windows,"ax",@progbits
|
.section .text.windows,"ax",@progbits
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
|
// Mergeable NUL-terminated UTF-8 string constant section.
|
||||||
|
//
|
||||||
|
// @note linker de-dupes C strings here across whole compile
|
||||||
|
// @note therefore item/values are reordered w.r.t. link order
|
||||||
|
// @note therefore no section relative addressing
|
||||||
|
.macro .rodata.str1.1
|
||||||
|
.section .rodata.str1.1,"aMS",@progbits,1
|
||||||
|
.align 1
|
||||||
|
.endm
|
||||||
|
|
||||||
|
// Locates unreferenced code invulnerable to --gc-sections.
|
||||||
|
.macro .keep.text
|
||||||
|
.section .keep.text,"ax",@progbits
|
||||||
|
.endm
|
||||||
|
|
||||||
|
// Flags code as only allowed for testing purposes.
|
||||||
|
.macro .testonly
|
||||||
|
.section .test,"ax",@progbits
|
||||||
|
.endm
|
||||||
|
|
||||||
|
// Makes code runnable while code morphing.
|
||||||
|
.macro .privileged
|
||||||
|
.section .privileged,"ax",@progbits
|
||||||
|
.endm
|
||||||
|
|
||||||
|
// Pulls unrelated module into linkage.
|
||||||
|
//
|
||||||
|
// In order for this technique to work with --gc-sections, another
|
||||||
|
// module somewhere might want to weakly reference whats yoinked.
|
||||||
|
.macro .yoink symbol:req
|
||||||
|
.section .yoink
|
||||||
|
#ifdef __x86_64__
|
||||||
|
nopl "\symbol"(%rip)
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
b "\symbol"
|
||||||
|
#endif
|
||||||
|
.previous
|
||||||
|
.endm
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
|
|
||||||
|
#if __MNO_VZEROUPPER__ + 0
|
||||||
|
#define vzeroupper
|
||||||
|
#endif
|
||||||
|
|
||||||
// Mergeable numeric constant sections.
|
// Mergeable numeric constant sections.
|
||||||
//
|
//
|
||||||
// @note linker de-dupes item/values across whole compile
|
// @note linker de-dupes item/values across whole compile
|
||||||
|
@ -129,31 +196,6 @@
|
||||||
.align 4
|
.align 4
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
// Mergeable NUL-terminated UTF-8 string constant section.
|
|
||||||
//
|
|
||||||
// @note linker de-dupes C strings here across whole compile
|
|
||||||
// @note therefore item/values are reordered w.r.t. link order
|
|
||||||
// @note therefore no section relative addressing
|
|
||||||
.macro .rodata.str1.1
|
|
||||||
.section .rodata.str1.1,"aMS",@progbits,1
|
|
||||||
.align 1
|
|
||||||
.endm
|
|
||||||
|
|
||||||
// Locates unreferenced code invulnerable to --gc-sections.
|
|
||||||
.macro .keep.text
|
|
||||||
.section .keep.text,"ax",@progbits
|
|
||||||
.endm
|
|
||||||
|
|
||||||
// Flags code as only allowed for testing purposes.
|
|
||||||
.macro .testonly
|
|
||||||
.section .test,"ax",@progbits
|
|
||||||
.endm
|
|
||||||
|
|
||||||
// Makes code runnable while code morphing.
|
|
||||||
.macro .privileged
|
|
||||||
.section .privileged,"ax",@progbits
|
|
||||||
.endm
|
|
||||||
|
|
||||||
// Loads address of errno into %rcx
|
// Loads address of errno into %rcx
|
||||||
.macro .errno
|
.macro .errno
|
||||||
call __errno_location
|
call __errno_location
|
||||||
|
@ -197,32 +239,6 @@
|
||||||
.weak \canonical
|
.weak \canonical
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
// Ends function definition.
|
|
||||||
// @cost saves 1-3 lines of code
|
|
||||||
.macro .endfn name:req bnd vis
|
|
||||||
.size "\name",.-"\name"
|
|
||||||
.type "\name",@function
|
|
||||||
.ifnb \bnd
|
|
||||||
.\bnd "\name"
|
|
||||||
.endif
|
|
||||||
.ifnb \vis
|
|
||||||
.\vis "\name"
|
|
||||||
.endif
|
|
||||||
.endm
|
|
||||||
|
|
||||||
// Ends variable definition.
|
|
||||||
// @cost saves 1-3 lines of code
|
|
||||||
.macro .endobj name:req bnd vis
|
|
||||||
.size "\name",.-"\name"
|
|
||||||
.type "\name",@object
|
|
||||||
.ifnb \bnd
|
|
||||||
.\bnd "\name"
|
|
||||||
.endif
|
|
||||||
.ifnb \vis
|
|
||||||
.\vis "\name"
|
|
||||||
.endif
|
|
||||||
.endm
|
|
||||||
|
|
||||||
// LOOP Instruction Replacement.
|
// LOOP Instruction Replacement.
|
||||||
.macro .loop label:req
|
.macro .loop label:req
|
||||||
.byte 0x83
|
.byte 0x83
|
||||||
|
@ -341,16 +357,6 @@
|
||||||
.byte 0x0f,0x1f,0x40,0x00
|
.byte 0x0f,0x1f,0x40,0x00
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
// Pulls unrelated module into linkage.
|
|
||||||
//
|
|
||||||
// In order for this technique to work with --gc-sections, another
|
|
||||||
// module somewhere might want to weakly reference whats yoinked.
|
|
||||||
.macro .yoink symbol:req
|
|
||||||
.section .yoink
|
|
||||||
nopl "\symbol"(%rip)
|
|
||||||
.previous
|
|
||||||
.endm
|
|
||||||
|
|
||||||
// Calls Windows function.
|
// Calls Windows function.
|
||||||
//
|
//
|
||||||
// @param cx,dx,r8,r9,stack
|
// @param cx,dx,r8,r9,stack
|
||||||
|
@ -542,6 +548,14 @@
|
||||||
#endif
|
#endif
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
.macro .underrun
|
||||||
|
.endm
|
||||||
|
.macro .overrun
|
||||||
|
.endm
|
||||||
|
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
#endif /* __x86_64__ */
|
||||||
#endif /* __ASSEMBLER__ */
|
#endif /* __ASSEMBLER__ */
|
||||||
#endif /* COSMOPOLITAN_LIBC_MACROS_H_ */
|
#endif /* COSMOPOLITAN_LIBC_MACROS_H_ */
|
||||||
|
|
23
libc/nexgen32e/auxv2.c
Normal file
23
libc/nexgen32e/auxv2.c
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/*-*- 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. │
|
||||||
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
||||||
|
#ifdef __aarch64__
|
||||||
|
unsigned long *__auxv;
|
||||||
|
#endif
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
// Environment variable pointer list.
|
// Environment variable pointer list.
|
||||||
.bss
|
.bss
|
||||||
.align 8
|
.balign 8
|
||||||
environ:
|
environ:
|
||||||
.quad 0
|
.quad 0
|
||||||
.endobj environ,globl
|
.endobj environ,globl
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue