* Add SystemV IPC drivers to PSIM
@ 2008-09-08 15:45 Joel Sherrill
0 siblings, 0 replies; 10+ messages in thread
From: Joel Sherrill @ 2008-09-08 15:45 UTC (permalink / raw)
To: Ralf Corsepius, gdb
[-- Attachment #1: Type: text/plain, Size: 1475 bytes --]
Hi,
As the first year in the copyright shows, this code
has been around a while. I found a message in the
RTEMS archives where I was updating it to gdb 4.17. :)
It adds support for System V semaphores and shared memory to psim.
It adds two files (hw_sem.c and hw_shm.c) and touches configure.ac
to add tests for support of System V IPC. Please regenerate
configure after patching.
The shared memory device maps System V shared memory
into the simulated PowerPC's address space. This lets
the simulated CPU share data with the host environment.
This data area can be protected by using the System V
semaphore device to lock the memory.
We use this to run RTEMS multiprocessor tests where the
two simulated CPUs communicate through the shared memory.
It has also been used by RTEMS applications to do "device IO"
to the shared memory and have a custom system simulator
provide feedback.
Can someone please review and commit? Thanks.
2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
* configure: Regenerated.
* configure.ac: Add test for System V shared memory and semaphore.
* debug.c, debug.h: Add trace support for new devices.
* hw_sem.c, hw_shm.c: New files.
* Makefile.in: Add hw_sem.c and hw_shm.c
--
Joel Sherrill, Ph.D. Director of Research & Development
joel.sherrill@OARcorp.com On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985
[-- Attachment #2: gdb-6.8-sysv-ipc-1.diff --]
[-- Type: text/x-patch, Size: 19804 bytes --]
diff -uNr --exclude configure --exclude autom4te.cache gdb-6.8-orig/sim/ppc/configure.ac gdb-6.8/sim/ppc/configure.ac
--- gdb-6.8-orig/sim/ppc/configure.ac 2008-03-14 16:35:27.000000000 -0500
+++ gdb-6.8/sim/ppc/configure.ac 2008-09-02 09:58:42.000000000 -0500
@@ -209,10 +209,105 @@
esac
])dnl
+AC_CACHE_CHECK([if union semun defined],
+ ac_cv_HAS_UNION_SEMUN,
+ [AC_TRY_COMPILE([
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>],
+[union semun arg ;],
+[ac_cv_has_union_semun="yes"],
+[ac_cv_has_union_semun="no"])
+AC_MSG_RESULT($ac_cv_has_union_semun)
+])
+
+
+if test "$ac_cv_has_union_semun" = "yes"; then
+ AC_CACHE_CHECK(whether System V semaphores are supported,
+ ac_cv_sysv_sem,
+ [
+ AC_TRY_RUN(
+ [
+ #include <sys/types.h>
+ #include <sys/ipc.h>
+ #include <sys/sem.h>
+ int main () {
+ union semun arg ;
+
+ int id=semget(IPC_PRIVATE,1,IPC_CREAT|0400);
+ if (id == -1)
+ exit(1);
+ arg.val = 0; /* avoid implicit type cast to union */
+ if (semctl(id, 0, IPC_RMID, arg) == -1)
+ exit(1);
+ exit(0);
+ }
+ ],
+ ac_cv_sysv_sem="yes", ac_cv_sysv_sem="no", :)
+ ])
+else # semun is not defined
+ AC_CACHE_CHECK(whether System V semaphores are supported,
+ ac_cv_sysv_sem,
+ [
+ AC_TRY_RUN(
+ [
+ #include <sys/types.h>
+ #include <sys/ipc.h>
+ #include <sys/sem.h>
+ union semun {
+ int val;
+ struct semid_ds *buf;
+ ushort *array;
+ };
+ int main () {
+ union semun arg ;
+
+ int id=semget(IPC_PRIVATE,1,IPC_CREAT|0400);
+ if (id == -1)
+ exit(1);
+ arg.val = 0; /* avoid implicit type cast to union */
+ if (semctl(id, 0, IPC_RMID, arg) == -1)
+ exit(1);
+ exit(0);
+ }
+ ],
+ ac_cv_sysv_sem="yes", ac_cv_sysv_sem="no", :)
+ ])
+fi
+
+AC_CACHE_CHECK(whether System V shared memory is supported,
+ac_cv_sysv_shm,
+[
+AC_TRY_RUN([
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+int main () {
+ int id=shmget(IPC_PRIVATE,1,IPC_CREAT|0400);
+ if (id == -1)
+ exit(1);
+ if (shmctl(id, IPC_RMID, 0) == -1)
+ exit(1);
+ exit(0);
+}
+],
+ac_cv_sysv_shm="yes", ac_cv_sysv_shm="no", :)
+])
+
+if test x"$ac_cv_sysv_shm" = x"yes" -a x"$ac_cv_sysv_sem" = x"yes" ; then
+ sim_sysv_ipc_hw=",sem,shm";
+else
+ sim_sysv_ipc_hw="";
+fi
+
+if test x"$ac_cv_has_union_semun" = x"yes" -a x"$ac_cv_sysv_sem" = x"yes" ; then
+ sim_hwflags="-DHAS_UNION_SEMUN";
+fi
+
AC_ARG_ENABLE(sim-hardware,
[ --enable-sim-hardware=list Specify the hardware to be included in the build.],
-[hardware="cpu,memory,nvram,iobus,htab,disk,trace,register,vm,init,core,pal,com,eeprom,opic,glue,phb,ide"
+[hardware="cpu,memory,nvram,iobus,htab,disk,trace,register,vm,init,core,pal,com,eeprom,opic,glue,phb,ide${sim_sysv_ipc_hw}"
case "${enableval}" in
yes) ;;
no) AC_MSG_ERROR("List of hardware must be specified for --enable-sim-hardware"); hardware="";;
@@ -224,14 +319,13 @@
sim_hw_obj=`echo $sim_hw_src | sed -e 's/\.c/.o/g'`
if test x"$silent" != x"yes" && test x"$hardware" != x""; then
echo "Setting hardware to $sim_hw_src, $sim_hw_obj"
-fi],[hardware="cpu,memory,nvram,iobus,htab,disk,trace,register,vm,init,core,pal,com,eeprom,opic,glue,phb,ide"
+fi],[hardware="cpu,memory,nvram,iobus,htab,disk,trace,register,vm,init,core,pal,com,eeprom,opic,glue,phb,ide${sim_sysv_ipc_hw}"
sim_hw_src=`echo $hardware | sed -e 's/,/.c hw_/g' -e 's/^/hw_/' -e s'/$/.c/'`
sim_hw_obj=`echo $sim_hw_src | sed -e 's/\.c/.o/g'`
if test x"$silent" != x"yes"; then
echo "Setting hardware to $sim_hw_src, $sim_hw_obj"
fi])dnl
-
AC_ARG_ENABLE(sim-hostbitsize,
[ --enable-sim-hostbitsize=32|64 Specify host bitsize (32 or 64).],
[case "${enableval}" in
diff -uNr --exclude configure --exclude autom4te.cache gdb-6.8-orig/sim/ppc/debug.c gdb-6.8/sim/ppc/debug.c
--- gdb-6.8-orig/sim/ppc/debug.c 1999-04-15 20:35:08.000000000 -0500
+++ gdb-6.8/sim/ppc/debug.c 2008-09-02 16:15:30.000000000 -0500
@@ -70,6 +70,8 @@
{ trace_pass_device, "pass-device" },
{ trace_phb_device, "phb-device" },
{ trace_register_device, "register-device", "Device initializing registers" },
+ { trace_sem_device, "sem-device" },
+ { trace_shm_device, "shm-device" },
{ trace_stack_device, "stack-device" },
{ trace_vm_device, "vm-device" },
/* packages */
diff -uNr --exclude configure --exclude autom4te.cache gdb-6.8-orig/sim/ppc/debug.h gdb-6.8/sim/ppc/debug.h
--- gdb-6.8-orig/sim/ppc/debug.h 1999-04-15 20:35:08.000000000 -0500
+++ gdb-6.8/sim/ppc/debug.h 2008-09-02 16:15:34.000000000 -0500
@@ -51,6 +51,8 @@
trace_pal_device,
trace_pass_device,
trace_phb_device,
+ trace_sem_device,
+ trace_shm_device,
trace_stack_device,
trace_register_device,
trace_vm_device,
diff -uNr --exclude configure --exclude autom4te.cache gdb-6.8-orig/sim/ppc/hw_sem.c gdb-6.8/sim/ppc/hw_sem.c
--- gdb-6.8-orig/sim/ppc/hw_sem.c 1969-12-31 18:00:00.000000000 -0600
+++ gdb-6.8/sim/ppc/hw_sem.c 2008-09-03 11:00:17.000000000 -0500
@@ -0,0 +1,301 @@
+/* This file is part of the program psim.
+
+ Copyright (C) 1997,2008, Joel Sherrill <joel@OARcorp.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ */
+
+
+#ifndef _HW_SEM_C_
+#define _HW_SEM_C_
+
+#include "device_table.h"
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#endif
+
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+#include <errno.h>
+
+/* DEVICE
+
+
+ sem - provide access to a unix semaphore
+
+
+ DESCRIPTION
+
+
+ This device implements an interface to a unix semaphore.
+
+
+ PROPERTIES
+
+
+ reg = <address> <size> (required)
+
+ Determine where the memory lives in the parents address space.
+
+ key = <integer> (required)
+
+ This is the key of the unix semaphore.
+
+ EXAMPLES
+
+
+ Enable tracing of the sem:
+
+ | bash$ psim -t sem-device \
+
+
+ Configure a UNIX semaphore using key 0x12345678 mapped into psim
+ address space at 0xfff00000:
+
+ | -o '/sem@0xfff00000/reg 0xfff00000 0x80000' \
+ | -o '/sem@0xfff00000/key 0x12345678' \
+
+ sim/ppc/run -o '/#address-cells 1' \
+ -o '/sem@0xc0000000/reg 0xc0000000 0x80000' \
+ -o '/sem@0xc0000000/key 0x12345678' ../psim-hello/hello
+
+ REGISTERS
+
+ offset 0 - lock count
+ offset 4 - lock operation
+ offset 8 - unlock operation
+
+ All reads return the current or resulting count.
+
+ BUGS
+
+ None known.
+
+ */
+
+typedef struct _hw_sem_device {
+ unsigned_word physical_address;
+ key_t key;
+ int id;
+ int initial;
+ int count;
+} hw_sem_device;
+
+static void
+hw_sem_init_data(device *me)
+{
+ hw_sem_device *sem = (hw_sem_device*)device_data(me);
+ const device_unit *d;
+ int status;
+#if !HAS_UNION_SEMUN
+ union semun {
+ int val;
+ struct semid_ds *buf;
+ unsigned short int *array;
+#if defined(__linux__)
+ struct seminfo *__buf;
+#endif
+ } ;
+#endif
+ union semun help;
+
+ /* initialize the properties of the sem */
+
+ if (device_find_property(me, "key") == NULL)
+ error("sem_init_data() required key property is missing\n");
+
+ if (device_find_property(me, "value") == NULL)
+ error("sem_init_data() required value property is missing\n");
+
+ sem->key = (key_t) device_find_integer_property(me, "key");
+ DTRACE(sem, ("semaphore key (%d)\n", sem->key) );
+
+ sem->initial = (int) device_find_integer_property(me, "value");
+ DTRACE(sem, ("semaphore initial value (%d)\n", sem->initial) );
+
+ d = device_unit_address(me);
+ sem->physical_address = d->cells[ d->nr_cells-1 ];
+ DTRACE(sem, ("semaphore physical_address=0x%x\n", sem->physical_address));
+
+ /* Now to initialize the semaphore */
+
+ if ( sem->initial != -1 ) {
+
+ sem->id = semget(sem->key, 1, IPC_CREAT | 0660);
+ if (sem->id == -1)
+ error("hw_sem_init_data() semget failed\n");
+
+ help.val = sem->initial;
+ status = semctl( sem->id, 0, SETVAL, help );
+ if (status == -1)
+ error("hw_sem_init_data() semctl -- set value failed\n");
+
+ } else {
+ sem->id = semget(sem->key, 1, 0660);
+ if (sem->id == -1)
+ error("hw_sem_init_data() semget failed\n");
+ }
+
+ sem->count = semctl( sem->id, 0, GETVAL, help );
+ if (sem->count == -1)
+ error("hw_sem_init_data() semctl -- get value failed\n");
+ DTRACE(sem, ("semaphore OS value (%d)\n", sem->count) );
+
+ if (sizeof(int) != 4)
+ error("hw_sem_init_data() typing problem\n");
+}
+
+static void
+hw_sem_attach_address_callback(device *me,
+ attach_type attach,
+ int space,
+ unsigned_word addr,
+ unsigned nr_bytes,
+ access_type access,
+ device *client) /*callback/default*/
+{
+ hw_sem_device *sem = (hw_sem_device*)device_data(me);
+
+ if (space != 0)
+ error("sem_attach_address_callback() invalid address space\n");
+
+ if (nr_bytes == 12)
+ error("sem_attach_address_callback() invalid size\n");
+
+ sem->physical_address = addr;
+ DTRACE(sem, ("semaphore physical_address=0x%x\n", addr));
+}
+
+static unsigned
+hw_sem_io_read_buffer(device *me,
+ void *dest,
+ int space,
+ unsigned_word addr,
+ unsigned nr_bytes,
+ cpu *processor,
+ unsigned_word cia)
+{
+ hw_sem_device *sem = (hw_sem_device*)device_data(me);
+ struct sembuf sb;
+ int status;
+ unsigned32 u32;
+#if !HAS_UNION_SEMUN
+ union semun {
+ int val;
+ struct semid_ds *buf;
+ unsigned short int *array;
+#if defined(__linux__)
+ struct seminfo *__buf;
+#endif
+ } ;
+#endif
+ union semun help;
+
+ /* do we need to worry about out of range addresses? */
+
+ DTRACE(sem, ("semaphore read addr=0x%x length=%d\n", addr, nr_bytes));
+
+ if (!(addr >= sem->physical_address && addr <= sem->physical_address + 11))
+ error("hw_sem_io_read_buffer() invalid address - out of range\n");
+
+ if ((addr % 4) != 0)
+ error("hw_sem_io_read_buffer() invalid address - alignment\n");
+
+ if (nr_bytes != 4)
+ error("hw_sem_io_read_buffer() invalid length\n");
+
+ switch ( (addr - sem->physical_address) / 4 ) {
+
+ case 0: /* OBTAIN CURRENT VALUE */
+ break;
+
+ case 1: /* LOCK */
+ sb.sem_num = 0;
+ sb.sem_op = -1;
+ sb.sem_flg = 0;
+
+ status = semop(sem->id, &sb, 1);
+ if (status == -1) {
+ perror( "hw_sem.c: lock" );
+ error("hw_sem_io_read_buffer() sem lock\n");
+ }
+
+ DTRACE(sem, ("semaphore lock %d\n", sem->count));
+ break;
+
+ case 2: /* UNLOCK */
+ sb.sem_num = 0;
+ sb.sem_op = 1;
+ sb.sem_flg = 0;
+
+ status = semop(sem->id, &sb, 1);
+ if (status == -1) {
+ perror( "hw_sem.c: unlock" );
+ error("hw_sem_io_read_buffer() sem unlock\n");
+ }
+ DTRACE(sem, ("semaphore unlock %d\n", sem->count));
+ break;
+
+ default:
+ error("hw_sem_io_read_buffer() invalid address - unknown error\n");
+ break;
+ }
+
+ /* assume target is big endian */
+ u32 = H2T_4(semctl( sem->id, 0, GETVAL, help ));
+
+ DTRACE(sem, ("semaphore OS value (%d)\n", u32) );
+ if (u32 == 0xffffffff) {
+ perror( "hw_sem.c: getval" );
+ error("hw_sem_io_read_buffer() semctl -- get value failed\n");
+ }
+
+ memcpy(dest, &u32, nr_bytes);
+ return nr_bytes;
+
+}
+
+static device_callbacks const hw_sem_callbacks = {
+ { generic_device_init_address, hw_sem_init_data },
+ { hw_sem_attach_address_callback, }, /* address */
+ { hw_sem_io_read_buffer, NULL }, /* IO */
+ { NULL, }, /* DMA */
+ { NULL, }, /* interrupt */
+ { NULL, }, /* unit */
+ NULL,
+};
+
+static void *
+hw_sem_create(const char *name,
+ const device_unit *unit_address,
+ const char *args)
+{
+ hw_sem_device *sem = ZALLOC(hw_sem_device);
+ return sem;
+}
+
+const device_descriptor hw_sem_device_descriptor[] = {
+ { "sem", hw_sem_create, &hw_sem_callbacks },
+ { NULL },
+};
+
+#endif /* _HW_SEM_C_ */
diff -uNr --exclude configure --exclude autom4te.cache gdb-6.8-orig/sim/ppc/hw_shm.c gdb-6.8/sim/ppc/hw_shm.c
--- gdb-6.8-orig/sim/ppc/hw_shm.c 1969-12-31 18:00:00.000000000 -0600
+++ gdb-6.8/sim/ppc/hw_shm.c 2008-09-03 11:01:16.000000000 -0500
@@ -0,0 +1,236 @@
+/* This file is part of the program psim.
+
+ Copyright (C) 1997,2008, Joel Sherrill <joel@OARcorp.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ */
+
+
+#ifndef _HW_SHM_C_
+#define _HW_SHM_C_
+
+#include "device_table.h"
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#endif
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+
+/* DEVICE
+
+
+ shm - map unix shared memory into psim address space
+
+
+ DESCRIPTION
+
+
+ This device implements an area of memory which is mapped into UNIX
+ shared memory.
+
+
+ PROPERTIES
+
+
+ reg = <address> <size> (required)
+
+ Determine where the memory lives in the parents address space.
+ The SHM area is assumed to be of the same length.
+
+ key = <integer> (required)
+
+ This is the key of the unix shared memory area.
+
+ EXAMPLES
+
+
+ Enable tracing of the shm:
+
+ | bash$ psim -t shm-device \
+
+
+ Configure a 512 kilobytes of UNIX shared memory with the key 0x12345678
+ mapped into psim address space at 0x0c000000.
+
+ | -o '/shm@0x0c000000/reg 0x0c000000 0x80000' \
+ | -o '/shm@0x0c000000/key 0x12345678' \
+
+ sim/ppc/run -o '/#address-cells 1' \
+ -o '/shm@0x0c000000/reg 0x0c000000 0x80000' \
+ -o '/shm@0x0c000000/key 0x12345678' ../psim-hello/hello
+
+ BUGS
+
+ None known.
+
+ */
+
+typedef struct _hw_shm_device {
+ unsigned_word physical_address;
+ char *shm_address;
+ unsigned sizeof_memory;
+ key_t key;
+ int id;
+} hw_shm_device;
+
+static void
+hw_shm_init_data(device *me)
+{
+ hw_shm_device *shm = (hw_shm_device*)device_data(me);
+ const device_unit *d;
+ reg_property_spec reg;
+ int i;
+
+ /* Obtain the Key Value */
+ if (device_find_property(me, "key") == NULL)
+ error("shm_init_data() required key property is missing\n");
+
+ shm->key = (key_t) device_find_integer_property(me, "key");
+ DTRACE(shm, ("shm key (0x%08x)\n", shm->key) );
+
+ /* Figure out where this memory is in address space and how long it is */
+ if ( !device_find_reg_array_property(me, "reg", 0, ®) )
+ error("hw_shm_init_data() no address registered\n");
+
+ /* Determine the address and length being as paranoid as possible */
+ shm->physical_address = 0xffffffff;
+ shm->sizeof_memory = 0xffffffff;
+
+ for ( i=0 ; i<reg.address.nr_cells; i++ ) {
+ if (reg.address.cells[0] == 0 && reg.size.cells[0] == 0)
+ continue;
+
+ if ( shm->physical_address != 0xffffffff )
+ device_error(me, "Only single celled address ranges supported\n");
+
+ shm->physical_address = reg.address.cells[i];
+ DTRACE(shm, ("shm physical_address=0x%x\n", shm->physical_address));
+
+ shm->sizeof_memory = reg.size.cells[i];
+ DTRACE(shm, ("shm length=0x%x\n", shm->sizeof_memory));
+ }
+
+ if ( shm->physical_address == 0xffffffff )
+ device_error(me, "Address not specified\n" );
+
+ if ( shm->sizeof_memory == 0xffffffff )
+ device_error(me, "Length not specified\n" );
+
+ /* Now actually attach to or create the shared memory area */
+ shm->id = shmget(shm->key, shm->sizeof_memory, IPC_CREAT | 0660);
+ if (shm->id == -1)
+ error("hw_shm_init_data() shmget failed\n");
+
+ shm->shm_address = shmat(shm->id, (char *)0, SHM_RND);
+ if (shm->shm_address == (void *)-1)
+ error("hw_shm_init_data() shmat failed\n");
+}
+
+static void
+hw_shm_attach_address_callback(device *me,
+ attach_type attach,
+ int space,
+ unsigned_word addr,
+ unsigned nr_bytes,
+ access_type access,
+ device *client) /*callback/default*/
+{
+ hw_shm_device *shm = (hw_shm_device*)device_data(me);
+
+ if (space != 0)
+ error("shm_attach_address_callback() invalid address space\n");
+
+ if (nr_bytes == 0)
+ error("shm_attach_address_callback() invalid size\n");
+}
+
+
+static unsigned
+hw_shm_io_read_buffer(device *me,
+ void *dest,
+ int space,
+ unsigned_word addr,
+ unsigned nr_bytes,
+ cpu *processor,
+ unsigned_word cia)
+{
+ hw_shm_device *shm = (hw_shm_device*)device_data(me);
+
+ /* do we need to worry about out of range addresses? */
+
+ DTRACE(shm, ("read %p %x %x %x\n", \
+ shm->shm_address, shm->physical_address, addr, nr_bytes) );
+
+ memcpy(dest, &shm->shm_address[addr - shm->physical_address], nr_bytes);
+ return nr_bytes;
+}
+
+
+static unsigned
+hw_shm_io_write_buffer(device *me,
+ const void *source,
+ int space,
+ unsigned_word addr,
+ unsigned nr_bytes,
+ cpu *processor,
+ unsigned_word cia)
+{
+ hw_shm_device *shm = (hw_shm_device*)device_data(me);
+
+ /* do we need to worry about out of range addresses? */
+
+ DTRACE(shm, ("write %p %x %x %x\n", \
+ shm->shm_address, shm->physical_address, addr, nr_bytes) );
+
+ memcpy(&shm->shm_address[addr - shm->physical_address], source, nr_bytes);
+ return nr_bytes;
+}
+
+static device_callbacks const hw_shm_callbacks = {
+ { generic_device_init_address, hw_shm_init_data },
+ { hw_shm_attach_address_callback, }, /* address */
+ { hw_shm_io_read_buffer,
+ hw_shm_io_write_buffer }, /* IO */
+ { NULL, }, /* DMA */
+ { NULL, }, /* interrupt */
+ { NULL, }, /* unit */
+ NULL,
+};
+
+static void *
+hw_shm_create(const char *name,
+ const device_unit *unit_address,
+ const char *args)
+{
+ hw_shm_device *shm = ZALLOC(hw_shm_device);
+ return shm;
+}
+
+
+
+const device_descriptor hw_shm_device_descriptor[] = {
+ { "shm", hw_shm_create, &hw_shm_callbacks },
+ { NULL },
+};
+
+#endif /* _HW_SHM_C_ */
diff -uNr --exclude configure --exclude autom4te.cache gdb-6.8-orig/sim/ppc/Makefile.in gdb-6.8/sim/ppc/Makefile.in
--- gdb-6.8-orig/sim/ppc/Makefile.in 2006-05-31 10:14:45.000000000 -0500
+++ gdb-6.8/sim/ppc/Makefile.in 2008-09-02 10:10:13.000000000 -0500
@@ -834,6 +834,8 @@
hw_pal.o: hw_pal.c $(DEVICE_TABLE_H) $(CPU_H)
hw_phb.o: hw_phb.c $(DEVICE_TABLE_H) $(HW_PHB_H) $(COREFILE_H)
hw_register.o: hw_register.c $(DEVICE_TABLE_H) $(PSIM_H)
+hw_sem.o: hw_sem.c $(DEVICE_TABLE_H) $(PSIM_H)
+hw_shm.o: hw_shm.c $(DEVICE_TABLE_H) $(PSIM_H)
hw_trace.o: hw_trace.c $(DEVICE_TABLE_H)
hw_vm.o: hw_vm.c $(DEVICE_TABLE_H) $(CPU_H)
# ignore this line, it stops make from getting confused
^ permalink raw reply [flat|nested] 10+ messages in thread* Add SystemV IPC drivers to PSIM
@ 2008-11-05 16:55 Joel Sherrill
2008-11-06 2:35 ` teawater
0 siblings, 1 reply; 10+ messages in thread
From: Joel Sherrill @ 2008-11-05 16:55 UTC (permalink / raw)
To: gdb-patches@sourceware.org
[-- Attachment #1: Type: text/plain, Size: 1675 bytes --]
Hi,
This is a repost of the patch was originally submitted 8 Sept.
http://sourceware.org/ml/gdb/2008-09/msg00047.html
Could someone please review and commit it?
Thanks.
--joel
=====================
As the first year in the copyright shows, this code
has been around a while. I found a message in the
RTEMS archives where I was updating it to gdb 4.17. :)
It adds support for System V semaphores and shared memory to psim.
It adds two files (hw_sem.c and hw_shm.c) and touches configure.ac
to add tests for support of System V IPC. Please regenerate
configure after patching.
The shared memory device maps System V shared memory
into the simulated PowerPC's address space. This lets
the simulated CPU share data with the host environment.
This data area can be protected by using the System V
semaphore device to lock the memory.
We use this to run RTEMS multiprocessor tests where the
two simulated CPUs communicate through the shared memory.
It has also been used by RTEMS applications to do "device IO"
to the shared memory and have a custom system simulator
provide feedback.
Can someone please review and commit? Thanks.
2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
* configure: Regenerated.
* configure.ac: Add test for System V shared memory and semaphore.
* debug.c, debug.h: Add trace support for new devices.
* hw_sem.c, hw_shm.c: New files.
* Makefile.in: Add hw_sem.c and hw_shm.c
--
Joel Sherrill, Ph.D. Director of Research & Development
joel.sherrill@OARcorp.com On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985
[-- Attachment #2: gdb-6.8-psim.diff --]
[-- Type: text/x-patch, Size: 19540 bytes --]
diff -Naur gdb-6.8.orig/sim/ppc/configure.ac gdb-6.8/sim/ppc/configure.ac
--- gdb-6.8.orig/sim/ppc/configure.ac 2008-03-14 22:35:27.000000000 +0100
+++ gdb-6.8/sim/ppc/configure.ac 2008-10-03 05:31:56.000000000 +0200
@@ -209,10 +209,105 @@
esac
])dnl
+AC_CACHE_CHECK([if union semun defined],
+ ac_cv_HAS_UNION_SEMUN,
+ [AC_TRY_COMPILE([
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>],
+[union semun arg ;],
+[ac_cv_has_union_semun="yes"],
+[ac_cv_has_union_semun="no"])
+AC_MSG_RESULT($ac_cv_has_union_semun)
+])
+
+
+if test "$ac_cv_has_union_semun" = "yes"; then
+ AC_CACHE_CHECK(whether System V semaphores are supported,
+ ac_cv_sysv_sem,
+ [
+ AC_TRY_RUN(
+ [
+ #include <sys/types.h>
+ #include <sys/ipc.h>
+ #include <sys/sem.h>
+ int main () {
+ union semun arg ;
+
+ int id=semget(IPC_PRIVATE,1,IPC_CREAT|0400);
+ if (id == -1)
+ exit(1);
+ arg.val = 0; /* avoid implicit type cast to union */
+ if (semctl(id, 0, IPC_RMID, arg) == -1)
+ exit(1);
+ exit(0);
+ }
+ ],
+ ac_cv_sysv_sem="yes", ac_cv_sysv_sem="no", :)
+ ])
+else # semun is not defined
+ AC_CACHE_CHECK(whether System V semaphores are supported,
+ ac_cv_sysv_sem,
+ [
+ AC_TRY_RUN(
+ [
+ #include <sys/types.h>
+ #include <sys/ipc.h>
+ #include <sys/sem.h>
+ union semun {
+ int val;
+ struct semid_ds *buf;
+ ushort *array;
+ };
+ int main () {
+ union semun arg ;
+
+ int id=semget(IPC_PRIVATE,1,IPC_CREAT|0400);
+ if (id == -1)
+ exit(1);
+ arg.val = 0; /* avoid implicit type cast to union */
+ if (semctl(id, 0, IPC_RMID, arg) == -1)
+ exit(1);
+ exit(0);
+ }
+ ],
+ ac_cv_sysv_sem="yes", ac_cv_sysv_sem="no", :)
+ ])
+fi
+
+AC_CACHE_CHECK(whether System V shared memory is supported,
+ac_cv_sysv_shm,
+[
+AC_TRY_RUN([
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+int main () {
+ int id=shmget(IPC_PRIVATE,1,IPC_CREAT|0400);
+ if (id == -1)
+ exit(1);
+ if (shmctl(id, IPC_RMID, 0) == -1)
+ exit(1);
+ exit(0);
+}
+],
+ac_cv_sysv_shm="yes", ac_cv_sysv_shm="no", :)
+])
+
+if test x"$ac_cv_sysv_shm" = x"yes" -a x"$ac_cv_sysv_sem" = x"yes" ; then
+ sim_sysv_ipc_hw=",sem,shm";
+else
+ sim_sysv_ipc_hw="";
+fi
+
+if test x"$ac_cv_has_union_semun" = x"yes" -a x"$ac_cv_sysv_sem" = x"yes" ; then
+ sim_hwflags="-DHAS_UNION_SEMUN";
+fi
+
AC_ARG_ENABLE(sim-hardware,
[ --enable-sim-hardware=list Specify the hardware to be included in the build.],
-[hardware="cpu,memory,nvram,iobus,htab,disk,trace,register,vm,init,core,pal,com,eeprom,opic,glue,phb,ide"
+[hardware="cpu,memory,nvram,iobus,htab,disk,trace,register,vm,init,core,pal,com,eeprom,opic,glue,phb,ide${sim_sysv_ipc_hw}"
case "${enableval}" in
yes) ;;
no) AC_MSG_ERROR("List of hardware must be specified for --enable-sim-hardware"); hardware="";;
@@ -224,14 +319,13 @@
sim_hw_obj=`echo $sim_hw_src | sed -e 's/\.c/.o/g'`
if test x"$silent" != x"yes" && test x"$hardware" != x""; then
echo "Setting hardware to $sim_hw_src, $sim_hw_obj"
-fi],[hardware="cpu,memory,nvram,iobus,htab,disk,trace,register,vm,init,core,pal,com,eeprom,opic,glue,phb,ide"
+fi],[hardware="cpu,memory,nvram,iobus,htab,disk,trace,register,vm,init,core,pal,com,eeprom,opic,glue,phb,ide${sim_sysv_ipc_hw}"
sim_hw_src=`echo $hardware | sed -e 's/,/.c hw_/g' -e 's/^/hw_/' -e s'/$/.c/'`
sim_hw_obj=`echo $sim_hw_src | sed -e 's/\.c/.o/g'`
if test x"$silent" != x"yes"; then
echo "Setting hardware to $sim_hw_src, $sim_hw_obj"
fi])dnl
-
AC_ARG_ENABLE(sim-hostbitsize,
[ --enable-sim-hostbitsize=32|64 Specify host bitsize (32 or 64).],
[case "${enableval}" in
diff -Naur gdb-6.8.orig/sim/ppc/debug.c gdb-6.8/sim/ppc/debug.c
--- gdb-6.8.orig/sim/ppc/debug.c 1999-04-16 03:35:08.000000000 +0200
+++ gdb-6.8/sim/ppc/debug.c 2008-10-03 05:31:56.000000000 +0200
@@ -70,6 +70,8 @@
{ trace_pass_device, "pass-device" },
{ trace_phb_device, "phb-device" },
{ trace_register_device, "register-device", "Device initializing registers" },
+ { trace_sem_device, "sem-device" },
+ { trace_shm_device, "shm-device" },
{ trace_stack_device, "stack-device" },
{ trace_vm_device, "vm-device" },
/* packages */
diff -Naur gdb-6.8.orig/sim/ppc/debug.h gdb-6.8/sim/ppc/debug.h
--- gdb-6.8.orig/sim/ppc/debug.h 1999-04-16 03:35:08.000000000 +0200
+++ gdb-6.8/sim/ppc/debug.h 2008-10-03 05:31:56.000000000 +0200
@@ -51,6 +51,8 @@
trace_pal_device,
trace_pass_device,
trace_phb_device,
+ trace_sem_device,
+ trace_shm_device,
trace_stack_device,
trace_register_device,
trace_vm_device,
diff -Naur gdb-6.8.orig/sim/ppc/hw_sem.c gdb-6.8/sim/ppc/hw_sem.c
--- gdb-6.8.orig/sim/ppc/hw_sem.c 1970-01-01 01:00:00.000000000 +0100
+++ gdb-6.8/sim/ppc/hw_sem.c 2008-10-03 05:31:56.000000000 +0200
@@ -0,0 +1,301 @@
+/* This file is part of the program psim.
+
+ Copyright (C) 1997,2008, Joel Sherrill <joel@OARcorp.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ */
+
+
+#ifndef _HW_SEM_C_
+#define _HW_SEM_C_
+
+#include "device_table.h"
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#endif
+
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+#include <errno.h>
+
+/* DEVICE
+
+
+ sem - provide access to a unix semaphore
+
+
+ DESCRIPTION
+
+
+ This device implements an interface to a unix semaphore.
+
+
+ PROPERTIES
+
+
+ reg = <address> <size> (required)
+
+ Determine where the memory lives in the parents address space.
+
+ key = <integer> (required)
+
+ This is the key of the unix semaphore.
+
+ EXAMPLES
+
+
+ Enable tracing of the sem:
+
+ | bash$ psim -t sem-device \
+
+
+ Configure a UNIX semaphore using key 0x12345678 mapped into psim
+ address space at 0xfff00000:
+
+ | -o '/sem@0xfff00000/reg 0xfff00000 0x80000' \
+ | -o '/sem@0xfff00000/key 0x12345678' \
+
+ sim/ppc/run -o '/#address-cells 1' \
+ -o '/sem@0xc0000000/reg 0xc0000000 0x80000' \
+ -o '/sem@0xc0000000/key 0x12345678' ../psim-hello/hello
+
+ REGISTERS
+
+ offset 0 - lock count
+ offset 4 - lock operation
+ offset 8 - unlock operation
+
+ All reads return the current or resulting count.
+
+ BUGS
+
+ None known.
+
+ */
+
+typedef struct _hw_sem_device {
+ unsigned_word physical_address;
+ key_t key;
+ int id;
+ int initial;
+ int count;
+} hw_sem_device;
+
+static void
+hw_sem_init_data(device *me)
+{
+ hw_sem_device *sem = (hw_sem_device*)device_data(me);
+ const device_unit *d;
+ int status;
+#if !HAS_UNION_SEMUN
+ union semun {
+ int val;
+ struct semid_ds *buf;
+ unsigned short int *array;
+#if defined(__linux__)
+ struct seminfo *__buf;
+#endif
+ } ;
+#endif
+ union semun help;
+
+ /* initialize the properties of the sem */
+
+ if (device_find_property(me, "key") == NULL)
+ error("sem_init_data() required key property is missing\n");
+
+ if (device_find_property(me, "value") == NULL)
+ error("sem_init_data() required value property is missing\n");
+
+ sem->key = (key_t) device_find_integer_property(me, "key");
+ DTRACE(sem, ("semaphore key (%d)\n", sem->key) );
+
+ sem->initial = (int) device_find_integer_property(me, "value");
+ DTRACE(sem, ("semaphore initial value (%d)\n", sem->initial) );
+
+ d = device_unit_address(me);
+ sem->physical_address = d->cells[ d->nr_cells-1 ];
+ DTRACE(sem, ("semaphore physical_address=0x%x\n", sem->physical_address));
+
+ /* Now to initialize the semaphore */
+
+ if ( sem->initial != -1 ) {
+
+ sem->id = semget(sem->key, 1, IPC_CREAT | 0660);
+ if (sem->id == -1)
+ error("hw_sem_init_data() semget failed\n");
+
+ help.val = sem->initial;
+ status = semctl( sem->id, 0, SETVAL, help );
+ if (status == -1)
+ error("hw_sem_init_data() semctl -- set value failed\n");
+
+ } else {
+ sem->id = semget(sem->key, 1, 0660);
+ if (sem->id == -1)
+ error("hw_sem_init_data() semget failed\n");
+ }
+
+ sem->count = semctl( sem->id, 0, GETVAL, help );
+ if (sem->count == -1)
+ error("hw_sem_init_data() semctl -- get value failed\n");
+ DTRACE(sem, ("semaphore OS value (%d)\n", sem->count) );
+
+ if (sizeof(int) != 4)
+ error("hw_sem_init_data() typing problem\n");
+}
+
+static void
+hw_sem_attach_address_callback(device *me,
+ attach_type attach,
+ int space,
+ unsigned_word addr,
+ unsigned nr_bytes,
+ access_type access,
+ device *client) /*callback/default*/
+{
+ hw_sem_device *sem = (hw_sem_device*)device_data(me);
+
+ if (space != 0)
+ error("sem_attach_address_callback() invalid address space\n");
+
+ if (nr_bytes == 12)
+ error("sem_attach_address_callback() invalid size\n");
+
+ sem->physical_address = addr;
+ DTRACE(sem, ("semaphore physical_address=0x%x\n", addr));
+}
+
+static unsigned
+hw_sem_io_read_buffer(device *me,
+ void *dest,
+ int space,
+ unsigned_word addr,
+ unsigned nr_bytes,
+ cpu *processor,
+ unsigned_word cia)
+{
+ hw_sem_device *sem = (hw_sem_device*)device_data(me);
+ struct sembuf sb;
+ int status;
+ unsigned32 u32;
+#if !HAS_UNION_SEMUN
+ union semun {
+ int val;
+ struct semid_ds *buf;
+ unsigned short int *array;
+#if defined(__linux__)
+ struct seminfo *__buf;
+#endif
+ } ;
+#endif
+ union semun help;
+
+ /* do we need to worry about out of range addresses? */
+
+ DTRACE(sem, ("semaphore read addr=0x%x length=%d\n", addr, nr_bytes));
+
+ if (!(addr >= sem->physical_address && addr <= sem->physical_address + 11))
+ error("hw_sem_io_read_buffer() invalid address - out of range\n");
+
+ if ((addr % 4) != 0)
+ error("hw_sem_io_read_buffer() invalid address - alignment\n");
+
+ if (nr_bytes != 4)
+ error("hw_sem_io_read_buffer() invalid length\n");
+
+ switch ( (addr - sem->physical_address) / 4 ) {
+
+ case 0: /* OBTAIN CURRENT VALUE */
+ break;
+
+ case 1: /* LOCK */
+ sb.sem_num = 0;
+ sb.sem_op = -1;
+ sb.sem_flg = 0;
+
+ status = semop(sem->id, &sb, 1);
+ if (status == -1) {
+ perror( "hw_sem.c: lock" );
+ error("hw_sem_io_read_buffer() sem lock\n");
+ }
+
+ DTRACE(sem, ("semaphore lock %d\n", sem->count));
+ break;
+
+ case 2: /* UNLOCK */
+ sb.sem_num = 0;
+ sb.sem_op = 1;
+ sb.sem_flg = 0;
+
+ status = semop(sem->id, &sb, 1);
+ if (status == -1) {
+ perror( "hw_sem.c: unlock" );
+ error("hw_sem_io_read_buffer() sem unlock\n");
+ }
+ DTRACE(sem, ("semaphore unlock %d\n", sem->count));
+ break;
+
+ default:
+ error("hw_sem_io_read_buffer() invalid address - unknown error\n");
+ break;
+ }
+
+ /* assume target is big endian */
+ u32 = H2T_4(semctl( sem->id, 0, GETVAL, help ));
+
+ DTRACE(sem, ("semaphore OS value (%d)\n", u32) );
+ if (u32 == 0xffffffff) {
+ perror( "hw_sem.c: getval" );
+ error("hw_sem_io_read_buffer() semctl -- get value failed\n");
+ }
+
+ memcpy(dest, &u32, nr_bytes);
+ return nr_bytes;
+
+}
+
+static device_callbacks const hw_sem_callbacks = {
+ { generic_device_init_address, hw_sem_init_data },
+ { hw_sem_attach_address_callback, }, /* address */
+ { hw_sem_io_read_buffer, NULL }, /* IO */
+ { NULL, }, /* DMA */
+ { NULL, }, /* interrupt */
+ { NULL, }, /* unit */
+ NULL,
+};
+
+static void *
+hw_sem_create(const char *name,
+ const device_unit *unit_address,
+ const char *args)
+{
+ hw_sem_device *sem = ZALLOC(hw_sem_device);
+ return sem;
+}
+
+const device_descriptor hw_sem_device_descriptor[] = {
+ { "sem", hw_sem_create, &hw_sem_callbacks },
+ { NULL },
+};
+
+#endif /* _HW_SEM_C_ */
diff -Naur gdb-6.8.orig/sim/ppc/hw_shm.c gdb-6.8/sim/ppc/hw_shm.c
--- gdb-6.8.orig/sim/ppc/hw_shm.c 1970-01-01 01:00:00.000000000 +0100
+++ gdb-6.8/sim/ppc/hw_shm.c 2008-10-03 05:31:56.000000000 +0200
@@ -0,0 +1,236 @@
+/* This file is part of the program psim.
+
+ Copyright (C) 1997,2008, Joel Sherrill <joel@OARcorp.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ */
+
+
+#ifndef _HW_SHM_C_
+#define _HW_SHM_C_
+
+#include "device_table.h"
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#endif
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+
+/* DEVICE
+
+
+ shm - map unix shared memory into psim address space
+
+
+ DESCRIPTION
+
+
+ This device implements an area of memory which is mapped into UNIX
+ shared memory.
+
+
+ PROPERTIES
+
+
+ reg = <address> <size> (required)
+
+ Determine where the memory lives in the parents address space.
+ The SHM area is assumed to be of the same length.
+
+ key = <integer> (required)
+
+ This is the key of the unix shared memory area.
+
+ EXAMPLES
+
+
+ Enable tracing of the shm:
+
+ | bash$ psim -t shm-device \
+
+
+ Configure a 512 kilobytes of UNIX shared memory with the key 0x12345678
+ mapped into psim address space at 0x0c000000.
+
+ | -o '/shm@0x0c000000/reg 0x0c000000 0x80000' \
+ | -o '/shm@0x0c000000/key 0x12345678' \
+
+ sim/ppc/run -o '/#address-cells 1' \
+ -o '/shm@0x0c000000/reg 0x0c000000 0x80000' \
+ -o '/shm@0x0c000000/key 0x12345678' ../psim-hello/hello
+
+ BUGS
+
+ None known.
+
+ */
+
+typedef struct _hw_shm_device {
+ unsigned_word physical_address;
+ char *shm_address;
+ unsigned sizeof_memory;
+ key_t key;
+ int id;
+} hw_shm_device;
+
+static void
+hw_shm_init_data(device *me)
+{
+ hw_shm_device *shm = (hw_shm_device*)device_data(me);
+ const device_unit *d;
+ reg_property_spec reg;
+ int i;
+
+ /* Obtain the Key Value */
+ if (device_find_property(me, "key") == NULL)
+ error("shm_init_data() required key property is missing\n");
+
+ shm->key = (key_t) device_find_integer_property(me, "key");
+ DTRACE(shm, ("shm key (0x%08x)\n", shm->key) );
+
+ /* Figure out where this memory is in address space and how long it is */
+ if ( !device_find_reg_array_property(me, "reg", 0, ®) )
+ error("hw_shm_init_data() no address registered\n");
+
+ /* Determine the address and length being as paranoid as possible */
+ shm->physical_address = 0xffffffff;
+ shm->sizeof_memory = 0xffffffff;
+
+ for ( i=0 ; i<reg.address.nr_cells; i++ ) {
+ if (reg.address.cells[0] == 0 && reg.size.cells[0] == 0)
+ continue;
+
+ if ( shm->physical_address != 0xffffffff )
+ device_error(me, "Only single celled address ranges supported\n");
+
+ shm->physical_address = reg.address.cells[i];
+ DTRACE(shm, ("shm physical_address=0x%x\n", shm->physical_address));
+
+ shm->sizeof_memory = reg.size.cells[i];
+ DTRACE(shm, ("shm length=0x%x\n", shm->sizeof_memory));
+ }
+
+ if ( shm->physical_address == 0xffffffff )
+ device_error(me, "Address not specified\n" );
+
+ if ( shm->sizeof_memory == 0xffffffff )
+ device_error(me, "Length not specified\n" );
+
+ /* Now actually attach to or create the shared memory area */
+ shm->id = shmget(shm->key, shm->sizeof_memory, IPC_CREAT | 0660);
+ if (shm->id == -1)
+ error("hw_shm_init_data() shmget failed\n");
+
+ shm->shm_address = shmat(shm->id, (char *)0, SHM_RND);
+ if (shm->shm_address == (void *)-1)
+ error("hw_shm_init_data() shmat failed\n");
+}
+
+static void
+hw_shm_attach_address_callback(device *me,
+ attach_type attach,
+ int space,
+ unsigned_word addr,
+ unsigned nr_bytes,
+ access_type access,
+ device *client) /*callback/default*/
+{
+ hw_shm_device *shm = (hw_shm_device*)device_data(me);
+
+ if (space != 0)
+ error("shm_attach_address_callback() invalid address space\n");
+
+ if (nr_bytes == 0)
+ error("shm_attach_address_callback() invalid size\n");
+}
+
+
+static unsigned
+hw_shm_io_read_buffer(device *me,
+ void *dest,
+ int space,
+ unsigned_word addr,
+ unsigned nr_bytes,
+ cpu *processor,
+ unsigned_word cia)
+{
+ hw_shm_device *shm = (hw_shm_device*)device_data(me);
+
+ /* do we need to worry about out of range addresses? */
+
+ DTRACE(shm, ("read %p %x %x %x\n", \
+ shm->shm_address, shm->physical_address, addr, nr_bytes) );
+
+ memcpy(dest, &shm->shm_address[addr - shm->physical_address], nr_bytes);
+ return nr_bytes;
+}
+
+
+static unsigned
+hw_shm_io_write_buffer(device *me,
+ const void *source,
+ int space,
+ unsigned_word addr,
+ unsigned nr_bytes,
+ cpu *processor,
+ unsigned_word cia)
+{
+ hw_shm_device *shm = (hw_shm_device*)device_data(me);
+
+ /* do we need to worry about out of range addresses? */
+
+ DTRACE(shm, ("write %p %x %x %x\n", \
+ shm->shm_address, shm->physical_address, addr, nr_bytes) );
+
+ memcpy(&shm->shm_address[addr - shm->physical_address], source, nr_bytes);
+ return nr_bytes;
+}
+
+static device_callbacks const hw_shm_callbacks = {
+ { generic_device_init_address, hw_shm_init_data },
+ { hw_shm_attach_address_callback, }, /* address */
+ { hw_shm_io_read_buffer,
+ hw_shm_io_write_buffer }, /* IO */
+ { NULL, }, /* DMA */
+ { NULL, }, /* interrupt */
+ { NULL, }, /* unit */
+ NULL,
+};
+
+static void *
+hw_shm_create(const char *name,
+ const device_unit *unit_address,
+ const char *args)
+{
+ hw_shm_device *shm = ZALLOC(hw_shm_device);
+ return shm;
+}
+
+
+
+const device_descriptor hw_shm_device_descriptor[] = {
+ { "shm", hw_shm_create, &hw_shm_callbacks },
+ { NULL },
+};
+
+#endif /* _HW_SHM_C_ */
diff -Naur gdb-6.8.orig/sim/ppc/Makefile.in gdb-6.8/sim/ppc/Makefile.in
--- gdb-6.8.orig/sim/ppc/Makefile.in 2006-05-31 17:14:45.000000000 +0200
+++ gdb-6.8/sim/ppc/Makefile.in 2008-10-03 05:31:56.000000000 +0200
@@ -834,6 +834,8 @@
hw_pal.o: hw_pal.c $(DEVICE_TABLE_H) $(CPU_H)
hw_phb.o: hw_phb.c $(DEVICE_TABLE_H) $(HW_PHB_H) $(COREFILE_H)
hw_register.o: hw_register.c $(DEVICE_TABLE_H) $(PSIM_H)
+hw_sem.o: hw_sem.c $(DEVICE_TABLE_H) $(PSIM_H)
+hw_shm.o: hw_shm.c $(DEVICE_TABLE_H) $(PSIM_H)
hw_trace.o: hw_trace.c $(DEVICE_TABLE_H)
hw_vm.o: hw_vm.c $(DEVICE_TABLE_H) $(CPU_H)
# ignore this line, it stops make from getting confused
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: Add SystemV IPC drivers to PSIM
2008-11-05 16:55 Joel Sherrill
@ 2008-11-06 2:35 ` teawater
2008-11-07 18:51 ` Joel Sherrill
0 siblings, 1 reply; 10+ messages in thread
From: teawater @ 2008-11-06 2:35 UTC (permalink / raw)
To: Joel Sherrill; +Cc: gdb-patches@sourceware.org
Hi Joel,
I think maybe you need cc this mail to maintainer of ppc sim Andrew
Cagney <ac131313@redhat.com>.
And porting this patch to gdb-cvs-head and divide it to some small
ones are better for other people review it.
Thanks,
Hui
On Thu, Nov 6, 2008 at 00:54, Joel Sherrill <joel.sherrill@oarcorp.com> wrote:
> Hi,
>
> This is a repost of the patch was originally submitted 8 Sept.
>
> http://sourceware.org/ml/gdb/2008-09/msg00047.html
>
> Could someone please review and commit it?
>
> Thanks.
>
>
> --joel
>
> =====================
>
> As the first year in the copyright shows, this code
> has been around a while. I found a message in the
> RTEMS archives where I was updating it to gdb 4.17. :)
>
>
>
>
> It adds support for System V semaphores and shared memory to psim.
> It adds two files (hw_sem.c and hw_shm.c) and touches configure.ac
> to add tests for support of System V IPC. Please regenerate
> configure after patching.
>
>
> The shared memory device maps System V shared memory
> into the simulated PowerPC's address space. This lets
> the simulated CPU share data with the host environment.
> This data area can be protected by using the System V
> semaphore device to lock the memory.
>
>
> We use this to run RTEMS multiprocessor tests where the
> two simulated CPUs communicate through the shared memory.
> It has also been used by RTEMS applications to do "device IO"
> to the shared memory and have a custom system simulator
> provide feedback.
>
>
> Can someone please review and commit? Thanks.
>
> 2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
>
> * configure: Regenerated.
> * configure.ac: Add test for System V shared memory and semaphore.
> * debug.c, debug.h: Add trace support for new devices.
> * hw_sem.c, hw_shm.c: New files.
> * Makefile.in: Add hw_sem.c and hw_shm.c
>
> --
> Joel Sherrill, Ph.D. Director of Research & Development
> joel.sherrill@OARcorp.com On-Line Applications Research
> Ask me about RTEMS: a free RTOS Huntsville AL 35805
> Support Available (256) 722-9985
>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Add SystemV IPC drivers to PSIM
2008-11-06 2:35 ` teawater
@ 2008-11-07 18:51 ` Joel Sherrill
2008-11-07 19:01 ` Daniel Jacobowitz
0 siblings, 1 reply; 10+ messages in thread
From: Joel Sherrill @ 2008-11-07 18:51 UTC (permalink / raw)
To: teawater; +Cc: gdb-patches@sourceware.org
teawater wrote:
> Hi Joel,
>
> I think maybe you need cc this mail to maintainer of ppc sim Andrew
> Cagney <ac131313@redhat.com>.
>
>
FWIW that bounces. I found a gnu.org email
address for him and it didn't bounce but I haven't
heard back either. :(
Most of it is boilerplate for adding a device. Looking
at the ChangeLog, Andrew hasn't done anything
except commit someone else's patch in a few years.
Is anyone other than Andrew capable of reviewing it?
> And porting this patch to gdb-cvs-head
Coming shortly
> and divide it to some small
> ones are better for other people review it.
>
>
It can only be divided by two since it adds two device
simulations. Worse they are somewhat related since the
semaphore is used to protect the shared memory during
accesses. So all the test code I have uses both.
--joel
> Thanks,
> Hui
>
> On Thu, Nov 6, 2008 at 00:54, Joel Sherrill <joel.sherrill@oarcorp.com> wrote:
>
>> Hi,
>>
>> This is a repost of the patch was originally submitted 8 Sept.
>>
>> http://sourceware.org/ml/gdb/2008-09/msg00047.html
>>
>> Could someone please review and commit it?
>>
>> Thanks.
>>
>>
>> --joel
>>
>> =====================
>>
>> As the first year in the copyright shows, this code
>> has been around a while. I found a message in the
>> RTEMS archives where I was updating it to gdb 4.17. :)
>>
>>
>>
>>
>> It adds support for System V semaphores and shared memory to psim.
>> It adds two files (hw_sem.c and hw_shm.c) and touches configure.ac
>> to add tests for support of System V IPC. Please regenerate
>> configure after patching.
>>
>>
>> The shared memory device maps System V shared memory
>> into the simulated PowerPC's address space. This lets
>> the simulated CPU share data with the host environment.
>> This data area can be protected by using the System V
>> semaphore device to lock the memory.
>>
>>
>> We use this to run RTEMS multiprocessor tests where the
>> two simulated CPUs communicate through the shared memory.
>> It has also been used by RTEMS applications to do "device IO"
>> to the shared memory and have a custom system simulator
>> provide feedback.
>>
>>
>> Can someone please review and commit? Thanks.
>>
>> 2008-09-08 Joel Sherrill <joel.sherrill@oarcorp.com>
>>
>> * configure: Regenerated.
>> * configure.ac: Add test for System V shared memory and semaphore.
>> * debug.c, debug.h: Add trace support for new devices.
>> * hw_sem.c, hw_shm.c: New files.
>> * Makefile.in: Add hw_sem.c and hw_shm.c
>>
>> --
>> Joel Sherrill, Ph.D. Director of Research & Development
>> joel.sherrill@OARcorp.com On-Line Applications Research
>> Ask me about RTEMS: a free RTOS Huntsville AL 35805
>> Support Available (256) 722-9985
>>
>>
>>
>>
--
Joel Sherrill, Ph.D. Director of Research & Development
joel.sherrill@OARcorp.com On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Add SystemV IPC drivers to PSIM
2008-11-07 18:51 ` Joel Sherrill
@ 2008-11-07 19:01 ` Daniel Jacobowitz
2008-11-07 20:58 ` Joel Sherrill
0 siblings, 1 reply; 10+ messages in thread
From: Daniel Jacobowitz @ 2008-11-07 19:01 UTC (permalink / raw)
To: Joel Sherrill; +Cc: teawater, gdb-patches@sourceware.org
On Fri, Nov 07, 2008 at 12:50:29PM -0600, Joel Sherrill wrote:
> Most of it is boilerplate for adding a device. Looking
> at the ChangeLog, Andrew hasn't done anything
> except commit someone else's patch in a few years.
> Is anyone other than Andrew capable of reviewing it?
You might try asking H-P (Hans-Peter Nilsson <hp@axis.com>).
Beyond that, I'm not sure what to say; no one is really taking care of
these simulators recently.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Add SystemV IPC drivers to PSIM
2008-11-07 19:01 ` Daniel Jacobowitz
@ 2008-11-07 20:58 ` Joel Sherrill
2008-11-08 0:07 ` Doug Evans
0 siblings, 1 reply; 10+ messages in thread
From: Joel Sherrill @ 2008-11-07 20:58 UTC (permalink / raw)
To: Joel Sherrill, teawater, gdb-patches@sourceware.org
Daniel Jacobowitz wrote:
> On Fri, Nov 07, 2008 at 12:50:29PM -0600, Joel Sherrill wrote:
>
>> Most of it is boilerplate for adding a device. Looking
>> at the ChangeLog, Andrew hasn't done anything
>> except commit someone else's patch in a few years.
>> Is anyone other than Andrew capable of reviewing it?
>>
>
> You might try asking H-P (Hans-Peter Nilsson <hp@axis.com>).
> Beyond that, I'm not sure what to say; no one is really taking care of
> these simulators recently.
>
>
Thanks. I have emailed him.
Hopefully we can turn up someone. If not, what's next?
We are using these patches in the RTEMS GDB RPMs and
reporting test results to gcc-testresults regularly with these
simulators.
--joel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Add SystemV IPC drivers to PSIM
2008-11-07 20:58 ` Joel Sherrill
@ 2008-11-08 0:07 ` Doug Evans
2008-11-10 14:42 ` Daniel Jacobowitz
2008-11-10 20:28 ` Joel Sherrill
0 siblings, 2 replies; 10+ messages in thread
From: Doug Evans @ 2008-11-08 0:07 UTC (permalink / raw)
To: Joel Sherrill; +Cc: gdb-patches@sourceware.org
On Fri, Nov 7, 2008 at 12:57 PM, Joel Sherrill
<joel.sherrill@oarcorp.com> wrote:
> Daniel Jacobowitz wrote:
>>
>> On Fri, Nov 07, 2008 at 12:50:29PM -0600, Joel Sherrill wrote:
>>
>>>
>>> Most of it is boilerplate for adding a device. Looking
>>> at the ChangeLog, Andrew hasn't done anything
>>> except commit someone else's patch in a few years.
>>> Is anyone other than Andrew capable of reviewing it?
>>>
>>
>> You might try asking H-P (Hans-Peter Nilsson <hp@axis.com>).
>> Beyond that, I'm not sure what to say; no one is really taking care of
>> these simulators recently.
>>
>>
>
> Thanks. I have emailed him.
>
> Hopefully we can turn up someone. If not, what's next?
> We are using these patches in the RTEMS GDB RPMs and
> reporting test results to gcc-testresults regularly with these
> simulators.
Hi. Once upon a time I hacked in the sim tree. What kind of review
is needed? I looked over the patch. It's pretty self-contained so
the risk is pretty low, and I trust you. :-)
For reference: http://sourceware.org/ml/gdb/2008-09/msg00047.html
The coding style seems to follow the psim style with maybe one caveat.
There's very little pretty-alignment like this in psim:
+typedef struct _hw_sem_device {
+ unsigned_word physical_address;
+ key_t key;
+ int id;
+ int initial;
+ int count;
+} hw_sem_device;
I'd prefer to stick with:
+typedef struct _hw_sem_device {
+ unsigned_word physical_address;
+ key_t key;
+ int id;
+ int initial;
+ int count;
+} hw_sem_device;
The indentation is off here and in another place:
+static void
+hw_sem_init_data(device *me)
+{
+ hw_sem_device *sem = (hw_sem_device*)device_data(me);
+ const device_unit *d;
+ int status;
+#if !HAS_UNION_SEMUN
+ union semun {
+ int val;
+ struct semid_ds *buf;
+ unsigned short int *array;
+#if defined(__linux__)
+ struct seminfo *__buf;
+#endif
+ } ;
+#endif
+ union semun help;
I can't tell from reading the code what will break if sizeof(int) !=
4. How about a comment?
[lots may break, but why check for it here is what I'm getting at]
Plus could "typing problem" be more specific?
+ if (sizeof(int) != 4)
+ error("hw_sem_init_data() typing problem\n");
I don't have an answer for this, but I don't see any other hw*.c
verifying the address either:
+ /* do we need to worry about out of range addresses? */
I think there's a cut-n-paste error in the sem docs. Should the
second 0xc0000000 be 0xfff00000?
I don't completely understand the device configuration syntax, but the
code checks for "value" yet you're using "reg" in the docs. Is that a
problem? [perhaps just more of the same cut-n-paste error of course]
Maybe something like -o '/sim@0xfff00000/value 0' or some such instead
of -o '/sem@0xfff00000/reg 0xfff00000 0x80000' ?
+ Configure a UNIX semaphore using key 0x12345678 mapped into psim
+ address space at 0xfff00000:
+
+ | -o '/sem@0xfff00000/reg 0xfff00000 0x80000' \
+ | -o '/sem@0xfff00000/key 0x12345678' \
+
+ sim/ppc/run -o '/#address-cells 1' \
+ -o '/sem@0xc0000000/reg 0xc0000000 0x80000' \
+ -o '/sem@0xc0000000/key 0x12345678' ../psim-hello/hello
Other than these nits, it's ok with me (fwiw of course).
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: Add SystemV IPC drivers to PSIM
2008-11-08 0:07 ` Doug Evans
@ 2008-11-10 14:42 ` Daniel Jacobowitz
2008-11-12 19:18 ` Doug Evans
2008-11-10 20:28 ` Joel Sherrill
1 sibling, 1 reply; 10+ messages in thread
From: Daniel Jacobowitz @ 2008-11-10 14:42 UTC (permalink / raw)
To: Doug Evans; +Cc: Joel Sherrill, gdb-patches@sourceware.org
On Fri, Nov 07, 2008 at 04:06:19PM -0800, Doug Evans wrote:
> Hi. Once upon a time I hacked in the sim tree. What kind of review
> is needed? I looked over the patch. It's pretty self-contained so
> the risk is pretty low, and I trust you. :-)
If you're willing to be a sim reviewer, I bet we can get you listed
as one in record time - are you? I'm reluctant to approve patches to
code that I know pretty much nothing about.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Add SystemV IPC drivers to PSIM
2008-11-10 14:42 ` Daniel Jacobowitz
@ 2008-11-12 19:18 ` Doug Evans
0 siblings, 0 replies; 10+ messages in thread
From: Doug Evans @ 2008-11-12 19:18 UTC (permalink / raw)
To: gdb-patches@sourceware.org
On Mon, Nov 10, 2008 at 6:41 AM, Daniel Jacobowitz wrote:
> On Fri, Nov 07, 2008 at 04:06:19PM -0800, Doug Evans wrote:
>> Hi. Once upon a time I hacked in the sim tree. What kind of review
>> is needed? I looked over the patch. It's pretty self-contained so
>> the risk is pretty low, and I trust you. :-)
>
> If you're willing to be a sim reviewer, I bet we can get you listed
> as one in record time - are you? I'm reluctant to approve patches to
> code that I know pretty much nothing about.
I'm not sure actually. On the one hand, sure, but on the other, while
I realize sim patches are relatively rare, committing to something I
often don't have time for is probably unfair to the community.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Add SystemV IPC drivers to PSIM
2008-11-08 0:07 ` Doug Evans
2008-11-10 14:42 ` Daniel Jacobowitz
@ 2008-11-10 20:28 ` Joel Sherrill
1 sibling, 0 replies; 10+ messages in thread
From: Joel Sherrill @ 2008-11-10 20:28 UTC (permalink / raw)
To: Doug Evans; +Cc: gdb-patches@sourceware.org
Doug Evans wrote:
> On Fri, Nov 7, 2008 at 12:57 PM, Joel Sherrill
> <joel.sherrill@oarcorp.com> wrote:
>
>> Daniel Jacobowitz wrote:
>>
>>> On Fri, Nov 07, 2008 at 12:50:29PM -0600, Joel Sherrill wrote:
>>>
>>>
>>>> Most of it is boilerplate for adding a device. Looking
>>>> at the ChangeLog, Andrew hasn't done anything
>>>> except commit someone else's patch in a few years.
>>>> Is anyone other than Andrew capable of reviewing it?
>>>>
>>>>
>>> You might try asking H-P (Hans-Peter Nilsson <hp@axis.com>).
>>> Beyond that, I'm not sure what to say; no one is really taking care of
>>> these simulators recently.
>>>
>>>
>>>
>> Thanks. I have emailed him.
>>
>> Hopefully we can turn up someone. If not, what's next?
>> We are using these patches in the RTEMS GDB RPMs and
>> reporting test results to gcc-testresults regularly with these
>> simulators.
>>
>
> Hi. Once upon a time I hacked in the sim tree. What kind of review
> is needed? I looked over the patch. It's pretty self-contained so
> the risk is pretty low, and I trust you. :-)
>
> For reference: http://sourceware.org/ml/gdb/2008-09/msg00047.html
>
> The coding style seems to follow the psim style with maybe one caveat.
> There's very little pretty-alignment like this in psim:
>
>
>
Got all the indentation I think.
> I can't tell from reading the code what will break if sizeof(int) !=
> 4. How about a comment?
> [lots may break, but why check for it here is what I'm getting at]
> Plus could "typing problem" be more specific?
>
> + if (sizeof(int) != 4)
> + error("hw_sem_init_data() typing problem\n");
> l
> I don't have an answer for this, but I don't see any other hw*.c
> verifying the address either:
>
You are right. This is unclear and now unnecessary. The problem
was that the "registers" on the device must match the
size of the integer returned by the native semctl()
call for semaphore count. All accesses must be
4 bytes wide in the semaphore access code.
But the code that had to deal with this has been updated
to explicitly move the semaphore count into an unsigned32
so there is no restriction now.
So I removed this.
> + /* do we need to worry about out of range addresses? */
>
> I think there's a cut-n-paste error in the sem docs. Should the
> second 0xc0000000 be 0xfff00000?
> I don't completely understand the device configuration syntax, but the
> code checks for "value" yet you're using "reg" in the docs. Is that a
> problem? [perhaps just more of the same cut-n-paste error of course]
> Maybe something like -o '/sim@0xfff00000/value 0' or some such instead
> of -o '/sem@0xfff00000/reg 0xfff00000 0x80000' ?
>
>
The syntax is hard to grok. I fixed this to match what
I use in my script that runs psim. 0xc0000000 for 12 bytes.
> + Configure a UNIX semaphore using key 0x12345678 mapped into psim
> + address space at 0xfff00000:
> +
> + | -o '/sem@0xfff00000/reg 0xfff00000 0x80000' \
> + | -o '/sem@0xfff00000/key 0x12345678' \
> +
> + sim/ppc/run -o '/#address-cells 1' \
> + -o '/sem@0xc0000000/reg 0xc0000000 0x80000' \
> + -o '/sem@0xc0000000/key 0x12345678' ../psim-hello/hello
>
> Other than these nits, it's ok with me (fwiw of course).
>
Thanks. I think I have gotten these fixed.
I will test a bit and resubmit a patch.
Thanks.
--joel
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2008-11-12 19:18 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-08 15:45 Add SystemV IPC drivers to PSIM Joel Sherrill
2008-11-05 16:55 Joel Sherrill
2008-11-06 2:35 ` teawater
2008-11-07 18:51 ` Joel Sherrill
2008-11-07 19:01 ` Daniel Jacobowitz
2008-11-07 20:58 ` Joel Sherrill
2008-11-08 0:07 ` Doug Evans
2008-11-10 14:42 ` Daniel Jacobowitz
2008-11-12 19:18 ` Doug Evans
2008-11-10 20:28 ` Joel Sherrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox