Documentation of the protected mode debugger

Introduction
Capabilities and Salient Features
System Requirements
Starting up the debugger
Usage guidelines and a brief tutorial
Design and Code overview
Compiling it from the source

Introduction

This is a bootable protected mode debugger for intel 386 class of processors, meaning that it can boot off a floppy into a protected mode environment and provide the user with a setup where he can debug his own code and also learn about the machine. It was made as a part of CSD course project .It can also be used as an educational demo for an operating system , since most of it is designed as a mini kernel.

Features and Capabilities

Here are some of the salient features and capabilities it offers :


System Requirements

The debugger shall work off a standard PC and doesn't need a color monitor.By a standard PC , I mean , a system having an intel 386 or higher processor ,a PS/2 keyboard,a 1.44 inch floppy drive.
It was tested on Pentium 4,on Bochs and on a real PC.

Starting up the debugger

Since the debugger is deisgned to boot from a floppy , the first thing you have to do is to get the provided disk image on the downloads page. And then burn it onto a floppy , since this is a disk image unlike an ordinary file, you need to transfer to a floppy like this :

So far , so good, now you need to boot up your machine with this floppy you just created.The way to do this is to restart your machine.When the computer boots up , it will ask you to press F2 or Del key to enter setup , do so . Now in setup (this depends on which bios you have) choose the floppy to be the highest priority boot device.The PC will boot up again, this time from a floppy.
The debugger prompt shall then come up on the screen: (for screenshots ,click here).

Usage guidelines and a brief tutorial

For sake of brevity this section can be found as a new page here

Design and Implementation overview



Development Environment and Languages Used
Module Description
Details on the debugger implementation

Development Environment and Languages Used

The code was developed on an intel 386 linux PC . Linux is a free OS , any one can download it off the web and use it . What's more it can run on the barest of hardware. Hence I chose linux over developing in dos and windows. (which require extensive support).
I have used C and assembly to code this. Assembly language is used primarily in the boot sector code ,interrupt handlers ,accessing the i386 structures like GDT , LDT etc. However a large part of the debugger is written in C.Because of the following reasons :
I have used nasm( a 32 bit freely available assembler ) and gcc (The infamous gnu C compiler ) to compile the code . Also sed is used to find some addresses of symbols in the kernel. These are standard tools that can be found on any linux distribution , and are downloadable from the net. To test the code , I have used a real PC and and an IA32 emulator called bochs.
All the tools used are public domain tools as they are freely available to anyone.More information abouthow to install them (if you don't already have them) and the forms they are available in (tarball archieve, rpm etc ) can be found from their respective home pages.

Concepts involved

To undersand the code , you need to understand a bit of the following :

Module Description



The debugger is chiefly composed of three main modules , namely
  1. Boot Up Module
  2. Kernel Proper
  3. Device Drivers
  4. Debugger Module
.
Their details are given below .

Bootup Module details


This resides in boot subdirectory. The bootup module composes of the following files :

Kernel Proper module details


This resides in kernel subdirectory. The kernel proper is incharge of initization and providing useful routines to the rest of the system. The following files are there in this modules :

Device drivers module


This is contained in the files like keyboard.cxx, floppy.cxx,timer.cxx in the kernel subdirectory. The int.s file in the same directory has the interrupt routines for floppy,timer,keyboard,debugger . All the interrupt routines do the following : These interrupts are initialized in initIDT() in idt.cxx.Note that the debugger interrupt is explained below.

Details on the debugger implementation


It consists of the debugger.c file in the kernel subdirectory and the int 1 handler in int.s.The debugger essentially consists of three peices of code , Launching of a user program :
When the user does a load program , the following things happen : Handling of a debugger interrupt in detail :
The doDebugerRoutine simply does a task switch to the saved kernel tss, this way the kernel resumes exactly where it left off , and later when the program eventually has to be run again , we just do task switch to the program TSS . Hence the program starts off by returning from the DoDebuggerInt routine , and the proceeds to complete the interrupt 1 . Note that the earlier saved context saved on the context may have been changed before it does an iret. (this is described above).

Compiling it from the source

Currently the source can be compiled only in linux , although since I have used pure ansi C and intel standard asm , it should theoretically compile even in windows.(Yes I am a linux freak!).
The entire source code can be found at the downloads page.Please take the latest version if you want the least no. of bugs and the maximum features. The source is in form of tar.gz archieve (tarball). To compile do the following:. This will create the floppy image called prodebug.img in the prodebug directory. Note that you need nasm and gcc to compile the sources.Burn it onto the disk as detailed above