Skip to content

Commit 1f331ae

Browse files
author
tthomps
committed
Begin implementing a link between the GUI shell and the kernel.
Add a system call that allows the GUI shell to register a callback with the OS. The OS can call this function to send messages to the GUI on behalf of the applications.
1 parent 1d13eda commit 1f331ae

File tree

13 files changed

+131
-2
lines changed

13 files changed

+131
-2
lines changed

MyOS_1/Build_Number.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
// Define a build number. This number will be incremented by a simple console program called by a post-build event
44
// It's put here in its own file to keep the other program from messing up the source
55
#define \
6-
BUILD_NUMBER 5654
6+
BUILD_NUMBER 5704

MyOS_1/GUI_Kernel.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "GUI_Kernel.h"
2+
#include "GUI_Messages.h"
3+
#include "Tasks/Context.h"
4+
5+
GUI_CALLBACK guiCallback = NULL;
6+
7+
void GUI_CallbackAdded()
8+
{
9+
// Send a new window message to the GUI shell for each running application
10+
for (int i = 0; i < MAX_TASKS; ++i)
11+
{
12+
if (!tasks[i].inUse)
13+
continue;
14+
15+
// Construct the message data
16+
GUI_NEW_CONSOLE_APP_DATA data;
17+
data.appName = tasks[i].imageName;
18+
19+
(*guiCallback)(tasks[i].PID, GUI_MSG_NEW_CONSOLE_APP, &data);
20+
}
21+
}

MyOS_1/GUI_Kernel.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
#include <stdint.h>
3+
4+
// definitions for interfacing between User apps <> kernel <> GUI shell
5+
6+
typedef void(*GUI_CALLBACK)(uint32_t PID, uint32_t messageType, void *pData);
7+
8+
extern GUI_CALLBACK guiCallback;
9+
10+
// Called immediately after a callback has been registered, to transition running apps into windowed consoles
11+
void GUI_CallbackAdded();

MyOS_1/GUI_Messages.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
#include <stdint.h>
3+
4+
// MESSAGES
5+
#define GUI_MSG_NEW_CONSOLE_APP 0x1000
6+
// END OF MESSAGES
7+
8+
// DATA TYPES USED BY MESSAGES
9+
10+
// Data type used by GUI_MSG_NEW_CONSOLE_APP messages
11+
typedef struct GUI_NEW_CONSOLE_APP_DATA
12+
{
13+
const char *appName;
14+
15+
// TODO: We may as well send the terminal contents over in the same message
16+
} GUI_NEW_CONSOLE_APP_DATA;
17+
// END OF DATA TYPES

MyOS_1/Interrupts/IDT.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ void IDT_Init(void)
9494
// Set handler for hiding shell display elements
9595
Set_IDT_Entry((unsigned long)hide_shell_display_interrupt_handler, SYSCALL_HIDE_SHELL_DISPLAY);
9696

97+
// Set handler for the GUI telling the kernel how to send the GUI messages
98+
Set_IDT_Entry((unsigned long)gui_register_callback_interrupt_handler, SYSCALL_REGISTER_GUI_CALLBACK);
99+
97100
/* fill the IDT descriptor */
98101
IDT_ptr.base = (uint32_t)IDT;
99102
IDT_ptr.size = (sizeof(IDT_ENTRY) * 256);

MyOS_1/Interrupts/Interrupts.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "../myos_io.h"
1515
#include "../Tasks/Context.h"
1616
#include "../Drivers/PS2_Mouse.h"
17+
#include "../GUI_Kernel.h"
1718

1819
unsigned long interrupts_fired;
1920

@@ -457,6 +458,40 @@ void _declspec(naked) graphics_blit_interrupt_handler(int eflags, int cs, const
457458
}
458459
}
459460

