From 9d18451b26939473f1d8ef38b1a24dba14428fff Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 19 Jun 2017 08:47:16 -0500 Subject: [PATCH] Finished constructor (hopefully) and header. --- MP2/MP2_Sources/cont_frame_pool.C | 62 ++++++++++++++++++++++++++++++- MP2/MP2_Sources/cont_frame_pool.H | 10 +++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/MP2/MP2_Sources/cont_frame_pool.C b/MP2/MP2_Sources/cont_frame_pool.C index 6ded45a..aeb5ec4 100644 --- a/MP2/MP2_Sources/cont_frame_pool.C +++ b/MP2/MP2_Sources/cont_frame_pool.C @@ -132,8 +132,66 @@ ContFramePool::ContFramePool(unsigned long _base_frame_no, unsigned long _info_frame_no, unsigned long _n_info_frames) { - // TODO: IMPLEMENTATION NEEEDED! - assert(false); + // Bitmap must fit in a single frame! + // NOTE: In theory, we don't need to make the bitmap any larger, + // since as stated in the instructions it is already big enough to + // hold for 128MB of memory with one bit per frame, so should still + // be enough for 64MB of memory with 2 bits per frame. + assert(_n_frames <= FRAME_SIZE * 8); + + base_frame_no = _base_frame_no; + nframes = _n_frames; + nFreeFrames = _n_frames; + info_frame_no = _info_frame_no; + n_info_frames = _n_info_frames; + + // If _info_frame_no is zero then we keep management info in the first + // frame(s), else we use the provided frame(s) to keep management info + // NOTE: need a second check for the number of info frames specified, if any. + if(info_frame_no == 0) + { + if(n_info_frames == 0) + { + bitmap = (unsigned char *) (base_frame_no * FRAME_SIZE); + } + else + { + bitmap = (unsigned char *) (base_frame_no * FRAME_SIZE * n_info_frames); + } + } + else + { + if(n_info_frames == 0) + { + bitmap = (unsigned char *) (info_frame_no * FRAME_SIZE); + } + else + { + bitmap = (unsigned char *) (info_frame_no * FRAME_SIZE * n_info_frames); + } + } + + // Number of frames must "fill" the bitmap! + assert ((nframes % 8 ) == 0); + + + // Everything ok. Proceed to mark all bits in the bitmap + // NOTE: I don't think this needs to be changed... + for(int i=0; i*8 < _n_frames; i++) + { + bitmap[i] = 0xFF; + } + + // Mark the first frame as being used if it is being used + // NOTE: need to mark multiple frames if needed. + unsigned long i = info_frame_no; + while(i < (info_frame_no + n_info_frames)) + { + bitmap[i*8] = 0x7F; + nFreeFrames--; + } + + Console::puts("Frame Pool initialized\n"); } unsigned long ContFramePool::get_frames(unsigned int _n_frames) diff --git a/MP2/MP2_Sources/cont_frame_pool.H b/MP2/MP2_Sources/cont_frame_pool.H index 115964c..54d7128 100755 --- a/MP2/MP2_Sources/cont_frame_pool.H +++ b/MP2/MP2_Sources/cont_frame_pool.H @@ -42,7 +42,17 @@ class ContFramePool { private: /* -- DEFINE YOUR CONT FRAME POOL DATA STRUCTURE(s) HERE. */ + + unsigned char * bitmap; // Remember the bitmap here needs 2 bits per frame + unsigned int nFreeFrames; // + unsigned long base_frame_no; // Where does the frame pool start in phys mem? + unsigned long nframes; // Size of the frame pool + unsigned long info_frame_no; // Where do we store the management information? + unsigned long n_info_frames; // Number of frames needed to store management info + void mark_inaccessible(unsigned long _frame_no); // Should be a frame marked as + // a head, otherwise fails + public: // The frame size is the same as the page size, duh...