#define DEBUG_TO_E9 1
#define DEBUG_TO_SERIAL 1
#define SERIAL_PORT 0x3F8
+#define GDB_SERIAL_PORT 0x2F8
// === IMPORTS ===
extern void Threads_Dump();
int gDebug_Level = 0;
int giDebug_KTerm = -1;
int gbDebug_SerialSetup = 0;
+ int gbGDB_SerialSetup = 0;
// === CODE ===
+int putDebugChar(char ch)
+{
+ if(!gbGDB_SerialSetup) {
+ outb(GDB_SERIAL_PORT + 1, 0x00); // Disable all interrupts
+ outb(GDB_SERIAL_PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
+ outb(GDB_SERIAL_PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
+ outb(GDB_SERIAL_PORT + 1, 0x00); // (hi byte)
+ outb(GDB_SERIAL_PORT + 3, 0x03); // 8 bits, no parity, one stop bit
+ outb(GDB_SERIAL_PORT + 2, 0xC7); // Enable FIFO with 14-byte threshold and clear it
+ outb(GDB_SERIAL_PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
+ gbDebug_SerialSetup = 1;
+ }
+ while( (inb(GDB_SERIAL_PORT + 5) & 0x20) == 0 );
+ outb(GDB_SERIAL_PORT, ch);
+ return 0;
+}
+int getDebugChar()
+{
+ if(!gbGDB_SerialSetup) {
+ outb(GDB_SERIAL_PORT + 1, 0x00); // Disable all interrupts
+ outb(GDB_SERIAL_PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
+ outb(GDB_SERIAL_PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
+ outb(GDB_SERIAL_PORT + 1, 0x00); // (hi byte)
+ outb(GDB_SERIAL_PORT + 3, 0x03); // 8 bits, no parity, one stop bit
+ outb(GDB_SERIAL_PORT + 2, 0xC7); // Enable FIFO with 14-byte threshold and clear it
+ outb(GDB_SERIAL_PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
+ gbDebug_SerialSetup = 1;
+ }
+ while( (inb(GDB_SERIAL_PORT + 5) & 1) == 0) ;
+ return inb(GDB_SERIAL_PORT);
+}
+
static void E9(char ch)
{
if(giDebug_KTerm != -1)
#if !CACHE_FAT\r
Uint32 ofs = Disk->bootsect.resvSectCount*512;\r
#endif\r
- ENTER("iHandle xCluster", handle, cluster);\r
+ ENTER("pDisk xCluster", Disk, cluster);\r
#if CACHE_FAT\r
val = Disk->FATCache[cluster];\r
+ if(Disk->type == FAT12 && val == EOC_FAT12) val = -1;\r
+ if(Disk->type == FAT16 && val == EOC_FAT16) val = -1;\r
+ if(Disk->type == FAT32 && val == EOC_FAT32) val = -1;\r
#else\r
if(Disk->type == FAT12) {\r
VFS_ReadAt(Disk->fileHandle, ofs+(cluster>>1)*3, 3, &val);\r
val = (cluster&1 ? val&0xFFF : val>>12);\r
+ if(val == EOC_FAT12) val = -1;\r
} else if(Disk->type == FAT16) {\r
VFS_ReadAt(Disk->fileHandle, ofs+cluster*2, 2, &val);\r
+ if(val == EOC_FAT16) val = -1;\r
} else {\r
VFS_ReadAt(Disk->fileHandle, ofs+cluster*4, 4, &val);\r
+ if(val == EOC_FAT32) val = -1;\r
}\r
#endif /*CACHE_FAT*/\r
LEAVE('x', val);\r
static void FAT_int_ReadCluster(int Handle, Uint32 Cluster, int Length, void *Buffer)\r
{\r
ENTER("iHandle xCluster iLength pBuffer", Handle, Cluster, Length, Buffer);\r
+ //Log("Cluster = %i (0x%x)", Cluster, Cluster);\r
VFS_ReadAt(\r
gFAT_Disks[Handle].fileHandle,\r
(gFAT_Disks[Handle].firstDataSect + (Cluster-2)*gFAT_Disks[Handle].bootsect.spc )\r
int i, cluster, pos;\r
int bpc;\r
void *tmpBuf;\r
- Uint eocMarker;\r
tFAT_VolInfo *disk = &gFAT_Disks[node->ImplInt];\r
\r
ENTER("Xoffset Xlength pbuffer", offset, length, buffer);\r
// Cluster is stored in Inode Field\r
cluster = node->Inode;\r
\r
- // Get EOC Marker\r
- if (disk->type == FAT12) eocMarker = EOC_FAT12;\r
- else if(disk->type == FAT16) eocMarker = EOC_FAT16;\r
- else if(disk->type == FAT32) eocMarker = EOC_FAT32;\r
- else {\r
- Log("ERROR: Unsupported FAT Variant.\n");\r
- free(tmpBuf);\r
- LEAVE('i', 0);\r
- return 0;\r
- }\r
- \r
// Sanity Check offset\r
if(offset > node->Size) {\r
//LOG("Reading past EOF (%i > %i)", offset, node->Size);\r
//Skip previous clusters\r
for(i=preSkip;i--;) {\r
cluster = FAT_int_GetFatValue(disk, cluster);\r
- if(cluster == eocMarker) {\r
+ if(cluster == -1) {\r
Warning("FAT_Read - Offset is past end of cluster chain mark");\r
+ LEAVE('i', 0);\r
+ return 0;\r
}\r
}\r
\r
memcpy((void*)(buffer+pos), tmpBuf, bpc);\r
pos += bpc;\r
cluster = FAT_int_GetFatValue(disk, cluster);\r
- if(cluster == eocMarker) {\r
+ if(cluster == -1) {\r
Warning("FAT_Read - Read past End of Cluster Chain");\r
free(tmpBuf);\r
LEAVE('i', 0);\r
// Set Other Data\r
node.Inode = ft->cluster | (ft->clusterHi<<16);\r
node.Size = ft->size;\r
+ LOG("ft->size = %i", ft->size);\r
node.ImplInt = parent->ImplInt;\r
node.UID = 0; node.GID = 0;\r
node.NumACLs = 1;\r
\r
// Get Byte Offset and skip\r
offset = dirpos * sizeof(fat_filetable);\r
- preSkip = (offset >> 9) / disk->bootsect.spc; // >>9 == /512\r
+ preSkip = offset / (512 * disk->bootsect.spc);\r
+ LOG("disk->bootsect.spc = %i", disk->bootsect.spc);\r
+ LOG("dirNode->size = %i", dirNode->Size);\r
cluster = dirNode->Inode; // Cluster ID\r
\r
// Do Cluster Skip\r
// - Pre FAT32 had a reserved area for the root.\r
- if( !(disk->type != FAT32 && cluster == disk->rootOffset) )\r
+ if( disk->type == FAT32 || cluster != disk->rootOffset )\r
{\r
//Skip previous clusters\r
for(a=preSkip;a--;) {\r
cluster = FAT_int_GetFatValue(disk, cluster);\r
+ // Check for end of cluster chain\r
+ if(cluster == -1) { LEAVE('n'); return NULL;}\r
}\r
}\r
\r
- // Check for end of cluster chain\r
- if((disk->type == FAT12 && cluster == EOC_FAT12)\r
- || (disk->type == FAT16 && cluster == EOC_FAT16)\r
- || (disk->type == FAT32 && cluster == EOC_FAT32)) {\r
- LEAVE('n');\r
- return NULL;\r
- }\r
- \r
// Bounds Checking (Used to spot heap overflows)\r
if(cluster > disk->clusterCount + 2)\r
{\r
return NULL;\r
}\r
\r
- LOG("cluster=0x%x, dirpos=%i\n", cluster, dirpos);\r
+ LOG("cluster=0x%x, dirpos=%i", cluster, dirpos);\r
\r
// Compute Offsets\r
// - Pre FAT32 cluster base (in sectors)\r
else\r
offset += (dirpos / 16) % disk->bootsect.spc;\r
// Offset in sector\r
- a = dirpos & 0xF;\r
+ a = dirpos % 16;\r
\r
LOG("offset=%i, a=%i", (Uint)offset, a);\r
\r
\r
LOG("name[0] = 0x%x", (Uint8)fileinfo[a].name[0]);\r
//Check if this is the last entry\r
- if(fileinfo[a].name[0] == '\0') {\r
+ if( fileinfo[a].name[0] == '\0' ) {\r
dirNode->Size = dirpos;\r
LOG("End of list");\r
LEAVE('n');\r
}\r
\r
// Check for empty entry\r
- if((Uint8)fileinfo[a].name[0] == 0xE5) {\r
- LOG("Empty Entry\n");\r
+ if( (Uint8)fileinfo[a].name[0] == 0xE5 ) {\r
+ LOG("Empty Entry");\r
LEAVE('p', VFS_SKIP);\r
return VFS_SKIP; // Skip\r
}\r
ENTER("pnode sname", node, name);\r
\r
// Fast Returns\r
- if(!name) return NULL;\r
- if(name[0] == '\0') return NULL;\r
+ if(!name || name[0] == '\0') {\r
+ LEAVE('n');\r
+ return NULL;\r
+ }\r
\r
#if USE_LFN\r
lfn = FAT_int_GetLFN(node);\r
{\r
// Load sector\r
if((i & 0xF) == 0) {\r
+ //Log("FAT_FindDir: diskOffset = 0x%x", diskOffset);\r
VFS_ReadAt(disk->fileHandle, diskOffset, 512, fileinfo);\r
diskOffset += 512;\r
}\r
// Get Real Filename\r
FAT_int_ProperFilename(tmpName, fileinfo[i&0xF].name);\r
\r
- LOG("tmpName = '%s'\n", tmpName);\r
+ LOG("tmpName = '%s'", tmpName);\r
\r
//Only Long name is case sensitive, 8.3 is not\r
#if USE_LFN\r
if( dirCluster == disk->rootOffset && disk->type != FAT32 )\r
continue;\r
dirCluster = FAT_int_GetFatValue(disk, dirCluster);\r
+ if(dirCluster == -1) break;\r
diskOffset = (disk->firstDataSect+(dirCluster-2)*disk->bootsect.spc)*512;\r
}\r
}\r