Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.os.development    |    Operating system development chatter    |    4,255 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 3,539 of 4,255    |
|    =?UTF-8?B?15DXldeo15kg15XXmdeh15HXn to All    |
|    paging makes OS to reboot infinitely    |
|    04 Dec 22 04:48:06    |
   
   From: turhuhxckuo@gmail.com   
      
   Hello, I'm writing an OS and I can't find my problem. The second i set the CR0   
   paging bit, the system reboots itself, and goes to an infinite loop.   
   currently i dont care about page allocations, i'll write this part later, for   
   now i want a paging setup that works, even with only one page directory entry.   
   if you know what might cause this, please let me know.   
   the kernel calls initPDT with some arbitrary number and goes to an infinite   
   loop.   
   my code is as followed (ignore irq, and print, they work fine):   
      
   #define PDT_SIZE 1024   
      
   typedef enum {   
    PRESENT = 1,   
    READWRITE = 2,   
    USER = 4,   
    WRITETHROUGH = 8,   
    CACHE = 16   
   } PageDirectoryFlags;   
      
   typedef uint32_t PDEntry;   
      
   typedef struct {   
    PDEntry entries[PDT_SIZE];   
   } PD;   
      
   typedef uint32_t PTEntry;   
      
   typedef struct {   
    PTEntry entries[PDT_SIZE];   
   } PT;   
      
   void startVirtualMode(uint32_t address) {   
    __asm__("mov %0, %%cr3"::"r"(address));   
    uint32_t cr0 = 0;   
    __asm__("mov %%cr0, %0":"=r"(cr0));   
    cr0 |= 0x80000000;   
    __asm__("mov %0, %%cr0"::"r"(cr0));   
   }   
      
   void initPDT(uint32_t address) {   
    PD* table = (PD*)address;   
      
    for (int i = 0; i < PDT_SIZE; i++) {   
    table->entries[i] = READWRITE | PRESENT | USER | (i>>22);   
    }   
      
    // last entry points to the pdt itself   
    table->entries[PDT_SIZE-1] = READWRITE | PRESENT | address;   
      
    irqInstallHandler(14, pagefault);   
      
    startVirtualMode(address);   
   }   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca