mempage.cpp

00001 #include "openem.h"
00002 #include "mempage.h"
00003 
00004 #include <stdlib.h>
00005 
00006 uint8 drm8(void *cpu_ref, uint32 addr)
00007 {
00008     OE_ASSERT(0);
00009     return 0;
00010 }
00011 
00012 void dwm8(void *cpu_ref, uint32 addr, uint8 dat)
00013 {
00014     OE_ASSERT(0);
00015 }
00016 
00017 uint16 drm16(void *cpu_ref, uint32 addr)
00018 {
00019     OE_ASSERT(0);
00020     return 0;
00021 }
00022 
00023 void dwm16(void *cpu_ref, uint32 addr, uint16 dat)
00024 {
00025     OE_ASSERT(0);
00026 }
00027 
00028 uint32 drm32(void *cpu_ref, uint32 addr)
00029 {
00030     OE_ASSERT(0);
00031     return 0;
00032 }
00033 
00034 void dwm32(void *cpu_ref, uint32 addr, uint32 dat)
00035 {
00036     OE_ASSERT(0);
00037 }
00038 
00039 
00040 // Number of pages * (page_size). Note that page_size has to be a power of 2. Returns 0 if successful, 0xFFFFFFFF if not enough memory or whatever.
00041 uint32 oe_pagetable::create_pagetable(uint32 numpages, uint32 page_size)
00042 {
00043     uninit();
00044     if (page_size == 0) return 0xFFFFFFFF;
00045     if (numpages == 0) return 0xFFFFFFFF;
00046     size = (numpages * page_size);
00047     clamp = size - 1;
00048     mask = page_size - 1;
00049     // Find out what the shift value is for page_size
00050     uint32 ptemp = page_size;
00051     shift = 0;
00052     for (;;) {
00053         if ((ptemp & 0x01) && (ptemp ^ 0x01)) return 0xFFFFFFFF;    // if it's not a power of 2
00054         if (ptemp == 0) return 0xFFFFFFFF;
00055         if (ptemp == 1) break;
00056         shift++;
00057         ptemp >>= 1;
00058     }
00059 
00060     // Now allocate the number of pages...
00061     calls = (oe_pagetable_ptrtable *)malloc(sizeof(oe_pagetable_ptrtable) * numpages);
00062     flags = (OE_PT_FLAG *)malloc(sizeof(OE_PT_FLAG) * numpages);
00063     mem = (uint8 **)malloc(sizeof(uint8 **) * numpages);
00064 
00065     // Now walk all the tables filling them in with NULL/0 and dummy pointers
00066     OE_PT_FLAG *fptr = flags;
00067     uint8 **mptr = mem;
00068     oe_pagetable_ptrtable *pptr = calls;
00069 
00070     for (uint32 u = 0; u < numpages; u++) {
00071         *fptr = 0;              // This sets a memory access to call a dummy function pointer automatically - which will then throw ASSERT
00072         *mptr = NULL;           // If a call happens to a page that is set for direct access, and it has not been initialized correctly, another ASSERT
00073         pptr->rm8 = &drm8;
00074         pptr->rm16 = &drm16;
00075         pptr->rm32 = &drm32;
00076         pptr->wm8 = &dwm8;
00077         pptr->wm16 = &dwm16;
00078         pptr->wm32 = &dwm32;
00079         pptr++;
00080         mptr++;
00081         fptr++;
00082     }
00083 
00084     return 0;
00085 }
00086 
00087 oe_pagetable::oe_pagetable()
00088 {
00089     init();
00090 }
00091 
00092 oe_pagetable::~oe_pagetable()
00093 {
00094     uninit();
00095 }
00096 
00097 void oe_pagetable::init(void)
00098 {
00099     shift = 0;
00100     calls = NULL;
00101     flags = NULL;
00102     mem = NULL;
00103     //psub = NULL;
00104 }
00105 
00106 void oe_pagetable::uninit(void)
00107 {
00108     if (calls != NULL) free(calls);
00109     if (flags != NULL) free(flags);
00110     if (mem != NULL) free(mem);
00111     //if (psub != NULL) free(psub);
00112     calls = NULL;
00113     flags = NULL;
00114     mem = NULL;
00115     //psub = NULL;
00116 }

Generated on Sat Sep 9 03:50:43 2006 for Openem APIs by  doxygen 1.4.7