Cut down on debug, fixed tabs, made process tree be killed when root is killed
authorJohn Hodge <[email protected]>
Mon, 28 Sep 2009 01:07:08 +0000 (09:07 +0800)
committerJohn Hodge <[email protected]>
Mon, 28 Sep 2009 01:07:08 +0000 (09:07 +0800)
Kernel/arch/x86/mm_virt.c
Kernel/drv/vterm.c
Kernel/threads.c
Kernel/vfs/open.c
Usermode/Applications/CLIShell_src/main.c
Usermode/Applications/cat_src/main.c

index 7db7ced..d2d4e4b 100644 (file)
@@ -40,6 +40,7 @@
 // === IMPORTS ===
 extern Uint32  gaInitPageDir[1024];
 extern Uint32  gaInitPageTable[1024];
+extern void    Threads_SegFault(Uint Addr);
 
 // === PROTOTYPES ===
 void   MM_PreinitVirtual();
@@ -124,6 +125,12 @@ void MM_PageFault(Uint Addr, Uint ErrorCode, tRegs *Regs)
                return;
        }
        
+       // If it was a user, tell the thread handler
+       if(ErrorCode & 4) {
+               Threads_SegFault(Addr);
+               return ;
+       }
+       
        // -- Check Error Code --
        if(ErrorCode & 8)
                Warning("Reserved Bits Trashed!");
index af92717..304de69 100644 (file)
@@ -472,7 +472,7 @@ void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
        
        switch(Ch)
        {
-       case 0: return; // Ignore NULL byte
+       case '\0':      return; // Ignore NULL byte
        case '\n':
                Term->WritePos += Term->Width;
        case '\r':
@@ -481,7 +481,7 @@ void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
        
        case '\t':
                do {
-                       Term->Text[ Term->WritePos ].Ch = '\t';
+                       Term->Text[ Term->WritePos ].Ch = '\0';
                        Term->Text[ Term->WritePos ].Colour = Term->CurColour;
                        Term->WritePos ++;
                } while(Term->WritePos & 7);
@@ -493,7 +493,7 @@ void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
                
                Term->WritePos --;
                // Singe Character
-               if(Term->Text[ Term->WritePos ].Ch != '\t') {
+               if(Term->Text[ Term->WritePos ].Ch != '\0') {
                        Term->Text[ Term->WritePos ].Ch = 0;
                        Term->Text[ Term->WritePos ].Colour = Term->CurColour;
                        break;
@@ -504,7 +504,7 @@ void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
                        Term->Text[ Term->WritePos ].Ch = 0;
                        Term->Text[ Term->WritePos ].Colour = Term->CurColour;
                        Term->WritePos --;
-               } while(Term->WritePos && i-- && Term->Text[ Term->WritePos ].Ch == '\t');
+               } while(Term->WritePos && i-- && Term->Text[ Term->WritePos ].Ch == '\0');
                break;
        
        default:
index 824cb16..bcea3fa 100644 (file)
@@ -256,7 +256,10 @@ tThread *Threads_int_GetPrev(tThread **List, tThread *Thread)
  */
 void Threads_Exit(int TID, int Status)
 {
-       Threads_Kill( Proc_GetCurThread(), (Uint)Status & 0xFF );
+       if( TID == 0 )
+               Threads_Kill( Proc_GetCurThread(), (Uint)Status & 0xFF );
+       else
+               Threads_Kill( Threads_GetThread(TID), (Uint)Status & 0xFF );
 }
 
 /**
@@ -270,14 +273,14 @@ void Threads_Kill(tThread *Thread, int Status)
        tMsg    *msg;
        
        // Kill all children
-       #if 0
+       #if 1
        {
                tThread *child;
                for(child = gActiveThreads;
                        child;
                        child = child->Next)
                {
-                       if(child->PTID == gCurrentThread->TID)
+                       if(child->PTID == Thread->TID)
                                Threads_Kill(child, -1);
                }
        }
@@ -453,6 +456,7 @@ void Threads_SetSignalHandler(int Num, void *Handler)
 
 /**
  * \fn void Threads_SendSignal(int TID, int Num)
+ * \brief Send a signal to a thread
  */
 void Threads_SendSignal(int TID, int Num)
 {
@@ -574,3 +578,13 @@ tThread *Threads_GetNextToRun(int CPU)
        
        return thread;
 }
+
+/**
+ * \fn void Threads_SegFault(tVAddr Addr)
+ * \brief Called when a Segment Fault occurs
+ */
+void Threads_SegFault(tVAddr Addr)
+{
+       //Threads_SendSignal( Proc_GetCurThread()->TID, SIGSEGV );
+       Threads_Kill( Proc_GetCurThread(), 0 );
+}
index f827473..0494294 100644 (file)
@@ -121,7 +121,7 @@ char *VFS_GetAbsPath(char *Path)
        
        // `ret` should now be the absolute path
        LEAVE('s', ret);
-       Log("VFS_GetAbsPath: RETURN '%s'", ret);
+       //Log("VFS_GetAbsPath: RETURN '%s'", ret);
        return ret;
 }
 
