disable lcd controller when booting linux, this prevents ghost-lines while
[linexec-j720] / memory.cpp
1 #include "stdafx.h"
2 #include "tester1.h"
3 #include <commctrl.h>
4 //#include <aygshell.h>
5 #include <sipapi.h>
6 #include "setup.h"
7
8 UINT32 ReadPhysical(UINT32 adr)
9 {
10         UINT32 base=  adr&0xffff0000;
11         UINT32 offset=adr&0x0000ffff;
12         UINT32 *p=(UINT32*)VirtualAlloc(0,0x10000,MEM_RESERVE,PAGE_READWRITE);
13         if(!p) return 0xFFFFFFFF;
14         if(!VirtualCopy((void*)p,(void*)(base/256),0x10000,PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL)) return 0xFFFFFFFF;
15         UINT32 val=p[offset/4];
16         VirtualFree(p,0,MEM_RELEASE);
17         return val;
18 }
19
20 void WritePhysical(UINT32 adr,UINT32 val)
21 {
22         UINT32 base=  adr&0xffff0000;
23         UINT32 offset=adr&0x0000ffff;
24         UINT32 *p=(UINT32*)VirtualAlloc(0,0x10000,MEM_RESERVE,PAGE_READWRITE);
25         VirtualCopy((void*)p,(void*)(base/256),0x10000,PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
26         p[offset/4]=val;
27         VirtualFree(p,0,MEM_RELEASE);
28 }
29
30 UINT32 VirtualToPhysical(UINT32 Virtual)
31 {
32         FILE *log=fopen("\\logger1.txt","w");
33
34         fprintf(log,"virtual: 0x%lx\n",Virtual);
35         UINT32 mmu=(UINT32)read_mmu();
36 //      mmu=0xa0000000;
37         fprintf(log,"mmu:  0x%lx \n",mmu);
38
39         UINT32 AdrFirstLevDesc=(mmu&0xffffc000)+((Virtual>>18)&0xfffffffc);
40         fprintf(log,"AdrFirstLevDesc:  0x%lx \n",AdrFirstLevDesc);
41
42         UINT32 FirstLevDesc=ReadPhysical(AdrFirstLevDesc);
43         fprintf(log,"FirstLevDesc:  0x%lx \n",FirstLevDesc);
44
45         
46         if(0)
47         {
48                 fprintf(log,"Page\n");
49                 UINT32 PhysAddr=(FirstLevDesc&0xfff00000)+(Virtual&0xfffff);
50                 fprintf(log,"Physical address:  0x%lx \n",PhysAddr);
51                 fclose(log);
52                 return PhysAddr;
53         }
54
55         if(FirstLevDesc&0x3==3) // tiny page
56         {
57                 fprintf(log,"Tiny page\n");
58                 UINT32 AdrSecondLevDesc=(FirstLevDesc&0xfffff000)+((Virtual>>8)&0xffc);
59                 fprintf(log,"AdrSecondLevDesc:  0x%lx \n",AdrSecondLevDesc);
60
61                 UINT32 SecondLevDesc=ReadPhysical(AdrSecondLevDesc);
62                 fprintf(log,"SecondLevDesc:  0x%lx \n",SecondLevDesc);
63         
64                 UINT32 PhysAddr=(SecondLevDesc&0xffffc000)+(Virtual&0x3ff);
65                 fprintf(log,"Physical address:  0x%lx \n",PhysAddr);
66                 fclose(log);
67                 return PhysAddr;
68         }
69 //      if(FirstLevDesc&0x3==3) // small page
70         {
71                 fprintf(log,"Else page\n");
72                 UINT32 AdrSecondLevDesc=(FirstLevDesc&0xfffffc00)+((Virtual>>10)&0x03fc);
73                 fprintf(log,"AdrSecondLevDesc:  0x%lx \n",AdrSecondLevDesc);
74
75                 UINT32 SecondLevDesc=ReadPhysical(AdrSecondLevDesc);
76                 fprintf(log,"SecondLevDesc:  0x%lx \n",SecondLevDesc);
77
78                 UINT32 PhysAddr=(SecondLevDesc&0xffff0000)+(Virtual&0xffff);
79                 fprintf(log,"Physical address:  0x%lx \n",PhysAddr);
80                 fclose(log);
81                 return PhysAddr;
82
83         }
84 }
85
86
87
88
89
90
91 void DumpMMU()
92 {
93         void *mmu=(void*)(MEM_START);
94
95         UINT32 *_mmu=(UINT32*)VirtualAlloc((void*)0x0,sizeof(void*)*0xffff, MEM_RESERVE,PAGE_READWRITE);
96         int ret=VirtualCopy(_mmu,(void *) ((UINT32)mmu/256),sizeof(void*)*0xffff        , PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
97
98         FILE *log=fopen("\\logger2.txt","w");
99         fprintf(log,"mmu_table=0x%lx : \n",_mmu);
100         fprintf(log,"mmu=0x%lx : \n",mmu);
101         fprintf(log,"ret=0x%x : \n",ret);
102         for(UINT32 z=0;z<=0x0100;z++)
103                 fprintf(log,"mmu_table[0x%x]=0x%lx: \n",z,_mmu[z]);
104         fclose(log);
105         return;
106 }