Main Page | Data Structures | File List | Globals | Related Pages

frame.h

Go to the documentation of this file.
00001 
00011 #ifndef __KERN_FRAME_H__
00012 #define __KERN_FRAME_H__
00013 
00014 #include <page.h>
00015 #include <list.h>
00016 
00017 /* the size of page frames in bytes */
00018 #define FRAME_SIZE              PAGE_SIZE
00019 /* the number of significant bits in a frame address */
00020 #define FRAME_ADDRESS_BITS      (32 - PAGE_SHIFT)
00021 /* the maximal number of bits that may be used to represent a frame's alignment */
00022 #define FRAME_ALIGNMENT_BITS    (PAGE_SHIFT - 1)
00023 /* the maximum alignment a flexible page may be, which is the number of power of two sizes possible */
00024 #define FRAME_ALIGNMENT_MAXIMUM (FRAME_ADDRESS_BITS - 1)
00025 
00026 typedef unsigned int FrameAddress;
00027 typedef unsigned int FrameAlignment;
00028 
00029 /* structure representing a flexible page */
00030 typedef struct
00031 {
00032         /* list node for the list of free physical frames of a given alignment */
00033         ListNode frameList;
00034         /* the frame's address, with its non-significant bits shifted off */
00035         unsigned int address : FRAME_ADDRESS_BITS;
00036         /* the frame's alignment, which is also it's size */
00037         unsigned int alignment : FRAME_ALIGNMENT_BITS;
00038         /* whether or not the frame has been allocated */ 
00039         unsigned int allocated : 1;
00040 } Frame;
00041 
00042 /* the actual memory address of a frame, which is the frame's index multiplied by the byte size of a frame */
00043 #define FRAME_ADDRESS(frame)    ((frame) -> address * FRAME_SIZE)
00044 
00045 /* a frame allocator managing a region of physical address space */
00046 typedef struct
00047 {
00048         /* the number of frames available to allocate */ 
00049         unsigned int framesAvailable;
00050         /* the starting frame address of the managed memory */
00051         FrameAddress frameStart;
00052         /* the last useable frame address of the managed memory */
00053         FrameAddress frameEnd;
00054         /* the frame meta-data for all managed frames */
00055         Frame * frames;
00056         /* free lists of frames of given alignments up to the maximum alignment */
00057         List freeLists [FRAME_ALIGNMENT_MAXIMUM + 1];
00058 } FrameAllocator;
00059 
00070 extern int frame_allocator_initialize (FrameAddress start, FrameAddress end);
00080 extern void frame_allocator_reserve (FrameAddress start, FrameAddress end);
00081 
00092 extern Frame * frame_allocate_within (FrameAlignment alignment, FrameAddress start, FrameAddress end);
00101 extern Frame * frame_allocate (FrameAlignment alignment);
00110 extern void frame_free (Frame * frame);
00111 
00118 extern unsigned int frame_availability (void);
00119 
00120 #endif /* __KERN_FRAME_H__ */
00121 
00122 

Generated on Fri Apr 9 21:59:16 2004 for 15-410 Project 3 by doxygen 1.3.2