index 8298c2a..4fe8a4a 100644 (file)
@@ -28,13 +28,15 @@ struct      {
        {"colour", Command_Colour}, {"clear", Command_Clear},\r
        {"cd", Command_Cd}, {"dir", Command_Dir}\r
 };\r
+static char    *cDEFAULT_PATH[] = {"/Acess"};\r
 #define        BUILTIN_COUNT   (sizeof(cBUILTINS)/sizeof(cBUILTINS[0]))\r
 \r
 // ==== LOCAL VARIABLES ====\r
+ int   giNumPathDirs = 1;\r
+char   **gasPathDirs = cDEFAULT_PATH;\r
 char   **gasEnvironment;\r
 char   gsCommandBuffer[1024];\r
 char   *gsCurrentDirectory = NULL;\r
-char   gsTmpBuffer[1024];\r
 char   **gasCommandHistory;\r
  int   giLastCommand = 0;\r
  int   giCommandSpace = 0;\r
@@ -45,6 +47,7 @@ int main(int argc, char *argv[], char *envp[])
        char    *sCommandStr;\r
        char    *saArgs[32];\r
         int    length = 0;\r
+        int    i;\r
         int    iArgCount = 0;\r
         int    bCached = 1;\r
        \r
@@ -105,17 +108,15 @@ int main(int argc, char *argv[], char *envp[])
                if(saArgs[1][0] == '\0')        continue;\r
                \r
                // Check Built-In Commands\r
-               //  [HACK] Mem Usage - Use Length in place of `i'\r
-               for(length=0;length<BUILTIN_COUNT;length++)\r
+               for( i = 0; i < BUILTIN_COUNT; i++ )\r
                {\r
-                       if(strcmp(saArgs[1], cBUILTINS[length].name) == 0)\r
+                       if( strcmp(saArgs[1], cBUILTINS[i].name) == 0 )\r
                        {\r
-                               cBUILTINS[length].fcn(iArgCount-1, &saArgs[1]);\r
+                               cBUILTINS[i].fcn(iArgCount-1, &saArgs[1]);\r
                                break;\r
                        }\r
                }\r
-               \r
-               if(length != BUILTIN_COUNT)     continue;\r
+               if(i != BUILTIN_COUNT)  continue;\r
                \r
                // Shall we?\r
                CallCommand( &saArgs[1] );\r
@@ -135,8 +136,7 @@ char *ReadCommandLine(int *Length)
        // Preset Variables\r
        ret = malloc( space+1 );\r
        if(!ret)        return NULL;\r
