summaryrefslogtreecommitdiff
path: root/pcr/reicast-git/error-mem.txt
blob: 341d63e54979f29281edbff1429106c7c9268c4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
in fault_handler -> ../../core/linux/common.cpp : 99
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
core/linux/common.cpp
-------------------------------------------------------------------------------------------------
#if !defined(TARGET_NO_EXCEPTIONS)
bool ngen_Rewrite(unat& addr,unat retadr,unat acc);
u32* ngen_readm_fail_v2(u32* ptr,u32* regs,u32 saddr);
bool VramLockedWrite(u8* address);
bool BM_LockedWrite(u8* address);

#if HOST_OS == OS_DARWIN
void sigill_handler(int sn, siginfo_t * si, void *segfault_ctx) {

    rei_host_context_t ctx;

    context_from_segfault(&ctx, segfault_ctx);

        unat pc = (unat)ctx.pc;
        bool dyna_cde = (pc>(unat)CodeCache) && (pc<(unat)(CodeCache + CODE_SIZE));

        printf("SIGILL @ %08X, fault_handler+0x%08X ... %08X -> was not in vram, %d\n", pc, pc - (unat)sigill_handler, (unat)si->si_addr, dyna_cde);

        printf("Entering infiniloop");

        for (;;);
        printf("PC is used here %08X\n", pc);
}
#endif

#if !defined(TARGET_NO_EXCEPTIONS)
void fault_handler (int sn, siginfo_t * si, void *segfault_ctx)
{
        rei_host_context_t ctx;

        context_from_segfault(&ctx, segfault_ctx);

        bool dyna_cde = ((unat)ctx.pc>(unat)CodeCache) && ((unat)ctx.pc<(unat)(CodeCache + CODE_SIZE));

        //ucontext_t* ctx=(ucontext_t*)ctxr;
        //printf("mprot hit @ ptr 0x%08X @@ code: %08X, %d\n",si->si_addr,ctx->uc_mcontext.arm_pc,dyna_cde);


        if (VramLockedWrite((u8*)si->si_addr) || BM_LockedWrite((u8*)si->si_addr))
                return;
        #if FEAT_SHREC == DYNAREC_JIT
                #if HOST_CPU==CPU_ARM
                        else if (dyna_cde)
                        {
                                ctx.pc = (u32)ngen_readm_fail_v2((u32*)ctx.pc, ctx.r, (unat)si->si_addr);

                                context_to_segfault(&ctx, segfault_ctx);
                        }
                #elif HOST_CPU==CPU_X86
                        else if (ngen_Rewrite((unat&)ctx.pc, *(unat*)ctx.esp, ctx.eax))
                        {
                                //remove the call from call stack
                                ctx.esp += 4;
                                //restore the addr from eax to ecx so it's valid again
                                ctx.ecx = ctx.eax;

                                context_to_segfault(&ctx, segfault_ctx);
                        }
                #elif HOST_CPU == CPU_X64
                        //x64 has no rewrite support
                #else
                        #error JIT: Not supported arch
                #endif
        #endif
        else
        {
                printf("SIGSEGV @ %p (fault_handler+0x%p) ... %p -> was not in vram\n", ctx.pc, ctx.pc - (unat)fault_handler, si->si_addr);
                die("segfault");
                signal(SIGSEGV, SIG_DFL);
        }
}
#endif
-------------------------------------------------------------------------------------------------
Error on : VramLockedWrite (video-ram - 8MB) || BM_LockedWrite (motherboard-ram - 16MB)
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
core/hw/mem/_vmem.cpp
-------------------------------------------------------------------------------------------------
bool BM_LockedWrite(u8* address)
{
        if (!_nvmem_enabled())
                return false;

#if FEAT_SHREC != DYNAREC_NONE
        u32 addr=address-(u8*)p_sh4rcb->fpcb;

        address=(u8*)p_sh4rcb->fpcb+ (addr&~PAGE_MASK);

        if (addr<sizeof(p_sh4rcb->fpcb))
        {
                //printf("Allocated %d PAGES [%08X]\n",++pagecnt,addr);

#if HOST_OS==OS_WINDOWS
                verify(VirtualAlloc(address,PAGE_SIZE,MEM_COMMIT,PAGE_READWRITE));
#else
                mprotect (address, PAGE_SIZE, PROT_READ | PROT_WRITE);
#endif

                bm_vmem_pagefill((void**)address,PAGE_SIZE);

                return true;
        }
#else
die("BM_LockedWrite and NO REC");
#endif
        return false;
}
-------------------------------------------------------------------------------------------------
core/rend/TexCache.cpp
-------------------------------------------------------------------------------------------------
bool VramLockedWrite(u8* address)
{
        size_t offset=address-vram.data;

        if (offset<VRAM_SIZE)
        {

                size_t addr_hash = offset/PAGE_SIZE;
                vector<vram_block*>* list=&VramLocks[addr_hash];

                {
                        vramlist_lock.Lock();

                        for (size_t i=0;i<list->size();i++)
                        {
                                if ((*list)[i])
                                {
                                        libPvr_LockedBlockWrite((*list)[i],(u32)offset);

                                        if ((*list)[i])
                                        {
                                                msgboxf("Error : pvr is supposed to remove lock",MBX_OK);
                                                dbgbreak;
                                        }

                                }
                        }
                        list->clear();

                        vram.UnLockRegion((u32)offset&(~(PAGE_SIZE-1)),PAGE_SIZE);

                        //TODO: Fix this for 32M wrap as well
                        if (_nvmem_enabled() && VRAM_SIZE == 0x800000) {
                                vram.UnLockRegion((u32)offset&(~(PAGE_SIZE-1)) + VRAM_SIZE,PAGE_SIZE);
                        }

                        vramlist_lock.Unlock();
                }

                return true;
        }
        else
                return false;
}
-------------------------------------------------------------------------------------------------
core/rend/TexCache.h
-------------------------------------------------------------------------------------------------
void vram_LockedWrite(u32 offset64);
-------------------------------------------------------------------------------------------------
core/stdclass.cpp
-------------------------------------------------------------------------------------------------
bool VramLockedWrite(u8* address);
bool RamLockedWrite(u8* address,u32* sp);