Meta: Add files to repository
This commit is contained in:
parent
80a0428b66
commit
39198164cd
1029 changed files with 78311 additions and 0 deletions
229
System/Setup/Environment.HC
Normal file
229
System/Setup/Environment.HC
Normal file
|
@ -0,0 +1,229 @@
|
|||
AutoComplete(0);
|
||||
|
||||
#define include_noreindex #include
|
||||
|
||||
I64 tos_nist_offset = 5603; // UTC -4
|
||||
|
||||
#define NIST_TIME_OFFSET (tos_nist_offset - local_time_offset / CDATE_FREQ)
|
||||
|
||||
public
|
||||
I64 CDate2Unix(CDate dt)
|
||||
{ // TempleOS datetime to Unix timestamp.
|
||||
return ToI64((dt - Str2Date("1/1/1970")) / CDATE_FREQ + NIST_TIME_OFFSET);
|
||||
}
|
||||
|
||||
public
|
||||
CDate Unix2CDate(I64 timestamp)
|
||||
{ // Unix timestamp to TempleOS datetime.
|
||||
return (timestamp - NIST_TIME_OFFSET) * CDATE_FREQ + Str2Date("1/1/1970");
|
||||
}
|
||||
|
||||
// FIXME: Put these in a "Builtin" library?
|
||||
U0 FifoU8Cpy(CFifoU8* f, U8* s)
|
||||
{
|
||||
if (!f || !s)
|
||||
return;
|
||||
while (*s)
|
||||
FifoU8Ins(f, *s++);
|
||||
}
|
||||
Bool KeyDown(I64 sc) return Bt(kbd.down_bitmap, sc);
|
||||
I64 T(Bool _condition, I64 _true, I64 _false)
|
||||
{
|
||||
if (_condition)
|
||||
return _true;
|
||||
return _false;
|
||||
}
|
||||
|
||||
asm
|
||||
{
|
||||
_MEMCPY_U16::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
PUSH RSI
|
||||
PUSH RDI
|
||||
CLD
|
||||
MOV RDI,U64 SF_ARG1[RBP]
|
||||
MOV RSI,U64 SF_ARG2[RBP]
|
||||
MOV RCX,U64 SF_ARG3[RBP]
|
||||
REP_MOVSW
|
||||
MOV RAX,RDI
|
||||
POP RDI
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 24
|
||||
_MEMCPY_U32::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
PUSH RSI
|
||||
PUSH RDI
|
||||
CLD
|
||||
MOV RDI,U64 SF_ARG1[RBP]
|
||||
MOV RSI,U64 SF_ARG2[RBP]
|
||||
MOV RCX,U64 SF_ARG3[RBP]
|
||||
REP_MOVSD
|
||||
MOV RAX,RDI
|
||||
POP RDI
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 24
|
||||
_MEMCPY_U64::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
PUSH RSI
|
||||
PUSH RDI
|
||||
CLD
|
||||
MOV RDI,U64 SF_ARG1[RBP]
|
||||
MOV RSI,U64 SF_ARG2[RBP]
|
||||
MOV RCX,U64 SF_ARG3[RBP]
|
||||
REP_MOVSQ
|
||||
MOV RAX,RDI
|
||||
POP RDI
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 24
|
||||
}
|
||||
|
||||
public _extern _MEMCPY_U16 U16* MemCpyU16(U16* dst, U16* src, I64 cnt);
|
||||
public
|
||||
_extern _MEMCPY_U32 U32* MemCpyU32(U32* dst, U32* src, I64 cnt);
|
||||
public
|
||||
_extern _MEMCPY_U64 U64* MemCpyU64(U64* dst, U64* src, I64 cnt);
|
||||
|
||||
I64 @lerp(U32 val, U32 mx1, U32 mx2)
|
||||
{
|
||||
F64 r = (val & mx1) / ToF64(mx1);
|
||||
return ToI64(r * mx2);
|
||||
}
|
||||
|
||||
U0 @patch_call_rel32(U32 from, U32 to)
|
||||
{
|
||||
*(from(U8*)) = 0xE8;
|
||||
*((from + 1)(I32*)) = to - from - 5;
|
||||
}
|
||||
|
||||
U0 @patch_jmp_rel32(U32 from, U32 to)
|
||||
{
|
||||
*(from(U8*)) = 0xE9;
|
||||
*((from + 1)(I32*)) = to - from - 5;
|
||||
}
|
||||
|
||||
CMemBlk* ShrinkMemBlkByPags(CMemBlk* from, I64 count)
|
||||
{
|
||||
from->pags -= count;
|
||||
U64 to = from;
|
||||
to += count * MEM_PAG_SIZE;
|
||||
MemCpy(to, from, MEM_PAG_SIZE);
|
||||
return to;
|
||||
}
|
||||
|
||||
U0 @sse_enable()
|
||||
{
|
||||
/* clang-format off */
|
||||
asm
|
||||
{
|
||||
MOV_EAX_CR0
|
||||
AND AX, 0xFFFB // clear coprocessor emulation CR0.EM
|
||||
OR AX, 0x2 // set coprocessor monitoring CR0.MP
|
||||
MOV_CR0_EAX
|
||||
MOV_EAX_CR4
|
||||
OR AX, 3 << 9 // set CR4.OSFXSR and CR4.OSXMMEXCPT at the same time
|
||||
MOV_CR4_EAX
|
||||
}
|
||||
/* clang-format on */
|
||||
}
|
||||
|
||||
U0 @sse_enable_on_all_cores()
|
||||
{
|
||||
I64 i;
|
||||
for (i = 1; i < mp_cnt; i++)
|
||||
Spawn(&@sse_enable, , , i);
|
||||
}
|
||||
|
||||
I64 @t(Bool _condition, I64 _true, I64 _false)
|
||||
{
|
||||
if (_condition)
|
||||
return _true;
|
||||
return _false;
|
||||
}
|
||||
|
||||
U0 @erythros_mem_task_loop()
|
||||
{
|
||||
while (1) {
|
||||
Sleep(1);
|
||||
};
|
||||
}
|
||||
|
||||
// Before doing anything else, we:
|
||||
|
||||
// 1. Mark memory in code heap below 0x1000000 as used.
|
||||
sys_code_bp->mem_free_lst->next->pags = 0;
|
||||
|
||||
// 2. Free up 64MB at bottom of code heap for non-HolyC programs
|
||||
sys_code_bp->mem_free_lst = ShrinkMemBlkByPags(sys_code_bp->mem_free_lst, 131072);
|
||||
|
||||
// 3. Enable SSE
|
||||
@sse_enable;
|
||||
|
||||
// 4. Init mem_tasks
|
||||
|
||||
CTask* erythros_mem_task = Spawn(&@erythros_mem_task_loop, , "ErythrosMemTask");
|
||||
|
||||
#define MALLOC_MEM_TASK_COUNT 4
|
||||
CTask** malloc_mem_task = CAlloc(sizeof(CTask*) * MALLOC_MEM_TASK_COUNT, erythros_mem_task);
|
||||
I64 malloc_current_mem_task = 0;
|
||||
|
||||
U0 @malloc_mem_tasks_init()
|
||||
{
|
||||
U8* scratch_buffer[64];
|
||||
I64 i;
|
||||
for (i = 0; i < MALLOC_MEM_TASK_COUNT; i++) {
|
||||
StrPrint(scratch_buffer, "ErythrosMallocTask%d", i);
|
||||
malloc_mem_task[i] = Spawn(&@erythros_mem_task_loop, , scratch_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@malloc_mem_tasks_init;
|
||||
|
||||
U0 dd() { DocDump(adam_task->put_doc); }
|
||||
//@patch_jmp_rel32(&Fault2, &Reboot); // Reboot instead of crashing to the debugger
|
||||
U0 NoBeep(I8, Bool) {};
|
||||
@patch_jmp_rel32(&Beep, &NoBeep); // Don't delay on beep when entering debugger
|
||||
|
||||
Bool BlkDevLock2(CBlkDev* bd)
|
||||
{
|
||||
BlkDevChk(bd);
|
||||
while (bd->lock_fwding)
|
||||
bd = bd->lock_fwding;
|
||||
if (!Bt(&bd->locked_flags, BDlf_LOCKED) || bd->owning_task != Fs) {
|
||||
while (LBts(&bd->locked_flags, BDlf_LOCKED))
|
||||
Sleep(Rand * 10);
|
||||
bd->owning_task = Fs;
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Bool DrvLock2(CDrv* dv)
|
||||
{
|
||||
DrvChk(dv);
|
||||
BlkDevLock2(dv->bd);
|
||||
if (!Bt(&dv->locked_flags, DVlf_LOCKED) || dv->owning_task != Fs) {
|
||||
while (LBts(&dv->locked_flags, DVlf_LOCKED))
|
||||
Sleep(Rand * 10);
|
||||
dv->owning_task = Fs;
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@patch_jmp_rel32(&BlkDevLock, &BlkDevLock2); // Patch BlkDevLock so we don't deadlock on multiple tasks reading from virtio disk
|
||||
@patch_jmp_rel32(&DrvLock, &DrvLock2); // Patch DrvLock so we don't deadlock on multiple tasks reading from virtio disk
|
||||
|
||||
U0 @erythros_mem_task_loop()
|
||||
{
|
||||
while (1) {
|
||||
Sleep(1);
|
||||
};
|
||||
}
|
||||
|
||||
CTask* erythros_mem_task = Spawn(&@erythros_mem_task_loop, , "ErythrosMemTask");
|
65
System/Setup/Init.HC
Normal file
65
System/Setup/Init.HC
Normal file
|
@ -0,0 +1,65 @@
|
|||
|
||||
// Save pointer to TempleOS system-wide (CTRL-ALT) callbacks
|
||||
U64 tos_fp_cbs_enabled = keydev.fp_ctrl_alt_cbs;
|
||||
U64 tos_fp_cbs_disabled = CAlloc(0xD0);
|
||||
|
||||
U0 @erythros_init()
|
||||
{
|
||||
I64 err = 0;
|
||||
|
||||
// Initialize Display
|
||||
if (!Display.Driver()) {
|
||||
err = Display.Init(1920, 1080, 32, FB_VMSVGA);
|
||||
}
|
||||
|
||||
if (err) {
|
||||
DocClear(Fs->put_doc);
|
||||
"No supported display device found.";
|
||||
while (1) {
|
||||
Sleep(1);
|
||||
};
|
||||
}
|
||||
|
||||
// Initialize Mouse
|
||||
Mouse.Init();
|
||||
Spawn(Mouse.Task, , "Mouse");
|
||||
|
||||
// Enable debug output
|
||||
Raw(ON);
|
||||
DocDump(adam_task->put_doc);
|
||||
|
||||
// Disable TempleOS system-wide (CTRL-ALT) callbacks
|
||||
keydev.fp_ctrl_alt_cbs = tos_fp_cbs_disabled;
|
||||
|
||||
// Suspend TempleOS Window Manager task
|
||||
Suspend(sys_winmgr_task);
|
||||
|
||||
// Reassign VGA writes to a random buffer to avoid collision with SVGA FB
|
||||
text.vga_alias = MAlloc(1048576, adam_task);
|
||||
|
||||
// Initialize Graphics2D Library
|
||||
Graphics2D.Init();
|
||||
|
||||
"\x1b[2J\x1b[H";
|
||||
//"%s\n", System.BuildInfo();
|
||||
|
||||
switch (Display.Driver()) {
|
||||
case FB_VMSVGA:
|
||||
"Display driver is: VMSVGA\n";
|
||||
break;
|
||||
}
|
||||
|
||||
// Initialize FileSystem
|
||||
// FileSystem.Init();
|
||||
|
||||
// Initialize Compositor
|
||||
Compositor.Init();
|
||||
|
||||
// Spawn Compositor
|
||||
Spawn(Compositor.Task, , "Compositor");
|
||||
|
||||
// Spawn SystemStarter
|
||||
Spawn(SystemStarter.Task, , "SystemStarter", 1);
|
||||
}
|
||||
|
||||
@erythros_init;
|
Loading…
Add table
Add a link
Reference in a new issue