Posts

Showing posts from 2011

Function call and stacks for Calling Conventions

Image
When a function is called arguments are passed to the called function by different means, like stacks ,registers. Similarly return is either done by stack or register, According to function calling conventions the compiler design the assembly code from c/cpp codes to pass arguments to called function. It also specify the stack handling of the portion used by the function. In x86 stack normally grow downward. EBP keeps track of the base of the frame(frame pointer),and ESP keeps track of the top of the stack.EAX have the return value. In PPC stack pointer is r1,Base pointer is r0,r3 is the return register. As I blogged before on PPC register classification . (from wikipedia) The C function Calling convention define following things Order in which arguments are pushed on the stack. Who is responsible for stack clean-up process either callee or caller function after call complete. Name decorating for individual function before linking. Available call c

Recent Liking

Image
Lately hearing RD barman and kishore's Songs. Seem like I becoming romantic .Though I like Mehdi Hassan and Gullam Ali also. The Guy Khurram Imtiaz has uploaded most of the best videos of kishore ,nushrat, ghulam ali etc check his playlists. http://www.youtube.com/user/KhurramDBG#g/p

Curiosity Mars Rover,monster truck for mars

Image
CAPE CANAVERAL, 27 NOV: Nasa's Curiosity rover, the biggest, most sophisticated robotic explorer ever built, blasted off on a journey to Mars, where it will hunt for signs that life once existed there.  Curiosity, which is the size of a large car and weighs in at one ton, has a laser beam for zapping interesting rocks and a tool kit for analysing their contents. It carries a robotic arm, a drill, and a set of 10 science instruments including two color video cameras. Sensors will enable it to report back on the Martian weather and the levels of radiation in the atmosphere ~ important data for Nasa as it devises future human exploration missions. Known formally as the Mars Science Laboratory (MSL), the spacecraft launched at 10.02 a.m. (1502 GMT) atop an Atlas V rocket to begin its nearly nine-month trip to the Red Planet. It has power house made from plutonium decaying. Specification and features: SIZE : 10 ft (3.0 m) in length, and weighs 1,984 lb (90

Difference between Declaration and Defination

In general definition is where the variable or function is whereas code tell the compiler to allocate some memo ry and initial values goes to it,whereas declaration is the place where we define its name,type, return type to compiler etc. For Functions: //declaration   int foo(char a,int ); //definition  int foo(int a , int b)  { ..... } For automatic and register  variable definition & declaration are same bcoz they allocate memory  whenever defined. For external  storage class variables they are different. Global variables are defined in another file.Symols are resolved in time of  object linking. Externals can be declared and defined outside a function without any storage class(?).They can be declared using the"extern" keyword [e.g. extern int a;] e.g f1.c int var_name ;  //declaration only for global and static (Only initialized in BSS but no memory storage) int var2_name ; //de int var3_name = 22 ; //declaration and definition void foo2(in

Intel Platform Codenames

After frustrated by the lots of codename while working with intel processor based SBC I made the list of recent processors and platforms.

Poetry - When I see my baby What do I see - by Johnny Tillostson

Poetry in motion walking by my side Her lovely locomotion Keeps my eyes open wide Poetry in motion see her gentle swaying A wave out on the ocean Could never move that way I love every movement There's nothing I would change She doesn't need improvement She's much too nice to rearrange Poetry in motion dancing close to me A flower of devotion a-swaying gracefully Woh-woh-woh-woh-woh-woh Woh-woh-woh-woh-woh..... Poetry in motion see her gentle swaying A wave out on the ocean Could never move that way I love every movement There's nothing I would change She doesn't need improvement She's much too nice to rearrange Poetry in motion all that I adore her No number nine love potion Could make me love her more Woh-woh-woh-woh-woh-woh Woh-woh-woh-woh-woh.....

Bengali to english tools

বেঙ্গলি ভাষা tools http://bengali.changathi.com/ http://dsal.uchicago.edu/dictionaries/biswas-bengali/ অভিধানhttp://dictionary.evergreenbangla.com/ is bengali avidhan Somewhat good http://translate.google.com/?hl=en

Differencce of address pointer manipulation in vxworksDiab and GNU GCC

