Re: bochs on sparc/solaris

David Laight <[email protected]>
Newsgroups gmane.comp.emulators.bochs.devel
Message-ID <[email protected]>
On Fri, Dec 28, 2012 at 08:37:46AM +0200, Stanislav wrote:
> There are several ways to workaround this.
> 
> First and preferable is to find appropriate compiler extension to mark
> memory access as unaligned.
> Smth like:
> 
> +#define WriteHostWordToLittleEndian(hostPtr,  nativeVar16) \
> +    *((Bit16u UNALIGNED*)(hostPtr)) = bswap16(nativeVar16)
> 
> Second is to rewrite the memory access macros (for all data sizes) to
> read/write data in byte granularity ad then to collect them into register.
> It was in old Bochs versions before but was removed because we assumed that
> almost all BE systems already support unaligned access.
> Here is the block (taken from Bochs 2.1 sources):
> 
> #define WriteHostWordToLittleEndian(hostPtr,  nativeVar16) { \
>     ((Bit8u *)(hostPtr))[0] = (Bit8u)  (nativeVar16); \
>     ((Bit8u *)(hostPtr))[1] = (Bit8u) ((nativeVar16)>>8); \
>     }

For gcc compiled code, you can define a structure member to have a
smaller alignment that would be usual. Referencing it on (say) sparc
will cause the compiler to generate the required byte accesses and
shifts.

For ppc (with recent gcc) you want to use the gcc builtin for
byteswap - so that the compiler can use the byteswapping memory
accesses (same is probably true for some (not-ancient) sparc cpu).

Faulting mis-aligned accesses is more comman than you you might think.
Hardware supports gets less trivial when the the word crosses page
boundaries.

	David

-- 
David Laight: [email protected]

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122912
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.