mirror of
https://github.com/jart/cosmopolitan.git
synced 2026-11-08 08:08:04 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7abca1531f | ||
|
|
7dc8973567 | ||
|
|
1753b669cf | ||
|
|
ae300d0c40 | ||
|
|
c6f75bf95a | ||
|
|
52565e7af3 | ||
|
|
3c19b6e352 | ||
|
|
a1677d605a | ||
|
|
dcbd2b8668 | ||
|
|
4d21cd315d | ||
|
|
da36e7e256 | ||
|
|
09bcfa23d5 | ||
|
|
6b90ff60cd | ||
|
|
2f41b4dcc6 | ||
|
|
5af25f687a | ||
|
|
9c81729008 | ||
|
|
8a236433a2 | ||
|
|
ab64ef7364 | ||
|
|
4177489762 | ||
|
|
4e93750afd | ||
|
|
ca88ce5026 | ||
|
|
6388ef21f8 | ||
|
|
7ffeb29bfc | ||
|
|
da4dffccc5 | ||
|
|
807706a099 | ||
|
|
83d0c3b870 | ||
|
|
6cd1037692 | ||
|
|
e0566c9675 | ||
|
|
3f35b37b68 | ||
|
|
67c27d9e6e | ||
|
|
2a3037d4e8 | ||
|
|
0a61fe4ea0 | ||
|
|
33e8fc8687 | ||
|
|
0ad609268f | ||
|
|
816b0e1851 | ||
|
|
2bd1e72d5a | ||
|
|
5ce83b08c8 | ||
|
|
5f088cec23 | ||
|
|
a8945714e8 | ||
|
|
8a6ac6dd63 | ||
|
|
f5da4efcaf | ||
|
|
b16b332539 | ||
|
|
4d3195f57a | ||
|
|
aad841610e | ||
|
|
7583b3accc | ||
|
|
06a4e2d29b | ||
|
|
67b9675c81 | ||
|
|
4d4aa9e791 | ||
|
|
813e11b90b | ||
|
|
fb7b7c6e21 | ||
|
|
d769df3482 | ||
|
|
c3ed8d6c7f | ||
|
|
937d921018 | ||
|
|
bfef17eb6d | ||
|
|
11ec99931b | ||
|
|
cfd453d125 | ||
|
|
6fa049c9c7 | ||
|
|
3364fc5b03 | ||
|
|
f064183646 | ||
|
|
e26bdbec52 | ||
|
|
5141d00992 | ||
|
|
b9f73e6a4d | ||
|
|
43b2475aaa | ||
|
|
1a08594f95 | ||
|
|
e55e71ab48 | ||
|
|
3573814e45 | ||
|
|
2134ffe005 | ||
|
|
e3ee3c78e9 | ||
|
|
8af91bcbe7 | ||
|
|
754974faaa | ||
|
|
9367253b4d | ||
|
|
32e289b1d8 | ||
|
|
d53a344e18 | ||
|
|
3e19b96ab8 | ||
|
|
1831e3ccf7 | ||
|
|
4651962070 | ||
|
|
8a6a1e25b1 | ||
|
|
7e4021bf82 | ||
|
|
2596a59374 | ||
|
|
0eaad9dd7b | ||
|
|
f4298f10c2 | ||
|
|
d932948fb4 | ||
|
|
5e069a64d4 | ||
|
|
3c24c12068 | ||
|
|
839e2f4cfb | ||
|
|
c42dbe0e9e | ||
|
|
94afa982c3 | ||
|
|
cc56038b05 | ||
|
|
f3baa05195 | ||
|
|
1c9065510f | ||
|
|
da199b7a45 | ||
|
|
98fba078a3 | ||
|
|
5d334b9ce0 | ||
|
|
35c7edac49 | ||
|
|
218ef49147 | ||
|
|
19d0c15e03 | ||
|
|
3e17c7b20f | ||
|
|
fcfe7c1080 | ||
|
|
91f4167a45 | ||
|
|
40291c9db3 | ||
|
|
cdc54ea1fd | ||
|
|
edd9297eba | ||
|
|
ac3b1dfb21 | ||
|
|
537c21338b | ||
|
|
c6c9b5dfde | ||
|
|
4a5698b5c9 | ||
|
|
6c7b8facaa | ||
|
|
7a393c06fe | ||
|
|
e345b42d78 | ||
|
|
e85aeda4ba | ||
|
|
3e1fd1d962 | ||
|
|
b740cca642 | ||
|
|
c797f139bb | ||
|
|
adebc5e4c3 | ||
|
|
5f1415af3a | ||
|
|
02b4a5c824 | ||
|
|
45b994ea23 | ||
|
|
2c15efc249 | ||
|
|
667ab245fe | ||
|
|
08d3700c15 | ||
|
|
6f35bd47ab | ||
|
|
bfa8581537 |
No files matched your search
@@ -0,0 +1,6 @@
|
||||
virt: lxd
|
||||
os: linux
|
||||
language: c
|
||||
script: make -j4 V=0
|
||||
notifications:
|
||||
email: false
|
||||
Vendored
+45
-2
@@ -1,13 +1,12 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"name": "Win32",
|
||||
"includePath": [
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++11",
|
||||
"compilerPath": "${workspaceFolder}/o/third_party/gcc/bin/x86_64-linux-musl-gcc",
|
||||
"forcedInclude": ["${workspaceFolder}/.vscode/vscode.h"],
|
||||
"defines": [
|
||||
"libcesque=",
|
||||
@@ -63,6 +62,50 @@
|
||||
"attributeallocalign(x)=",
|
||||
"nullterminated(x)="
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"cStandard": "gnu17",
|
||||
"compilerPath": "${workspaceFolder}/o/third_party/gcc/bin/x86_64-linux-musl-gcc",
|
||||
"compilerArgs": [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-fdebug-prefix-map=${workspaceFolder}=",
|
||||
"-frecord-gcc-switches",
|
||||
"-Wa,-W",
|
||||
"-Wa,-I.",
|
||||
"-Wa,--noexecstack",
|
||||
"-Wa,--nocompress-debug-sections",
|
||||
"-Og",
|
||||
"-g",
|
||||
"-gdescribe-dies",
|
||||
"-msse3",
|
||||
"-mno-red-zone",
|
||||
"-fno-math-errno",
|
||||
"-fno-trapping-math",
|
||||
"-fno-fp-int-builtin-inexact",
|
||||
"-fno-ident",
|
||||
"-fno-common",
|
||||
"-fno-gnu-unique",
|
||||
"-fstrict-aliasing",
|
||||
"-fstrict-overflow",
|
||||
"-fno-semantic-interposition",
|
||||
"-mno-omit-leaf-frame-pointer",
|
||||
"-fno-jump-tables",
|
||||
"-nostdinc",
|
||||
"-iquote."
|
||||
],
|
||||
"forcedInclude": [
|
||||
"libc/integral/normalize.inc"
|
||||
],
|
||||
"defines": [
|
||||
"COSMO",
|
||||
"MODE=",
|
||||
"IMAGE_BASE_VIRTUAL=0x400000"
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
||||
Vendored
-158
@@ -1,160 +1,2 @@
|
||||
#define __VSCODE_INTELLISENSE__ 1
|
||||
#include "libc/integral/normalize.inc"
|
||||
|
||||
#if 0
|
||||
#define __VSCODE_INTELLISENSE__ 1
|
||||
#define __BIGGEST_ALIGNMENT__ 1
|
||||
#define __CHAR_MAX__ 0x7F
|
||||
#define __SCHAR_MAX__ __CHAR_MAX__
|
||||
#define __SHRT_MAX__ 0x7FFF
|
||||
#define __INT_MAX__ 0x7FFFFFFF
|
||||
#define __LONG_MAX__ 0x7FFFFFFFFFFFFFFF
|
||||
#define __LONG_LONG_MAX__ __LONG_MAX__
|
||||
#define __CHAR_MIN__ -((__CHAR_MAX__) + 1)
|
||||
#define __SHRT_MIN__ -((__SHRT_MAX__) + 1)
|
||||
#define __INT_MIN__ -((__INT_MAX__) + 1)
|
||||
#define __LONG_MIN__ -((__LONG_MAX__) + 1)
|
||||
#define __LONG_LONG_MIN__ -((__LONG_LONG_MAX__) + 1)
|
||||
#define __UCHAR_MAX__ 0xFF
|
||||
#define __USHRT_MAX__ 0xFFFF
|
||||
#define __UINT_MAX__ 0xFFFFFFFF
|
||||
#define __ULONG_MAX__ 0xFFFFFFFFFFFFFFFF
|
||||
#define __SIZE_MAX__ __ULONG_MAX__
|
||||
#define __SSIZE_MAX__ __LONG_MAX__
|
||||
#define __UINTPTR_MAX__ __SIZE_MAX__
|
||||
#define __INTPTR_MAX__ __SSIZE_MAX__
|
||||
#define __WCHAR_MAX__ __UINT_MAX__
|
||||
#define __PTRDIFF_MAX__ __UINTPTR_MAX__
|
||||
#define __INTMAX_MAX__ __ULONG_MAX__
|
||||
#define __SIZEOF_POINTER__ 8
|
||||
#define __SIZEOF_SHORT__ 2
|
||||
#define __SIZEOF_INT__ 4
|
||||
#define __SIZEOF_LONG__ 8
|
||||
#define __SIZEOF_LONG_LONG__ 8
|
||||
#define __SIZEOF_PTRDIFF_T__ 8
|
||||
#define __SIZEOF_SIZE_T__ 8
|
||||
#define __SIZEOF_WCHAR_T__ 4
|
||||
#define __SIZEOF_WINT_T__ 4
|
||||
#define __SIZEOF_FLOAT__ 4
|
||||
#define __SIZEOF_FLOAT128__ 16
|
||||
#define __SIZEOF_DOUBLE__ 8
|
||||
#define __SIZEOF_FLOAT80__ 10
|
||||
#define __SIZEOF_LONG_DOUBLE__ 16
|
||||
#define __FLT_MAX__ 1
|
||||
#define __DBL_MAX__ 1
|
||||
|
||||
#define __INT_LEAST8_TYPE__ signed char
|
||||
#define __INT_LEAST16_TYPE__ signed short
|
||||
#define __INT_LEAST32_TYPE__ signed int
|
||||
#define __INT_LEAST64_TYPE__ signed long long
|
||||
#define __UINT_LEAST8_TYPE__ unsigned char
|
||||
#define __UINT_LEAST16_TYPE__ unsigned short
|
||||
#define __UINT_LEAST32_TYPE__ unsigned int
|
||||
#define __UINT_LEAST64_TYPE__ unsigned long long
|
||||
|
||||
#define __UINT8_MAX__ __UCHAR_MAX__
|
||||
#define __UINT16_MAX__ __USHRT_MAX__
|
||||
#define __UINT32_MAX__ __UINT_MAX__
|
||||
#define __UINT64_MAX__ __ULONG_MAX__
|
||||
|
||||
#define __INT8_MAX__ __CHAR_MAX__
|
||||
#define __INT16_MAX__ __SHRT_MAX__
|
||||
#define __INT32_MAX__ __INT_MAX__
|
||||
#define __INT64_MAX__ __LONG_MAX__
|
||||
|
||||
#define ATEXIT_MAX 1
|
||||
#define STACKSIZE 0x10000
|
||||
#define ARG_MAX 255
|
||||
#define OPEN_MAX 0x7FFF
|
||||
#define CHAR_BIT 7
|
||||
#define NSIG 1
|
||||
#define NULL (0)
|
||||
#define false 0
|
||||
#define true (!(false))
|
||||
#define COSMOPOLITAN_C_START_
|
||||
#define COSMOPOLITAN_C_END_
|
||||
#define PAGESIZE 0x1000
|
||||
#define BIGPAGESIZE 0x10000
|
||||
#define NAME_MAX 255
|
||||
|
||||
#define SWITCHEROO(...) 0
|
||||
|
||||
extern unsigned g_loglevel;
|
||||
|
||||
typedef void * va_list;
|
||||
|
||||
#define va_start(...) 0
|
||||
#define va_end(...) 0
|
||||
#define va_arg(x, y) (y)(0)
|
||||
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
#define int64_t long long
|
||||
#define int128_t int64_t
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef unsigned long long uint128_t;
|
||||
|
||||
typedef int errno_t;
|
||||
typedef uint64_t size_t;
|
||||
typedef unsigned long long ssize_t;
|
||||
typedef uint64_t uintptr_t;
|
||||
typedef long long intptr_t;
|
||||
|
||||
typedef unsigned long long uintmax_t;
|
||||
typedef long long intmax_t;
|
||||
|
||||
typedef uint32_t bool32;
|
||||
|
||||
#ifndef __cplusplus
|
||||
typedef uint8_t bool;
|
||||
typedef uint16_t char16_t;
|
||||
typedef uint32_t char32_t;
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef char32_t wint_t;
|
||||
typedef char32_t wchar_t;
|
||||
typedef struct { int ax, dx; } axdx_t;
|
||||
|
||||
/* duplicate and replace xmmintrin.internal.h to fix it for IntelliSense
|
||||
* SEE: <> */
|
||||
|
||||
#define _Vector_size(x) __attribute__((__vector_size__(x)))
|
||||
|
||||
#define IMAGE_BASE_VIRTUAL 0x400000
|
||||
#define __SIGACTION(...) (0)
|
||||
#define VEIL(x, y) (y)
|
||||
#define STATIC_YOINK(x)
|
||||
#define BUFSIZ 1
|
||||
#define FRAMESIZE 0x10000
|
||||
#define PATH_MAX 252
|
||||
#define concat(x, y, z) 0
|
||||
#define CONCAT(a, b, c, d, e) 0
|
||||
#define shuffle(...) 0
|
||||
#define reverse(x, y) 0
|
||||
#define autotype(x) intptr_t
|
||||
|
||||
#define _Generic_(...) (void*)(0)
|
||||
#define _Generic(...) _Generic_
|
||||
#define _Alignas(...)
|
||||
#define _Section(...)
|
||||
|
||||
#define offsetof(x, y) 0
|
||||
#define INITIALIZER(...) struct _dummy
|
||||
#define __far
|
||||
#define tinystrstr(...) 0
|
||||
#define BENCHLOOP(...) 0
|
||||
|
||||
#ifdef __hook
|
||||
#undef __hook
|
||||
#endif /* __hook */
|
||||
|
||||
#ifdef UriKeyval
|
||||
#undef UriKeyval
|
||||
#endif /* UriKeyval */
|
||||
|
||||
#define _Static_assert(...) 0
|
||||
#endif /* 0 */
|
||||
@@ -1,3 +1,5 @@
|
||||
ISC License
|
||||
|
||||
Copyright 2020 Justine Alexandra Roberts Tunney
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for
|
||||
@@ -40,8 +40,7 @@
|
||||
# o/dbg/examples/crashreport.com
|
||||
# less examples/crashreport.c
|
||||
#
|
||||
# # extremely tiny binaries (scout's honor escape hatch)
|
||||
# # please pay the $1k for commercial license if you can
|
||||
# # extremely tiny binaries
|
||||
# make -j8 -O MODE=tiny \
|
||||
# LDFLAGS+=-s \
|
||||
# CPPFLAGS+=-DIM_FEELING_NAUGHTY \
|
||||
@@ -101,7 +100,6 @@ include libc/str/str.mk # │
|
||||
include third_party/xed/xed.mk # │
|
||||
include third_party/zlib/zlib.mk # │
|
||||
include libc/elf/elf.mk # │
|
||||
include ape/lib/apelib.mk # │
|
||||
include ape/ape.mk # │
|
||||
include libc/fmt/fmt.mk #─┘
|
||||
include libc/calls/calls.mk #─┐
|
||||
@@ -133,11 +131,11 @@ include dsp/tty/tty.mk # ├──ONLINE RUNTIME
|
||||
include libc/dns/dns.mk # │ You can communicate with the network
|
||||
include libc/crypto/crypto.mk # │
|
||||
include net/http/http.mk #─┘
|
||||
include third_party/duktape/duktape.mk
|
||||
include third_party/regex/regex.mk
|
||||
include third_party/third_party.mk
|
||||
include libc/testlib/testlib.mk
|
||||
include tool/viz/lib/vizlib.mk
|
||||
include third_party/lua/lua.mk
|
||||
include examples/examples.mk
|
||||
include third_party/lz4cli/lz4cli.mk
|
||||
include tool/build/lib/buildlib.mk
|
||||
@@ -173,14 +171,13 @@ include test/libc/time/test.mk
|
||||
include test/libc/stdio/test.mk
|
||||
include test/libc/release/test.mk
|
||||
include test/libc/test.mk
|
||||
include test/ape/lib/test.mk
|
||||
include test/ape/test.mk
|
||||
include test/net/http/test.mk
|
||||
include test/net/test.mk
|
||||
include test/tool/build/lib/test.mk
|
||||
include test/tool/build/test.mk
|
||||
include test/tool/viz/lib/test.mk
|
||||
include test/tool/viz/test.mk
|
||||
include test/tool/net/test.mk
|
||||
include test/tool/test.mk
|
||||
include test/dsp/core/test.mk
|
||||
include test/dsp/scale/test.mk
|
||||
@@ -206,7 +203,7 @@ depend: o/$(MODE)/depend
|
||||
tags: TAGS HTAGS
|
||||
|
||||
o/$(MODE)/.x:
|
||||
@$(MKDIR) $(@D) && touch $@
|
||||
@mkdir -p $(@D) && touch $@
|
||||
|
||||
o/$(MODE)/srcs.txt: o/$(MODE)/.x $(MAKEFILES) $(call uniq,$(foreach x,$(SRCS),$(dir $(x))))
|
||||
$(file >$@) $(foreach x,$(SRCS),$(file >>$@,$(x)))
|
||||
@@ -215,15 +212,15 @@ o/$(MODE)/hdrs.txt: o/$(MODE)/.x $(MAKEFILES) $(call uniq,$(foreach x,$(HDRS) $(
|
||||
$(file >$@) $(foreach x,$(HDRS) $(INCS),$(file >>$@,$(x)))
|
||||
|
||||
o/$(MODE)/depend: o/$(MODE)/.x o/$(MODE)/srcs.txt o/$(MODE)/hdrs.txt $(SRCS) $(HDRS) $(INCS)
|
||||
@build/mkdeps -o $@ -r o/$(MODE)/ o/$(MODE)/srcs.txt o/$(MODE)/hdrs.txt
|
||||
@$(COMPILE) -AMKDEPS $(MKDEPS) -o $@ -r o/$(MODE)/ o/$(MODE)/srcs.txt o/$(MODE)/hdrs.txt
|
||||
|
||||
TAGS: o/$(MODE)/srcs.txt $(SRCS)
|
||||
@rm -f $@
|
||||
@ACTION=TAGS TARGET=$@ build/do $(TAGS) $(TAGSFLAGS) -L $< -o $@
|
||||
@$(COMPILE) -ATAGS -T$@ $(TAGS) $(TAGSFLAGS) -L $< -o $@
|
||||
|
||||
HTAGS: o/$(MODE)/hdrs.txt $(HDRS)
|
||||
@rm -f $@
|
||||
@ACTION=TAGS TARGET=$@ build/do build/htags -L $< -o $@
|
||||
@$(COMPILE) -ATAGS -T$@ build/htags -L $< -o $@
|
||||
|
||||
loc: o/$(MODE)/tool/build/summy.com
|
||||
find -name \*.h -or -name \*.c -or -name \*.S | \
|
||||
@@ -237,16 +234,15 @@ COSMOPOLITAN_OBJECTS = \
|
||||
LIBC_NT_MSWSOCK \
|
||||
LIBC_OHMYPLUS \
|
||||
LIBC_X \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_GETOPT \
|
||||
LIBC_LOG \
|
||||
LIBC_UNICODE \
|
||||
LIBC_TIME \
|
||||
LIBC_ZIPOS \
|
||||
THIRD_PARTY_ZLIB \
|
||||
APE_LIB \
|
||||
THIRD_PARTY_MUSL \
|
||||
LIBC_STDIO \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_REGEX \
|
||||
LIBC_ALG \
|
||||
LIBC_MEM \
|
||||
@@ -269,8 +265,8 @@ COSMOPOLITAN_OBJECTS = \
|
||||
LIBC_FMT \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_SYSV \
|
||||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
LIBC_INTRIN \
|
||||
LIBC_NT_KERNEL32 \
|
||||
LIBC_NEXGEN32E
|
||||
@@ -315,7 +311,7 @@ o/cosmopolitan.h: \
|
||||
o/$(MODE)/tool/build/rollup.com \
|
||||
libc/integral/normalize.inc \
|
||||
$(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS))
|
||||
@ACTION=ROLLUP TARGET=$@ build/do $^ >$@
|
||||
@$(COMPILE) -AROLLUP -T$@ $^ >$@
|
||||
|
||||
o/cosmopolitan.html: \
|
||||
o/$(MODE)/third_party/chibicc/chibicc.com.dbg \
|
||||
|
||||
@@ -19,19 +19,31 @@ libc](https://justine.lol/cosmopolitan/index.html) website. We also have
|
||||
## Getting Started
|
||||
|
||||
If you're doing your development work on Linux or BSD then you need just
|
||||
five files to get started:
|
||||
five files to get started. Here's what you do on Linux:
|
||||
|
||||
```sh
|
||||
wget https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-0.2.zip
|
||||
unzip cosmopolitan-amalgamated-0.2.zip
|
||||
echo 'main() { printf("hello world\n"); }' >hello.c
|
||||
gcc -g -O -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \
|
||||
wget https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-0.3.zip
|
||||
unzip cosmopolitan-amalgamation-0.3.zip
|
||||
printf 'main() { printf("hello world\\n"); }\n' >hello.c
|
||||
gcc -g -Os -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \
|
||||
-fno-omit-frame-pointer -pg -mnop-mcount \
|
||||
-o hello.com.dbg hello.c -fuse-ld=bfd -Wl,-T,ape.lds \
|
||||
-include cosmopolitan.h crt.o ape.o cosmopolitan.a
|
||||
objcopy -S -O binary hello.com.dbg hello.com
|
||||
./hello.com
|
||||
```
|
||||
|
||||
You now have a portable program. Please note that your APE binary will
|
||||
assimilate itself as a conventional resident of your platform after the
|
||||
first run, so it can be fast and efficient for subsequent executions.
|
||||
|
||||
```sh
|
||||
./hello.com
|
||||
bash -c './hello.com' # zsh/fish workaround (we upstreamed a patch)
|
||||
```
|
||||
|
||||
So if you intend to copy the binary to Windows or Mac then please do
|
||||
that before you run it, not after.
|
||||
|
||||
If you're developing on Windows or MacOS then you need to download an
|
||||
x86_64-pc-linux-gnu toolchain beforehand. See the [Compiling on
|
||||
Windows](https://justine.lol/cosmopolitan/windows-compiling.html)
|
||||
@@ -41,10 +53,23 @@ universal binaries possible.
|
||||
Cosmopolitan can also be compiled from source on any Linux distro.
|
||||
|
||||
```sh
|
||||
wget https://justine.lol/cosmopolitan/cosmopolitan-0.2.tar.gz
|
||||
tar xf cosmopolitan-0.2.tar.gz # see releases page
|
||||
cd cosmopolitan-0.2
|
||||
wget https://justine.lol/cosmopolitan/cosmopolitan-0.3.tar.gz
|
||||
tar xf cosmopolitan-0.3.tar.gz # see releases page
|
||||
cd cosmopolitan
|
||||
make -j16
|
||||
o//examples/hello.com
|
||||
find o -name \*.com | xargs ls -rShal | less
|
||||
```
|
||||
|
||||
## Support Vector
|
||||
|
||||
| Platform | Min Version | Circa |
|
||||
| :--- | ---: | ---: |
|
||||
| AMD | K8 Venus | 2005 |
|
||||
| Intel | Core | 2006 |
|
||||
| New Technology | Vista | 2006 |
|
||||
| GNU/Systemd | 2.6.18 | 2007 |
|
||||
| XNU's Not UNIX! | 15.6 | 2018 |
|
||||
| FreeBSD | 12 | 2018 |
|
||||
| OpenBSD | 6.4 | 2018 |
|
||||
| NetBSD | 9.1 | 2020 |
|
||||
@@ -32,20 +32,19 @@
|
||||
╠──────────────────────────────────────────────────────▌▀▄─▐──▀▄─▐▄─▐▄▐▄─▐▄─▐▄─│
|
||||
│ αcτµαlly pδrταblε εxεcµταblε § program header │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/config.h"
|
||||
#include "ape/lib/pc.h"
|
||||
#include "ape/macros.internal.h"
|
||||
#include "ape/notice.inc"
|
||||
#include "ape/relocations.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/elf/def.h"
|
||||
#include "libc/macho.internal.h"
|
||||
#include "libc/nexgen32e/uart.internal.h"
|
||||
#include "libc/nexgen32e/vidya.internal.h"
|
||||
#include "libc/nt/pedef.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/runtime/pc.internal.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
|
||||
#define USE_SYMBOL_HACK 0
|
||||
#define USE_SYMBOL_HACK 1
|
||||
|
||||
.section .text,"ax",@progbits
|
||||
.align __SIZEOF_POINTER__
|
||||
@@ -62,9 +61,6 @@ __ro: .endobj __ro,globl,hidden # ←for gdb readibility
|
||||
.previous
|
||||
.section .rodata.str1.1,"a",@progbits
|
||||
cstr: .endobj cstr,globl,hidden # ←for gdb readibility
|
||||
.previous
|
||||
.section .sort.rodata.real.str1.1,"a",@progbits
|
||||
rlstr: .endobj rlstr,globl,hidden # ←for gdb readibility
|
||||
.previous
|
||||
.section .head,"ax",@progbits
|
||||
|
||||
@@ -105,7 +101,7 @@ rlstr: .endobj rlstr,globl,hidden # ←for gdb readibility
|
||||
│ αcτµαlly pδrταblε εxεcµταblε § the old technology │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
|
||||
#if SupportsWindows() || SupportsXnu()
|
||||
#if SupportsWindows() || SupportsMetal() || SupportsXnu()
|
||||
|
||||
// MZ Literally Executable Header
|
||||
//
|
||||
@@ -117,11 +113,7 @@ rlstr: .endobj rlstr,globl,hidden # ←for gdb readibility
|
||||
//
|
||||
// @param dl is drive number
|
||||
// @noreturn
|
||||
ape_mz: .ascii "MZ" # Mark 'Zibo' Joseph Zbikowski
|
||||
jno 2f # MZ: bytes on last page
|
||||
jo 2f # MZ: 512-byte pages in file
|
||||
.ascii "='" # MZ: reloc table entry count
|
||||
.ascii "\n\0" # MZ: data segment file offset / 16
|
||||
ape_mz: .asciz "MZqFpD='\n" # Mark 'Zibo' Joseph Zbikowski
|
||||
.short 0x1000 # MZ: lowers upper bound load / 16
|
||||
.short 0xf800 # MZ: roll greed on bss
|
||||
.short 0 # MZ: lower bound on stack segment
|
||||
@@ -135,14 +127,14 @@ ape_mz: .ascii "MZ" # Mark 'Zibo' Joseph Zbikowski
|
||||
.ascii "JT" # MZ: OEM identifier
|
||||
.short 0 # MZ: OEM information
|
||||
.org 0x40-4 # MZ: bytes reserved for you
|
||||
#if SupportsWindows()
|
||||
#if SupportsWindows() || SupportsMetal()
|
||||
.long RVA(ape_pe) # PE: the new technology
|
||||
#else
|
||||
.long 0
|
||||
#endif
|
||||
.endfn ape_mz,globl,hidden
|
||||
|
||||
#else /* !(SupportsWindows() || SupportsXnu()) */
|
||||
#else /* !(SupportsWindows() || SupportsMetal() || SupportsXnu()) */
|
||||
|
||||
// ELF Literally Executable Header
|
||||
//
|
||||
@@ -172,7 +164,9 @@ ape_mz: .ascii "MZ" # Mark 'Zibo' Joseph Zbikowski
|
||||
.short ape_elf_shnum # 3c: e_shnum
|
||||
.short ape_elf_shstrndx # 3e: e_shstrndx
|
||||
|
||||
#endif /* SupportsWindows() || SupportsXnu() */
|
||||
#endif /* SupportsWindows() || SupportsMetal() || SupportsXnu() */
|
||||
|
||||
#if SupportsMetal()
|
||||
|
||||
// Disk Operating System Stub
|
||||
//
|
||||
@@ -190,7 +184,7 @@ stub: mov $0x40,%dl # *literally* dos
|
||||
3: .byte 0xbd,0,0 # a.k.a. mov imm,%bp
|
||||
jmp pc # real mode, is real
|
||||
jmp _start # surprise it's unix
|
||||
// .endfn stub
|
||||
.endfn stub
|
||||
|
||||
/*─────────────────────────────────────────────────────────────────────────────╗
|
||||
│ αcτµαlly pδrταblε εxεcµταblε § ibm personal computer │
|
||||
@@ -220,18 +214,17 @@ pc: cld
|
||||
.byte 0x0f,0x1f,0207 # nop rdi binbase
|
||||
.short (0x7c00-IMAGE_BASE_VIRTUAL)/512
|
||||
#endif
|
||||
mov $REAL_STACK_FRAME>>4,%di # we need a stack
|
||||
xor %cx,%cx
|
||||
mov $0x70000>>4,%di # we need a stack
|
||||
xor %cx,%cx # 0x7f000-0x80000
|
||||
mov %cx,%es
|
||||
rlstack %di,%cx
|
||||
#if SupportsMetal()
|
||||
push %cs # memcpy() [relocate this page]
|
||||
pop %ds
|
||||
call 1f
|
||||
1: pop %si
|
||||
push %cs # determine load address
|
||||
pop %ds # and relocate this code
|
||||
call 1f # to a way lower address
|
||||
1: pop %si # and we'll make cs zero
|
||||
sub $RVA(1b),%si
|
||||
mov $IMAGE_BASE_REAL>>4,%ax
|
||||
push %ax # save real base
|
||||
push %ax # save IMAGE_BASE_REAL>>4
|
||||
push %ax
|
||||
pop %es
|
||||
xor %di,%di
|
||||
@@ -241,18 +234,18 @@ pc: cld
|
||||
.byte 0x0f,0x1f,0207 # nop rdi binbase
|
||||
.short (IMAGE_BASE_REAL-0x7c00)/512
|
||||
#endif
|
||||
ljmp $0,$REAL(1f) # longjmp()
|
||||
1: mov %cx,%ds # %ds and %cs are now zero
|
||||
mov $XLM_SIZE,%cx # memset to clear real bss
|
||||
mov $XLM_BASE_REAL>>4,%ax
|
||||
ljmp $0,$REAL(1f)
|
||||
1: mov %cx,%ds
|
||||
mov $IMAGE_BASE_REAL-0x0500,%cx # clears bss
|
||||
mov $0x0500>>4,%ax # struct mman
|
||||
mov %ax,%es
|
||||
xor %ax,%ax
|
||||
xor %di,%di
|
||||
rep stosb
|
||||
cmp $0x40,%dl # statfs() [disk geometry]
|
||||
cmp $0x40,%dl
|
||||
je 6f
|
||||
call dsknfo
|
||||
pop %es # restore real base
|
||||
pop %es # restore IMAGE_BASE_REAL>>4
|
||||
mov $1,%al # current sector
|
||||
xor %cx,%cx # current cylinder
|
||||
xor %dh,%dh # current head
|
||||
@@ -260,15 +253,7 @@ pc: cld
|
||||
3: call pcread
|
||||
dec %di
|
||||
jnz 3b
|
||||
6: mov $XLM(LOADSTATE),%di # ax,cx,dx,es
|
||||
stosw
|
||||
xchg %cx,%ax
|
||||
stosw
|
||||
xchg %dx,%ax
|
||||
stosw
|
||||
mov %es,%ax
|
||||
stosw
|
||||
ljmp $0,$REAL(realmodeloader)
|
||||
6: ljmp $0,$REAL(realmodeloader)
|
||||
.endfn pc
|
||||
|
||||
// Determines disk geometry.
|
||||
@@ -329,7 +314,7 @@ dsknfo: push %bx
|
||||
movpp %es,%ds
|
||||
xor %si,%si
|
||||
mov %si,%es
|
||||
mov $XLM(DRIVE_BASE_TABLE),%si
|
||||
mov $0x1510,%si # mman::pc_drive_base_table
|
||||
xchg %si,%di
|
||||
movsw #→ headunloadtime, headloadtime
|
||||
movsw #→ shutofftime, bytespersector
|
||||
@@ -382,11 +367,11 @@ pcread: push %ax
|
||||
add $512>>4,%si
|
||||
mov %si,%es
|
||||
inc %al # ++sector
|
||||
cmp XLM(DRIVE_LAST_SECTOR),%al
|
||||
cmp 0x151c,%al # mman::pc_drive_last_sector
|
||||
jbe 2f
|
||||
mov $1,%al
|
||||
inc %dh # ++head
|
||||
cmp XLM(DRIVE_LAST_HEAD),%dh
|
||||
cmp 0x1520,%dh # mman::pc_drive_last_head
|
||||
jbe 2f
|
||||
xor %dh,%dh
|
||||
inc %cx # ++cylinder
|
||||
@@ -398,6 +383,82 @@ pcread: push %ax
|
||||
jmp pcread
|
||||
.endfn pcread
|
||||
|
||||
// Video put string.
|
||||
//
|
||||
// @param di is the string
|
||||
// @clob bp,bx
|
||||
// @mode real
|
||||
rvputs: mov %di,%si
|
||||
0: lodsb
|
||||
test %al,%al
|
||||
je 1f
|
||||
mov $7,%bx # normal mda/cga style page zero
|
||||
mov $0x0e,%ah # teletype output al cp437
|
||||
int $0x10 # vidya service
|
||||
jmp 0b
|
||||
1: ret
|
||||
.endfn rvputs
|
||||
|
||||
// Abnormally halts startup.
|
||||
//
|
||||
// @param di message
|
||||
// @mode real
|
||||
// @noreturn
|
||||
rldie: push %di
|
||||
mov $REAL(str.error),%di
|
||||
call rvputs
|
||||
pop %di
|
||||
call rvputs
|
||||
mov $REAL(str.crlf),%di
|
||||
call rvputs
|
||||
0: rep nop
|
||||
jmp 0b
|
||||
.endfn rldie
|
||||
|
||||
// Initializes present PC serial lines.
|
||||
sinit4: mov $4,%cx
|
||||
mov $0x400,%si # BDA.COM1
|
||||
0: lodsw
|
||||
test %ax,%ax
|
||||
jz 1f
|
||||
push %cx
|
||||
push %si
|
||||
xchg %ax,%di
|
||||
mov $REAL(sconf),%si
|
||||
call sinit
|
||||
pop %si
|
||||
pop %cx
|
||||
1: loop 0b
|
||||
ret
|
||||
.endfn sinit4,global,hidden
|
||||
|
||||
// Initializes Serial Line Communications 8250 UART 16550A
|
||||
//
|
||||
// @param word di tty port
|
||||
// @param char (*{es:,e,r}si)[4] register initial values
|
||||
// @mode long,legacy,real
|
||||
// @see www.lammertbies.nl/comm/info/serial-uart.html
|
||||
sinit: mov %di,%dx
|
||||
test %dx,%dx
|
||||
jz 2f
|
||||
push %dx
|
||||
push %si
|
||||
xor %cx,%cx
|
||||
mov $UART_LCR,%cl
|
||||
add %cx,%dx
|
||||
lodsb %ds:(%si),%al
|
||||
pop %si
|
||||
or $UART_DLAB,%al
|
||||
out %al,%dx
|
||||
pop %dx
|
||||
1: lodsb %ds:(%si),%al
|
||||
out %al,%dx
|
||||
inc %dx
|
||||
dec %cx
|
||||
jns 1b
|
||||
2: ret
|
||||
.endfn sinit,global,hidden
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ αcτµαlly pδrταblε εxεcµταblε § partition table ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
@@ -472,7 +533,7 @@ ape_disk:
|
||||
╚────────────────────────────────────────────────────────────────────────────│─╝
|
||||
the bourne executable & linkable format */
|
||||
|
||||
#if SupportsWindows() || SupportsXnu()
|
||||
#if SupportsWindows() || SupportsMetal() || SupportsXnu()
|
||||
apesh: .ascii "'\n#'\"\n" # sixth edition shebang
|
||||
.ascii "o=\"$(command -v \"$0\")\"\n"
|
||||
#if SupportsXnu()
|
||||
@@ -509,9 +570,11 @@ apesh: .ascii "'\n#'\"\n" # sixth edition shebang
|
||||
.shstub ape_elf_phnum,2 # 38: e_phnum
|
||||
.ascii "\\0\\0" # 3a: e_shentsize
|
||||
.shstub ape_elf_shnum,2 # 3c: e_shnum
|
||||
.shstub ape_elf_shstrndx,2 # 3e: e_shstrndx
|
||||
.shstub ape_elf_shstrndx,2 # 3e: e_shstrndx
|
||||
.ascii "' >&7\n"
|
||||
.ascii "exec 7<&-\n"
|
||||
.ascii "else\n"
|
||||
.ascii "exit 1\n"
|
||||
.ascii "fi\n"
|
||||
.ascii "exec \"$0\" \"$@\"\n" # etxtbsy tail recursion
|
||||
.ascii "R=$?\n" # architecture optimistic
|
||||
@@ -527,14 +590,11 @@ apesh: .ascii "'\n#'\"\n" # sixth edition shebang
|
||||
.ascii "fi\n"
|
||||
.ascii "exit $R\n"
|
||||
.endobj apesh
|
||||
#endif /* SupportsWindows() || SupportsXnu() */
|
||||
#endif /* SupportsWindows() || SupportsMetal() || SupportsXnu() */
|
||||
|
||||
#if SupportsSystemv() || SupportsMetal()
|
||||
.section .elf.phdrs,"a",@progbits
|
||||
.align __SIZEOF_POINTER__
|
||||
.type ape_phdrs,@object
|
||||
.globl ape_phdrs
|
||||
ape_phdrs:
|
||||
.long PT_LOAD # text segment
|
||||
.long PT_LOAD
|
||||
.long PF_R|PF_X
|
||||
.stub ape_rom_offset,quad
|
||||
.stub ape_rom_vaddr,quad
|
||||
@@ -542,8 +602,7 @@ ape_phdrs:
|
||||
.stub ape_rom_filesz,quad
|
||||
.stub ape_rom_memsz,quad
|
||||
.stub ape_rom_align,quad
|
||||
.align __SIZEOF_POINTER__
|
||||
.long PT_LOAD # data segment
|
||||
.long PT_LOAD
|
||||
.long PF_R|PF_W
|
||||
.stub ape_ram_offset,quad
|
||||
.stub ape_ram_vaddr,quad
|
||||
@@ -551,22 +610,16 @@ ape_phdrs:
|
||||
.stub ape_ram_filesz,quad
|
||||
.stub ape_ram_memsz,quad
|
||||
.stub ape_ram_align,quad
|
||||
#if SupportsLinux()
|
||||
// Linux ignores mprotect() and returns 0 without this lool
|
||||
// It has nothing to do with the stack, which is still exec
|
||||
.align __SIZEOF_POINTER__
|
||||
.long PT_GNU_STACK # p_type
|
||||
.long PF_R|PF_W # p_flags
|
||||
.quad 0 # p_offset
|
||||
.quad 0 # p_vaddr
|
||||
.quad 0 # p_paddr
|
||||
.quad 0 # p_filesz
|
||||
.quad 0 # p_memsz
|
||||
.quad 16 # p_align
|
||||
#endif
|
||||
.long PT_GNU_STACK
|
||||
.long PF_R|PF_W
|
||||
.stub ape_stack_offset,quad
|
||||
.stub ape_stack_vaddr,quad
|
||||
.stub ape_stack_paddr,quad
|
||||
.stub ape_stack_filesz,quad
|
||||
.stub ape_stack_memsz,quad
|
||||
.stub ape_stack_align,quad
|
||||
#if SupportsOpenbsd() || SupportsNetbsd()
|
||||
.align __SIZEOF_POINTER__
|
||||
.long PT_NOTE # notes
|
||||
.long PT_NOTE
|
||||
.long PF_R
|
||||
.stub ape_note_offset,quad
|
||||
.stub ape_note_vaddr,quad
|
||||
@@ -576,6 +629,7 @@ ape_phdrs:
|
||||
.stub ape_note_align,quad
|
||||
#endif
|
||||
.previous
|
||||
#endif /* SupportsSystemv() || SupportsMetal() */
|
||||
|
||||
#if SupportsOpenbsd()
|
||||
.section .note.openbsd.ident,"a",@progbits
|
||||
@@ -818,7 +872,7 @@ PETEXT = 0b01110000000000000000000001100000
|
||||
PEDATA = 0b11000000000000000000000011000000
|
||||
PEIMPS = 0b11000000000000000000000001000000
|
||||
|
||||
#if SupportsWindows()
|
||||
#if SupportsWindows() || SupportsMetal()
|
||||
|
||||
.section .pe.header,"a",@progbits
|
||||
.align __SIZEOF_POINTER__
|
||||
@@ -836,23 +890,23 @@ ape_pe: .ascin "PE",4
|
||||
.long 0 # SizeOfCode
|
||||
.long 0 # SizeOfInitializedData
|
||||
.long 0 # SizeOfUninitializedData
|
||||
.long RVA(WinMain) # EntryPoint
|
||||
.long RVA(ape_pe_entry) # EntryPoint
|
||||
.long 0 # BaseOfCode
|
||||
.quad IMAGE_BASE_VIRTUAL # ImageBase
|
||||
.quad ape_pe_base # ImageBase
|
||||
.long 4096 # SectionAlignment
|
||||
.long 4096 # FileAlignment
|
||||
.short 6 # MajorOperatingSystemVersion
|
||||
.short v_ntversion # MajorOperatingSystemVersion
|
||||
.short 0 # MinorOperatingSystemVersion
|
||||
.short 0 # MajorImageVersion
|
||||
.short 0 # MinorImageVersion
|
||||
.short 6 # MajorSubsystemVersion
|
||||
.short v_ntsubversion # MajorSubsystemVersion
|
||||
.short 0 # MinorSubsystemVersion
|
||||
.long 0 # Win32VersionValue
|
||||
.long RVA(_end) # SizeOfImage
|
||||
.long RVA(_ehead) # SizeOfHeaders
|
||||
.long 0 # Checksum
|
||||
.short v_ntsubsystem # Subsystem: 0=Neutral,2=GUI,3=Console
|
||||
.short DLLEXE # DllCharacteristics
|
||||
.stub v_ntdllchar,short # DllCharacteristics
|
||||
.quad 0x0000000000100000 # StackReserve
|
||||
.quad 0x00000000000fc000 # StackCommit
|
||||
.quad 0 # HeapReserve
|
||||
@@ -860,7 +914,7 @@ ape_pe: .ascin "PE",4
|
||||
.long 0 # LoaderFlags
|
||||
.long 16 # NumberOfDirectoryEntries
|
||||
.long 0,0 # ExportsDirectory
|
||||
.long RVA(ape_idata_idt) # ImportsDirectory
|
||||
.stub ape_idata,long # ImportsDirectory
|
||||
.stub ape_idata_idtsize,long # ImportsDirectorySize
|
||||
.long 0,0 # ResourcesDirectory
|
||||
.long 0,0 # ExceptionsDirectory
|
||||
@@ -872,7 +926,7 @@ ape_pe: .ascin "PE",4
|
||||
.long 0,0 # ThreadLocalStorage
|
||||
.long 0,0 # LoadConfigurationDirectory
|
||||
.long 0,0 # BoundImportDirectory
|
||||
.long RVA(ape_idata_iat) # ImportAddressDirectory
|
||||
.stub ape_idata,long # ImportAddressDirectory
|
||||
.stub ape_idata_iatsize,long # ImportAddressDirectorySize
|
||||
.long 0,0 # DelayImportDescriptor
|
||||
.long 0,0 # ComPlusRuntimeHeader
|
||||
@@ -890,7 +944,7 @@ ape_pe: .ascin "PE",4
|
||||
.long 0 # Line Number Table Offset
|
||||
.short 0 # Relocation Count
|
||||
.short 0 # Line Number Count
|
||||
.long PETEXT # Flags
|
||||
.long PETEXT # Flags
|
||||
.previous
|
||||
|
||||
.section .pe.sections,"a",@progbits
|
||||
@@ -903,10 +957,10 @@ ape_pe: .ascin "PE",4
|
||||
.long 0 # Line Number Table Offset
|
||||
.short 0 # Relocation Count
|
||||
.short 0 # Line Number Count
|
||||
.long PEDATA # Flags
|
||||
.long PEDATA # Flags
|
||||
.previous
|
||||
|
||||
#endif /* SupportsWindows() */
|
||||
#endif /* SupportsWindows() || SupportsMetal() */
|
||||
|
||||
.section .idata.ro.idt.1,"a",@progbits
|
||||
.type ape_idata_idtend,@object
|
||||
@@ -944,13 +998,6 @@ ape_idata_iatend:
|
||||
better code/data separation (.head is rwx[real] rx[long]) */
|
||||
|
||||
// NUL-Terminated Strings.
|
||||
ape.str:
|
||||
str.ape:
|
||||
.byte 0xe0,0x63,0xe7,0xe6,0xe0,0x6c,0x6c,0x79 #αcτµαlly
|
||||
.byte 0x20,0x70,0xeb,0x72,0xe7,0xe0,0x62,0x6c # pδrταbl
|
||||
.byte 0xee,0x20,0xee,0x78,0xee,0x63,0xe6,0xe7 #ε εxεcµτ
|
||||
.byte 0xe0,0x62,0x6c,0xee,0x0d,0x0a,0x00 #αblε.
|
||||
.endobj str.ape
|
||||
str.error:
|
||||
.asciz "error: "
|
||||
.endobj str.error
|
||||
@@ -963,19 +1010,12 @@ str.cpuid:
|
||||
str.oldskool:
|
||||
.asciz "oldskool"
|
||||
.endobj str.oldskool
|
||||
str.dsknfo:
|
||||
.asciz "dsknfo"
|
||||
.endobj str.dsknfo
|
||||
str.e820:
|
||||
.asciz "e820"
|
||||
.endobj str.e820
|
||||
str.memory:
|
||||
.asciz "nomem"
|
||||
.endobj str.memory
|
||||
str.long:
|
||||
.asciz "nolong"
|
||||
.endobj str.long
|
||||
.endobj ape.str
|
||||
|
||||
// Serial Line Configuration (8250 UART 16550)
|
||||
// If it's hacked, it'll at least get hacked very slowly.
|
||||
@@ -1065,8 +1105,8 @@ ape_grub:
|
||||
.align 4
|
||||
ape_grub_entry:
|
||||
.code32
|
||||
cmp $GRUB_EAX,%eax
|
||||
jne triplf
|
||||
// cmp $GRUB_EAX,%eax
|
||||
// jne triplf
|
||||
push $0
|
||||
popf
|
||||
mov $0x40,%dl
|
||||
@@ -1082,18 +1122,12 @@ ape_grub_entry:
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
the default mode of operation on modern cpus */
|
||||
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
realmodeloader:
|
||||
call16 rlinit
|
||||
call16 sinit4
|
||||
mov $REAL(str.ape),%di
|
||||
call16 rvputs
|
||||
call rlinit
|
||||
call sinit4
|
||||
.optfn _start16
|
||||
call16 _start16
|
||||
call16 longmodeloader
|
||||
call _start16
|
||||
call longmodeloader
|
||||
.endfn realmodeloader
|
||||
|
||||
.section .sort.text.real.init.1,"ax",@progbits
|
||||
@@ -1106,86 +1140,6 @@ rlinit: .previous/*
|
||||
ret
|
||||
.previous
|
||||
|
||||
// Initializes present PC serial lines.
|
||||
sinit4: mov $4,%cx
|
||||
mov $kBiosDataAreaXlm+COM1,%si
|
||||
0: lodsw
|
||||
test %ax,%ax
|
||||
jz 1f
|
||||
push %cx
|
||||
push %si
|
||||
xchg %ax,%di
|
||||
mov $REAL(sconf),%si
|
||||
call16 sinit
|
||||
pop %si
|
||||
pop %cx
|
||||
1: loop 0b
|
||||
ret
|
||||
.endfn sinit4,global,hidden
|
||||
|
||||
// Initializes Serial Line Communications 8250 UART 16550A
|
||||
//
|
||||
// @param word di tty port
|
||||
// @param char (*{es:,e,r}si)[4] register initial values
|
||||
// @mode long,legacy,real
|
||||
// @see www.lammertbies.nl/comm/info/serial-uart.html
|
||||
sinit: mov %di,%dx
|
||||
test %dx,%dx
|
||||
jz 2f
|
||||
push %dx
|
||||
push %si
|
||||
xorw %cx,%cx
|
||||
mov $UART_LCR,%cl
|
||||
add %cx,%dx
|
||||
lodsb %ds:(%si),%al
|
||||
pop %si
|
||||
or $UART_DLAB,%al
|
||||
out %al,%dx
|
||||
pop %dx
|
||||
1: lodsb %ds:(%si),%al
|
||||
out %al,%dx
|
||||
add $1,%dx
|
||||
sub $1,%cx
|
||||
jns 1b
|
||||
2: ret
|
||||
.endfn sinit,global,hidden
|
||||
|
||||
// Video put string.
|
||||
//
|
||||
// @param di is the string
|
||||
// @mode real
|
||||
rvputs: push %bp
|
||||
push %bx
|
||||
mov %di,%si
|
||||
0: lodsb
|
||||
test %al,%al
|
||||
je 1f
|
||||
mov $7,%bx # normal mda/cga style page zero
|
||||
mov $0x0e,%ah # teletype output al cp437
|
||||
int $0x10 # vidya service
|
||||
jmp 0b
|
||||
1: pop %bx
|
||||
pop %bp
|
||||
ret
|
||||
.endfn rvputs
|
||||
|
||||
// Abnormally halts startup.
|
||||
//
|
||||
// @param di message
|
||||
// @mode real
|
||||
// @noreturn
|
||||
rldie: push %di
|
||||
mov $REAL(str.error),%di
|
||||
call16 rvputs
|
||||
pop %di
|
||||
call16 rvputs
|
||||
mov $REAL(str.crlf),%di
|
||||
call16 rvputs
|
||||
xor %ax,%ax # get keystroke
|
||||
int $0x16 # keyboard service
|
||||
call16 triplf
|
||||
.endfn rldie
|
||||
|
||||
/* █ █▒
|
||||
█ █
|
||||
█▓▄ █ █
|
||||
@@ -1233,18 +1187,11 @@ rldie: push %di
|
||||
long mode is long */
|
||||
|
||||
longmodeloader:
|
||||
call16 lcheck
|
||||
call16 a20
|
||||
mov $XLM(E820),%di
|
||||
mov $XLM_E820_SIZE,%si
|
||||
call16 e820
|
||||
jc 9f
|
||||
call16 unreal
|
||||
// call hiload
|
||||
call16 pinit
|
||||
call16 golong
|
||||
9: mov $REAL(str.e820),%ax
|
||||
call16 rldie
|
||||
call lcheck
|
||||
call a20
|
||||
call e820
|
||||
call pinit
|
||||
call golong
|
||||
.endfn longmodeloader
|
||||
|
||||
// Long Mode Hardware Check
|
||||
@@ -1280,35 +1227,25 @@ lcheck: pushf # check for i8086 / i8088 / i80186
|
||||
jne 10f
|
||||
xor %ax,%ax
|
||||
1: ret
|
||||
9: mov $REAL(str.oldskool),%ax
|
||||
9: mov $REAL(str.oldskool),%di
|
||||
jmp 20f
|
||||
10: mov $REAL(str.long),%ax
|
||||
10: mov $REAL(str.long),%di
|
||||
jmp 20f
|
||||
12: mov $REAL(str.cpuid),%ax
|
||||
jmp 20f
|
||||
20: call16 rldie
|
||||
12: mov $REAL(str.cpuid),%di
|
||||
20: call rldie
|
||||
.endfn lcheck
|
||||
|
||||
// Gets memory map from BIOS.
|
||||
//
|
||||
// @param di paragraph aligned buffer
|
||||
// @param si bytes in buffer to fill
|
||||
// @return number of bytes written or CF on error
|
||||
// @mode real
|
||||
e820: push %bp
|
||||
mov %sp,%bp
|
||||
pushl $'S'<<24|'M'<<16|'A'<<8|'P' # magic @ -4(%bp)
|
||||
push %bx
|
||||
shr $4,%di
|
||||
e820: mov $0x0510>>4,%di # mman::e820
|
||||
mov %di,%es
|
||||
xor %edi,%edi # es:di is destination buffer
|
||||
xor %ebx,%ebx # ebx is an api state tracker
|
||||
1: mov $0xE820,%eax # magic
|
||||
mov $8+8+4+4,%ecx # sizeof(struct SmapEntry)
|
||||
mov -4(%bp),%edx # magic
|
||||
mov $0x534d4150,%edx # magic number
|
||||
int $0x15 # ax,bx,cx,dx,di → ax,bx,cx
|
||||
jc 9f # cf = unsupported or abuse
|
||||
cmp -4(%bp),%eax # more magic means success
|
||||
cmp %edx,%eax # more magic means success
|
||||
jne 9f
|
||||
test %cx,%cx # discard empty results
|
||||
jz 5f
|
||||
@@ -1318,78 +1255,14 @@ e820: push %bp
|
||||
jnz 5f
|
||||
4: add $8+8+4+4,%di # keep entry
|
||||
5: test %ebx,%ebx # last entry?
|
||||
jz 7f
|
||||
cmp %si,%di # out of buf?
|
||||
jz 8f
|
||||
cmp $0x1000,%di
|
||||
jb 1b
|
||||
7: mov %di,%ax
|
||||
8: pop %bx
|
||||
leave
|
||||
ret
|
||||
9: stc
|
||||
jmp 8b
|
||||
8: ret
|
||||
9: mov $REAL(str.e820),%di
|
||||
call rldie
|
||||
.endfn e820
|
||||
|
||||
// Unreal Mode.
|
||||
// Makes 4gb of real memory accessible via %fs segment.
|
||||
unreal: cli
|
||||
lgdt REAL(gdt)
|
||||
mov %cr0,%eax
|
||||
or $CR0_PE,%al
|
||||
mov %eax,%cr0
|
||||
jmp 1f
|
||||
1: mov $GDT_LEGACY_DATA,%cx
|
||||
mov %cx,%fs
|
||||
and $~CR0_PE,%al
|
||||
mov %eax,%cr0
|
||||
ljmp $0,$REAL(1f)
|
||||
1: sti
|
||||
ret
|
||||
.endfn unreal
|
||||
|
||||
// Loads remainder of executable off disk.
|
||||
hiload: push %bx
|
||||
mov $IMAGE_BASE_REAL,%esi # relocate, again
|
||||
mov $IMAGE_BASE_PHYSICAL,%ebx
|
||||
mov $v_ape_realsectors,%ecx
|
||||
shl $9,%ecx
|
||||
or $-4,%edx
|
||||
0: add $4,%edx
|
||||
cmp %edx,%ecx
|
||||
je 1f
|
||||
mov %fs:(%esi,%edx),%eax
|
||||
mov %eax,%fs:(%ebx,%edx)
|
||||
jmp 0b
|
||||
1: lea (%ebx,%edx),%ebx
|
||||
mov $v_ape_highsectors,%di # then copy rest off disk
|
||||
mov $REAL_SCRATCH_AREA>>4,%ax # to real memory buffer
|
||||
mov %ax,%es
|
||||
mov XLM(LOADSTATE)+0,%ax
|
||||
mov XLM(LOADSTATE)+2,%cx
|
||||
mov XLM(LOADSTATE)+4,%dx
|
||||
0: test %di,%di
|
||||
jz 9f
|
||||
mov %di,%ax
|
||||
push %bx
|
||||
xor %bx,%bx
|
||||
call16 pcread
|
||||
pop %bx
|
||||
sub %ax,%di
|
||||
push %cx
|
||||
mov %ax,%cx # copy real buffer to high
|
||||
shl $9,%cx # no way bios loaded >64k
|
||||
xor %si,%si
|
||||
1: mov %es:(%si),%eax
|
||||
mov %eax,%fs:(%ebx)
|
||||
add $4,%ebx
|
||||
add $4,%si
|
||||
sub $4,%cx
|
||||
jnz 1b
|
||||
pop %cx
|
||||
jmp 0b
|
||||
9: pop %bx
|
||||
ret
|
||||
.endfn hiload
|
||||
|
||||
// Asks keyboard to grant system 65,519 more bytes of memory.
|
||||
//
|
||||
// Yup.
|
||||
@@ -1420,26 +1293,26 @@ a20: cli
|
||||
pop %ds
|
||||
jne 3f
|
||||
mov $1,%ax
|
||||
call16 1f
|
||||
call 1f
|
||||
mov $0xad,%al
|
||||
out %al,$0x64
|
||||
call16 1f
|
||||
call 1f
|
||||
mov $0xd0,%al
|
||||
out %al,$0x64
|
||||
call16 2f
|
||||
call 2f
|
||||
in $0x60,%al
|
||||
push %ax
|
||||
call16 1f
|
||||
call 1f
|
||||
mov $0xd1,%al
|
||||
out %al,$0x64
|
||||
call16 1f
|
||||
call 1f
|
||||
pop %ax
|
||||
or $2,%al
|
||||
out %al,$0x60
|
||||
call16 1f
|
||||
call 1f
|
||||
mov $0xae,%al
|
||||
out %al,$0x64
|
||||
call16 1f
|
||||
call 1f
|
||||
jmp a20
|
||||
1: in $0x64,%al
|
||||
test $2,%al
|
||||
@@ -1454,33 +1327,26 @@ a20: cli
|
||||
.endfn a20
|
||||
|
||||
// Initializes long mode paging.
|
||||
//
|
||||
// Modern computers access memory via four levels of indirection:
|
||||
//
|
||||
// register char (*(*(*(*ram)[512])[512])[512])[4096] asm(cr3)
|
||||
//
|
||||
// Your page tables grow down in memory, starting from the real
|
||||
// stack segment base. This function only defines enough tables
|
||||
// to get us started.
|
||||
#define TIP REAL_STACK_FRAME
|
||||
pinit: push %ds
|
||||
mov $(TIP-0x4000)>>4,%ax
|
||||
#define SEG 0x79000
|
||||
mov $SEG>>4,%ax
|
||||
mov %ax,%ds
|
||||
movl $TIP-0x2000+PAGE_V+PAGE_RW,0x3000 # PML4T→PDPT
|
||||
movl $TIP-0x3000+PAGE_V+PAGE_RW,0x2000 # PDPT→PDT
|
||||
movl $TIP-0x4000+PAGE_V+PAGE_RW,0x1000 # PDT→PD
|
||||
mov $0x100000/0x1000,%cx # PD→512kb
|
||||
movl $0x7d000+PAGE_V+PAGE_RW,0x7e000-SEG # PDPT←PML4T (+)
|
||||
movl $0x7c000+PAGE_V+PAGE_RW,0x7e800-SEG # PDPT←PML4T (-)
|
||||
movl $0x7b000+PAGE_V+PAGE_RW,0x7d000-SEG # PDT←PDPT (+)
|
||||
movl $0x7a000+PAGE_V+PAGE_RW,0x7c000-SEG # PDT←PDPT (-)
|
||||
movl $0x79000+PAGE_V+PAGE_RW,0x7b000-SEG # PD←PDT (+)
|
||||
movl $0x79000+PAGE_V+PAGE_RW,0x7a000-SEG # PD←PDT (-)
|
||||
mov $512,%cx # PD±2MB
|
||||
mov $PAGE_V+PAGE_RW,%eax
|
||||
xor %si,%si
|
||||
0: mov %eax,(%si)
|
||||
add $0x1000,%eax
|
||||
add $8,%si
|
||||
loop 0b
|
||||
movb $0,0 # unmap null
|
||||
pop %ds
|
||||
movl $TIP-0x4000,XLM(PAGE_TABLE_STACK_POINTER) # STACK→XLM
|
||||
mov $TIP-0x1000,%eax # PML4T→CR3
|
||||
mov $0x7e000,%eax # PML4T←CR3
|
||||
mov %eax,%cr3
|
||||
pop %ds
|
||||
ret
|
||||
.endfn pinit
|
||||
|
||||
@@ -1488,7 +1354,7 @@ pinit: push %ds
|
||||
//
|
||||
// @see Intel Manual V3A §4.1.2
|
||||
golong: cli
|
||||
lidt XLM(BADIDT)
|
||||
lidt 0x1522 # mman::bad_idt
|
||||
mov %cr4,%eax
|
||||
or $CR4_PAE|CR4_PGE|CR4_OSFXSR,%eax
|
||||
mov %eax,%cr4
|
||||
@@ -1505,7 +1371,6 @@ golong: cli
|
||||
.endfn golong
|
||||
|
||||
// Long mode is long.
|
||||
// @noreturn
|
||||
.code64
|
||||
long: push $GDT_LONG_DATA
|
||||
pop %rax
|
||||
@@ -1514,37 +1379,89 @@ long: push $GDT_LONG_DATA
|
||||
mov %eax,%es
|
||||
mov %eax,%fs
|
||||
mov %eax,%gs
|
||||
mov $0x80000,%esp
|
||||
xor %r12d,%r12d
|
||||
xor %r13d,%r13d
|
||||
xor %r14d,%r14d
|
||||
xor %r15d,%r15d
|
||||
xor %ebx,%ebx
|
||||
xor %ebp,%ebp
|
||||
mov $REAL_STACK_FRAME+FRAMESIZE,%esp
|
||||
call __map_image
|
||||
ezlea metal,ax
|
||||
push %rbp
|
||||
mov $0x0500,%rdi # mman
|
||||
mov %cr3,%rsi
|
||||
mov $IMAGE_BASE_REAL,%edx
|
||||
call __map_phdrs
|
||||
push $0x037f
|
||||
fldcw (%rsp)
|
||||
movabs $kernel,%rax
|
||||
jmp *%rax
|
||||
.endfn long
|
||||
|
||||
// Long mode in virtual address space.
|
||||
// @noreturn
|
||||
metal:
|
||||
/* ▄▄▒▀▀▀▀▒▒▄░
|
||||
█████▓▓▄░░░░ ▒▒▄░
|
||||
▐█▓▓█▓▄█████▓░ ▀▒▄
|
||||
▓█▓▓▓▓▓▓▓▓▓█▓ ░▀▒░
|
||||
░▀▀▓█▓▓▓▓▓▓█▓ ░▀▒▄▄▒▄▄▄▒▒▒▀▀▀▀▀▀▀▀▀▀▀▀▀▀▒▒▄▒
|
||||
░▀▓▓█▓▓▓▓▓▄ ░ ░▀▒▄▄ ▄
|
||||
░▀█▓▓▓▓▓▄░ ░▀▒░ ▄▓▌
|
||||
▀█▓▓▓▓▓█▓░ ░▀▄░ ░▄▓██░
|
||||
░▀█▓▓▓▓▓█▄ ░▀▒▄▄▄▄▄▄▄▄▒▀▓█▓█▓░
|
||||
░▀█▓▓▓▓█▓░ ░▄▓█▓▓█▓▄▌
|
||||
░▀█▓▓▓▓▓▄ ▄▄▄▓▓██▓▓▒▒░ ▒▒▄▓█▓▓▓▓█▓
|
||||
▀█▓▓▓▓▓▓▄▄░ ░▄▄▓██▓▓▓▓▓██████████████▓▓▓▓▓▓█▀
|
||||
▐█▓▓▓▓▓▓▓██▓▓▄▄▄▄▄▄▄▄▄▓▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█████████▓▓▀░
|
||||
▀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█░ ░░░░░░
|
||||
▄░▓█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▌
|
||||
█▓▄▀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▓▀▀▀▀▀▀▀▓█▓▓▓▓▓▓▓▓▓▓▓▓
|
||||
▐█▓█▓░▓█▓▓▓▓▓▓▓█▀▀▀▀▒░ ▐▓▓▓▓▓▓▄▒▀▓█▓▓▓▓▓▓▓▓█▌
|
||||
▐█▓▓▓█▒▀█▓▓▓▓▓▓█▌ ▀█▓▓▓▓▓█▄░▀▓▓█▓▓▓▓▓▓█░
|
||||
█▓▓▓▓▓█░▐█▓▓▓▓▓█▌ ▀▓█▓▓▓▓█▌ ░▀█▓▓▓▓▓█▄
|
||||
█▓▓▓▓█▌ ░█▓▓▓▓▓█░ ▓█▓▓▓▓▓░ ▒█▓▓▓▓▓█░
|
||||
█▓▓▓▓█░ █▓▓▓▓▓█░ █▓▓▓▓▓█░ ▐█▓▓▓▓█▌
|
||||
▐█▓▓▓▓▓▄ █▓▓▓▓▓█ ░▄▄▓█▓▓▓▓▓█░ ▐█▓▓▓▓█░
|
||||
▓█▓▓▓█▓▐█▓▓▓▓█▌ ▓██▓▓▓▓▓▓█▀ ▓█▓▓▓▓█
|
||||
▀▓██▒▄█▓▓▓▓▓█░ ░█▓▓▓▓▓██▀░ ░▓█▓▓▓▓█▌
|
||||
░░█▓▓▓▓▓█▓ ░▀▀▀▀▀▀ ▓█▓▓▓▓▓▓
|
||||
╔───────────────────────────────────────────────────────────▀▀▀▀▀▀───────────│─╗
|
||||
│ αcτµαlly pδrταblε εxεcµταblε § cosmopolitan libc runtime runtime ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
kernel: movabs $ape_stack_vaddr,%rsp
|
||||
add $ape_stack_memsz,%rsp
|
||||
movl $0,0x7b000 # unmap null 2mb
|
||||
#if USE_SYMBOL_HACK
|
||||
.byte 0x0f,0x1f,0207 # nop rdi binbase
|
||||
.long (IMAGE_BASE_VIRTUAL-IMAGE_BASE_REAL)/512
|
||||
#endif
|
||||
xor %eax,%eax # clear bss
|
||||
mov $ape_bss_vaddr,%edi
|
||||
mov $ape_bss_memsz,%ecx
|
||||
rep stosb
|
||||
.weak __hostos
|
||||
ezlea __hostos,ax
|
||||
test %rax,%rax
|
||||
jz 1f
|
||||
movb $METAL,(%rax)
|
||||
1: push $0 # auxv
|
||||
push $0
|
||||
push $0 # envp
|
||||
push $0 # auxv
|
||||
push $0 # argc
|
||||
1: xor %eax,%eax
|
||||
xor %ecx,%ecx
|
||||
xor %edx,%edx
|
||||
xor %edi,%edi
|
||||
xor %esi,%esi
|
||||
xor %r8d,%r8d
|
||||
xor %r9d,%r9d
|
||||
xor %r10d,%r10d
|
||||
xor %r11d,%r11d
|
||||
push $0 # auxv[1][1]
|
||||
push $0 # auxv[1][0]
|
||||
push $.Larg0 # auxv[0][1]
|
||||
push $31 # auxv[0][0] AT_EXECFN
|
||||
push $0 # envp[1]
|
||||
push $.Lenv0 # envp[0]
|
||||
push $0 # argv[1]
|
||||
push $.Larg0 # argv[0]
|
||||
push $1 # argc
|
||||
jmp _start
|
||||
.endfn metal
|
||||
.endfn kernel
|
||||
|
||||
.rodata
|
||||
.Larg0: .asciz "ape.com"
|
||||
.Lenv0: .asciz "METAL=1"
|
||||
.previous
|
||||
|
||||
#endif /* SupportsMetal() */
|
||||
|
||||
@@ -1565,6 +1482,7 @@ metal:
|
||||
.type ape_note,@object
|
||||
.type ape_note_end,@object
|
||||
.type ape_note_vaddr,@object
|
||||
.type ape_phdrs,@object
|
||||
.type ape_pe_sections,@object
|
||||
.type ape_pe_sections_end,@object
|
||||
.type ape_text_nops,@object
|
||||
@@ -1600,12 +1518,6 @@ ape_pad_text:
|
||||
ape_pad_privileged:
|
||||
.previous
|
||||
|
||||
.section .ape.pad.test,"a",@progbits
|
||||
.type ape_pad_test,@object
|
||||
.hidden ape_pad_test
|
||||
ape_pad_test:
|
||||
.previous
|
||||
|
||||
.section .ape.pad.rodata,"a",@progbits
|
||||
.type ape_pad_rodata,@object
|
||||
.hidden ape_pad_rodata
|
||||
|
||||
+55
-35
@@ -175,7 +175,7 @@
|
||||
|
||||
#ifdef __LINKER__
|
||||
#include "ape/macros.internal.h"
|
||||
#include "ape/config.h"
|
||||
#include "ape/relocations.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nt/pedef.internal.h"
|
||||
#include "libc/zip.h"
|
||||
@@ -196,42 +196,39 @@ SECTIONS {
|
||||
/*BEGIN: linux addressability guarantee */
|
||||
/*BEGIN: bsd addressability guarantee */
|
||||
|
||||
.head SEGMENT_START("text-segment", IMAGE_BASE_VIRTUAL) : {
|
||||
.head SEGMENT_START("text-segment", IMAGE_BASE_VIRTUAL) : AT(IMAGE_BASE_REAL) {
|
||||
HIDDEN(_base = .);
|
||||
|
||||
/* Real Mode */
|
||||
KEEP(*(.head))
|
||||
. += 1;
|
||||
KEEP(*(.text.head))
|
||||
|
||||
/* Executable & Linkable Format */
|
||||
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 1);
|
||||
. = ALIGN(__SIZEOF_POINTER__);
|
||||
HIDDEN(ape_phdrs = .);
|
||||
KEEP(*(.elf.phdrs))
|
||||
HIDDEN(ape_phdrs_end = .);
|
||||
. += 1;
|
||||
|
||||
/* OpenBSD */
|
||||
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 1);
|
||||
. = ALIGN(__SIZEOF_POINTER__);
|
||||
HIDDEN(ape_note = .);
|
||||
KEEP(*(.note.openbsd.ident))
|
||||
KEEP(*(.note.netbsd.ident))
|
||||
HIDDEN(ape_note_end = .);
|
||||
. += 1;
|
||||
|
||||
/* Portable Executable */
|
||||
KEEP(*(.pe.header))
|
||||
HIDDEN(ape_pe_sections = .);
|
||||
KEEP(*(.pe.sections))
|
||||
HIDDEN(ape_pe_sections_end = .);
|
||||
. += 1;
|
||||
|
||||
/* Mach-O */
|
||||
KEEP(*(.macho))
|
||||
. = ALIGN(__SIZEOF_POINTER__);
|
||||
HIDDEN(ape_macho_end = .);
|
||||
. += 1;
|
||||
|
||||
KEEP(*(.ape.pad.head))
|
||||
. = ALIGN(SupportsWindows() ? PAGESIZE : 16);
|
||||
. = ALIGN(SupportsWindows() || SupportsMetal() ? PAGESIZE : 16);
|
||||
HIDDEN(_ehead = .);
|
||||
} :Head
|
||||
|
||||
@@ -241,9 +238,8 @@ SECTIONS {
|
||||
/* Code that needs to be addressable in Real Mode */
|
||||
*(.text.real)
|
||||
KEEP(*(SORT_BY_NAME(.sort.text.real.*)))
|
||||
*(.rodata.real)
|
||||
KEEP(*(SORT_BY_NAME(.sort.rodata.real.*)))
|
||||
HIDDEN(_ereal = .);
|
||||
. += 1;
|
||||
|
||||
/*END: realmode addressability guarantee */
|
||||
|
||||
@@ -276,17 +272,17 @@ SECTIONS {
|
||||
KEEP(*(SORT_BY_NAME(.sort.text.*)))
|
||||
|
||||
KEEP(*(.ape.pad.test));
|
||||
HIDDEN(__test_start = .);
|
||||
*(.test.unlikely)
|
||||
*(.test .test.*)
|
||||
|
||||
/* Privileged code invulnerable to magic */
|
||||
KEEP(*(.ape.pad.privileged));
|
||||
. += . > 0 ? 1 : 0;
|
||||
HIDDEN(__privileged_start = .);
|
||||
HIDDEN(__test_end = .);
|
||||
. += 1;
|
||||
. += . > 0 ? 1 : 0;
|
||||
*(.privileged)
|
||||
HIDDEN(__privileged_end = .);
|
||||
. += . > 0 ? 1 : 0;
|
||||
|
||||
/*BEGIN: Read Only Data */
|
||||
|
||||
@@ -306,11 +302,10 @@ SECTIONS {
|
||||
KEEP(*(.comment))
|
||||
KEEP(*(.commentepilogue))
|
||||
#endif
|
||||
|
||||
|
||||
/* Windows DLL Import Directory */
|
||||
KEEP(*(.idata.ro));
|
||||
KEEP(*(SORT_BY_NAME(.idata.ro.*)))
|
||||
. += 1;
|
||||
|
||||
. = ALIGN(__SIZEOF_POINTER__);
|
||||
PROVIDE_HIDDEN(__init_array_start = .);
|
||||
@@ -369,11 +364,23 @@ SECTIONS {
|
||||
PROVIDE_HIDDEN(edata = .);
|
||||
} :Ram
|
||||
|
||||
.bss . : {
|
||||
/*END: file content that's loaded by o/s */
|
||||
/*BEGIN: bss memory void */
|
||||
|
||||
.zip . : {
|
||||
KEEP(*(SORT_BY_NAME(.zip.*)))
|
||||
HIDDEN(_ezip = .);
|
||||
}
|
||||
|
||||
/*END: file content */
|
||||
/*BEGIN: bss memory that's addressable */
|
||||
|
||||
.bss ALIGN(__SIZEOF_POINTER__) : {
|
||||
KEEP(*(SORT_BY_NAME(.piro.bss.init.*)))
|
||||
*(.piro.bss)
|
||||
KEEP(*(SORT_BY_NAME(.piro.bss.sort.*)))
|
||||
HIDDEN(__piro_end = .);
|
||||
. += . > 0 ? 1 : 0;
|
||||
/*END: Post-Initialization Read-Only */
|
||||
|
||||
/* Statically Allocated Empty Space */
|
||||
@@ -383,15 +390,10 @@ SECTIONS {
|
||||
|
||||
KEEP(*(SORT_BY_NAME(.sort.bss.*)))
|
||||
|
||||
/* eXtreme Low Memory w/ Userspace Remapping */
|
||||
. = ALIGN(0x1000);
|
||||
*(.xlm)
|
||||
. = ALIGN(0x1000);
|
||||
|
||||
. = ALIGN(0x10000); /* for brk()/sbrk() allocation */
|
||||
. = ALIGN(FRAMESIZE); /* for brk()/sbrk() allocation */
|
||||
HIDDEN(_end = .);
|
||||
PROVIDE_HIDDEN(end = .);
|
||||
} :Ram
|
||||
}
|
||||
|
||||
/*END: nt addressability guarantee */
|
||||
/*END: bsd addressability guarantee */
|
||||
@@ -462,11 +464,18 @@ HIDDEN(ape_rom_rva = RVA(ape_rom_vaddr));
|
||||
HIDDEN(ape_ram_offset = ape_rom_offset + ape_rom_filesz);
|
||||
HIDDEN(ape_ram_vaddr = ADDR(.data));
|
||||
HIDDEN(ape_ram_paddr = LOADADDR(.data));
|
||||
HIDDEN(ape_ram_filesz = LOADADDR(.bss) - LOADADDR(.data));
|
||||
HIDDEN(ape_ram_filesz = SIZEOF(.data));
|
||||
HIDDEN(ape_ram_memsz = ADDR(.bss) + SIZEOF(.bss) - ape_ram_vaddr);
|
||||
HIDDEN(ape_ram_align = PAGESIZE);
|
||||
HIDDEN(ape_ram_rva = RVA(ape_ram_vaddr));
|
||||
|
||||
HIDDEN(ape_stack_offset = ape_ram_offset + ape_ram_filesz);
|
||||
HIDDEN(ape_stack_vaddr = 0x700000000000 - STACKSIZE);
|
||||
HIDDEN(ape_stack_paddr = ape_ram_paddr + ape_ram_filesz);
|
||||
HIDDEN(ape_stack_filesz = 0);
|
||||
HIDDEN(ape_stack_memsz = STACKSIZE);
|
||||
HIDDEN(ape_stack_align = 16);
|
||||
|
||||
HIDDEN(ape_note_offset = ape_rom_offset + (ape_note - ape_rom_vaddr));
|
||||
HIDDEN(ape_note_vaddr = ape_note);
|
||||
HIDDEN(ape_note_paddr = ape_rom_paddr + ape_note_offset);
|
||||
@@ -502,20 +511,30 @@ SHSTUB2(ape_macho_dd_skip, RVA(ape_macho) / 8);
|
||||
SHSTUB2(ape_macho_dd_count, (ape_macho_end - ape_macho) / 8);
|
||||
#endif
|
||||
|
||||
#if SupportsWindows()
|
||||
#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_idata_idtsize = ape_idata_idtend - ape_idata_idt);
|
||||
HIDDEN(ape_idata_iatsize = ape_idata_iatend - ape_idata_iat);
|
||||
HIDDEN(v_ntsubsystem = (DEFINED(GetMessage)
|
||||
? kNtImageSubsystemWindowsGui
|
||||
: kNtImageSubsystemWindowsCui));
|
||||
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()
|
||||
HIDDEN(v_ape_realsectors =
|
||||
MIN(REAL_SCRATCH_AREA - IMAGE_BASE_REAL,
|
||||
MIN(0x70000 - IMAGE_BASE_REAL,
|
||||
ROUNDUP(RVA(_edata), 4096)) / 512);
|
||||
HIDDEN(v_ape_realpages = v_ape_realsectors / (4096 / 512));
|
||||
HIDDEN(v_ape_highsectors =
|
||||
@@ -526,8 +545,9 @@ HIDDEN(v_ape_highsectors =
|
||||
#define ZIPCONST(NAME, VAL) HIDDEN(NAME = DEFINED(__zip_start) ? VAL : 0);
|
||||
ZIPCONST(v_zip_cdoffset, __zip_start - IMAGE_BASE_VIRTUAL);
|
||||
ZIPCONST(v_zip_cdirsize, __zip_end - __zip_start);
|
||||
ASSERT(v_zip_cdirsize % kZipCdirHdrLinkableSize == 0, "bad zip cdir");
|
||||
ZIPCONST(v_zip_records, v_zip_cdirsize / kZipCdirHdrLinkableSize);
|
||||
ZIPCONST(v_zip_commentsize, _edata - __zip_end - kZipCdirHdrMinSize);
|
||||
ZIPCONST(v_zip_commentsize, _ezip - __zip_end - kZipCdirHdrMinSize);
|
||||
|
||||
#if SupportsXnu()
|
||||
/* Generates deterministic ID. */
|
||||
@@ -605,7 +625,7 @@ CHURN(v_ape_realsectors);
|
||||
#if SupportsXnu()
|
||||
CHURN(ape_macho);
|
||||
#endif
|
||||
#if SupportsWindows()
|
||||
#if SupportsWindows() || SupportsMetal()
|
||||
CHURN(ape_mz);
|
||||
CHURN(ape_pe);
|
||||
CHURN(ape_pe_offset);
|
||||
|
||||
+2
-6
@@ -20,8 +20,8 @@ APE = $(APE_DEPS) \
|
||||
o/$(MODE)/ape/ape.lds
|
||||
|
||||
APELINK = \
|
||||
ACTION=LINK.ape \
|
||||
$(COMPILE) \
|
||||
-ALINK.ape \
|
||||
$(LINK) \
|
||||
$(LINKARGS) \
|
||||
$(OUTPUT_OPTION)
|
||||
@@ -31,12 +31,10 @@ APE_HDRS = $(filter %.h,$(APE_FILES))
|
||||
APE_INCS = $(filter %.inc,$(APE_FILES))
|
||||
APE_SRCS = $(filter %.S,$(APE_FILES))
|
||||
APE_OBJS = $(APE_SRCS:%.S=o/$(MODE)/%.o)
|
||||
APE_DEPS = $(APE_LIB)
|
||||
APE_CHECKS = $(APE_HDRS:%=o/%.ok)
|
||||
|
||||
o/$(MODE)/ape/ape.lds: \
|
||||
ape/ape.lds \
|
||||
ape/config.h \
|
||||
ape/macros.internal.h \
|
||||
libc/dce.h \
|
||||
libc/zip.h
|
||||
@@ -49,6 +47,4 @@ $(APE_OBJS): $(BUILD_FILES) \
|
||||
ape/ape.mk
|
||||
|
||||
.PHONY: o/$(MODE)/ape
|
||||
o/$(MODE)/ape: $(APE) \
|
||||
$(APE_CHECKS) \
|
||||
o/$(MODE)/ape/lib
|
||||
o/$(MODE)/ape: $(APE) $(APE_CHECKS)
|
||||
-118
@@ -1,118 +0,0 @@
|
||||
#ifndef APE_CONFIG_H_
|
||||
#define APE_CONFIG_H_
|
||||
#include "ape/relocations.h"
|
||||
#include "libc/macros.h"
|
||||
|
||||
/*
|
||||
* Post-Initialization Read-Only Code Size Threshold.
|
||||
*
|
||||
* An executable needs to have at least this much code, before the
|
||||
* linker adds non-mandatory 4kb alignments. The benefit is better
|
||||
* memory protection. The tradeoff is sparser binaries.
|
||||
*/
|
||||
#ifndef APE_PIRO_THRESHOLD
|
||||
#ifdef CONFIG_DBG
|
||||
#define APE_PIRO_THRESHOLD 0x1000
|
||||
#else
|
||||
#define APE_PIRO_THRESHOLD 0x10000
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef METAL_STDIN
|
||||
#define METAL_STDIN COM1
|
||||
#endif
|
||||
#ifndef METAL_STDOUT
|
||||
#define METAL_STDOUT COM1
|
||||
#endif
|
||||
#ifndef METAL_STDERR
|
||||
#define METAL_STDERR COM1
|
||||
#endif
|
||||
|
||||
#ifndef VIDYA_MODE
|
||||
#define VIDYA_MODE VIDYA_MODE_CGA
|
||||
#endif
|
||||
|
||||
/* FPU Control Word (x87) Exception Masks
|
||||
@see Intel Manual V1 §8.1.5
|
||||
|
||||
IM: Invalid Operation ───────────────┐
|
||||
DM: Denormal Operand ───────────────┐│
|
||||
ZM: Zero Divide ───────────────────┐││
|
||||
OM: Overflow ─────────────────────┐│││
|
||||
UM: Underflow ───────────────────┐││││
|
||||
PM: Precision ──────────────────┐│││││
|
||||
PC: Precision Control ────────┐ ││││││
|
||||
{float,∅,double,long double} │ ││││││
|
||||
RC: Rounding Control ───────┐ │ ││││││
|
||||
{even, →-∞, →+∞, →0} │┌┤ ││││││
|
||||
┌┤││ ││││││
|
||||
d││││rr││││││*/
|
||||
#define X87_NORMAL 0b000000000001101111111
|
||||
#define X87_DTOA 0b000000000001000000000
|
||||
#define X87_DTOA_MASK 0b000000000001100000000
|
||||
#ifndef X87_DEFAULT
|
||||
#define X87_DEFAULT X87_NORMAL
|
||||
#endif
|
||||
|
||||
#ifndef UART_BAUD_RATE
|
||||
#define UART_BAUD_RATE 9600 /* bits per second ∈ [50,115200] */
|
||||
#endif
|
||||
#define UART_CONF_DLR (1843200 /*hz*/ / 16 /*wut*/ / (UART_BAUD_RATE))
|
||||
#ifndef UART_CONF_IIR
|
||||
/* ┌interrupt trigger level {1,4,8,14}
|
||||
│ ┌enable 64 byte fifo (UART 16750+)
|
||||
│ │ ┌select dma mode
|
||||
│ │ │┌clear transmit fifo
|
||||
│ │ ││┌clear receive fifo
|
||||
├┐│ │││┌enable fifos*/
|
||||
#define UART_CONF_IIR 0b00000000
|
||||
#endif
|
||||
#ifndef UART_CONF_LCR
|
||||
/* ┌dlab: flips configuration mode state
|
||||
│┌enable break signal
|
||||
││ ┌parity {none,odd,even,high,low}
|
||||
││ │ ┌extra stop bit
|
||||
││ │ │┌data word length (bits+5)
|
||||
││┌┴┐│├┐*/
|
||||
#define UART_CONF_LCR 0b01000011
|
||||
#endif
|
||||
|
||||
#define XLM(VAR) (XLM_BASE_REAL + XLM_##VAR)
|
||||
#define XLMV(VAR) (__xlm + XLM_##VAR)
|
||||
#define XLM_BASE_REAL 0x1000
|
||||
#define XLM_E820 0
|
||||
#define XLM_E820_SIZE 0x2000
|
||||
#define XLM_BIOS_DATA_AREA 0x2000
|
||||
#define XLM_BIOS_DATA_AREA_SIZE 256
|
||||
#define XLM_DRIVE_BASE_TABLE 0x2200 /* drive values are contiguous */
|
||||
#define XLM_DRIVE_BASE_TABLE_SIZE 11
|
||||
#define XLM_DRIVE_TYPE 0x220b
|
||||
#define XLM_DRIVE_TYPE_SIZE 1
|
||||
#define XLM_DRIVE_LAST_SECTOR 0x220c /* 1-based inclusive, e.g. 18 */
|
||||
#define XLM_DRIVE_LAST_SECTOR_SIZE 1
|
||||
#define XLM_DRIVE_LAST_CYLINDER 0x220d /* 0-based incl, e.g. 79 */
|
||||
#define XLM_DRIVE_LAST_CYLINDER_SIZE 2
|
||||
#define XLM_DRIVE_ATTACHED 0x220f
|
||||
#define XLM_DRIVE_ATTACHED_SIZE 1
|
||||
#define XLM_DRIVE_LAST_HEAD 0x2210 /* 0-based inclusive, e.g. 1 */
|
||||
#define XLM_DRIVE_LAST_HEAD_SIZE 1
|
||||
#define XLM_DRIVE 0x2211
|
||||
#define XLM_DRIVE_SIZE 1
|
||||
#define XLM_HAVEEXTMEMKB 0x2212
|
||||
#define XLM_HAVEEXTMEMKB_SIZE 4
|
||||
#define XLM_VIDEO_POSITION_FAR_POINTER 0x2216 /* video cursor far pointer */
|
||||
#define XLM_VIDEO_POSITION_FAR_POINTER_SIZE 4
|
||||
#define XLM_PAGE_TABLE_STACK_POINTER 0x2220
|
||||
#define XLM_PAGE_TABLE_STACK_POINTER_SIZE 8
|
||||
#define XLM_BADIDT 0x2230
|
||||
#define XLM_BADIDT_SIZE 6
|
||||
#define XLM_LOADSTATE 0x2240
|
||||
#define XLM_LOADSTATE_SIZE 8
|
||||
#define XLM_SIZE ROUNDUP(XLM_LOADSTATE + XLM_LOADSTATE_SIZE, 0x1000)
|
||||
#define IMAGE_BASE_REAL (XLM_BASE_REAL + XLM_SIZE)
|
||||
|
||||
#if !defined(__LINKER__) && !defined(__ASSEMBLER__)
|
||||
extern char __xlm[XLM_SIZE];
|
||||
#endif /* !defined(__LINKER__) && !defined(__ASSEMBLER__) */
|
||||
|
||||
#endif /* APE_CONFIG_H_ */
|
||||
@@ -1,45 +0,0 @@
|
||||
#-*-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───────────────────────┘
|
||||
|
||||
PKGS += APE_LIB
|
||||
|
||||
APE_LIB_ARTIFACTS += APE_LIB_A
|
||||
APE_LIB = $(APE_LIB_A_DEPS) $(APE_LIB_A)
|
||||
APE_LIB_A = o/$(MODE)/ape/lib/apelib.a
|
||||
APE_LIB_A_FILES := $(wildcard ape/lib/*)
|
||||
APE_LIB_A_HDRS = $(filter %.h,$(APE_LIB_A_FILES))
|
||||
APE_LIB_A_SRCS_S = $(filter %.S,$(APE_LIB_A_FILES))
|
||||
APE_LIB_A_SRCS_C = $(filter %.c,$(APE_LIB_A_FILES))
|
||||
|
||||
APE_LIB_A_SRCS = \
|
||||
$(APE_LIB_A_SRCS_S) \
|
||||
$(APE_LIB_A_SRCS_C)
|
||||
|
||||
APE_LIB_A_OBJS = \
|
||||
$(APE_LIB_A_SRCS_S:%.S=o/$(MODE)/%.o) \
|
||||
$(APE_LIB_A_SRCS_C:%.c=o/$(MODE)/%.o)
|
||||
|
||||
APE_LIB_A_DIRECTDEPS = \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_INTRIN \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS
|
||||
|
||||
APE_LIB_A_CHECKS = $(APE_LIB_A_HDRS:%=o/$(MODE)/%.ok)
|
||||
APE_LIB_A_DEPS = $(call uniq,$(foreach x,$(APE_LIB_A_DIRECTDEPS),$($(x))))
|
||||
|
||||
$(APE_LIB_A): ape/lib/ $(APE_LIB_A).pkg $(APE_LIB_A_OBJS)
|
||||
$(APE_LIB_A).pkg: $(APE_LIB_A_OBJS) $(foreach x,$(APE_LIB_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
APE_LIB_LIBS = $(foreach x,$(APE_LIB_ARTIFACTS),$($(x)))
|
||||
APE_LIB_SRCS = $(foreach x,$(APE_LIB_ARTIFACTS),$($(x)_SRCS))
|
||||
APE_LIB_HDRS = $(foreach x,$(APE_LIB_ARTIFACTS),$($(x)_HDRS))
|
||||
APE_LIB_BINS = $(foreach x,$(APE_LIB_ARTIFACTS),$($(x)_BINS))
|
||||
APE_LIB_CHECKS = $(foreach x,$(APE_LIB_ARTIFACTS),$($(x)_CHECKS))
|
||||
APE_LIB_OBJS = $(foreach x,$(APE_LIB_ARTIFACTS),$($(x)_OBJS))
|
||||
$(APE_LIB_OBJS): $(BUILD_FILES) libc/str/str.mk
|
||||
|
||||
.PHONY: o/$(MODE)/ape/lib
|
||||
o/$(MODE)/ape/lib: \
|
||||
$(APE_LIB_CHECKS) \
|
||||
$(APE_LIB_A)
|
||||
@@ -1,35 +0,0 @@
|
||||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 sw=8 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 "ape/macros.internal.h"
|
||||
#include "ape/notice.inc"
|
||||
.section .real,"ax",@progbits
|
||||
.source __FILE__
|
||||
.code16
|
||||
|
||||
// Resets personal computer.
|
||||
//
|
||||
// @param di drive number, e.g. A:\ is 0x00, C:\ is 0x80
|
||||
// @mode real
|
||||
// @noreturn
|
||||
bootdr: push %bp
|
||||
mov %sp,%bp
|
||||
mov %di,%dx
|
||||
int $0x19
|
||||
ljmp $0xf000,$0xfff0
|
||||
.endfn bootdr,globl
|
||||
@@ -1,37 +0,0 @@
|
||||
/*-*- 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 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 "ape/lib/pc.h"
|
||||
#include "ape/config.h"
|
||||
#include "ape/macros.internal.h"
|
||||
#include "ape/notice.inc"
|
||||
.section .real,"ax",@progbits
|
||||
.source __FILE__
|
||||
.code16
|
||||
|
||||
.globl e820map
|
||||
.hidden e820map
|
||||
.type e820map,@object
|
||||
.size e820map,XLM_E820_SIZE
|
||||
e820map = ape_xlm + XLM_E820
|
||||
|
||||
.globl e820map_xlm
|
||||
.hidden e820map_xlm
|
||||
.type e820map_xlm,@object
|
||||
.size e820map_xlm,XLM_E820_SIZE
|
||||
e820map_xlm = XLM(E820)
|
||||
@@ -1,31 +0,0 @@
|
||||
/*-*- 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 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 "ape/lib/pc.h"
|
||||
#include "ape/config.h"
|
||||
#include "ape/macros.internal.h"
|
||||
#include "ape/notice.inc"
|
||||
.section .real,"ax",@progbits
|
||||
.source __FILE__
|
||||
.code16
|
||||
|
||||
.globl g_pml4t
|
||||
.hidden g_pml4t
|
||||
.type g_pml4t,@object
|
||||
.size g_pml4t,0x1000
|
||||
g_pml4t = REAL_STACK_FRAME - 0x1000
|
||||
@@ -1,37 +0,0 @@
|
||||
/*-*- 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 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 "ape/lib/pc.h"
|
||||
#include "ape/config.h"
|
||||
#include "ape/macros.internal.h"
|
||||
#include "ape/notice.inc"
|
||||
.section .real,"ax",@progbits
|
||||
.source __FILE__
|
||||
.code16
|
||||
|
||||
.globl g_ptsp
|
||||
.hidden g_ptsp
|
||||
.type g_ptsp,@object
|
||||
.size g_ptsp,XLM_PAGE_TABLE_STACK_POINTER_SIZE
|
||||
g_ptsp = ape_xlm + XLM_PAGE_TABLE_STACK_POINTER
|
||||
|
||||
.globl g_ptsp_xlm
|
||||
.hidden g_ptsp_xlm
|
||||
.type g_ptsp_xlm,@object
|
||||
.size g_ptsp_xlm,XLM_PAGE_TABLE_STACK_POINTER_SIZE
|
||||
g_ptsp_xlm = XLM(PAGE_TABLE_STACK_POINTER)
|
||||
@@ -1,42 +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 "ape/lib/pc.h"
|
||||
#include "libc/assert.h"
|
||||
|
||||
static textreal uint64_t __pushpagetable(uint64_t *ptsp) {
|
||||
return (*ptsp -= PAGESIZE) | PAGE_V | PAGE_RW;
|
||||
}
|
||||
|
||||
textreal uint64_t *__getpagetableentry(int64_t vaddr, unsigned depth,
|
||||
struct PageTable *pml4t,
|
||||
uint64_t *ptsp) {
|
||||
uint64_t *entry;
|
||||
unsigned char shift;
|
||||
assert(depth <= 3);
|
||||
assert(!(*ptsp & 0xfff));
|
||||
assert(!((uintptr_t)pml4t & 0xfff));
|
||||
shift = 39;
|
||||
for (;;) {
|
||||
entry = &pml4t->p[(vaddr >> shift) & 511];
|
||||
if (!depth--) return entry;
|
||||
shift -= 9;
|
||||
if (!*entry) *entry = __pushpagetable(ptsp);
|
||||
pml4t = (void *)(*entry & PAGE_TA);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*-*- 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 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 "ape/lib/pc.h"
|
||||
#include "ape/config.h"
|
||||
#include "ape/macros.internal.h"
|
||||
#include "ape/notice.inc"
|
||||
.section .real,"ax",@progbits
|
||||
.source __FILE__
|
||||
.code16
|
||||
|
||||
.globl kBiosDataArea
|
||||
.hidden kBiosDataArea
|
||||
.type kBiosDataArea,@object
|
||||
.size kBiosDataArea,XLM_BIOS_DATA_AREA_SIZE
|
||||
kBiosDataArea = ape_xlm + XLM_BIOS_DATA_AREA
|
||||
|
||||
.globl kBiosDataAreaXlm
|
||||
.hidden kBiosDataAreaXlm
|
||||
.type kBiosDataAreaXlm,@object
|
||||
.size kBiosDataAreaXlm,XLM_BIOS_DATA_AREA_SIZE
|
||||
kBiosDataAreaXlm = XLM(BIOS_DATA_AREA)
|
||||
|
||||
.section .sort.text.real.init.2.kBiosDataArea,"ax",@progbits
|
||||
movpp %ds,%es # copy bios data to valid page
|
||||
mov $PC_BIOS_DATA_AREA,%si
|
||||
mov $XLM(BIOS_DATA_AREA),%di
|
||||
mov $XLM_BIOS_DATA_AREA_SIZE,%cx
|
||||
rep movsb
|
||||
.previous
|
||||
@@ -1,26 +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 "ape/lib/pc.h"
|
||||
|
||||
textreal void pageunmap(int64_t vaddr) {
|
||||
uint64_t *entry;
|
||||
entry = __getpagetableentry(vaddr, 3, &g_pml4t, &g_ptsp_xlm);
|
||||
*entry &= ~PAGE_V;
|
||||
asm volatile("invlpg\t(%0)" : /* no outputs */ : "r"(vaddr) : "memory");
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#ifndef APE_MACROS_H_
|
||||
#define APE_MACROS_H_
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#ifdef __ASSEMBLER__
|
||||
/* clang-format off */
|
||||
|
||||
@@ -26,13 +26,6 @@
|
||||
* @fileoverview Macros relevant to αcτµαlly pδrταblε εxεcµταblε.
|
||||
*/
|
||||
|
||||
// Calls function in real mode.
|
||||
// It's needed because LLVM 8 LLD doesn't support R_X86_64_PC16.
|
||||
.macro call16 name:req
|
||||
mov $REAL(\name),%ax
|
||||
call *%ax
|
||||
.endm
|
||||
|
||||
// Calls near (i.e. pc+pcrel<64kB) FUNCTION.
|
||||
// @mode long,legacy,real
|
||||
// @cost 9 bytes overhead
|
||||
|
||||
+2
-20
@@ -11,6 +11,8 @@
|
||||
In some cases it's necessary to use addend macros that change virtual
|
||||
addresses into the other two types: physical and real. */
|
||||
|
||||
#define IMAGE_BASE_REAL 0x2000
|
||||
|
||||
#ifndef IMAGE_BASE_VIRTUAL
|
||||
#define IMAGE_BASE_VIRTUAL 0x400000
|
||||
#endif
|
||||
@@ -19,26 +21,6 @@
|
||||
#define IMAGE_BASE_PHYSICAL 0x100000
|
||||
#endif
|
||||
|
||||
#ifndef REAL_SCRATCH_AREA
|
||||
/**
|
||||
* Location of anything goes memory for real mode.
|
||||
*
|
||||
* The MBR won't load program content beyond this address, so we have
|
||||
* room for buffers, page tables, etc. before we reach the stack frame.
|
||||
*/
|
||||
#define REAL_SCRATCH_AREA 0x40000
|
||||
#endif
|
||||
|
||||
#ifndef REAL_STACK_FRAME
|
||||
/**
|
||||
* Location of real mode 64kb stack frame.
|
||||
*
|
||||
* This address was chosen because memory beyond 0x80000 can't be
|
||||
* accessed safely without consulting e820.
|
||||
*/
|
||||
#define REAL_STACK_FRAME 0x70000
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns Relative Virtual Address.
|
||||
*/
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# Program Deprioritizer
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# This is a drop-in replacement for the traditional Unix `nice`
|
||||
# command that also invokes `ionice`, which is important, since
|
||||
# network and traffic is usually what clobber the system.
|
||||
|
||||
if [ -z "$IONICE" ]; then
|
||||
if IONICE=$(command -v ionice 2>/dev/null); then
|
||||
IONICE="$IONICE -c3"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$NICE" ]; then
|
||||
NICE=$(command -v nice 2>/dev/null)
|
||||
fi
|
||||
|
||||
if [ -z "$IONICE$NICE" ]; then
|
||||
echo "error: can't be nice" >&2
|
||||
fi
|
||||
|
||||
exec $IONICE $NICE "$@"
|
||||
@@ -1,53 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# Cosmopolitan Archiver
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This goes 100x faster than ar and ranlib.
|
||||
#
|
||||
# EXAMPLE
|
||||
#
|
||||
# build/archive rcsD library.a foo.o ...
|
||||
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
if [ -x "o//tool/build/ar.com" ]; then
|
||||
set -- "o//tool/build/ar.com" "$@"
|
||||
else
|
||||
if [ ! -x o/build/bootstrap/ar.com ]; then
|
||||
mkdir -p o/build/bootstrap &&
|
||||
cp -f build/bootstrap/ar.com o/build/bootstrap/ar.com.$$ &&
|
||||
mv -f o/build/bootstrap/ar.com.$$ o/build/bootstrap/ar.com || exit
|
||||
fi
|
||||
set -- o/build/bootstrap/ar.com "$@"
|
||||
fi
|
||||
OUT=$3
|
||||
|
||||
printf "$LOGFMT" "${ACTION:-ARCHIVE.a}" "$OUT" >&2
|
||||
# if [ "$V" = "0" ]; then
|
||||
# printf "$LOGFMT" "${ACTION:-ARCHIVE.a}" "$OUT" >&2
|
||||
# else
|
||||
# # some of these windows nt archives are quite huge
|
||||
# COLUMNS=${COLUMNS:-80}
|
||||
# COLUMNS=$((COLUMNS - 4))
|
||||
# printf "%s\n" "$*" |
|
||||
# /usr/bin/fold -s -w $COLUMNS |
|
||||
# sed -e '1bb' -e 's/^/ /' -e ':b' -e '$b' -e 's/$/ \\/' >&2
|
||||
# fi
|
||||
|
||||
REASON=failed
|
||||
trap REASON=interrupted INT
|
||||
|
||||
"$@" >/dev/null && exit
|
||||
|
||||
if [ "$TERM" = "dumb" ]; then
|
||||
f='%s %s\r\n\r\n'
|
||||
else
|
||||
f='\033[91m%s\033[39m \033[94m%s\033[39m\r\n\r\n'
|
||||
fi
|
||||
printf "$f" "archive $REASON:" "$*" >&2
|
||||
exit 1
|
||||
@@ -1,49 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# GNU Assembler Veneer
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This script wraps normal assembler commands that're transparently
|
||||
# passed-through. It adds ephemeral logging and directory creation.
|
||||
#
|
||||
# EXAMPLE
|
||||
#
|
||||
# TARGET=program build/assemble as -o program program.o
|
||||
#
|
||||
# SEE ALSO
|
||||
#
|
||||
# https://justine.storage.googleapis.com/perm/as.pdf
|
||||
|
||||
if [ ! -d o/third_party/gcc ]; then
|
||||
third_party/gcc/unbundle.sh
|
||||
fi
|
||||
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-OBJECTIFY.s}" "$TARGET" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
if [ "$TARGET" ]; then
|
||||
TARGETDIR="${TARGET%/*}"
|
||||
if [ "$TARGETDIR" != "$TARGET" ] && [ ! -d "$TARGETDIR" ]; then
|
||||
$MKDIR "$TARGETDIR" || exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
"$@" && exit
|
||||
|
||||
if [ "$TERM" = "dumb" ]; then
|
||||
f='%s %s\r\n\r\n'
|
||||
else
|
||||
f='\033[91m%s\033[39m \033[94m%s\033[39m\r\n\r\n'
|
||||
fi
|
||||
printf "$f" "assemble failed:" "$*" >&2
|
||||
exit 1
|
||||
@@ -1,9 +0,0 @@
|
||||
#!/bin/sh
|
||||
# -*- mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8 -*-
|
||||
# vi: set net ft=sh ts=2 sts=2 sw=2 fenc=utf-8 :vi
|
||||
|
||||
echo c |
|
||||
bochs \
|
||||
-q \
|
||||
-f ape/etc/bochsrc.dbg \
|
||||
floppya:1_44=$1,status=inserted
|
||||
@@ -1,51 +0,0 @@
|
||||
#!/bin/sh
|
||||
# -*- mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8 -*-
|
||||
# vi: set net ft=sh ts=2 sts=2 sw=2 fenc=utf-8 :vi
|
||||
#
|
||||
# bochs-scriptable executes a disk with serial uart stdio.
|
||||
#
|
||||
# USAGE
|
||||
#
|
||||
# build/bochs-scriptable IMAGE...
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This script is useful for end-to-end testing metal apps in <100ms.
|
||||
#
|
||||
# SEE ALSO
|
||||
#
|
||||
# build/boot(1)
|
||||
|
||||
while getopts h X; do
|
||||
case $X in
|
||||
h) exec less "$0" ;;
|
||||
\?) echo "$0: bad arg" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
trap '' INT
|
||||
|
||||
IMG=$1
|
||||
OUT=/tmp/$USER.$$.bochs.stdout
|
||||
ERR=/tmp/$USER.$$.bochs.stderr
|
||||
|
||||
mkfifo $OUT || exit
|
||||
|
||||
cat <$OUT &
|
||||
CAT=$!
|
||||
exec 4>$OUT
|
||||
rm -f $OUT
|
||||
|
||||
echo c |
|
||||
bochs \
|
||||
-q \
|
||||
-f ape/etc/bochsrc.ffs \
|
||||
display_library:nogui \
|
||||
floppya:1_44=$1,status=inserted \
|
||||
>>$ERR 2>>$ERR
|
||||
RC=$?
|
||||
|
||||
kill $CAT
|
||||
exec 4>&-
|
||||
rm -f $ERR
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,21 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# Source File Concatenation Tool
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This program is the same as cat, but inserts preprocessor directives
|
||||
# that allow compiler errors to point back to the original lines.
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
cat
|
||||
else
|
||||
for x; do
|
||||
printf '# 1 "%s"\n' "$x"
|
||||
cat "$x"
|
||||
done
|
||||
fi
|
||||
-298
@@ -1,298 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# GNU/LLVM Compiler Frontend Frontend
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This wrapper script filters out certain flags so the compiler won't
|
||||
# whine, and passes extra information to the preprocessor.
|
||||
#
|
||||
# EXAMPLE
|
||||
#
|
||||
# build/compile cc -o program program.c
|
||||
|
||||
if [ ! -d o/third_party/gcc ]; then
|
||||
third_party/gcc/unbundle.sh
|
||||
fi
|
||||
|
||||
if [ "$1" = "clang-10" ]; then
|
||||
if ! command -v clang-10 >/dev/null; then
|
||||
shift
|
||||
set -- o/third_party/gcc/bin/x86_64-linux-musl-gcc "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$1" = "clang++-10" ]; then
|
||||
if ! command -v clang++-10 >/dev/null; then
|
||||
shift
|
||||
set -- o/third_party/gcc/bin/x86_64-linux-musl-g++ "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
|
||||
GZME=
|
||||
ASAN=
|
||||
UBSAN=
|
||||
PLAT="${1%% *}"
|
||||
FDIAGNOSTIC_COLOR=
|
||||
CCNAME=${CCNAME:-gcc}
|
||||
CCVERSION=${CCVERSION:-4}
|
||||
COUNTERMAND=
|
||||
|
||||
# The GNU Compiler Collection passes a lot of CFLAGS to the preprocessor
|
||||
# (which we call CCFLAGS) but it should pass more; and we do just that.
|
||||
NOPG=0
|
||||
FIRST=1
|
||||
OUTARG=0
|
||||
INVISIBLE=0
|
||||
for x; do
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set --
|
||||
FIRST=0
|
||||
fi
|
||||
if [ $OUTARG -eq 1 ]; then
|
||||
OUTARG=0
|
||||
OUT="$x"
|
||||
fi
|
||||
case "$x" in
|
||||
-o)
|
||||
set -- "$@" "$x"
|
||||
OUTARG=1
|
||||
;;
|
||||
-w)
|
||||
set -- "$@" "$x" -D__W__
|
||||
;;
|
||||
-x-no-pg)
|
||||
NOPG=1
|
||||
;;
|
||||
-pg)
|
||||
if [ $NOPG -eq 0 ] && [ $INVISIBLE -eq 0 ]; then
|
||||
set -- "$@" "$x" -D__PG__ # @see libc/macros.h
|
||||
fi
|
||||
;;
|
||||
-mfentry)
|
||||
if [ $NOPG -eq 0 ] && [ $INVISIBLE -eq 0 ]; then
|
||||
set -- "$@" "$x" -D__MFENTRY__
|
||||
fi
|
||||
;;
|
||||
-fomit-frame-pointer)
|
||||
INVISIBLE=1
|
||||
set -- "$@" "$x"
|
||||
;;
|
||||
-mno-vzeroupper)
|
||||
set -- "$@" "$x" -Wa,-msse2avx -D__MNO_VZEROUPPER__
|
||||
;;
|
||||
-fsanitize=address)
|
||||
ASAN="$x -D__FSANITIZE_ADDRESS__"
|
||||
;;
|
||||
-fsanitize=undefined)
|
||||
# UBSAN w/ -fdata-sections exceeds ELF's 65,280 section limit
|
||||
UBSAN="$x -fno-data-sections"
|
||||
;;
|
||||
-fno-sanitize=address)
|
||||
ASAN=
|
||||
;;
|
||||
-fno-sanitize=ubsan)
|
||||
UBSAN=
|
||||
;;
|
||||
-fno-sanitize=all)
|
||||
ASAN=
|
||||
UBSAN=
|
||||
;;
|
||||
-mnop-mcount)
|
||||
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 6 ]; then
|
||||
set -- "$@" "$x" -D__MNOP_MCOUNT__
|
||||
fi
|
||||
;;
|
||||
-mrecord-mcount)
|
||||
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 6 ]; then
|
||||
set -- "$@" "$x" -D__MRECORD_MCOUNT__
|
||||
fi
|
||||
;;
|
||||
-fsanitize=implicit*integer*)
|
||||
if ! [ "$CCNAME" = "gcc" ]; then
|
||||
set -- "$@" "$x"
|
||||
fi
|
||||
;;
|
||||
-f*sanitize*|-gz*|-*stack-protector*|-fvect-cost*|-mstringop*)
|
||||
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 6 ]; then
|
||||
set -- "$@" "$x"
|
||||
fi
|
||||
;;
|
||||
-freorder-blocks-and-partition|-fstack-clash-protection)
|
||||
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 8 ]; then
|
||||
set -- "$@" "$x"
|
||||
fi
|
||||
;;
|
||||
-fdiagnostic-color=*)
|
||||
FDIAGNOSTIC_COLOR=$x
|
||||
;;
|
||||
-fopt-info*=*.optinfo)
|
||||
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 9 ]; then
|
||||
GZME="$GZME ${x##*=}"
|
||||
set -- "$@" "$x"
|
||||
fi
|
||||
;;
|
||||
-R*) # e.g. clang's -Rpass-missed=all
|
||||
if [ "${PLAT#*clang}" != "${PLAT}" ]; then
|
||||
set -- "$@" "$x"
|
||||
fi
|
||||
;;
|
||||
-fsave-optimization-record) # clang only
|
||||
if [ "${PLAT#*clang}" != "${PLAT}" ]; then
|
||||
set -- "$@" "$x"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
set -- "$@" "$x"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [ -z "$FDIAGNOSTIC_COLOR" ] && [ "$TERM" != "dumb" ]; then
|
||||
FDIAGNOSTIC_COLOR=-fdiagnostics-color=always
|
||||
fi
|
||||
|
||||
if [ "${PLAT#*clang}" != "${PLAT}" ]; then
|
||||
FIRST=1
|
||||
for x; do
|
||||
# clang's assembler isn't complete yet
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set -- \
|
||||
"$x" \
|
||||
-fno-integrated-as \
|
||||
-Wno-unused-command-line-argument \
|
||||
-Wno-incompatible-pointer-types-discards-qualifiers
|
||||
FIRST=0
|
||||
continue
|
||||
fi
|
||||
TRAPV= # clang handles -f{,no-}{trap,wrap}v weird
|
||||
# removes flags clang whines about
|
||||
case "$x" in
|
||||
-gstabs) ;;
|
||||
-ftrapv) ;;
|
||||
-ffixed-*) ;;
|
||||
-fcall-saved*) ;;
|
||||
-fsignaling-nans) ;;
|
||||
-fcx-limited-range) ;;
|
||||
-fno-fp-int-builtin-inexact) ;;
|
||||
-Wno-unused-but-set-variable) ;;
|
||||
-Wunsafe-loop-optimizations) ;;
|
||||
-mdispatch-scheduler) ;;
|
||||
-ftracer) ;;
|
||||
-frounding-math) ;;
|
||||
-fmerge-constants) ;;
|
||||
-fmodulo-sched) ;;
|
||||
-msse2avx)
|
||||
set -- "$@" -Wa,-msse2avx
|
||||
;;
|
||||
-fopt-info-vec) ;;
|
||||
-fopt-info-vec-missed) ;;
|
||||
-fmodulo-sched-allow-regmoves) ;;
|
||||
-fgcse-*) ;;
|
||||
-freschedule-modulo-scheduled-loops) ;;
|
||||
-freschedule-modulo-scheduled-loops) ;;
|
||||
-fipa-pta) ;;
|
||||
-fsched2-use-superblocks) ;;
|
||||
-fbranch-target-load-optimize) ;;
|
||||
-fdelete-dead-exceptions) ;;
|
||||
-funsafe-loop-optimizations) ;;
|
||||
-fcall-used*) ;;
|
||||
-mmitigate-rop) ;;
|
||||
-mnop-mcount) ;;
|
||||
-fno-align-jumps) ;;
|
||||
-fno-align-labels) ;;
|
||||
-fno-align-loops) ;;
|
||||
-fivopts) ;;
|
||||
-fschedule-insns) ;;
|
||||
-fno-semantic-interposition) ;;
|
||||
-mno-fentry) ;;
|
||||
-f*shrink-wrap) ;;
|
||||
-f*schedule-insns2) ;;
|
||||
-fvect-cost-model=*) ;;
|
||||
-fsimd-cost-model=*) ;;
|
||||
-fversion-loops-for-strides) ;;
|
||||
-fopt-info*) ;;
|
||||
-f*var-tracking-assignments) ;;
|
||||
-femit-struct-debug-baseonly) ;;
|
||||
-ftree-loop-vectorize) ;;
|
||||
-gdescribe-dies) ;;
|
||||
-flimit-function-alignment) ;;
|
||||
-ftree-loop-im) ;;
|
||||
-fno-instrument-functions) ;;
|
||||
-fstack-clash-protection) ;;
|
||||
-mstringop-strategy=*) ;;
|
||||
-mpreferred-stack-boundary=*) ;;
|
||||
-*stack-protector*) ;; # clang requires segmented memory for this
|
||||
-f*gnu-unique) ;;
|
||||
-Wframe-larger-than=*) ;;
|
||||
-f*whole-program) ;;
|
||||
-Wa,--size-check=*) ;;
|
||||
-Wa,--listing*) ;;
|
||||
-mfpmath=sse+387) ;;
|
||||
-Wa,--noexecstack) ;;
|
||||
-freg-struct-return) ;;
|
||||
-mcall-ms2sysv-xlogues) ;;
|
||||
-mno-vzeroupper)
|
||||
set -- "$@" -mllvm -x86-use-vzeroupper=0
|
||||
;;
|
||||
-Wa,-a*)
|
||||
x="${x#*=}"
|
||||
if [ "$x" ] && [ -p "$x" ]; then
|
||||
printf '' >"$x"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
set -- "$@" "$x"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
set -- "$@" -fno-stack-protector
|
||||
else
|
||||
# removes flags only clang supports
|
||||
FIRST=1
|
||||
for x; do
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set --
|
||||
FIRST=0
|
||||
fi
|
||||
case "$x" in
|
||||
-Oz) set -- "$@" -Os ;;
|
||||
*) set -- "$@" "$x" ;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
set -- "$@" -no-canonical-prefixes $FDIAGNOSTIC_COLOR $ASAN $UBSAN $COUNTERMAND
|
||||
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-COMPILE}" "${TARGET:-$OUT}" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
OUTDIR="${OUT%/*}"
|
||||
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
|
||||
$MKDIR "$OUTDIR" || exit 2
|
||||
fi
|
||||
|
||||
REASON=failed
|
||||
trap REASON=interrupted INT
|
||||
|
||||
if "$@"; then
|
||||
for f in $GZME; do
|
||||
if GZ=${GZ:-$(command -v gzip)}; then
|
||||
if [ -f "$f" ]; then
|
||||
build/actuallynice $GZ $ZFLAGS -qf $f &
|
||||
fi
|
||||
fi
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf "\n$LOGFMT" "$CCNAME $CCVERSION: compile $REASON:" "$*" >&2
|
||||
exit 1
|
||||
+4
-9
@@ -130,7 +130,7 @@ endif
|
||||
|
||||
# Linux-Only Tiny Mode
|
||||
#
|
||||
# - `make MODE=tiny`
|
||||
# - `make MODE=tinylinux`
|
||||
# - No checks
|
||||
# - No asserts
|
||||
# - No canaries
|
||||
@@ -158,7 +158,7 @@ endif
|
||||
|
||||
# Linux+BSD Tiny Mode
|
||||
#
|
||||
# - `make MODE=tiny`
|
||||
# - `make MODE=tinylinuxbsd`
|
||||
# - No apple
|
||||
# - No checks
|
||||
# - No asserts
|
||||
@@ -187,7 +187,7 @@ endif
|
||||
|
||||
# Unix Tiny Mode
|
||||
#
|
||||
# - `make MODE=tiny`
|
||||
# - `make MODE=tinysysv`
|
||||
# - No checks
|
||||
# - No asserts
|
||||
# - No canaries
|
||||
@@ -215,7 +215,7 @@ endif
|
||||
|
||||
# Tiny Metallic Unix Mode
|
||||
#
|
||||
# - `make MODE=tiny`
|
||||
# - `make MODE=tinynowin`
|
||||
# - No checks
|
||||
# - No asserts
|
||||
# - No canaries
|
||||
@@ -282,11 +282,6 @@ endif
|
||||
# such as MSVC or XCode. You can run your binary objects through a tool
|
||||
# like objconv to convert them to COFF or MachO. Then use ANSI mode to
|
||||
# rollup one header file that'll enable linkage with minimal issues.
|
||||
#
|
||||
# Lastly note that in some cases, such as gc(), there simply isn't any
|
||||
# ANSI workaround available. It's only in cases like that when we'll use
|
||||
# the __asm__() header workaround, rather than simply removing it. We do
|
||||
# however try to do that much less often than mainstream C libraries.
|
||||
|
||||
ifeq ($(MODE), ansi)
|
||||
|
||||
|
||||
+14
-47
@@ -43,31 +43,28 @@
|
||||
# TARGET_ARCH microarchitecture flags (e.g. -march=native)
|
||||
|
||||
V ?= 1
|
||||
LC_ALL = C.UTF-8
|
||||
LC_ALL = C
|
||||
SOURCE_DATE_EPOCH = 0
|
||||
|
||||
DD ?= /bin/dd
|
||||
CP ?= /bin/cp -f
|
||||
RM ?= /bin/rm -f
|
||||
SED ?= /bin/sed
|
||||
MKDIR ?= /bin/mkdir -p
|
||||
TAGS ?= /usr/bin/ctags # emacs source builds or something breaks it
|
||||
ARFLAGS = rcsD
|
||||
ZFLAGS ?=
|
||||
XARGS ?= xargs -P4 -rs8000
|
||||
NICE ?= build/actuallynice
|
||||
DOT ?= dot
|
||||
GZ ?= gzip
|
||||
CLANG = clang-10
|
||||
CLANG = clang
|
||||
FC = gfortran #/opt/cross9f/bin/x86_64-linux-musl-gfortran
|
||||
|
||||
# see build/compile, etc. which run third_party/gcc/unbundle.sh
|
||||
AR = build/bootstrap/ar.com
|
||||
PKG = build/bootstrap/package.com
|
||||
MKDEPS = build/bootstrap/mkdeps.com
|
||||
ZIPOBJ = build/bootstrap/zipobj.com
|
||||
AS = o/third_party/gcc/bin/x86_64-linux-musl-as
|
||||
CC = o/third_party/gcc/bin/x86_64-linux-musl-gcc
|
||||
CXX = o/third_party/gcc/bin/x86_64-linux-musl-g++
|
||||
CXXFILT = o/third_party/gcc/bin/x86_64-linux-musl-c++filt
|
||||
LD = o/third_party/gcc/bin/x86_64-linux-musl-ld.bfd
|
||||
AR = build/archive
|
||||
NM = o/third_party/gcc/bin/x86_64-linux-musl-nm
|
||||
GCC = o/third_party/gcc/bin/x86_64-linux-musl-gcc
|
||||
STRIP = o/third_party/gcc/bin/x86_64-linux-musl-strip
|
||||
@@ -78,53 +75,21 @@ ADDR2LINE = o/third_party/gcc/bin/x86_64-linux-musl-addr2line
|
||||
COMMA := ,
|
||||
PWD := $(shell pwd)
|
||||
IMAGE_BASE_VIRTUAL ?= 0x400000
|
||||
HELLO := $(shell build/hello)
|
||||
TMPDIR := $(shell build/findtmp)
|
||||
LOGFMT := $(shell build/getlogfmt)
|
||||
COMPILE := $(shell build/getcompile)
|
||||
CCNAME := $(shell build/getccname $(CC))
|
||||
CCVERSION := $(shell build/getccversion $(CC))
|
||||
BLAH1 := $(shell build/zipobj 2>/dev/null)
|
||||
BLAH2 := $(shell build/package 2>/dev/null)
|
||||
COMPILE := $(shell build/getcompile) -V$(shell build/getccversion $(CC))
|
||||
|
||||
export ADDR2LINE
|
||||
export CCNAME
|
||||
export CCVERSION
|
||||
export COMPILE
|
||||
export CP
|
||||
export DD
|
||||
export GZ
|
||||
export IMAGE_BASE_VIRTUAL
|
||||
export LC_ALL
|
||||
export LOGFMT
|
||||
export MKDIR
|
||||
export MODE
|
||||
export OBJDUMP
|
||||
export RM
|
||||
export SED
|
||||
export SOURCE_DATE_EPOCH
|
||||
export TMPDIR
|
||||
export V
|
||||
export ZFLAGS
|
||||
|
||||
unexport COMPILER_PATH
|
||||
unexport CPATH
|
||||
unexport CPLUS_INCLUDE_PATH
|
||||
unexport C_INCLUDE_PATH
|
||||
unexport DEPENDENCIES_OUTPUT
|
||||
unexport GCC_COMPARE_DEBUG
|
||||
unexport GCC_EXEC_PREFIX
|
||||
unexport LANG
|
||||
unexport LC_CTYPE
|
||||
unexport LC_MESSAGES
|
||||
unexport LIBRARY_PATH
|
||||
unexport OBJC_INCLUDE_PATH
|
||||
unexport SUNPRO_DEPENDENCIES
|
||||
|
||||
FTRACE = \
|
||||
-pg
|
||||
|
||||
SANITIZER = \
|
||||
-fsanitize=leak \
|
||||
-fsanitize=address
|
||||
|
||||
NO_MAGIC = \
|
||||
@@ -171,6 +136,8 @@ MATHEMATICAL = \
|
||||
-fwrapv
|
||||
|
||||
DEFAULT_CPPFLAGS = \
|
||||
-DCOSMO \
|
||||
-DMODE='"$(MODE)"' \
|
||||
-DIMAGE_BASE_VIRTUAL=$(IMAGE_BASE_VIRTUAL) \
|
||||
-nostdinc \
|
||||
-iquote.
|
||||
@@ -197,6 +164,7 @@ DEFAULT_LDFLAGS = \
|
||||
-static \
|
||||
-nostdlib \
|
||||
-m elf_x86_64 \
|
||||
--gc-sections \
|
||||
--build-id=none \
|
||||
--no-dynamic-linker \
|
||||
-z max-page-size=0x1000
|
||||
@@ -289,8 +257,8 @@ COMPILE.F.flags = $(cc.flags) $(cpp.flags) $(copt.flags) $(f.flags)
|
||||
COMPILE.i.flags = $(cc.flags) $(copt.flags) $(c.flags)
|
||||
COMPILE.ii.flags = $(cc.flags) $(copt.flags) $(cxx.flags)
|
||||
LINK.flags = $(DEFAULT_LDFLAGS) $(CONFIG_LDFLAGS) $(LDFLAGS)
|
||||
OBJECTIFY.c.flags = $(OBJECTIFY.S.flags) $(c.flags)
|
||||
OBJECTIFY.cxx.flags = $(OBJECTIFY.S.flags) $(cxx.flags)
|
||||
OBJECTIFY.c.flags = $(OBJECTIFY.S.flags) $(copt.flags) $(c.flags)
|
||||
OBJECTIFY.cxx.flags = $(OBJECTIFY.S.flags) $(copt.flags) $(cxx.flags)
|
||||
OBJECTIFY.s.flags = $(ASONLYFLAGS) $(s.flags)
|
||||
OBJECTIFY.S.flags = $(copt.flags) $(cc.flags) $(o.flags) $(cpp.flags) $(S.flags)
|
||||
OBJECTIFY.f.flags = $(copt.flags) $(cc.flags) $(o.flags) $(copt.flags) $(S.flags) $(f.flags)
|
||||
@@ -313,8 +281,7 @@ PREPROCESS = $(CC) $(PREPROCESS.flags)
|
||||
PREPROCESS.lds = $(CC) $(PREPROCESS.lds.flags)
|
||||
LINK = $(LD) $(LINK.flags)
|
||||
ELF = o/libc/elf/elf.lds
|
||||
ELFLINK = ACTION=LINK.elf $(LINK) $(LINKARGS) $(OUTPUT_OPTION)
|
||||
ARCHIVE = $(AR) $(ARFLAGS)
|
||||
ELFLINK = $(COMPILE) -ALINK.elf $(LINK) $(LINKARGS) $(OUTPUT_OPTION)
|
||||
LINKARGS = $(patsubst %.lds,-T %.lds,$(call uniqr,$(LD.libs) $(filter-out %.pkg,$^)))
|
||||
LOLSAN = build/lolsan -b $(IMAGE_BASE_VIRTUAL)
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# Generic Command Runner
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This does auto mkdir and ephemeral logging.
|
||||
#
|
||||
# EXAMPLE
|
||||
#
|
||||
# build/do PROG [ARGS...]
|
||||
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
|
||||
# Ensure directory creation if -o PATH flag is passed.
|
||||
OUT="$TARGET"
|
||||
FIRST=1
|
||||
OUTARG=0
|
||||
for x; do
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set --
|
||||
FIRST=0
|
||||
elif [ $OUTARG -eq 1 ]; then
|
||||
OUTARG=0
|
||||
OUT="$x"
|
||||
fi
|
||||
case "$x" in
|
||||
-o)
|
||||
OUTARG=1
|
||||
;;
|
||||
-o*)
|
||||
OUT=${x#-o}
|
||||
;;
|
||||
esac
|
||||
set -- "$@" "$x"
|
||||
done
|
||||
if [ "$OUT" ]; then
|
||||
OUTDIR="${OUT%/*}"
|
||||
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
|
||||
$MKDIR "$OUTDIR" || exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
# Log command.
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-BUILD}" "$TARGET" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
exec gdb -q -nh -i=mi $1 \
|
||||
-ex "set confirm off" \
|
||||
-ex "add-symbol-file $1.dbg 0x401000" \
|
||||
-ex "run"
|
||||
@@ -1,46 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# Compiler Name Discovery
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# Cosmopolitan itself may be built using either GCC and Clang, and our
|
||||
# build irons out many of the differences between the two. This script
|
||||
# determines which one's in play, which is nontrivial, since they tend
|
||||
# to call themselves so many different names.
|
||||
|
||||
if [ ! -d o/third_party/gcc ]; then
|
||||
third_party/gcc/unbundle.sh
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
SPECIAL_TEXT=$(
|
||||
$1 --version |
|
||||
sed -n '
|
||||
/chibicc/ {
|
||||
i\
|
||||
chibicc
|
||||
q
|
||||
}
|
||||
/Free Software/ {
|
||||
i\
|
||||
gcc
|
||||
q
|
||||
}
|
||||
/clang/ {
|
||||
i\
|
||||
clang
|
||||
q
|
||||
}
|
||||
')
|
||||
|
||||
if [ -z "$SPECIAL_TEXT" ]; then
|
||||
echo gcc
|
||||
else
|
||||
printf '%s\n' "$SPECIAL_TEXT"
|
||||
fi
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
if ! [ o/build/bootstrap/compile.com -nt build/bootstrap/compile.com ]; then
|
||||
mkdir -p o/build/bootstrap/
|
||||
cp -f build/bootstrap/compile.com o/build/bootstrap/compile.$$.com
|
||||
o/build/bootstrap/compile.$$.com --do-nothing
|
||||
o/build/bootstrap/compile.$$.com -n
|
||||
mv -f o/build/bootstrap/compile.$$.com o/build/bootstrap/compile.com
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# Printf Logger Initializer
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This program is invoked once by build/definitions.mk to choose the
|
||||
# most appropriate format string when logging command invocations.
|
||||
|
||||
W1=15
|
||||
if [ "$TERM" = "dumb" ]; then
|
||||
if [ "$COLUMNS" = "" ]; then
|
||||
if TPUT=$(command -v tput); then
|
||||
COLUMNS=$("$TPUT" cols)
|
||||
else
|
||||
COLUMNS=80
|
||||
fi
|
||||
fi
|
||||
COLUMNS=$((COLUMNS - 1))
|
||||
W2=$((COLUMNS - W1))
|
||||
printf '%%-%ds%%-%ds\\r' "$W1" "$W2"
|
||||
else
|
||||
echo ♥cosmo >&2
|
||||
printf '\\033[F\\033[K%%-%ds%%s\\r\\n' "$W1"
|
||||
fi
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# HELLO BUILD
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# We generate a line at the start of each Makefile run, because if we
|
||||
# use `make V=0` mode then the terminal logging trick we use in
|
||||
# tool/build/compile.c will delete the previous line, and we'd rather
|
||||
# have that line not be the bash prompt that ran make.
|
||||
#
|
||||
# This script is also useful for giving us an indicator each time the
|
||||
# build restarts itself from scratch, which can happen in cases like
|
||||
# when dependencies need to be regenerated by tool/build/mkdeps.c
|
||||
|
||||
echo ♥cosmo >&2
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
|
||||
for x; do
|
||||
printf '#include "%s"\n' "$x"
|
||||
done
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# GNU Linker Veneer
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This script wraps normal linker commands that're transparently
|
||||
# passed-through. It adds ephemeral logging and directory creation.
|
||||
#
|
||||
# EXAMPLE
|
||||
#
|
||||
# build/linker ld -o program program.o
|
||||
|
||||
if [ ! -d o/third_party/gcc ]; then
|
||||
third_party/gcc/unbundle.sh
|
||||
fi
|
||||
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
|
||||
OUT=
|
||||
FIRST=1
|
||||
OUTARG=0
|
||||
for x; do
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set --
|
||||
FIRST=0
|
||||
elif [ $OUTARG -eq 1 ]; then
|
||||
OUTARG=0
|
||||
OUT="$x"
|
||||
fi
|
||||
case "$x" in
|
||||
-o)
|
||||
OUTARG=1
|
||||
;;
|
||||
esac
|
||||
set -- "$@" "$x"
|
||||
done
|
||||
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-LINK.elf}" "$OUT" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
OUTDIR="${OUT%/*}"
|
||||
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
|
||||
$MKDIR "$OUTDIR" || exit 2
|
||||
fi
|
||||
|
||||
REASON=failed
|
||||
trap REASON=interrupted INT
|
||||
|
||||
"$@" && exit
|
||||
|
||||
if [ "$TERM" = "dumb" ]; then
|
||||
f='%s %s\r\n\r\n'
|
||||
else
|
||||
f='\033[91m%s\033[39m \033[94m%s\033[39m\r\n\r\n'
|
||||
fi
|
||||
printf "$f" "link $REASON:" "$*" >&2
|
||||
exit 1
|
||||
@@ -1,22 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
|
||||
if [ -x "o/$MODE/tool/build/mkdeps.com" ]; then
|
||||
set -- "o/$MODE/tool/build/mkdeps.com" "$@"
|
||||
else
|
||||
if [ ! -x o/build/bootstrap/mkdeps.com ]; then
|
||||
mkdir -p o/build/bootstrap &&
|
||||
cp -a build/bootstrap/mkdeps.com \
|
||||
o/build/bootstrap/mkdeps.com || exit
|
||||
fi
|
||||
set -- o/build/bootstrap/mkdeps.com "$@"
|
||||
fi
|
||||
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-MKDEPS}" "$3" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
@@ -1,22 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# GNU Disassembly Veneer
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This script wraps normal objdump commands that're transparently
|
||||
# passed-through.
|
||||
#
|
||||
# EXAMPLE
|
||||
#
|
||||
# build/objdump -xd o/tiny/examples/life.com.dbg
|
||||
|
||||
if [ ! -d o/third_party/gcc ]; then
|
||||
third_party/gcc/unbundle.sh
|
||||
fi
|
||||
|
||||
exec o/third_party/gcc/bin/x86_64-linux-musl-objdump "$@"
|
||||
+4
-5
@@ -23,9 +23,8 @@
|
||||
# - tool/build/runitd.c
|
||||
|
||||
.PRECIOUS: o/$(MODE)/%.com.ok
|
||||
o/$(MODE)/%.com.ok: \
|
||||
o/$(MODE)/tool/build/runit.com.dbg \
|
||||
o/$(MODE)/tool/build/runitd.com \
|
||||
o/$(MODE)/%.com.ok: \
|
||||
o/$(MODE)/tool/build/runit.com \
|
||||
o/$(MODE)/tool/build/runitd.com \
|
||||
o/$(MODE)/%.com
|
||||
@ACTION=TEST TARGET=$@ build/do $^ $(HOSTS)
|
||||
@touch $@
|
||||
@$(COMPILE) -ATEST -tT$@ $^ $(HOSTS)
|
||||
@@ -1,33 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
|
||||
if [ "$TOOL_BUILD_PACKAGE" ]; then
|
||||
set -- "$TOOL_BUILD_PACKAGE" "$@"
|
||||
else
|
||||
if [ -x "o/tool/build/package.com.dbg" ]; then
|
||||
set -- "o/tool/build/package.com.dbg" "$@"
|
||||
else
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
CP=${CP:-$(command -v cp) -f} || exit
|
||||
if [ ! -x o/build/bootstrap/package.com ]; then
|
||||
$MKDIR o/build/bootstrap &&
|
||||
$CP -a build/bootstrap/package.com \
|
||||
o/build/bootstrap/package.com || exit
|
||||
fi
|
||||
set -- o/build/bootstrap/package.com "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
printf "$LOGFMT" "${ACTION:-PACKAGE}" "$3" >&2
|
||||
# if [ "$V" = "0" ]; then
|
||||
# printf "$LOGFMT" "${ACTION:-PACKAGE}" "$3" >&2
|
||||
# else
|
||||
# COLUMNS=${COLUMNS:-80}
|
||||
# COLUMNS=$((COLUMNS - 4))
|
||||
# printf "%s\n" "$*" |
|
||||
# /usr/bin/fold -s -w $COLUMNS |
|
||||
# sed -e '1bb' -e 's/^/ /' -e ':b' -e '$b' -e 's/$/ \\/' >&2
|
||||
# fi
|
||||
|
||||
exec "$@"
|
||||
-2189
File diff suppressed because it is too large.
Load diff
@@ -1,7 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
|
||||
for x; do
|
||||
printf '#include "%s"\n' "$x"
|
||||
done
|
||||
+61
-67
@@ -16,73 +16,67 @@
|
||||
|
||||
MAKEFLAGS += --no-builtin-rules
|
||||
|
||||
o/%.a:; @$(ARCHIVE) $@ $^
|
||||
o/%.o: %.s; @TARGET=$@ $(COMPILE) $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.s; @TARGET=$@ $(COMPILE) $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/%.s: %.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.s: o/%.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.i: %.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.o: %.S; @ACTION=OBJECTIFY.S $(COMPILE) $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.S; @ACTION=OBJECTIFY.S $(COMPILE) $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/%.s: %.i; @ACTION=COMPILE.i $(COMPILE) $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/%.s: o/%.i; @ACTION=COMPILE.i $(COMPILE) $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/%.o: %.cc; @ACTION=OBJECTIFY.cxx $(COMPILE) $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.cc; @ACTION=OBJECTIFY.cxx $(COMPILE) $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/%.lds: %.lds; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
|
||||
o/%.inc: %.h; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) -D__ASSEMBLER__ -P $<
|
||||
o/%.pkg:; @build/package $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^)
|
||||
o/%.h.ok: %.h; @ACTION=CHECK.h $(COMPILE) $(COMPILE.c) -x c -g0 -o $@ $<
|
||||
o/%.h.okk: %.h; @ACTION=CHECK.h $(COMPILE) $(COMPILE.cxx) -x c++ -g0 -o $@ $<
|
||||
o/%.greg.o: %.greg.c; @ACTION=OBJECTIFY.greg $(COMPILE) $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/%.zip.o: o/%; @build/zipobj $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $<
|
||||
o/%.a: ; @$(COMPILE) -AARCHIVE -T$@ $(AR) $(ARFLAGS) $@ $^
|
||||
o/%.o: %.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/%.s: %.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.s: o/%.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.i: %.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/%.o: %.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/%.s: %.i ; @$(COMPILE) -ACOMPILE.i $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/%.s: o/%.i ; @$(COMPILE) -ACOMPILE.i $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/%.o: %.cc ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/%.o: o/%.cc ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/%.lds: %.lds ; @$(COMPILE) -APREPROCESS $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
|
||||
o/%.inc: %.h ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) -D__ASSEMBLER__ -P $<
|
||||
o/%.pkg: ; @$(COMPILE) -APACKAGE -T$@ $(PKG) $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^)
|
||||
o/%.h.ok: %.h ; @$(COMPILE) -ACHECK.h $(COMPILE.c) -x c -g0 -o $@ $<
|
||||
o/%.h.okk: %.h ; @$(COMPILE) -ACHECK.h $(COMPILE.cxx) -x c++ -g0 -o $@ $<
|
||||
o/%.greg.o: %.greg.c ; @$(COMPILE) -AOBJECTIFY.greg $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/%.zip.o: o/% ; @$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $<
|
||||
|
||||
o/$(MODE)/%.a:; @$(ARCHIVE) $@ $^
|
||||
o/$(MODE)/%: o/$(MODE)/%.dbg; @ACTION=OBJCOPY TARGET=$@ $(COMPILE) $(OBJCOPY) -S -O binary $< $@
|
||||
o/$(MODE)/%.o: %.s; @TARGET=$@ $(COMPILE) $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.s; @TARGET=$@ $(COMPILE) $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: %.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: o/$(MODE)/%.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.c; @ACTION=OBJECTIFY.c $(COMPILE) $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.f; @ACTION=OBJECTIFY.f $(COMPILE) $(OBJECTIFY.f) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.F; @ACTION=OBJECTIFY.F $(COMPILE) $(OBJECTIFY.F) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.c; @ACTION=OBJECTIFY.c $(COMPILE) $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ss: %.c; @ACTION=COMPILE.c $(COMPILE) $(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ss: o/$(MODE)/%.c; @ACTION=OBJECTIFY.s $(COMPILE) $(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.S; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.c; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.cc; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: o/$(MODE)/%.c; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.h: %.c; @ACTION=AMALGAMATE $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
|
||||
o/$(MODE)/%.h: o/$(MODE)/%.c; @ACTION=AMALGAMATE $(COMPILE) $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
|
||||
o/$(MODE)/%.o: %.S; @ACTION=OBJECTIFY.S $(COMPILE) $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.S; @ACTION=OBJECTIFY.S $(COMPILE) $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: %.i; @ACTION=COMPILE.i $(COMPILE) $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: o/$(MODE)/%.i; @ACTION=COMPILE.i $(COMPILE) $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.cc; @ACTION=OBJECTIFY.cxx $(COMPILE) $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.cc; @ACTION=OBJECTIFY.cxx $(COMPILE) $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.lds: %.lds; @ACTION=PREPROCESS $(COMPILE) $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.h.ok: %.h; @ACTION=CHECK.h $(COMPILE) $(COMPILE.c) -x c -g0 -o $@ $<
|
||||
o/$(MODE)/%.h.okk: %.h; @ACTION=CHECK.h $(COMPILE) $(COMPILE.cxx) -x c++ -g0 -o $@ $<
|
||||
o/$(MODE)/%.o: %.greg.c; @ACTION=OBJECTIFY.greg $(COMPILE) $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.greg.o: %.greg.c; @ACTION=OBJECTIFY.greg $(COMPILE) $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ansi.o: %.ansi.c; @ACTION=OBJECTIFY.ansi $(COMPILE) $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ansi.o: %.c; @ACTION=OBJECTIFY.ansi $(COMPILE) $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c99.o: %.c99.c; @ACTION=OBJECTIFY.c99 $(COMPILE) $(OBJECTIFY.c99.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c11.o: %.c11.c; @ACTION=OBJECTIFY.c11 $(COMPILE) $(OBJECTIFY.c11.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c2x.o: %.c2x.c; @ACTION=OBJECTIFY.c2x $(COMPILE) $(OBJECTIFY.c2x.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.initabi.o: %.initabi.c; @ACTION=OBJECTIFY.init $(COMPILE) $(OBJECTIFY.initabi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ncabi.o: %.ncabi.c; @ACTION=OBJECTIFY.nc $(COMPILE) $(OBJECTIFY.ncabi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.real.o: %.c; @ACTION=OBJECTIFY.real $(COMPILE) $(OBJECTIFY.real.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.runs: o/$(MODE)/%; @ACTION=CHECK.runs TARGET=$< build/runcom $< $(TESTARGS) && touch $@
|
||||
o/$(MODE)/%.pkg:; @build/package $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^)
|
||||
o/$(MODE)/%.zip.o: %; @build/zipobj $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.a: ; @$(COMPILE) -AARCHIVE -T$@ $(AR) $(ARFLAGS) $@ $^
|
||||
o/$(MODE)/%: o/$(MODE)/%.dbg ; @$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@
|
||||
o/$(MODE)/%.o: %.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.s ; @$(COMPILE) -AOBJECTIFY.s $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: %.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: o/$(MODE)/%.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.c ; @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.f ; @$(COMPILE) -AOBJECTIFY.f $(OBJECTIFY.f) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.F ; @$(COMPILE) -AOBJECTIFY.F $(OBJECTIFY.F) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.c ; @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ss: %.c ; @$(COMPILE) -ACOMPILE.c $(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ss: o/$(MODE)/%.c ; @$(COMPILE) -AOBJECTIFY.s $(COMPILE.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.S ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.c ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: %.cc ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.i: o/$(MODE)/%.c ; @$(COMPILE) -APREPROCESS $(PREPROCESS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.h: %.c ; @$(COMPILE) -AAMALGAMATE $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
|
||||
o/$(MODE)/%.h: o/$(MODE)/%.c ; @$(COMPILE) -AAMALGAMATE $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
|
||||
o/$(MODE)/%.o: %.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.S ; @$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: %.i ; @$(COMPILE) -ACOMPILE.i $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.s: o/$(MODE)/%.i ; @$(COMPILE) -ACOMPILE.i $(COMPILE.i) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: %.cc ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.o: o/$(MODE)/%.cc ; @$(COMPILE) -AOBJECTIFY.cxx $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.lds: %.lds ; @$(COMPILE) -APREPROCESS $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.h.ok: %.h ; @$(COMPILE) -ACHECK.h $(COMPILE.c) -x c -g0 -o $@ $<
|
||||
o/$(MODE)/%.h.okk: %.h ; @$(COMPILE) -ACHECK.h $(COMPILE.cxx) -x c++ -g0 -o $@ $<
|
||||
o/$(MODE)/%.o: %.greg.c ; @$(COMPILE) -AOBJECTIFY.greg $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.greg.o: %.greg.c ; @$(COMPILE) -AOBJECTIFY.greg $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ansi.o: %.ansi.c ; @$(COMPILE) -AOBJECTIFY.ansi $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ansi.o: %.c ; @$(COMPILE) -AOBJECTIFY.ansi $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c99.o: %.c99.c ; @$(COMPILE) -AOBJECTIFY.c99 $(OBJECTIFY.c99.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c11.o: %.c11.c ; @$(COMPILE) -AOBJECTIFY.c11 $(OBJECTIFY.c11.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.c2x.o: %.c2x.c ; @$(COMPILE) -AOBJECTIFY.c2x $(OBJECTIFY.c2x.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.initabi.o: %.initabi.c ; @$(COMPILE) -AOBJECTIFY.init $(OBJECTIFY.initabi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.ncabi.o: %.ncabi.c ; @$(COMPILE) -AOBJECTIFY.nc $(OBJECTIFY.ncabi.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.real.o: %.c ; @$(COMPILE) -AOBJECTIFY.real $(OBJECTIFY.real.c) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%.runs: o/$(MODE)/% ; @$(COMPILE) -ACHECK -tT$@ $< $(TESTARGS)
|
||||
o/$(MODE)/%.pkg: ; @$(COMPILE) -APACKAGE -T$@ $(PKG) $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^)
|
||||
o/$(MODE)/%.zip.o: % ; @$(COMPILE) -AZIPOBJ $(ZIPOBJ) $(ZIPOBJ_FLAGS) $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-gcc.asm: %.c ; @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-clang.asm: %.c ; @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
|
||||
o/$(MODE)/%-gcc.asm: %.c; @ACTION=OBJECTIFY.c $(COMPILE) $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-clang.asm: CC = $(CLANG)
|
||||
o/$(MODE)/%-clang.asm: %.c; @ACTION=OBJECTIFY.c $(COMPILE) $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
o/$(MODE)/%-gcc.asm: %.f; @ACTION=OBJECTIFY.f $(COMPILE) $(OBJECTIFY.f) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-clang.asm: CC = $(CLANG)
|
||||
o/$(MODE)/%-clang.asm: %.f; @ACTION=OBJECTIFY.f $(COMPILE) $(OBJECTIFY.f) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
o/$(MODE)/%-gcc.asm: %.F; @ACTION=OBJECTIFY.F $(COMPILE) $(OBJECTIFY.F) -S -g0 $(OUTPUT_OPTION) $<
|
||||
o/$(MODE)/%-clang.asm: CC = $(CLANG)
|
||||
o/$(MODE)/%-clang.asm: %.F; @ACTION=OBJECTIFY.F $(COMPILE) $(OBJECTIFY.F) -S -g0 $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
|
||||
DD=${DD:-$(command -v dd)} || exit
|
||||
$DD if="$1" of="$1.bak" bs=4096 count=1 conv=notrunc 2>/dev/null
|
||||
"$@"
|
||||
rc=$?
|
||||
echo "$1"
|
||||
$DD if="$1.bak" of="$1" bs=4096 count=1 conv=notrunc 2>/dev/null
|
||||
exit $rc
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# SSH Command Wrapper
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This script, like most of our wrappers, asks the tooling to whine
|
||||
# less often.
|
||||
|
||||
exec ${SSH:-ssh} -o LogLevel=QUIET "$@"
|
||||
@@ -1,51 +0,0 @@
|
||||
#!/bin/sh
|
||||
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
|
||||
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
|
||||
|
||||
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
||||
CP=${CP:-$(command -v cp) -f} || exit
|
||||
SED=${SED:-$(command -v sed)} || exit
|
||||
|
||||
MODE=
|
||||
|
||||
OUT=
|
||||
FIRST=1
|
||||
OUTARG=0
|
||||
for x; do
|
||||
if [ $FIRST -eq 1 ]; then
|
||||
set --
|
||||
FIRST=0
|
||||
elif [ $OUTARG -eq 1 ]; then
|
||||
OUTARG=0
|
||||
OUT="$x"
|
||||
fi
|
||||
case "$x" in
|
||||
-o)
|
||||
OUTARG=1
|
||||
;;
|
||||
esac
|
||||
set -- "$@" "$x"
|
||||
done
|
||||
OUTDIR="${OUT%/*}"
|
||||
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
|
||||
$MKDIR "$OUTDIR" || exit 2
|
||||
fi
|
||||
|
||||
if [ -x "o/$MODE/tool/build/zipobj.com.dbg" ]; then
|
||||
set -- "o/$MODE/tool/build/zipobj.com.dbg" "$@"
|
||||
else
|
||||
if [ ! -x o/build/bootstrap/zipobj.com ]; then
|
||||
$MKDIR o/build/bootstrap &&
|
||||
$CP -a build/bootstrap/zipobj.com \
|
||||
o/build/bootstrap/zipobj.com || exit
|
||||
fi
|
||||
set -- o/build/bootstrap/zipobj.com "$@"
|
||||
fi
|
||||
|
||||
if [ "$V" = "0" ]; then
|
||||
printf "$LOGFMT" "${ACTION:-ZIPOBJ}" "$3" >&2
|
||||
else
|
||||
printf "%s\n" "$*" >&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#ifndef COSMOPOLITAN_DSP_CORE_C161_H_
|
||||
#define COSMOPOLITAN_DSP_CORE_C161_H_
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
#define EXTRA_SHARP 2
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#ifndef COSMOPOLITAN_DSP_CORE_C161S_H_
|
||||
#define COSMOPOLITAN_DSP_CORE_C161S_H_
|
||||
#include "dsp/core/c161.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
forceinline pureconst artificial signed char C161S(signed char al,
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/core/core.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "libc/assert.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "dsp/core/core.h"
|
||||
#include "dsp/core/q.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#ifndef COSMOPOLITAN_DSP_CORE_HALF_H_
|
||||
#define COSMOPOLITAN_DSP_CORE_HALF_H_
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#ifndef COSMOPOLITAN_DSP_CORE_KS8_H_
|
||||
#define COSMOPOLITAN_DSP_CORE_KS8_H_
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#ifndef COSMOPOLITAN_DSP_CORE_KSS8_H_
|
||||
#define COSMOPOLITAN_DSP_CORE_KSS8_H_
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
#define BIAS 0x84
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#ifndef COSMOPOLITAN_DSP_CORE_Q_H_
|
||||
#define COSMOPOLITAN_DSP_CORE_Q_H_
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/math.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
.align 16
|
||||
|
||||
// Mixes audio.
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/core/core.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/limits.h"
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
.source __FILE__
|
||||
|
||||
clamp4int256$core:
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@
|
||||
#include "libc/bits/initializer.internal.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@
|
||||
│ SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/mpeg/mpeg.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
PL_MPEG (MIT License)\\n\
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "dsp/core/ks8.h"
|
||||
#include "dsp/core/kss8.h"
|
||||
#include "dsp/scale/cdecimate2xuint8x8.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/tty.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/termios.h"
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
// TODO(jart): write me
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
#include "libc/bits/initializer.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
struct TtyRgb rgb2ttyi2f_(int r, int g, int b) {
|
||||
return rgb2ttyf((__m128){r, g, b} / 255);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
struct TtyRgb rgb2xterm24_(int r, int g, int b) {
|
||||
return (struct TtyRgb){MAX(MIN(r, 255), 0), MAX(MIN(g, 255), 0),
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/tty.h"
|
||||
#include "libc/alg/arraylist2.internal.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
/* TODO(jart): DELETE */
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/itoa8.h"
|
||||
#include "dsp/tty/tty.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/check.h"
|
||||
|
||||
|
||||
+2
-2
@@ -23,11 +23,11 @@
|
||||
#include "dsp/tty/windex.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
+2
-2
@@ -26,8 +26,8 @@
|
||||
#include "libc/calls/typedef/sigaction_f.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
.source __FILE__
|
||||
|
||||
// Returns index of minimum uint16 in array.
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
.source __FILE__
|
||||
|
||||
// Returns index of minimum positive int16 in array.
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/macros.internal.h"
|
||||
.source __FILE__
|
||||
|
||||
// Dispatches to fastest windex() implementation.
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ void GetOpts(int argc, char *argv[]) {
|
||||
|
||||
int cp(const char *src, const char *dst) {
|
||||
if (endswith(dst, "/") || isdirectory(dst)) {
|
||||
dst = gc(xasprintf("%s/%s", dst, basename));
|
||||
dst = _gc(xasprintf("%s/%s", dst, basename));
|
||||
}
|
||||
if (!force && access(dst, W_OK) == -1 && errno != ENOENT) goto OnFail;
|
||||
if (copyfile(src, dst, flags) == -1) goto OnFail;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
||||
+8
-73
@@ -7,88 +7,23 @@
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/bits/pushpop.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/nt/enum/errormodeflags.h"
|
||||
#include "libc/nt/signals.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Demonstrates SEGFAULT via NULL pointer dereference.
|
||||
* @fileoverview How to print backtraces and cpu state on crash.
|
||||
*
|
||||
* In MODE=dbg mode, UBSAN should catch this and display a backtrace.
|
||||
* In most other modes, e.g. MODE=balanced, the oncrash.c sig handler
|
||||
* will either launch GDB or display a very fancy report.
|
||||
*
|
||||
* make -j8 -O MODE=opt o/opt/examples/crashreportdemo.com
|
||||
* o/opt/examples/crashreportdemo.com
|
||||
* make -j8 -O o//examples/crashreport.com
|
||||
* o//examples/crashreport.com
|
||||
*
|
||||
* To prevent the GDB GUI from popping up:
|
||||
*
|
||||
* export GDB=""
|
||||
* make -j8 -O MODE=opt o/opt/examples/crashreportdemo.com
|
||||
* o/opt/examples/crashreportdemo.com
|
||||
* export GDB=
|
||||
* make -j8 -O o//examples/crashreport.com
|
||||
* o//examples/crashreport.com
|
||||
*/
|
||||
|
||||
int boo;
|
||||
|
||||
void boop(void);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int64_t res;
|
||||
volatile int64_t x;
|
||||
showcrashreports();
|
||||
res = 0;
|
||||
|
||||
asm volatile("mov\t$0x1111111111111111,%rax\n\t"
|
||||
"mov\t$0x3333333333333333,%rcx\n\t"
|
||||
"mov\t$0x4444444444444444,%rdx\n\t"
|
||||
"mov\t$0x8888888888888888,%r8\n\t"
|
||||
"mov\t$0x9999999999999999,%r9d\n\t"
|
||||
"mov\t$0xaaaaaaaaaaaaaaaa,%r10d\n\t"
|
||||
"mov\t$0xbbbbbbbbbbbbbbbb,%r11d\n\t"
|
||||
"mov\t$0x0000000000000000,%rax\n\t"
|
||||
"movd\t%rax,%xmm0\n\t"
|
||||
"mov\t$0x1111111111111111,%rax\n\t"
|
||||
"push\t%rax\n\t"
|
||||
"push\t%rax\n\t"
|
||||
"movdqu\t(%rsp),%xmm1\n\t"
|
||||
"pop\t%rax\n\t"
|
||||
"pop\t%rax\n\t"
|
||||
"mov\t$0x2222222222220022,%rax\n\t"
|
||||
"movd\t%rax,%xmm2\n\t"
|
||||
"mov\t$0x3333333333333333,%rax\n\t"
|
||||
"movd\t%rax,%xmm3\n\t"
|
||||
"mov\t$0x4444444444444444,%rax\n\t"
|
||||
"movd\t%rax,%xmm4\n\t"
|
||||
"mov\t$0x5555555555555555,%rax\n\t"
|
||||
"movd\t%rax,%xmm5\n\t"
|
||||
"mov\t$0x6666666666666666,%rax\n\t"
|
||||
"movd\t%rax,%xmm6\n\t"
|
||||
"mov\t$0x7777777777777777,%rax\n\t"
|
||||
"movd\t%rax,%xmm7\n\t"
|
||||
"mov\t$0x8888888888888888,%rax\n\t"
|
||||
"movd\t%rax,%xmm8\n\t"
|
||||
"mov\t$0x9999999999999999,%rax\n\t"
|
||||
"movd\t%rax,%xmm9\n\t"
|
||||
"mov\t$0xaaaaaaaaaaaaaaaa,%rax\n\t"
|
||||
"movd\t%rax,%xmm10\n\t"
|
||||
"mov\t$0xbbbbbbbbbbbbbbbb,%rax\n\t"
|
||||
"movd\t%rax,%xmm11\n\t"
|
||||
"mov\t$0xcccccccccccccccc,%rax\n\t"
|
||||
"movd\t%rax,%xmm12\n\t"
|
||||
"mov\t$0xdddddddddddddddd,%rax\n\t"
|
||||
"movd\t%rax,%xmm13\n\t"
|
||||
"mov\t$0xeeeeeeeeeeeeeeee,%rax\n\t"
|
||||
"movd\t%rax,%xmm14\n\t"
|
||||
"mov\t$0xffffffffffffffff,%rax\n\t"
|
||||
"movd\t%rax,%xmm15\n\t"
|
||||
"fldpi\n\t"
|
||||
"xor\t%eax,%eax\n\t"
|
||||
"div\t%eax\n\t");
|
||||
|
||||
return res;
|
||||
return 1 / (x = 0);
|
||||
}
|
||||
+2
-3
@@ -14,7 +14,6 @@
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nt/thread.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
@@ -32,9 +31,9 @@ int main(int argc, char *argv[]) {
|
||||
ssize_t rc;
|
||||
size_t got, wrote;
|
||||
unsigned char buf[512];
|
||||
struct sigaction saint = {.sa_handler = GotCtrlC};
|
||||
fprintf(stderr, "This echos stdio until Ctrl+C is pressed.\n");
|
||||
CHECK_NE(
|
||||
-1, sigaction(SIGINT, &(struct sigaction){.sa_handler = GotCtrlC}, NULL));
|
||||
CHECK_NE(-1, sigaction(SIGINT, &saint, NULL));
|
||||
for (;;) {
|
||||
rc = read(0, buf, BUFSIZ);
|
||||
if (rc != -1) {
|
||||
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/dns/dns.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/consts/ai.h"
|
||||
#include "libc/sysv/consts/ipproto.h"
|
||||
#include "libc/sysv/consts/shut.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "net/http/uri.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Downloads HTTP URL to stdout.
|
||||
*
|
||||
* make -j8 o//examples/curl.com
|
||||
* o//examples/curl.com http://justine.lol/ape.html
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int sock;
|
||||
ssize_t rc;
|
||||
unsigned long need;
|
||||
struct UriSlice path;
|
||||
size_t i, got, toto, msglen;
|
||||
char buf[1500], host[256], port[7];
|
||||
const char *url, *msg, *pathstr, *crlfcrlf, *contentlength;
|
||||
struct UriSlice us[16];
|
||||
struct Uri u = {.segs.p = us, .segs.n = ARRAYLEN(us)};
|
||||
struct addrinfo *addr, *addrs;
|
||||
struct addrinfo hints = {.ai_family = AF_INET,
|
||||
.ai_socktype = SOCK_STREAM,
|
||||
.ai_protocol = IPPROTO_TCP,
|
||||
.ai_flags = AI_NUMERICSERV};
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "USAGE: %s URL\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
url = argv[1];
|
||||
CHECK_NE(-1, uriparse(&u, url, strlen(url)), "BAD URL: %`'s", url);
|
||||
CHECK_EQ(kUriSchemeHttp, urischeme(u.scheme, url));
|
||||
urislice2cstr(host, sizeof(host), u.host, url, "127.0.0.1");
|
||||
urislice2cstr(port, sizeof(port), u.port, url, "80");
|
||||
path = uripath(&u);
|
||||
pathstr = path.n ? url + path.i : "/";
|
||||
msg = _gc(xstrcat("GET ", pathstr,
|
||||
" HTTP/1.1\r\n"
|
||||
"Host: ",
|
||||
host,
|
||||
"\r\n"
|
||||
"Connection: close\r\n"
|
||||
"Content-Length: 0\r\n"
|
||||
"Accept: text/plain; */*\r\n"
|
||||
"Accept-Encoding: identity\r\n"
|
||||
"User-Agent: github.com/jart/cosmopolitan\r\n"
|
||||
"\r\n"));
|
||||
msglen = strlen(msg);
|
||||
CHECK_EQ(EAI_SUCCESS, getaddrinfo(host, port, &hints, &addrs));
|
||||
for (addr = addrs; addr; addr = addr->ai_next) {
|
||||
CHECK_NE(-1, (sock = socket(addr->ai_family, addr->ai_socktype,
|
||||
addr->ai_protocol)));
|
||||
CHECK_NE(-1, connect(sock, addr->ai_addr, addr->ai_addrlen));
|
||||
CHECK_EQ(msglen, write(sock, msg, msglen));
|
||||
shutdown(sock, SHUT_WR);
|
||||
buf[0] = '\0';
|
||||
CHECK_NE(-1, (rc = read(sock, buf, sizeof(buf))));
|
||||
got = rc;
|
||||
CHECK(startswith(buf, "HTTP/1.1 200"), "%`'.*s", got, buf);
|
||||
CHECK_NOTNULL((crlfcrlf = memmem(buf, got, "\r\n\r\n", 4)));
|
||||
need = strtol((char *)firstnonnull(
|
||||
memmem(buf, crlfcrlf - buf, "\r\nContent-Length: ", 18),
|
||||
firstnonnull(memmem(buf, crlfcrlf - buf,
|
||||
"\r\ncontent-length: ", 18),
|
||||
"\r\nContent-Length: -1")) +
|
||||
18,
|
||||
NULL, 10);
|
||||
got = MIN(got - (crlfcrlf + 4 - buf), need);
|
||||
CHECK_EQ(got, write(1, crlfcrlf + 4, got));
|
||||
for (toto = got; toto < need; toto += got) {
|
||||
CHECK_NE(-1, (rc = read(sock, buf, sizeof(buf))));
|
||||
if (!(got = rc)) exit(18);
|
||||
got = MIN(got, need - toto);
|
||||
CHECK_EQ(got, write(1, buf, got));
|
||||
}
|
||||
close(sock);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+1
-1
@@ -16,6 +16,6 @@
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
puts(gc(xiso8601ts(NULL)));
|
||||
puts(_gc(xiso8601ts(NULL)));
|
||||
return 0;
|
||||
}
|
||||
@@ -1,376 +0,0 @@
|
||||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "dsp/core/core.h"
|
||||
#include "dsp/core/twixt8.h"
|
||||
#include "dsp/scale/scale.h"
|
||||
#include "dsp/tty/itoa8.h"
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "libc/alg/arraylist2.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/ioctl.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/struct/winsize.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "third_party/stb/stb_image.h"
|
||||
|
||||
/**
|
||||
* Hat tips go out to Hornet, CRTC, DESiRE, Hans Petter Jansson, Guihua
|
||||
* Cui, Ming Ronnier Luoand anyone else Mister Rogers would describe as
|
||||
* the The Helpers Of This World who've helped us learn more about the
|
||||
* cool yet exceedingly difficult things possible to do with graphics.
|
||||
*/
|
||||
|
||||
#define DIN99 1
|
||||
#define GAMMA 4.1
|
||||
#define GAMMA_A .05
|
||||
#define GAMMA_B 50.
|
||||
#define GAMMA_C .055
|
||||
#define COLORSPACE_SRC kSrgbD65ToXyzD50
|
||||
#define COLORSPACE_TTY kSrgbD65ToXyzD50
|
||||
|
||||
#define SQR(X) ((X) * (X))
|
||||
#define DEG(X) ((X)*M_PI / 180)
|
||||
|
||||
const double kXyzKappa = 24389 / 27.;
|
||||
const double kXyzEpsilon = 216 / 24389.;
|
||||
|
||||
const double kSrgbD65ToXyzD50[3][3] = {
|
||||
{.4360747, .3850649, .1430804},
|
||||
{.2225045, .7168786, .0606169},
|
||||
{.0139322, .0971045, .7141733},
|
||||
};
|
||||
|
||||
const double kCieRgbEToXyz[3][3] = {
|
||||
{.4887180, .3106803, .2006017},
|
||||
{.1762044, .8129847, .0108109},
|
||||
{.0000000, .0102048, .9897952},
|
||||
};
|
||||
|
||||
const unsigned char kShadePct[] = {0300, 0200, 0100};
|
||||
const unsigned short kShadeRune[] = {u'▓', u'▒', u'░'};
|
||||
|
||||
const unsigned char kAnsiTango[16][3] = {
|
||||
{46, 52, 54}, {204, 0, 0}, {78, 154, 6}, {196, 160, 0},
|
||||
{52, 101, 164}, {117, 80, 123}, {6, 152, 154}, {211, 215, 207},
|
||||
{85, 87, 83}, {239, 41, 41}, {138, 226, 52}, {252, 233, 79},
|
||||
{114, 159, 207}, {173, 127, 168}, {52, 226, 226}, {238, 238, 236},
|
||||
};
|
||||
|
||||
const unsigned char kCga[16][3] = {
|
||||
{0, 0, 0}, {170, 0, 0}, {0, 170, 0}, {170, 85, 0},
|
||||
{0, 0, 170}, {170, 0, 170}, {0, 170, 170}, {170, 170, 170},
|
||||
{85, 85, 85}, {255, 85, 85}, {85, 255, 85}, {255, 255, 85},
|
||||
{85, 85, 255}, {255, 85, 255}, {85, 255, 255}, {255, 255, 255},
|
||||
};
|
||||
|
||||
struct Blends {
|
||||
size_t i, n;
|
||||
struct Blend {
|
||||
unsigned char color[4];
|
||||
unsigned char bg, fg;
|
||||
unsigned short rune;
|
||||
} * p;
|
||||
} blends;
|
||||
|
||||
static double Gamma(double x) {
|
||||
if (x < GAMMA_A) return x / GAMMA_B;
|
||||
return pow(1 / (1 + GAMMA_C) * (x + GAMMA_C), GAMMA);
|
||||
}
|
||||
|
||||
static void *LoadRgb(double rgb[3], const unsigned char pix[3]) {
|
||||
rgb[0] = Gamma(1. / 255 * pix[0]);
|
||||
rgb[1] = Gamma(1. / 255 * pix[1]);
|
||||
rgb[2] = Gamma(1. / 255 * pix[2]);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
static double Lab(double x) {
|
||||
return x > kXyzEpsilon ? cbrtf(x) : (kXyzKappa * x + 16) / 116;
|
||||
}
|
||||
|
||||
static void XyzToLab(double lab[3], const double d50xyz[3]) {
|
||||
double Y, L, a, b;
|
||||
Y = Lab(d50xyz[1]);
|
||||
L = 116 * Y - 16;
|
||||
a = 500 * (Lab(d50xyz[0]) - Y);
|
||||
b = 200 * (Y - Lab(d50xyz[2]));
|
||||
lab[0] = L, lab[1] = a, lab[2] = b;
|
||||
}
|
||||
|
||||
static void XyzToDin99d(unsigned char din99d[3], const double d50xyz[3]) {
|
||||
double e, f, G, C, h, xyz[3], lab[3];
|
||||
memcpy(xyz, d50xyz, sizeof(xyz));
|
||||
xyz[0] = 1.12f * xyz[0] - .12f * xyz[2];
|
||||
XyzToLab(lab, xyz);
|
||||
e = (+lab[1] * cosf(DEG(50)) + lab[2] * sinf(DEG(50)));
|
||||
f = (-lab[1] * sinf(DEG(50)) + lab[2] + cosf(DEG(50))) * 1.14;
|
||||
G = sqrtf(SQR(e) + SQR(f));
|
||||
C = logf(1 + .06 * G) * 22.5f;
|
||||
h = atan2f(f, e) + DEG(50);
|
||||
h = fmodf(h, DEG(360));
|
||||
if (h < 0) h += DEG(360);
|
||||
din99d[0] = MIN(255, MAX(0, 325.22f * logf(1 + .0036 * lab[0]) * 2.5f));
|
||||
din99d[1] = MIN(255, MAX(0, C * cos(h) * 2.5f + 128));
|
||||
din99d[2] = MIN(255, MAX(0, C * sin(h) * 2.5f + 128));
|
||||
}
|
||||
|
||||
static void AddColor(int bg, int fg, int rune, int r, int g, int b, int x) {
|
||||
int i;
|
||||
if (blends.i) {
|
||||
for (i = blends.i; --i;) {
|
||||
if (blends.p[i].color[0] == r && blends.p[i].color[1] == g &&
|
||||
blends.p[i].color[2] == b) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
CHECK_NE(
|
||||
-1,
|
||||
APPEND(&blends.p, &blends.i, &blends.n,
|
||||
(&(struct Blend){
|
||||
.bg = bg, .fg = fg, .rune = rune, .color = {r, g, b, x}})));
|
||||
}
|
||||
|
||||
static void AddBlend(int bgxterm, int fgxterm, int rune, int shade,
|
||||
const unsigned char bgrgb[4],
|
||||
const unsigned char fgrgb[4]) {
|
||||
AddColor(bgxterm, fgxterm, rune, twixt8(bgrgb[0], fgrgb[0], shade),
|
||||
twixt8(bgrgb[1], fgrgb[1], shade), twixt8(bgrgb[2], fgrgb[2], shade),
|
||||
0);
|
||||
}
|
||||
|
||||
static void MakeBlends(const unsigned char palette[16][3]) {
|
||||
int r, i, j, k;
|
||||
double rgb[3], xyz[3];
|
||||
unsigned char tab[256][4];
|
||||
unsigned char cube[6] = {0, 0137, 0207, 0257, 0327, 0377};
|
||||
unsigned char seqs[2][2] = {{16, 255}};
|
||||
for (i = 0; i < 16; ++i) {
|
||||
tab[i][0] = palette[i][0];
|
||||
tab[i][1] = palette[i][1];
|
||||
tab[i][2] = palette[i][2];
|
||||
tab[i][3] = i;
|
||||
}
|
||||
for (i = 16; i < 232; ++i) {
|
||||
tab[i][0] = cube[((i - 020) / 044) % 6];
|
||||
tab[i][1] = cube[((i - 020) / 6) % 6];
|
||||
tab[i][2] = cube[(i - 020) % 6];
|
||||
tab[i][3] = i;
|
||||
}
|
||||
for (i = 232; i < 256; ++i) {
|
||||
tab[i][0] = 8 + (i - 232) * 10;
|
||||
tab[i][1] = 8 + (i - 232) * 10;
|
||||
tab[i][2] = 8 + (i - 232) * 10;
|
||||
tab[i][3] = i;
|
||||
}
|
||||
#if DIN99
|
||||
for (i = 0; i < 256; ++i) {
|
||||
LoadRgb(rgb, tab[i]);
|
||||
vmatmul3(xyz, rgb, COLORSPACE_TTY);
|
||||
XyzToDin99d(tab[i], xyz);
|
||||
}
|
||||
#endif
|
||||
for (r = 0; r < ARRAYLEN(seqs); ++r) {
|
||||
for (i = seqs[r][0]; i <= seqs[r][1]; ++i) {
|
||||
for (j = seqs[r][0]; j <= seqs[r][1]; ++j) {
|
||||
if (i == j) {
|
||||
AddColor(i, 0, 0, tab[i][0], tab[i][1], tab[i][2], 0);
|
||||
} else {
|
||||
for (k = 0; k < ARRAYLEN(kShadeRune); ++k) {
|
||||
AddBlend(i, j, kShadeRune[k], kShadePct[k], tab[i], tab[j]);
|
||||
AddBlend(j, i, kShadeRune[k], kShadePct[k], tab[j], tab[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int PickColor(unsigned char color[3]) {
|
||||
int i, best, least, dist;
|
||||
best = -1;
|
||||
least = INT_MAX;
|
||||
for (i = 0; i < blends.i; ++i) {
|
||||
dist = SQR(blends.p[i].color[0] - color[0]) +
|
||||
SQR(blends.p[i].color[1] - color[1]) +
|
||||
SQR(blends.p[i].color[2] - color[2]);
|
||||
if (dist < least) {
|
||||
least = dist;
|
||||
best = i;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
static void SetBg(int x) {
|
||||
if (0 <= x && x < 16) {
|
||||
if (x < 8) {
|
||||
x += 40;
|
||||
} else {
|
||||
x -= 8;
|
||||
x *= 100;
|
||||
}
|
||||
printf("\e[%dm", x);
|
||||
} else {
|
||||
/* assert(false); */
|
||||
printf("\e[48;5;%dm", x);
|
||||
}
|
||||
}
|
||||
|
||||
static void SetFg(int x) {
|
||||
if (0 <= x && x < 16) {
|
||||
if (x < 8) {
|
||||
x += 30;
|
||||
} else {
|
||||
x -= 8;
|
||||
x *= 90;
|
||||
}
|
||||
printf("\e[%dm", x);
|
||||
} else {
|
||||
/* assert(false); */
|
||||
printf("\e[38;5;%dm", x);
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintImage(long yn, long xn, unsigned char src[4][yn][xn]) {
|
||||
int y, x, c;
|
||||
double rgb[3], xyz[3];
|
||||
unsigned char din99d[3];
|
||||
for (y = 0; y < yn; ++y) {
|
||||
printf("\n");
|
||||
for (x = 0; x < xn; ++x) {
|
||||
din99d[0] = src[0][y][x];
|
||||
din99d[1] = src[1][y][x];
|
||||
din99d[2] = src[2][y][x];
|
||||
#if DIN99
|
||||
LoadRgb(rgb, din99d);
|
||||
vmatmul3(xyz, rgb, COLORSPACE_SRC);
|
||||
XyzToDin99d(din99d, xyz);
|
||||
#endif
|
||||
c = PickColor(din99d);
|
||||
if (blends.p[c].rune) {
|
||||
SetBg(blends.p[c].bg);
|
||||
SetFg(blends.p[c].fg);
|
||||
printf("%hc", blends.p[c].rune);
|
||||
} else {
|
||||
SetBg(blends.p[c].bg);
|
||||
printf(" ");
|
||||
}
|
||||
}
|
||||
printf("\e[0m");
|
||||
}
|
||||
printf("\r");
|
||||
}
|
||||
|
||||
static void *Deinterlace(long dcn, long dyn, long dxn,
|
||||
unsigned char dst[dcn][dyn][dxn], long syw, long sxw,
|
||||
long scw, const unsigned char src[syw][sxw][scw],
|
||||
long syn, long sxn, long sy0, long sx0, long sc0) {
|
||||
long y, x, c;
|
||||
for (y = 0; y < dyn; ++y) {
|
||||
for (x = 0; x < dxn; ++x) {
|
||||
for (c = 0; c < dcn; ++c) {
|
||||
dst[c][y][x] = src[sy0 + y][sx0 + x][sc0 + c];
|
||||
}
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
static void GetTermSize(int out_rows[1], int out_cols[1]) {
|
||||
struct winsize ws;
|
||||
ws.ws_row = 24;
|
||||
ws.ws_col = 80;
|
||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) {
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
|
||||
}
|
||||
out_rows[0] = ws.ws_row;
|
||||
out_cols[0] = ws.ws_col;
|
||||
}
|
||||
|
||||
static void ProcessImage(long syn, long sxn, unsigned char img[syn][sxn][4]) {
|
||||
int dyn, dxn;
|
||||
double ry, rx;
|
||||
GetTermSize(&dyn, &dxn);
|
||||
ry = syn, rx = sxn;
|
||||
ry /= dyn, rx /= dxn;
|
||||
PrintImage(
|
||||
dyn, dxn,
|
||||
EzGyarados(4, dyn, dxn, gc(xmemalign(32, dyn * dxn * 4)), 4, syn, sxn,
|
||||
Deinterlace(4, syn, sxn, gc(xmemalign(32, syn * sxn * 4)), syn,
|
||||
sxn, 4, img, syn, sxn, 0, 0, 0),
|
||||
0, 4, dyn, dxn, syn, sxn, ry, rx, 0, 0));
|
||||
}
|
||||
|
||||
static void WithImageFile(const char *path,
|
||||
void fn(long yn, long xn,
|
||||
unsigned char src[yn][xn][4])) {
|
||||
struct stat st;
|
||||
void *map, *data;
|
||||
int fd, yn, xn, cn;
|
||||
CHECK_NE(-1, (fd = open(path, O_RDONLY)), "%s", path);
|
||||
CHECK_NE(-1, fstat(fd, &st));
|
||||
CHECK_GT(st.st_size, 0);
|
||||
CHECK_LE(st.st_size, INT_MAX);
|
||||
CHECK_NE(MAP_FAILED,
|
||||
(map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)));
|
||||
CHECK_NOTNULL(
|
||||
(data = stbi_load_from_memory(map, st.st_size, &xn, &yn, NULL, 4)), "%s",
|
||||
path);
|
||||
CHECK_NE(-1, munmap(map, st.st_size));
|
||||
CHECK_NE(-1, close(fd));
|
||||
fn(yn, xn, data);
|
||||
free(data);
|
||||
}
|
||||
|
||||
static void PrintData(void) {
|
||||
int i;
|
||||
for (i = 0; i < blends.i; ++i) {
|
||||
printf("%3d %3d %3d %3d %3d %d\n", blends.p[i].color[0],
|
||||
blends.p[i].color[1], blends.p[i].color[2], blends.p[i].bg,
|
||||
blends.p[i].fg, blends.p[i].rune);
|
||||
}
|
||||
}
|
||||
|
||||
void *OpenRgbMap(const char *path) {
|
||||
int fd;
|
||||
void *map;
|
||||
size_t size;
|
||||
size = 256 * 256 * 256 * 3;
|
||||
CHECK_NE(-1, (fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644)));
|
||||
CHECK_NE(-1, ftruncate(fd, size));
|
||||
CHECK_NE(MAP_FAILED,
|
||||
(map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)));
|
||||
CHECK_NE(-1, close(fd));
|
||||
return map;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i;
|
||||
MakeBlends(kCga);
|
||||
for (i = 1; i < argc; ++i) {
|
||||
WithImageFile(argv[i], ProcessImage);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+7
-12
@@ -33,13 +33,13 @@ EXAMPLES_BINS = \
|
||||
$(EXAMPLES_COMS:%=%.dbg)
|
||||
|
||||
EXAMPLES_DIRECTDEPS = \
|
||||
APE_LIB \
|
||||
DSP_CORE \
|
||||
DSP_SCALE \
|
||||
DSP_TTY \
|
||||
LIBC_ALG \
|
||||
LIBC_BITS \
|
||||
LIBC_CALLS \
|
||||
LIBC_DNS \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_LOG \
|
||||
@@ -64,10 +64,12 @@ EXAMPLES_DIRECTDEPS = \
|
||||
LIBC_UNICODE \
|
||||
LIBC_X \
|
||||
LIBC_ZIPOS \
|
||||
NET_HTTP \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_DLMALLOC \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_GETOPT \
|
||||
THIRD_PARTY_LUA \
|
||||
THIRD_PARTY_MUSL \
|
||||
THIRD_PARTY_STB \
|
||||
THIRD_PARTY_XED \
|
||||
@@ -79,7 +81,6 @@ EXAMPLES_DEPS := \
|
||||
|
||||
o/$(MODE)/examples/examples.pkg: \
|
||||
$(EXAMPLES_OBJS) \
|
||||
$(THIRD_PARTY_DUKTAPE_A).pkg \
|
||||
$(foreach x,$(EXAMPLES_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/$(MODE)/examples/unbourne.o: \
|
||||
@@ -94,11 +95,10 @@ o/$(MODE)/examples/%.com.dbg: \
|
||||
$(APE)
|
||||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/examples/hellojs.com.dbg: \
|
||||
o/$(MODE)/examples/hellolua.com.dbg: \
|
||||
$(EXAMPLES_DEPS) \
|
||||
$(THIRD_PARTY_DUKTAPE) \
|
||||
o/$(MODE)/examples/hellojs.o \
|
||||
o/$(MODE)/examples/hello.js.zip.o \
|
||||
o/$(MODE)/examples/hellolua.o \
|
||||
o/$(MODE)/examples/hellolua.lua.zip.o \
|
||||
o/$(MODE)/examples/examples.pkg \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
@@ -115,7 +115,6 @@ o/$(MODE)/examples/ispell.com.dbg: \
|
||||
|
||||
o/$(MODE)/examples/nesemu1.com.dbg: \
|
||||
$(EXAMPLES_DEPS) \
|
||||
$(THIRD_PARTY_DUKTAPE) \
|
||||
o/$(MODE)/examples/nesemu1.o \
|
||||
o/$(MODE)/usr/share/rom/mario.nes.zip.o \
|
||||
o/$(MODE)/usr/share/rom/zelda.nes.zip.o \
|
||||
@@ -128,13 +127,9 @@ o/$(MODE)/examples/nesemu1.com.dbg: \
|
||||
$(EXAMPLES_OBJS): examples/examples.mk
|
||||
|
||||
usr/share/dict/words: usr/share/dict/words.gz
|
||||
@$(MKDIR) $(dir $@)
|
||||
@mkdir -p $(@D)
|
||||
@$(GZ) $(ZFLAGS) -d <$< >$@
|
||||
|
||||
o/$(MODE)/examples/ugh.ok: o/$(MODE)/examples/wut.com
|
||||
$<
|
||||
touch $@
|
||||
|
||||
.PHONY: o/$(MODE)/examples
|
||||
o/$(MODE)/examples: \
|
||||
o/$(MODE)/examples/package \
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 2) return 1;
|
||||
execv(argv[1], argv + 1);
|
||||
abort();
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/itimerval.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/color.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/itimer.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/time/time.h"
|
||||
|
||||
static const struct itimerval kTimer = {{0, 10000}, {0, 10000}}; /* 10ms */
|
||||
static volatile bool32 showprogress_;
|
||||
static const char *magic_;
|
||||
|
||||
void OnInterrupt(int sig) {
|
||||
showprogress_ = true;
|
||||
}
|
||||
|
||||
void ShowProgress(uintmax_t i, uintmax_t j, uintmax_t n) {
|
||||
fprintf(stderr, "%s%,40jd%,40jd%,40jd\r\n", magic_, i, j, n);
|
||||
showprogress_ = false;
|
||||
}
|
||||
|
||||
static bool IsPrime(uintmax_t i) {
|
||||
uintmax_t j, n;
|
||||
for (j = 3, n = (unsigned long)floorl(sqrtl(i)); j <= n; j += 2) {
|
||||
if (showprogress_) ShowProgress(i, j, n);
|
||||
if (i % j == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void TryNumber(uintmax_t x, uintmax_t i) {
|
||||
if (IsPrime(i)) {
|
||||
printf("%s%,jd%s%,jd\n", "the prime nearest ", x, " is ", i);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
uintmax_t x, i, j;
|
||||
CHECK_EQ(2, argc);
|
||||
signal(SIGALRM, OnInterrupt);
|
||||
setitimer(ITIMER_REAL, &kTimer, NULL);
|
||||
magic_ = cancolor() ? "\e[F\e[K" : "";
|
||||
if ((x = strtoumax(argv[1], NULL, 0)) % 2 == 0) ++x;
|
||||
TryNumber(x, x);
|
||||
for (i = x, j = x;;) {
|
||||
if (i < UINTMAX_MAX) TryNumber(x, i), i += 2;
|
||||
if (j > 1) TryNumber(x, j), j -= 2;
|
||||
}
|
||||
}
|
||||
+65
-1
@@ -7,9 +7,73 @@
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nexgen32e/nt2sysv.h"
|
||||
#include "libc/nt/dll.h"
|
||||
#include "libc/nt/enum/cw.h"
|
||||
#include "libc/nt/enum/mb.h"
|
||||
#include "libc/nt/enum/sw.h"
|
||||
#include "libc/nt/enum/wm.h"
|
||||
#include "libc/nt/enum/ws.h"
|
||||
#include "libc/nt/events.h"
|
||||
#include "libc/nt/messagebox.h"
|
||||
#include "libc/nt/struct/msg.h"
|
||||
#include "libc/nt/struct/wndclass.h"
|
||||
#include "libc/nt/windows.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* @fileoverview GUI Example
|
||||
*
|
||||
* Cosmopolitan has had a razor sharp focus on making sockets and stdio
|
||||
* work well across platforms. When you call a function like read(), it
|
||||
* will just work on platforms like Windows too. In order to do that we
|
||||
* need to support the WIN32 API, which you can use, but please note it
|
||||
* isn't polyfilled on other platforms in the same way as POSIX APIs.
|
||||
*/
|
||||
|
||||
static const char16_t kClassName[] = u"cosmopolitan";
|
||||
|
||||
static int64_t WindowProc(int64_t hwnd, uint32_t uMsg, uint64_t wParam,
|
||||
int64_t lParam) {
|
||||
switch (uMsg) {
|
||||
case kNtWmDestroy:
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
default:
|
||||
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
}
|
||||
|
||||
static void Gui(void) {
|
||||
int64_t h;
|
||||
struct NtMsg msg;
|
||||
struct NtWndClass wc;
|
||||
memset(&wc, 0, sizeof(wc));
|
||||
wc.lpfnWndProc = NT2SYSV(WindowProc);
|
||||
wc.hInstance = GetModuleHandle(NULL);
|
||||
wc.lpszClassName = kClassName;
|
||||
RegisterClass(&wc);
|
||||
h = CreateWindowEx(0, kClassName, u"Hello Cosmopolitan",
|
||||
kNtWsOverlappedwindow, kNtCwUsedefault, kNtCwUsedefault,
|
||||
kNtCwUsedefault, kNtCwUsedefault, 0, 0, wc.hInstance, 0);
|
||||
ShowWindow(h, kNtSwNormal);
|
||||
/*
|
||||
* NOTE: Cosmopolitan linker script is hard-coded to change the
|
||||
* subsystem from CUI to GUI when GetMessage() is linked.
|
||||
*/
|
||||
while (GetMessage(&msg, 0, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
return MessageBox(0, u"hello world", u"cosmopolitan", kNtMbOk) ? 0 : 1;
|
||||
if (!IsWindows()) {
|
||||
fputs("Sorry! This GUI demo only runs on Windows\n", stderr);
|
||||
fputs("https://github.com/jart/cosmopolitan/issues/57\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
Gui();
|
||||
}
|
||||
@@ -10,13 +10,6 @@
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
int main() {
|
||||
/*
|
||||
* Cosmopolitan's "Hello World" demonstrates a best practice.
|
||||
*
|
||||
* Since we conditionally link heavyweight features based on which
|
||||
* characters are present in the format string, it's a good idea to
|
||||
* have that string consist solely of directives.
|
||||
*/
|
||||
printf("%s\n", "hello world");
|
||||
return 0;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
NativePrint('Hello world!\n');
|
||||
NativePrint('2+3=' + NativeAdd(2, 3) + '\n');
|
||||
+2
-14
@@ -9,20 +9,8 @@
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
|
||||
#define kMessage "hello \e[1mworld\e[0m\r\n"
|
||||
|
||||
int main() {
|
||||
/*
|
||||
* Cosmopolitan "Hello World" using system calls.
|
||||
*
|
||||
* Another Cosmopolitan best practice is to use the standard symbolic
|
||||
* names for file descriptors 0, 1, and 2. This is a good idea because
|
||||
* on Windows the numbers are actually different. Because Cosmopolitan
|
||||
* is a zero-emulation library, we address that problem by turning
|
||||
* traditional #define's into variables, which the runtime determines
|
||||
* automatically.
|
||||
*/
|
||||
return write(STDOUT_FILENO, kMessage, strlen(kMessage)) != -1 ? 0 : 1;
|
||||
write(1, "hello world\n", 12);
|
||||
return 0;
|
||||
}
|
||||
+2
-5
@@ -8,12 +8,9 @@
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
int main() {
|
||||
dprintf(STDOUT_FILENO, "%s\n", gc(xasprintf("%'s", "(╯°□°)╯︵' ┻━┻")));
|
||||
printf("%s \n", "hello world");
|
||||
return errno;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/errno.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
int main() {
|
||||
printf("%s \n", "hello world");
|
||||
return errno;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "third_party/duktape/duktape.h"
|
||||
|
||||
STATIC_YOINK("zip_uri_support");
|
||||
|
||||
static duk_ret_t NativePrint(duk_context *ctx) {
|
||||
duk_push_string(ctx, " ");
|
||||
duk_insert(ctx, 0);
|
||||
duk_join(ctx, duk_get_top(ctx) - 1);
|
||||
fputs(duk_safe_to_string(ctx, -1), stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static duk_ret_t NativeAdd(duk_context *ctx) {
|
||||
int i, n;
|
||||
double r;
|
||||
n = duk_get_top(ctx);
|
||||
for (r = i = 0; i < n; i++) r += duk_to_number(ctx, i);
|
||||
duk_push_number(ctx, r);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int fd;
|
||||
struct stat st;
|
||||
const char *code;
|
||||
duk_context *ctx;
|
||||
ctx = duk_create_heap_default();
|
||||
duk_push_c_function(ctx, NativePrint, DUK_VARARGS);
|
||||
duk_put_global_string(ctx, "NativePrint");
|
||||
duk_push_c_function(ctx, NativeAdd, DUK_VARARGS);
|
||||
duk_put_global_string(ctx, "NativeAdd");
|
||||
|
||||
CHECK_NE(-1, (fd = open("zip:examples/hello.js", O_RDONLY)));
|
||||
CHECK_NE(-1, fstat(fd, &st));
|
||||
CHECK_NOTNULL((code = gc(malloc(st.st_size))));
|
||||
CHECK_EQ(st.st_size, read(fd, code, st.st_size));
|
||||
CHECK_NE(-1, close(fd));
|
||||
|
||||
duk_eval_string(ctx, code);
|
||||
duk_pop(ctx);
|
||||
duk_destroy_heap(ctx);
|
||||
return 0;
|
||||
}
|
||||
@@ -7,12 +7,24 @@
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "third_party/lua/lauxlib.h"
|
||||
#include "third_party/lua/lualib.h"
|
||||
|
||||
int NativeAdd(lua_State *L) {
|
||||
lua_Number x, y;
|
||||
x = luaL_checknumber(L, 1);
|
||||
y = luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, x + y);
|
||||
return 1; /* number of results */
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int pid;
|
||||
pid = fork();
|
||||
fprintf(stderr, "fork returned %d\n", pid);
|
||||
lua_State *L;
|
||||
L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
lua_pushcfunction(L, NativeAdd);
|
||||
lua_setglobal(L, "NativeAdd");
|
||||
luaL_dofile(L, "zip:examples/hellolua.lua");
|
||||
lua_close(L);
|
||||
return 0;
|
||||
}
|
||||
Loaded 100 of 2735 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user