PMM -- simplification of code
This commit is contained in:
		
							parent
							
								
									9bc1abceff
								
							
						
					
					
						commit
						e86857dca4
					
				| @ -1,25 +1,28 @@ | |||||||
| #include <memory.h> | #include <memory.h> | ||||||
| 
 | 
 | ||||||
| uint64_t first = 0; | // Virtual addres of next free page
 | ||||||
|  | uint64_t next = 0; | ||||||
| 
 | 
 | ||||||
| void pmm_free(uint64_t page) | void pmm_free(uint64_t page) | ||||||
| { | { | ||||||
|   page = (uint64_t)P2V(page); |   // Write previous free pointer to freed page
 | ||||||
|   *(uint64_t *)page = first; |   *(uint64_t *)P2V(page) = next; | ||||||
|   first = page; |   // And update free pointer
 | ||||||
|  |   next = (uint64_t)P2V(page); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| uint64_t pmm_alloc() | uint64_t pmm_alloc() | ||||||
| { | { | ||||||
|   uint64_t page = first; |   if(!next) return 0; | ||||||
|   first = page?*(uint64_t *)page:0; |   uint64_t page = next; | ||||||
|   page = (uint64_t)(page?V2P(page):0); |   // Read new free pointer from allocated page
 | ||||||
|   return page; |   next = *(uint64_t *)page; | ||||||
|  |   return (uint64_t)V2P(page); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| uint64_t pmm_calloc() | uint64_t pmm_calloc() | ||||||
| { | { | ||||||
|   uint64_t page = pmm_alloc(); |   uint64_t page = pmm_alloc(); | ||||||
|   memset(P2V(page), 0, 0x1000); |   memset(P2V(page), 0, PAGE_SIZE); | ||||||
|   return page; |   return page; | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user