mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-26 04:20:30 +00:00
Make more improvements
This change includes many bug fixes, for the NT polyfills, strings, memory, boot, and math libraries which were discovered by adding more tools for recreational programming, such as PC emulation. Lemon has also been vendored because it works so well at parsing languages.
This commit is contained in:
parent
416fd86676
commit
23d333c090
201 changed files with 14558 additions and 3082 deletions
|
@ -49,14 +49,15 @@ o/$(MODE)/tool/build/emubin/%.bin.dbg: \
|
|||
$(TOOL_BUILD_EMUBIN_A).pkg
|
||||
@$(ELFLINK) -e emucrt -z max-page-size=0x10
|
||||
|
||||
o/$(MODE)/tool/build/emubin/real/spiral.o: tool/build/emubin/real/spiral.c
|
||||
@$(MKDIR) $(@D)
|
||||
/opt/cross/bin/i486-linux-musl-gcc -nostdlib -nostdinc -m16 -Os -g -c -o $@ $<
|
||||
o/tiny/tool/build/emubin/spiral.bin.dbg: \
|
||||
$(TOOL_BUILD_EMUBIN_DEPS) \
|
||||
o/tiny/tool/build/emubin/spiral.real.o
|
||||
@$(ELFLINK) -z max-page-size=0x10 -T tool/build/emucrt/real.lds
|
||||
|
||||
o/$(MODE)/tool/build/emubin/real/spiral.bin: o/$(MODE)/tool/build/emubin/real/spiral.o
|
||||
/opt/cross/bin/i486-linux-musl-ld -static -nostdlib --oformat=binary -T tool/build/emubin/real/spiral.lds -o $@ $^
|
||||
|
||||
o/$(MODE)/tool/build/emubin/hug.o: OVERRIDE_CFLAGS += -ffast-math
|
||||
o/tiny/tool/build/emubin/mdatest.bin.dbg: \
|
||||
$(TOOL_BUILD_EMUBIN_DEPS) \
|
||||
o/tiny/tool/build/emubin/mdatest.real.o
|
||||
@$(ELFLINK) -z max-page-size=0x10 -T tool/build/emucrt/real.lds
|
||||
|
||||
.PHONY: o/$(MODE)/tool/build/emubin
|
||||
o/$(MODE)/tool/build/emubin: \
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode: ld-script; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-│
|
||||
│vi: set et sts=2 tw=2 fenc=utf-8 :vi│
|
||||
/*-*- 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 │
|
||||
│ │
|
||||
|
@ -17,21 +17,28 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "tool/build/emubin/poke.h"
|
||||
#include "tool/build/emubin/real.h"
|
||||
|
||||
ENTRY(_start)
|
||||
/*
|
||||
m=tiny; make -j12 MODE=$m o/$m/tool/build/{tinyemu,emulator}.com \
|
||||
o/$m/tool/build/emubin/mdatest.bin && o/$m/tool/build/emulator.com \
|
||||
-rt o/$m/tool/build/emubin/mdatest.bin
|
||||
*/
|
||||
|
||||
SECTIONS {
|
||||
|
||||
.text 0x7c00 : {
|
||||
*(.start)
|
||||
*(.text .text.*)
|
||||
*(.rodata .rodata.*)
|
||||
*(.data .data.*)
|
||||
*(.bss .bss.*)
|
||||
*(COMMON)
|
||||
}
|
||||
|
||||
/DISCARD/ : {
|
||||
*(.*)
|
||||
static void MdaTest(uint16_t p[25][80]) {
|
||||
int i, y, x;
|
||||
for (i = 0; i < 256; ++i) {
|
||||
y = i / 16;
|
||||
x = i % 16 * 3;
|
||||
POKE(p[y][x + 0], i << 8 | "0123456789abcdef"[(i & 0xf0) >> 4]);
|
||||
POKE(p[y][x + 1], i << 8 | "0123456789abcdef"[(i & 0x0f) >> 0]);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
SetVideoMode(7);
|
||||
SetEs(0xb0000 >> 4);
|
||||
MdaTest((void *)0);
|
||||
for (;;) asm("pause");
|
||||
}
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "tool/build/emubin/metalsha256.h"
|
||||
|
||||
#define DISINGENUOUS /* 100 million NOPs is still 100 MIPS lool */
|
||||
//#define DISINGENUOUS /* 100 million NOPs is still 100 MIPS lool */
|
||||
|
||||
static void Print(uint8_t c) {
|
||||
asm volatile("out\t%0,$0xE9" : /* no outputs */ : "a"(c) : "memory");
|
||||
|
|
11
tool/build/emubin/poke.h
Normal file
11
tool/build/emubin/poke.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef COSMOPOLITAN_TOOL_BUILD_EMUBIN_POKE_H_
|
||||
#define COSMOPOLITAN_TOOL_BUILD_EMUBIN_POKE_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define POKE(MEM, VAL) \
|
||||
asm volatile("mov\t%1,%%es:%0" : "=m"(MEM) : "Qi"((typeof(MEM))(VAL)))
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_TOOL_BUILD_EMUBIN_POKE_H_ */
|
26
tool/build/emubin/real.h
Normal file
26
tool/build/emubin/real.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef COSMOPOLITAN_TOOL_BUILD_EMUBIN_REAL_H_
|
||||
#define COSMOPOLITAN_TOOL_BUILD_EMUBIN_REAL_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
asm(".pushsection .start,\"ax\",@progbits\n\t"
|
||||
".globl\t_start\n"
|
||||
"_start:\n\t"
|
||||
"jmp\t1f\n1:\t"
|
||||
"call\tmain\n\t"
|
||||
"nop\n\t"
|
||||
".popsection");
|
||||
|
||||
forceinline void SetEs(int base) {
|
||||
asm volatile("mov%z0\t%0,%%es" : /* no outputs */ : "r"(base));
|
||||
}
|
||||
|
||||
forceinline void SetVideoMode(int mode) {
|
||||
asm volatile("int\t$0x10"
|
||||
: /* no outputs */
|
||||
: "a"(mode));
|
||||
}
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_TOOL_BUILD_EMUBIN_REAL_H_ */
|
|
@ -17,6 +17,8 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "tool/build/emubin/poke.h"
|
||||
#include "tool/build/emubin/real.h"
|
||||
|
||||
#define signbit(x) __builtin_signbit(x)
|
||||
|
||||
|
@ -38,45 +40,49 @@ static const unsigned char kBlocks[] = {
|
|||
[0b0001] = 0xdf, // ▀
|
||||
};
|
||||
|
||||
static void *memset(void *di, int al, unsigned long cx) {
|
||||
asm("rep stosb %%al,(%0)"
|
||||
forceinline void *memset(void *di, int al, unsigned long cx) {
|
||||
asm("rep stosb"
|
||||
: "=D"(di), "=c"(cx), "=m"(*(char(*)[cx])di)
|
||||
: "0"(di), "1"(cx), "a"(al));
|
||||
return di;
|
||||
}
|
||||
|
||||
static long double pi(void) {
|
||||
forceinline long double pi(void) {
|
||||
long double x;
|
||||
asm("fldpi" : "=t"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static void sincosl(long double x, long double *sin, long double *cos) {
|
||||
forceinline long double tau(void) {
|
||||
return pi() * 2;
|
||||
}
|
||||
|
||||
forceinline void sincosl(long double x, long double *sin, long double *cos) {
|
||||
asm("fsincos" : "=t"(*sin), "=u"(*cos) : "0"(x));
|
||||
}
|
||||
|
||||
static long double atan2l(long double x, long double y) {
|
||||
forceinline long double atan2l(long double x, long double y) {
|
||||
asm("fpatan" : "+t"(x) : "u"(y) : "st(1)");
|
||||
return x;
|
||||
}
|
||||
|
||||
static long lrintl(long double x) {
|
||||
forceinline long lrintl(long double x) {
|
||||
long i;
|
||||
asm("fistp%z0\t%0" : "=m"(i) : "t"(x) : "st");
|
||||
return i;
|
||||
}
|
||||
|
||||
static long double truncl(long double x) {
|
||||
forceinline long double truncl(long double x) {
|
||||
asm("frndint" : "+t"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static long double fabsl(long double x) {
|
||||
forceinline long double fabsl(long double x) {
|
||||
asm("fabs" : "+t"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
static long lroundl(long double x) {
|
||||
forceinline long lroundl(long double x) {
|
||||
int s = signbit(x);
|
||||
x = truncl(fabsl(x) + .5);
|
||||
if (s) x = -x;
|
||||
|
@ -93,36 +99,40 @@ static void SetFpuControlWord(unsigned short cw) {
|
|||
asm volatile("fldcw\t%0" : /* no outputs */ : "m"(cw));
|
||||
}
|
||||
|
||||
static void InitializeFpu(void) {
|
||||
asm("fninit");
|
||||
}
|
||||
|
||||
static void SetTruncationRounding(void) {
|
||||
SetFpuControlWord(GetFpuControlWord() | 0x0c00);
|
||||
}
|
||||
|
||||
static void spiral(unsigned char p[25][80][2], unsigned char B[25][80]) {
|
||||
static void spiral(unsigned char p[25][80][2], unsigned char B[25][80], int g) {
|
||||
int i, x, y;
|
||||
long double a, b, u, v, h;
|
||||
for (a = b = i = 0; i < 1000; ++i) {
|
||||
sincosl(a, &u, &v);
|
||||
h = atan2l(u, v);
|
||||
h = atan2l(u, v) - .333L * g;
|
||||
x = lroundl(80 + u * b);
|
||||
y = lroundl(25 + v * b * (1. / ((266 / 64.) * (900 / 1600.))));
|
||||
B[y >> 1][x >> 1] |= 1 << ((y & 1) << 1 | (x & 1));
|
||||
p[y >> 1][x >> 1][0] = kBlocks[B[y >> 1][x >> 1]];
|
||||
p[y >> 1][x >> 1][1] = (lrintl((h + pi() * 2) * (8 / (pi() * 2))) & 7) + 8;
|
||||
POKE(p[y >> 1][x >> 1][0], kBlocks[B[y >> 1][x >> 1]]);
|
||||
POKE(p[y >> 1][x >> 1][1], (lrintl((h + tau()) * (8 / tau())) & 7) + 8);
|
||||
a += .05;
|
||||
b += .05;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
asm(".pushsection .start,\"ax\",@progbits\n\t"
|
||||
".globl\t_start\n"
|
||||
"_start:\n\t"
|
||||
"callw\tmain\n\t"
|
||||
".popsection");
|
||||
int g;
|
||||
InitializeFpu();
|
||||
SetTruncationRounding();
|
||||
for (;;) {
|
||||
memset((void *)0x40000, 0, 25 * 80);
|
||||
memset((void *)0xb8000, 0, 25 * 80 * 2);
|
||||
spiral((void *)0xb8000, (void *)0x40000);
|
||||
SetVideoMode(3);
|
||||
for (g = 0;; ++g) {
|
||||
SetEs(0);
|
||||
memset((void *)(0x7c00 + 512), 0, 25 * 80);
|
||||
SetEs(0xb8000 >> 4);
|
||||
memset((void *)0, 0, 25 * 80 * 2);
|
||||
spiral((void *)0, (void *)(0x7c00 + 512), g);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue