Changeset 518
- Timestamp:
- 05/24/08 09:46:43 (6 months ago)
- Files:
-
- 1 modified
-
Whitix/branches/hybrid/arch/i386/mm/virt.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Whitix/branches/hybrid/arch/i386/mm/virt.c
r399 r518 22 22 #include <fs/vfs.h> 23 23 #include <vmm.h> 24 #include <module.h> 25 #include <init.h> 24 26 #include <sections.h> 25 27 #include <malloc.h> 26 28 #include <slab.h> 29 #include <imports.h> 27 30 28 31 #define PGDIR_SELF 1023 /* Entry in the page directory of the page directory itself */ … … 62 65 int VirtMemManagerSetup(struct Process* process) 63 66 { 64 process->memManager=(struct MemManager*) MemCacheAlloc(managerCache);67 process->memManager=(struct MemManager*)memCacheAlloc(managerCache); 65 68 if (!process->memManager) 66 69 return -EFAULT; … … 174 177 175 178 error: 176 printf("VirtMemManagerInit failed\n");179 KePrint("VirtMemManagerInit failed\n"); 177 180 IrqRestoreFlags(flags); 178 181 return -ENOMEM; … … 194 197 return 0; 195 198 } 199 200 SYMBOL_EXPORT(VirtSetCurrent); 196 201 197 202 int VirtDestroyMemManager(struct MemManager* manager) … … 221 226 VirtUnmapPhysPage((DWORD)vPageDir); 222 227 ListRemove(&manager->list); 223 MemCacheFree(managerCache,manager); 224 225 return 0; 226 } 227 228 extern int SlabInit(); 228 memCacheFree(managerCache,manager); 229 230 return 0; 231 } 232 233 int VirtEarlyInit() 234 { 235 /* Init the kernel page tables */ 236 VirtMemManagerInit(&kernelMem, true); 237 238 return 0; 239 } 229 240 230 241 int VirtInit() 231 242 { 232 /* Init the kernel page tables */ 233 VirtMemManagerInit(&kernelMem,true); 234 235 /* And the slab allocator */ 236 SlabInit(); 237 238 managerCache=MemCacheCreate("Manager Cache",sizeof(struct MemManager),NULL,NULL,0); 243 managerCache=memCacheCreate("Manager Cache",sizeof(struct MemManager),NULL,NULL,0); 239 244 if (!managerCache) 240 245 return -ENOMEM; … … 282 287 } 283 288 289 SYMBOL_EXPORT(VirtMemMapPage); 290 284 291 void VirtUnmapPages(DWORD start,DWORD len) 285 292 { … … 325 332 } 326 333 327 printf("VirtMapPhysPage failed\n"); 328 IrqRestoreFlags(flags); 329 return 0; 330 } 334 KePrint("VirtMapPhysPage failed\n"); 335 IrqRestoreFlags(flags); 336 return 0; 337 } 338 339 SYMBOL_EXPORT(VirtMapPhysPage); 331 340 332 341 DWORD VirtMapPhysRange(DWORD virt,DWORD endVirt,DWORD numPages,int perms) … … 339 348 IrqSaveFlags(flags); 340 349 341 // printf("VirtMapPhysRange(%#X,%#X,%u,%d)\n",virt,endVirt,numPages,perms);350 // KePrint("VirtMapPhysRange(%#X,%#X,%u,%d)\n",virt,endVirt,numPages,perms); 342 351 343 352 for (i=virt; i<endVirt; i+=PAGE_SIZE) … … 366 375 /* Now map them in */ 367 376 for (i=start; i<start+(numPages*PAGE_SIZE); i+=PAGE_SIZE) 368 VirtMemMapPage(i,PageAlloc()->physAddr,perms); 377 { 378 struct PhysPage* page=PageAlloc(); 379 380 if (!page) 381 { 382 for (i-=PAGE_SIZE; i>start; i-=PAGE_SIZE) 383 VirtUnmapPhysPage(PageGetStruct(PAGE_ALIGN(VirtToPhys(i)))); 384 385 return 0; 386 } 387 388 VirtMemMapPage(i,page->physAddr,perms); 389 } 369 390 370 391 IrqRestoreFlags(flags); … … 372 393 return start; 373 394 } 395 396 SYMBOL_EXPORT(VirtMapPhysRange); 374 397 375 398 void VirtUnmapPhysPage(DWORD virt) … … 383 406 } 384 407 408 SYMBOL_EXPORT(VirtUnmapPhysPage); 409 385 410 DWORD VirtAllocateTemp(DWORD phys) 386 411 { … … 400 425 } 401 426 427 SYMBOL_EXPORT(VirtAllocateTemp); 428 402 429 void VirtShowFault(DWORD address,int error) 403 430 { 404 printf("\nAddress = %#X (pageDir[%d] = %#X)",address,address >> 22,pageDir[address >> 22]);431 KePrint("\nAddress = %#X (pageDir[%d] = %#X)",address,address >> 22,pageDir[address >> 22]); 405 432 406 433 if (pageDir[address >> 22]) 407 printf(" pageTable[%d] = %#X",address >> 12,pageTable[address >> 12]);408 409 printf("\n");434 KePrint(" pageTable[%d] = %#X",address >> 12,pageTable[address >> 12]); 435 436 KePrint("\n"); 410 437 411 438 if (error & 1) 412 printf("Protection violation, ");439 KePrint("Protection violation, "); 413 440 else 414 printf("Page not present, ");441 KePrint("Page not present, "); 415 442 416 443 if (error & 2) 417 printf("writing, ");444 KePrint("writing, "); 418 445 else 419 printf("reading, ");446 KePrint("reading, "); 420 447 421 448 if (error & 4) 422 printf("in user mode\n");449 KePrint("in user mode\n"); 423 450 else 424 printf("in kernel mode\n");451 KePrint("in kernel mode\n"); 425 452 } 426 453 427 454 DWORD VirtToPhys(DWORD virt) 428 455 { 429 return pageTable[PGTABLE_ENT(virt)]; 430 } 431 456 return PAGE_ALIGN(pageTable[PGTABLE_ENT(virt)])+PAGE_OFFSET(virt); 457 } 458 459 SYMBOL_EXPORT(VirtToPhys); 460
