aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas <nbnoll@eml.cc>2021-12-10 15:49:00 -0800
committerNicholas <nbnoll@eml.cc>2021-12-10 15:53:05 -0800
commit2e719300a037bbdafdc8a5c38b4812c678d62ddc (patch)
treeb5750baaadc2b5d0b5fe22b85ca39bbea4f837c0
parent25537c3d3b9b68af91573dec39d1f46c3d97f735 (diff)
Chore: merge main into laptopselfhost
-rw-r--r--.gitignore9
-rwxr-xr-xbin/status4
-rw-r--r--include/base/math.h10
-rw-r--r--src/base/math/sqrtf.c99
-rw-r--r--src/rules.mk3
-rw-r--r--sys/linux/amd64/arch/constants.h2
-rw-r--r--sys/linux/port/os/constants.h9
-rw-r--r--sys/linux/port/os/types.h13
-rwxr-xr-xvendor/sync38
9 files changed, 164 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore
index 5b7262d..ee3ca0f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,15 +9,12 @@ etc/
figs/
.cache/
+sys/linux/*/linux
+sys/linux/*/asm*
+
include/libc
include/vendor
-sys/cc
-sys/nixos
-sys/libdraw
-sys/libimage
-sys/libterm
-
src/base/utf/*-14.0.0.c
.dep/
diff --git a/bin/status b/bin/status
index 451a428..a0f6f39 100755
--- a/bin/status
+++ b/bin/status
@@ -111,7 +111,7 @@ refresh_time() {
refresh_all() {
refresh_volume
- #refresh_battery
+ refresh_battery
refresh_ip
refresh_cpu
refresh_mail
@@ -140,7 +140,7 @@ refresh_weather
refresh_ip
while true
do
- #refresh_battery
+ refresh_battery
refresh_memory
refresh_cpu
refresh_mail
diff --git a/include/base/math.h b/include/base/math.h
index 65d3058..41d3858 100644
--- a/include/base/math.h
+++ b/include/base/math.h
@@ -7,12 +7,15 @@ int math·isInf(double, int);
ulong math·umuldiv(ulong, ulong, ulong);
long math·muldiv(long, long, long);
+/* integer specific functions */
+int math·abs(int);
+long math·labs(long);
+
+/* double specific functions */
double math·pow(double, double);
double math·atan2(double, double);
double math·fabs(double);
double math·atan(double);
-int math·abs(int);
-long math·labs(long);
double math·ldexp(double, int);
double math·log(double);
double math·log10(double);
@@ -33,6 +36,9 @@ double math·fmod(double, double);
double math·modf(double, double*);
double math·frexp(double, int*);
+/* float specific functions */
+float math·sqrtf(float);
+
double math·copysign(double, double);
#define math·HUGE 3.4028234e38
diff --git a/src/base/math/sqrtf.c b/src/base/math/sqrtf.c
new file mode 100644
index 0000000..c952248
--- /dev/null
+++ b/src/base/math/sqrtf.c
@@ -0,0 +1,99 @@
+#include <u.h>
+#include <base.h>
+
+static const uint16 tab[128] = {
+0xb451,0xb2f0,0xb196,0xb044,0xaef9,0xadb6,0xac79,0xab43,
+0xaa14,0xa8eb,0xa7c8,0xa6aa,0xa592,0xa480,0xa373,0xa26b,
+0xa168,0xa06a,0x9f70,0x9e7b,0x9d8a,0x9c9d,0x9bb5,0x9ad1,
+0x99f0,0x9913,0x983a,0x9765,0x9693,0x95c4,0x94f8,0x9430,
+0x936b,0x92a9,0x91ea,0x912e,0x9075,0x8fbe,0x8f0a,0x8e59,
+0x8daa,0x8cfe,0x8c54,0x8bac,0x8b07,0x8a64,0x89c4,0x8925,
+0x8889,0x87ee,0x8756,0x86c0,0x862b,0x8599,0x8508,0x8479,
+0x83ec,0x8361,0x82d8,0x8250,0x81c9,0x8145,0x80c2,0x8040,
+0xff02,0xfd0e,0xfb25,0xf947,0xf773,0xf5aa,0xf3ea,0xf234,
+0xf087,0xeee3,0xed47,0xebb3,0xea27,0xe8a3,0xe727,0xe5b2,
+0xe443,0xe2dc,0xe17a,0xe020,0xdecb,0xdd7d,0xdc34,0xdaf1,
+0xd9b3,0xd87b,0xd748,0xd61a,0xd4f1,0xd3cd,0xd2ad,0xd192,
+0xd07b,0xcf69,0xce5b,0xcd51,0xcc4a,0xcb48,0xca4a,0xc94f,
+0xc858,0xc764,0xc674,0xc587,0xc49d,0xc3b7,0xc2d4,0xc1f4,
+0xc116,0xc03c,0xbf65,0xbe90,0xbdbe,0xbcef,0xbc23,0xbb59,
+0xba91,0xb9cc,0xb90a,0xb84a,0xb78c,0xb6d0,0xb617,0xb560,
+};
+
+static inline uint32
+mul32(uint32 a, uint32 b)
+{
+ return (uint64)a*b >> 32;
+}
+
+float
+math·sqrtf(float x)
+{
+ uint32 ix, m, m1, m0, even, ey;
+ union{float f; uint32 i;} phi;
+
+ phi.f=x, ix=phi.i;
+ if(ix - 0x00800000 >= 0x7f800000 - 0x00800000){
+ /* x < 0x1p-126 or inf or nan. */
+ if(ix * 2 == 0)
+ return x;
+ if(ix == 0x7f800000)
+ return x;
+ if(ix > 0x7f800000)
+ return (x-x)/(x-x);
+ /* x is subnormal, normalize it. */
+ phi.f=x * 0x1p23f, ix=phi.i;
+ ix -= 23 << 23;
+ }
+
+ /* x = 4^e m; with int e and m in [1, 4). */
+ even = ix & 0x00800000;
+ m1 = (ix << 8) | 0x80000000;
+ m0 = (ix << 7) & 0x7fffffff;
+ m = even ? m0 : m1;
+
+ /* 2^e is the exponent part of the return value. */
+ ey = ix >> 1;
+ ey += 0x3f800000 >> 1;
+ ey &= 0x7f800000;
+
+ /* compute r ~ 1/sqrt(m), s ~ sqrt(m) with 2 goldschmidt iterations. */
+ static const uint32 three = 0xc0000000;
+ uint32 r, s, d, u, i;
+ i = (ix >> 17) % 128;
+ r = (uint32)tab[i] << 16;
+ /* |r*sqrt(m) - 1| < 0x1p-8 */
+ s = mul32(m, r);
+ /* |s/sqrt(m) - 1| < 0x1p-8 */
+ d = mul32(s, r);
+ u = three - d;
+ r = mul32(r, u) << 1;
+ /* |r*sqrt(m) - 1| < 0x1.7bp-16 */
+ s = mul32(s, u) << 1;
+ /* |s/sqrt(m) - 1| < 0x1.7bp-16 */
+ d = mul32(s, r);
+ u = three - d;
+ s = mul32(s, u);
+ /* -0x1.03p-28 < s/sqrt(m) - 1 < 0x1.fp-31 */
+ s = (s - 1)>>6;
+ /* s < sqrt(m) < s + 0x1.08p-23 */
+
+ /* compute nearest rounded result. */
+ uint32 d0, d1, d2;
+ float y, t;
+ d0 = (m << 16) - s*s;
+ d1 = s - d0;
+ d2 = d1 + s + 1;
+ s += d1 >> 31;
+ s &= 0x007fffff;
+ s |= ey;
+ phi.i = s, y = phi.f;
+
+ /* handle rounding and inexact exception. */
+ uint32 tiny = (d2==0) ? 0 : 0x01000000;
+ tiny |= (d1^d2) & 0x80000000;
+ phi.i=tiny, t=phi.f;
+ y = y + t;
+
+ return y;
+}
diff --git a/src/rules.mk b/src/rules.mk
index 5e848ae..ddad693 100644
--- a/src/rules.mk
+++ b/src/rules.mk
@@ -17,4 +17,7 @@ include $(DIR)/rules.mk
DIR := $(d)/libbio
include $(DIR)/rules.mk
+DIR := $(d)/libfont
+include $(DIR)/rules.mk
+
include share/pop.mk
diff --git a/sys/linux/amd64/arch/constants.h b/sys/linux/amd64/arch/constants.h
index f1c1b4c..9ba607c 100644
--- a/sys/linux/amd64/arch/constants.h
+++ b/sys/linux/amd64/arch/constants.h
@@ -2,7 +2,7 @@
#define sys·OCreate 0100
#define sys·OUnique 0200
-#define sys·ONoTTY 0400
+#define sys·ONoCtlTTY 0400
#define sys·OTrunc 01000
#define sys·OAppend 02000
#define sys·ONoBlock 04000
diff --git a/sys/linux/port/os/constants.h b/sys/linux/port/os/constants.h
index 458c2c2..410698a 100644
--- a/sys/linux/port/os/constants.h
+++ b/sys/linux/port/os/constants.h
@@ -6,7 +6,6 @@
#define sys·FileCanWrite 2
#define sys·FileCanRead 4
-
/* device modes */
#define sys·ModeFile 0170000
#define sys·ModeDir 0040000
@@ -18,10 +17,10 @@
#define sys·ModeSocket 0140000
/* ioctl values */
-#define sys·IoCtlTermGet 0x5401
-#define sys·IoCtlTermSet 0x5402
-#define sys·IoCtlTermGetWinSize 0x5413
-#define sys·IoCtlTermSetWinSize 0x5414
+#define sys·IoCtlTermGet 0x5401
+#define sys·IoCtlTermSet 0x5402
+#define sys·IoCtlTermGetWindowSize 0x5413
+#define sys·IoCtlTermSetWindowSize 0x5414
#define sys·TermVInterupt 0
#define sys·TermVQuit 1
diff --git a/sys/linux/port/os/types.h b/sys/linux/port/os/types.h
index 9452e39..7f83c3d 100644
--- a/sys/linux/port/os/types.h
+++ b/sys/linux/port/os/types.h
@@ -1,4 +1,5 @@
#pragma once
+
#define packed __attribute__((packed))
/*
@@ -112,11 +113,10 @@ struct sys·DirEntry
* terminal
*/
-/* termios
- * NOTE: this is incorrect for Mips and PowerPC...
- */
typedef struct sys·TerminalIO sys·TerminalIO;
+typedef struct sys·WindowSize sys·WindowSize;
+/* termios NOTE: this is incorrect for Mips and PowerPC... */
struct sys·TerminalIO
{
uint i,o,c,l; /* input,output,control,local flags */
@@ -126,4 +126,11 @@ struct sys·TerminalIO
uint ospeed; /* output speed */
};
+/* screen/window */
+struct sys·WindowSize
+{
+ ushort row, col;
+ ushort dx, dy; /* pixels */
+};
+
#undef packed
diff --git a/vendor/sync b/vendor/sync
index 5daf751..48895f8 100755
--- a/vendor/sync
+++ b/vendor/sync
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash -e
# globals
@@ -183,6 +183,35 @@ build_wlroots()
}
# ------------------------------------------------------------------------
+# kernel headers
+
+KERNEL_URL="https://github.com/sabotage-linux/kernel-headers"
+KERNEL_TAG="v4.19.88-1"
+
+build_kernel()
+{
+ git clone $KERNEL_URL kernel
+ cd kernel && git checkout $KERNEL_TAG
+
+ # probably wrong for risxv64
+ for subdir in linux asm asm-generic
+ do
+ for arch in amd64 i386 riscv64
+ do
+ cp -rL "./x86/include/$subdir" "../../sys/linux/$arch/$subdir"
+ done
+ for arch in arm arm64
+ do
+ cp -rL "$arch/include/$subdir" "../../sys/linux/$arch/$subdir"
+ done
+ done
+
+ cd $VENDOR
+ echo $KERNEL_TAG > kernel/build.tag
+}
+
+
+# ------------------------------------------------------------------------
# utility functions
update()
@@ -190,10 +219,10 @@ update()
base=$1
tag=$2
- if [ -d $base ] && [ `cat $base/build.tag` = $tag ]; then
+ if [ -d "$base" ] && [ "$(cat "$base/build.tag")" = "$tag" ]; then
echo "$base: up to date"
else
- build_$base
+ "build_$base"
fi
}
@@ -205,4 +234,5 @@ update()
update musl $MUSL_TAG
update zlib $ZLIB_TAG
-update wlroots $WLROOTS_TAG
+update kernel $WLROOTS_TAG
+# update wlroots $WLROOTS_TAG