diff --git a/VMM_TASKS b/VMM_TASKS new file mode 100644 index 0000000..91d599a --- /dev/null +++ b/VMM_TASKS @@ -0,0 +1,5 @@ +getfreevirtualpage.c + +Figure out what address 0x100000 signifies then create a define for it. Reference -> if( _current->oInfo.vmStart <= 0x100000 ) { + +What is the difference between K_PANIC and kpanic \ No newline at end of file diff --git a/sys/vmm/getfreevirtualpage.c b/sys/vmm/getfreevirtualpage.c index 9b047f4..bdcd0a8 100644 --- a/sys/vmm/getfreevirtualpage.c +++ b/sys/vmm/getfreevirtualpage.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2002-2018 The UbixOS Project. + * Copyright (c) 2002-2018, 2022 The UbixOS Project. * All rights reserved. * * This was developed by Christopher W. Olsen for the UbixOS Project. @@ -45,90 +45,134 @@ 08/11/02 - This Will Return Next Avilable Free Page Of Tasks VM Space ************************************************************************/ -void *vmm_getFreeVirtualPage(pidType pid, int count, int type) { - int y = 0, counter = 0, pdI = 0x0, ptI = 0x0; +void *vmm_getFreeVirtualPage( pidType pid, int count, int type ) { - uint32_t *pageDirectory = 0x0; - uint32_t *pageTable = 0x0; + int y = 0, counter = 0, pdI = 0x0, ptI = 0x0; - uint32_t start_page = 0x0; - uint32_t map_from = 0x0; + uint32_t *pageDirectory = 0x0; + uint32_t *pageTable = 0x0; - spinLock(&fvpSpinLock); + uint32_t start_page = 0x0; + uint32_t map_from = 0x0; - pageDirectory = (uint32_t *) PD_BASE_ADDR; + spinLock( &fvpSpinLock ); - /* Lets Search For A Free Page */ - if (_current->oInfo.vmStart <= 0x100000) - kpanic("Invalid vmStart\n"); + pageDirectory = ( uint32_t * ) PD_BASE_ADDR; - /* Get Our Starting Address */ - if (type == VM_THRD) { - start_page = (uint32_t) (_current->td.vm_daddr + ctob(_current->td.vm_dsize)); - } - else if (type == VM_TASK) { - start_page = _current->oInfo.vmStart; - } - else - K_PANIC("Invalid Type"); + /* Lets Search For A Free Page */ + if( _current->oInfo.vmStart <= 0x100000 ) { + + kpanic( "Invalid vmStart\n" ); + + } + + /* Get Our Starting Address */ + if( type == VM_THRD ) { + + start_page = ( uint32_t ) ( _current->td.vm_daddr + ctob( _current->td.vm_dsize ) ); + + } else if (type == VM_TASK) { + + start_page = _current->oInfo.vmStart; + + } else { + + K_PANIC( "Invalid Type" ); + + } - /* Locate Initial Page Table */ - keepMapping: - pdI = PD_INDEX(start_page); + /* Locate Initial Page Table */ + keepMapping: - if (pdI > PD_INDEX(VMM_USER_END)) { - map_from = 0x0; - goto doneMapping; - } + pdI = PD_INDEX(start_page); - /* If Page Directory Is Not Yet Allocated Allocate It */ - if ((pageDirectory[pdI] & PAGE_PRESENT) != PAGE_PRESENT) { - vmm_allocPageTable(pdI, pid); - } + if( pdI > PD_INDEX( VMM_USER_END ) ) { - pageTable = (uint32_t *) (PT_BASE_ADDR + (pdI * PAGE_SIZE)); + map_from = 0x0; - ptI = PT_INDEX(start_page); + goto doneMapping; - for (y = ptI; y < PT_ENTRIES && counter < count; y++, counter++) { + } - /* Loop Through The Page Table Find An UnAllocated Page */ - if ((pageTable[y] & PAGE_PRESENT) == PAGE_PRESENT) { - if ((pageTable[y] & PAGE_COW) == PAGE_COW) - kprintf("COW PAGE NOT CLEANED!"); + /* If Page Directory Is Not Yet Allocated Allocate It */ + if( ( pageDirectory[pdI] & PAGE_PRESENT ) != PAGE_PRESENT ) { - start_page += (PAGE_SIZE * counter); - map_from = 0x0; - counter = 0; - goto keepMapping; - } + vmm_allocPageTable( pdI, pid ); - if (map_from == 0x0) - map_from = start_page; - } + } - if (counter < count) { - start_page += (PAGE_SIZE * counter); - goto keepMapping; - } + pageTable = ( uint32_t * ) ( PT_BASE_ADDR + ( pdI * PAGE_SIZE ) ); - gotPages: - if (type == VM_THRD) - _current->td.vm_dsize += btoc(count * PAGE_SIZE); - else if (type == VM_TASK) - _current->oInfo.vmStart = map_from + (count * PAGE_SIZE); + ptI = PT_INDEX( start_page ); - //_current->oInfo.vmStart += (count * PAGE_SIZE); + for( y = ptI; y < PT_ENTRIES && counter < count; y++, counter++ ) { - for (counter = 0; counter < count; counter++) { - if ((vmm_remapPage((uint32_t) vmm_findFreePage(pid), (map_from + (counter * PAGE_SIZE)), PAGE_DEFAULT, pid, 0)) == 0x0) - kpanic("vmmRemapPage: getFreeVirtualPage-1: (%i)[0x%X]\n", type, map_from + (counter * PAGE_SIZE)); + /* Loop Through The Page Table Find An UnAllocated Page */ + if( ( pageTable[y] & PAGE_PRESENT ) == PAGE_PRESENT ) { - bzero((map_from + (counter * PAGE_SIZE)), PAGE_SIZE); - } + if( ( pageTable[y] & PAGE_COW ) == PAGE_COW ) { - doneMapping: - spinUnlock(&fvpSpinLock); - return (map_from); + kprintf( "COW PAGE NOT CLEANED!" ); + + } + + start_page += ( PAGE_SIZE * counter ); + + map_from = 0x0; + + counter = 0; + + goto keepMapping; + + } + + if( map_from == 0x0 ) { + + map_from = start_page; + + } + + } + + if( counter < count ) { + + start_page += ( PAGE_SIZE * counter ); + + goto keepMapping; + + } + + gotPages: + + if( type == VM_THRD ) { + + _current->td.vm_dsize += btoc( count * PAGE_SIZE ); + + } else if( type == VM_TASK ) { + + _current->oInfo.vmStart = map_from + ( count * PAGE_SIZE ); + + } + + //_current->oInfo.vmStart += (count * PAGE_SIZE); + + for( counter = 0; counter < count; counter++ ) { + + if( ( vmm_remapPage( ( uint32_t ) vmm_findFreePage( pid ), ( map_from + ( counter * PAGE_SIZE ) ), PAGE_DEFAULT, pid, 0 ) ) == 0x0 ) { + + kpanic( "vmmRemapPage: getFreeVirtualPage-1: (%i)[0x%X]\n", type, map_from + ( counter * PAGE_SIZE ) ); + + } + + bzero( ( map_from + ( counter * PAGE_SIZE ) ), PAGE_SIZE ); + + } + + doneMapping: + + spinUnlock( &fvpSpinLock ); + + return( map_from ); + } diff --git a/sys/vmm/vmm_allocpagetable.c b/sys/vmm/vmm_allocpagetable.c index c9d5cec..b290ea1 100644 --- a/sys/vmm/vmm_allocpagetable.c +++ b/sys/vmm/vmm_allocpagetable.c @@ -4,43 +4,56 @@ #include -int vmm_allocPageTable(uint32_t pdI, pidType pid) { - uint32_t *pageDirectory = PD_BASE_ADDR; - uint32_t *pageTable = 0x0; +int vmm_allocPageTable( uint32_t pdI, pidType pid ) { - if ((pdI >= PD_ENTRIES) || ((pageDirectory[pdI] & PAGE_PRESENT) == PAGE_PRESENT)) - return(-1); + uint32_t *pageDirectory = PD_BASE_ADDR; + uint32_t *pageTable = 0x0; + + if( ( pdI >= PD_ENTRIES ) || ( ( pageDirectory[pdI] & PAGE_PRESENT ) == PAGE_PRESENT ) ) { + + return( -1 ); + + } - /* Lock The Page Directory So We Dont Collide With Another Thread */ - //spinLock(&pdSpinLock); + /* Lock The Page Directory So We Dont Collide With Another Thread */ + //spinLock(&pdSpinLock); - /* Map Page Table Page Into Page Directory */ - if ((pdI >= PD_INDEX(VMM_USER_START)) && (pdI <= PD_INDEX(VMM_USER_END))) - pageDirectory[pdI] = (uint32_t) vmm_findFreePage(pid) | PAGE_DEFAULT; - else - pageDirectory[pdI] = (uint32_t) vmm_findFreePage(pid) | KERNEL_PAGE_DEFAULT; + /* Map Page Table Page Into Page Directory */ + if( ( pdI >= PD_INDEX( VMM_USER_START ) ) && ( pdI <= PD_INDEX( VMM_USER_END ) ) ) { - /* Map Page Table To Virtual Space So We Can Easily Manipulate It */ - pageTable = (uint32_t *) (PT_BASE_ADDR + (PD_INDEX( PT_BASE_ADDR ) * PAGE_SIZE)); + pageDirectory[pdI] = ( uint32_t ) vmm_findFreePage( pid ) | PAGE_DEFAULT; - if ((pageTable[pdI] & PAGE_PRESENT) == PAGE_PRESENT) - kpanic("How did this happen"); + } else { - pageTable[pdI] = pageDirectory[pdI]; + pageDirectory[pdI] = ( uint32_t ) vmm_findFreePage( pid ) | KERNEL_PAGE_DEFAULT; + + } + + /* Map Page Table To Virtual Space So We Can Easily Manipulate It */ + pageTable = ( uint32_t * ) ( PT_BASE_ADDR + ( PD_INDEX( PT_BASE_ADDR ) * PAGE_SIZE ) ); + + if( ( pageTable[pdI] & PAGE_PRESENT ) == PAGE_PRESENT ) { + + kpanic( "How did this happen" ); + + } + + pageTable[pdI] = pageDirectory[pdI]; - /* Reload Page Directory */ - asm( - "movl %cr3,%eax\n" - "movl %eax,%cr3\n" - ); + /* Reload Page Directory */ + asm( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); - /* Clean The Page */ - pageTable = (uint32_t *) (PT_BASE_ADDR + (pdI * PAGE_SIZE)); - bzero(pageTable, PAGE_SIZE); + /* Clean The Page */ + pageTable = ( uint32_t * ) (PT_BASE_ADDR + ( pdI * PAGE_SIZE ) ); - //spinUnlock(&pdSpinLock); + bzero( pageTable, PAGE_SIZE ); - return(0x0); + //spinUnlock(&pdSpinLock); + + return( 0x0 ); }