Working on GUI, side changes to the message passing
authorJohn Hodge <tpg@prelude.(none)>
Tue, 2 Feb 2010 12:16:35 +0000 (20:16 +0800)
committerJohn Hodge <tpg@prelude.(none)>
Tue, 2 Feb 2010 12:16:35 +0000 (20:16 +0800)
Kernel/Makefile.BuildNum
Kernel/messages.c
Kernel/syscalls.c
Usermode/Applications/axwin2_src/WM/Makefile [new file with mode: 0644]
Usermode/Applications/axwin2_src/WM/commandline.c [new file with mode: 0644]
Usermode/Applications/axwin2_src/WM/common.h [new file with mode: 0644]
Usermode/Applications/axwin2_src/WM/helpers.c [new file with mode: 0644]
Usermode/Applications/axwin2_src/WM/main.c [new file with mode: 0644]
Usermode/Applications/axwin2_src/WM/messages.c [new file with mode: 0644]
Usermode/Applications/axwin2_src/WM/video.c [new file with mode: 0644]
Usermode/include/axwin/messages.h [new file with mode: 0644]

index 3cd471c..d38d7b9 100644 (file)
@@ -1 +1 @@
-BUILD_NUM = 1407
+BUILD_NUM = 1408
index c5e14c9..aaedf5c 100644 (file)
@@ -94,7 +94,15 @@ int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer)
        
        // Get message
        if(Buffer != GETMSG_IGNORE)
+       {
+               if( !CheckMem( Buffer, cur->Messages->Length ) )
+               {
+                       *Err = -EINVAL;
+                       RELEASE( &cur->IsLocked );
+                       return -1;
+               }
                memcpy(Buffer, cur->Messages->Data, cur->Messages->Length);
+       }
        ret = cur->Messages->Length;
        
        // Remove from list
index a555720..523b3f2 100644 (file)
@@ -118,9 +118,10 @@ void SyscallHandler(tSyscallRegs *Regs)
        // -- Check for messages
        case SYS_GETMSG:
                CHECK_NUM_NULLOK(Regs->Arg1, sizeof(Uint));
-               //NOTE: Uncertain due to length being unknown
-               // (Proc_GetMessage should check itself)
-               CHECK_NUM_NULLOK(Regs->Arg2, sizeof(Uint)*4);
+               if( Regs->Arg2 && Regs->Arg2 != -1 && !MM_IsUser(Regs->Arg2) )
+               {
+                       err = -EINVAL;  ret = -1;       break;
+               }
                // *Source, *Data
                ret = Proc_GetMessage(&err, (Uint*)Regs->Arg1, (void*)Regs->Arg2);
                break;
