From 1c2a87ec67d332b6a165c79398693eac1eb1166e Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 2 Feb 2010 20:16:35 +0800 Subject: [PATCH] Working on GUI, side changes to the message passing --- Kernel/Makefile.BuildNum | 2 +- Kernel/messages.c | 8 ++ Kernel/syscalls.c | 7 +- Usermode/Applications/axwin2_src/WM/Makefile | 11 +++ .../Applications/axwin2_src/WM/commandline.c | 62 ++++++++++++++++ Usermode/Applications/axwin2_src/WM/common.h | 25 +++++++ Usermode/Applications/axwin2_src/WM/helpers.c | 11 +++ Usermode/Applications/axwin2_src/WM/main.c | 44 +++++++++++ .../Applications/axwin2_src/WM/messages.c | 73 +++++++++++++++++++ Usermode/Applications/axwin2_src/WM/video.c | 65 +++++++++++++++++ Usermode/include/axwin/messages.h | 55 ++++++++++++++ 11 files changed, 359 insertions(+), 4 deletions(-) create mode 100644 Usermode/Applications/axwin2_src/WM/Makefile create mode 100644 Usermode/Applications/axwin2_src/WM/commandline.c create mode 100644 Usermode/Applications/axwin2_src/WM/common.h create mode 100644 Usermode/Applications/axwin2_src/WM/helpers.c create mode 100644 Usermode/Applications/axwin2_src/WM/main.c create mode 100644 Usermode/Applications/axwin2_src/WM/messages.c create mode 100644 Usermode/Applications/axwin2_src/WM/video.c create mode 100644 Usermode/include/axwin/messages.h diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 3cd471cb..d38d7b9c 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 1407 +BUILD_NUM = 1408 diff --git a/Kernel/messages.c b/Kernel/messages.c index c5e14c94..aaedf5c0 100644 --- a/Kernel/messages.c +++ b/Kernel/messages.c @@ -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 diff --git a/Kernel/syscalls.c b/Kernel/syscalls.c index a555720f..523b3f2a 100644 --- a/Kernel/syscalls.c +++ b/Kernel/syscalls.c @@ -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 index 00000000..7fa10003 --- /dev/null +++ b/Usermode/Applications/axwin2_src/WM/Makefile @@ -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 index 00000000..df6328f0 --- /dev/null +++ b/Usermode/Applications/axwin2_src/WM/commandline.c @@ -0,0 +1,62 @@ +/* + * Acess GUI (AxWin) Version 2 + * By John Hodge (thePowersGang) + */ +#include "common.h" +#include + +// === 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 index 00000000..0b3e8fc0 --- /dev/null +++ b/Usermode/Applications/axwin2_src/WM/common.h @@ -0,0 +1,25 @@ +/* + * Acess GUI (AxWin) Version 2 + * By John Hodge (thePowersGang) + */ +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#include +#include +#include + +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 index 00000000..d9238175 --- /dev/null +++ b/Usermode/Applications/axwin2_src/WM/helpers.c @@ -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 index 00000000..13039a3a --- /dev/null +++ b/Usermode/Applications/axwin2_src/WM/main.c @@ -0,0 +1,44 @@ +/* + * Acess GUI (AxWin) Version 2 + * By John Hodge (thePowersGang) + */ +#include "common.h" +#include + +// === 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 index 00000000..f10e6bb1 --- /dev/null +++ b/Usermode/Applications/axwin2_src/WM/messages.c @@ -0,0 +1,73 @@ +/* + * Acess GUI (AxWin) Version 2 + * By John Hodge (thePowersGang) + */ +#include "common.h" +#include +#include + +#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 index 00000000..00dbe16c --- /dev/null +++ b/Usermode/Applications/axwin2_src/WM/video.c @@ -0,0 +1,65 @@ +/* + * Acess GUI (AxWin) Version 2 + * By John Hodge (thePowersGang) + */ +#include "common.h" +#include +#include + +// === 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 index 00000000..c11b8644 --- /dev/null +++ b/Usermode/include/axwin/messages.h @@ -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 -- 2.20.1