-       len = 0;\r
-       pos = 0;\r
+       len = 0;        pos = 0;\r
                \r
        // Read In Command Line\r
        do {\r
@@ -246,35 +246,64 @@ void CallCommand(char **Args)
        t_sysFInfo      info;\r
         int    pid = -1;\r
         int    fd = 0;\r
+       char    sTmpBuffer[1024];\r
+       char    *exefile = Args[0];\r
        \r
-       \r
-       // - Calling a file\r
-       GeneratePath(Args[0], gsCurrentDirectory, gsTmpBuffer);\r
-       \r
-       \r
-       // Check file existence\r
-       fd = open(gsTmpBuffer, 0);\r
-       if(fd == -1) {\r
-               Print("Unknown Command: `");Print(Args[0]);Print("'\n");        // Error Message\r
-               return ;\r
+       if(exefile[0] == '/'\r
+       || (exefile[0] == '.' && exefile[1] == '/')\r
+       || (exefile[0] == '.' && exefile[1] == '.' && exefile[2] == '/')\r
+               )\r
+       {\r
+               GeneratePath(exefile, gsCurrentDirectory, sTmpBuffer);\r
+               // Check file existence\r
+               fd = open(sTmpBuffer, OPENFLAG_EXEC);\r
+               if(fd == -1) {\r
+                       Print("Unknown Command: `");Print(Args[0]);Print("'\n");        // Error Message\r
+                       return ;\r
+               }\r
+               \r
+               // Get File info and close file\r
+               finfo( fd, &info, 0 );\r
+               close( fd );\r
+               \r
+               // Check if the file is a directory\r
+               if(info.flags & FILEFLAG_DIRECTORY) {\r
+                       Print("`");Print(sTmpBuffer);   // Error Message\r
+                       Print("' is a directory.\n");\r
+                       return ;\r
+               }\r
        }\r
-       \r
-       // Check if the file is a directory\r
-       finfo( fd, &info, 0 );\r
-       close( fd );\r
-       if(info.flags & FILEFLAG_DIRECTORY) {\r
-               Print("`");Print(gsTmpBuffer);  // Error Message\r
-               Print("' is a directory.\n");\r
-               return ;\r
+       else\r
+       {\r
+                int    i;\r
+               \r
+               // Check all components of $PATH\r
+               for( i = 0; i < giNumPathDirs; i++ )\r
+               {\r
+                       GeneratePath(exefile, gasPathDirs[i], sTmpBuffer);\r
+                       fd = open(sTmpBuffer, OPENFLAG_EXEC);\r
+                       if(fd == -1)    continue;\r
+                       finfo( fd, &info, 0 );\r
+                       close( fd );\r
+                       if(info.flags & FILEFLAG_DIRECTORY)     continue;\r
+                       // Woohoo! We found a valid command\r
+                       break;\r
+               }\r
+               \r
+               // Exhausted path directories\r
+               if( i == giNumPathDirs ) {\r
+                       Print("Unknown Command: `");Print(exefile);Print("'\n");\r
+                       return ;\r
+               }\r
        }\r
        \r
        // Create new process\r
        pid = clone(CLONE_VM, 0);\r
        // Start Task\r
        if(pid == 0)\r
-               execve(gsTmpBuffer, Args, gasEnvironment);\r
+               execve(sTmpBuffer, Args, gasEnvironment);\r
        if(pid <= 0) {\r
-               Print("Unablt to create process: `");Print(gsTmpBuffer);Print("'\n");   // Error Message\r
+               Print("Unablt to create process: `");Print(sTmpBuffer);Print("'\n");    // Error Message\r
        }\r
        else {\r
                 int    status;\r
@@ -294,7 +323,6 @@ void Command_Colour(int argc, char **argv)
        // Verify Arg Count\r
        if(argc < 2)\r
        {\r
-               Print("Please specify a colour\n");\r
                goto usage;\r
        }\r
        \r
@@ -335,6 +363,7 @@ void Command_Colour(int argc, char **argv)
 \r
        // Function Usage (Requested via a Goto (I know it's ugly))\r
 usage:\r
+       Print("Usage: colour <foreground> [<background>]\n");\r
        Print("Valid Colours are ");\r
        for(fg=0;fg<8;fg++)\r
        {\r
@@ -345,6 +374,10 @@ usage:
        return;\r
 }\r
 \r
+/**\r
+ * \fn void Command_Clear(int argc, char **argv)\r
+ * \brief Clear the screen\r
+ */\r
 void Command_Clear(int argc, char **argv)\r
 {\r
        write(_stdout, 4, "\x1B[2J");   //Clear Screen\r
index a7f3ab3..8fc8463 100644 (file)
@@ -7,6 +7,10 @@
 
 #define        BUF_SIZE        1024
 
+/**
+ * \fn int main(int argc, char *argv[])
+ * \brief Entrypoint
+ */
 int main(int argc, char *argv[])
 {
         int    fd;
@@ -18,7 +22,6 @@ int main(int argc, char *argv[])
                return -1;
        }
 
-       //printf("Contents of `%s'\n", argv[1]);
        fd = open(argv[1], OPENFLAG_READ);
        if(fd == -1) {
                printf("Unable to open '%s' for reading\n", argv[1]);
@@ -27,7 +30,6 @@ int main(int argc, char *argv[])
 
        do {
                num = read(fd, BUF_SIZE, buf);
-               //printf("num = %i\n", num);
                buf[num] = '\0';
                printf("%s", buf);
        } while(num == BUF_SIZE);

UCC git Repository :: git.ucc.asn.au