Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:18

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief RTEMS monitor IO (device drivers) support
0007  *
0008  * There are 2 "driver" things the monitor knows about.
0009  *
0010  *    1. Regular RTEMS drivers.
0011  *         This is a table indexed by major device number and
0012  *         containing driver entry points only.
0013  *
0014  *    2. Driver name table.
0015  *         A separate table of names for drivers.
0016  *         The table converts driver names to a major number
0017  *         as index into the driver table and a minor number
0018  *         for an argument to driver.
0019  *
0020  *  Drivers are displayed with 'driver' command.
0021  *  Names are displayed with 'name' command.
0022  */
0023 
0024 /*
0025  * COPYRIGHT (c) 1989-2022. On-Line Applications Research Corporation (OAR).
0026  *
0027  * Redistribution and use in source and binary forms, with or without
0028  * modification, are permitted provided that the following conditions
0029  * are met:
0030  * 1. Redistributions of source code must retain the above copyright
0031  *    notice, this list of conditions and the following disclaimer.
0032  * 2. Redistributions in binary form must reproduce the above copyright
0033  *    notice, this list of conditions and the following disclaimer in the
0034  *    documentation and/or other materials provided with the distribution.
0035  *
0036  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0037  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0038  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0039  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0040  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0041  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0042  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0043  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0044  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0045  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0046  * POSSIBILITY OF SUCH DAMAGE.
0047  */
0048 
0049 #ifdef HAVE_CONFIG_H
0050 #include "config.h"
0051 #endif
0052 
0053 #include <rtems.h>
0054 #include <rtems/ioimpl.h>
0055 #include <rtems/monitor.h>
0056 
0057 #include <stdio.h>
0058 #include <stdlib.h>             /* strtoul() */
0059 #include <inttypes.h>
0060 
0061 #define DATACOL 15
0062 #define CONTCOL DATACOL     /* continued col */
0063 
0064 
0065 void
0066 rtems_monitor_driver_canonical(
0067     rtems_monitor_driver_t *canonical_driver,
0068     const void             *driver_void
0069 )
0070 {
0071     const rtems_driver_address_table *d = (const rtems_driver_address_table *) driver_void;
0072 
0073     rtems_monitor_symbol_canonical_by_value(&canonical_driver->initialization,
0074                                             (void *) d->initialization_entry);
0075 
0076     rtems_monitor_symbol_canonical_by_value(&canonical_driver->open,
0077                                             (void *) d->open_entry);
0078     rtems_monitor_symbol_canonical_by_value(&canonical_driver->close,
0079                                             (void *) d->close_entry);
0080     rtems_monitor_symbol_canonical_by_value(&canonical_driver->read,
0081                                             (void *) d->read_entry);
0082     rtems_monitor_symbol_canonical_by_value(&canonical_driver->write,
0083                                             (void *) d->write_entry);
0084     rtems_monitor_symbol_canonical_by_value(&canonical_driver->control,
0085                                             (void *) d->control_entry);
0086 }
0087 
0088 
0089 const void *
0090 rtems_monitor_driver_next(
0091     void                  *object_info RTEMS_UNUSED,
0092     rtems_monitor_driver_t *canonical_driver,
0093     rtems_id              *next_id
0094 )
0095 {
0096     uint32_t   n = rtems_object_id_get_index(*next_id);
0097 
0098     if (n >= _IO_Number_of_drivers)
0099         goto failed;
0100 
0101     _Objects_Allocator_lock();
0102 
0103     /*
0104      * dummy up a fake id and name for this item
0105      */
0106 
0107     canonical_driver->id = n;
0108     canonical_driver->name = rtems_build_name('-', '-', '-', '-');
0109 
0110     *next_id += 1;
0111     return (const void *) (&_IO_Driver_address_table[n]);
0112 
0113 failed:
0114     *next_id = RTEMS_OBJECT_ID_FINAL;
0115     return 0;
0116 }
0117 
0118 
0119 void
0120 rtems_monitor_driver_dump_header(
0121     bool verbose RTEMS_UNUSED
0122 )
0123 {
0124     fprintf(stdout,"\
0125   Major      Entry points\n");
0126 /*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
0127 0         1         2         3         4         5         6         7       */
0128     rtems_monitor_separator();
0129 }
0130 
0131 void
0132 rtems_monitor_driver_dump(
0133     rtems_monitor_driver_t *monitor_driver,
0134     bool                    verbose
0135 )
0136 {
0137     uint32_t            length = 0;
0138 
0139     length += fprintf(stdout,"  %" PRId32 "", monitor_driver->id);
0140     length += rtems_monitor_pad(13, length);
0141     length += fprintf(stdout,"init: ");
0142     length += rtems_monitor_symbol_dump(&monitor_driver->initialization, verbose);
0143     length += fprintf(stdout,";  control: ");
0144     length += rtems_monitor_symbol_dump(&monitor_driver->control, verbose);
0145     length += fprintf(stdout,"\n");
0146     length = 0;
0147 
0148     length += rtems_monitor_pad(13, length);
0149 
0150     length += fprintf(stdout,"open: ");
0151     length += rtems_monitor_symbol_dump(&monitor_driver->open, verbose);
0152     length += fprintf(stdout,";  close: ");
0153     length += rtems_monitor_symbol_dump(&monitor_driver->close, verbose);
0154     length += fprintf(stdout,"\n");
0155     length = 0;
0156 
0157     length += rtems_monitor_pad(13, length);
0158 
0159     length += fprintf(stdout,"read: ");
0160     length += rtems_monitor_symbol_dump(&monitor_driver->read, verbose);
0161     length += fprintf(stdout,";  write: ");
0162     length += rtems_monitor_symbol_dump(&monitor_driver->write, verbose);
0163     length += fprintf(stdout,"\n");
0164     length = 0;
0165 }