ref: ea04c68f2bd28d6c75d21688a07ac6b817192b67
parent: 789b8fe40e156ad0252230b13dd4ada96f3eed8b
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Wed Oct 2 21:13:53 EDT 2024
remove non-portable posix stuff, use C compiler builtins instead (thanks be0ba and thedæmon for testing)
--- a/Make.android-386
+++ b/Make.android-386
@@ -19,8 +19,3 @@
AUDIO=none
all: default
-
-libmachdep.a:
- arch=386; \
- (cd posix-$$arch && make)
-
--- a/Make.android-amd64
+++ b/Make.android-amd64
@@ -19,8 +19,3 @@
AUDIO=none
all: default
-
-libmachdep.a:
- arch=amd64; \
- (cd posix-$$arch && make)
-
--- a/Make.android-arm
+++ b/Make.android-arm
@@ -20,7 +20,3 @@
all: default
-libmachdep.a:
- arch=arm; \
- (cd posix-$$arch && make)
-
--- a/Make.android-arm64
+++ b/Make.android-arm64
@@ -19,8 +19,3 @@
AUDIO=none
all: default
-
-libmachdep.a:
- arch=arm64; \
- (cd posix-$$arch && make)
-
--- a/Make.dragonfly
+++ b/Make.dragonfly
@@ -15,7 +15,3 @@
AUDIO=none
all: default
-
-libmachdep.a:
- arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/'`; \
- (cd posix-$$arch && make)
--- a/Make.fbdev
+++ b/Make.fbdev
@@ -16,7 +16,3 @@
AUDIO=alsa
all: default
-
-libmachdep.a:
- arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/'`; \
- (cd posix-$$arch && make)
--- a/Make.freebsd
+++ b/Make.freebsd
@@ -15,7 +15,3 @@
AUDIO=unix
all: default
-
-libmachdep.a:
- arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/'`; \
- (cd posix-$$arch && make)
--- a/Make.haiku
+++ b/Make.haiku
@@ -13,9 +13,4 @@
LDFLAGS=
TARG=drawterm
-
all: default
-
-libmachdep.a:
- arch=`uname -m|sed 's/BePC/386/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/'`; \
- (cd posix-$$arch && make)
--- a/Make.irix
+++ b/Make.irix
@@ -19,6 +19,3 @@
MAKE=gmake
all: default
-
-libmachdep.a:
- (cd posix-mips && $(MAKE))
--- a/Make.linux
+++ b/Make.linux
@@ -15,7 +15,3 @@
AUDIO=pipewire
all: default
-
-libmachdep.a:
- arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/'`; \
- (cd posix-$$arch && make)
--- a/Make.linux386
+++ b/Make.linux386
@@ -16,7 +16,3 @@
AUDIO=unix
all: default
-
-libmachdep.a:
- arch=386; \
- (cd posix-$$arch && make)
--- a/Make.netbsd
+++ b/Make.netbsd
@@ -16,7 +16,3 @@
all: default
-libmachdep.a:
- arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/'`; \
- (cd posix-$$arch && make)
-
--- a/Make.openbsd
+++ b/Make.openbsd
@@ -14,7 +14,3 @@
AUDIO=sndio
all: default
-
-libmachdep.a:
- arch=`uname -m|sed 's/i.86/386/; s/macppc/power/; s/socppc/power/; s/x86_64/amd64/; s/sparc64/sun4u/'`; \
- (cd posix-$$arch && make)
--- a/Make.osx-cocoa
+++ b/Make.osx-cocoa
@@ -14,7 +14,3 @@
AUDIO=none
all: default
-
-libmachdep.a:
- arch=`uname -m|sed 's/i.86/386/;s/x86_64/amd64/'`; \
- (cd posix-$$arch && make)
--- a/Make.osx-x11
+++ b/Make.osx-x11
@@ -15,7 +15,3 @@
AUDIO=none
all: default
-
-libmachdep.a:
- arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/'`; \
- (cd posix-$$arch && make)
--- a/Make.pthread
+++ b/Make.pthread
@@ -17,7 +17,3 @@
AUDIO=unix
all: default
-
-libmachdep.a:
- arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/'`; \
- (cd posix-$$arch && make)
--- a/Make.sun
+++ b/Make.sun
@@ -15,7 +15,3 @@
AUDIO=none
all: default
-
-libmachdep.a:
- arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/'`; \
- (cd posix-$$arch && make)
--- a/Make.unix
+++ b/Make.unix
@@ -17,7 +17,3 @@
AUDIO=unix
all: default
-
-libmachdep.a:
- arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/; s/armv[567].*/arm/; s/aarch64/arm64/'`; \
- (cd posix-$$arch && make)
--- a/Make.win32
+++ b/Make.win32
@@ -33,10 +33,6 @@
all: default
-# for root
-libmachdep.a:
- (cd win32-386; make)
-
glenda-t.$O: glenda-t.rc glenda-t.ico
$(WINDRES) -i glenda-t.rc -o glenda-t.o
--- a/Make.win64
+++ b/Make.win64
@@ -23,10 +23,5 @@
all: default
-# for root
-libmachdep.a:
- (cd posix-amd64; make)
-
glenda-t.$O: glenda-t.rc glenda-t.ico
$(WINDRES) -i glenda-t.rc -o glenda-t.o
-
--- a/Makefile
+++ b/Makefile
@@ -38,6 +38,9 @@
clean:
rm -f *.o */*.o */*.a *.a drawterm drawterm.exe
+libmachdep.a:
+ (cd posix-port; $(MAKE))
+
kern/libkern.a:
(cd kern; $(MAKE))
--- a/posix-386/Makefile
+++ /dev/null
@@ -1,18 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-
-OFILES=\
- getcallerpc.$O\
- tas.$O
-
-default: $(LIB)
-$(LIB): $(OFILES)
- $(AR) r $(LIB) $(OFILES)
- $(RANLIB) $(LIB)
-
-%.$O: %.c
- $(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
- $(AS) -o $*.$O $*.s
--- a/posix-386/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
- return ((uintptr*)a)[-1];
-}
--- a/posix-386/tas.c
+++ /dev/null
@@ -1,23 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-int
-tas(int *x)
-{
- int v;
-
- __asm__( "movl $1, %%eax\n\t"
- "xchgl %%eax,(%%ecx)"
- : "=a" (v)
- : "c" (x)
- );
- switch(v) {
- case 0:
- case 1:
- return v;
- default:
- print("canlock: corrupted 0x%lux\n", v);
- return 1;
- }
-}
-
--- a/posix-amd64/Makefile
+++ /dev/null
@@ -1,15 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-
-OFILES=\
- getcallerpc.$O\
- tas.$O
-
-default: $(LIB)
-$(LIB): $(OFILES)
- $(AR) r $(LIB) $(OFILES)
- $(RANLIB) $(LIB)
-
-%.$O: %.c
- $(CC) $(CFLAGS) $*.c
--- a/posix-amd64/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
- return ((uintptr*)a)[-1];
-}
--- a/posix-amd64/tas.c
+++ /dev/null
@@ -1,23 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-int
-tas(int *x)
-{
- int v;
-
- __asm__( "movl $1, %%eax\n\t"
- "xchgl %%eax,(%%rcx)"
- : "=a" (v)
- : "c" (x)
- );
- switch(v) {
- case 0:
- case 1:
- return v;
- default:
- print("canlock: corrupted 0x%lux\n", v);
- return 1;
- }
-}
-
--- a/posix-arm/Makefile
+++ /dev/null
@@ -1,23 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-
-OFILES=\
- getcallerpc.$O\
- tas.$O
-
-default: $(LIB)
-$(LIB): $(OFILES)
- $(AR) r $(LIB) $(OFILES)
- $(RANLIB) $(LIB)
-
-%.$O: %.c
- $(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
- $(AS) -o $*.$O $*.s
-
-%.s: %.spp
- cpp $*.spp >$*.s
-
-
--- a/posix-arm/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
- return ((uintptr*)a)[-1];
-}
--- a/posix-arm/tas.c
+++ /dev/null
@@ -1,35 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-int
-tas(int *x)
-{
- int v, t, i = 1;
-
-#if ARMv5
- __asm__(
- "swp %0, %1, [%2]"
- : "=&r" (v)
- : "r" (1), "r" (x)
- : "memory"
- );
-#else
- __asm__ (
- "1: ldrex %0, [%2]\n"
- " strex %1, %3, [%2]\n"
- " teq %1, #0\n"
- " bne 1b"
- : "=&r" (v), "=&r" (t)
- : "r" (x), "r" (i)
- : "cc");
-#endif
- switch(v) {
- case 0:
- case 1:
- return v;
- default:
- print("canlock: corrupted 0x%lux\n", v);
- return 1;
- }
-}
-
--- a/posix-arm64/Makefile
+++ /dev/null
@@ -1,22 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-
-OFILES=\
- getcallerpc.$O\
- tas.$O
-
-default: $(LIB)
-$(LIB): $(OFILES)
- $(AR) r $(LIB) $(OFILES)
- $(RANLIB) $(LIB)
-
-%.$O: %.c
- $(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
- $(AS) -o $*.$O $*.s
-
-%.s: %.spp
- cpp $*.spp >$*.s
-
--- a/posix-arm64/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
- return ((uintptr*)a)[-1];
-}
--- a/posix-arm64/tas.c
+++ /dev/null
@@ -1,34 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-#ifndef __has_builtin
-#define __has_builtin(x) 0
-#endif
-
-int
-tas(int *x)
-{
-#if __has_builtin(__atomic_test_and_set) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7)))
- return __atomic_test_and_set(x, __ATOMIC_ACQ_REL);
-#else
- int v,t, i = 1;
-
- __asm__ (
- "1: ldxr %0, [%2]\n"
- " stxr %w1, %3, [%2]\n"
- " cmp %1, #0\n"
- " bne 1b"
- : "=&r" (v), "=&r" (t)
- : "r" (x), "r" (i)
- : "cc");
-
- switch(v) {
- case 0:
- case 1:
- return v;
- default:
- print("canlock: corrupted 0x%lux\n", v);
- return 1;
- }
-#endif
-}
--- a/posix-mips/Makefile
+++ /dev/null
@@ -1,16 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-
-OFILES=\
- getcallerpc.$O\
- tas.$O
-
-default: $(LIB)
-$(LIB): $(OFILES)
- $(AR) r $(LIB) $(OFILES)
- $(RANLIB) $(LIB)
-
-tas.$O: tas.s
- ln -sf tas.s tas.S
- $(CC) -c -o tas.$O -mips3 tas.S
--- a/posix-mips/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
- return ((ulong*)a)[-1];
-}
--- a/posix-mips/tas.s
+++ /dev/null
@@ -1,20 +1,0 @@
-#include <machine/regdef.h>
-
-.globl tas
-.ent tas 2
-
-tas:
-.set noreorder
-1:
- ori t1, zero, 12345 /* t1 = 12345 */
- ll t0, (a0) /* t0 = *a0 */
- sc t1, (a0) /* *a0 = t1 if *a0 hasn't changed; t1=success */
- beq t1, zero, 1b /* repeat if *a0 did change */
- nop
-
- j $31 /* return */
- or v0, t0, zero /* set return value on way out */
-
-.set reorder
-.end tas
-
--- a/posix-port/Makefile
+++ b/posix-port/Makefile
@@ -4,6 +4,7 @@
OFILES=\
getcallerpc.$O\
+ tas.$O\
default: $(LIB)
$(LIB): $(OFILES)
--- a/posix-port/getcallerpc.c
+++ b/posix-port/getcallerpc.c
@@ -4,5 +4,6 @@
uintptr
getcallerpc(void *a)
{
- return 0;
+ USED(a);
+ return (uintptr)__builtin_extract_return_addr(__builtin_return_address(0));
}
--- a/posix-power/Makefile
+++ /dev/null
@@ -1,25 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-
-CFLAGS+= -Wa,-mregnames
-
-OFILES=\
- getcallerpc.$O\
- tas.$O
-
-default: $(LIB)
-$(LIB): $(OFILES)
- $(AR) r $(LIB) $(OFILES)
- $(RANLIB) $(LIB)
-
-%.$O: %.c
- $(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
- $(AS) -o $*.$O $*.s
-
-%.s: %.spp
- cpp $*.spp >$*.s
-
-
--- a/posix-power/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
- return ((uintptr*)a)[-1];
-}
--- a/posix-power/tas.c
+++ /dev/null
@@ -1,42 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-/*
- * first argument (l) is in r3 at entry.
- * r3 contains return value upon return.
- */
-int
-tas(int *x)
-{
- int v;
- /*
- * this __asm__ works with gcc 2.95.2 (mac os x 10.1).
- * this assembly language destroys r0 (0), some other register (v),
- * r4 (x) and r5 (temp).
- */
- __asm__("\n sync\n"
- " li r0,0\n"
- " mr r4,%1 /* &l->val */\n"
- " lis r5,0xdead /* assemble constant 0xdeaddead */\n"
- " ori r5,r5,0xdead /* \" */\n"
- "tas1:\n"
- " dcbf r4,r0 /* cache flush; \"fix for 603x bug\" */\n"
- " lwarx %0,r4,r0 /* v = l->val with reservation */\n"
- " cmp cr0,0,%0,r0 /* v == 0 */\n"
- " bne tas0\n"
- " stwcx. r5,r4,r0 /* if (l->val same) l->val = 0xdeaddead */\n"
- " bne tas1\n"
- "tas0:\n"
- " sync\n"
- " isync\n"
- : "=r" (v)
- : "r" (x)
- : "cc", "memory", "r0", "r4", "r5"
- );
- switch(v) {
- case 0: return 0;
- case 0xdeaddead: return 1;
- default: print("tas: corrupted 0x%lux\n", v);
- }
- return 0;
-}
--- a/posix-ppc64le/Makefile
+++ /dev/null
@@ -1,25 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-
-CFLAGS+= -Wa,-mregnames
-
-OFILES=\
- getcallerpc.$O\
- tas.$O
-
-default: $(LIB)
-$(LIB): $(OFILES)
- $(AR) r $(LIB) $(OFILES)
- $(RANLIB) $(LIB)
-
-%.$O: %.c
- $(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
- $(AS) -o $*.$O $*.s
-
-%.s: %.spp
- cpp $*.spp >$*.s
-
-
--- a/posix-ppc64le/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
- return ((uintptr*)a)[-1];
-}
--- a/posix-ppc64le/tas.c
+++ /dev/null
@@ -1,37 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-/*
- * first argument (l) is in r3 at entry.
- * r3 contains return value upon return.
- */
-int
-tas(int *x)
-{
- int v;
-
- __asm__("\n sync\n"
- " li r0,0\n"
- " mr r4,%1 /* &l->val */\n"
- " lis r5,0xdead /* assemble constant 0xdeaddead */\n"
- " ori r5,r5,0xdead /* \" */\n"
- "tas1:\n"
- " lwarx %0,r4,r0 /* v = l->val with reservation */\n"
- " cmp cr0,0,%0,r0 /* v == 0 */\n"
- " bne tas0\n"
- " stwcx. r5,r4,r0 /* if (l->val same) l->val = 0xdeaddead */\n"
- " bne tas1\n"
- "tas0:\n"
- " sync\n"
- " isync\n"
- : "=r" (v)
- : "r" (x)
- : "cc", "memory", "r0", "r4", "r5"
- );
- switch(v) {
- case 0: return 0;
- case 0xdeaddead: return 1;
- default: print("tas: corrupted 0x%lux\n", v);
- }
- return 0;
-}
--- a/posix-riscv64/Makefile
+++ /dev/null
@@ -1,18 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-
-OFILES=\
- getcallerpc.$O\
- tas.$O
-
-default: $(LIB)
-$(LIB): $(OFILES)
- $(AR) r $(LIB) $(OFILES)
- $(RANLIB) $(LIB)
-
-%.$O: %.c
- $(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
- $(AS) -o $*.$O $*.s
--- a/posix-riscv64/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
- return ((uintptr*)a)[-1];
-}
--- a/posix-riscv64/tas.c
+++ /dev/null
@@ -1,28 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-int
-tas(int *x)
-{
- int v, i = 1;
-
- __asm__(
- "1: lr.w t0, (%1)\n"
- " sc.w t1, %2, (%1)\n"
- " bnez t1, 1b\n"
- " mv %0, t0"
- : "=r" (v)
- : "r" (x), "r" (i)
- : "t1", "t0"
- );
-
- switch(v) {
- case 0:
- case 1:
- return v;
- default:
- print("canlock: corrupted 0x%lux\n", v);
- return 1;
- }
-}
-
--- a/posix-sun4u/Makefile
+++ /dev/null
@@ -1,24 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-
-OFILES=\
- getcallerpc.$O\
- tas.$O
-
-default: $(LIB)
-$(LIB): $(OFILES)
- $(AR) r $(LIB) $(OFILES)
- $(RANLIB) $(LIB)
-
-%.$O: %.c
- $(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
- $(AS) -o $*.$O $*.s
-
-%.s: %.spp
- cpp $*.spp >$*.s
-
-
-
--- a/posix-sun4u/getcallerpc.c
+++ /dev/null
@@ -1,9 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
- return ((ulong*)a)[-1];
-}
-
--- a/posix-sun4u/tas.s
+++ /dev/null
@@ -1,5 +1,0 @@
-.globl tas
-tas:
- retl
- ldstub [%o0], %o0
-
--- a/win32-386/Makefile
+++ /dev/null
@@ -1,23 +1,0 @@
-ROOT=..
-include ../Make.config
-LIB=../libmachdep.a
-
-OFILES=\
- getcallerpc.$O\
- tas.$O
-
-default: $(LIB)
-$(LIB): $(OFILES)
- $(AR) r $(LIB) $(OFILES)
- $(RANLIB) $(LIB)
-
-%.$O: %.c
- $(CC) $(CFLAGS) $*.c
-
-%.$O: %.s
- $(AS) -o $*.$O $*.s
-
-%.s: %.spp
- cpp $*.spp >$*.s
-
-
--- a/win32-386/getcallerpc.c
+++ /dev/null
@@ -1,8 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-uintptr
-getcallerpc(void *a)
-{
- return ((uintptr*)a)[-1];
-}
--- a/win32-386/tas.c
+++ /dev/null
@@ -1,23 +1,0 @@
-#include "u.h"
-#include "libc.h"
-
-int
-tas(int *x)
-{
- int v;
-
- __asm__( "movl $1, %%eax\n\t"
- "xchgl %%eax,(%%ecx)"
- : "=a" (v)
- : "c" (x)
- );
- switch(v) {
- case 0:
- case 1:
- return v;
- default:
- print("canlock: corrupted 0x%lux\n", v);
- return 1;
- }
-}
-