I was wondering what was happening for vxWorks Diab compiler and GNU gcc compiler. GNU gcc needs void *  for printing%p where diab dont generate such warning. for %x also gnu expect unsigned int * as argument where diab also don't generate any warning.

Copy_to_user or copy_from_user instead of memcpy

Quite the contrary, it does handle the case for swapped out memory. Lets take a look at it, shall we? copy_to/from_user boils down to __copy_user in arch/i386/lib/usercopy.c: #define __copy_user(to,from,size) \ do { \ int __d0, __d1, __d2; \ __asm__ __volatile__( \ " cmp $7,%0\n" \ " jbe 1f\n" \ " movl %1,%0\n" \ " negl %0\n" \ " andl $7,%0\n" \ " subl %0,%3\n" \ "4: rep; movsb\n" \ " movl %3,%0\n"

Interrupt and exceptions

x386 Specific   The 386 recognizes two event classes: exceptions and interrupts. Both cause a forced context switch to new a procedure or task. Interrupts can occur at unexpected times during the execution of a program and are used to respond to signals from hardware. Exceptions are caused by the execution of instructions. According to source Interrupts are of two types 1) Masakble 2)Non-Maskable According to Source Exceptions are of two types 1)Processor Detected 2) Programmed Exception Non-maskable interrupts and processor exceptions are assigned vector from 0-31.2 to 255 vectors can be used for maskable interrupt or programmed exception.Those are assigned/put in databus by external interrupt controller during interrupt acknowledgemt.  Vector Description 0 divide error 1 debug exception 2 NMI interrupt 3 Breakpoint 4 INTO-detected Overflow 5 BOUND range exceeded

Simulation vs Emulation

Simulation is the imitation of some real thing, state of affairs, or process. The act of simulating something generally entails representing certain key characteristics or behaviours of a selected physical or abstract system. Simulation is used in many contexts, such as simulation of technology for performance optimization, safety engineering , testing , training , education, and video games. Training simulators include flight simulators for training aircraft pilots in order to provide them with a lifelike experience. The simulator simulates the behavior of your system through software, so you can simulate a program that will run on a microcontroller or on a FPGA. And you can simulate the behavior of a hardware system using mathematical equations. In computing, an emulator is hardware and/or software that duplicates (or emulates ) the functions of a first computer system in a different second computer system, so that the behavior of the second system closely resembles t

Working of System Calls in Operating Systems

System call is used in user application to request some hardware/Operating system service access. When user call a system call it actually call some user level library (glibc/ulibc) which is in between User and Operating System.They are implemented as short pieces of assembly code named as system call stub.Which actually place system call number associated to the particular system call to a register (For x86 EAX) , place the arguments other registers (for x86 EBX,ECX etc.)  and issue a trap instruction ( in X86 calling assembly call INT 0x80 , " sc " for powerpc) to switch from user mode to kernel privileged mode. In trap handler kernel code copies arguments to kernel stack and call corresponding system call handler. According to system call dispatcher a new system call may be attached to kernel in compile time or run time. After running system code handler it return by putting return value in some register. (In PPC r3 register) Note: While passing arguments fro

Structure member Alignment & Padding

Structure and union variable declarations A structure or union declaration has the same form as a definition except the declaration does not have a brace-enclosed list of members. You must declare the structure or union data type before you can define a variable having that type. Read syntax diagramSkip visual syntax diagramStructure or union variable declaration syntax .-----------------------------. V | >>---+-------------------------+-+--+-struct-+------------------> +-storage_class_specifier-+ '-union--' '-type_qualifier----------' >--tag_identifier--declarator--;------------------------------->< Bit Fields Alignment If a series of bit fields does not add up to the size of an int, padding can take place. The amount of padding is determined by the alignment characteristics of the members of the structure. The following example demonstrates padding, and is valid for all implementations. Suppose th

typeof, offsetof, container_of

http://gcc.gnu.org/onlinedocs/gcc/Typeof.html http://kerneltrap.com/node/15927 http://en.wikipedia.org/wiki/Offsetof #define offsetof(st, m)      \     ((size_t) ( (char *)&((st *)(0))->m - (char *)0 )) http://www.kroah.com/log/linux/container_of.html #define container_of(ptr, type, member) ({ \     const typeof( ((type *)0)->member ) *__mptr = (ptr);  \     (type *)( (char *)__mptr - offsetof(type,member) );}) C pre processor http://tigcc.ticalc.org/doc/cpp.html http://stackoverflow.com/questions/1552454/can-i-substitute-func-into-an-identifier-name-in-a-c-macro

