Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int kernelGateDispatcher(unsigned char moduleID, unsigned char functionID, int par1, void* ptr1) {
- //This function calls the module function given by moduleID and functionID.
- //To do so, it has to map the module's memory into address space (at 0x4000),
- //re-map the pages pointed to by ptr1 in order to avoid conflicts with the module
- //(map ptr1's memory to 0x8000) and adjust ptr1 accordingly.
- //
- //The stack has already been switched before this dispatcher function gets called.
- unsigned char oldPg1, oldPg2, oldPg3;
- int rval = -1;
- if ((unsigned int)(modules[moduleID].entry) != 0x0000) {
- //Save the old page mapping
- oldPg1 = getPage(1);
- oldPg2 = getPage(2);
- oldPg3 = getPage(3);
- if (((unsigned int)ptr1 & 0xC000) == (0x4000)) {
- //The pointer points into page 1, where the module will be mapped.
- //That's a conflict, so we have to adjust stuff.
- //Move the two affected pages up by one in the mapping
- //0x4000..0xBFFF ---> 0x8000..0xFFFF
- setPage(2, oldPg1);
- setPage(3, oldPg2);
- //Adjust the pointer
- ptr1 = (void*)(((unsigned int)ptr1 & ~(0xC000)) | 0x8000);
- }
- //Map it to 0x4000 and call it
- setPage(1, modules[moduleID].page);
- rval = modules[moduleID].entry(functionID, par1, ptr1);
- //Restore the old mapping
- setPage(1, oldPg1);
- setPage(2, oldPg2);
- setPage(3, oldPg3);
- }
- return rval;
- }
Advertisement
Add Comment
Please, Sign In to add comment