Guest User

Untitled

a guest
Nov 10th, 2014
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. int kernelGateDispatcher(unsigned char moduleID, unsigned char functionID, int par1, void* ptr1) {
  2.     //This function calls the module function given by moduleID and functionID.
  3.     //To do so, it has to map the module's memory into address space (at 0x4000),
  4.     //re-map the pages pointed to by ptr1 in order to avoid conflicts with the module
  5.     //(map ptr1's memory to 0x8000) and adjust ptr1 accordingly.
  6.     //
  7.     //The stack has already been switched before this dispatcher function gets called.
  8.    
  9.     unsigned char oldPg1, oldPg2, oldPg3;
  10.     int rval = -1;
  11.    
  12.     if ((unsigned int)(modules[moduleID].entry) != 0x0000) {
  13.         //Save the old page mapping
  14.         oldPg1 = getPage(1);
  15.         oldPg2 = getPage(2);
  16.         oldPg3 = getPage(3);
  17.        
  18.         if (((unsigned int)ptr1 & 0xC000) == (0x4000)) {
  19.             //The pointer points into page 1, where the module will be mapped.
  20.             //That's a conflict, so we have to adjust stuff.
  21.            
  22.             //Move the two affected pages up by one in the mapping
  23.             //0x4000..0xBFFF ---> 0x8000..0xFFFF
  24.             setPage(2, oldPg1);
  25.             setPage(3, oldPg2);
  26.            
  27.             //Adjust the pointer
  28.             ptr1 = (void*)(((unsigned int)ptr1 & ~(0xC000)) | 0x8000);
  29.         }
  30.        
  31.         //Map it to 0x4000 and call it
  32.         setPage(1, modules[moduleID].page);
  33.         rval = modules[moduleID].entry(functionID, par1, ptr1);
  34.        
  35.         //Restore the old mapping
  36.         setPage(1, oldPg1);
  37.         setPage(2, oldPg2);
  38.         setPage(3, oldPg3);
  39.     }
  40.    
  41.     return rval;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment