| | 1 | /* $Header: d:/cvsroot/tads/TADS2/H_IX86.H,v 1.2 1999/05/17 02:52:12 MJRoberts Exp $ */ |
| | 2 | |
| | 3 | /* |
| | 4 | * Copyright (c) 1998, 2008 Michael J. Roberts. All Rights Reserved. |
| | 5 | * |
| | 6 | * Please see the accompanying license file, LICENSE.TXT, for information |
| | 7 | * on using and copying this software. |
| | 8 | */ |
| | 9 | /* |
| | 10 | Name |
| | 11 | h_ix86_64.h - hardware definitions for x86-64 (64-bit x86) platforms |
| | 12 | Function |
| | 13 | These definitions are designed ONLY for 64-bit x86 CPUs. Note that these |
| | 14 | probably will NOT work on 16- and 32-bit x86 hardware. |
| | 15 | Notes |
| | 16 | IMPORTANT! See the note below about the typedef for hix_int32. |
| | 17 | Modified |
| | 18 | 03/25/08 MJRoberts - created (from h_ix86.h) |
| | 19 | */ |
| | 20 | |
| | 21 | #ifndef H_IX86_64_H |
| | 22 | #define H_IX86_64_H |
| | 23 | |
| | 24 | #ifdef HAVE_CONFIG_H |
| | 25 | #include <config.h> |
| | 26 | #endif |
| | 27 | |
| | 28 | /* ------------------------------------------------------------------------ */ |
| | 29 | /* |
| | 30 | * Define local covers for the 32-bit and 16-bit integer types. |
| | 31 | * |
| | 32 | * For some of our operations, we need to translate between the local |
| | 33 | * native types and the portable types. The portable types are explicitly |
| | 34 | * defined with exact byte sizes and byte orderings. One way to do these |
| | 35 | * translations is to read and write the portable values one byte at a |
| | 36 | * time, and do some arithmetic to carry out the translation to the native |
| | 37 | * types. However, there's a more efficient approach: x86 CPUs happen to |
| | 38 | * have native types that match our portable types in size and byte order, |
| | 39 | * so the efficient way to do the translations is simply to use the correct |
| | 40 | * native type that corresponds to each portable type. |
| | 41 | * |
| | 42 | * That's the purpose of these definitions - since the portable types are |
| | 43 | * of specific sizes, we need to map the native type that exactly matches |
| | 44 | * each portable type. |
| | 45 | * |
| | 46 | * This is complicated by a *second* level of mapping, which is from C |
| | 47 | * types (short, int, long) to native types (WORD, DWORD, QWORD): this |
| | 48 | * mapping can vary by compiler. |
| | 49 | * |
| | 50 | * So, our typedefs here are designed to give us the correct mapping from C |
| | 51 | * types to portable types, by taking into account the way our compiler |
| | 52 | * maps from C to native. |
| | 53 | */ |
| | 54 | #if SIZEOF_INT == 4 |
| | 55 | typedef int hix_int32; |
| | 56 | #else |
| | 57 | #error SIZEOF_INT must be defined in your makefile - \ |
| | 58 | set SIZEOF_INT to the number of bytes in an 'int' for your compiler |
| | 59 | #endif |
| | 60 | |
| | 61 | #if SIZEOF_SHORT == 2 |
| | 62 | typedef short hix_int16; |
| | 63 | typedef unsigned short hix_uint16; |
| | 64 | #else |
| | 65 | #error SIZEOF_SHORT must be defined in your makefile - \ |
| | 66 | set SIZEOF_SHORT to the number of bytes in a 'short' for your compiler |
| | 67 | #endif |
| | 68 | |
| | 69 | /* ------------------------------------------------------------------------ */ |
| | 70 | |
| | 71 | /* round a size to worst-case alignment boundary */ |
| | 72 | #define osrndsz(s) (((s)+3) & ~3) |
| | 73 | |
| | 74 | /* round a pointer to worst-case alignment boundary */ |
| | 75 | #define osrndpt(p) ((uchar *)((((ulong)(p)) + 3) & ~3)) |
| | 76 | |
| | 77 | /* read unaligned portable unsigned 2-byte value, returning int */ |
| | 78 | #define osrp2(p) ((int)*(hix_uint16 *)(p)) |
| | 79 | |
| | 80 | /* read unaligned portable signed 2-byte value, returning int */ |
| | 81 | #define osrp2s(p) ((int)*(hix_int16 *)(p)) |
| | 82 | |
| | 83 | /* write int to unaligned portable 2-byte value */ |
| | 84 | #define oswp2(p, i) (*(hix_uint16 *)(p)=(hix_uint16)(i)) |
| | 85 | |
| | 86 | /* read unaligned portable 4-byte value, returning long */ |
| | 87 | #define osrp4(p) (*(hix_int32 *)(p)) |
| | 88 | |
| | 89 | /* write long to unaligned portable 4-byte value */ |
| | 90 | #define oswp4(p, l) (*(hix_int32 *)(p)=(l)) |
| | 91 | |
| | 92 | |
| | 93 | #endif /* H_IX86_64_H */ |
| | 94 | |