Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
TinkerOS 5.15
Browse files Browse the repository at this point in the history
  • Loading branch information
tinkeros committed Jul 5, 2024
1 parent 6b8cf71 commit 74ab50f
Show file tree
Hide file tree
Showing 87 changed files with 3,119 additions and 418 deletions.
2 changes: 1 addition & 1 deletion Adam/ABlkDev/DskPrt.HC
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CPlannedDrv
};

public I64 DskPrt(U8 drv_let=0,...)
{
{//Partition disk
/*Partition the disk containing partition drv_let.
drv_let=0 means add new drive that is not already mounted.
Expand Down
6 changes: 6 additions & 0 deletions Adam/AExts.HC
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ extern U0 InUntilKey(I64 scan_code,I64 sc_mask=0xFF|SCF_SHIFT|SCF_CTRL|SCF_ALT,
extern I64 InGetChar(...);
extern I64 InUntilChar(...);
extern Bool BootMHDIns(U8 drv_let,U8 *drv_lst=NULL);
extern I64 Hypervisor();
extern U0 PCILookUpDevs();
extern U0 PCILookUpDev(I64 vendor, I64 dev);
extern Bool PciFindByID(U16 vendor_id, U16 device_id, U16 class_code=NULL, U16 sub_code=NULL,
I64* bus_out=NULL, I64* dev_out=NULL, I64* fun_out=NULL);

13 changes: 13 additions & 0 deletions Adam/AMath.HC
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,16 @@ public Complex *CPoly(Complex *dst,I64 n,Complex *zeros,Complex *x)
CEqu(dst,1.0,0.0);
return dst;
}

public U64 NextPow2(U64 x)
{// Get next power of 2 >= input
x--;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x |= x >> 32;
x++;
return x;
}
3 changes: 1 addition & 2 deletions Adam/AutoComplete/ACInit.HC
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public U0 ACInit(U8 *mask=NULL)
if (DrvIsWritable && FileFind(ACD_DEF_FILENAME_Z) &&
!FileFind(ACD_DEF_FILENAME))
{
if (bd->type!=BDT_RAM)
if (!Gs->num && bd->type!=BDT_RAM)
{
start_flag=FALSE;
Spawn(&ACProgressTask,&start_flag);
Expand All @@ -167,7 +167,6 @@ public U0 ACInit(U8 *mask=NULL)
ACDWordsLoad;
LBtr(&ac.flags,ACf_INIT_IN_PROGRESS);
LBts(&sys_run_level,RLf_AUTO_COMPLETE);
AutoComplete(ON);
}

I64 AutoCompleteSize()
Expand Down
9 changes: 9 additions & 0 deletions Adam/AutoComplete/ACTask.HC
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,12 @@ public Bool AutoComplete(Bool val=OFF)
}
return old_val;
}

U0 ShowACWhenReady()
{
while (!Bt(&sys_run_level,RLf_AUTO_COMPLETE))
{
Sleep(100);
}
AutoComplete(ON);
}
22 changes: 22 additions & 0 deletions Adam/AutoComplete/DoACInit.HC
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "/Adam/AutoComplete/ACInit"


U0 DoACInit()
{
Silent; //no output to scrn
ACInit("/*;!*/Bible.TXT*");
Silent(OFF); //no output to scrn
}

DoACInit;


// If not Adam, give him symbols too
if (!Gs->num)
AdamFile("/Adam/AutoComplete/ACInit");



Adam("ShowACWhenReady;\n");


12 changes: 11 additions & 1 deletion Adam/Ctrls/CtrlsA.HC
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,20 @@ Bool CtrlInsideRect(CCtrl *c,I64 x,I64 y)

public Bool CtrlInside(CCtrl *c,I64 x,I64 y)
{//Is x,y inside a ctrl?
Bool res;
if (c->flags&CTRLF_SHOW)
{
if (c->inside_ctrl)
return (*c->inside_ctrl)(c,x,y);
{
try {
res=(*c->inside_ctrl)(c,x,y);
}
catch {
Fs->catch_except=TRUE;
res=FALSE;
}
return res;
}
else
return CtrlInsideRect(c,x,y);
}
Expand Down
158 changes: 142 additions & 16 deletions Adam/Device/Comm.HC
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CComm
I64 base,
device,
flags,
poll,
type;
CFifoU8 *RX_fifo;
};
Expand Down Expand Up @@ -64,6 +65,33 @@ public U0 CommHndlr(I64 port)
}
}

public U0 PollCommHndlr(I64 port)
{// Com port IRQ handler
CComm *c;
CFifoU8 *f;
I64 stat, free_size=COMM_RX_FIFO_SIZE;
c=&comm_ports[port];
if (Bt(&c->flags,COMf_ENABLED))
{
f=c->RX_fifo;
if (f->out_ptr>f->in_ptr)
free_size-=f->mask+1-(f->out_ptr-f->in_ptr);
else
free_size-=f->in_ptr-f->out_ptr;
while (free_size>0)
{
stat=InU8(c->base+UART_LSR);
if (stat & 1) //RX
{
FifoU8Ins(c->RX_fifo,InU8(c->base+UART_RDR));
free_size--;
}
else
break;
}
}
}

interrupt U0 IRQComm3()
{// Com 2/4 IRQ handler
CommHndlr(2);
Expand All @@ -78,21 +106,18 @@ interrupt U0 IRQComm4()
OutU8(0x20,0x20);
}


interrupt U0 IRQCommPCI()
{// Com 5+ IRQ handler
I64 port=5;
while (port<=MAX_COMM_NUM)
{
if (Bt(comm_ports[port].flags,COMf_ENABLED) && comm_ports[port].base>0)
if (Bt(&comm_ports[port].flags,COMf_ENABLED) && comm_ports[port].base>0)
CommHndlr(port++);
}
*(dev.uncached_alias + LAPIC_EOI)(U32*)=0;
}


// TODO add PCIE
// TODO common PCI/PCIE function
// TODO add other PCIE, common PCI/PCIE function

I64 AddPCIComms(I64 next_port)
{
Expand Down Expand Up @@ -143,8 +168,12 @@ public CComm *CommInit7n1(I64 port,I64 baud)
OutU8(c->base+UART_MCR,4);
OutU8(c->base+UART_IER,0); //Disable all IRQ
OutU8(c->base+UART_MCR,0xA); //out2 and rts
OutU8(0x21,InU8(0x21) & (0xFF-0x18)); //Enable 8259 IRQ 3 & 4
OutU8(c->base+UART_IER,1); //RX but no THR empty
if (!c->poll) {
OutU8(0x21,InU8(0x21) & (0xFF-0x18)); //Enable 8259 IRQ 3 & 4
OutU8(c->base+UART_IER,1); //RX but no THR empty
}
else
OutU8(c->base+UART_IIR,0xC7);
LBts(&c->flags,COMf_ENABLED);
POPFD
return c;
Expand All @@ -168,32 +197,70 @@ public CComm *CommInit8n1(I64 port,I64 baud)
OutU8(c->base+UART_MCR,4);
OutU8(c->base+UART_IER,0); //Disable all IRQ
OutU8(c->base+UART_MCR,0xA); //out2 and rts
OutU8(0x21,InU8(0x21) & (0xFF-0x18)); //Enable 8259 IRQ 3 & 4
OutU8(c->base+UART_IER,1); //RX but no THR empty
if (!c->poll) {
OutU8(0x21,InU8(0x21) & (0xFF-0x18)); //Enable 8259 IRQ 3 & 4
OutU8(c->base+UART_IER,1); //RX but no THR empty
}
else
OutU8(c->base+UART_IIR,0xC7);
LBts(&c->flags,COMf_ENABLED);
POPFD
return c;
}

public U0 CommPutChar(I64 port,U8 b)
public U0 PollComm(U8 *data)
{// Polls a serial port
PUSHFD
CLI
PollCommHndlr(data);
POPFD
}

public U0 CommPutChar(I64 port,U8 b, I64 timeout_ms=500)
{// Write 1 byte to com port
I64 base=comm_ports[port].base;
F64 timeout_time=tS+ToF64(timeout_ms)/1000.0;
while (!(InU8(base+UART_LSR) & 0x20))
{
if (tS>timeout_time) throw('ComErr');
Yield;
}
OutU8(base+UART_THR,b);
while (!(InU8(base+UART_LSR) & 0x20))
{
if (tS>timeout_time) throw('ComErr');
Yield;
}
if (Bt(&comm_ports[port].flags,COMf_ENABLED) && comm_ports[port].poll)
{
Spawn(&PollComm, port);
if (tS>timeout_time) throw('ComErr');
Yield;
}
}

public U8 CommGetChar(I64 port)
public U8 CommGetChar(I64 port, I64 timeout_ms=500)
{// Get 1 byte from com port
U8 chr;
F64 timeout_time=tS+ToF64(timeout_ms)/1000.0;
if (Bt(&comm_ports[port].flags,COMf_ENABLED) && comm_ports[port].poll)
{
PollCommHndlr(port);
}
while (1)
{
if (FifoU8Rem(comm_ports[port].RX_fifo, &chr))
return chr;
else
Yield;
else {
if (Bt(&comm_ports[port].flags,COMf_ENABLED) && comm_ports[port].poll)
{
PollCommHndlr(port);
Yield;
}
else
Yield;
}
if (tS>timeout_time) throw('ComErr');
}
}

Expand All @@ -203,11 +270,21 @@ public Bool CommGetCharNoWait(I64 port, U8 *byte_out)
{
return TRUE;
}
if (Bt(&comm_ports[port].flags,COMf_ENABLED) && comm_ports[port].poll)
{
PollCommHndlr(port);
if (FifoU8Rem(comm_ports[port].RX_fifo, byte_out))
{
return TRUE;
}
}
return FALSE;
}

public U0 CommFlush(I64 port)
{// Flush com port fifos
if (Bt(&comm_ports[port].flags,COMf_ENABLED) && comm_ports[port].poll)
PollCommHndlr(port);
FifoU8Flush(comm_ports[port].RX_fifo);
}

Expand All @@ -234,7 +311,7 @@ public U0 CommPrint(I64 port,U8 *fmt,...)
Free(buf);
}

public U0 PciRerouteInterrupts(I64 base, I64 cpu=0)
U0 PciRerouteInterrupts(I64 base, I64 cpu=0)
{
I64 i;
U8 *da = dev.uncached_alias + IOAPIC_REG;
Expand All @@ -248,10 +325,29 @@ public U0 PciRerouteInterrupts(I64 base, I64 cpu=0)
}
}

U0 DisablePciInterrupts(I64 cpu=0)
{
I64 i, base=0x40;
U8 *da = dev.uncached_alias + IOAPIC_REG;
U32 *_d = dev.uncached_alias + IOAPIC_DATA;
for(i=0; i<4; i++)
{
*da=IOREDTAB +i*2 +1;
*_d=dev.mp_apic_ids[cpu] << 24;
*da=IOREDTAB+i*2;
*_d=0x14000+base+i;
}
}

U0 EnablePCIComms()
{
I64 i=5;

if (comm_ports[5].base)
{
while (comm_ports[i].base) {
comm_ports[i++].poll=0;
}
IntEntrySet(0x40, &IRQCommPCI, IDTET_IRQ);
IntEntrySet(0x41, &IRQCommPCI, IDTET_IRQ);
IntEntrySet(0x42, &IRQCommPCI, IDTET_IRQ);
Expand Down Expand Up @@ -288,7 +384,17 @@ public U0 CommInit()
}
IntEntrySet(0x23,&IRQComm3);
IntEntrySet(0x24,&IRQComm4);
if (next_port>5) EnablePCIComms;
for (i=0; i<4; i++)
{
comm_ports[i].poll=0;
}
if (next_port>5)
{
for (i=5; i<next_port; i++)
{
comm_ports[i].poll=1;
}
}
}
CommInit;

Expand All @@ -300,7 +406,27 @@ U0 CommRep()
{
if (comm_ports[i].base)
{
"COM %d - base 0x%08x\n",i,comm_ports[i].base;
if (comm_ports[i].poll)
"COM %d - base 0x%08x (polled)\n",i,comm_ports[i].base;
else
"COM %d - base 0x%08x\n",i,comm_ports[i].base;
}
}
}

I64 CommGetFifoCnt(I64 port)
{
CComm *c;
CFifoU8 *f;
I64 cnt=0;
c=&comm_ports[port];
if (Bt(&c->flags,COMf_ENABLED))
{
f=c->RX_fifo;
if (f->out_ptr>f->in_ptr)
cnt+=f->mask+1-(f->out_ptr-f->in_ptr);
else
cnt+=f->in_ptr-f->out_ptr;
}
return cnt;
}
Loading

0 comments on commit 74ab50f

Please sign in to comment.