1
0
mirror of https://github.com/open-simh/simh.git synced 2026-04-25 03:44:58 +00:00

SCP: HP Only SCP and additional 3.11.2 JDB SCP Extensions

This commit is contained in:
J. David Bryan
2021-01-19 19:23:33 -08:00
committed by Mark Pizzolato
parent 79f71ce384
commit 685ca317a3
13 changed files with 565 additions and 193 deletions

View File

@@ -1,6 +1,6 @@
/* sim_shmem.c: simulator shared memory library
Copyright (c) 2015-2016, Robert M Supnik
Copyright (c) 2015-2020, Robert M Supnik
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -23,6 +23,9 @@
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from Robert M Supnik.
25-Aug-20 JDB Added __FreeBSD__ define to Unix implementation guard
01-Jul-20 JDB Added __CYGWIN__ define to Unix implementation guard
This library includes:
sim_shmem_open create or attach to a shared memory region
@@ -119,7 +122,7 @@ t_bool sim_shmem_atomic_cas (int32 *ptr, int32 oldv, int32 newv)
return (InterlockedCompareExchange ((LONG volatile *) ptr, newv, oldv) == oldv);
}
#elif defined (__linux__) || defined (__APPLE__)
#elif defined (__linux__) || defined (__APPLE__) || defined (__CYGWIN__) || defined (__FreeBSD__)
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -134,7 +137,7 @@ struct SHMEM {
t_stat sim_shmem_open (const char *name, size_t size, SHMEM **shmem, void **addr)
{
#ifdef HAVE_SHM_OPEN
#if defined (HAVE_SHM_OPEN) && defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
*shmem = (SHMEM *)calloc (1, sizeof(**shmem));
mode_t orig_mask;
@@ -191,25 +194,30 @@ if ((*shmem)->shm_base == MAP_FAILED) {
*addr = (*shmem)->shm_base;
return SCPE_OK;
#else
*shmem = NULL;
return SCPE_NOFNC;
#endif
}
void sim_shmem_close (SHMEM *shmem)
{
#if defined (HAVE_SHM_OPEN)
if (shmem == NULL)
return;
if (shmem->shm_base != MAP_FAILED)
munmap (shmem->shm_base, shmem->shm_size);
if (shmem->shm_fd != -1)
if (shmem->shm_fd != -1) {
shm_unlink (shmem->shm_name);
close (shmem->shm_fd);
}
free (shmem->shm_name);
free (shmem);
#endif
}
int32 sim_shmem_atomic_add (int32 *p, int32 v)
{
#if defined (HAVE_GCC_SYNC_BUILTINS)
#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
return __sync_add_and_fetch((int *) p, v);
#else
return *p + v;
@@ -218,7 +226,7 @@ return *p + v;
t_bool sim_shmem_atomic_cas (int32 *ptr, int32 oldv, int32 newv)
{
#if defined (HAVE_GCC_SYNC_BUILTINS)
#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
return __sync_bool_compare_and_swap (ptr, oldv, newv);
#else
if (*ptr == oldv) {