TempleOSCD_140715.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:46:09 +02:00
1 parent 7ef616a20e
commit 64f679eeb9
1095 files changed
+24814 -221011

No files matched your search

+1 -7
View File
@@ -1,8 +1,4 @@
/*
$WW,1$You may wonder why I use "&" instead of "%".
$WW,0$
*/
//$WW,1$You may wonder why I use "&" instead of "%".
#define SAMPLE_SIZE 100000000
@@ -45,9 +41,7 @@ U0 TimeIns()
TimeIns;
/* Program Output$HL,0$$WW+H,1$$FD,1$
8 Cores 2.660GHz
Remainder Version #1 Cycles : 26.85345
Remainder Version #2 Cycles : -0.00800
$HL,1$*/
+4 -9
View File
@@ -1,5 +1,4 @@
/*
"Fixed point" means you use integers
/*"Fixed point" means you use integers
that are scaled by a value. A common
example would be using number of pennies
instead of dollars with a float.
@@ -37,7 +36,7 @@ U0 Main()
for (i=1000000000;i;i--)
f_sum+=f_val;
"Float Sum:%.9f Time:%7.3fs\n",f_sum,tS-t0;
NewLine;
'\n';
}
U0 DoIt2()
@@ -48,8 +47,7 @@ U0 DoIt2()
"i&0xFFFFFFFF=%X\n",i&0xFFFFFFFF;
"i>>32 =%X\n",i>>32;
/*
Standard integer types are declared
/* Standard integer types are declared
with a special compiler feature which
allows a structure to be accessed as a
whole. That's why the i variable can
@@ -74,7 +72,6 @@ public U64i union I64
For a complete lst of nonstandard compiler
features, see $LK,"::/Doc/HolyC.TXT"$.
*/
"i.u32[0] =%X\n",i.u32[0];
@@ -87,8 +84,7 @@ DoIt2;
//See $LK,"::/Demo/Lectures/FixedPointAdvanced.CPP"$
/* Program Output$HL,0$$WW+H,1$$FD,1$
/*Program Output$HL,0$$WW+H,1$$FD,1$
8 Cores 2.660GHz
Integer Sum:2000000199.768689408 Time: 0.787s
@@ -99,5 +95,4 @@ i&0xFFFFFFFF=9ABCDEF0
i>>32 =12345678
i.u32[0] =9ABCDEF0
i.u32[1] =12345678
$HL,1$*/
+1 -3
View File
@@ -1,5 +1,4 @@
/*
"Fixed point" means you use integers
/*"Fixed point" means you use integers
that are scaled by a value. A common
example would be using number of pennies
instead of dollars with a float.
@@ -110,7 +109,6 @@ U0 Main()
"$$RED$$Float Cycles :%10.5f$$FG$$\n",
ToF64(test_time)/SAMPLE_SIZE;
//Measure fixed point arithmetic
d2=Sin(1.0)*0x100000000;
sum=0;
+2 -2
View File
@@ -8,7 +8,7 @@ F64 VGAPattern(I64 p)
for (plane=1;plane<0x10;plane<<=1) {
OutU8(VGA_SC_INDEX,VGA_MAP_MASK);
OutU8(VGA_SC_DATA,plane);
MemSetU64(0xA0000,p,640*480/64);
MemSetI64(0xA0000,p,640*480/64);
}
return tS-start;
}
@@ -29,7 +29,7 @@ U0 GrDemo()
" $$GREEN$$Load@60Hz:$$RED$$%5.1f%%$$FG$$\n",1/t,100*t*60.0;
}
Preempt(old_preempt);
//<CTRL-ALT-F> will flush screen VGA cache.
//<CTRL-ALT-f> will flush screen VGA cache.
VGAFlush;
}
+1 -4
View File
@@ -1,4 +1,4 @@
//This is the software interrupt num
//This is the software interrupt num
//we will use. See $LK,"Software Int's",A="MN:I_WAKE"$ for
//picking a num. Nums are subject to change.
@@ -50,7 +50,6 @@ _F_UM_CALL::
_extern _F_UM_INT F64 UnaryMinusInt(F64 d);
_extern _F_UM_CALL F64 UnaryMinusCall(F64 d);
#define SAMPLE_SIZE 1000000
U0 TimeIns()
{
@@ -82,9 +81,7 @@ U0 TimeIns()
TimeIns;
/* Program Output$HL,0$$WW+H,1$$FD,1$
$PT$$FG$$BG$6 Cores 3.395GHz
Interrupt Cycles: 573.98543
Call Cycles: 9.74349
$HL,1$*/
+5 -7
View File
@@ -4,7 +4,7 @@ $ID,2$The mini compiler is like the main compiler, except the main compiler's le
The main compiler generates $LK,"Intermediate Code",A="FF:::/Compiler/CmpDefs.HPP,IC_END"$ at the parser stage. See $LK,"PrsExpression",A="MN:PrsExpression"$(), $LK,"PrsStatement",A="MN:PrsStatement"$().
The main compiler optimizes See $LK,"Intermediate Code Attributes",A="FF:D:/Compiler/CmpInit.CPP,ST_INTERMEDIATE_CODE"$, $LK,"Combining Consts",A="FF:::/Compiler/OptPass012.CPP,case IC_MUL"$, $LK,"Choosing Reg Vars",A="FF:::/Compiler/OptPass3.CPP,num_reg_vars"$. Set $LK,"OTrace",A="MN:OTrace"$(ON) to see the optimization stages.
The main compiler optimizes See $LK,"Intermediate Code Attributes",A="FF:D:/Compiler/CmpInit.CPP,ST_INTERMEDIATE_CODE"$, $LK,"Combining Consts",A="FF:::/Compiler/OptPass012.CPP,case IC_MUL"$, $LK,"Choosing Reg Vars",A="FF:::/Compiler/OptPass3.CPP,cmp.num_reg_vars"$. Set $LK,"OTrace",A="MN:OTrace"$(ON) to see the optimization stages.
The main compiler makes machine code in the back end. See $LK,"IC Struct",A="MN:CIntermediateCode"$, $LK,"LCCCompile",A="MN:LCCCompile"$ and $LK,"OptPass789",A="FF:::/Compiler/OptPass789.CPP,IC_MUL"$(), $LK,"BackEnd",A="FF:::/Compiler/Back1a.CPP,ICMul"$. Set $LK,"CTrace",A="MN:CTrace"$(ON) to see the output of the backend.
$ID,-2$
@@ -30,7 +30,7 @@ $ID,-2$$WW,0$*/
#define OP_SUB 4
I64 Lex(U8 **_src,I64 *num)
{ //See $LK,"Lex",A="MN:Lex"$().
{//See $LK,"Lex",A="MN:Lex"$().
U8 *src=*_src;
I64 i;
while (TRUE) {
@@ -90,7 +90,7 @@ I64 Lex(U8 **_src,I64 *num)
extern I64 Parse(U8 **_src,U8 **_dst);
U0 PrsTerm(U8 **_src,U8 **_dst,I64 prec)
{ //See $LK,"PrsExpression",A="MN:PrsExpression"$().
{//See $LK,"PrsExpression",A="MN:PrsExpression"$().
I64 i;
U8 *src2;
U8 *dst2;
@@ -111,8 +111,7 @@ U0 PrsTerm(U8 **_src,U8 **_dst,I64 prec)
}
I64 Parse(U8 **_src,U8 **_dst)
{
//See $LK,"PrsExpression",A="MN:PrsExpression"$().
{//See $LK,"PrsExpression",A="MN:PrsExpression"$().
//See $LK,"Opcode Fmts",A="FF:::/Compiler/OpCodes.TXT,IDIV"$ for details on asm instructions.
I64 i;
U8 *dst=*_dst;
@@ -195,7 +194,6 @@ I64 Parse(U8 **_src,U8 **_dst)
}
}
U0 Main()
{
U8 *src,*src2,*code,*dst;
@@ -208,7 +206,7 @@ U0 Main()
"This will compile an expression\n"
"consisting of integers, parentheses\n"
"and the operators +,-,* and /.\n";
src=MGetS;
src=GetStr;
if (*src) {
src2=src;
dst=code;
+6 -6
View File
@@ -1,5 +1,5 @@
//See $LK,"::/Demo/Lectures/GraphicsCPULoad.CPP"$
U8 reverse[256], //The VGA bits are backward
U8 reverse[256], //The VGA bits are bwd
image[640*480/8]; //We need read-modify write.
//0xA0000 memory can't be read.
@@ -16,7 +16,7 @@ U0 MGInit()
}
U0 MGUpdate()
{ //Copy image to VGA memory
{//Copy image to VGA memory
//For better performance we could only write what's changed.
//0xA0000 is slower than normal RAM.
OutU8(VGA_SC_INDEX,VGA_MAP_MASK);
@@ -31,11 +31,11 @@ U0 MGPlot(I64 x,I64 y)
}
U0 MGHLine(I64 x1,I64 x2,I64 y)
{ //Warning! No clipping
{//Warning! No clipping
//For performance, we do as many whole-bytes as possible.
U8 *ptr;
I64 i,w,leading,trailing,whole_bytes;
if (x2<x1) SwapU64(&x1,&x2);
if (x2<x1) SwapI64(&x1,&x2);
ptr=image+y*640/8+x1>>3;
w=x2-x1+1;
leading =8-x1&7;
@@ -54,7 +54,7 @@ U0 MGHLine(I64 x1,I64 x2,I64 y)
}
U0 MGLine(I64 x1,I64 y1,I64 x2,I64 y2)
{ //Warning! No clipping
{//Warning! No clipping
I64 dx=x2-x1,dy=y2-y1;
x1<<=32; x2<<=32;
y1<<=32; y2<<=32;
@@ -124,7 +124,7 @@ It is not normal to by-pass the TempleOS graphcis routines.
The TempleOS graphics don't know VGA has changed.
This bit tells TempleOS to update whole screen.
*/
//<CTRL-ALT-F> will flush screen VGA cache.
//<CTRL-ALT-f> will flush screen VGA cache.
VGAFlush;
}
+56
View File
@@ -0,0 +1,56 @@
class Person
{
U8 first [32];
U8 last [32];
U8 address1 [64];
U8 address2 [64];
U8 city [32];
U8 state_zip[32];
};
U0 OffsetDemo1()
{
Person *p=MAlloc(sizeof(Person));
StrCpy(p->first, "Terry");
StrCpy(p->last, "Davis");
StrCpy(p->address1, "8144 Sickle Lane");
StrCpy(p->address2, "");
StrCpy(p->city, "Las Vegas");
StrCpy(p->state_zip,"NV 89128");
}
U(&OffsetDemo1,34);
PressAKey;
/*
x86 has signed 8-bit displacements
and signed 32-bit displacements.
This example uses 8-bit negative displacements.
*/
class Person
{ $$=-128;
U8 first [32];
U8 last [32];
U8 address1 [64];
U8 address2 [64];
U8 city [32];
U8 state_zip[32];
};
U0 OffsetDemo2()
{
Person *p=MAlloc(sizeof(Person))(I64)+128;
StrCpy(p->first, "Terry");
StrCpy(p->last, "Davis");
StrCpy(p->address1, "8144 Sickle Lane");
StrCpy(p->address2, "");
StrCpy(p->city, "Las Vegas");
StrCpy(p->state_zip,"NV 89128");
}
U(&OffsetDemo2,34);
PressAKey;
+1 -8
View File
@@ -1,5 +1,4 @@
/*
The moral of this story is simple
/*The moral of this story is simple
instruction level optimizations
don't matter much on a modern Intel CPU
because they convert complex instructions
@@ -28,7 +27,6 @@ _BADLY_UNOPTIMIZED::
JB @@05
RET
_WELL_OPTIMIZED1::
XOR RAX,RAX
MOV RCX,SAMPLES-1
@@ -67,8 +65,6 @@ _WELL_OPTIMIZED3::
RET
}
_extern _BADLY_UNOPTIMIZED I64 Loop1();
_extern _WELL_OPTIMIZED1 I64 Loop2();
_extern _WELL_OPTIMIZED2 I64 Loop3();
@@ -99,9 +95,7 @@ t0=tS;
i=Loop4;
"Result:%d Time:%9.6f\n",i,tS-t0;
/* Program Output$HL,0$$WW+H,1$$FD,1$
8 Cores 2.660GHz
Bad Code
Result:3200000040000000 Time: 0.069966
@@ -111,5 +105,4 @@ Good Code #2
Result:3200000040000000 Time: 0.062907
Good Code #3
Result:3200000040000000 Time: 0.156359
$HL,1$*/
+2 -2
View File
@@ -48,7 +48,7 @@ U0 Main()
//has the first four vects.
for (i=IOREDTAB;i<IOREDTAB+4*2;i+=2) {
*da=i+1;
*_d=mp_apic_ids[DEST_CPU]<<24;
*_d=dev.mp_apic_ids[DEST_CPU]<<24;
*da=i;
*_d=0x4000+0x40+(i-IOREDTAB)/2;
}
@@ -63,7 +63,7 @@ U0 Main()
//Disable vects
for (i=IOREDTAB;i<IOREDTAB+4*2;i+=2) {
*da=i+1;
*_d=mp_apic_ids[DEST_CPU]<<24;
*_d=dev.mp_apic_ids[DEST_CPU]<<24;
*da=i;
*_d=0x14000+0x40+(i-IOREDTAB)/2;
}
+11 -11
View File
@@ -1,12 +1,12 @@
//What's funner than page tables for programmers to play with!!
/*What's funner than page tables for programmers to play with!!
//This changes a page table entry for VGA graphics memory.
//TempleOS keeps a cached copy of VGA memory in
//$LK,"gr_screen_image",A="MN:gr_screen_image"$. See $LK,"GrUpdateVGAGraphics",A="MN:GrUpdateVGAGraphics"$.
//TempleOS used 4096 size pages for memory below addr 2 Meg
//and 2 Meg pages above two Meg. See $LK,"MemPageSize",A="MN:MemPageSize"$() and $LK,"INIT_MEMORY",A="FF:::/Kernel/Mem1a.CPP,SYS_INIT_MEM"$.
This changes a page table entry for VGA graphics memory.
TempleOS keeps a cached copy of VGA memory in
$LK,"gr.screen_image",A="MN:CGrGlbls"$. See $LK,"GrUpdateVGAGraphics",A="MN:GrUpdateVGAGraphics"$.
TempleOS used 4096 size pages for memory below addr 2 Meg
and 2 Meg pages above two Meg. See $LK,"MemPageSize",A="MN:MemPageSize"$() and $LK,"INIT_MEMORY",A="FF:::/Kernel/Mem1a.CPP,SYS_INIT_MEM"$.
*/
U0 PageTableDemo1()
{
@@ -28,7 +28,7 @@ U0 PageTableDemo1()
// SetRAX(0x100000+0x1000*(MEM_NUM_PML1+MEM_NUM_PML2+MEM_NUM_PML3));
// MOV_CR3_EAX
//<CTRL-ALT-F> will flush screen VGA cache.
//<CTRL-ALT-f> will flush screen VGA cache.
VGAFlush;
PressAKey;
@@ -37,12 +37,12 @@ U0 PageTableDemo1()
InvlPg(VGA_GRAPHIC_MEM_BASE);
InvlPg(VGA_GRAPHIC_MEM_BASE+0x1000);
//<CTRL-ALT-F> will flush screen VGA cache.
//<CTRL-ALT-f> will flush screen VGA cache.
VGAFlush;
}
PageTableDemo1;
//See $LK,"MemBlks2MegAlloc",A="MN:MemBlks2MegAlloc"$(), $LK,"MemBlks2MegFree",A="MN:MemBlks2MegFree"$() for page aligned allocations.
//See $LK,"CBlkPool",A="MN:CBlkPool"$, $LK,"CHeapCtrl",A="MN:CHeapCtrl"$, $LK,"sys_code_bp",A="MN:sys_code_bp"$, $LK,"sys_data_bp",A="MN:sys_data_bp"$.
//See $LK,"Memory",A="HI:Memory"$
//See $LK,"CBlkPool",A="MN:CBlkPool"$, $LK,"CHeapCtrl",A="MN:CHeapCtrl"$, $LK,"sys_code_bp",A="MN:sys_code_bp"$ and $LK,"sys_data_bp",A="MN:sys_data_bp"$.
//See $LK,"Memory Overview",A="FI:::/Doc/MemOverview.TXT"$ and $LK,"Memory Routines",A="HI:Memory"$.
-3
View File
@@ -2,8 +2,6 @@ I64 *addr=VGA_GRAPHIC_MEM_BASE,
*pte_addr=MemPageTable(addr),
err_code=0,
*reported_fault_addr;
/*
0[RBP]=old base ptr
8[RBP]=err code
@@ -24,7 +22,6 @@ interrupt haserrcode U0 PageFault()
reported_fault_addr=GetRAX;
}
U0 PageTableDemo2()
{
U8 *old_idte=IntEntrySet(I_PAGE_FAULT,&PageFault,IDTET_IRQ);
+1 -6
View File
@@ -1,5 +1,4 @@
/*
TempleOS runs exclusively in ring 0.
/*TempleOS runs exclusively in ring 0.
Ring 0 is part of the $LK,"Charter",A="FI:::/Doc/Charter.TXT"$.
This demo is for you to play around
with ring 3. TempleOS is for
@@ -25,8 +24,6 @@ TO_RING0:: //Set to handle general protection 0xD fault temporarily.
IRET
}
U0 Ring3Demo()
{
U8 *old_vect;
@@ -38,7 +35,6 @@ U0 Ring3Demo()
SetRAX(Gs->tss->tr_ring3+3);
LTR AX
asm {
MOV U64 [&old_stk],RSP
@@ -76,5 +72,4 @@ R3_CALLBACK:
"Progress1 After :%X\n",progress1;
}
Ring3Demo;
+3 -6
View File
@@ -7,8 +7,6 @@ U0 PlotXY(I64 x,I64 y)
LBts(VGA_GRAPHIC_MEM_BASE,y*GR_WIDTH+x^7);
}
U0 Main()
{
I64 i;
@@ -33,8 +31,7 @@ U0 Main()
OutU8(VGA_SC_DATA,BLUE);
for (i=0;i<200;i++)
PlotXY(200-i,i);
/*
If you want a mixed color select multiple planes
/*If you want a mixed color select multiple planes
but you have to be sure the unselected planes
are zero, so select them and make them zero.
You can't do reads on VGA memory, by the way.
@@ -44,9 +41,9 @@ That means no read-modify-writes, too.
Preempt(old_preempt);
//TempleOS has a 4 plane memory duplicate of the screen, $LK,"gr_screen_image",A="MN:gr_screen_image"$,
//TempleOS has a 4 plane memory duplicate of the screen, $LK,"gr.screen_image",A="MN:CGrGlbls"$,
//and only writes actual changes. See $LK,"GrUpdateVGAGraphics",A="MN:GrUpdateVGAGraphics"$().
//<CTRL-ALT-F> will flush screen VGA cache.
//<CTRL-ALT-f> will flush screen VGA cache.
VGAFlush;
}
-2
View File
@@ -15,7 +15,6 @@ U0 LoadTask(I64)
}
}
U0 SpinningPreempt()
{
I64 i;
@@ -56,7 +55,6 @@ U0 SpinningNoInterrupts()
STI
}
U0 CooperativeMultitaskingPreempt()
{
F64 timeout=tS+3.0;
+2 -2
View File
@@ -45,11 +45,11 @@ U0 TimeIns()
TimeIns;
/* Program Output$HL,0$$WW+H,1$$FD,1$
/*Program Output$HL,0$$WW+H,1$$FD,1$
8 Cores 2.660GHz
Cached Cycles: 202,220
Uncached Cycles: 14,357,016
$FG,2$The difference is even greater
because the loop overhead was not subtracted.
$HL,1$*/