<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EmbLogic &#187; sahilchugh0777</title>
	<atom:link href="https://www.emblogic.com/blog/author/sahilchugh0777/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.emblogic.com/blog</link>
	<description>Embedded System and ARM Training</description>
	<lastBuildDate>Tue, 03 Mar 2020 13:00:06 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>Role Of Device Driver</title>
		<link>https://www.emblogic.com/blog/06/role-of-device-driver/</link>
		<comments>https://www.emblogic.com/blog/06/role-of-device-driver/#comments</comments>
		<pubDate>Fri, 20 Jun 2014 12:24:13 +0000</pubDate>
		<dc:creator><![CDATA[sahilchugh0777]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10577</guid>
		<description><![CDATA[As a programmer, you will be able to make your own choices about your driver, choosing an acceptable trade-off between the programming time required and the flexibility of the result. Though it may appear strange to say that a driver &#8230; <a href="https://www.emblogic.com/blog/06/role-of-device-driver/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h2 class="sect1"><a name="t1"></a></h2>
<p><a name="INDEX-6"></a> <a name="INDEX-7"></a> <a name="INDEX-8"></a> As a programmer, you will be able to make your own choices about your driver, choosing an acceptable trade-off between the programming time required and the flexibility of the result. Though it may appear strange to say that a driver is &#8220;flexible,&#8221; we like this word because it emphasizes that the role of a device driver is providing <em class="emphasis">mechanism</em>, not <em class="emphasis">policy</em>.</p>
<p><a name="INDEX-8"></a></p>
<p><a name="INDEX-8"></a><a name="INDEX-9"></a> <a name="INDEX-10"></a> The distinction between mechanism and policy is one of the best ideas behind the Unix design. Most programming problems can indeed be split into two parts: &#8220;what capabilities are to be provided&#8221; (the mechanism) and &#8220;how those capabilities can be used&#8221; (the policy). If the two issues are addressed by different parts of the program, or even by different programs altogether, the software package is much easier to develop and to adapt to particular needs.</p>
<p><a name="INDEX-10"></a></p>
<p>For example, Unix management of the graphic display is split between the X server, which knows the hardware and offers a unified interface to user programs, and the window and session managers, which implement a particular policy without knowing anything about the hardware. People can use the same window manager on different hardware, and different users can run different configurations on the same workstation. Even completely different desktop environments, such as KDE and GNOME, can coexist on the same system. Another example is the layered structure of TCP/IP networking: the operating system offers the socket abstraction, which implements no policy regarding the data to be transferred, while different servers are in charge of the services (and their associated policies). Moreover, a server like <em class="application">ftpd</em> provides the file transfer mechanism, while users can use whatever client they prefer; both command-line and graphic clients exist, and anyone can write a new user interface to transfer files.</p>
<p><a name="INDEX-10"></a></p>
<p>Where drivers are concerned, the same separation of mechanism and policy applies. The floppy driver is policy free &#8212; its role is only to show the diskette as a continuous array of data blocks. Higher levels of the system provide policies, such as who may access the floppy drive, whether the drive is accessed directly or via a filesystem, and whether users may mount filesystems on the drive. Since different environments usually need to use hardware in different ways, it&#8217;s important to be as policy free as possible.</p>
<p><a name="INDEX-10"></a></p>
<p>When <em class="emphasis">writing</em> drivers, a programmer should pay particular attention to this fundamental concept: write kernel code to access the hardware, but don&#8217;t force particular policies on the user, since different users have different needs. The driver should deal with making the hardware available, leaving all the issues about <em class="emphasis">how</em> to use the hardware to the applications. A driver, then, is flexible if it offers access to the hardware capabilities without adding constraints. Sometimes, however, some policy decisions must be made. For example, a digital I/O driver may only offer byte-wide access to the hardware in order to avoid the extra code needed to handle individual bits.</p>
<p><a name="INDEX-10"></a></p>
<p>You can also look at your driver from a different perspective: it is a software layer that lies between the applications and the actual device. This privileged role of the driver allows the driver programmer to choose exactly how the device should appear: different drivers can offer different capabilities, even for the same device. The actual driver design should be a balance between many different considerations. For instance, a single device may be used concurrently by different programs, and the driver programmer has complete freedom to determine how to handle concurrency. You could implement memory mapping on the device independently of its hardware capabilities, or you could provide a user library to help application programmers implement new policies on top of the available primitives, and so forth. One major consideration is the trade-off between the desire to present the user with as many options as possible and the time in which you have to do the writing as well as the need to keep things simple so that errors don&#8217;t creep in.</p>
<p><a name="INDEX-10"></a></p>
<p>Policy-free drivers have a number of typical characteristics. These include support for both synchronous and asynchronous operation, the ability to be opened multiple times, the ability to exploit the full capabilities of the hardware, and the lack of software layers to &#8220;simplify things&#8221; or provide policy-related operations. Drivers of this sort not only work better for their end users, but also turn out to be easier to write and maintain as well. Being policy free is actually a common target for software designers.</p>
<p><a name="INDEX-10"></a></p>
<p><a name="INDEX-10"></a><a name="INDEX-11"></a> <a name="INDEX-12"></a> Many device drivers, indeed, are released together with user programs to help with configuration and access to the target device. Those programs can range from simple utilities to complete graphical applications. Examples include the <em class="emphasis">tunelp</em>program, which adjusts how the parallel port printer driver operates, and the graphical <em class="emphasis">cardctl</em> utility that is part of the PCMCIA driver package. Often a client library is provided as well, which provides capabilities that do not need to be implemented as part of the driver itself.</p>
<p><a name="INDEX-12"></a></p>
<p><a name="INDEX-12"></a><a name="INDEX-13"></a><a name="INDEX-14"></a> The scope of this book is the kernel, so we&#8217;ll try not to deal with policy issues, or with application programs or support libraries. Sometimes we&#8217;ll talk about different policies and how to support them, but we won&#8217;t go into much detail about programs using the device or the policies they enforce. You should understand, however, that user programs are an integral part of a software package and that even policy-free packages are distributed with configuration files that apply a default behavior to the underlying mechanisms.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/06/role-of-device-driver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inter-Process Communication with Sockets</title>
		<link>https://www.emblogic.com/blog/06/inter-process-communication-with-sockets/</link>
		<comments>https://www.emblogic.com/blog/06/inter-process-communication-with-sockets/#comments</comments>
		<pubDate>Tue, 17 Jun 2014 12:20:46 +0000</pubDate>
		<dc:creator><![CDATA[sahilchugh0777]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10533</guid>
		<description><![CDATA[Inter-Process Communication with Sockets Client-Server Model A standard model for distributed applications is the client-server model. A server is a process that is waiting to be contacted by a client process so that the server can do something or the &#8230; <a href="https://www.emblogic.com/blog/06/inter-process-communication-with-sockets/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h1>Inter-Process Communication with Sockets</h1>
<h2>Client-Server Model</h2>
<p>A standard model for distributed applications is the client-server model. A server is a process that is waiting to be contacted by a client process so that the server can do something or the client. A typical scenario is as follows:</p>
<ul>
<li>The server process is started on some computer system. It initializes itself, then goes to sleep waiting for a client process to contact it requesting some service.</li>
<li>A client process is started, either on the same system or on another system that is connected to the server&#8217;s system with a network. The client process sends a request across the network to the server requesting a service of some form.</li>
<li>When the server process has finished providing its service to the client, the server goes back to sleep, waiting for the next client request to arrive.</li>
</ul>
<h2>Socket definition</h2>
<p>A communication between two processes running on two computer systems can be completely specified by the association: <i>{protocol, local-address, local-process, remote-address, remote-process}</i> We also define a half association as either <i>{protocol, local-address, local-process}</i> or <i>{protocol, remote-address, remote-process}</i>, which specify half of a connection. This half association is also called <b>socket</b>, or transport address. The term socket has been popularized by the Berkeley Unix networking system, where it is &#8220;an end point of communication&#8221;, which corresponds to the definition of half association.</p>
<h2>System calls related to sockets</h2>
<p>For a UNIX file, there are six system calls for input/output (I/O): open, create, close, read, write and lseek. All these system calls work with a file descriptor, a number corresponding to a certain file. It would be nice if the interface to the network facilities maintained the file descriptor semantics of the Unix file system, but network I/O involves more details and options than the file input/output. However, the difference is not extremely big.</p>
<p><img src="http://www.it.uom.gr/teaching/distrubutedSite/dsIdaLiu/labs/lab2_1/tcp_seq.gif" alt="" align="middle" /></p>
<p>This figure shows a time line of a typical scenario that takes place for a connection-oriented transfer. First the server is started, then sometimes later a client is started that connects to the server.</p>
<p>To do network I/O, the first thing a process must do is call the socket (see the man page for the system calls presented, e.g. man -s3n socket) system call, specifying the type of communication protocol desired.</p>
<pre>#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;

int socket(int family, int type, int protocol);
</pre>
<p>for our lab, we will use only the internet protocols and stream socket type, so the function call will look like: sockfd = socket(AF_INET, SOCK_STREAM, 0); The socket system call returns a small integer value, similar to a file descriptor. We call this a socket descriptor, or a sockfd.</p>
<p>Up to now, for the association <i>{protocol, local-address, local-process, remote-address, remote-process}</i> we have only specified the protocol. In order to fill the local-address and local-process elements of the association we will use the bind system call.</p>
<pre>#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;

int bind(int sockfd, struct sockaddr *myaddr, int addrlen);
</pre>
<p>The second argument of bind is a pointer to a protocol-specific address, and the third argument is the size of the address structure. bind tells the system &#8220;this is my address and any messages received for this address are to be given to me&#8221;.</p>
<p>Then, the server indicates that is willing to receive connections:</p>
<pre> 
int listen(int sockfd, int backlog); 
</pre>
<p>The backlog argument specifies how many connection requests can be queued by the system while it waits for the server to execute the accept system call.</p>
<p>After executing the listen system call, an actual connection is waited for by having the server execute the accept system call.</p>
<pre>#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;

int accept(int sockfd, struct sockaddr *peer, int *addrlen);
</pre>
<p>accept takes the first connection request from the queue, and creates another socket with the same proprieties as sockfd. When a connection request is received and accepted, the new socket descriptor returned by accept refers to a complete association <i>{protocol, remote-address, remote-process}</i> with the last two fields filled with information from the client. The client&#8217;s address is also set in the second (*peer) parameter together with its length, *addrlen;</p>
<p>A client process connects to a socket descriptor following the socket system call to establish a connection with a server:</p>
<pre>#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;

int connect(int sockfd, struct sockaddr *servaddr, int addrlen);
</pre>
<p>The sockfd is a socket descriptor that was returned by the socket system call. The second and the third argument are a pointer to a socket address, and its size.</p>
<p>From now on, the server and the client can use the write/read system calls for file descriptors in order to communicate. Stream sockets exhibit a behaviour with the read and write system calls that differs from normal file I/O. A read or a write on a socket might input or output fewer bytes than requested, but this is not an error condition. The reason is that buffer limits might be reached for the socket in the kernel and all that is required is for the caller to invoke the read or write system call again, for the remaining bytes.</p>
<p>Many of the socket system calls require a pointer to a socket address structure as an argument. The definition of this structure is in</p>
<pre>&lt;sys/socket.h&gt;:

struct sockaddr {
	u_short 	sa_family; /* address_family: AF_xxx value */	
	char 		sa_data[14];
};
</pre>
<p>The contents of the 14 bytes of protocol-specific address are interpreted according to the type of address. For the Internet family, the following structures are defined in <code>&lt;netinet/in.h&gt;:</code></p>
<pre>struct in_addr {
	u_long 		s_addr; /* 32 bit netid/hostid */
};

struct sockaddr_in {
	short 		sin_family; 		/* AF_INET */
	u_short 	sin_port; 		/* 16 bit port number, network byte ordered */
	srtuct in_addr 	sin_addr; 		/* 32 bit netid/hostid, network byte ordered */
	char 		sin_zero[8]; 		/* unused */
}
</pre>
<p>Both the client and the server close their sockets using the close function call.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/06/inter-process-communication-with-sockets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction To Threads</title>
		<link>https://www.emblogic.com/blog/06/introduction-to-threads-2/</link>
		<comments>https://www.emblogic.com/blog/06/introduction-to-threads-2/#comments</comments>
		<pubDate>Tue, 03 Jun 2014 06:50:46 +0000</pubDate>
		<dc:creator><![CDATA[sahilchugh0777]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10272</guid>
		<description><![CDATA[A thread of execution is often regarded as the smallest unit of processing that a scheduler works on. A process can have multiple threads of execution which are executed asynchronously. This asynchronous execution brings in the capability of each thread &#8230; <a href="https://www.emblogic.com/blog/06/introduction-to-threads-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div class="format_text entry-content">
<div style="margin: 7px 0px 6px 0px;padding: 5px"></div>
<p>A thread of execution is often regarded as the smallest unit of processing that a scheduler works on.</p>
<p>A process can have multiple threads of execution which are executed asynchronously.</p>
<p>This asynchronous execution brings in the capability of each thread handling a particular work or service independently. Hence multiple threads running in a process handle their services which overall constitutes the complete capability of the process.<br />
<span id="more-10017"></span><br />
In this article we will touch base on the fundamentals of threads and build the basic understanding required to learn the practical aspects of Linux threads.</p>
<h3>Why Threads are Required?</h3>
<p>Now, one would ask why do we need multiple threads in a process?? Why can’t a process with only one (default) main thread be used in every situation.</p>
<p>Well, to answer this lets consider an example :</p>
<p>Suppose there is a process, that receiving real time inputs and corresponding to each input it has to produce a certain output. Now, if the process is not multi-threaded ie if the process does not involve multiple threads, then the whole processing in the process becomes synchronous. This means that the process takes an input processes it and produces an output.</p>
<div style="margin-left: 2px;margin-top: 10px;margin-bottom: 10px"></div>
<p>The limitation in the above design is that the process cannot accept an input until its done processing the earlier one and in case processing an input takes longer than expected then accepting further inputs goes on hold.</p>
<p>To consider the impact of the above limitation, if we map the generic example above with a  socket server process that can accept input connection, process them and provide the socket client with output. Now, if in processing any input if the server process takes more than expected time and in the meantime another input (connection request) comes to the socket server then the server process would not be able to accept the new input connection as its already stuck in processing the old input connection. This may lead to a connection time out at the socket client which is not at all desired.</p>
<p>This shows that synchronous model of execution cannot be applied everywhere and hence was the requirement of asynchronous model of execution felt which is implemented by using threads.</p>
<h3>Difference Between threads and processes</h3>
<p>Following are some of the major differences between the thread and the processes :</p>
<ul>
<li>Processes do not share their address space while threads executing under same process share the address space.</li>
<li>From the above point its clear that processes execute independent of each other and the synchronization between processes is taken care by kernel only while on the other hand the thread synchronization has to be taken care by the process under which the threads are executing</li>
<li>Context switching between threads is fast as compared to context switching between processes</li>
<li>The interaction between two processes is achieved only through the standard inter process communication while threads executing under the same process can communicate easily as they share most of the resources like memory, text segment etc</li>
</ul>
<h3>User threads Vs Kernel Threads</h3>
<p>Threads can exist in user space as well as in kernel space.</p>
<p>A <strong>user space</strong> threads are created, controlled and destroyed using user space thread libraries. These threads are not known to kernel and hence kernel is nowhere involved in their processing. These threads follow co-operative multitasking where-in a thread releases CPU on its own wish ie the scheduler cannot preempt the thread. Th advantages of user space threads is that the switching between two threads does not involve much overhead and is generally very fast while on the negative side since these threads follow co-operative multitasking so if one thread gets block the whole process gets blocked.</p>
<p>A <strong>kernel space</strong> thread is created, controlled and destroyed by the kernel. For every thread that exists in user space there is a corresponding kernel thread. Since these threads are managed by kernel so they follow preemptive multitasking where-in the scheduler can preempt a thread in execution with a higher priority thread which is ready for execution. The major advantage of kernel threads is that even if one of the thread gets blocked the whole process is not blocked as kernel threads follow preemptive scheduling while on the negative side the context switch is not very fast as compared to user space threads.</p>
<p>If we talk of Linux then kernel threads are optimized to such an extent that they are considered better than user space threads and mostly used in all scenarios except where prime requirement is that of cooperative multitasking.</p>
<h3>Problem with Threads</h3>
<p>There are some major problems that arise while using threads :</p>
<ul>
<li>Many operating system does not implement threads as processes rather they see threads as part of parent process. In this case, what would happen if a thread calls fork() or even worse what if a thread execs a new binary?? These scenarios may have dangerous consequences for example in the later problem the whole parent process could get replaced with the address space of the newly exec’d binary. This is not at all desired.  Linux which is POSIX complaint makes sure that calling a fork() duplicates only the thread that has called the fork() function while an exec from any of the thread would stop all the threads in the parent process.</li>
<li>Another problem that may arise is the concurrency problems. Since threads share all the segments (except the stack segment) and can be preempted at any stage by the scheduler than any global variable or data structure that can be left in inconsistent state by preemption of one thread could cause severe problems when the next high priority thread executes the same function and uses the same variables or data structures.</li>
</ul>
<p>For the problem 1 mentioned above, all we can say is that its a design issue and design for applications should be done in a way that least problems of this kind arise.</p>
<p>For the problem 2 mentioned above, using locking mechanisms programmer can lock a chunk of code inside a function so that even if a context switch happens (when the function global variable and data structures were in inconsistent state) then also next thread is not able to execute the same code until the locked code block inside the function is unlocked by the previous thread (or the thread that acquired it</p>
</div>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/06/introduction-to-threads-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Device Drivers Inroduction</title>
		<link>https://www.emblogic.com/blog/05/device-drivers-inroduction/</link>
		<comments>https://www.emblogic.com/blog/05/device-drivers-inroduction/#comments</comments>
		<pubDate>Tue, 27 May 2014 06:39:51 +0000</pubDate>
		<dc:creator><![CDATA[sahilchugh0777]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10214</guid>
		<description><![CDATA[One of the purposes of an operating system is to hide the peculiarities of the system&#8217;s hardware devices from its users. For example the Virtual File System presents a uniform view of the mounted filesystems irrespective of the underlying physical &#8230; <a href="https://www.emblogic.com/blog/05/device-drivers-inroduction/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>One of the purposes of an operating system is to hide the peculiarities of the system&#8217;s hardware devices from its users. For example the Virtual File System presents a uniform view of the mounted filesystems irrespective of the underlying physical devices. This chapter describes how the Linux kernel manages the physical devices in the system.</p>
<p>The CPU is not the only intelligent device in the system, every physical device has its own hardware controller. The keyboard, mouse and serial ports are controlled by a SuperIO chip, the IDE disks by an IDE controller, SCSI disks by a SCSI controller and so on. Each hardware controller has its own control and status registers (CSRs) and these differ between devices. The CSRs for an Adaptec 2940 SCSI controller are completely different from those of an NCR 810 SCSI controller. The CSRs are used to start and stop the device, to initialize it and to diagnose any problems with it. Instead of putting code to manage the hardware controllers into every application, the code is kept in the Linux kernel. The software that handles or manages a hardware controller is known as a device driver. The Linux kernel device drivers are, essentially, a shared library of privileged, memory resident, low level hardware handling routines. It is Linux&#8217;s device drivers that handle the peculiarities of the devices they are managing.</p>
<p>&nbsp;</p>
<p>Linux supports three types of hardware devices: character, block and network. Character devices are read and written directly without buffering, for example the system&#8217;s serial ports /dev/cua0 and /dev/cua1. Block devices can only be written to and read from in multiples of the block size, typically 512 or 1024 bytes. Block devices are accessed via the buffer cache and may be randomly accessed, that is to say, any block can be read or written no matter where it is on the device. Block devices can be accessed via their device special file but more commonly they are accessed via the file system. Only a block device can support a mounted file system. Network devices are accessed via the BSD socket interface and the networking subsytems described in the section on networking.</p>
<p>There are many different device drivers in the Linux kernel (that is one of Linux&#8217;s strengths) but they all share some common attributes:</p>
<p>&nbsp;</p>
<dl>
<dt><b>Kernel code</b></dt>
<dd>Device drivers are part of the kernel and, like other code within the kernel, if they go wrong they can seriously damage the system. A badly written driver may even crash the system, possibly corrupting file systems and losing data.&nbsp;</p>
</dd>
<dt><b>Kernel interfaces</b></dt>
<dd>Device drivers provide a standard interface to the Linux kernel or to the appropriate subsystem. For example, the terminal driver provides a file I/O interface to the Linux kernel and a SCSI device driver provides a SCSI device interface to the SCSI subsystem which, in turn, provides both file I/O and buffer cache interfaces to the kernel.&nbsp;</p>
</dd>
<dt><b>Kernel mechanisms and services</b></dt>
<dd>Device drivers make use of standard kernel services such as memory allocation, interrupt delivery and wait queues to operate.&nbsp;</p>
</dd>
<dt><b>Loadable</b></dt>
<dd>Most of the Linux device drivers can be loaded on demand as kernel modules when they are needed and unloaded when they are no longer being used. This makes the kernel very adaptable and efficient with the system&#8217;s resources.&nbsp;</p>
</dd>
<dt><b>Configurable</b></dt>
<dd>Linux device drivers can be built into the kernel. Which devices are built is configurable when the kernel is compiled.&nbsp;</p>
</dd>
<dt><b>Dynamic</b></dt>
<dd>As the system boots and each device driver is initialized it looks for the hardware devices that it will control. If those devices do not exist (maybe are just not found), the device driver is simply redundant and causes no harm apart from occupying a little of the system&#8217;s memory.</dd>
</dl>
<p>&nbsp;</p>
<h2>Memory</h2>
<p>Device drivers have to be careful when using memory. As they are part of the Linux kernel they cannot use virtual memory. Each time a device driver runs, maybe as an interrupt is received or as a bottom half or task queue handler is scheduled, the current process may change. The device driver cannot rely on a particular process running even if it is doing work on its behalf. Like the rest of the kernel, device drivers use data structures to keep track of the device they controll. The kernel would become unnecessarily large if these data structures were statically allocated, part of the device driver&#8217;s code. Most device drivers allocate kernel, non-paged, memory to hold their data.</p>
<p>Linux provides kernel memory allocation and deallocation routines and it is these that the device drivers use. Kernel memory is allocated in chunks that are powers of 2. For example 128 or 512 bytes, even if the device driver asks for less. The number of bytes that the device driver requests is rounded up to the next block size boundary. This makes kernel memory deallocation easier as the smaller free blocks can be recombined into bigger blocks.</p>
<p>It may be that Linux needs to do quite a lot of extra work when the kernel memory is requested. If the amount of free memory is low, physical pages may need to be discarded or written to the swap device. Normally, Linux would suspend the requestor, putting the process onto a wait queue until there is enough physical memory. Not all device drivers (or indeed Linux kernel code) may want this to happen and so the kernel memory allocation routines can be requested to fail if they cannot immediately allocate memory.</p>
<p>The device driver can also specify that it wants to DMA to and from the memory it allocates. It is the Linux kernel, not the device driver, however, that takes care of the details. This way it is the Linux kernel rather than the device driver decides what constitutes DMA&#8217;able memory for the system.</p>
<p>&nbsp;</p>
<h2>Interfacing Device Drivers with the Kernel</h2>
<p>To ensure that access is always done in the correct manner, the Linux kernel must be able to interact with device drivers in standard ways. Each class of device driver, character, block and network, provides common interfaces that the kernel uses when requesting services from them. These common interfaces mean that the kernel can treat often very different devices and their device drivers absolutely the same. For example, SCSI and IDE disks behave very differently but the Linux kernel uses the same interface to both of them.</p>
<p>Linux is very dynamic, every time a Linux kernel boots it may encounter different physical devices and thus need different device drivers. Linux allows you to include device drivers at kernel build time via its configuration scripts. When these drivers are initialized at boot time they may not discover any hardware to control. Other drivers can be loaded as kernel modules when they are needed. To cope with this dynamic nature of device drivers, device drivers register themselves with the kernel as they are initialized. Linux maintains tables of registered device drivers as part of its interfaces with them. These tables include pointers to routines and information that supports the interface with the device class.</p>
<p>&nbsp;</p>
<h3>Character Devices</h3>
<p>Figure: Character Devices</p>
<p>Character devices, the simplest of Linux&#8217;s devices, are accessed as files, applications use standard system calls to open them, read from them, write to them and close them exactly as if the device were a file. This is true even if the device is a modem being used by the PPP daemon to connect a Linux system onto a network. As a character device is initialized its device driver registers itself with the Linux kernel by adding an entry into the chrdevs vector of device_struct data structures. The device&#8217;s major device identifier (for example 4 for the tty device) is used as an index into this vector. The major device identifier for a device is fixed.</p>
<p>Each entry in the chrdevs vector, a device_struct data structure contains two elements: a pointer to the name of the registered device driver and a pointer to a block of file operations. This block of file operations is itself the addresses of routines within the character device driver, each of which handles specific file operations such as open, read, write and close. The contents of <span class="file">/proc/devices</span> for character devices is taken from the chrdevs vector.</p>
<p>When a character special file representing a character device (for example <span class="device">/dev/cua0</span>) is opened, the kernel must set things up so that the correct character device driver&#8217;s file operation routines will be called. Just like an ordinairy file or directory, each device special file is represented by a VFS inode . The VFS inode for a character special file, indeed for all device special files, contains both the major and minor identifiers for the device. This VFS inode was created by the underlying filesystem, for example EXT2, from information in the real filesystem when the device special file&#8217;s name was looked up.</p>
<p>Each VFS inode has associated with it a set of file operations and these are different depending on the filesystem object that the inode represents. Whenever a VFS inode representing a character special file is created, its file operations are set to the default character device operations.</p>
<p>This has only one file operation, the open file operation. When the character special file is opened by an application the generic open file operation uses the device&#8217;s major identifier as an index into the chrdevs vector to retrieve the file operations block for this particular device. It also sets up the file data structure describing this character special file, making its file operations pointer point to those of the device driver. Thereafter all of the applications file operations will be mapped to calls to the character devices set of file operations.</p>
<p>&nbsp;</p>
<h3>Block Devices</h3>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/05/device-drivers-inroduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DEVICE DRIVER</title>
		<link>https://www.emblogic.com/blog/05/device-driver-11/</link>
		<comments>https://www.emblogic.com/blog/05/device-driver-11/#comments</comments>
		<pubDate>Tue, 13 May 2014 07:29:03 +0000</pubDate>
		<dc:creator><![CDATA[sahilchugh0777]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=10069</guid>
		<description><![CDATA[Character Device Driver: In order to create a link between your device means your hardware either it is internal or externally attached and user application we need a set of rules which will define how your concerned device shall deal &#8230; <a href="https://www.emblogic.com/blog/05/device-driver-11/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p style="text-align: left"><strong>Character Device Driver</strong>: In order to create a link between your device means your hardware either it is internal or externally attached and user application we need a set of rules which will define how your concerned device shall deal with application make sure user will get a satisfactory output as desired.</p>
<p style="text-align: left">First let me give you a brief idea of architecture which helped me to create my device driver. Its is mainly divided in two basic parts first one is know as your USER LEVEL where application runs and the 2nd is your KERNEL LEVEL where your device driver is defined.</p>
<p style="text-align: left">This is how a link is created between application and device through device driver.</p>
<p style="text-align: left"><strong>APPLICATION</strong>——-&gt;<strong>NODE</strong>——&gt;<strong>DEVICE DRIVER</strong>——–&gt; <strong>DEVICE</strong></p>
<p style="text-align: left">NODE is an interface between USER LEVEL and KERNEL LEVEL..</p>
<p style="text-align: left">There are few kernel defined structure and rest are user defined structure through which we can define the functionality of our device driver.</p>
<p style="text-align: left">KERNEL DEFINED STRUCTURE– 1-&gt;<strong>Struct File</strong> 2-&gt;<strong>struct Inode</strong> 3-&gt;<strong>Cdev</strong>. etc</p>
<p style="text-align: left">USER DEFINED STRUCTURE– 1-&gt;<strong>struct ScullDev</strong> 2-&gt;<strong> struct Scullqse</strong>t 3-&gt;<strong>struct file operations</strong>.</p>
<p style="text-align: left">Lets look how all these all structure works one by one.</p>
<p style="text-align: left"><strong>Scull</strong> is a memory space which is allocated in machine memory to your device. in scull we have two vital structure know as <strong>struct Sculldev</strong> and <strong>struct Scullqset</strong>. The former one is the starting point of scull as well as contains data about all the scullqset present in your scull in a way it contains metadata. its member are as fallow- 1-*scullqset 2-no of scullqset 3-datasize 4-quantum size 5-device size. and last but not the least  struct Cdev.</p>
<p style="text-align: left">The later one <strong>Scullqset</strong> is a structure which store data or information. it mainly has two member first one is a pointer to next scullqset and the second one double pointer to y.our data, means first it will point to an array of pointer known as qset ,contains the add of quantum where actually our data is kept.</p>
<p style="text-align: left"><strong>Struct file operations</strong>-&gt; it generally defines the behavior of our device. it is used here to map the user level system calls to programmer defined system calls. some system calls are <strong>OPEN,CLOSE,WRITE,READ</strong>… etc</p>
<p style="text-align: left"><strong>Struct Cdev</strong>—&gt; it mainly has three member 1st one is owner which specifies about its owner name 2nd is a pointer to file operation,3rd to dev which contains major and minor no. now what is this major and minor no. lets have a look before we proceed further</p>
<p style="text-align: left"><strong>Major no</strong> is a number which is given to each and every device driver we have in our machine and <strong>minor no</strong> is the number which represents your the device associated with that particular device driver. struct Cdev is your device representation in kernel Space.</p>
<p style="text-align: left">Now comes kernel level structures into picture. <strong>STRUCT INODE</strong> .. as we all know that in linux everything is file either it is a text file, some kind of code or any device with each and every file there is an associated inode structure , here we will mainly concentrate and concerned about which is particularly represents our device. “inode is the only way through which we can or its better to say our application can interact with our device. main member are i_cev which points to your struct cdev. pointer to file operations.</p>
<p style="text-align: left"><strong>Struct file</strong>-&gt; members are *f_pos which takes the account of the cursor in your file. pointer to file operations , *private data which will help us to do mapping from your user level to kernal level as its stores the address of your SCULL so we can access all the data which we have stored in quantum part of scullqset from user level. this is all about the architecture now lets have  look on the operations or working.</p>
<p style="text-align: left"><strong>STEPS TO BE FOLLOWED</strong>:</p>
<p style="text-align: left">1.<strong> Insmod</strong> which will load our module, module is a source code which is loaded on demand.</p>
<p style="text-align: left">2. <strong>Registration</strong>:register our device driver and device so that DD will get a major number and device gets its own minor number.</p>
<p style="text-align: left">3.<strong>Allocation</strong>: Allocate space to Scull in machine memory.</p>
<p style="text-align: left">4.<strong>Initialize Scull</strong>–&gt; cdev_init— create link between struct inode and struct cdev… define owner.. cdev_add make attribute of device available to our kernael.</p>
<p style="text-align: left">5. <strong>Sculldev initiallization</strong>: define size of qset,quantun,device..etc</p>
<p style="text-align: left">6.<strong> Scull Trim</strong>. flash data if present in the memory space which is assigned to scull</p>
<p style="text-align: left">7.<strong>Open</strong>: define open system call.</p>
<p style="text-align: left">8. <strong>Write</strong>: before doing that allocate space to Scullqset then to qset and at last to quantum now we can write data to our quantum, <strong>LSEEK</strong> if needed.</p>
<p style="text-align: left">9. <strong>Read</strong>: read whatever you have written to quantum.</p>
<p>10. <strong>Release</strong>: de-allocate all the space, unregister your device and DD, remove your module</p>
<p style="text-align: left"><strong>Character Device Driver</strong>: In order to create a link between your device means your hardware either it is internal or externally attached and user application we need a set of rules which will define how your concerned device shall deal with application make sure user will get a satisfactory output as desired.</p>
<p style="text-align: left">First let me give you a brief idea of architecture which helped me to create my device driver. Its is mainly divided in two basic parts first one is know as your USER LEVEL where application runs and the 2nd is your KERNEL LEVEL where your device driver is defined.</p>
<p style="text-align: left">This is how a link is created between application and device through device driver.</p>
<p style="text-align: left"><strong>APPLICATION</strong>——-&gt;<strong>NODE</strong>——&gt;<strong>DEVICE DRIVER</strong>——–&gt; <strong>DEVICE</strong></p>
<p style="text-align: left">NODE is an interface between USER LEVEL and KERNEL LEVEL..</p>
<p style="text-align: left">There are few kernel defined structure and rest are user defined structure through which we can define the functionality of our device driver.</p>
<p style="text-align: left">KERNEL DEFINED STRUCTURE– 1-&gt;<strong>Struct File</strong> 2-&gt;<strong>struct Inode</strong> 3-&gt;<strong>Cdev</strong>. etc</p>
<p style="text-align: left">USER DEFINED STRUCTURE– 1-&gt;<strong>struct ScullDev</strong> 2-&gt;<strong> struct Scullqse</strong>t 3-&gt;<strong>struct file operations</strong>.</p>
<p style="text-align: left">Lets look how all these all structure works one by one.</p>
<p style="text-align: left"><strong>Scull</strong> is a memory space which is allocated in machine memory to your device. in scull we have two vital structure know as <strong>struct Sculldev</strong> and <strong>struct Scullqset</strong>. The former one is the starting point of scull as well as contains data about all the scullqset present in your scull in a way it contains metadata. its member are as fallow- 1-*scullqset 2-no of scullqset 3-datasize 4-quantum size 5-device size. and last but not the least  struct Cdev.</p>
<p style="text-align: left">The later one <strong>Scullqset</strong> is a structure which store data or information. it mainly has two member first one is a pointer to next scullqset and the second one double pointer to y.our data, means first it will point to an array of pointer known as qset ,contains the add of quantum where actually our data is kept.</p>
<p style="text-align: left"><strong>Struct file operations</strong>-&gt; it generally defines the behavior of our device. it is used here to map the user level system calls to programmer defined system calls. some system calls are <strong>OPEN,CLOSE,WRITE,READ</strong>… etc</p>
<p style="text-align: left"><strong>Struct Cdev</strong>—&gt; it mainly has three member 1st one is owner which specifies about its owner name 2nd is a pointer to file operation,3rd to dev which contains major and minor no. now what is this major and minor no. lets have a look before we proceed further</p>
<p style="text-align: left"><strong>Major no</strong> is a number which is given to each and every device driver we have in our machine and <strong>minor no</strong> is the number which represents your the device associated with that particular device driver. struct Cdev is your device representation in kernel Space.</p>
<p style="text-align: left">Now comes kernel level structures into picture. <strong>STRUCT INODE</strong> .. as we all know that in linux everything is file either it is a text file, some kind of code or any device with each and every file there is an associated inode structure , here we will mainly concentrate and concerned about which is particularly represents our device. “inode is the only way through which we can or its better to say our application can interact with our device. main member are i_cev which points to your struct cdev. pointer to file operations.</p>
<p style="text-align: left"><strong>Struct file</strong>-&gt; members are *f_pos which takes the account of the cursor in your file. pointer to file operations , *private data which will help us to do mapping from your user level to kernal level as its stores the address of your SCULL so we can access all the data which we have stored in quantum part of scullqset from user level. this is all about the architecture now lets have  look on the operations or working.</p>
<p style="text-align: left"><strong>STEPS TO BE FOLLOWED</strong>:</p>
<p style="text-align: left">1.<strong> Insmod</strong> which will load our module, module is a source code which is loaded on demand.</p>
<p style="text-align: left">2. <strong>Registration</strong>:register our device driver and device so that DD will get a major number and device gets its own minor number.</p>
<p style="text-align: left">3.<strong>Allocation</strong>: Allocate space to Scull in machine memory.</p>
<p style="text-align: left">4.<strong>Initialize Scull</strong>–&gt; cdev_init— create link between struct inode and struct cdev… define owner.. cdev_add make attribute of device available to our kernael.</p>
<p style="text-align: left">5. <strong>Sculldev initiallization</strong>: define size of qset,quantun,device..etc</p>
<p style="text-align: left">6.<strong> Scull Trim</strong>. flash data if present in the memory space which is assigned to scull</p>
<p style="text-align: left">7.<strong>Open</strong>: define open system call.</p>
<p style="text-align: left">8. <strong>Write</strong>: before doing that allocate space to Scullqset then to qset and at last to quantum now we can write data to our quantum, <strong>LSEEK</strong> if needed.</p>
<p style="text-align: left">9. <strong>Read</strong>: read whatever you have written to quantum.</p>
<p>10. <strong>Release</strong>: de-allocate all the space, unregister your device and DD, remove your module</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/05/device-driver-11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Major and Minor Numbers</title>
		<link>https://www.emblogic.com/blog/05/major-and-minor-numbers/</link>
		<comments>https://www.emblogic.com/blog/05/major-and-minor-numbers/#comments</comments>
		<pubDate>Mon, 12 May 2014 06:16:43 +0000</pubDate>
		<dc:creator><![CDATA[sahilchugh0777]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=9998</guid>
		<description><![CDATA[Char devices are accessed through names in the filesystem. Those names are called special files or device files or simply nodes of the filesystem tree; they are conventionally located in the /dev directory. Special files for char drivers are identified &#8230; <a href="https://www.emblogic.com/blog/05/major-and-minor-numbers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><strong></strong></p>
<h2 class="sect1"><a name="t2"></a></h2>
<p><a name="INDEX-453"></a> <a name="INDEX-454"></a> <a name="INDEX-455"></a> <a name="INDEX-456"></a> <a name="INDEX-457"></a> <a name="INDEX-458"></a> <a name="INDEX-459"></a> <a name="INDEX-460"></a> <a name="INDEX-461"></a> Char devices are accessed through names in the filesystem. Those names are called special files or device files or simply nodes of the filesystem tree; they are conventionally located in the <em class="filename">/dev</em> directory. Special files for char drivers are identified by a &#8220;c&#8221; in the first column of the output of <em class="emphasis">ls -l</em>. Block devices appear in <em class="filename">/dev</em> as well, but they are identified by a &#8220;b.&#8221; The focus of this chapter is on char devices, but much of the following information applies to block devices as well.</p>
<p><strong><a name="INDEX-461"></a> </strong></p>
<p><a name="INDEX-461"></a><a name="INDEX-462"></a> <a name="INDEX-463"></a> If you issue the <em class="application">ls -l</em> command, you&#8217;ll see two numbers (separated by a comma) in the device file entries before the date of last modification, where the file length normally appears. These numbers are the major device number and minor device number for the particular device. The following listing shows a few devices as they appear on a typical system. Their major numbers are 1, 4, 7, and 10, while the minors are 1, 3, 5, 64, 65, and 129.</p>
<p><strong><a name="INDEX-463"></a></strong></p>
<blockquote>
<pre class="code"> crw-rw-rw- 1 root   root    1, 3   Feb 23 1999  null
 crw------- 1 root   root   10, 1   Feb 23 1999  psaux
 crw------- 1 rubini tty     4, 1   Aug 16 22:22 tty1
 crw-rw-rw- 1 root   dialout 4, 64  Jun 30 11:19 ttyS0
 crw-rw-rw- 1 root   dialout 4, 65  Aug 16 00:00 ttyS1
 crw------- 1 root   sys     7, 1   Feb 23 1999  vcs1
 crw------- 1 root   sys     7, 129 Feb 23 1999  vcsa1
 crw-rw-rw- 1 root   root    1, 5   Feb 23 1999  zero
</pre>
</blockquote>
<p><strong><a name="INDEX-463"></a></strong></p>
<p>The major number identifies the driver associated with the device. For example, <em class="filename">/dev/null</em> and <em class="filename">/dev/zero</em> are both managed by driver 1, whereas virtual consoles and serial terminals are managed by driver 4; similarly, both <em class="filename">vcs1</em> and <em class="filename">vcsa1</em> devices are managed by driver 7. The kernel uses the major number at <em class="emphasis">open</em> time to dispatch execution to the appropriate driver.</p>
<p><strong><a name="INDEX-463"></a></strong></p>
<p><a name="INDEX-463"></a><a name="INDEX-464"></a> <a name="INDEX-465"></a> The minor number is used only by the driver specified by the major number; other parts of the kernel don&#8217;t use it, and merely pass it along to the driver. It is common for a driver to control several devices (as shown in the listing); the minor number provides a way for the driver to differentiate among them.</p>
<p><strong><a name="INDEX-465"></a> </strong></p>
<p><a name="INDEX-465"></a><a name="INDEX-466"></a> <a name="INDEX-467"></a> Version 2.4 of the kernel, though, introduced a new (optional) feature, the device file system or <em class="emphasis">devfs</em>. If this file system is used, management of device files is simplified and quite different; on the other hand, the new filesystem brings several user-visible incompatibilities, and as we are writing it has not yet been chosen as a default feature by system distributors. The previous description and the following instructions about adding a new driver and special file assume that <em class="emphasis">devfs</em> is not present. The gap is filled later in this chapter, in &#8220;The Device Filesystem&#8221;.</p>
<p><strong><a name="INDEX-467"></a> </strong></p>
<p><a name="INDEX-467"></a><a name="INDEX-468"></a> <a name="INDEX-469"></a> <a name="INDEX-470"></a> <a name="INDEX-471"></a> When <em class="emphasis">devfs</em> is not being used, adding a new driver to the system means assigning a major number to it. The assignment should be made at driver (module) initialization by calling the following function, defined in <tt class="literal">&lt;linux/fs.h&gt;</tt>:</p>
<p><strong><a name="INDEX-471"></a></strong></p>
<blockquote>
<pre class="code"> int register_chrdev(unsigned int major, const char *name,
      struct file_operations *fops);
</pre>
</blockquote>
<p><strong><a name="INDEX-471"></a></strong></p>
<p><a name="INDEX-471"></a><a name="INDEX-472"></a> <a name="INDEX-473"></a> <a name="INDEX-474"></a> <a name="INDEX-475"></a> The return value indicates success or failure of the operation. A negative return code signals an error; a 0 or positive return code reports successful completion. The <tt class="literal">major</tt> argument is the major number being requested, <tt class="literal">name</tt> is the name of your device, which will appear in <em class="filename">/proc/devices</em>, and <tt class="literal">fops</tt> is the pointer to an array of function pointers, used to invoke your driver&#8217;s entry points, as explained in &#8220;File Operations&#8221;, later in this chapter.</p>
<p><strong><a name="INDEX-475"></a></strong></p>
<p>The major number is a small integer that serves as the index into a static array of char drivers; &#8220;Dynamic Allocation of Major Numbers&#8221; later in this chapter explains how to select a major number. The 2.0 kernel supported 128 devices; 2.2 and 2.4 increased that number to 256 (while reserving the values 0 and 255 for future uses). Minor numbers, too, are eight-bit quantities; they aren&#8217;t passed to <em class="emphasis">register_chrdev</em> because, as stated, they are only used by the driver itself. There is tremendous pressure from the developer community to increase the number of possible devices supported by the kernel; increasing device numbers to at least 16 bits is a stated goal for the 2.5 development series.</p>
<p><strong><a name="INDEX-475"></a></strong></p>
<p><a name="INDEX-475"></a><a name="INDEX-476"></a> Once the driver has been registered in the kernel table, its operations are associated with the given major number. Whenever an operation is performed on a character device file associated with that major number, the kernel finds and invokes the proper function from the <tt class="literal">file_operations</tt> structure. For this reason, the pointer passed to <em class="emphasis">register_chrdev</em> should point to a global structure within the driver, not to one local to the module&#8217;s initialization function.</p>
<p><strong><a name="INDEX-476"></a> </strong></p>
<p><a name="INDEX-476"></a><a name="INDEX-477"></a> <a name="INDEX-478"></a> The next question is how to give programs a name by which they can request your driver. A name must be inserted into the <em class="filename">/dev</em> directory and associated with your driver&#8217;s major and minor numbers.</p>
<p><strong><a name="INDEX-478"></a> </strong></p>
<p><a name="INDEX-478"></a><a name="INDEX-479"></a> The command to create a device node on a filesystem is <em class="application">mknod</em>; superuser privileges are required for this operation. The command takes three arguments in addition to the name of the file being created. For example, the command</p>
<p><strong><a name="INDEX-479"></a></strong></p>
<blockquote>
<pre class="code"> mknod /dev/scull0 c 254 0
</pre>
</blockquote>
<p><strong><a name="INDEX-479"></a></strong></p>
<p>creates a char device (<tt class="literal">c</tt>) whose major number is 254 and whose minor number is 0. Minor numbers should be in the range 0 to 255 because, for historical reasons, they are sometimes stored in a single byte. There are sound reasons to extend the range of available minor numbers, but for the time being, the eight-bit limit is still in force.</p>
<p><strong><a name="INDEX-479"></a></strong></p>
<p>Please note that once created by <em class="application">mknod</em>, the special device file remains unless it is explicitly deleted, like any information stored on disk. You may want to remove the device created in this example by issuing <em class="emphasis">rm /dev/scull0</em>.</p>
<p><strong><a name="INDEX-479"></a><a name="chardynamajor"></a></strong></p>
<h3 class="sect2"></h3>
<p><strong><a name="chardynamajor"></a></strong></p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/05/major-and-minor-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>what is bash ?</title>
		<link>https://www.emblogic.com/blog/04/what-is-bash/</link>
		<comments>https://www.emblogic.com/blog/04/what-is-bash/#comments</comments>
		<pubDate>Tue, 01 Apr 2014 12:20:31 +0000</pubDate>
		<dc:creator><![CDATA[sahilchugh0777]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=9726</guid>
		<description><![CDATA[Bash is the shell, or command language interpreter, for the GNU operating system. The name is an acronym for the ‘Bourne-Again SHell’, a pun on Stephen Bourne, the author of the direct ancestor of the current Unix shell sh, which &#8230; <a href="https://www.emblogic.com/blog/04/what-is-bash/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Bash is the shell, or command language interpreter, for the GNU operating system. The name is an acronym for the ‘Bourne-Again SHell’, a pun on Stephen Bourne, the author of the direct ancestor of the current Unix shell sh, which appeared in the Seventh Edition Bell Labs Research version of Unix.</p>
<p>Bash is largely compatible with sh and incorporates useful features from the Korn shell ksh and the C shell csh. It is intended to be a conformant implementation of the IEEE POSIX Shell and Tools portion of the IEEE POSIX specification (IEEE Standard 1003.1). It offers functional improvements over sh for both interactive and programming use.</p>
<p>While the GNU operating system provides other shells, including a version of csh, Bash is the default shell. Like other GNU software, Bash is quite portable. It currently runs on nearly every version of Unix and a few other operating systems &#8211; independently-supported ports exist for MS-DOS, OS/2, and Windows platforms. </p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/04/what-is-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Difference between physical addressing and virtual addressing concept</title>
		<link>https://www.emblogic.com/blog/03/difference-between-physical-addressing-and-virtual-addressing-concept/</link>
		<comments>https://www.emblogic.com/blog/03/difference-between-physical-addressing-and-virtual-addressing-concept/#comments</comments>
		<pubDate>Mon, 31 Mar 2014 12:10:44 +0000</pubDate>
		<dc:creator><![CDATA[sahilchugh0777]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=9337</guid>
		<description><![CDATA[up vote 8 down vote accepted Physical addressing means that your program actually knows the real layout of RAM. When you access a variable at address 0x8746b3, that&#8217;s where it&#8217;s really stored in the physical RAM chips. With virtual addressing, &#8230; <a href="https://www.emblogic.com/blog/03/difference-between-physical-addressing-and-virtual-addressing-concept/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>up vote 8 down vote accepted</p>
<p>Physical addressing means that your program actually knows the real layout of RAM. When you access a variable at address 0x8746b3, that&#8217;s where it&#8217;s really stored in the physical RAM chips.</p>
<p>With virtual addressing, all application memory accesses go to a page table, which then maps from the virtual to the physical address. So every application has its own &#8220;private&#8221; address space, and no program can read or write to another program&#8217;s memory. This is called segmentation.</p>
<p>Virtual addressing has many benefits. It protects programs from crashing each other through poor pointer manipulation, etc. Because each program has its own distinct virtual memory set, no program can read another&#8217;s data &#8211; this is both a safety and a security plus. Virtual memory also enables paging, where a program&#8217;s physical RAM may be stored on a disk (or, now, slower flash) when not in use, then called back when an application attempts to access the page. Also, since only one program may be resident at a particular physical page, in a physical paging system, either a) all programs must be compiled to load at different memory addresses or b) every program must use Position-Independent Code, or c) some sets of programs cannot run simultaneously.</p>
<p>The physical-virtual mapping may be done in software (with hardware support for memory traps) or in pure hardware. Sometimes even the page tables themselves are on a special set of hardware memory. I don&#8217;t know off the top of my head which embedded system does what, but every desktop has a hardware TLB (Translation Lookaside Buffer, basically a cache for the virtual-physical mappings) and some now have advanced Memory Mapping Units that help with virtual machines and the like.</p>
<p>The only downsides of virtual memory are added complexity in the hardware implementation and slower performance.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/difference-between-physical-addressing-and-virtual-addressing-concept/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Output of following program?</title>
		<link>https://www.emblogic.com/blog/03/output-of-following-program/</link>
		<comments>https://www.emblogic.com/blog/03/output-of-following-program/#comments</comments>
		<pubDate>Tue, 25 Mar 2014 07:09:18 +0000</pubDate>
		<dc:creator><![CDATA[sahilchugh0777]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=9333</guid>
		<description><![CDATA[int main() { static int i=5; if(&#8211;i){ main(); printf(&#8220;%d &#8220;,i); } } answer is 0000]]></description>
				<content:encoded><![CDATA[<p>int main()<br />
{<br />
    static int i=5;<br />
    if(&#8211;i){<br />
        main();<br />
        printf(&#8220;%d &#8220;,i);<br />
    }<br />
}</p>
<p>answer is 0000</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/output-of-following-program/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is the diffrence between single quoted and dauble quoted declaration of char array</title>
		<link>https://www.emblogic.com/blog/03/what-is-the-diffrence-between-single-quoted-and-dauble-quoted-declaration-of-char-array/</link>
		<comments>https://www.emblogic.com/blog/03/what-is-the-diffrence-between-single-quoted-and-dauble-quoted-declaration-of-char-array/#comments</comments>
		<pubDate>Mon, 24 Mar 2014 08:29:32 +0000</pubDate>
		<dc:creator><![CDATA[sahilchugh0777]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=9207</guid>
		<description><![CDATA[In C/C++, when a character array is initialized with a double quoted string and array size is not specified, compiler automatically allocates one extra space for string terminator ‘?. For example, following program prints 6 as output. #include int main() &#8230; <a href="https://www.emblogic.com/blog/03/what-is-the-diffrence-between-single-quoted-and-dauble-quoted-declaration-of-char-array/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>In C/C++, when a character array is initialized with a double quoted string and array size is not specified, compiler automatically allocates one extra space for string terminator ‘?. For example, following program prints 6 as output.<br />
#include<br />
int main()<br />
{<br />
  char arr[] = &#8220;geeks&#8221;; // size of arr[] is 6 as it is &#8221; terminated<br />
  printf(&#8220;%d&#8221;, sizeof(arr));<br />
  getchar();<br />
  return 0;<br />
}</p>
<p>If array size is specified as 5 in the above program then the program works without any warning/error and prints 5 in C, but causes compilation error in C++.<br />
// Works in C, but compilation error in C++<br />
#include<br />
int main()<br />
{<br />
  char arr[5] = &#8220;geeks&#8221;;  // arr[] is not terminated with &#8221;<br />
                                   // and its size is 5<br />
  printf(&#8220;%d&#8221;, sizeof(arr));<br />
  getchar();<br />
  return 0;<br />
}</p>
<p>When character array is initialized with comma separated list of characters and array size is not specified, compiler doesn’t create extra space for string terminator ‘?. For example, following program prints 5.<br />
#include<br />
int main()<br />
{<br />
  char arr[]= {&#8216;g&#8217;, &#8216;e&#8217;, &#8216;e&#8217;, &#8216;k&#8217;, &#8216;s&#8217;}; // arr[] is not terminated with &#8221; and its size is 5<br />
  printf(&#8220;%d&#8221;, sizeof(arr));<br />
  getchar();<br />
  return 0;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/what-is-the-diffrence-between-single-quoted-and-dauble-quoted-declaration-of-char-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Write a C Programme that does not terminate when Cntrl+C is pressed</title>
		<link>https://www.emblogic.com/blog/03/write-a-c-programme-that-does-not-terminate-when-cntrlc-is-pressed/</link>
		<comments>https://www.emblogic.com/blog/03/write-a-c-programme-that-does-not-terminate-when-cntrlc-is-pressed/#comments</comments>
		<pubDate>Fri, 21 Mar 2014 06:44:51 +0000</pubDate>
		<dc:creator><![CDATA[sahilchugh0777]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=9198</guid>
		<description><![CDATA[Write a C program that doesn’t terminate when Ctrl+C is pressed. It prints a message “Cannot be terminated using Ctrl+c” and continues execution. We can use signal handling in C for this. When Ctrl+C is pressed, SIGINT signal is generated, &#8230; <a href="https://www.emblogic.com/blog/03/write-a-c-programme-that-does-not-terminate-when-cntrlc-is-pressed/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Write a C program that doesn’t terminate when Ctrl+C is pressed. It prints a message “Cannot be terminated using Ctrl+c” and continues execution.</p>
<p>We can use signal handling in C for this. When Ctrl+C is pressed, SIGINT signal is generated, we can catch this signal and run our defined signal handler.  C standard defines following 6 signals in signal.h header file.</p>
<p>SIGABRT – abnormal termination.<br />
SIGFPE – floating point exception.<br />
SIGILL – invalid instruction.<br />
SIGINT – interactive attention request sent to the program.<br />
SIGSEGV – invalid memory access.<br />
SIGTERM – termination request sent to the program.</p>
<p>Additional signals are specified Unix and Unix-like operating systems (such as Linux) defines more than 15 additional signals. See http://en.wikipedia.org/wiki/Unix_signal#POSIX_signals<br />
The standard C library function signal() can be used to set up a handler for any of the above signals.<br />
/* A C program that does not terminate when Ctrl+C is pressed */<br />
#include<br />
#include </p>
<p>/* Signal Handler for SIGINT */<br />
void sigintHandler(int sig_num)<br />
{<br />
    /* Reset handler to catch SIGINT next time.<br />
       Refer http://en.cppreference.com/w/c/program/signal */<br />
    signal(SIGINT, sigintHandler);<br />
    printf(&#8220;\n Cannot be terminated using Ctrl+C \n&#8221;);<br />
    fflush(stdout);<br />
}</p>
<p>int main ()<br />
{<br />
    /* Set the SIGINT (Ctrl-C) signal handler to sigintHandler<br />
       Refer http://en.cppreference.com/w/c/program/signal */<br />
    signal(SIGINT, sigintHandler);</p>
<p>    /* Infinite loop */<br />
    while(1)<br />
    {<br />
    }<br />
    return 0;<br />
}</p>
<p>Ouput: When Ctrl+C was pressed two times</p>
<p> Cannot be terminated using Ctrl+C</p>
<p> Cannot be terminated using Ctrl+C</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/write-a-c-programme-that-does-not-terminate-when-cntrlc-is-pressed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
