Cerebration
Action of the brain, whether conscious or unconscious. My blogs do not necessarily have a theme or a focus. They are here, because I felt like putting it here. They could be something which I am thinking about, something which I want to talk to someone about, something which I am working on or want to share. In short they are my feelings, opinions, work and good things I want to share.
Monday, June 14, 2010
What motivates us at home and at workplace?
Sunday, June 13, 2010
Simple stopclock using BASH
Saturday, April 24, 2010
Saturday, April 17, 2010
LKML Summary Podcast – A semi-daily summary of LKML traffic
kernelpodcast.org provides a semi-daily summary of email traffic on the Linux Kernel Mailing List (LKML) in the form of a podcast and audio transcripts. It was started by Jon Masters as a means to force himself to keep up with the LKML.
Friday, April 16, 2010
Monday, April 05, 2010
Calling a C function from Assembly
Recently I had a requirement of having to call a C function from assembly (in the Linux kernel). One might wonder why someone would have to call a C function from assembly. Well… the reason is I wanted a dump of registers before I put the processor (OMAP) to sleep. The sleep code in Linux is written in assembly and I wanted the dump in a place just before the final call (to sleep) is made. Writing an assembly routine would be too difficult.
I could have taken a dump before the code jumped to assembly and then followed the assembly code to see what changes are being made to which register to arrive at the register values before the processor is put to sleep. In fact I did that in my initial investigation. I could have also stored the values of the registers in a place in memory and printed them once the code gets back to C. However, I wanted to find a way to call a C function from assembly because that seemed very challenging and moreover, why should we make life difficult (by writing code in assembly) when we have a high level language to solve our problems.
I am not going deep in to the details of what all I tried, but here is what I did finally.
ARM’s SWI (software interrupts) instructions are used to execute system calls. On execution of the SWI instruction, the control is transferred to the kernel and depending on the number (which is part of the SWI instruction), the kernel executes the appropriate SWI handler (a system call). I used this method to call a system call of my own, which I used to dump the registers. The SWI instruction is a simple assembly instruction (something like swi 0x00900142).
I know that implementing a new system call for such small things is not recommended, but this was mainly for debugging an issue. This is not going to be part of any distribution.
More details about implementing a system call can be found by Googling.
Friday, March 26, 2010
Debugging early boot problems in Linux
Got this from Here. Posting only the portion I was interested in.
Accessing the printk buffer after a silent hang on boot.
This can also be useful when we are debugging the power management (that’s what I was doing when I wrote this).
Sometimes, if the kernel hangs early in the boot process, you get no messages on the console before the hang. Sometimes it's just "Uncompressing Linux.......". That's it.
However, there may still be messages in the printk buffer, which can give you an idea of where the problem is. The kernel starts putting messages into the printk buffer as soon as it starts. They stay buffered there until the console code has a chance to initialize the console device (often the serial port for embedded devices). Even though these messages are not printed before the hang, it is still possible in some circumstances to dump the printk buffer and see the messages.
When the kernel crashes as soon as it starts booting without any prints then its possible to dump the printk buffer from the boot loader. To do it you have to know how your boot loader maps memory compared to the kernel.
U-boot example on an OMAP OSK based board
When the kernel crashes, reset the board and drop to the boot loader prompt. Its important that you don't power cycle the board.
In the source tree of the compiled kernel which just crashed do
grep __log_buf System.map |
or
grep __log_buf /proc/kallsyms |
This showed
$ grep __log_buf System.map |
In our case, this address maps to 0x101eca94. So I reset the target board and use the following:
OMAP5912 OSK # md 0x101eca94 |
Similarly, the following steps shows the printk buffer (usually what got printed just before reset)
grep printk_buf System.map |
this shows the linked address of the printk_buf, e.g.:
c01ec5f4 b printk_buf.5 |
The address "c01ec5f4 " is in kernel virtual. Find the physical address mapping of it. So, after resetting the target board, but without letting it try to boot again, at the boot loader prompt
OMAP5912 OSK # md 101ec5f4 |
And you see the printk buffer that never got flushed to the UART. Knowing what's there can be very useful in debugging.