//------------------------------------------------------------------------- //------------------------------------------------------------------------- #define ICACHE #define MMU //#define DCACHE extern void PUT32 ( unsigned int, unsigned int ); extern unsigned int GET32 ( unsigned int ); extern void dummy ( unsigned int ); extern void uart_init ( void ); extern void hexstrings ( unsigned int d ); extern void hexstring ( unsigned int d ); extern void init_timer ( void ); extern unsigned int timer_tick ( void ); extern void start_l1cache ( void ); extern void stop_l1cache ( void ); extern void start_mmu ( unsigned int, unsigned int ); #include "zlib.h" #include "twain.h" #include "twaindef.h" unsigned char cdata[TESTDATALEN]; unsigned char udata[TESTDATALEN]; unsigned int malloc_base; //program 0x00000000 to 0x00200000 // 0x00030000 - 0x00080000 heap //0x00200000 mmu table //unsigned int copycount; //unsigned int setcount; #define MALLOCBASE 0x00030000 #define MMUTABLEBASE 0x00200000 #define MMUTABLESIZE (0x8000) #define MMUTABLEMASK ((MMUTABLESIZE-1)>>2) #define TOP_LEVEL_WORDS (1<<((31-20)+1)) #define COARSE_TABLE_WORDS (1<<((19-12)+1)) #define SMALL_TABLE_WORDS (1<<((11-0)+1)) unsigned int nextfree; //------------------------------------------------------------------- unsigned int next_coarse_offset ( unsigned int x ) { unsigned int mask; mask=(~0)<<(10-2); mask=~mask; while(x&mask) x++; //lazy brute force return(x); } //------------------------------------------------------------------- unsigned int add_one ( unsigned int add, unsigned int flags ) { unsigned int ra; unsigned int rb; unsigned int rc; //bits 31:20 index into the top level table ra=add>>20; rc=MMUTABLEBASE+(ra<<2); rb=GET32(rc); if(rb) { //printf("Address %08X already allocated\n",add); hexstring(add); hexstring(rc); hexstring(rb); hexstring(0xBADADD); return(1); } add=ra<<20; rb=next_coarse_offset(nextfree); rc=rb+COARSE_TABLE_WORDS; if(rc>=MMUTABLESIZE) { //printf("Not enough room\n"); hexstring(0xBAD); return(1); } nextfree=rc; //use course page table pointer on top level table PUT32(MMUTABLEBASE+(ra<<2),(MMUTABLEBASE+(rb<<2))|0x00000001); //fill in the course page table. with small entries for(ra=0;ra 0) *ptr++ = val; return dest; } //------------------------------------------------------------------------ void * xmalloc ( unsigned int size ) { void *ret; ret=(void *)malloc_base; malloc_base+=size; malloc_base+=3; malloc_base&=~3; return(ret); } //------------------------------------------------------------------------ void * xcalloc ( unsigned int a, unsigned int b ) { void *ret; ret=xmalloc(a*b); xmemset(ret,0,a*b); return(ret); } //------------------------------------------------------------------------ void xfree ( void *ptr ) { } //------------------------------------------------------------------------ int notmain ( void ) { unsigned long cdest; unsigned long udest; int cret; int uret; unsigned int cerrors; unsigned int uerrors; unsigned int ra; unsigned int beg,end; #ifdef ICACHE start_l1cache(); #endif //copycount=0; //setcount=0; uart_init(); hexstring(0x12345678); #ifdef MMU for(nextfree=0;nextfree