English Amiga Board


Go Back   English Amiga Board > Support > support.WinUAE

 
 
Thread Tools
Old 30 March 2010, 18:53   #1
ara
Registered User
 
Join Date: Oct 2009
Location: Belgium
Age: 50
Posts: 42
access emulated memory

Hi,

Actually I have a question, not really a problem. The question is quite technical...

I would like to access the emulated Amiga memory from the x86 side as efficiently as possible. Is the following piece of code okay?
Quote:
// Read a byte from (a0). Just an example!
uae_u8 b ;
if(canbang)
b=NATMEM_OFFSET[m68k_areg(regs,0)] ;
else
b=get_byte(m68k_areg(regs,0)) ;
Seems to work here for "ordinary" memory accesses. But what about accesses to custom chip registers, etc? The code generated by the JIT compiler seems to simply read and write the "real" x86 memory without further checks but I have to admit that I don't understand every detail (for example, the test of the "special_mem" flag in "compemu_support/readbyte.cpp").
ara is offline  
Old 30 March 2010, 19:40   #2
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,506
Your code fails when accessing IO regions.

special_mem is the important bit. JIT uses normal (indirect) memory access functions when building native x86 code, direct access is only enabled if special_mem has correct flags set after memory access function returns.

Do not assume if memory region is directly accessible by checking address ranges. ("too easy solution but too fragile")

You only need to do normal indirect "check" access only once per memory "bank" to confirm if direct access is supported.
Toni Wilen is offline  
Old 30 March 2010, 23:20   #3
ara
Registered User
 
Join Date: Oct 2009
Location: Belgium
Age: 50
Posts: 42
Quote:
Originally Posted by Toni Wilen View Post
special_mem is the important bit. JIT uses normal (indirect) memory access functions when building native x86 code, direct access is only enabled if special_mem has correct flags set after memory access function returns.
Sorry for asking again, but it seems that the JIT compiler is a hard piece of code, at least for me. Could you explain how it works, please?:

In "newcpu/execute_normal", the emulator executes one instruction after the other until a jump instruction is reached (end of block). For each instruction, it remembers the status of the memory access:
Quote:
pc_hist[blocklen].specmem = special_mem;
Then, it starts to compile in "compemu_support/compile_block". Each time it generates the x86 code for a 68000 instruction, it first restores the "special_mem" flag:
Quote:
special_mem=pc_hist[i].specmem;
Does that mean that it generates direct-access x86 code if the corresponding 68000 instruction accessed "normal" memory? If the answer is yes, how can that work
  1. in case of memory accesses via address register (variable destination address, sometimes normal memory, sometimes IO region)?
  2. in case of instructions with two memory accesses (source and destination)?
It can't work like I described it above, can it? What is my mistake?

Last edited by ara; 30 March 2010 at 23:25.
ara is offline  
Old 30 March 2010, 23:37   #4
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,506
Quote:
Originally Posted by ara View Post
Sorry for asking again, but it seems that the JIT compiler is a hard piece of code, at least for me. Could you explain how it works, please?:
I don't know how it exactly works and I don't want to know

Quote:
Does that mean that it generates direct-access x86 code if the corresponding 68000 instruction accessed "normal" memory? If the answer is yes, how can that work
Correct, it works because of installed exception (access violation) handler. All non-direct memory banks are not mapped in host's memory space (host OS does this magic), any direct read or write triggers the exception routine that analyses the failed access and fixes it. (I don't know how)
Toni Wilen is offline  
Old 30 March 2010, 23:46   #5
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,506
I think this is fast and safe and is not JIT specific:

if (valid_address(addr, len))
paddr = get_real_address(addr); // paddr can be used directly
else
// loop using get_byte() or similar
Toni Wilen is offline  
Old 31 March 2010, 00:43   #6
ara
Registered User
 
Join Date: Oct 2009
Location: Belgium
Age: 50
Posts: 42
Thanks for your help. The solution based on valid_address/get_real_address looks fine.

I just took a look at EvalException(...). Oh my god...
What happens if you have an illegal memory access inside the WinUAE code due to an ordinary bug? Will it also try to "fix" it?
ara is offline  
Old 03 April 2010, 13:05   #7
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,506
Quote:
Originally Posted by ara View Post
Thanks for your help. The solution based on valid_address/get_real_address looks fine.

I just took a look at EvalException(...). Oh my god...
Now you know why nobody wants to work with JIT code

Quote:
What happens if you have an illegal memory access inside the WinUAE code due to an ordinary bug? Will it also try to "fix" it?
I am not sure but I think exception handler will sometimes attempt to fix real bugs too.. (I have seen weird things happening like illegal access in GUI code causing weird insta-returns from C functions..)
Toni Wilen is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
memory access speed question Lord Riton Coders. General 42 27 February 2019 14:26
Break on Memory Access? Khyron support.WinUAE 3 21 August 2010 00:10
Blizzard Turbo Memory - SMD memory chips doesn't work sanjyuubi Hardware mods 5 26 May 2010 15:40
HOWTO : Access the Interwebs from within an emulated WB NewDeli New to Emulation or Amiga scene 16 29 September 2009 00:54
System you would like to see emulated next Ian Retrogaming General Discussion 18 08 November 2001 08:16

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 18:09.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.56467 seconds with 13 queries