|
||||
Warning, cross-references for /kernel/mem/physical.c need to be fixed.
0001 /* The Quest Operating System 0002 * Copyright (C) 2005-2010 Richard West, Boston University 0003 * 0004 * This program is free software: you can redistribute it and/or modify 0005 * it under the terms of the GNU General Public License as published by 0006 * the Free Software Foundation, either version 3 of the License, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU General Public License 0015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0016 */ 0017 0018 #include "mem/physical.h" 0019 #include "kernel.h" 0020 0021 /* Declare space for bitmap (physical) memory usage table. 0022 * PHYS_INDEX_MAX entries of 32-bit integers each for a 4K page => 4GB 0023 * memory limit when PHYS_INDEX_MAX=32768 0024 */ 0025 uint32 mm_table[PHYS_INDEX_MAX] __attribute__ ((aligned (4096))); 0026 uint32 mm_limit; /* Actual physical page limit */ 0027 0028 /* Find free page in mm_table 0029 * 0030 * Returns physical address rather than virtual, since we we don't 0031 * want user-level pages mapped into kernel page tables in all cases 0032 */ 0033 uint32 0034 alloc_phys_frame (void) 0035 { 0036 0037 int i; 0038 0039 for (i = 0; i < mm_limit; i++) 0040 if (BITMAP_TST (mm_table, i)) { /* Free page */ 0041 BITMAP_CLR (mm_table, i); 0042 return (i << 12); /* physical byte address of free page/frame */ 0043 } 0044 0045 return -1; /* Error -- no free page? */ 0046 } 0047 0048 uint32 0049 alloc_phys_frames (uint32 count) 0050 { 0051 0052 int i, j; 0053 0054 for (i = 0; i < mm_limit - count + 1; i++) { 0055 for (j = 0; j < count; j++) { 0056 if (!BITMAP_TST (mm_table, i + j)) { /* Is not free page? */ 0057 i = i + j; 0058 goto keep_searching; 0059 } 0060 } 0061 /* found window: */ 0062 for (j = 0; j < count; j++) { 0063 BITMAP_CLR (mm_table, i + j); 0064 } 0065 return (i << 12); /* physical byte address of free frames */ 0066 keep_searching: 0067 ; 0068 } 0069 return -1; /* Error -- no free page? */ 0070 } 0071 0072 void 0073 free_phys_frame (uint32 frame) 0074 { 0075 BITMAP_SET (mm_table, frame >> 12); 0076 } 0077 0078 void 0079 free_phys_frames (uint32 frame, uint32 count) 0080 { 0081 int i; 0082 frame >>= 12; 0083 for (i = 0; i < count; i++) 0084 BITMAP_SET (mm_table, frame + i); 0085 } 0086 0087 /* 0088 * Local Variables: 0089 * indent-tabs-mode: nil 0090 * mode: C 0091 * c-file-style: "gnu" 0092 * c-basic-offset: 2 0093 * End: 0094 */ 0095 0096 /* vi: set et sw=2 sts=2: */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 1.2.0 LXR engine. |