We are using 4.3 FreeBSD as a platform for our project. So we need to know all the knowledge about the BSD kernel and also our code will be in the Kernel space , therefore we have to build new kernel image according to respective changes that we will do in the kernel. For compilation purpose of the 4.3 FreeBSD, you should go through the following steps :                                                                

(1) Make the changes in the kernel files if you want to make ( you do it at your own risk).

(2) Then if you want to make any addition in the Configuration file of kernel, then you first give command :      cd  /usr/src/sys/i386/conf/ directory, make a copy of the configuration file /usr/src/sys/i386/conf/GENERIC in the same directory, (e.g. cp GENERIC MYKERNEL), then add the line that you want to add in this new file (e.g. for sound card driver activation , you need to add : device pcm).  

(3) Then config the kernel using command : config -g MYKERNEL, the -g option tells to add debugging information. This will create a compilation directory on the system as /usr/src/sys/compile/MYKERNEL/

(4) After config, you need to change directory by command : cd /usr/src/sys/compile/MYKERNEL/

(5) Here in this directory, you give the command : make depend, to check the dependencies among the different modules or files.

(6) Then give command : make

(7) At last stage of compilation give the command : make install, here your previous kernel image in the boot directory will be overwritten by new kernel image, kernel and older is saved as kernel.old.


                                    To setup up the kernel debugging environment is the most frustrating stuff that we have experienced in our life. For the 4.3 FreeBSD kernel debugging purpose, we have used two machines, a target machine and a development machine( with better configuration than target machine). Now you require a Null Modem Cable for serial communication between two machines. 

                                    Now we will see the changes that need to be done in the Kernel files.

(1) The following changes have to be done only on Development machine. You should first add the following line in the kernel configuration file ( /usr/src/sys/i386/conf/MYKERNEL), 

        options ddb  //To add the debugger 

        makeoptions debug = -g // To add the debugging information

(2) Then in the same file, for serial port (sio0 i.e. your COM1 port) configuration, you need to set the port flag  in line : device sio0 at isa? port IO_COM1 flags 0x10 irq 4 to 0x80

(3) Then compile kernel of the Development machine as said in the Kernel Compilation part above.

(4) Then copy the new kernel image /usr/src/sys/compile/MYKERNEL/kernel.debug from the development machine to the target machine.

(5) Now boot the target machine with the new kernel image by giving command load kernel.debug at the booting time of the machine, then give the command boot -d to enter that machine in the debugger stage. Then you will see the prompt as debugger interface started, then give the command gdb on that ddb prompt after that press s to enter in the state of actual start of debugging from development machine. 

(6) On the developement machine, run emacs, there you load gdb with the Kernel image that we want to debug with option -k for kernel debugging. Then you will get the prompt (kgdb) in the emacs window, then give the command target remote /dev/cuaa0 (for COM1) to start kernel debugging through serial line communication.

(7) If you are getting the error as : Ignoring packet error....., then you need to set your standard baud rate for the serial line of both the machine to same value (9600) using command set baudrate 9600.

                        If you face any problems in these two operations, then you can freely send your any quries to us. Send Queries.