mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-20 09:30:31 +00:00
Add pseudoteletypewriter to emulator
https://justine.storage.googleapis.com/emulator628.mp4
This commit is contained in:
parent
e86cff8ba0
commit
5aabacb361
94 changed files with 3245 additions and 2179 deletions
|
@ -23,6 +23,11 @@
|
|||
.source __FILE__
|
||||
|
||||
/ Calls global initialization functions.
|
||||
/
|
||||
/ @param r12 is argc
|
||||
/ @param r13 is argv
|
||||
/ @param r14 is environ
|
||||
/ @param r15 is auxv
|
||||
_construct:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
|
|
|
@ -43,8 +43,8 @@ static struct CxaAtexitBlocks {
|
|||
*
|
||||
* Destructors are called in reverse order. They won't be called if the
|
||||
* program aborts or _exit() is called. Invocations of this function are
|
||||
* usually generated by the C++ compiler. Behavior is limitless if you
|
||||
* choose to link calloc() and free().
|
||||
* usually generated by the C++ compiler. Behavior is limitless if some
|
||||
* other module has linked calloc().
|
||||
*
|
||||
* @param fp is void(*)(T)
|
||||
* @param arg is passed to callback
|
||||
|
@ -78,8 +78,11 @@ int __cxa_atexit(void *fp, void *arg, void *pred) {
|
|||
/**
|
||||
* Triggers global destructors.
|
||||
*
|
||||
* They're called in LIFO order. If a destructor adds more destructors,
|
||||
* then those destructors will be called immediately following, before
|
||||
* iteration continues.
|
||||
*
|
||||
* @param pred can be null to match all
|
||||
* @note reentrant emptor
|
||||
*/
|
||||
void __cxa_finalize(void *pred) {
|
||||
unsigned i;
|
||||
|
|
|
@ -1,71 +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 │
|
||||
│ │
|
||||
│ 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 "ape/lib/pc.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nexgen32e/nexgen32e.h"
|
||||
#include "libc/nt/struct/context.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
#define kNtContextXstate 0x00100040
|
||||
#define kNtXstateAvx 2
|
||||
#define kNtXstateMaskAvx (1ull << kNtXstateAvx)
|
||||
|
||||
static void EnableAvx(void) {
|
||||
asm volatile("mov\t%%cr4,%%rax\n\t"
|
||||
"or\t%0,%%rax\n\t"
|
||||
"mov\t%%rax,%%cr4\n\t"
|
||||
"xor\t%%ecx,%%ecx\n\t"
|
||||
"xgetbv\n\t"
|
||||
"or\t%1,%%eax\n\t"
|
||||
"xsetbv"
|
||||
: /* no outputs */
|
||||
: "i"(CR4_OSXSAVE), "i"(XCR0_X87 | XCR0_SSE | XCR0_AVX)
|
||||
: "rax", "rcx", "rdx", "memory", "cc");
|
||||
}
|
||||
|
||||
static void EnableAvxOnWindows(void) {
|
||||
/* typedef uint64_t (*getenabledxstatefeatures_f)(void) __msabi; */
|
||||
/* typedef bool32 (*initializecontext_f)(void *buffer, uint32_t flags, */
|
||||
/* struct NtContext **out_context, */
|
||||
/* uint32_t *inout_buffersize) __msabi;
|
||||
*/
|
||||
/* typedef bool32 (*getxstatefeaturesmask_f)(struct NtContext * context, */
|
||||
/* uint64_t * out_featuremask)
|
||||
* __msabi; */
|
||||
/* typedef bool32 (*setxstatefeaturesmask_f)(struct NtContext * context, */
|
||||
/* uint64_t featuremask) __msabi; */
|
||||
/* getenabledxstatefeatures_f GetEnabledXStateFeatures; */
|
||||
/* initializecontext_f InitializeContext; */
|
||||
/* getxstatefeaturesmask_f GetXStateFeaturesMask; */
|
||||
/* setxstatefeaturesmask_f SetXStateFeaturesMask; */
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests authorization from operating system to do 256-bit math.
|
||||
* @assume avx cpuid check performed by caller
|
||||
*/
|
||||
int _init_enableavx(void) {
|
||||
if (IsMetal()) {
|
||||
EnableAvx();
|
||||
} else if (IsWindows()) {
|
||||
EnableAvxOnWindows();
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -129,7 +129,7 @@ void *mmap(void *addr, size_t size, int prot, int flags, int fd, int64_t off) {
|
|||
if (!CANONICAL(addr)) return VIP(einval());
|
||||
if (!(!!(flags & MAP_ANONYMOUS) ^ (fd != -1))) return VIP(einval());
|
||||
if (!(!!(flags & MAP_PRIVATE) ^ !!(flags & MAP_SHARED))) return VIP(einval());
|
||||
if (!(IsWindows() && fd != -1)) size = ROUNDUP(size, FRAMESIZE);
|
||||
if (fd != -1) size = ROUNDUP(size, FRAMESIZE);
|
||||
if (flags & MAP_FIXED) {
|
||||
if (UntrackMemoryIntervals(addr, size) == -1) {
|
||||
return MAP_FAILED;
|
||||
|
|
|
@ -37,6 +37,7 @@ LIBC_RUNTIME_A_DIRECTDEPS = \
|
|||
LIBC_BITS \
|
||||
LIBC_CALLS \
|
||||
LIBC_CONV \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_ELF \
|
||||
LIBC_FMT \
|
||||
LIBC_NEXGEN32E \
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
#include "libc/macros.h"
|
||||
|
||||
/ Self-bootstraps process upon existence before calling main.
|
||||
/
|
||||
/ @param r12 is argc
|
||||
/ @param r13 is argv
|
||||
/ @param r14 is environ
|
||||
/ @param r15 is auxv
|
||||
_spawn: push %rbp
|
||||
mov %rsp,%rbp
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue