-BUILD_NUM = 1868
+BUILD_NUM = 1933
#else
__asm__ __volatile__ ("mov %0, %%cr3"::"a"(thread->MemState.CR3));
#endif
+
+ #if 0
+ if(thread->SavedState.ESP > 0xC0000000
+ && thread->SavedState.ESP < thread->KernelStack-0x2000) {
+ Log_Warning("Proc", "Possible bad ESP %p (PID %i)", thread->SavedState.ESP);
+ }
+ #endif
+
// Switch threads
__asm__ __volatile__ (
"mov %1, %%esp\n\t" // Restore ESP
return inb(GDB_SERIAL_PORT);
}
+volatile int gbInPutChar = 0;
+
static void Debug_Putchar(char ch)
{
- if(giDebug_KTerm != -1)
- VFS_Write(giDebug_KTerm, 1, &ch);
-
+ #if DEBUG_TO_E9
+ __asm__ __volatile__ ( "outb %%al, $0xe9" :: "a"(((Uint8)ch)) );
+ #endif
+
#if DEBUG_TO_SERIAL
if(!gbDebug_SerialSetup) {
outb(SERIAL_PORT + 1, 0x00); // Disable all interrupts
while( (inb(SERIAL_PORT + 5) & 0x20) == 0 );
outb(SERIAL_PORT, ch);
#endif
-
- #if DEBUG_TO_E9
- __asm__ __volatile__ ( "outb %%al, $0xe9" :: "a"(((Uint8)ch)) );
- #endif
+
+ if(gbInPutChar) return ;
+ gbInPutChar = 1;
+ if(giDebug_KTerm != -1)
+ VFS_Write(giDebug_KTerm, 1, &ch);
+ gbInPutChar = 0;
}
static void Debug_Puts(char *Str)
void Debug_SetKTerminal(char *File)
{
- if(giDebug_KTerm != -1)
- VFS_Close(giDebug_KTerm);
- giDebug_KTerm = VFS_Open(File, VFS_OPENFLAG_WRITE);
- Log_Log("Debug", "Opened '%s' as 0x%x", File, giDebug_KTerm);
+ int tmp;
+ if(giDebug_KTerm != -1) {
+ tmp = giDebug_KTerm;
+ giDebug_KTerm = -1;
+ VFS_Close(tmp);
+ }
+ tmp = VFS_Open(File, VFS_OPENFLAG_WRITE);
+ Log_Log("Debug", "Opened '%s' as 0x%x", File, tmp);
+ giDebug_KTerm = tmp;
+ Log_Log("Debug", "Returning to %p", __builtin_return_address(0));
}
void Debug_Enter(char *FuncName, char *ArgTypes, ...)
/*
* Acess2 VGA Controller Driver
*/
+#define DEBUG 0
#include <acess.h>
#include <fs_devfs.h>
#include <tpl_drv_video.h>
/*
* Acess2 Virtual Terminal Driver
*/
-#define DEBUG 1
+#define DEBUG 0
#include <acess.h>
#include <fs_devfs.h>
#include <modules.h>
// --- Video State ---
short giVT_RealWidth; //!< Real Width
short giVT_RealHeight; //!< Real Height
- int gbVT_TextMode = 1;
// --- Driver Handles ---
char *gsVT_OutputDevice = NULL;
char *gsVT_InputDevice = NULL;
strcpy(gsVT_InputDevice, args[1]);
args ++;
break;
-
}
}
}
// Set kernel output to VT0
Debug_SetKTerminal("/Devices/VTerm/0");
+ Log_Log("VTerm", "Returning %i", MODULE_ERR_OK);
return MODULE_ERR_OK;
}
{
int num;
- //ENTER("pNode sName", Node, Name);
+ ENTER("pNode sName", Node, Name);
// Open the input and output files if needed
if(giVT_OutputDevHandle == -2) VT_InitOutput();
return NULL;
}
// Return node
- //LEAVE('p', &gVT_Terminals[num].Node);
+ LEAVE('p', &gVT_Terminals[num].Node);
return &gVT_Terminals[num].Node;
}
}
break;
- case TERM_MODE_FB:
- //case TERM_MODE_:
+ //case TERM_MODE_FB:
+ default:
while(pos < Length)
{
while(term->InputRead == term->InputWrite) Threads_Yield();
{
tVTerm *term = &gVT_Terminals[ Node->Inode ];
- //ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
-
// Write
switch( term->Mode )
{
}
}
- //LEAVE('i', 0);
return 0;
}
memcpy(
Term->Text,
&Term->Text[Term->Width],
- Term->Width*(Term->Height-1)*VT_SCROLLBACK*sizeof(tVT_Char)
+ (Term->Width*Term->Height*VT_SCROLLBACK-Term->Width)*sizeof(tVT_Char)
);
// Clear last row
Term->Text[ base + i ].Colour = Term->CurColour;
}
+ //LOG("Scrolled buffer");
VT_int_UpdateScreen( Term, 1 );
}
else if(Term->WritePos > Term->Width*Term->Height+Term->ViewPos)
{
Term->ViewPos += Term->Width;
+ //LOG("Scrolled screen");
VT_int_UpdateScreen( Term, 1 );
}
else
if( Term->Mode == TERM_MODE_TEXT )
{
- if(gbVT_TextMode)
- {
- if(UpdateAll) {
- VFS_WriteAt(
- giVT_OutputDevHandle,
- 0,
- Term->Width*Term->Height*sizeof(tVT_Char),
- &Term->Text[Term->ViewPos]
- );
- } else {
- int pos = Term->WritePos - Term->WritePos % Term->Width;
- VFS_WriteAt(
- giVT_OutputDevHandle,
- (pos - Term->ViewPos)*sizeof(tVT_Char),
- Term->Width*sizeof(tVT_Char),
- &Term->Text[pos]
- );
- }
- }
- else
- {
- //TODO: Do VT Rendered Text
- #if 0
- if( UpdateAll ) {
- VT_RenderText(0, Term->Width*Term->Height, &Term->Text[Term->ViewPos]);
- }
- else {
- int pos = Term->WritePos - Term->WritePos % Term->Width;
- VT_RenderText(
- pos - Term->ViewPos,
- Term->Width,
- &Term->Text[pos]
- );
- }
- #endif
+ if(UpdateAll) {
+ //LOG("UpdateAll = 1");
+ //LOG("VFS_WriteAt(0x%x, 0, %i*sizeof(tVT_Char), &Term->Text[%i])",
+ // giVT_OutputDevHandle, Term->Width*Term->Height, Term->ViewPos);
+ VFS_WriteAt(
+ giVT_OutputDevHandle,
+ 0,
+ Term->Width*Term->Height*sizeof(tVT_Char),
+ &Term->Text[Term->ViewPos]
+ );
+ } else {
+ int pos = Term->WritePos - Term->WritePos % Term->Width;
+ //LOG("UpdateAll = 0");
+ //LOG("VFS_WriteAt(0x%x, %i*sizeof(tVT_Char), %i*sizeof(tVT_Char), &Term->Text[%i])",
+ // giVT_OutputDevHandle, (pos - Term->ViewPos), Term->Width, pos);
+ VFS_WriteAt(
+ giVT_OutputDevHandle,
+ (pos - Term->ViewPos)*sizeof(tVT_Char),
+ Term->Width*sizeof(tVT_Char),
+ &Term->Text[pos]
+ );
}
}
else
LEAVE_RET('i', ret);
return ret;
}
+ LOG("ret = %i", ret);
// Remove from loading list
gLoadingModules = gLoadingModules->Next;
{
tVFS_Handle *h;
+ //Log_Debug("VFS", "VFS_GetHandle: (FD=0x%x)", FD);
+
if(FD < 0) return NULL;
if(FD & VFS_KERNEL_FLAG) {
}
if(h->Node == NULL) return NULL;
+ //Log_Debug("VFS", "VFS_GetHandle: RETURN %p", h);
return h;
}
};\r
tSpinlock glVesa_Lock;\r
tVM8086 *gpVesa_BiosState;\r
- int giVesaCurrentMode = -1;\r
+ int giVesaCurrentMode = 0;\r
int giVesaCurrentFormat = VIDEO_BUFFMT_TEXT;\r
int giVesaDriverId = -1;\r
char *gVesaFramebuffer = (void*)0xC00A0000;\r
gVesa_Modes[i].fbSize = 0;\r
}\r
\r
+ gVesa_Modes[i].pitch = modeinfo->pitch;\r
gVesa_Modes[i].width = modeinfo->Xres;\r
gVesa_Modes[i].height = modeinfo->Yres;\r
gVesa_Modes[i].bpp = modeinfo->bpp;\r
// Default Text mode\r
if( giVesaCurrentMode == 0 )\r
{\r
- Uint8 *fb = (Uint8 *)(KERNEL_BASE|0xB8000);\r
- Uint32 *buf = Buffer;\r
+ Uint16 *fb = (Uint16*)(KERNEL_BASE|0xB8000);\r
+ tVT_Char *chars = Buffer;\r
int rem;\r
\r
if( giVesaCurrentFormat != VIDEO_BUFFMT_TEXT ) {\r
return -1;\r
}\r
\r
- if( Offset + Length > 25*80*8 ) {\r
+ if( Offset + Length > 25*80*sizeof(tVT_Char) ) {\r
Log_Warning("VESA", "Vesa_Write - Framebuffer Overflow");\r
LEAVE('i', 0);\r
return 0;\r
}\r
\r
- fb += 2*Offset;\r
- for(rem = Length / sizeof(tVT_Char); rem --; fb += 2)\r
+ fb += 2*(Offset/sizeof(tVT_Char));\r
+ LOG("fb = %p", fb);\r
+ for(rem = Length / sizeof(tVT_Char); rem --; fb ++, chars++)\r
{\r
- if( *buf < 0x80 )\r
- *fb = *buf & 0x7F;\r
+ if( chars->Ch < 0x80 )\r
+ *fb = chars->Ch & 0x7F;\r
else\r
*fb = 0x00;\r
- buf ++;\r
\r
- fb[1] = 0;\r
- fb[1] |= (*buf & 0x888) == 0x888 ? 0x8 : 0;\r
- fb[1] |= (*buf & 0x700) > 0x300 ? 0x4 : 0;\r
- fb[1] |= (*buf & 0x070) > 0x030 ? 0x2 : 0;\r
- fb[1] |= (*buf & 0x007) > 0x003 ? 0x1 : 0;\r
- fb[1] |= (*buf & 0x888000) == 0x888000 ? 0x80 : 0;\r
- fb[1] |= (*buf & 0x700000) > 0x300000 ? 0x40 : 0;\r
- fb[1] |= (*buf & 0x070000) > 0x030000 ? 0x20 : 0;\r
- fb[1] |= (*buf & 0x007000) > 0x003000 ? 0x10 : 0;\r
- buf ++;\r
+ *fb |= (chars->FGCol & 0x888) == 0x888 ? 0x8 : 0;\r
+ *fb |= (chars->FGCol & 0x700) > 0x300 ? 0x4 : 0;\r
+ *fb |= (chars->FGCol & 0x070) > 0x030 ? 0x2 : 0;\r
+ *fb |= (chars->FGCol & 0x007) > 0x003 ? 0x1 : 0;\r
+ *fb |= (chars->BGCol & 0x888) == 0x888 ? 0x80 : 0;\r
+ *fb |= (chars->BGCol & 0x700) > 0x300 ? 0x40 : 0;\r
+ *fb |= (chars->BGCol & 0x070) > 0x030 ? 0x20 : 0;\r
+ *fb |= (chars->BGCol & 0x007) > 0x003 ? 0x10 : 0;\r
+ //LOG("%08x (%03x,%03x) = %04x",\r
+ // chars->Ch, chars->BGCol, chars->FGCol, *fb);\r
}\r
Length /= sizeof(tVT_Char);\r
Length *= sizeof(tVT_Char);\r
\r
Offset /= sizeof(tVT_Char);\r
dest = (void*)gVesaFramebuffer;\r
- x = (Offset % gVesa_Modes[giVesaCurrentMode].width) * giVT_CharWidth;\r
- y = (Offset / gVesa_Modes[giVesaCurrentMode].width) * giVT_CharHeight;\r
+ LOG("gVesa_Modes[%i].width = %i", giVesaCurrentMode, gVesa_Modes[giVesaCurrentMode].width);\r
+ x = (Offset % (gVesa_Modes[giVesaCurrentMode].width/giVT_CharWidth)) * giVT_CharWidth;\r
+ y = (Offset / (gVesa_Modes[giVesaCurrentMode].width/giVT_CharWidth)) * giVT_CharHeight;\r
+ LOG("(x,y) = (%i,%i)", x, y);\r
\r
// Sanity Check\r
if(y > gVesa_Modes[giVesaCurrentMode].height) {\r
IPv4_RegisterCallback(IP4PROT_TCP, TCP_GetPacket);
}
-/**
- * \brief Open a connection to another host using TCP
- * \param Conn Connection structure
- */
-void TCP_StartConnection(tTCPConnection *Conn)
-{
- tTCPHeader hdr;
-
- Conn->State = TCP_ST_SYN_SENT;
-
- hdr.SourcePort = htons(Conn->LocalPort);
- hdr.DestPort = htons(Conn->RemotePort);
- Conn->NextSequenceSend = rand();
- hdr.SequenceNumber = htonl(Conn->NextSequenceSend);
- hdr.DataOffset = (sizeof(tTCPHeader)/4) << 4;
- hdr.Flags = TCP_FLAG_SYN;
- hdr.WindowSize = htons(TCP_WINDOW_SIZE); // Max
- hdr.Checksum = 0; // TODO
- hdr.UrgentPointer = 0;
-
- TCP_SendPacket( Conn, sizeof(tTCPHeader), &hdr );
- return ;
-}
-
/**
* \brief Sends a packet from the specified connection, calculating the checksums
* \param Conn Connection
if( Connection->State == TCP_ST_SYN_SENT )
{
- if( Header->Flags & (TCP_FLAG_SYN|TCP_FLAG_ACK) ) {
+ if( (Header->Flags & (TCP_FLAG_SYN|TCP_FLAG_ACK)) == (TCP_FLAG_SYN|TCP_FLAG_ACK) ) {
Header->DestPort = Header->SourcePort;
Header->SourcePort = htons(Connection->LocalPort);
Header->DataOffset = (sizeof(tTCPHeader)/4) << 4;
Log_Log("TCP", "ACKing SYN-ACK");
TCP_SendPacket( Connection, sizeof(tTCPHeader), Header );
+ Connection->State = TCP_ST_OPEN;
}
- Connection->State = TCP_ST_OPEN;
}
// Get length of data
// TODO: Check what to do here
if(Header->Flags & TCP_FLAG_FIN) {
if( Connection->State == TCP_ST_FIN_SENT ) {
-
+ Connection->State = TCP_ST_FINISHED;
+ return ;
}
else {
Connection->State = TCP_ST_FINISHED;
conn->Node.IOCtl = TCP_Client_IOCtl;
conn->Node.Close = TCP_Client_Close;
+ conn->RecievedBuffer = RingBuffer_Create( TCP_RECIEVE_BUFFER_SIZE );
+
LOCK(&glTCP_OutbountCons);
conn->Next = gTCP_OutbountCons;
gTCP_OutbountCons = conn;
size_t len;
ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
+ LOG("conn = %p", conn);
+ LOG("conn->State = %i", conn->State);
// Check if connection is open
- while( conn->State == TCP_ST_HALFOPEN ) Threads_Yield();
+ while( conn->State == TCP_ST_HALFOPEN || conn->State == TCP_ST_SYN_SENT )
+ Threads_Yield();
if( conn->State != TCP_ST_OPEN ) {
LEAVE('i', 0);
return 0;
packet->DataOffset = (sizeof(tTCPHeader)/4)*16;
packet->WindowSize = TCP_WINDOW_SIZE;
- //packet->AcknowlegementNumber = htonl(Connection->NextSequenceRcv);
- packet->AcknowlegementNumber = 0;
+ packet->AcknowlegementNumber = htonl(Connection->NextSequenceRcv);
packet->SequenceNumber = htonl(Connection->NextSequenceSend);
- packet->Flags = TCP_FLAG_PSH; // Hey, ACK if you can!
+ packet->Flags = TCP_FLAG_PSH|TCP_FLAG_ACK; // Hey, ACK if you can!
memcpy(packet->Options, Data, Length);
ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
// Check if connection is open
- while( conn->State == TCP_ST_HALFOPEN ) Threads_Yield();
+ while( conn->State == TCP_ST_HALFOPEN || conn->State == TCP_ST_SYN_SENT )
+ Threads_Yield();
if( conn->State != TCP_ST_OPEN ) {
LEAVE('i', 0);
return 0;
return Length;
}
+/**
+ * \brief Open a connection to another host using TCP
+ * \param Conn Connection structure
+ */
+void TCP_StartConnection(tTCPConnection *Conn)
+{
+ tTCPHeader hdr;
+
+ Conn->State = TCP_ST_SYN_SENT;
+
+ hdr.SourcePort = htons(Conn->LocalPort);
+ hdr.DestPort = htons(Conn->RemotePort);
+ Conn->NextSequenceSend = rand();
+ hdr.SequenceNumber = htonl(Conn->NextSequenceSend);
+ hdr.DataOffset = (sizeof(tTCPHeader)/4) << 4;
+ hdr.Flags = TCP_FLAG_SYN;
+ hdr.WindowSize = htons(TCP_WINDOW_SIZE); // Max
+ hdr.Checksum = 0; // TODO
+ hdr.UrgentPointer = 0;
+
+ TCP_SendPacket( Conn, sizeof(tTCPHeader), &hdr );
+
+ Conn->NextSequenceSend ++;
+ Conn->State = TCP_ST_SYN_SENT;
+ return ;
+}
+
/**
* \brief Control a client socket
*/
return 0;
case 7: // Connect
- if(conn->LocalPort == -1)
+ if(conn->LocalPort == 0xFFFF)
conn->LocalPort = TCP_GetUnusedPort();
if(conn->RemotePort == -1)
return 0;
void TCP_Client_Close(tVFS_Node *Node)
{
- free(Node->ImplPtr);
+ tTCPConnection *conn = Node->ImplPtr;
+ tTCPHeader packet;
+
+ packet.SourcePort = htons(conn->LocalPort);
+ packet.DestPort = htons(conn->RemotePort);
+ packet.DataOffset = (sizeof(tTCPHeader)/4)*16;
+ packet.WindowSize = TCP_WINDOW_SIZE;
+
+ packet.AcknowlegementNumber = 0;
+ packet.SequenceNumber = htonl(conn->NextSequenceSend);
+ packet.Flags = TCP_FLAG_FIN;
+
+ conn->State = TCP_ST_FIN_SENT;
+
+ TCP_SendPacket( conn, sizeof(tTCPHeader), &packet );
+
+ while( conn->State == TCP_ST_FIN_SENT ) Threads_Yield();
+
+ free(conn);
}