mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-28 05:20:28 +00:00
Get Cosmopolitan into releasable state
A new rollup tool now exists for flattening out the headers in a way that works better for our purposes than cpp. A lot of the API clutter has been removed. APIs that aren't a sure thing in terms of general recommendation are now marked internal. There's now a smoke test for the amalgamation archive and gigantic header file. So we can now guarantee you can use this project on the easiest difficulty setting without the gigantic repository. A website is being created, which is currently a work in progress: https://justine.storage.googleapis.com/cosmopolitan/index.html
This commit is contained in:
parent
dba7552c1e
commit
ea0b5d9d1c
775 changed files with 6864 additions and 3963 deletions
|
@ -3,13 +3,11 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
enum CpuCacheType {
|
||||
kCpuCacheTypeData = 1,
|
||||
kCpuCacheTypeInstruction,
|
||||
kCpuCacheTypeUnified,
|
||||
};
|
||||
#define kCpuCacheTypeData 1
|
||||
#define kCpuCacheTypeInstruction 2
|
||||
#define kCpuCacheTypeUnified 3
|
||||
|
||||
unsigned getcachesize(enum CpuCacheType, int);
|
||||
unsigned getcachesize(int, int);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/nexgen32e/crc32.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
|
||||
|
|
|
@ -26,10 +26,10 @@ void djbsort$avx2(int32_t *, long);
|
|||
/**
|
||||
* D.J. Bernstein's outrageously fast integer sorting algorithm.
|
||||
*/
|
||||
void djbsort(size_t n, int32_t a[n]) {
|
||||
void djbsort(int32_t *a, size_t n) {
|
||||
if (X86_HAVE(AVX2)) {
|
||||
djbsort$avx2(a, n);
|
||||
} else {
|
||||
insertionsort(n, a);
|
||||
insertionsort(a, n);
|
||||
}
|
||||
}
|
||||
|
|
12
libc/nexgen32e/ffs.h
Normal file
12
libc/nexgen32e/ffs.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_FFS_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_FFS_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
int ffs(int) pureconst;
|
||||
int ffsl(long int) pureconst;
|
||||
int ffsll(long long int) pureconst;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_FFS_H_ */
|
|
@ -1,29 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_FPU_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_FPU_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/**
|
||||
* Saves FPU state.
|
||||
* @see X86_HAVE(FXSR)
|
||||
*/
|
||||
#define FXSAVE(STATE) \
|
||||
asm volatile("fxsave\t%0" \
|
||||
: "=m"(STATE) \
|
||||
: /* x87/sse */ \
|
||||
: "memory")
|
||||
|
||||
/**
|
||||
* Restores FPU state.
|
||||
* @see X86_HAVE(FXSR)
|
||||
*/
|
||||
#define FXRSTOR(STATE) \
|
||||
asm volatile("fxrstor\t%0" \
|
||||
: /* x87/sse */ \
|
||||
: "m"(STATE) \
|
||||
: "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", \
|
||||
"xmm7", "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", \
|
||||
"xmm14", "xmm15", "st", "st(1)", "st(2)", "st(3)", "st(4)", \
|
||||
"st(5)", "st(6)", "st(7)", "memory", "fpsr", "fpcr")
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_FPU_H_ */
|
|
@ -33,10 +33,9 @@
|
|||
/ @param rax,rdx,xmm0,xmm1,st0,st1 is return value
|
||||
/ @see test/libc/runtime/gc_test.c
|
||||
/ <LIMBO>
|
||||
CollectGarbage:
|
||||
decq g_garbage(%rip)
|
||||
mov g_garbage(%rip),%r8
|
||||
mov g_garbage+16(%rip),%r9
|
||||
__gc: decq __garbage(%rip)
|
||||
mov __garbage(%rip),%r8
|
||||
mov __garbage+16(%rip),%r9
|
||||
js 9f
|
||||
shl $5,%r8
|
||||
lea (%r9,%r8),%r8
|
||||
|
@ -59,12 +58,12 @@ CollectGarbage:
|
|||
leave
|
||||
ret
|
||||
9: call abort
|
||||
.endfn CollectGarbage,globl,hidden
|
||||
.endfn __gc,globl,hidden
|
||||
.source __FILE__
|
||||
|
||||
.bss
|
||||
.align 8
|
||||
g_garbage:
|
||||
__garbage:
|
||||
.quad 0 # garbage.i
|
||||
.quad 0 # garbage.n
|
||||
.quad 0 # garbage.p
|
||||
|
@ -74,10 +73,10 @@ g_garbage:
|
|||
.quad 0 # garbage.p[𝑖].arg
|
||||
.quad 0 # garbage.p[𝑖].ret
|
||||
.endr
|
||||
.endobj g_garbage,globl,hidden
|
||||
.endobj __garbage,globl,hidden
|
||||
.previous
|
||||
|
||||
.init.start 100,_init_garbage
|
||||
movb $INITIAL_CAPACITY,g_garbage+8(%rip)
|
||||
movl $g_garbage+24,g_garbage+16(%rip)
|
||||
movb $INITIAL_CAPACITY,__garbage+8(%rip)
|
||||
movl $__garbage+24,__garbage+16(%rip)
|
||||
.init.end 100,_init_garbage
|
||||
|
|
|
@ -14,9 +14,9 @@ struct Garbages {
|
|||
} * p;
|
||||
};
|
||||
|
||||
hidden extern struct Garbages g_garbage;
|
||||
hidden extern struct Garbages __garbage;
|
||||
|
||||
int64_t CollectGarbage(void) hidden;
|
||||
int64_t __gc(void) hidden;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
@ -33,8 +33,8 @@
|
|||
gclongjmp:
|
||||
.leafprologue
|
||||
.profilable
|
||||
.weak g_garbage
|
||||
lea g_garbage(%rip),%r12
|
||||
.weak __garbage
|
||||
lea __garbage(%rip),%r12
|
||||
test %r12,%r12
|
||||
jnz .L.unwind.destructors
|
||||
0: jmp longjmp
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
* Sorts array of signed 32-bit integers.
|
||||
* @see djbsort()
|
||||
*/
|
||||
textreal void insertionsort(size_t n, int32_t a[n]) {
|
||||
textreal void insertionsort(int32_t *a, size_t n) {
|
||||
int t;
|
||||
unsigned i, j;
|
||||
for (i = 1; i < n; ++i) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_LZ4_H_
|
||||
#define COSMOPOLITAN_LIBC_LZ4_H_
|
||||
#include "libc/bits/bits.h"
|
||||
#if 0
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § lz4 ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│─╝
|
||||
|
@ -10,39 +9,36 @@
|
|||
@see https://github.com/lz4/lz4/blob/master/doc/lz4_Frame_format.md
|
||||
@see https://github.com/lz4/lz4/blob/master/doc/lz4_Block_format.md
|
||||
@see http://ticki.github.io/blog/how-lz4-works/ */
|
||||
#endif
|
||||
|
||||
#define LZ4_EOF 0
|
||||
#define LZ4_VERSION 1
|
||||
#define LZ4_MAGICNUMBER 0x184D2204
|
||||
#define LZ4_SKIPPABLE0 0x184D2A50
|
||||
#define LZ4_SKIPPABLEMASK 0xFFFFFFF0
|
||||
#define LZ4_MAXHEADERSIZE (MAGICNUMBER_SIZE + 2 + 8 + 4 + 1)
|
||||
#define LZ4_BLOCKMAXSIZE_64KB 4
|
||||
#define LZ4_EOF 0
|
||||
#define LZ4_VERSION 1
|
||||
#define LZ4_MAGICNUMBER 0x184D2204
|
||||
#define LZ4_SKIPPABLE0 0x184D2A50
|
||||
#define LZ4_SKIPPABLEMASK 0xFFFFFFF0
|
||||
#define LZ4_MAXHEADERSIZE (MAGICNUMBER_SIZE + 2 + 8 + 4 + 1)
|
||||
#define LZ4_BLOCKMAXSIZE_64KB 4
|
||||
#define LZ4_BLOCKMAXSIZE_256KB 5
|
||||
#define LZ4_BLOCKMAXSIZE_1MB 6
|
||||
#define LZ4_BLOCKMAXSIZE_4MB 7
|
||||
#define LZ4_BLOCKMAXSIZE_1MB 6
|
||||
#define LZ4_BLOCKMAXSIZE_4MB 7
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
#if 0
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § lz4 » frames ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
#endif
|
||||
|
||||
#define LZ4_MAGIC(FRAME) read32le(FRAME)
|
||||
#define LZ4_FRAME_VERSION(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 6) & 0b11)
|
||||
#define LZ4_FRAME_BLOCKINDEPENDENCE(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 5) & 1)
|
||||
#define LZ4_FRAME_BLOCKCHECKSUMFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 4) & 1)
|
||||
#define LZ4_MAGIC(FRAME) read32le(FRAME)
|
||||
#define LZ4_FRAME_VERSION(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 6) & 0b11)
|
||||
#define LZ4_FRAME_BLOCKINDEPENDENCE(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 5) & 1)
|
||||
#define LZ4_FRAME_BLOCKCHECKSUMFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 4) & 1)
|
||||
#define LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 3) & 1)
|
||||
#define LZ4_FRAME_BLOCKCONTENTCHECKSUMFLAG(FRAME) \
|
||||
((_LZ4_FRAME_FLG(FRAME) >> 2) & 1)
|
||||
#define LZ4_FRAME_DICTIONARYIDFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 0) & 1)
|
||||
#define LZ4_FRAME_BLOCKMAXSIZE(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 4) & 0b111)
|
||||
#define LZ4_FRAME_RESERVED1(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 1) & 1)
|
||||
#define LZ4_FRAME_RESERVED2(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 7) & 1)
|
||||
#define LZ4_FRAME_RESERVED3(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 0) & 0b1111)
|
||||
#define LZ4_FRAME_BLOCKMAXSIZE(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 4) & 0b111)
|
||||
#define LZ4_FRAME_RESERVED1(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 1) & 1)
|
||||
#define LZ4_FRAME_RESERVED2(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 7) & 1)
|
||||
#define LZ4_FRAME_RESERVED3(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 0) & 0b1111)
|
||||
#define LZ4_FRAME_BLOCKCONTENTSIZE(FRAME) \
|
||||
(LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ? read64le((FRAME) + 4 + 1 + 1) : 0)
|
||||
#define LZ4_FRAME_DICTIONARYID(FRAME) \
|
||||
|
@ -57,17 +53,15 @@ COSMOPOLITAN_C_START_
|
|||
(4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \
|
||||
4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME) + 1)
|
||||
#define _LZ4_FRAME_FLG(FRAME) (*((FRAME) + 4))
|
||||
#define _LZ4_FRAME_BD(FRAME) (*((FRAME) + 5))
|
||||
#define _LZ4_FRAME_BD(FRAME) (*((FRAME) + 5))
|
||||
|
||||
#if 0
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § lz4 » blocks ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
#endif
|
||||
|
||||
#define LZ4_BLOCK_DATA(block) (block + sizeof(uint32_t))
|
||||
#define LZ4_BLOCK_DATASIZE(block) (read32le(block) & 0x7fffffff)
|
||||
#define LZ4_BLOCK_ISEOF(block) (read32le(block) == LZ4_EOF)
|
||||
#define LZ4_BLOCK_DATA(block) (block + sizeof(uint32_t))
|
||||
#define LZ4_BLOCK_DATASIZE(block) (read32le(block) & 0x7fffffff)
|
||||
#define LZ4_BLOCK_ISEOF(block) (read32le(block) == LZ4_EOF)
|
||||
#define LZ4_BLOCK_ISCOMPRESSED(block) ((read32le(block) & 0x80000000) == 0)
|
||||
#define LZ4_BLOCK_SIZE(frame, block) \
|
||||
(sizeof(uint32_t) + LZ4_BLOCK_DATASIZE(block) + \
|
||||
|
|
|
@ -1,22 +1,3 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/macros.h"
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ MemCpy: .leafprologue
|
|||
.L1: mov (%rsi),%cl
|
||||
mov %cl,(%rdi)
|
||||
jmp .L0
|
||||
.Lerms: cmp $4*1024*1024,%rdx
|
||||
.Lerms: cmp $4*1024*1024,%rdx # TODO: getcachesize()
|
||||
ja .Lnts
|
||||
push %rdi
|
||||
push %rsi
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
COSMOPOLITAN_C_START_
|
||||
|
||||
void imapxlatab(void *);
|
||||
void insertionsort(size_t n, int32_t[n]);
|
||||
void *doublebytes(size_t, void *);
|
||||
void insertionsort(int32_t *, size_t);
|
||||
|
||||
int64_t div10int64(int64_t) libcesque pureconst;
|
||||
int64_t div100int64(int64_t) libcesque pureconst;
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
/ @param %rax is function address
|
||||
/ @param %rcx,%rdx,%r8,%r9
|
||||
/ @return %rax,%xmm0
|
||||
/ @note this is so much slower than sysv2nt()
|
||||
/ @note slower than __sysv2nt
|
||||
/ @see NT2SYSV() macro
|
||||
__nt2sysv:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
|
|
14
libc/nexgen32e/nt2sysv.h
Normal file
14
libc/nexgen32e/nt2sysv.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_NT2SYSV_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_NT2SYSV_H_
|
||||
#include "libc/nexgen32e/trampoline.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/**
|
||||
* Creates function to thunk FUNCTION from MSX64 to System V ABI.
|
||||
*
|
||||
* This macro should be used when specifying callbacks in the WIN32 API.
|
||||
*/
|
||||
#define NT2SYSV(FUNCTION) TRAMPOLINE(FUNCTION, __nt2sysv)
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_NT2SYSV_H_ */
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/macros.h"
|
||||
#include "libc/nexgen32e/uart.h"
|
||||
#include "libc/nexgen32e/uart.internal.h"
|
||||
#include "libc/notice.inc"
|
||||
.real
|
||||
.code16 # ∩ .code32 ∩ .code64
|
||||
|
|
20
libc/nexgen32e/trampoline.h
Normal file
20
libc/nexgen32e/trampoline.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_TRAMPOLINE_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_TRAMPOLINE_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
#define TRAMPOLINE(FUNCTION, THUNK) \
|
||||
({ \
|
||||
typeof(FUNCTION) *Tramp; \
|
||||
asm(".pushsection .text.trampoline\n" \
|
||||
"183:\n\t" \
|
||||
"mov\t%1,%%eax\n\t" \
|
||||
"jmp\t" #THUNK "\n\t" \
|
||||
".popsection\n\t" \
|
||||
"mov\t$183b,%k0" \
|
||||
: "=r"(Tramp) \
|
||||
: "i"(FUNCTION)); \
|
||||
Tramp; \
|
||||
})
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_TRAMPOLINE_H_ */
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/macros.h"
|
||||
#include "libc/nexgen32e/vidya.h"
|
||||
#include "libc/nexgen32e/vidya.internal.h"
|
||||
#include "libc/notice.inc"
|
||||
.real
|
||||
.code16 # ∩ .code32 ∩ .code64
|
||||
|
|
|
@ -1,130 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╠──────────────────────────────────────────────────────────────────────────────╣
|
||||
│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░█▀█░█▀█░▀█▀░█░█░█▀█░█░░░█░░░█░█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░█▀█░█░▄░░█░░█░█░█▀█░█░░░█░░░▀█▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░▀░▀░▀▀▀░░▀░░▀▀▀░▀░▀░▀▀▀░▀▀▀░░▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░█▀█░█▀█░█▀█░▀█▀░█▀█░█▀█░█░░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░█▀▀░█ █░██▀░░█░░█▀█░█▀█░█░░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░▀░░░▀▀▀░▀░▀░░▀░░▀░▀░▀▀▀░▀▀▀░▀▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░█▀▀░█░█░█▀▀░█▀█░█░█░▀█▀░█▀█░█▀█░█░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░▄▄░░░▐█░░│
|
||||
│░░░░░░░█▀▀░▄▀▄░█▀▀░█░▄░█░█░░█░░█▀█░█▀█░█░░█▀▀░░░░░░░░░░░░▄▄▄░░░▄██▄░░█▀░░░█░▄░│
|
||||
│░░░░░░░▀▀▀░▀░▀░▀▀▀░▀▀▀░▀▀▀░░▀░░▀░▀░▀▀▀░▀▀░▀▀▀░░░░░░░░░░▄██▀█▌░██▄▄░░▐█▀▄░▐█▀░░│
|
||||
│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▐█▀▀▌░░░▄▀▌░▌░█░▌░░▌░▌░░│
|
||||
╠──────────────────────────────────────────────────────▌▀▄─▐──▀▄─▐▄─▐▄▐▄─▐▄─▐▄─│
|
||||
│ αcτµαlly pδrταblε εxεcµταblε § pc display helpers │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_VIDYA_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_VIDYA_H_
|
||||
|
||||
/**
|
||||
* @fileoverview PC Display Helpers.
|
||||
*
|
||||
* These functions provide the baseline of PC graphics & teletype
|
||||
* emulation support that doesn't require switching context or cpu mode.
|
||||
*
|
||||
* @see https://youtu.be/yHXx3orN35Y
|
||||
* @see https://youtu.be/H1p1im_2uf4
|
||||
* @see Google's SGABIOS which logs MDA/CGA displays to UART as ASCII
|
||||
* @mode long,legacy,real
|
||||
*/
|
||||
|
||||
#define VIDYA_ROWS 25
|
||||
#define VIDYA_COLUMNS 80
|
||||
#define VIDYA_SIZE (VIDYA_ROWS * VIDYA_COLUMNS * 2)
|
||||
#define VIDYA_MODE_MDA 7
|
||||
#define VIDYA_MODE_CGA 3
|
||||
#define VIDYA_ADDR_MDA 0xb0000
|
||||
#define VIDYA_ADDR_CGA 0xb8000
|
||||
#define VIDYA_ATTR_NORMAL 0x07 /* cozy default for both mda and cga */
|
||||
#define VIDYA_REWIND ~0x7fff /* derived from mode addr min. lzcnt */
|
||||
#define VIDYA_SERVICE 0x10
|
||||
#define VIDYA_SET_MODE 0x0003
|
||||
#define VIDYA_SET_CURSOR 0x0100
|
||||
#define VIDYA_SET_CURSOR_NONE 0x2000
|
||||
#define VIDYA_SET_BLINKING 0x1003
|
||||
#define VIDYA_SET_BLINKING_NONE 0x0000
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
enum VidyaMode {
|
||||
kVidyaModeMda = VIDYA_MODE_MDA,
|
||||
kVidyaModeCga = VIDYA_MODE_CGA
|
||||
};
|
||||
|
||||
enum VidyaColor {
|
||||
kVidyaColorBlack = 0x0,
|
||||
kVidyaColorBlue = 0x1,
|
||||
kVidyaColorGreen = 0x2,
|
||||
kVidyaColorCyan = 0x3,
|
||||
kVidyaColorRed = 0x4,
|
||||
kVidyaColorMagenta = 0x5,
|
||||
kVidyaColorBrown = 0x6,
|
||||
kVidyaColorLightGray = 0x7,
|
||||
kVidyaColorDarkGray = 0x8,
|
||||
kVidyaColorLightBlue = 0x9,
|
||||
kVidyaColorLightGreen = 0xa,
|
||||
kVidyaColorLightCyan = 0xb,
|
||||
kVidyaColorLightRed = 0xc,
|
||||
kVidyaColorLightMagenta = 0xd,
|
||||
kVidyaColorYellow = 0xe,
|
||||
kVidyaColorWhite = 0xf
|
||||
};
|
||||
|
||||
struct thatispacked VidyaCell {
|
||||
unsigned glyph : 8; /* IBM Code Page 437 */
|
||||
union VidyaAttr {
|
||||
enum {
|
||||
kVidyaAttrBlank = 0x00,
|
||||
kVidyaAttrNormal = VIDYA_ATTR_NORMAL,
|
||||
kVidyaAttrMdaFlipped = 0x70,
|
||||
kVidyaAttrMdaFlippedFaded = 0x78,
|
||||
kVidyaAttrMdaFlippedIntense = 0xf0,
|
||||
kVidyaAttrMdaFlippedFadedIntense = 0xf8
|
||||
} preset : 8;
|
||||
struct VidyaTextDecoration { /* MDA Only */
|
||||
unsigned underline : 1;
|
||||
unsigned __ignore1 : 1;
|
||||
unsigned bold : 1;
|
||||
unsigned __ignore2 : 3;
|
||||
unsigned intense : 1;
|
||||
} decoration;
|
||||
struct { /* CGA Only */
|
||||
enum VidyaColor fg : 4;
|
||||
enum VidyaColor bg : 4;
|
||||
} color;
|
||||
} attr;
|
||||
};
|
||||
|
||||
typedef union VidyaAttr VidyaAttr;
|
||||
typedef struct VidyaCell VidyaCell;
|
||||
typedef struct VidyaCell VidyaPage[VIDYA_ROWS][VIDYA_COLUMNS];
|
||||
|
||||
__far VidyaPage *vinit(enum VidyaMode mode);
|
||||
__far VidyaPage *vcls(__far VidyaCell *pos);
|
||||
__far VidyaCell *vputc(__far VidyaCell *pos, int c);
|
||||
__far VidyaCell *vputs(__far VidyaCell *pos, const char *str);
|
||||
__far VidyaCell *vtput(__far VidyaCell *pos, const void *data, size_t size);
|
||||
__far VidyaCell *vscroll(__far VidyaCell *pos, size_t bytes);
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_VIDYA_H_ */
|
83
libc/nexgen32e/vidya.internal.h
Normal file
83
libc/nexgen32e/vidya.internal.h
Normal file
|
@ -0,0 +1,83 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_VIDYA_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_VIDYA_H_
|
||||
|
||||
#define VIDYA_ROWS 25
|
||||
#define VIDYA_COLUMNS 80
|
||||
#define VIDYA_SIZE (VIDYA_ROWS * VIDYA_COLUMNS * 2)
|
||||
#define VIDYA_MODE_MDA 7
|
||||
#define VIDYA_MODE_CGA 3
|
||||
#define VIDYA_ADDR_MDA 0xb0000
|
||||
#define VIDYA_ADDR_CGA 0xb8000
|
||||
#define VIDYA_ATTR_NORMAL 0x07 /* cozy default for both mda and cga */
|
||||
#define VIDYA_REWIND ~0x7fff /* derived from mode addr min. lzcnt */
|
||||
#define VIDYA_SERVICE 0x10
|
||||
#define VIDYA_SET_MODE 0x0003
|
||||
#define VIDYA_SET_CURSOR 0x0100
|
||||
#define VIDYA_SET_CURSOR_NONE 0x2000
|
||||
#define VIDYA_SET_BLINKING 0x1003
|
||||
#define VIDYA_SET_BLINKING_NONE 0x0000
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
enum VidyaMode {
|
||||
kVidyaModeMda = VIDYA_MODE_MDA,
|
||||
kVidyaModeCga = VIDYA_MODE_CGA
|
||||
};
|
||||
|
||||
enum VidyaColor {
|
||||
kVidyaColorBlack = 0x0,
|
||||
kVidyaColorBlue = 0x1,
|
||||
kVidyaColorGreen = 0x2,
|
||||
kVidyaColorCyan = 0x3,
|
||||
kVidyaColorRed = 0x4,
|
||||
kVidyaColorMagenta = 0x5,
|
||||
kVidyaColorBrown = 0x6,
|
||||
kVidyaColorLightGray = 0x7,
|
||||
kVidyaColorDarkGray = 0x8,
|
||||
kVidyaColorLightBlue = 0x9,
|
||||
kVidyaColorLightGreen = 0xa,
|
||||
kVidyaColorLightCyan = 0xb,
|
||||
kVidyaColorLightRed = 0xc,
|
||||
kVidyaColorLightMagenta = 0xd,
|
||||
kVidyaColorYellow = 0xe,
|
||||
kVidyaColorWhite = 0xf
|
||||
};
|
||||
|
||||
struct thatispacked VidyaCell {
|
||||
unsigned glyph : 8; /* IBM Code Page 437 */
|
||||
union VidyaAttr {
|
||||
enum {
|
||||
kVidyaAttrBlank = 0x00,
|
||||
kVidyaAttrNormal = VIDYA_ATTR_NORMAL,
|
||||
kVidyaAttrMdaFlipped = 0x70,
|
||||
kVidyaAttrMdaFlippedFaded = 0x78,
|
||||
kVidyaAttrMdaFlippedIntense = 0xf0,
|
||||
kVidyaAttrMdaFlippedFadedIntense = 0xf8
|
||||
} preset : 8;
|
||||
struct VidyaTextDecoration { /* MDA Only */
|
||||
unsigned underline : 1;
|
||||
unsigned __ignore1 : 1;
|
||||
unsigned bold : 1;
|
||||
unsigned __ignore2 : 3;
|
||||
unsigned intense : 1;
|
||||
} decoration;
|
||||
struct { /* CGA Only */
|
||||
enum VidyaColor fg : 4;
|
||||
enum VidyaColor bg : 4;
|
||||
} color;
|
||||
} attr;
|
||||
};
|
||||
|
||||
typedef union VidyaAttr VidyaAttr;
|
||||
typedef struct VidyaCell VidyaCell;
|
||||
typedef struct VidyaCell VidyaPage[VIDYA_ROWS][VIDYA_COLUMNS];
|
||||
|
||||
__far VidyaPage *vinit(enum VidyaMode mode);
|
||||
__far VidyaPage *vcls(__far VidyaCell *pos);
|
||||
__far VidyaCell *vputc(__far VidyaCell *pos, int c);
|
||||
__far VidyaCell *vputs(__far VidyaCell *pos, const char *str);
|
||||
__far VidyaCell *vtput(__far VidyaCell *pos, const void *data, size_t size);
|
||||
__far VidyaCell *vscroll(__far VidyaCell *pos, size_t bytes);
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_VIDYA_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue