mirror of
https://github.com/mikpe/pdp10-tools.git
synced 2026-01-26 04:02:19 +00:00
Initial import
This commit is contained in:
134
include/pdp10-arith.h
Normal file
134
include/pdp10-arith.h
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* pdp10-arith.h
|
||||
*
|
||||
* Provide functions for performing arithmetic operations on PDP10 integer types.
|
||||
* Currently only 36-bit signed operations are supported.
|
||||
*/
|
||||
#ifndef PDP10_ARITH_H
|
||||
#define PDP10_ARITH_H
|
||||
|
||||
#include "pdp10-stdint.h"
|
||||
|
||||
/* Zero-extend a pdp10_{u,}int36_t to the full width of its representation type.
|
||||
* Use this to prepare operands before unsigned operations, or to correct results
|
||||
* after signed operations.
|
||||
*/
|
||||
static inline pdp10_uint36_t pdp10_zext_uint36(pdp10_uint36_t x)
|
||||
{
|
||||
return x & PDP10_UINT36_MAX;
|
||||
}
|
||||
|
||||
/* Sign-extend a pdp10_int36_t to the full width of its representation type.
|
||||
* Use this to prepare operands before signed operations.
|
||||
*
|
||||
* Based on the following trick for sign-extending an octet x: ((x & 0xff) ^ 0x80) - 0x80,
|
||||
* c.f. <http://sourceware.org/ml/binutils/2001-05/msg00093.html>.
|
||||
*/
|
||||
static inline pdp10_int36_t pdp10_sext_int36(pdp10_uint36_t x)
|
||||
{
|
||||
const pdp10_uint36_t PDP10_UINT36_SBIT = ~(PDP10_UINT36_MAX >> 1) & PDP10_UINT36_MAX;
|
||||
|
||||
return ((x & PDP10_UINT36_MAX) ^ PDP10_UINT36_SBIT) - PDP10_UINT36_SBIT;
|
||||
}
|
||||
|
||||
static inline pdp10_uint36_t pdp10_neg_int36(pdp10_uint36_t x)
|
||||
{
|
||||
return pdp10_zext_uint36(-pdp10_sext_int36(x));
|
||||
}
|
||||
|
||||
static inline pdp10_uint36_t pdp10_not_int36(pdp10_uint36_t x)
|
||||
{
|
||||
return pdp10_zext_uint36(~pdp10_sext_int36(x));
|
||||
}
|
||||
|
||||
static inline pdp10_uint36_t pdp10_add_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_zext_uint36(pdp10_sext_int36(x) + pdp10_sext_int36(y));
|
||||
}
|
||||
|
||||
static inline pdp10_uint36_t pdp10_sub_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_zext_uint36(pdp10_sext_int36(x) - pdp10_sext_int36(y));
|
||||
}
|
||||
|
||||
static inline pdp10_uint36_t pdp10_mul_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_zext_uint36(pdp10_sext_int36(x) * pdp10_sext_int36(y));
|
||||
}
|
||||
|
||||
static inline pdp10_uint36_t pdp10_div_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_zext_uint36(pdp10_sext_int36(x) / pdp10_sext_int36(y));
|
||||
}
|
||||
|
||||
static inline pdp10_uint36_t pdp10_rem_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_zext_uint36(pdp10_sext_int36(x) % pdp10_sext_int36(y));
|
||||
}
|
||||
|
||||
static inline pdp10_uint36_t pdp10_lsl_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_zext_uint36(pdp10_zext_uint36(x) << pdp10_zext_uint36(y));
|
||||
}
|
||||
|
||||
static inline pdp10_uint36_t pdp10_lsr_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_zext_uint36(pdp10_zext_uint36(x) >> pdp10_zext_uint36(y));
|
||||
}
|
||||
|
||||
static inline pdp10_uint36_t pdp10_asr_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_zext_uint36(pdp10_sext_int36(x) >> pdp10_zext_uint36(y));
|
||||
}
|
||||
|
||||
static inline pdp10_uint36_t pdp10_or_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return (pdp10_zext_uint36(x) | pdp10_zext_uint36(y));
|
||||
}
|
||||
|
||||
static inline pdp10_uint36_t pdp10_and_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return (pdp10_zext_uint36(x) & pdp10_zext_uint36(y));
|
||||
}
|
||||
|
||||
static inline pdp10_uint36_t pdp10_xor_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return (pdp10_zext_uint36(x) ^ pdp10_zext_uint36(y));
|
||||
}
|
||||
|
||||
static inline int pdp10_eq_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_zext_uint36(x) == pdp10_zext_uint36(y);
|
||||
}
|
||||
|
||||
static inline int pdp10_ne_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_zext_uint36(x) != pdp10_zext_uint36(y);
|
||||
}
|
||||
|
||||
static inline int pdp10_lt_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_sext_int36(x) < pdp10_sext_int36(y);
|
||||
}
|
||||
|
||||
static inline int pdp10_gt_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_sext_int36(x) > pdp10_sext_int36(y);
|
||||
}
|
||||
|
||||
static inline int pdp10_ge_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_sext_int36(x) >= pdp10_sext_int36(y);
|
||||
}
|
||||
|
||||
static inline int pdp10_le_int36(pdp10_uint36_t x, pdp10_uint36_t y)
|
||||
{
|
||||
return pdp10_sext_int36(x) <= pdp10_sext_int36(y);
|
||||
}
|
||||
|
||||
static inline int pdp10_nonzero_int36(pdp10_uint36_t x)
|
||||
{
|
||||
return pdp10_zext_uint36(x) != 0;
|
||||
}
|
||||
|
||||
#endif /* PDP10_ARITH_H */
|
||||
1235
include/pdp10-elf36.h
Normal file
1235
include/pdp10-elf36.h
Normal file
File diff suppressed because it is too large
Load Diff
28
include/pdp10-extint.h
Normal file
28
include/pdp10-extint.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* pdp10-extint.h
|
||||
*
|
||||
* Provide types and procedures for converting 18 and 36-bit integers
|
||||
* to and from arrays of 9-bit bytes (nonets). Use these together with
|
||||
* pdp10_fread() and pdp10_fwrite() to convert 18 and 36-bit integers
|
||||
* between host-level and file-level binary representations.
|
||||
*/
|
||||
#ifndef PDP10_EXTINT_H
|
||||
#define PDP10_EXTINT_H
|
||||
|
||||
#include "pdp10-stdint.h"
|
||||
|
||||
typedef struct {
|
||||
pdp10_uint9_t x[2];
|
||||
} pdp10_ext_uint18_t;
|
||||
|
||||
void pdp10_uint18_to_ext(pdp10_uint18_t val, pdp10_ext_uint18_t *ext);
|
||||
pdp10_uint18_t pdp10_uint18_from_ext(const pdp10_ext_uint18_t *ext);
|
||||
|
||||
typedef struct {
|
||||
pdp10_uint9_t x[4];
|
||||
} pdp10_ext_uint36_t;
|
||||
|
||||
void pdp10_uint36_to_ext(pdp10_uint36_t val, pdp10_ext_uint36_t *ext);
|
||||
pdp10_uint36_t pdp10_uint36_from_ext(const pdp10_ext_uint36_t *ext);
|
||||
|
||||
#endif /* PDP10_EXTINT_H */
|
||||
38
include/pdp10-inttypes.h
Normal file
38
include/pdp10-inttypes.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* pdp10-inttypes.h
|
||||
*
|
||||
* Provide format conversions for 18 and 36-bit integers.
|
||||
* For 9-bit integers, pdp_uint9_t, just use the regular
|
||||
* int-sized d/o/u/x formats.
|
||||
*/
|
||||
#ifndef PDP10_INTTYPES_H
|
||||
#define PDP10_INTTYPES_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "pdp10-stdint.h"
|
||||
|
||||
#if defined(UINT18_MAX)
|
||||
#define PDP10_PRId18 PRId18
|
||||
#define PDP10_PRIo18 PRIo18
|
||||
#define PDP10_PRIu18 PRIu18
|
||||
#define PDP10_PRIx18 PRIx18
|
||||
#else
|
||||
#define PDP10_PRId18 PRId32
|
||||
#define PDP10_PRIo18 PRIo32
|
||||
#define PDP10_PRIu18 PRIu32
|
||||
#define PDP10_PRIx18 PRIx32
|
||||
#endif
|
||||
|
||||
#if defined(UINT36_MAX)
|
||||
#define PDP10_PRId36 PRId36
|
||||
#define PDP10_PRIo36 PRIo36
|
||||
#define PDP10_PRIu36 PRIu36
|
||||
#define PDP10_PRIx36 PRIx36
|
||||
#else
|
||||
#define PDP10_PRId36 PRId64
|
||||
#define PDP10_PRIo36 PRIo64
|
||||
#define PDP10_PRIu36 PRIu64
|
||||
#define PDP10_PRIx36 PRIx64
|
||||
#endif
|
||||
|
||||
#endif /* PDP10_INTTYPES_H */
|
||||
71
include/pdp10-stdint.h
Normal file
71
include/pdp10-stdint.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* pdp10-stdint.h
|
||||
*
|
||||
* Provide stdint.h-like type names and macros for 9, 18, and 36-bit unsigned
|
||||
* integer types.
|
||||
*
|
||||
* Standard uint<N>_t types must not contain any any extraneous bits, but that
|
||||
* cannot be guaranteed for these 9, 18, and 36-bit types when they are embedded
|
||||
* in larger 16, 32, and 64-bit host types. For arithmetic on these types, use
|
||||
* the operations provided by pdp10-arith.h.
|
||||
*
|
||||
* Do not use these 18 or 36-bit types for file-level binary data structures,
|
||||
* instead use the pdp10-extint.h and pdp10-stdio.h facilities to explicitly
|
||||
* convert between file-level and host-level binary data structures.
|
||||
*/
|
||||
#ifndef PDP10_STDINT_H
|
||||
#define PDP10_STDINT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(UINT9_MAX)
|
||||
|
||||
typedef uint9_t pdp10_uint9_t;
|
||||
#define PDP10_UINT9_MAX UINT9_MAX
|
||||
#define PDP10_UINT9_C(c) UINT9_C(c)
|
||||
|
||||
#else /* !UINT9_MAX */
|
||||
|
||||
typedef uint16_t pdp10_uint9_t;
|
||||
#define PDP10_UINT9_MAX ((1U << 9) - 1)
|
||||
#define PDP10_UINT9_C(c) c
|
||||
|
||||
#endif /* !UINT9_MAX */
|
||||
|
||||
#if defined(UINT18_MAX)
|
||||
|
||||
typedef uint18_t pdp10_uint18_t;
|
||||
#define PDP10_UINT18_MAX UINT18_MAX
|
||||
#define PDP10_UINT18_C(c) UINT18_C(c)
|
||||
|
||||
#else /* !UINT18_MAX */
|
||||
|
||||
typedef uint32_t pdp10_uint18_t;
|
||||
#define PDP10_UINT18_MAX ((1UL << 18) - 1)
|
||||
#define PDP10_UINT18_C(c) c ## U
|
||||
|
||||
#endif /* !UINT18_MAX */
|
||||
|
||||
#if defined(UINT36_MAX)
|
||||
|
||||
typedef uint36_t pdp10_uint36_t;
|
||||
#define PDP10_UINT36_MAX UINT36_MAX
|
||||
#define PDP10_UINT36_C(c) UINT36_C(c)
|
||||
|
||||
typedef int36_t pdp10_int36_t;
|
||||
#define PDP10_INT36_MAX INT36_MAX
|
||||
#define PDP10_INT36_C(c) INT36_C(c)
|
||||
|
||||
#else /* !UINT36_MAX */
|
||||
|
||||
typedef uint64_t pdp10_uint36_t;
|
||||
#define PDP10_UINT36_MAX ((1ULL << 36) - 1)
|
||||
#define PDP10_UINT36_C(c) c ## ULL
|
||||
|
||||
typedef int64_t pdp10_int36_t;
|
||||
#define PDP10_INT36_MAX ((1LL << (36 - 1)) - 1)
|
||||
#define PDP10_INT36_C(c) c ## LL
|
||||
|
||||
#endif /* !UINT36_MAX */
|
||||
|
||||
#endif /* PDP10_STDINT_H */
|
||||
38
include/pdp10-stdio.h
Normal file
38
include/pdp10-stdio.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* pdp10-stdio.h
|
||||
*
|
||||
* Provide stdio.h-like interface for I/O to and from files with 9-bit logical bytes (nonets),
|
||||
* represented by native files with 8-bit physical bytes (octets).
|
||||
*/
|
||||
#ifndef PDP10_STDIO_H
|
||||
#define PDP10_STDIO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct pdp10_file;
|
||||
typedef struct pdp10_file PDP10_FILE;
|
||||
|
||||
/* append modes are not permitted */
|
||||
PDP10_FILE *pdp10_fopen(const char *path, const char *mode);
|
||||
|
||||
int pdp10_fflush(PDP10_FILE *pdp10fp);
|
||||
int pdp10_fclose(PDP10_FILE *pdp10fp);
|
||||
int pdp10_fgetc(PDP10_FILE *pdp10fp); /* returns a nonet, [0-511], or EOF */
|
||||
int pdp10_fputc(uint16_t nonet_ch, PDP10_FILE *pdp10fp);
|
||||
|
||||
enum {
|
||||
PDP10_SEEK_SET = 0,
|
||||
PDP10_SEEK_CUR = 1,
|
||||
PDP10_SEEK_END = 2,
|
||||
};
|
||||
int pdp10_fseeko(PDP10_FILE *pdp10fp, off_t offset, int whence);
|
||||
|
||||
/* pdp10_fread() and pdp10_fwrite() deliberately only permit transfers of strings
|
||||
* (size == 1), marshalled 9/18/36-bit primitives (nmemb == 1, size == 1, 2, or 4),
|
||||
* or empty objects (size == 0 || nmemb == 0). To transfer structures, transfer
|
||||
* their primitive fields individually.
|
||||
*/
|
||||
size_t pdp10_fread(uint16_t *ptr, size_t size, size_t nmemb, PDP10_FILE *pdp10fp);
|
||||
size_t pdp10_fwrite(const uint16_t *ptr, size_t size, size_t nmemb, PDP10_FILE *pdp10fp);
|
||||
|
||||
#endif /* PDP10_STDIO_H */
|
||||
Reference in New Issue
Block a user