461+
void _declspec(naked) gui_register_callback_interrupt_handler(int eflags, int cs, GUI_CALLBACK callbackFunc)
462+
{
463+
// supress warning about unused parameters
464+
(void)eflags, (void)cs, (void)callbackFunc;
465+
466+
_asm
467+
{
468+
// prologue
469+
push ebp
470+
mov ebp, esp
471+
pushad
472+
}
473+
474+
++interrupts_fired;
475+
476+
if (debugLevel)
477+
terminal_writestring("GUI register callback interrupt handler fired.\n");
478+
479+
// TODO IMPORTANT The GUI application should be mapped to kernel space
480+
481+
guiCallback = callbackFunc;
482+
483+
GUI_CallbackAdded();
484+
485+
_asm
486+
{
487+
popad
488+
// epilogue
489+
pop ebp
490+
491+
iretd
492+
}
493+
}
494+
460495
void _declspec(naked) hide_shell_display_interrupt_handler(int eflags, int cs)
461496
{
462497
// supress warning about unused parameters

MyOS_1/Interrupts/Interrupts.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "../Graphics/Display_HAL.h"
88
#include "../myos_io.h"
99
#include "../Drivers/mouse.h"
10+
#include "../GUI_Kernel.h"
1011

1112
#define HARDWARE_INTERRUPTS_BASE 0x20
1213

@@ -38,6 +39,8 @@ void gpf_exception_handler(void);
3839

3940
void graphics_blit_interrupt_handler(int eflags, int cs, const SDL_Rect *sourceRect, PIXEL_32BIT *image);
4041

42+
void gui_register_callback_interrupt_handler(int eflags, int cs, GUI_CALLBACK callbackFunc);
43+
4144
void hide_shell_display_interrupt_handler(int eflags, int cs);
4245

4346
void Interrupts_Add_Shared_Handler(bool (*sharedHandlerAddress)(void), uint8_t irq);

MyOS_1/Interrupts/System_Calls.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ size_t SystemCallFRead(void * bufPtr, size_t elemSize, size_t count, FILE * stre
7676
return retVal;
7777
}
7878

79+
void SystemCallRegisterGuiCallback(GUI_CALLBACK guiCallback)
80+
{
81+
const int pointerSize = sizeof(GUI_CALLBACK);
82+
83+
__asm
84+
{
85+
push [guiCallback] // push argument onto stack
86+
int SYSCALL_REGISTER_GUI_CALLBACK // call gui_register_callback_interrupt_handler(guiCallback)
87+
add esp, pointerSize // restore value of stack pointer
88+
}
89+
}
90+
7991
int SystemCallFSeek(FILE * stream, long int off, int origin)
8092
{
8193
int retVal;

MyOS_1/Interrupts/System_Calls.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extern "C" {
1010
#include "../Libs/SDL/include/SDL_rect.h"
1111
#include "../myos_io.h"
1212
#include "../Drivers/mouse.h"
13+
#include "../GUI_Kernel.h"
1314

1415
#define SYSCALL_PRINT 255
1516
#define SYSCALL_PRINTF 254
@@ -28,6 +29,7 @@ extern "C" {
2829
#define SYSCALL_DISPATCH_NEW_TASK 241
2930
#define SYSCALL_GET_MOUSE_STATE 240
3031
#define SYSCALL_HIDE_SHELL_DISPLAY 239
32+
#define SYSCALL_REGISTER_GUI_CALLBACK 238
3133

3234
void SystemCallExit();
3335
#define exit SystemCallExit
@@ -67,6 +69,9 @@ void SystemCallPrint(char *str);
6769
bool SystemCallReadFromKeyboard(uint16_t *key);
6870
#define readFromKeyboard SystemCallReadFromKeyboard
6971

72+
void SystemCallRegisterGuiCallback(GUI_CALLBACK guiCallback);
73+
#define registerGuiCallback SystemCallRegisterGuiCallback
74+
7075
#define printf SystemCallPrintf
7176
int __cdecl SystemCallPrintf(const char* format, ...);
7277

MyOS_1/MyOS_1.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@
299299
<ClCompile Include="Graphics\font.c" />
300300
<ClCompile Include="Graphics\Graphical_Terminal.c" />
301301
<ClCompile Include="Graphics\picofont.c" />
302+
<ClCompile Include="GUI_Kernel.c" />
302303
<ClCompile Include="Interrupts\IDT.c" />
303304
<ClCompile Include="Interrupts\Interrupts.c" />
304305
<ClCompile Include="Interrupts\PIC.c" />
@@ -350,6 +351,8 @@
350351
<ClInclude Include="Graphics\Display_HAL.h" />
351352
<ClInclude Include="Graphics\Graphical_Terminal.h" />
352353
<ClInclude Include="Graphics\picofont.h" />
354+
<ClInclude Include="GUI_Kernel.h" />
355+
<ClInclude Include="GUI_Messages.h" />
353356
<ClInclude Include="Interrupts\IDT.h" />
354357
<ClInclude Include="Interrupts\Interrupts.h" />
355358
<ClInclude Include="Interrupts\PIC.h" />

MyOS_1/MyOS_1.vcxproj.filters

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
<Filter Include="Header Files\Tasks">
6565
<UniqueIdentifier>{b27b41e5-298f-4e04-9dea-743123199d72}</UniqueIdentifier>
6666
</Filter>
67+
<Filter Include="Header Files\GUI">
68+
<UniqueIdentifier>{441e1d72-2ac6-46dd-b47e-a3a9f01acb81}</UniqueIdentifier>
69+
</Filter>
70+
<Filter Include="Source Files\GUI">
71+
<UniqueIdentifier>{ed1bb142-e86a-48ef-85ae-82740aea315c}</UniqueIdentifier>
72+
</Filter>
6773
</ItemGroup>
6874
<ItemGroup>
6975
<ClCompile Include="paging.c">
@@ -201,6 +207,9 @@
201207
<ClCompile Include="Tasks\Dispatcher.c">
202208
<Filter>Source Files\Tasks</Filter>
203209
</ClCompile>
210+
<ClCompile Include="GUI_Kernel.c">
211+
<Filter>Source Files\GUI</Filter>
212+
</ClCompile>
204213
</ItemGroup>
205214
<ItemGroup>
206215
<ClInclude Include="misc.h">
@@ -341,6 +350,12 @@
341350
<ClInclude Include="Drivers\mouse.h">
342351
<Filter>Source Files\Drivers</Filter>
343352
</ClInclude>
353+
<ClInclude Include="GUI_Kernel.h">
354+
<Filter>Header Files\GUI</Filter>
355+
</ClInclude>
356+
<ClInclude Include="GUI_Messages.h">
357+
<Filter>Header Files\GUI</Filter>
358+
</ClInclude>
344359
</ItemGroup>
345360
<ItemGroup>
346361
<Text Include="Referenced_Reading.txt">

MyOS_1/Tasks/Context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typedef struct CONTEXT_INFO
2121
char imageName[MAX_IMAGE_NAME_LENGTH];
2222
bool inUse;
2323
bool exclusive; // True to disable switching to any other tasks
24+
uint32_t PID;
2425
// ? What else?
2526
} CONTEXT_INFO, PROCESS_CONTROL_BLOCK;
2627

@@ -52,6 +53,8 @@ extern PROCESS_CONTROL_BLOCK tasks[MAX_TASKS];
5253
extern int ticksLeftInTask;
5354
extern int currentTask;
5455

56+
extern uint32_t nextPID;
57+
5558
extern bool multiEnable; // TEMPTEMP
5659

5760
void DispatchNewTask(uint32_t programStart, uint32_t stackSize, const char *imageName, bool exclusive);

MyOS_1/Tasks/Dispatcher.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ READY_QUEUE_ENTRY *readyQueueHead = NULL;
77

88
int currentTask = 0; // 0 is for the main kernel thread
99
int ticksLeftInTask = TICKS_PER_TASK;
10-
10+
uint32_t nextPID = 1000;
1111

1212
// This must be global so we can access it while playing with the stack in ways the compiler can't predict
1313
uint32_t stackPtr;
@@ -61,6 +61,7 @@ void DispatchNewTask(uint32_t programStart, uint32_t stackSize, const char *imag
6161
tasks[taskSlot].ESP = stackPtr;
6262
strncpy(tasks[taskSlot].imageName, imageName, MAX_IMAGE_NAME_LENGTH - 1);
6363
tasks[taskSlot].inUse = true;
64+
tasks[taskSlot].PID = nextPID++;
6465

6566
// Create ready queue entry
6667
READY_QUEUE_ENTRY *queueEntry;

0 commit comments

Comments
 (0)