Skip to content

Commit

Permalink
Merge pull request #702 from FedorLap2006/x86
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke authored Dec 30, 2023
2 parents efbb2e1 + a30b3c1 commit e57f5f6
Show file tree
Hide file tree
Showing 63 changed files with 1,457 additions and 119 deletions.
51 changes: 48 additions & 3 deletions abis/linux/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,28 @@ typedef struct __stack {
#define SI_USER 0
#define SI_KERNEL 128

#if defined(__i386__)
#define REG_GS 0
#define REG_FS 1
#define REG_ES 2
#define REG_DS 3
#define REG_EDI 4
#define REG_ESI 5
#define REG_EBP 6
#define REG_ESP 7
#define REG_EBX 8
#define REG_EDX 9
#define REG_ECX 10
#define REG_EAX 11
#define REG_TRAPNO 12
#define REG_ERR 13
#define REG_EIP 14
#define REG_CS 15
#define REG_EFL 16
#define REG_UESP 17
#define REG_SS 18
#define NGREG 19
#elif defined(__x86_64__)
#define REG_R8 0
#define REG_R9 1
#define REG_R10 2
Expand All @@ -217,6 +239,8 @@ typedef struct __stack {
#define REG_TRAPNO 20
#define REG_OLDMASK 21
#define REG_CR2 22
#define NGREG 23
#endif

struct sigevent {
union sigval sigev_value;
Expand All @@ -240,9 +264,7 @@ struct sigaction {

// Taken from the linux kernel headers

#if defined(__x86_64__)

#define NGREG 23
#if defined(__x86_64__) || defined(__i386__)

struct _fpreg {
unsigned short significand[4];
Expand All @@ -260,6 +282,7 @@ struct _xmmreg {
};

struct _fpstate {
#if defined(__x86_64__)
uint16_t cwd;
uint16_t swd;
uint16_t ftw;
Expand All @@ -271,6 +294,28 @@ struct _fpstate {
struct _fpxreg _st[8];
struct _xmmreg _xmm[16];
uint32_t padding[24];
#elif defined(__i386__)
uint32_t cw;
uint32_t sw;
uint32_t tag;
uint32_t ipoff;
uint32_t cssel;
uint32_t dataoff;
uint32_t datasel;
struct _fpreg _st[8];
uint16_t status;
uint16_t magic;

// FXSR FPU

uint32_t _fxsr_env[6];
uint32_t mxscr;
uint32_t reserved;
struct _fpxreg _fxsr_st[8];
struct _xmmreg _xmm[8];

uint32_t padding2[56];
#endif
};

typedef struct {
Expand Down
25 changes: 25 additions & 0 deletions abis/linux/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,31 @@ struct stat {
unsigned int __unused5;
};

#elif defined(__i386__)

struct stat {
dev_t st_dev;
int __st_dev_padding;
long __st_ino_truncated;
mode_t st_mode;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
int __st_rdev_padding;
off_t st_size;
blksize_t st_blksize;
blkcnt_t st_blocks;
struct {
long tv_sec;
long tv_nsec;
} __st_atim32, __st_mtim32, __st_ctim32;
ino_t st_ino;
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
};

#endif

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion abis/linux/suseconds_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

#include <bits/types.h>

typedef __mlibc_int64 suseconds_t;
typedef long suseconds_t;

#endif /* _ABIBITS_SUSECONDS_T_H */
6 changes: 3 additions & 3 deletions abis/mlibc/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <abi-bits/pid_t.h>
#include <abi-bits/uid_t.h>
#include <bits/types.h>
#include <bits/size_t.h>

union sigval {
Expand Down Expand Up @@ -94,8 +95,7 @@ typedef void (*__sighandler) (int);
#define SEGV_MAPERR 1
#define SEGV_ACCERR 2

// TODO: replace this by uint64_t
typedef long sigset_t;
typedef __mlibc_uint64 sigset_t;

#define SIGUNUSED SIGSYS

Expand Down Expand Up @@ -163,7 +163,7 @@ struct sigaction {
void (*sa_sigaction)(int, siginfo_t *, void *);
};

#if defined(__x86_64__) || defined(__aarch64__)
#if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__)
// TODO: This is wrong for AArch64.

typedef struct {
Expand Down
7 changes: 6 additions & 1 deletion ci/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ packages:
configure:
- args:
- 'meson'
- 'setup'
- '--prefix=/usr'
- '--libdir=lib'
- '--buildtype=debugoptimized'
Expand Down Expand Up @@ -54,6 +55,7 @@ packages:
configure:
- args:
- 'meson'
- 'setup'
- '--prefix=/usr'
- '--libdir=lib'
- '--buildtype=debugoptimized'
Expand All @@ -80,6 +82,7 @@ packages:
configure:
- args:
- 'meson'
- 'setup'
- '--prefix=/usr'
- '--libdir=lib'
- '--buildtype=debugoptimized'
Expand Down Expand Up @@ -107,6 +110,7 @@ packages:
configure:
- args:
- 'meson'
- 'setup'
- '--prefix=/usr'
- '--libdir=lib'
- '--buildtype=debugoptimized'
Expand Down Expand Up @@ -138,6 +142,7 @@ packages:
configure:
- args:
- 'meson'
- 'setup'
- '--prefix=/usr'
- '--libdir=lib'
- '--buildtype=debugoptimized'
Expand All @@ -161,7 +166,7 @@ packages:
from_source: linux
configure:
# custom build system requires in tree-ish builds
- args: ['cp', '-Tr', '@THIS_SOURCE_DIR@', '.']
- args: ['cp', '-Tr', '@THIS_SOURCE_DIR@/', '.']
build:
- args: |
LINUX_ARCH="@OPTION:arch@"
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ internal_sources = [
]

internal_dso_sources = [
'options/internal/gcc-extra/mlibc_crtbegin.S',
'options/internal' / host_machine.cpu_family() / 'mlibc_crtbegin.S',
'options/internal' / host_machine.cpu_family() / 'mlibc_crtend.S',
]

Expand Down
5 changes: 3 additions & 2 deletions options/ansi/include/bits/ansi/fenv.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#ifndef MLIBC_FENV_H
#define MLIBC_FENV_H

#if defined(__x86_64__)
#if defined(__x86_64__) || defined(__i386__)

#define FE_DENORMAL 2
#define FE_DIVBYZERO 4
#define FE_INEXACT 32
#define FE_INVALID 1
#define FE_OVERFLOW 8
#define FE_UNDERFLOW 16

#define FE_ALL_EXCEPT 63
#define FE_ALL_EXCEPT (FE_DENORMAL | FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)

#define FE_TONEAREST 0
#define FE_DOWNWARD 0x400
Expand Down
82 changes: 45 additions & 37 deletions options/ansi/include/inttypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
/* gate behind !__MLIBC_ABI_ONLY */
#ifndef __MLIBC_ABI_ONLY

#if UINTPTR_MAX == UINT64_MAX
# define __PRI64 "l"
# define __PRIPTR "l"
#else
# define __PRI64 "ll"
# define __PRIPTR ""
#endif

// TODO: This is extremly unelegant and fragile.
#define PRId8 "d"
#define PRIi8 "i"
Expand All @@ -26,16 +34,16 @@
#define PRIiLEAST32 "i"
#define PRIdFAST32 "ld"
#define PRIiFAST32 "li"
#define PRId64 "ld"
#define PRIi64 "li"
#define PRIdLEAST64 "ld"
#define PRIiLEAST64 "li"
#define PRIdFAST64 "ld"
#define PRIiFAST64 "li"
#define PRIdMAX "ld"
#define PRIiMAX "li"
#define PRIdPTR "ld"
#define PRIiPTR "li"
#define PRId64 __PRI64 "d"
#define PRIi64 __PRI64 "i"
#define PRIdLEAST64 __PRI64 "d"
#define PRIiLEAST64 __PRI64 "i"
#define PRIdFAST64 __PRI64 "d"
#define PRIiFAST64 __PRI64 "i"
#define PRIdMAX __PRI64 "d"
#define PRIiMAX __PRI64 "i"
#define PRIdPTR __PRIPTR "d"
#define PRIiPTR __PRIPTR "i"
#define PRIo8 "o"
#define PRIu8 "u"
#define PRIx8 "x"
Expand Down Expand Up @@ -72,42 +80,42 @@
#define PRIuFAST32 "lu"
#define PRIxFAST32 "lx"
#define PRIXFAST32 "lX"
#define PRIo64 "lo"
#define PRIu64 "lu"
#define PRIx64 "lx"
#define PRIX64 "lX"
#define PRIoLEAST64 "lo"
#define PRIuLEAST64 "lu"
#define PRIxLEAST64 "lx"
#define PRIXLEAST64 "lX"
#define PRIoFAST64 "lo"
#define PRIuFAST64 "lu"
#define PRIxFAST64 "lx"
#define PRIXFAST64 "lX"
#define PRIoMAX "lo"
#define PRIuMAX "lu"
#define PRIxMAX "lx"
#define PRIXMAX "lX"
#define PRIoPTR "lo"
#define PRIuPTR "lu"
#define PRIxPTR "lx"
#define PRIXPTR "lX"
#define PRIo64 __PRI64 "o"
#define PRIu64 __PRI64 "u"
#define PRIx64 __PRI64 "x"
#define PRIX64 __PRI64 "X"
#define PRIoLEAST64 __PRI64 "o"
#define PRIuLEAST64 __PRI64 "u"
#define PRIxLEAST64 __PRI64 "x"
#define PRIXLEAST64 __PRI64 "X"
#define PRIoFAST64 __PRI64 "o"
#define PRIuFAST64 __PRI64 "u"
#define PRIxFAST64 __PRI64 "x"
#define PRIXFAST64 __PRI64 "X"
#define PRIoMAX __PRI64 "o"
#define PRIuMAX __PRI64 "u"
#define PRIxMAX __PRI64 "x"
#define PRIXMAX __PRI64 "X"
#define PRIoPTR __PRIPTR "o"
#define PRIuPTR __PRIPTR "u"
#define PRIxPTR __PRIPTR "x"
#define PRIXPTR __PRIPTR "X"

#define SCNu32 "u"
#define SCNu64 "lu"
#define SCNuMAX "lu"
#define SCNu64 __PRI64 "u"
#define SCNuMAX __PRI64 "u"
#define SCNx16 "hx"
#define SCNx32 "x"
#define SCNx64 "lx"
#define SCNxMAX "lx"
#define SCNx64 __PRI64 "x"
#define SCNxMAX __PRI64 "x"
#define SCNi8 "hhi"
#define SCNxPTR "lx"
#define SCNxPTR __PRIPTR "x"

#define SCNi8 "hhi"
#define SCNi64 "li"
#define SCNi64 __PRI64 "i"

#define SCNd32 "d"
#define SCNd64 "ld"
#define SCNd64 __PRI64 "d"

#endif /* !__MLIBC_ABI_ONLY */

Expand Down
2 changes: 1 addition & 1 deletion options/ansi/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,5 @@ if not headers_only
'musl-generic-math/truncl.c',
pic: true,
include_directories: libc_include_dirs,
c_args: ['-Wno-unused', '-Wno-implicit', '-Wno-parentheses', '-Wno-sign-compare', '-Wno-attributes', '-Wno-unknown-pragmas'])
c_args: ['-Wno-unused', '-Wno-implicit', '-Wno-parentheses', '-Wno-sign-compare', '-Wno-attributes', '-Wno-unknown-pragmas', '-Wno-maybe-uninitialized'])
endif
File renamed without changes.
5 changes: 3 additions & 2 deletions options/internal/aarch64/setjmp.S
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ longjmp:
ldp d12, d13, [x0, #144]
ldp d14, d15, [x0, #160]

mov x0, x1
ret
cmp w1, 0
csinc w0, w1, wzr, ne
br x30
.section .note.GNU-stack,"",%progbits

4 changes: 4 additions & 0 deletions options/internal/gcc-extra/cxxabi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
__ensure(!"operator delete called! delete expressions cannot be used in mlibc.");
}
#else
extern "C" [[gnu::visibility("hidden")]] void _ZdlPvj() { // operator delete (void *, unsigned int)
__ensure(!"operator delete called! delete expressions cannot be used in mlibc.");
}

extern "C" [[gnu::visibility("hidden")]] void _ZdlPvm() { // operator delete (void *, size_t)
__ensure(!"operator delete called! delete expressions cannot be used in mlibc.");
}
Expand Down
8 changes: 7 additions & 1 deletion options/internal/gcc/stack_protector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ void initStackGuard(void *entropy) {

} // namespace mlibc

extern "C" void __stack_chk_fail() {
extern "C" [[noreturn]] void __stack_chk_fail() {
mlibc::panicLogger() << "Stack smashing detected!" << frg::endlog;
__builtin_unreachable();
}

extern "C" [[noreturn, gnu::visibility("hidden")]] void __stack_chk_fail_local() {
__stack_chk_fail();
};

6 changes: 6 additions & 0 deletions options/internal/include/bits/ssize_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
#define MLIBC_SSIZE_T_H

// TODO: use ptrdiff_t instead?
#if __UINTPTR_MAX__ == __UINT64_MAX__
typedef long ssize_t;
#elif __UINTPTR_MAX__ == __UINT32_MAX__
typedef int ssize_t;
#else
#error "unsupported architecture"
#endif

#endif // MLIBC_SSIZE_T_H

Loading

0 comments on commit e57f5f6

Please sign in to comment.