mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
parent
a988896048
commit
f317a47cd8
15 changed files with 315 additions and 253 deletions
52
ape/ape.lds
52
ape/ape.lds
|
@ -553,32 +553,6 @@ SHSTUB2(ape_loader_dd_count,
|
||||||
? ROUNDUP(ape_loader_end - ape_loader, PAGESIZE) / 64
|
? ROUNDUP(ape_loader_end - ape_loader, PAGESIZE) / 64
|
||||||
: 0);
|
: 0);
|
||||||
|
|
||||||
#if SupportsXnu()
|
|
||||||
SHSTUB2(ape_macho_dd_skip, RVA(ape_macho) / 8);
|
|
||||||
SHSTUB2(ape_macho_dd_count, (ape_macho_end - ape_macho) / 8);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SupportsWindows() || SupportsMetal()
|
|
||||||
#define LINK_WINDOWS (SupportsWindows() && !DEFINED(EfiMain))
|
|
||||||
PFSTUB4(ape_pe_offset, ape_pe - ape_mz);
|
|
||||||
HIDDEN(ape_pe_optsz = ape_pe_sections - (ape_pe + 24));
|
|
||||||
HIDDEN(ape_pe_shnum = (ape_pe_sections_end - ape_pe_sections) / 40);
|
|
||||||
HIDDEN(ape_pe_base = IMAGE_BASE_VIRTUAL);
|
|
||||||
HIDDEN(ape_idata = LINK_WINDOWS ? RVA(ape_idata_iat) : 0);
|
|
||||||
HIDDEN(ape_idata_iatsize = LINK_WINDOWS ? ape_idata_iatend - ape_idata_iat : 0);
|
|
||||||
HIDDEN(ape_idata = LINK_WINDOWS ? RVA(ape_idata_idt) : 0);
|
|
||||||
HIDDEN(ape_idata_idtsize = LINK_WINDOWS ? ape_idata_idtend - ape_idata_idt : 0);
|
|
||||||
HIDDEN(v_ntversion = LINK_WINDOWS ? 6 : 1);
|
|
||||||
HIDDEN(v_ntdllchar = LINK_WINDOWS ? 288 : 0);
|
|
||||||
HIDDEN(v_ntsubversion = LINK_WINDOWS ? 6 : 5);
|
|
||||||
HIDDEN(v_ntsubsystem = (LINK_WINDOWS
|
|
||||||
? (DEFINED(GetMessage)
|
|
||||||
? kNtImageSubsystemWindowsGui
|
|
||||||
: kNtImageSubsystemWindowsCui)
|
|
||||||
: kNtImageSubsystemEfiApplication));
|
|
||||||
HIDDEN(ape_pe_entry = LINK_WINDOWS ? WinMain : EfiMain);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SupportsMetal()
|
#if SupportsMetal()
|
||||||
HIDDEN(v_ape_realsectors =
|
HIDDEN(v_ape_realsectors =
|
||||||
MIN(0x70000 - IMAGE_BASE_REAL,
|
MIN(0x70000 - IMAGE_BASE_REAL,
|
||||||
|
@ -685,6 +659,32 @@ CHURN(WinMain);
|
||||||
#endif /* SupportsWindows() */
|
#endif /* SupportsWindows() */
|
||||||
#endif /* SupportsXnu() */
|
#endif /* SupportsXnu() */
|
||||||
|
|
||||||
|
#if SupportsWindows() || SupportsMetal()
|
||||||
|
#define LINK_WINDOWS (SupportsWindows() && !DEFINED(EfiMain))
|
||||||
|
PFSTUB4(ape_pe_offset, ape_pe - ape_mz);
|
||||||
|
HIDDEN(ape_pe_optsz = ape_pe_sections - (ape_pe + 24));
|
||||||
|
HIDDEN(ape_pe_shnum = (ape_pe_sections_end - ape_pe_sections) / 40);
|
||||||
|
HIDDEN(ape_pe_base = IMAGE_BASE_VIRTUAL);
|
||||||
|
HIDDEN(ape_idata = LINK_WINDOWS ? RVA(ape_idata_iat) : 0);
|
||||||
|
HIDDEN(ape_idata_iatsize = LINK_WINDOWS ? ape_idata_iatend - ape_idata_iat : 0);
|
||||||
|
HIDDEN(ape_idata = LINK_WINDOWS ? RVA(ape_idata_idt) : 0);
|
||||||
|
HIDDEN(ape_idata_idtsize = LINK_WINDOWS ? ape_idata_idtend - ape_idata_idt : 0);
|
||||||
|
HIDDEN(v_ntversion = LINK_WINDOWS ? 6 : 1);
|
||||||
|
HIDDEN(v_ntdllchar = LINK_WINDOWS ? 288 : 0);
|
||||||
|
HIDDEN(v_ntsubversion = LINK_WINDOWS ? 6 : 5);
|
||||||
|
HIDDEN(v_ntsubsystem = (LINK_WINDOWS
|
||||||
|
? (DEFINED(GetMessage)
|
||||||
|
? kNtImageSubsystemWindowsGui
|
||||||
|
: kNtImageSubsystemWindowsCui)
|
||||||
|
: kNtImageSubsystemEfiApplication));
|
||||||
|
HIDDEN(ape_pe_entry = LINK_WINDOWS ? WinMain : EfiMain);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SupportsXnu()
|
||||||
|
SHSTUB2(ape_macho_dd_skip, RVA(ape_macho) / 8);
|
||||||
|
SHSTUB2(ape_macho_dd_count, (ape_macho_end - ape_macho) / 8);
|
||||||
|
#endif
|
||||||
|
|
||||||
ASSERT(DEFINED(ape_mz) ? ape_mz == IMAGE_BASE_VIRTUAL : 1, "linker panic");
|
ASSERT(DEFINED(ape_mz) ? ape_mz == IMAGE_BASE_VIRTUAL : 1, "linker panic");
|
||||||
ASSERT((DEFINED(__init_bss_end) ? __init_bss_end : 0) % __SIZEOF_POINTER__ == 0,
|
ASSERT((DEFINED(__init_bss_end) ? __init_bss_end : 0) % __SIZEOF_POINTER__ == 0,
|
||||||
"__init_bss misalign");
|
"__init_bss misalign");
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "libc/bits/asmflag.h"
|
#include "libc/bits/asmflag.h"
|
||||||
#include "libc/bits/bits.h"
|
#include "libc/bits/bits.h"
|
||||||
#include "libc/calls/asan.internal.h"
|
#include "libc/calls/asan.internal.h"
|
||||||
#include "libc/calls/clock_gettime.h"
|
#include "libc/calls/clock_gettime.internal.h"
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/calls/state.internal.h"
|
#include "libc/calls/state.internal.h"
|
||||||
#include "libc/calls/strace.internal.h"
|
#include "libc/calls/strace.internal.h"
|
||||||
|
|
|
@ -7,8 +7,8 @@ COSMOPOLITAN_C_START_
|
||||||
typedef int clock_gettime_f(int, struct timespec *);
|
typedef int clock_gettime_f(int, struct timespec *);
|
||||||
|
|
||||||
extern clock_gettime_f *__clock_gettime;
|
extern clock_gettime_f *__clock_gettime;
|
||||||
hidden clock_gettime_f __clock_gettime_init;
|
clock_gettime_f *__clock_gettime_get(bool *) hidden;
|
||||||
hidden clock_gettime_f *__clock_gettime_get(bool *);
|
int __clock_gettime_init(int, struct timespec *) hidden;
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
@ -20,7 +20,7 @@
|
||||||
#include "libc/bits/initializer.internal.h"
|
#include "libc/bits/initializer.internal.h"
|
||||||
#include "libc/bits/safemacros.internal.h"
|
#include "libc/bits/safemacros.internal.h"
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/clock_gettime.h"
|
#include "libc/calls/clock_gettime.internal.h"
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/calls/state.internal.h"
|
#include "libc/calls/state.internal.h"
|
||||||
#include "libc/calls/strace.internal.h"
|
#include "libc/calls/strace.internal.h"
|
||||||
|
|
|
@ -50,14 +50,18 @@ int64_t TimeValToWindowsTime(struct timeval) libcesque nosideeffect;
|
||||||
struct timeval WindowsDurationToTimeVal(int64_t) libcesque nosideeffect;
|
struct timeval WindowsDurationToTimeVal(int64_t) libcesque nosideeffect;
|
||||||
struct timespec WindowsDurationToTimeSpec(int64_t) libcesque nosideeffect;
|
struct timespec WindowsDurationToTimeSpec(int64_t) libcesque nosideeffect;
|
||||||
|
|
||||||
static inline struct NtFileTime MakeFileTime(int64_t x) {
|
#define MakeFileTime(x) \
|
||||||
return (struct NtFileTime){(uint32_t)x, (uint32_t)(x >> 32)};
|
({ \
|
||||||
}
|
int64_t __x = x; \
|
||||||
|
(struct NtFileTime){(uint32_t)__x, (uint32_t)(__x >> 32)}; \
|
||||||
|
})
|
||||||
|
|
||||||
static inline int64_t ReadFileTime(struct NtFileTime t) {
|
#define ReadFileTime(t) \
|
||||||
uint64_t x = t.dwHighDateTime;
|
({ \
|
||||||
return x << 32 | t.dwLowDateTime;
|
struct NtFileTime __t = t; \
|
||||||
}
|
uint64_t x = __t.dwHighDateTime; \
|
||||||
|
(int64_t)(x << 32 | __t.dwLowDateTime); \
|
||||||
|
})
|
||||||
|
|
||||||
#define FileTimeToTimeSpec(x) WindowsTimeToTimeSpec(ReadFileTime(x))
|
#define FileTimeToTimeSpec(x) WindowsTimeToTimeSpec(ReadFileTime(x))
|
||||||
#define FileTimeToTimeVal(x) WindowsTimeToTimeVal(ReadFileTime(x))
|
#define FileTimeToTimeVal(x) WindowsTimeToTimeVal(ReadFileTime(x))
|
||||||
|
|
|
@ -9,13 +9,14 @@ bool32 GetVersionEx(struct NtOsVersionInfo *lpVersionInformation);
|
||||||
|
|
||||||
#if defined(__GCC_ASM_FLAG_OUTPUTS__) && !defined(__STRICT_ANSI__)
|
#if defined(__GCC_ASM_FLAG_OUTPUTS__) && !defined(__STRICT_ANSI__)
|
||||||
#define IsAtLeastWindows10() (GetNtMajorVersion() >= 10)
|
#define IsAtLeastWindows10() (GetNtMajorVersion() >= 10)
|
||||||
static pureconst inline unsigned char GetNtMajorVersion(void) {
|
#define GetNtMajorVersion() \
|
||||||
uintptr_t _x;
|
({ \
|
||||||
asm("mov\t%%gs:96,%q0\r\n"
|
uintptr_t __x; \
|
||||||
"mov\t280(%q0),%b0"
|
asm("mov\t%%gs:96,%q0\r\n" \
|
||||||
: "=q"(_x));
|
"mov\t280(%q0),%b0" \
|
||||||
return _x;
|
: "=q"(__x)); \
|
||||||
}
|
(unsigned char)__x; \
|
||||||
|
})
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
|
|
|
@ -4,14 +4,17 @@
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
||||||
forceinline bool SlicesEqual(const char *a, size_t n, const char *b, size_t m) {
|
#define SlicesEqual(a, n, b, m) \
|
||||||
return n == m && !memcmp(a, b, n);
|
({ \
|
||||||
}
|
size_t __n = (n); \
|
||||||
|
__n == (m) && !memcmp(a, b, __n); \
|
||||||
|
})
|
||||||
|
|
||||||
forceinline bool SlicesEqualCase(const void *a, size_t n, const void *b,
|
#define SlicesEqualCase(a, n, b, m) \
|
||||||
size_t m) {
|
({ \
|
||||||
return n == m && !memcasecmp(a, b, n);
|
size_t __n = (n); \
|
||||||
}
|
__n == (m) && !memcasecmp(a, b, __n); \
|
||||||
|
})
|
||||||
|
|
||||||
int CompareSlices(const char *, size_t, const char *, size_t);
|
int CompareSlices(const char *, size_t, const char *, size_t);
|
||||||
int CompareSlicesCase(const char *, size_t, const char *, size_t);
|
int CompareSlicesCase(const char *, size_t, const char *, size_t);
|
||||||
|
|
|
@ -9,9 +9,12 @@
|
||||||
* @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
|
* @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
|
||||||
* @see fmod()
|
* @see fmod()
|
||||||
*/
|
*/
|
||||||
static inline double emod(double x, double y) {
|
#define emod(x, y) \
|
||||||
return x - fabs(y) * floor(x / fabs(y));
|
({ \
|
||||||
}
|
double __x = x; \
|
||||||
|
double __y = y; \
|
||||||
|
__x - fabs(__y) * floor(__x / fabs(__y)); \
|
||||||
|
})
|
||||||
|
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
#endif /* COSMOPOLITAN_LIBC_TINYMATH_EMOD_H_ */
|
#endif /* COSMOPOLITAN_LIBC_TINYMATH_EMOD_H_ */
|
||||||
|
|
|
@ -9,9 +9,12 @@
|
||||||
* @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
|
* @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
|
||||||
* @see fmodl()
|
* @see fmodl()
|
||||||
*/
|
*/
|
||||||
static inline long double emodl(long double x, long double y) {
|
#define emodl(x, y) \
|
||||||
return x - fabsl(y) * floorl(x / fabsl(y));
|
({ \
|
||||||
}
|
long double __x = x; \
|
||||||
|
long double __y = y; \
|
||||||
|
__x - fabsl(__y) * floorl(__x / fabsl(__y)); \
|
||||||
|
})
|
||||||
|
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
#endif /* COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_ */
|
#endif /* COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_ */
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/clock_gettime.h"
|
#include "libc/calls/clock_gettime.internal.h"
|
||||||
#include "libc/calls/internal.h"
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/calls/struct/timespec.h"
|
#include "libc/calls/struct/timespec.h"
|
||||||
#include "libc/calls/struct/timeval.h"
|
#include "libc/calls/struct/timeval.h"
|
||||||
|
|
|
@ -1,148 +1,191 @@
|
||||||
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
|
#-*-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───────────────────────┘
|
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
|
||||||
|
|
||||||
o/$(MODE)/test/libc/release/cosmopolitan.zip: \
|
o/$(MODE)/test/libc/release/cosmopolitan.zip: \
|
||||||
o/cosmopolitan.h \
|
o/cosmopolitan.h \
|
||||||
o/$(MODE)/ape/ape.lds \
|
o/$(MODE)/ape/ape.lds \
|
||||||
o/$(MODE)/libc/crt/crt.o \
|
o/$(MODE)/libc/crt/crt.o \
|
||||||
o/$(MODE)/ape/ape.o \
|
o/$(MODE)/ape/ape.o \
|
||||||
o/$(MODE)/ape/ape-no-modify-self.o \
|
o/$(MODE)/ape/ape-no-modify-self.o \
|
||||||
o/$(MODE)/cosmopolitan.a \
|
o/$(MODE)/cosmopolitan.a \
|
||||||
o/$(MODE)/third_party/zip/zip.com
|
o/$(MODE)/third_party/zip/zip.com
|
||||||
@$(COMPILE) -AZIP -T$@ \
|
@$(COMPILE) -AZIP -T$@ \
|
||||||
o/$(MODE)/third_party/zip/zip.com \
|
o/$(MODE)/third_party/zip/zip.com \
|
||||||
-qj $@ \
|
-qj $@ \
|
||||||
o/cosmopolitan.h \
|
o/cosmopolitan.h \
|
||||||
o/$(MODE)/ape/ape.lds \
|
o/$(MODE)/ape/ape.lds \
|
||||||
o/$(MODE)/libc/crt/crt.o \
|
o/$(MODE)/libc/crt/crt.o \
|
||||||
o/$(MODE)/ape/ape.o \
|
o/$(MODE)/ape/ape.o \
|
||||||
o/$(MODE)/ape/ape-no-modify-self.o \
|
o/$(MODE)/ape/ape-no-modify-self.o \
|
||||||
o/$(MODE)/cosmopolitan.a
|
o/$(MODE)/cosmopolitan.a
|
||||||
|
|
||||||
o/$(MODE)/test/libc/release/smoke.com: \
|
o/$(MODE)/test/libc/release/smoke.o: \
|
||||||
o/$(MODE)/test/libc/release/smoke.com.dbg
|
test/libc/release/smoke.c \
|
||||||
@$(COMPILE) -AOBJCOPY -T$< $(OBJCOPY) -S -O binary $< $@
|
o/cosmopolitan.h
|
||||||
|
@$(COMPILE) -ACC $(CC) \
|
||||||
|
-o $@ \
|
||||||
|
-c \
|
||||||
|
-Os \
|
||||||
|
-fno-pie \
|
||||||
|
-nostdinc \
|
||||||
|
-fno-omit-frame-pointer \
|
||||||
|
-include o/cosmopolitan.h \
|
||||||
|
$<
|
||||||
|
|
||||||
o/$(MODE)/test/libc/release/smoke.com.dbg: \
|
o/$(MODE)/test/libc/release/smoke.com.dbg: \
|
||||||
test/libc/release/smoke.c \
|
o/$(MODE)/test/libc/release/smoke.o \
|
||||||
o/cosmopolitan.h \
|
o/$(MODE)/ape/ape.lds \
|
||||||
o/$(MODE)/ape/ape.lds \
|
o/$(MODE)/libc/crt/crt.o \
|
||||||
o/$(MODE)/libc/crt/crt.o \
|
o/$(MODE)/ape/ape.o \
|
||||||
o/$(MODE)/ape/ape.o \
|
|
||||||
o/$(MODE)/cosmopolitan.a
|
|
||||||
@$(COMPILE) -ACC $(CC) \
|
|
||||||
-o $@ \
|
|
||||||
-Os \
|
|
||||||
-static \
|
|
||||||
-no-pie \
|
|
||||||
-fno-pie \
|
|
||||||
-nostdlib \
|
|
||||||
-nostdinc \
|
|
||||||
-mno-red-zone \
|
|
||||||
-fno-omit-frame-pointer \
|
|
||||||
-Wl,-T,o/$(MODE)/ape/ape.lds \
|
|
||||||
-include o/cosmopolitan.h \
|
|
||||||
test/libc/release/smoke.c \
|
|
||||||
o/$(MODE)/libc/crt/crt.o \
|
|
||||||
o/$(MODE)/ape/ape.o \
|
|
||||||
o/$(MODE)/cosmopolitan.a
|
o/$(MODE)/cosmopolitan.a
|
||||||
|
@$(COMPILE) -ALD $(LD) \
|
||||||
|
-static \
|
||||||
|
-no-pie \
|
||||||
|
-nostdlib \
|
||||||
|
-T o/$(MODE)/ape/ape.lds \
|
||||||
|
o/$(MODE)/test/libc/release/smoke.o \
|
||||||
|
o/$(MODE)/libc/crt/crt.o \
|
||||||
|
o/$(MODE)/ape/ape.o \
|
||||||
|
o/$(MODE)/cosmopolitan.a \
|
||||||
|
-o $@
|
||||||
|
|
||||||
o/$(MODE)/test/libc/release/smoke-nms.com.dbg: \
|
o/$(MODE)/test/libc/release/smoke-nms.com.dbg: \
|
||||||
test/libc/release/smoke.c \
|
o/$(MODE)/test/libc/release/smoke.o \
|
||||||
o/cosmopolitan.h \
|
o/$(MODE)/ape/ape.lds \
|
||||||
o/$(MODE)/ape/ape.lds \
|
o/$(MODE)/libc/crt/crt.o \
|
||||||
o/$(MODE)/libc/crt/crt.o \
|
o/$(MODE)/ape/ape-no-modify-self.o \
|
||||||
o/$(MODE)/ape/ape-no-modify-self.o \
|
|
||||||
o/$(MODE)/cosmopolitan.a
|
|
||||||
@$(COMPILE) -ACC $(CC) \
|
|
||||||
-o $@ \
|
|
||||||
-Os \
|
|
||||||
-static \
|
|
||||||
-no-pie \
|
|
||||||
-fno-pie \
|
|
||||||
-nostdlib \
|
|
||||||
-nostdinc \
|
|
||||||
-mno-red-zone \
|
|
||||||
-fno-omit-frame-pointer \
|
|
||||||
-Wl,-T,o/$(MODE)/ape/ape.lds \
|
|
||||||
-include o/cosmopolitan.h \
|
|
||||||
test/libc/release/smoke.c \
|
|
||||||
o/$(MODE)/libc/crt/crt.o \
|
|
||||||
o/$(MODE)/ape/ape-no-modify-self.o \
|
|
||||||
o/$(MODE)/cosmopolitan.a
|
o/$(MODE)/cosmopolitan.a
|
||||||
|
@$(COMPILE) -ALD $(LD) \
|
||||||
|
-static \
|
||||||
|
-no-pie \
|
||||||
|
-nostdlib \
|
||||||
|
-T o/$(MODE)/ape/ape.lds \
|
||||||
|
o/$(MODE)/test/libc/release/smoke.o \
|
||||||
|
o/$(MODE)/libc/crt/crt.o \
|
||||||
|
o/$(MODE)/ape/ape-no-modify-self.o \
|
||||||
|
o/$(MODE)/cosmopolitan.a \
|
||||||
|
-o $@
|
||||||
|
|
||||||
o/$(MODE)/test/libc/release/smokecxx.com: \
|
o/$(MODE)/test/libc/release/smoke-chibicc.com.dbg: \
|
||||||
o/$(MODE)/test/libc/release/smokecxx.com.dbg
|
o/$(MODE)/test/libc/release/smoke-chibicc.o \
|
||||||
@$(COMPILE) -AOBJCOPY -T$< $(OBJCOPY) -S -O binary $< $@
|
o/$(MODE)/ape/ape.lds \
|
||||||
|
o/$(MODE)/libc/crt/crt.o \
|
||||||
|
o/$(MODE)/ape/ape-no-modify-self.o \
|
||||||
|
o/$(MODE)/cosmopolitan.a \
|
||||||
|
o/$(MODE)/third_party/chibicc/chibicc.com
|
||||||
|
@$(COMPILE) -ALD $(LD) \
|
||||||
|
-static \
|
||||||
|
-no-pie \
|
||||||
|
-nostdlib \
|
||||||
|
-T o/$(MODE)/ape/ape.lds \
|
||||||
|
o/$(MODE)/test/libc/release/smoke-chibicc.o \
|
||||||
|
o/$(MODE)/libc/crt/crt.o \
|
||||||
|
o/$(MODE)/ape/ape-no-modify-self.o \
|
||||||
|
o/$(MODE)/cosmopolitan.a \
|
||||||
|
-o $@
|
||||||
|
|
||||||
o/$(MODE)/test/libc/release/smokecxx.com.dbg: \
|
o/$(MODE)/test/libc/release/smoke-chibicc.o: \
|
||||||
test/libc/release/smokecxx.cc \
|
test/libc/release/smoke.c \
|
||||||
o/cosmopolitan.h \
|
o/cosmopolitan.h \
|
||||||
o/$(MODE)/ape/ape.lds \
|
o/$(MODE)/third_party/chibicc/chibicc.com
|
||||||
o/$(MODE)/libc/crt/crt.o \
|
@$(COMPILE) -ACHIBICC \
|
||||||
o/$(MODE)/ape/ape.o \
|
o/$(MODE)/third_party/chibicc/chibicc.com \
|
||||||
o/$(MODE)/cosmopolitan.a
|
$(CHIBICC_FLAGS) \
|
||||||
@$(COMPILE) -ACXX $(CXX) \
|
-o $@ \
|
||||||
-o $@ \
|
-c \
|
||||||
-Os \
|
-Os \
|
||||||
-static \
|
-static \
|
||||||
-no-pie \
|
-fno-pie \
|
||||||
-fno-pie \
|
-nostdlib \
|
||||||
-nostdlib \
|
-nostdinc \
|
||||||
-nostdinc \
|
-mno-red-zone \
|
||||||
-mno-red-zone \
|
-fno-omit-frame-pointer \
|
||||||
-fno-omit-frame-pointer \
|
-include o/cosmopolitan.h \
|
||||||
-Wl,-T,o/$(MODE)/ape/ape.lds \
|
$<
|
||||||
-include o/cosmopolitan.h \
|
|
||||||
test/libc/release/smokecxx.cc \
|
|
||||||
o/$(MODE)/libc/crt/crt.o \
|
|
||||||
o/$(MODE)/ape/ape.o \
|
|
||||||
o/$(MODE)/cosmopolitan.a
|
|
||||||
|
|
||||||
o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
|
o/$(MODE)/test/libc/release/smokecxx.com.dbg: \
|
||||||
test/libc/release/smoke.c \
|
o/$(MODE)/test/libc/release/smokecxx.o \
|
||||||
o/cosmopolitan.h \
|
o/$(MODE)/ape/ape.lds \
|
||||||
o/$(MODE)/ape/ape.lds \
|
o/$(MODE)/libc/crt/crt.o \
|
||||||
o/$(MODE)/libc/crt/crt.o \
|
o/$(MODE)/ape/ape.o \
|
||||||
o/$(MODE)/ape/ape.o \
|
|
||||||
o/$(MODE)/cosmopolitan.a
|
o/$(MODE)/cosmopolitan.a
|
||||||
@$(COMPILE) -AANSI $(CC) \
|
@$(COMPILE) -ALD $(LD) \
|
||||||
-o $@ \
|
-static \
|
||||||
-Os \
|
-no-pie \
|
||||||
-ansi \
|
-nostdlib \
|
||||||
-static \
|
-T o/$(MODE)/ape/ape.lds \
|
||||||
-no-pie \
|
o/$(MODE)/test/libc/release/smokecxx.o \
|
||||||
-fno-pie \
|
o/$(MODE)/libc/crt/crt.o \
|
||||||
-nostdlib \
|
o/$(MODE)/ape/ape.o \
|
||||||
-nostdinc \
|
o/$(MODE)/cosmopolitan.a \
|
||||||
-mno-red-zone \
|
-o $@
|
||||||
-fno-omit-frame-pointer \
|
|
||||||
-Wl,-T,o/$(MODE)/ape/ape.lds \
|
o/$(MODE)/test/libc/release/smokecxx.o: \
|
||||||
-include o/cosmopolitan.h \
|
test/libc/release/smokecxx.cc \
|
||||||
test/libc/release/smoke.c \
|
o/cosmopolitan.h
|
||||||
o/$(MODE)/libc/crt/crt.o \
|
@$(COMPILE) -ACXX $(CXX) \
|
||||||
o/$(MODE)/ape/ape.o \
|
-o $@ \
|
||||||
|
-c \
|
||||||
|
-Os \
|
||||||
|
-fno-pie \
|
||||||
|
-nostdinc \
|
||||||
|
-fno-omit-frame-pointer \
|
||||||
|
-include o/cosmopolitan.h \
|
||||||
|
test/libc/release/smokecxx.cc
|
||||||
|
|
||||||
|
o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
|
||||||
|
o/$(MODE)/test/libc/release/smokeansi.o \
|
||||||
|
o/$(MODE)/ape/ape.lds \
|
||||||
|
o/$(MODE)/libc/crt/crt.o \
|
||||||
|
o/$(MODE)/ape/ape.o \
|
||||||
o/$(MODE)/cosmopolitan.a
|
o/$(MODE)/cosmopolitan.a
|
||||||
|
@$(COMPILE) -ALD $(LD) \
|
||||||
|
-static \
|
||||||
|
-no-pie \
|
||||||
|
-nostdlib \
|
||||||
|
-T o/$(MODE)/ape/ape.lds \
|
||||||
|
o/$(MODE)/test/libc/release/smokeansi.o \
|
||||||
|
o/$(MODE)/libc/crt/crt.o \
|
||||||
|
o/$(MODE)/ape/ape.o \
|
||||||
|
o/$(MODE)/cosmopolitan.a \
|
||||||
|
-o $@
|
||||||
|
|
||||||
|
o/$(MODE)/test/libc/release/smokeansi.o: \
|
||||||
|
test/libc/release/smoke.c \
|
||||||
|
o/cosmopolitan.h
|
||||||
|
@$(COMPILE) -AANSI $(CC) \
|
||||||
|
-o $@ \
|
||||||
|
-c \
|
||||||
|
-Os \
|
||||||
|
-ansi \
|
||||||
|
-static \
|
||||||
|
-fno-pie \
|
||||||
|
-nostdinc \
|
||||||
|
-fno-omit-frame-pointer \
|
||||||
|
-include o/cosmopolitan.h \
|
||||||
|
test/libc/release/smoke.c
|
||||||
|
|
||||||
# TODO(jart): Rewrite these shell scripts as C code.
|
# TODO(jart): Rewrite these shell scripts as C code.
|
||||||
# o/$(MODE)/test/libc/release/metal.ok: \
|
# o/$(MODE)/test/libc/release/metal.ok: \
|
||||||
# test/libc/release/metal.sh \
|
# test/libc/release/metal.sh \
|
||||||
# o/$(MODE)/examples/hello.com \
|
# o/$(MODE)/examples/hello.com \
|
||||||
# o/$(MODE)/tool/build/blinkenlights.com.dbg
|
# o/$(MODE)/tool/build/blinkenlights.com.dbg
|
||||||
# @$(COMPILE) -ASHTEST -tT$@ $<
|
# @$(COMPILE) -ASHTEST -tT$@ $<
|
||||||
# o/$(MODE)/test/libc/release/emulate.ok: \
|
# o/$(MODE)/test/libc/release/emulate.ok: \
|
||||||
# test/libc/release/emulate.sh \
|
# test/libc/release/emulate.sh \
|
||||||
# o/$(MODE)/examples/hello.com \
|
# o/$(MODE)/examples/hello.com \
|
||||||
# o/$(MODE)/tool/build/blinkenlights.com.dbg
|
# o/$(MODE)/tool/build/blinkenlights.com.dbg
|
||||||
# @$(COMPILE) -ASHTEST -tT$@ $<
|
# @$(COMPILE) -ASHTEST -tT$@ $<
|
||||||
|
|
||||||
.PHONY: o/$(MODE)/test/libc/release
|
.PHONY: o/$(MODE)/test/libc/release
|
||||||
o/$(MODE)/test/libc/release: \
|
o/$(MODE)/test/libc/release: \
|
||||||
o/$(MODE)/test/libc/release/smoke.com \
|
o/$(MODE)/test/libc/release/smoke.com \
|
||||||
o/$(MODE)/test/libc/release/smoke.com.runs \
|
o/$(MODE)/test/libc/release/smoke.com.runs \
|
||||||
o/$(MODE)/test/libc/release/smoke-nms.com \
|
o/$(MODE)/test/libc/release/smoke-nms.com \
|
||||||
o/$(MODE)/test/libc/release/smoke-nms.com.runs \
|
o/$(MODE)/test/libc/release/smoke-nms.com.runs \
|
||||||
o/$(MODE)/test/libc/release/smokecxx.com \
|
o/$(MODE)/test/libc/release/smoke-chibicc.com \
|
||||||
o/$(MODE)/test/libc/release/smokecxx.com.runs \
|
o/$(MODE)/test/libc/release/smoke-chibicc.com.runs \
|
||||||
o/$(MODE)/test/libc/release/smokeansi.com \
|
o/$(MODE)/test/libc/release/smokecxx.com \
|
||||||
|
o/$(MODE)/test/libc/release/smokecxx.com.runs \
|
||||||
|
o/$(MODE)/test/libc/release/smokeansi.com \
|
||||||
o/$(MODE)/test/libc/release/smokeansi.com.runs
|
o/$(MODE)/test/libc/release/smokeansi.com.runs
|
||||||
|
|
2
third_party/chibicc/asm.c
vendored
2
third_party/chibicc/asm.c
vendored
|
@ -285,7 +285,7 @@ static void CouldNotAllocateRegister(AsmOperand *op, const char *kind) {
|
||||||
|
|
||||||
static void PickAsmRegisters(Asm *a) {
|
static void PickAsmRegisters(Asm *a) {
|
||||||
int i, j, m, pick, regset, xmmset, x87sts;
|
int i, j, m, pick, regset, xmmset, x87sts;
|
||||||
regset = 0b1111111111000111; // exclude bx,sp,bp
|
regset = 0b1111111111001111; // exclude bx,sp,bp
|
||||||
xmmset = 0b1111111111111111;
|
xmmset = 0b1111111111111111;
|
||||||
x87sts = 0b0000000011111111;
|
x87sts = 0b0000000011111111;
|
||||||
regset ^= regset & a->regclob; // don't allocate from clobber list
|
regset ^= regset & a->regclob; // don't allocate from clobber list
|
||||||
|
|
21
third_party/chibicc/chibicc.c
vendored
21
third_party/chibicc/chibicc.c
vendored
|
@ -1,6 +1,7 @@
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/struct/siginfo.h"
|
#include "libc/calls/struct/siginfo.h"
|
||||||
#include "libc/calls/ucontext.h"
|
#include "libc/calls/ucontext.h"
|
||||||
|
#include "libc/intrin/kprintf.h"
|
||||||
#include "libc/runtime/gc.internal.h"
|
#include "libc/runtime/gc.internal.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/x/x.h"
|
#include "libc/x/x.h"
|
||||||
|
@ -264,9 +265,9 @@ static void parse_args(int argc, char **argv) {
|
||||||
} else if (!strncmp(argv[i], "-x", 2)) {
|
} else if (!strncmp(argv[i], "-x", 2)) {
|
||||||
opt_x = parse_opt_x(argv[i] + 2);
|
opt_x = parse_opt_x(argv[i] + 2);
|
||||||
} else if (startswith(argv[i], "-Wa")) {
|
} else if (startswith(argv[i], "-Wa")) {
|
||||||
strarray_push_comma(&as_extra_args, argv[i]);
|
strarray_push_comma(&as_extra_args, argv[i] + 3);
|
||||||
} else if (startswith(argv[i], "-Wl")) {
|
} else if (startswith(argv[i], "-Wl")) {
|
||||||
strarray_push_comma(&ld_extra_args, argv[i]);
|
strarray_push_comma(&ld_extra_args, argv[i] + 3);
|
||||||
} else if (!strcmp(argv[i], "-Xassembler")) {
|
} else if (!strcmp(argv[i], "-Xassembler")) {
|
||||||
strarray_push(&as_extra_args, argv[++i]);
|
strarray_push(&as_extra_args, argv[++i]);
|
||||||
} else if (!strcmp(argv[i], "-Xlinker")) {
|
} else if (!strcmp(argv[i], "-Xlinker")) {
|
||||||
|
@ -447,8 +448,7 @@ static bool run_subprocess(char **argv) {
|
||||||
_Exit(1);
|
_Exit(1);
|
||||||
}
|
}
|
||||||
// Wait for the child process to finish.
|
// Wait for the child process to finish.
|
||||||
do
|
do rc = wait(&ws);
|
||||||
rc = wait(&ws);
|
|
||||||
while (rc == -1 && errno == EINTR);
|
while (rc == -1 && errno == EINTR);
|
||||||
return WIFEXITED(ws) && WEXITSTATUS(ws) == 0;
|
return WIFEXITED(ws) && WEXITSTATUS(ws) == 0;
|
||||||
}
|
}
|
||||||
|
@ -657,27 +657,28 @@ static void run_linker(StringArray *inputs, char *output) {
|
||||||
if (!ld || !*ld) ld = "ld";
|
if (!ld || !*ld) ld = "ld";
|
||||||
StringArray arr = {0};
|
StringArray arr = {0};
|
||||||
strarray_push(&arr, ld);
|
strarray_push(&arr, ld);
|
||||||
strarray_push(&arr, "-o");
|
|
||||||
strarray_push(&arr, output);
|
|
||||||
strarray_push(&arr, "-m");
|
strarray_push(&arr, "-m");
|
||||||
strarray_push(&arr, "elf_x86_64");
|
strarray_push(&arr, "elf_x86_64");
|
||||||
strarray_push(&arr, "-z");
|
strarray_push(&arr, "-z");
|
||||||
strarray_push(&arr, "max-page-size=0x1000");
|
strarray_push(&arr, "max-page-size=0x1000");
|
||||||
|
strarray_push(&arr, "-static");
|
||||||
strarray_push(&arr, "-nostdlib");
|
strarray_push(&arr, "-nostdlib");
|
||||||
strarray_push(&arr, "--gc-sections");
|
strarray_push(&arr, "--gc-sections");
|
||||||
strarray_push(&arr, "--build-id=none");
|
strarray_push(&arr, "--build-id=none");
|
||||||
strarray_push(&arr, "--no-dynamic-linker");
|
strarray_push(&arr, "--no-dynamic-linker");
|
||||||
strarray_push(&arr, xasprintf("-Ttext-segment=%#x", IMAGE_BASE_VIRTUAL));
|
strarray_push(&arr, xasprintf("-Ttext-segment=%#x", IMAGE_BASE_VIRTUAL));
|
||||||
strarray_push(&arr, "-T");
|
/* strarray_push(&arr, "-T"); */
|
||||||
strarray_push(&arr, LDS);
|
/* strarray_push(&arr, LDS); */
|
||||||
strarray_push(&arr, APE);
|
/* strarray_push(&arr, APE); */
|
||||||
strarray_push(&arr, CRT);
|
/* strarray_push(&arr, CRT); */
|
||||||
for (int i = 0; i < ld_extra_args.len; i++) {
|
for (int i = 0; i < ld_extra_args.len; i++) {
|
||||||
strarray_push(&arr, ld_extra_args.data[i]);
|
strarray_push(&arr, ld_extra_args.data[i]);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < inputs->len; i++) {
|
for (int i = 0; i < inputs->len; i++) {
|
||||||
strarray_push(&arr, inputs->data[i]);
|
strarray_push(&arr, inputs->data[i]);
|
||||||
}
|
}
|
||||||
|
strarray_push(&arr, "-o");
|
||||||
|
strarray_push(&arr, output);
|
||||||
handle_exit(run_subprocess(arr.data));
|
handle_exit(run_subprocess(arr.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
52
third_party/xed/x86.h
vendored
52
third_party/xed/x86.h
vendored
|
@ -202,31 +202,33 @@ struct XedDecodedInst {
|
||||||
struct XedOperands op;
|
struct XedOperands op;
|
||||||
};
|
};
|
||||||
|
|
||||||
forceinline void xed_operands_set_mode(struct XedOperands *p, int mmode) {
|
#define xed_operands_set_mode(p, machine_mode) \
|
||||||
p->realmode = false;
|
do { \
|
||||||
switch (mmode) {
|
struct XedOperands *__p = p; \
|
||||||
default:
|
__p->realmode = false; \
|
||||||
case XED_MACHINE_MODE_LONG_64:
|
switch (machine_mode) { \
|
||||||
p->mode = XED_MODE_LONG;
|
default: \
|
||||||
return;
|
case XED_MACHINE_MODE_LONG_64: \
|
||||||
case XED_MACHINE_MODE_LEGACY_32:
|
__p->mode = XED_MODE_LONG; \
|
||||||
case XED_MACHINE_MODE_LONG_COMPAT_32:
|
break; \
|
||||||
p->mode = XED_MODE_LEGACY;
|
case XED_MACHINE_MODE_LEGACY_32: \
|
||||||
break;
|
case XED_MACHINE_MODE_LONG_COMPAT_32: \
|
||||||
case XED_MACHINE_MODE_REAL:
|
__p->mode = XED_MODE_LEGACY; \
|
||||||
p->realmode = true;
|
break; \
|
||||||
p->mode = XED_MODE_REAL;
|
case XED_MACHINE_MODE_REAL: \
|
||||||
break;
|
__p->realmode = true; \
|
||||||
case XED_MACHINE_MODE_UNREAL:
|
__p->mode = XED_MODE_REAL; \
|
||||||
p->realmode = true;
|
break; \
|
||||||
p->mode = XED_MODE_LEGACY;
|
case XED_MACHINE_MODE_UNREAL: \
|
||||||
break;
|
__p->realmode = true; \
|
||||||
case XED_MACHINE_MODE_LEGACY_16:
|
__p->mode = XED_MODE_LEGACY; \
|
||||||
case XED_MACHINE_MODE_LONG_COMPAT_16:
|
break; \
|
||||||
p->mode = XED_MODE_REAL;
|
case XED_MACHINE_MODE_LEGACY_16: \
|
||||||
break;
|
case XED_MACHINE_MODE_LONG_COMPAT_16: \
|
||||||
}
|
__p->mode = XED_MODE_REAL; \
|
||||||
}
|
break; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
extern const char kXedErrorNames[];
|
extern const char kXedErrorNames[];
|
||||||
extern const uint8_t kXedEamode[2][3];
|
extern const uint8_t kXedEamode[2][3];
|
||||||
|
|
74
third_party/xed/x86isa.h
vendored
74
third_party/xed/x86isa.h
vendored
|
@ -211,42 +211,44 @@ struct XedChipFeatures {
|
||||||
uint64_t f[3];
|
uint64_t f[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
forceinline void xed_set_chip_modes(struct XedDecodedInst *d, int chip) {
|
#define xed_set_chip_modes(d, chip) \
|
||||||
switch (chip) {
|
do { \
|
||||||
case XED_CHIP_INVALID:
|
struct XedDecodedInst *__d = d; \
|
||||||
break;
|
switch (chip) { \
|
||||||
case XED_CHIP_I86:
|
case XED_CHIP_INVALID: \
|
||||||
case XED_CHIP_I86FP:
|
break; \
|
||||||
case XED_CHIP_I186:
|
case XED_CHIP_I86: \
|
||||||
case XED_CHIP_I186FP:
|
case XED_CHIP_I86FP: \
|
||||||
case XED_CHIP_I286REAL:
|
case XED_CHIP_I186: \
|
||||||
case XED_CHIP_I286:
|
case XED_CHIP_I186FP: \
|
||||||
case XED_CHIP_I2186FP:
|
case XED_CHIP_I286REAL: \
|
||||||
case XED_CHIP_I386REAL:
|
case XED_CHIP_I286: \
|
||||||
case XED_CHIP_I386:
|
case XED_CHIP_I2186FP: \
|
||||||
case XED_CHIP_I386FP:
|
case XED_CHIP_I386REAL: \
|
||||||
case XED_CHIP_I486REAL:
|
case XED_CHIP_I386: \
|
||||||
case XED_CHIP_I486:
|
case XED_CHIP_I386FP: \
|
||||||
case XED_CHIP_QUARK:
|
case XED_CHIP_I486REAL: \
|
||||||
case XED_CHIP_PENTIUM:
|
case XED_CHIP_I486: \
|
||||||
case XED_CHIP_PENTIUMREAL:
|
case XED_CHIP_QUARK: \
|
||||||
case XED_CHIP_PENTIUMMMX:
|
case XED_CHIP_PENTIUM: \
|
||||||
case XED_CHIP_PENTIUMMMXREAL:
|
case XED_CHIP_PENTIUMREAL: \
|
||||||
d->op.mode_first_prefix = 1;
|
case XED_CHIP_PENTIUMMMX: \
|
||||||
break;
|
case XED_CHIP_PENTIUMMMXREAL: \
|
||||||
default:
|
__d->op.mode_first_prefix = 1; \
|
||||||
break;
|
break; \
|
||||||
}
|
default: \
|
||||||
switch (chip) {
|
break; \
|
||||||
case XED_CHIP_INVALID:
|
} \
|
||||||
case XED_CHIP_ALL:
|
switch (chip) { \
|
||||||
case XED_CHIP_AMD:
|
case XED_CHIP_INVALID: \
|
||||||
break;
|
case XED_CHIP_ALL: \
|
||||||
default:
|
case XED_CHIP_AMD: \
|
||||||
d->op.is_intel_specific = 1;
|
break; \
|
||||||
break;
|
default: \
|
||||||
}
|
__d->op.is_intel_specific = 1; \
|
||||||
}
|
break; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
extern const uint64_t kXedChipFeatures[XED_CHIP_LAST][3];
|
extern const uint64_t kXedChipFeatures[XED_CHIP_LAST][3];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue