Ramshankar's Realm
I'm moving my blog postings from here to my new blog here.
See you there! That means bookmark and link me! :D
I'm moving my blog postings from here to my new blog here.
See you there! That means bookmark and link me! :D
Posted by
Ramshankar
at
2:23 PM
0
comments
CHECK THIS
Credits to the original poster, that was truly hilarious!!!!
:)
Posted by
Ramshankar
at
11:38 AM
0
comments
There is a nice way (using GNU binutils) to inject debug symbols into a release binary. This isn't an unknown trick but certainly not widely known even among most Linux/Unix programmers. Of course you cannot magically just add debugging symbols into a release build, you first need to have the appropriate debug binary built.
Here are the basic steps:
$objcopy --only-keep-debug myProg myProg.debug
$objcopy --add-gnu-debuglink=myProj.debug myProg
$objcopy --strip-debug myProg
Posted by
Ramshankar
at
11:24 AM
0
comments
Labels: binutils, debug symbols, solaris
I had to upgrade to Solaris Nevada build 75. I was previously using build 64, which was using a terribly old Gnome and missed some libraries that you would normally expect on a *nix system (xCursor etc.)
Build 75 also comes with the latest Gnome offering 2.20.0 with a much awaited Pidgin. No more crappy Gaim!! With updated GIMP, gedit among several others. As far as the OS goes, it has new libs, has xVM (the hypervisor) all included in nevada itself. It also has the necessary Crossbow components, revised drivers and a revised installer as well.
The new GUI installer looked far better than the crappy CDE one, but just as my luck would have the new installer kept crashing and I had to use the old GUI one. I couldn't perform an upgrade of my earlier build either as the installer (after about 30 agonizing minutes) told me I have not the required disk space. So had to perform a clean re-install, and restored various stuff from local zip backups.
Anyway, so far so good. This has been a good update from Sun.
Posted by
Ramshankar
at
1:52 PM
0
comments
My sockets bound,
but no bytes found,
my threads all spawn,
but deadlocks live on,
my program compiles,
my program even links,
but the output stinks,
memory pages are locked
but they still get swapped,
core dump, kernel panics,
do I still prefer *nix?,
corrupted is my code,
rebooting in safe mode,
cannot stand another crash,
perhaps time for the trash,
giving one last attempt,
alives comes the ethernet!
my sockets are fillling!
deadlocks all fleeing,
magic numbers equate,
the output is now perfect,
what a stroke of luck,
luck mixed with efforts,
fixed the socket ports,
gone are all the frowns,
life is full of ups and downs,
take it as it comes.
Blah blah... Now. Back to fixing the stubborn driver that won't unload.
Posted by
Ramshankar
at
6:27 PM
0
comments
Here's my workspace juggling feat...
Posted by
Ramshankar
at
6:46 PM
0
comments
Labels: solaris, workspaces
Solaris doesn't easily expose an API to allocate on-demand physically contiguous, custom aligned memory. It has no calls like BSD's contigmalloc() or Darwin's IOMallocContiguous(). Here's a code snippet on how to do it:
struct ddi_dma_attr g_SolarisX86PhysMemLimits =
{
DMA_ATTR_V0, /* Version Number */
(uint64_t)0, /* lower limit */
(uint64_t)0xffffffff, /* high limit (32-bit PA, 4G) */
(uint64_t)0xffffffff, /* counter limit */
(uint64_t)MMU_PAGESIZE, /* alignment */
(uint64_t)MMU_PAGESIZE, /* burst size */
(uint64_t)MMU_PAGESIZE, /* effective DMA size */
(uint64_t)0xffffffff, /* max DMA xfer size */
(uint64_t)0xffffffff, /* segment boundary */
1, /* scatter-gather list length */
1, /* device granularity */
0 /* bus-specific flags */
};
caddr_t kernVirtAddr;
int rc = i_ddi_mem_alloc(NULL, &g_SolarisX86PhysMemLimits, sizeInBytes,
1, 0, NULL, &kernVirtAddr, NULL, NULL);
i_ddi_mem_alloc(dev_info_t *dip, ddi_dma_attr_t *attr,
size_t length, int cansleep, int flags,
ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp,
size_t *real_length, ddi_acc_hdl_t *ap)
i_ddi_mem_free(kernVirtAddr, NULL)
Posted by
Ramshankar
at
6:43 PM
9
comments
Labels: allocation, kernel, physical contiguous memory, solaris
After some exploration and googling the Sun forums, I now know the difference between add_drv and modload. The man pages for these 2 commands don't really point out the difference between them. Here's a better picture of their potential usage...
modload:
Loads the module into memory whether it's needed or not. The driver gets initialized but the kernel doesn't call the Attach routine.
This means its initialized and ready for a speedy-attach! For example when plugging a USB device the USB driver requires lesser time if it's already initialized and just needs to attach. This can also be useful for filesystem drivers.
However it must be noted that the kernel module isn't reloaded upon reboot.
add_drv:
Adds the module to the system. The driver gets initialized and also attached. For non-device (pseudo) the driver would initialize and attach immediately. For drivers that attach to a particular device, the system would call modload when necessary (example for USB when the device is plugged in).
The driver remains installed and does not get removed after a reboot.
So after a short one week hectic vacation in Singapore I'm back in Chennai. As for what I did in Singapore, the usual: Bus rides, MRT, visit the zoo, some specific gadget shopping. I haven't had time to copy the pictures to my computer yet. Next, back to work as well.
Posted by
Ramshankar
at
9:58 PM
0
comments
Writing device drivers under a new Operating System can be a bit of challenge. Especially if its not similar to other OS's you're used to.
Here's a simple skeleton opensolaris pseudo character driver that simple aims to simple publish an entry under /devices/pseudo.
#include <sys/types.h>And don't forget the .conf file for the driver:
#include <sys/param.h>
#include <sys/errno.h>
#include <sys/uio.h>
#include <sys/buf.h>
#include <sys/modctl.h>
#include <sys/open.h>
#include <sys/conf.h>
#include <sys/cmn_err.h>
#include <sys/stat.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#define DEVICE_NAME "mytdrv"
#define DEVICE_DESC "My Test Driver"
static int mtd_open (dev_t* pDev, int flag, int otyp, cred_t* pCred);
static int mtd_close (dev_t pDev, int flag, int otyp, cred_t* pCred);
static int mtd_read (dev_t dev, struct uio* pUio, cred_t* pCred);
static int mtd_write (dev_t dev, struct uio* pUio, cred_t* pCred);
static int mtd_attach (dev_info_t* pDip, ddi_attach_cmd_t cmd);
static int mtd_detach(dev_info_t* pDip, ddi_detach_cmd_t cmd);
static int mtd_getinfo (dev_info_t *dip, ddi_info_cmd_t infocmd,
void *arg, void **result);
static struct cb_ops mtd_cb_ops =
{
mtd_open,
mtd_close,
nodev, /* b strategy */
nodev, /* b dump */
nodev, /* b print */
mtd_read,
mtd_write,
nodev, /* c ioctl */
nodev, /* c devmap */
nodev, /* c mmap */
nodev, /* c segmap */
nochpoll, /* c poll */
ddi_prop_op, /* property ops */
NULL, /* streamtab */
D_NEW | D_MP, /* compat. flag */
CB_REV /* revision */
};
static struct dev_ops mtd_dev_ops =
{
DEVO_REV, /* driver build revision */
0, /* ref count */
nodev,
nulldev, /* identify */
nulldev, /* probe */
mtd_attach,
mtd_detach,
nodev, /* reset */
&mtd_cb_ops,
(struct bus_ops *)0,
nodev /* power */
};
static struct modldrv md =
{
&mod_driverops, /* extern from kernel */
DEVICE_DESC,
&mtd_dev_ops
};
static struct modlinkage ml =
{
MODREV_1, /* loadable module system revision */
&md,
NULL /* terminate array of linkage structures */
};
/** Track module instances */
dev_info_t* dip;
int _init (void)
{
cmn_err(CE_NOTE, "MyDrvSolaris _init");
return mod_install(&ml);
}
int _fini (void)
{
cmn_err(CE_NOTE, "MyDrvSolaris _fini");
return mod_remove (&ml);
}
int _info (struct modinfo* pModInfo)
{
cmn_err(CE_NOTE, "MyDrvSolaris _info");
return mod_info (&ml, pModInfo);
}
static int mtd_open (dev_t *pDev, int flag, int otyp, cred_t* cred)
{
cmn_err(CE_CONT, "MyDrvSolarisOpen");
return DDI_SUCCESS;
}
static int mtd_close (dev_t pDev, int flag, int otyp, cred_t* cred)
{
cmn_err(CE_CONT, "MyDrvSolarisClose");
return DDI_SUCCESS;
}
static int mtd_read (dev_t dev, struct uio* pUio, cred_t* credp)
{
cmn_err(CE_CONT, "MyDrvSolarisRead");
return DDI_SUCCESS;
}
static int mtd_write (dev_t dev, struct uio* pUio, cred_t* credp)
{
cmn_err(CE_CONT, "MyDrvSolarisWrite");
return DDI_SUCCESS;
}
static int mtd_attach (dev_info_t* pDip, ddi_attach_cmd_t enmCmd)
{
cmn_err(CE_NOTE, "MyDrvSolarisAttach");
switch (enmCmd)
{
case DDI_ATTACH:
{
int instance = ddi_get_instance (pDip);
dip = pDip;
if (ddi_create_minor_node(pDip, "0", S_IFCHR,
instance, DDI_PSEUDO, 0) == DDI_SUCCESS)
{
cmn_err(CE_NOTE, "MyDrvSolarisAttach: successful.");
return DDI_SUCCESS;
}
else
{
/** Is this really necessary? */
ddi_remove_minor_node(pDip, NULL);
}
break;
}
default:
return DDI_FAILURE;
}
return DDI_FAILURE;
}
static int mtd_detach (dev_info_t* pDip, ddi_detach_cmd_t enmCmd)
{
cmn_err(CE_CONT, "MyDrvSolarisDetach");
switch (enmCmd)
{
case DDI_DETACH:
{
dip = NULL;
ddi_remove_minor_node (pDip, NULL);
return DDI_SUCCESS;
break;
}
default:
return DDI_FAILURE;
}
}
#
#
name="mytdrv" parent="pseudo";
gcc -D_KERNEL -ffreestanding -nodefaultlibs -c mytdrv.c
ld -r -o mytdrv mytdrv.o
su
cp mytdrv /usr/kernel/drv
cp mytdrv.conf /usr/kernel/drv
add_drv mytdrv
modload mytdrv
modinfo |grep mytdrv
modunload -i (id)
rem_drv mytdrv
devfsadm: driver failed to attach: mytdrv
Posted by
Ramshankar
at
7:12 PM
0
comments