diff --git a/Usermode/Applications/axwin2_src/WM/Makefile b/Usermode/Applications/axwin2_src/WM/Makefile
new file mode 100644 (file)
index 0000000..7fa1000
--- /dev/null
@@ -0,0 +1,11 @@
+# Project: Acess GUI Window Manager
+
+-include ../../Makefile.cfg
+
+CPPFLAGS += -I../include
+
+DIR = Apps/AxWin/1.0
+BIN = ../AxWinWM
+OBJ = main.o helpers.o commandline.o video.o messages.o
+
+-include ../../Makefile.tpl
diff --git a/Usermode/Applications/axwin2_src/WM/commandline.c b/Usermode/Applications/axwin2_src/WM/commandline.c
new file mode 100644 (file)
index 0000000..df6328f
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Acess GUI (AxWin) Version 2
+ * By John Hodge (thePowersGang)
+ */
+#include "common.h"
+#include <string.h>
+
+// === PROTOTYPES ===
+void   ShowUsage(char *ProgName);
+void   ShowHelp(char *ProgName);
+
+// === CODE ===
+void ParseCommandline(int argc, char *argv[])
+{
+        int    i;
+       char    *arg;
+       
+       for( i = 1; i < argc; i++ )
+       {
+               arg = argv[i];
+               if(arg[0] == '-')
+               {
+                       if( arg[1] == '-' )
+                       {
+                               if( strcmp(&arg[2], "help") == 0 ) {
+                                       ShowHelp(argv[0]);
+                                       exit(EXIT_SUCCESS);
+                               }
+                               else {
+                                       ShowUsage(argv[0]);
+                                       exit(EXIT_FAILURE);
+                               }
+                       }
+                       else
+                       {
+                               while( *++arg )
+                               {
+                                       switch(*arg)
+                                       {
+                                       case 'h':
+                                       case '?':
+                                               ShowHelp(argv[0]);
+                                               exit(EXIT_SUCCESS);
+                                               break;
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
+void ShowUsage(char *ProgName)
+{
+       fprintf(stderr, "Usage: %s [-h|--help]\n", ProgName);
+}
+
+void ShowHelp(char *ProgName)
+{
+       ShowUsage(ProgName);
+       fprintf(stderr, "\n");
+       fprintf(stderr, "\t--help\tShow this message\n");
+}
diff --git a/Usermode/Applications/axwin2_src/WM/common.h b/Usermode/Applications/axwin2_src/WM/common.h
new file mode 100644 (file)
index 0000000..0b3e8fc
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Acess GUI (AxWin) Version 2
+ * By John Hodge (thePowersGang)
+ */
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+
+extern char    *gsTerminalDevice;
+extern char    *gsMouseDevice;
+
+extern int     giScreenWidth;
+extern int     giScreenHeight;
+extern uint32_t        *gpScreenBuffer;
+
+extern int     giTerminalFD;
+extern int     giMouseFD;
+
+// === Functions ===
+extern void    memset32(void *ptr, uint32_t val, size_t count);
+
+#endif
diff --git a/Usermode/Applications/axwin2_src/WM/helpers.c b/Usermode/Applications/axwin2_src/WM/helpers.c
new file mode 100644 (file)
index 0000000..d923817
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+ * Acess GUI (AxWin) Version 2
+ * By John Hodge (thePowersGang)
+ */
+#include "common.h"
+
+// === CODE ===
+void memset32(void *ptr, uint32_t val, size_t count)
+{
+       __asm__ __volatile__ ("rep stosl" : : "D"(ptr),"a"(val),"c"(count));
+}
diff --git a/Usermode/Applications/axwin2_src/WM/main.c b/Usermode/Applications/axwin2_src/WM/main.c
new file mode 100644 (file)
index 0000000..13039a3
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Acess GUI (AxWin) Version 2
+ * By John Hodge (thePowersGang)
+ */
+#include "common.h"
+#include <acess/sys.h>
+
+// === IMPORTS ===
+extern void    ParseCommandline(int argc, char *argv[]);
+extern void    Video_Setup();
+
+// === GLOBALS ===
+char   *gsTerminalDevice = NULL;
+char   *gsMouseDevice = NULL;
+
+ int   giScreenWidth = 640;
+ int   giScreenHeight = 480;
+uint32_t       *gpScreenBuffer = NULL;
+
+ int   giTerminalFD = -1;
+ int   giMouseFD = -1;
+
+// === CODE ===
+/**
+ * \brief Program Entrypoint
+ */
+int main(int argc, char *argv[])
+{
+       ParseCommandline(argc, argv);
+       
+       if( gsTerminalDevice == NULL ) {
+               gsTerminalDevice = "/Devices/VTerm/7";
+       }
+       
+       Video_Setup();
+       
+       // Main Loop
+       for(;;)
+       {
+               yield();
+       }
+       return 0;
+}
diff --git a/Usermode/Applications/axwin2_src/WM/messages.c b/Usermode/Applications/axwin2_src/WM/messages.c
new file mode 100644 (file)
index 0000000..f10e6bb
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Acess GUI (AxWin) Version 2
+ * By John Hodge (thePowersGang)
+ */
+#include "common.h"
+#include <acess/sys.h>
+#include <axwin/messages.h>
+
+#define STATICBUF_SIZE 64
+
+// === TYPES ===
+typedef void tMessages_Handle_Callback(int, size_t,void*);
+
+// === PROTOTYPES ===
+void   Messages_PollIPC();
+void   Messages_RespondIPC(int ID, size_t Length, void *Data);
+void   Messages_Handle(tAxWin_Message *Msg, tMessages_Handle_Callback *Respond, int ID);
+
+// === GLOBALS ===
+
+// === CODE ===
+void Messages_PollIPC()
+{
+        int    len;
+        int    tid = 0;
+       char    staticBuf[STATICBUF_SIZE];
+       tAxWin_Message  *msg;
+       
+       // Wait for a message
+       while( (len = SysGetMessage(&tid, NULL)) )
+               yield();
+       
+       // Allocate the space for it
+       if( len <= STATICBUF_SIZE )
+               msg = (void*)staticBuf;
+       else {
+               msg = malloc( len );
+               if(!msg) {
+                       fprintf(
+                               stderr,
+                               "ERROR - Unable to allocate message buffer, ignoring message from %i\n",
+                               tid);
+                       SysGetMessage(NULL, GETMSG_IGNORE);
+                       return ;
+               }
+       }
+       
+       // Get message data
+       SysGetMessage(NULL, msg);
+       
+       Messages_Handle(msg, Messages_RespondIPC, tid);
+}
+
+void Messages_RespondIPC(int ID, size_t Length, void *Data)
+{
+       SysSendMessage(ID, Length, Data);
+}
+
+void Messages_Handle(tAxWin_Message *Msg, tMessages_Handle_Callback *Respond, int ID)
+{
+       switch(Msg->ID)
+       {
+       case MSG_REQ_PING:
+               Msg->ID = MSG_RSP_PONG;
+               Respond(ID, sizeof(Msg->ID), Msg);
+               break;
+       default:
+               fprintf(stderr, "WARNING: Unknown message %i from %i (%p)\n",
+                       Msg->ID, ID, Respond);
+               break;
+       }
+}
+
diff --git a/Usermode/Applications/axwin2_src/WM/video.c b/Usermode/Applications/axwin2_src/WM/video.c
new file mode 100644 (file)
index 0000000..00dbe16
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Acess GUI (AxWin) Version 2
+ * By John Hodge (thePowersGang)
+ */
+#include "common.h"
+#include <acess/sys.h>
+#include <acess/devices/terminal.h>
+
+// === PROTOTYPES ===
+void   Video_Setup();
+void   Video_Update();
+
+// === GLOBALS ===
+
+// === CODE ===
+void Video_Setup()
+{
+        int    tmpInt;
+       
+       // Open terminal
+       giTerminalFD = open(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE);
+       if( giTerminalFD == -1 )
+       {
+               fprintf(stderr, "ERROR: Unable to open '%s' (%i)\n", gsTerminalDevice, _errno);
+               exit(-1);
+       }
+       
+       // Set width
+       tmpInt = giScreenWidth;
+       tmpInt = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, &tmpInt );
+       if(tmpInt != giScreenWidth)
+       {
+               fprintf(stderr, "Warning: Selected width (%i) is invalid, clipped to %i\n",
+                       giScreenWidth, tmpInt);
+               giScreenWidth = tmpInt;
+       }
+       
+       // Set height
+       tmpInt = giScreenHeight;
+       tmpInt = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, &tmpInt );
+       if(tmpInt != giScreenHeight)
+       {
+               fprintf(stderr, "Warning: Selected height (%i) is invalid, clipped to %i\n",
+                       giScreenHeight, tmpInt);
+               giScreenHeight = tmpInt;
+       }
+       
+       // Set mode to video
+       tmpInt = TERM_MODE_FB;
+       ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
+       
+       // Force VT8 to be shown
+       ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
+       
+       // Create local framebuffer (back buffer)
+       gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 );
+       memset32( gpScreenBuffer, 0x8888FF, giScreenWidth*giScreenHeight );
+       Video_Update();
+}
+
+void Video_Update()
+{
+       seek(giTerminalFD, 0, SEEK_SET);
+       write(giTerminalFD, giScreenWidth*giScreenHeight*4, gpScreenBuffer);
+}
diff --git a/Usermode/include/axwin/messages.h b/Usermode/include/axwin/messages.h
new file mode 100644 (file)
index 0000000..c11b864
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * \file messages.h
+ * \author John Hodge (thePowersGang)
+ * \brief AxWin Control Messages and structures
+ */
+#ifndef _AXWIN_MESSAGES_H
+#define _AXWIN_MESSAGES_H
+
+typedef struct sAxWin_Message  tAxWin_Message;
+
+/**
+ * \brief Message IDs
+ */
+enum eAxWin_Messages
+{
+       // Server Requests
+       MSG_SREQ_PING,
+       // - Windows
+       MSG_SREQ_NEWWINDOW,
+       MSG_SREQ_GETFLAGS,      MSG_SREQ_SETFLAGS,
+       MSG_SREQ_GETRECT,       MSG_SREQ_SETRECT,
+       // - Drawing
+       MSG_SREQ_SETCOL,
+       MSG_SREQ_PSET,
+       MSG_SREQ_LINE,  MSG_SREQ_CURVE,
+       MSG_SREQ_RECT,  MSG_SREQ_FILLRECT,
+       MSG_SREQ_RIMG,  MSG_SREQ_SIMG,  // Register/Set Image
+       MSG_SREQ_SETFONT,       MSG_SREQ_PUTTEXT,
+       
+       // Server Responses
+       MSG_SRSP_PONG,
+       MSG_SRSP_IMG,   // Returns the image ID
+       
+       NUM_MSG
+};
+
+/**
+ * \brief New Window Request structure
+ */
+struct sAxWin_Req_NewWindow
+{
+       
+};
+
+/**
+ * \brief Overarching Message Structure
+ * \note sizeof(tAxWin_Message) is never valid
+ */
+struct sAxWin_Message
+{
+       uint16_t        ID;
+       uint16_t        Size;   //!< Size in DWORDS
+};
+
+#endif

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