Test application: mini-peeker.c

Here's the source code for a test application called mini-peeker.c that maps in the minidriver data area and prints the contents:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/mman.h>
#include <sys/neutrino.h>
#include <sys/syspage.h>
#include <hw/inout.h>
#include <inttypes.h>

struct mini_data
{
   uint16_t     nstartup;
   uint16_t     nstartupp;
   uint16_t     nstartupf;
   uint16_t     nkernel;
   uint16_t     nprocess;
   uint16_t     data_len;
};

int main(int argc, char *argv[]) 
{
   int               i, count;
   int               dump_data = 0;
   uint8_t           *dptr;
   struct mini_data  *mdata;
        
   if (argv[1])
       dump_data = 1;
                
   ThreadCtl(_NTO_TCTL_IO, 0);

   /* map in minidriver data area */
   dptr = mmap( 0, 65535, PROT_READ | PROT_WRITE | PROT_NOCACHE,
                MAP_PHYS | MAP_SHARED, NOFD,
                SYSPAGE_ENTRY(mdriver)->data_paddr);
   if (dptr == NULL)
   {
        fprintf(stderr, "Unable to get data pointer\n");
        return (-1);
   }

   mdata = (struct mini_data *) dptr;
   dptr = dptr + sizeof(struct mini_data);

   /* dump mini-driver data */  
   printf("---------------- MDRIVER DATA -------------------\n");
   printf("\tMDRIVER_STARTUP         calls = %d\n", mdata->nstartup);
   printf("\tMDRIVER_STARTUP_PREPARE calls = %d\n", mdata->nstartupp);
   printf("\tMDRIVER_STARTUP_FINI    calls = %d\n", mdata->nstartupf);
   printf("\tMDRIVER_KERNEL          calls = %d\n", mdata->nkernel);
   printf("\tMDRIVER_PROCESS         calls = %d\n", mdata->nprocess);
   printf("\tData Length             calls = %d\n", mdata->data_len);
   count = mdata->data_len;

   if (dump_data)
   {    
       printf("State information:\n");
       for (i = 0; i < count; i++)
            printf("%d\n", dptr[i]);
    }
    printf("\n---------------------------------\n");

   return EXIT_SUCCESS;
}