Signed integer representeton in memory

For char range -128 to +127; MSB is used for sign representation, 2 complement is used to represent -ve val for any -ve value take 2s complement to convert it to hex form. and to return to its original decimal value also do 2s complement. for example  -30  in hex will be 30 = 0x1E => 2s complement = ~0x1E + 1 = 0xE2 To get a -ve decimal value 0xE2 's 2s complement = 1E =30; Note:  2s complement is used for negative integers (negation of positive int) Note:char a= 0x80 (== -128); now a<<1 gives -256 (though it's out of range) Ref: http://en.wikipedia.org/wiki/Signed_number_representations http://www.hoomanb.com/cs/yorku/2021/data_representation.pdf http://www.swarthmore.edu/NatSci/echeeve1/Ref/BinaryMath/NumSys.html

Floating point Calculation

http://www.fsinc.com/reference/html/com9anm.htm http://www.math.uic.edu/~hanson/mcs471/FloatingPointRep.html http://www.randelshofer.ch/fhw/gri/float.html http://www.keil.com/support/man/docs/c51/c51_ap_floatingpt.htm http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF

Bit counting in a UINT32

unsigned int v; // count bits set in this (32-bit value) unsigned int c; // store the total here   /* Naive way */ for(c = 0; v; c++) v &= v - 1 ;     /* Parallel computing */     static const int S[] = {1, 2, 4, 8, 16}; // Magic Binary Numbers static const int B[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF}; c = v - ((v >> 1) & B[0]); c = ((c >> S[1]) & B[1]) + (c & B[1]); c = ((c >> S[2]) + c) & B[2]; c = ((c >> S[3]) + c) & B[3]; c = ((c >> S[4]) + c) & B[4];   The B array, which is in binary pattern: B[0] = 0x55555555 = 01010101 01010101 01010101 01010101 B[1] = 0x33333333 = 00110011 00110011 00110011 00110011 B[2] = 0x0F0F0F0F = 00001111 00001111 00001111 00001111 B[3] = 0x00FF00FF = 00000000 11111111 00000000 11111111 B[4] = 0x0000FFFF = 00000000 00000000 11111111 11111111 We can adjust the method for larger integer sizes by continuing with the patterns for the Binary Magic Numbers, B and S. If

Circle draw without floating point calculation

Drawing x^2 +y^2 =r^2 without floating point calculation based on   Bresenham's line algorithm. ( raster circle drawing) ------------------------------------------------------------------------------------ void CircleDraw ( int x0 , int y0 , int radius ) { int f = 1 - radius ; int ddF_x = 1 ; int ddF_y = - 2 * radius ; int x = 0 ; int y = radius ; putPixel ( x0 , y0 + radius ) ; putPixel ( x0 , y0 - radius ) ; putPixel ( x0 + radius , y0 ) ; putPixel ( x0 - radius , y0 ) ; while ( x < y ) { // ddF_x == 2 * x + 1; // ddF_y == -2 * y; // f == x*x + y*y - radius*radius + 2*x - y + 1; if ( f >= 0 ) { y --; ddF_y += 2 ; f += ddF_y ; } x ++; ddF_x += 2 ; f += ddF_x ; putPixel ( x0 + x , y0 + y ) ; putPixel ( x0 - x , y0 + y ) ; putPixel ( x0 + x , y0 - y ) ; putPixel ( x0 - x , y0 - y ) ; putPixel ( x0

UART & RS232

Image
Universal Asynchronous Transmitter Receiver LSB first.Each character is sent as a logic low start bit , a configurable number of data bits (usually 7 or 8, sometimes 5), an optional parity bit, and one or more logic high stop bits . RS232 is standard to control the signaling RTS/CTS handshaking: DTE assert Ready to send (RTS) signal to DCE ,DCE reply by asserting Clear to send (CTS) in older RS232,Still in RS-232 to RS-485 bus converter use this mechanism to check bus mastering. DTE :data terminating Equipment (e.g. desktop) DCE:data circuit terminating equipment