Building your own operating system
Introduction
If you know how an operating system works, it will help you a lot in programming, especially for system programs like device drivers; even for
non-system-programming, it can help a lot. And also, I'm sure every one would like to have their own operating system.
You would also learn from this article how to read and write raw sectors from a disk.
Background
In this article, I would explain the first part of building an operating system.
Here is what happens when you start your computer:
1. The BIOS (Basic Input Output System - this is a program that comes with any mother board and it is placed in a chip on the mother board) checks
all the computer components to make sure that they are all working.
2. If all the components are working, the BIOS starts searching for a drive that might have an operating system. (The BIOS can look in hard drives,
floppy drives, CD-ROM drives etc. The order the BIOS checks can be set it in the BIOS setup program. To get to the BIOS setup, right when the
computer turns on, press the DELETE key until you see the BIOS setup program; in some computers, it can be a different button than DELETE, so look in
your mother board specification to find how to get to the BIOS setup program. And also look up (if you don't now how to do it) how to change the
search search of BIOS while looking for an operating system.)
3. The BIOS checks the first drive to see if he has a valid BOOT sector. (A disk is divided into little regions that are named sectors. The BOOT
sector size is 512 bytes in most drives.) If the drive has a valid BOOT sector, the BIOS loads that sector in to the memory at address 0:7c00
(=31,744) and gives control to that area of the memory.
4. Now this little program that was loaded from the BOOT sector continues to load the operating system, and after the operating system is loaded, it
initializes the operating system and gives the control to the operating system.
Making a bootable disk
The steps would be like this:
1. Take a floppy diskette that you don't need.
2. Use the program that comes with this article, BOOTSectorUtility.exe, to copy the file BOOT.bin to the floppy diskette BOOT sector.
3. Make sure that your BIOS is set to BOOT from the floppy drive first, so that our operating system would be loaded.
4. Restart your computer (make sure that the floppy diskette is in the drive), and watch what our BOOT sector does.
With BOOTSectorUtility.exe, you can also search your regular operating system, by saving the boot sector of the drive of your operating system to a
file.
And to read that file, start the command line and type Debug <file path> (if you have a Microsoft operating system).
The Debug command starts a 16 bit debugger (any boot sector is in 16 bit code, because when the computer starts, it is in 16 bit mode, and only after
the boot sector is run, can it change the CPU to 32 bit mode or 64 bit mode). Press u <Enter> (u = unassemble) to unassemble the file. Figure 1
shows an example.
Figure 1 Unassembeling 16 bit code.
Reading raw bytes from a drive
You can read raw sectors from a drive like this:
Collapse
-
-
//
-
-
// Reading/writing raw sectors.
-
-
//
-
-
-
//pBuffer has to be at least 512 bytes wide.
-
-
BOOL ReadSector(char chDriveName,char *pBuffer,DWORD nSector)
-
{
-
-
char Buffer[256];
-
HANDLE hDevice;
-
DWORD dwBytesReaden;
-
-
//Init the drive name (as a Driver name).
-
-
-
hDevice =
-
CreateFile(Buffer, // drive to open.
-
-
GENERIC_READ,
-
FILE_SHARE_READ | // share mode.
-
-
FILE_SHARE_WRITE,
-
NULL, // default security attributes.
-
-
OPEN_EXISTING, // disposition.
-
-
0, // file attributes.
-
-
NULL); //
-
-
-
if(hDrive==INVALID_HANDLE_VALUE)//if Error Openning a drive.
-
-
{
-
return FALSE;
-
}
-
-
//Move the read pointer to the right sector.
-
-
if(SetFilePointer(hDevice,
-
nSector*512,
-
NULL,
-
FILE_BEGIN)==0xFFFFFFFF)
-
return FALSE;
-
-
//Read the Sector.
-
-
ReadFile(hDevice,
-
pBuffer,
-
512,
-
&dwBytesReaden,
-
0);
-
-
//if Error reading the sector.
-
-
if(dwBytesReaden!=512)
-
return FALSE;
-
-
return TRUE;
-
}
-
Making a BOOT program
Now, I will explain the basics of a boot program (to understand this, you need to be familiar with Assembler and Interrupts and Interrupts vector
table).
[Interrupts vector table = From Address 0 -> 1,024 holds 256 structures (4 bytes in size) that holds an address in the form: CS:IP = xxxx:xxxx. So
you have addresses from INT 1 -> INT 256. Each interrupt has an index into that table. This table is used like this: if you, for example, use the
instruction INT 10h, the CPU checks in index 10h in the interrupt table were the address of the routine is that handles INT 10h, and the CPU jumps to
that address to execute it].
Now, I will explain how to print a string, read sectors, and wait for a key press using only the BIOS.
To print a string, I use the INT 10h function 0Ah (AH = 0Ah). To move the cursor, I use the INT 10h function 2h (AH = 2h). To read sectors, I use the
INT 13h function 2h (AH = 2h). To wait for a key stroke, use the INT 16h function 0h (AH = 0h).
I used TASM v3.1 and TLINK to make my boot sector, but you can use any x86 16 bit assembler compiler.
(If you can't get a copy of TASM and TLINK, you can send me an e-mail and if it is legal, I would send you a copy of them).
(TASM and TLINK v3.1 were released in 1992 by Borland International).
Now I would explain the steps the BOOT program does.
1. Make a stack frame (if not you don't have any stack).
2. Set the DS (data segment) so you can access the data.
3. In my boot sector, I added this: (Display a message to the user, Wait for a key stroke, Continue).
4. Set up the Disk Parameter Block (the Disk Parameter Block is a structure that holds information about the drive, like how much sectors it has
etc., the drive controller uses it for knowing how to read the disk in the drive).
5. To set the Disk Parameter Block, get its address (its address is pointed by INT 1Eh (in the memory, this is 1E x 4 bytes = 78h = 30 x 4 bytes =
120).
This is an example of how to initialize the Disk Parameter Block for a 3.5 inch (1.44 MB) floppy Disk.
-
-
-
StepRateAndHeadUnloadTime db 0DFh
-
HeadLoadTimeAndDMAModeFlag db 2h
-
DelayForMotorTurnOff db 25h
-
BytesPerSector db 2h
-
SectorsPerTrack db 12h
-
IntersectorGapLength db 1bh
-
DataLength db 0FFh
-
IntersectorGapLengthDuringFormat db 54h
-
FormatByteValue db 0F6h
-
HeadSettlingTime db 0Fh
-
DelayUntilMotorAtNormalSpeed db 8h
-
-
DisketteSectorAddress(as LBA)OfTheDataArea db 0
-
CylinderNumberToReadFrom db 0
-
SectorNumberToReadFrom db 0
-
DisketteSectorAddress (as LBA) OfTheRootDirectory db 0
-
6. And set the address that INT 1E points at to the address of the Disk Parameter Block you set up.
7. Reset the drive (by using the INT 13h function 0).
8. Start reading the diskette by using the INT 13h function 2h.
9. Give control to the loaded operating system (this is done by inserting in the code the op code of a jump to were you loaded the operating system.
Let's say you loaded the operating system 512 bytes from were the BIOS loaded the BOOT sector (0:7c00h).
-
-
db 0E9h ; FAR JMP op code.
-
-
db 512 ; 512 bytes
-
or you can use another way: call some address, and there, change the return address in the stack to were you want the jump to,
like this:
-
-
call GiveControlToOS
-
-
GiveControlToOS:
-
Pop ax
-
Pop ax
-
Mov ax,CodeSegement ;Push the new CS to return.
-
-
Push ax
-
mov ax,InstructionPointer ;Push the new IP to return.
-
-
Push ax
-
-
ret ;Return to the modified address.
-
10. In the end of the boot sector the bytes would be 0x55h 0x0AAh. If the boot sector doesn't have this value, the BIOS
would not load that boot sector.
After this, the BOOT sector finishes its job and the operating system starts running.
You can download the files I used for my boot sector here, the files are BOOT.asm, BOOT.bin (this is the sector itself).
The BOOT sector program
Collapse
-
-
.MODEL SMALL
-
-
.CODE
-
-
ORG 7c00h ;Because BIOS loades the OS at
-
-
; address 0:7C00h so ORG 7C00h
-
-
; makes that the refrence to date
-
-
; are with the right offset (7c00h).
-
-
-
ProgramStart:
-
-
-
; CS = 0 / IP = 7C00h // SS = ? / SP = ?
-
-
; You are now at address 7c00.
-
-
jmp start ;Here we start the, BIOS gave us now the control.
-
-
-
-
-
;///////////////////////////////////////////
-
-
;//Here goes all the data of the program.
-
-
;///////////////////////////////////////////
-
-
-
xCursor db 0
-
yCursor db 0
-
-
-
nSector db 0
-
nTrack db 0
-
nSide db 0
-
nDrive db 0
-
-
nTrays db 0
-
-
'Are You Ready to start Loading the OS...',0
-
szReady db
-
'Error Reading Drive, Press any Key to reboot...',0
-
szErrorReadingDrive db
-
;//Done Reading a track.
-
-
szPlaceMarker db '~~~~',0
-
szDone db 'Done',0
-
-
pOS dw 7E00h
-
;//Points to were to download the Operating System.
-
-
-
;//Disk Paremeter Table.
-
-
StepRateAndHeadUnloadTime db 0DFh
-
HeadLoadTimeAndDMAModeFlag db 2h
-
DelayForMotorTurnOff db 25h
-
;// (1 = 256) //(2 = 512 bytes)
-
-
BytesPerSector db 2h
-
;// 18 sectors in a track.
-
-
SectorsPerTrack db 18
-
IntersectorGapLength db 1Bh
-
DataLength db 0FFh
-
IntersectorGapLengthDuringFormat db 54h
-
FormatByteValue db 0F6h
-
HeadSettlingTime db 0Fh
-
DelayUntilMotorAtNormalSpeed db 8h
-
-
DisketteSectorAddress_as_LBA_OfTheDataArea db 0
-
CylinderNumberToReadFrom db 0
-
SectorNumberToReadFrom db 0
-
DisketteSectorAddress_as_LBA_OfTheRootDirectory db 0
-
-
;/////////////////////////////////
-
-
;//Here the program starts.
-
-
;/////////////////////////////////
-
-
-
-
Start:
-
-
CLI ;Clear Interupt Flag so while setting
-
-
;up the stack any intrupt would not be fired.
-
-
-
mov AX,7B0h ;lets have the stack start at 7c00h-256 = 7B00h
-
-
mov SS,ax ;SS:SP = 7B0h:256 = 7B00h:256
-
-
mov SP,256 ;Lets make the stack 256 bytes.
-
-
-
Mov ax,CS ;Set the data segment = CS = 0
-
-
mov DS,ax
-
-
XOR AX,AX ;Makes AX=0.
-
-
MOV ES,AX ;Make ES=0
-
-
-
-
STI ;Set Back the Interupt Flag after
-
-
;we finished setting a stack fram.
-
-
-
Call ClearScreen ;ClearScreen()
-
-
LEA AX,szReady ;Get Address of szReady.
-
-
CALL PrintMessage ;Call PrintfMessage()
-
-
CALL GetKey ;Call GetKey()
-
-
-
CALL SetNewDisketteParameterTable
-
;SetNewDisketteParameterTable()
-
-
-
CALL DownloadOS
-
CALL GetKey ;Call GetKey()
-
-
CALL FAR PTR GiveControlToOS ;Give Control To OS.
-
-
-
ret
-
-
;/////////////////////////////////////
-
-
;//Prints a message to the screen.
-
-
;/////////////////////////////////////
-
-
PrintMessage PROC
-
mov DI,AX ;AX holds the address of the string to Display.
-
-
Mov xCursor,1 ;Column.
-
-
-
ContinuPrinting:
-
-
-
JE EndPrintingMessage ;if you gat to the end of the string return.
-
-
-
mov AH,2 ;Move Cursor
-
-
mov DH,yCursor ;row.
-
-
mov DL,xCursor ;column.
-
-
mov BH,0 ;page number.
-
-
INT 10h
-
INC xCursor
-
-
mov AH,0Ah ;Display Character Function.
-
-
mov AL,[DI] ;character to display.
-
-
mov BH,0 ;page number.
-
-
mov CX,1 ;number of times to write character
-
-
INT 10h
-
-
-
-
INC DI ;Go to next character.
-
-
-
-
-
EndPrintingMessage:
-
-
;be printed in the second line.
-
-
-
cmp yCursor,25
-
JNE dontMoveCorsurToBegin
-
Mov yCursor,0
-
-
dontMoveCorsurToBegin:
-
ret
-
-
-
PrintMessage EndP
-
;//////////////////////////////////////
-
-
;//Watis for the user to press a key.
-
-
;//////////////////////////////////////
-
-
GetKey PROC
-
-
mov ah,0
-
int 16h ;Wait for a key press.
-
-
Ret
-
-
GetKey EndP
-
;///////////////////////////////////////////
-
-
;//Gives Control To Second Part Loader.
-
-
;///////////////////////////////////////////
-
-
GiveControlToOS PROC
-
-
LEA AX,szDone
-
Call PrintMessage
-
CALL GetKey
-
-
db 0e9h ;Far JMP op code.
-
-
dw 512 ;JMP 512 bytes ahead.
-
-
-
; POP AX ;//Another why to make
-
-
;the CPU jump to a new place.
-
-
; POP AX
-
-
; Push 7E0h ;Push New CS address.
-
-
; Push 0 ;Push New IP address.
-
-
;The address that comes out is 7E00:0000.
-
-
;(512 bytes Higher from were BIOS Put us.)
-
-
; ret
-
-
-
-
GiveControlToOS EndP
-
;///////////////////////////////////
-
-
;//Clear Screen.
-
-
;///////////////////////////////////
-
-
ClearScreen PROC
-
-
mov ax,0600h ;//Scroll All Screen UP to Clear Screen.
-
-
mov bh,07
-
mov cx,0
-
mov dx,184fh
-
int 10h
-
-
Mov xCursor,0 ;//Set Corsur Position So next
-
-
//write would start in
-
//the beginning of screen.
-
Mov yCursor,0
-
-
Ret
-
-
ClearScreen EndP
-
;/////////////////////////////////
-
-
;//PrintPlaceMarker.
-
-
;/////////////////////////////////
-
-
PrintPlaceMarker PROC
-
-
-
LEA AX,szPlaceMarker
-
CALL PrintMessage ;Call PrintfMessage()
-
-
CALL GetKey ;Call GetKey()
-
-
ret
-
-
PrintPlaceMarker EndP
-
;/////////////////////////////////////////
-
-
;//Set New Disk Parameter Table
-
-
;/////////////////////////////////////////
-
-
SetNewDisketteParameterTable PROC
-
-
LEA DX,StepRateAndHeadUnloadTime
-
;//Get the address of the Disk Parameters Block.
-
-
-
;//Int 1E (that is in address 0:78h)
-
-
;//holds the address of the disk parametrs
-
-
;//block, so now change it to
-
-
;//our parametr black.
-
-
;//DX holds the address of our Parameters block.
-
-
MOV WORD PTR CS:[0078h],DX
-
MOV WORD PTR CS:[007Ah],0000
-
-
;Reset Drive To Update the DisketteParameterTable.
-
-
MOV AH,0
-
INT 13H
-
-
ret
-
-
SetNewDisketteParameterTable EndP
-
;///////////////////////////////////
-
-
;//DownloadOS
-
-
;///////////////////////////////////
-
-
DownloadOS PROC
-
mov nDrive,0
-
mov nSide,0
-
mov nTrack,0
-
mov nSector,1
-
-
ContinueDownload:
-
-
INC nSector ;Read Next Sector.
-
-
cmp nSector,19 ;Did we get to end of track.
-
-
JNE StayInTrack
-
CALL PrintPlaceMarker ;Print now '~~~~' so the user would
-
-
;now that we finished reding a track
-
-
-
mov nSector,1 ;And Read Next Sector.
-
-
CMP nTrack,5 ;Read 5 Tracks (Modify this value
-
-
;to how much Tracks you want to read).
-
-
JE EndDownloadingOS
-
-
StayInTrack:
-
-
;ReadSector();
-
-
Call ReadSector
-
-
-
JMP ContinueDownload
-
;If diden't yet finish Loading OS.
-
-
-
EndDownloadingOS:
-
-
ret
-
-
DownloadOS EndP
-
;////////////////////////////////////////
-
-
;//Read Sector.
-
-
;////////////////////////////////////////
-
-
ReadSector PROC
-
-
mov nTrays,0
-
-
TryAgain:
-
-
mov AH,2 ;//Read Function.
-
-
mov AL,1 ;//1 Sector.
-
-
mov CH,nTrack
-
mov CL,nSector ;//Remember: Sectors start with 1, not 0.
-
-
mov DH,nSide
-
mov DL,nDrive
-
Mov BX,pOS ;//ES:BX points to the address
-
-
;to were to store the sector.
-
-
INT 13h
-
-
-
CMP AH,0 ;Int 13 return Code is in AH.
-
-
JE EndReadSector ;if 'Sucsess' (AH = 0) End function.
-
-
-
mov AH,0 ;Else Reset Drive . And Try Again...
-
-
INT 13h
-
cmp nTrays,3 ;Chack if you tryed reading
-
-
;more then 3 times.
-
-
-
JE DisplayError ; if tryed 3 Times Display Error.
-
-
-
INC nTrays
-
-
jmp TryAgain ;Try Reading again.
-
-
-
DisplayError:
-
LEA AX,szErrorReadingDrive
-
Call PrintMessage
-
Call GetKey
-
mov AH,0 ;Reboot Computer.
-
-
INT 19h
-
-
-
EndReadSector:
-
;ADD WORD PTR pOS,512 ;//Move the pointer
-
-
;(ES:BX = ES:pOS = 0:pOS) 512 bytes.
-
-
;//Here you set the varible
-
-
;pOS (pOS points to were BIOS
-
-
;//Would load the Next Sector).
-
-
Ret
-
-
ReadSector EndP
-
;////////////////////////////////////
-
-
;//
-
-
;////////////////////////////////////
-
-
END ProgramStart
-
-
Points of interest
It took some time until I got a running boot sector. I would list a couple of bugs I had in the beginning while writing my boot sector.
1. I didn't set up a right stack frame.
2. I didn't modify the Disk Parameter Block.
3. I loaded the operating system to areas that are used by BIOS routines (and even to the Interpret table).
4. In the end of the boot sector, it must have the bytes 0x55h 0x0AAh (this is a signature that it is a valid bootable sector).
(For using BOOTSectorUtility.exe, you would need the .NET 2.0 Framework installed on your computer. To download the .NET 2.0 Framework, click here.) The building files are located in the download section.
Courtesy of
S Keller from codeproject
Occupation: Systems Engineer
Location: United States United Stateshttp://www.codeproject.com/KB/system/MakingOS.aspx
Heres a couple links for the project:
Project Files 4.51kb
http://www.codeproject.com/KB/system/MakingOS/ProjectFiles.zip
Boot Sector Utility 41.4kbhttp://www.codeproject.com/KB/system/MakingOS/BOOTSectorUtility.zip
Making an Operating System 2 -
Figure 1 - Running other Operating Systems in your current OS with a PC Emulator.
Introduction
I think that one of the most important ways of being a real professional programmer is
to design and build an Operating System. It is not enough to read how an OS works,
you have to build one with your own hands.
Now, I would list what you will gain from learning how to develop an Operating System:
1. A programmer is like an astronaut in space, the more he knows about the spaceship
he is flying, and how to fix it in case of a problem, it is more likely that he would return
safely back to earth. In the case of a programmer, the more he knows about the PC
and the Operating system, his programs would be more reliable, stronger, and faster,
and with less bugs.
2. Learning the executables file format (helps a lot).
3. Learning the Assembler (Every one would admit, that knowing assembler is a wonde-
rful thing).
4. Knowing what goes on behind the scenes.
5. Learning the hardware of the Computer (CPU architecture, PCI, SATA, cash, Netwo-
rk card, ATA/ATAPI, etc.).
6. Learning a lot of new tricks that can help you a lot in other kinds of programming.
7. Learning all this would improve the programs you write a lot (even for regular Win32
user interface programming).
If you are not yet convinced, try it out and you would see how much fun it is to program Operating Systems.
This article is the second part of my previous article.
In this article, I would:
1. Show you how to test and debug your Operating System in a very easy way.
2. Build and test your own mother board.
3. When resetting the drive with INT 13h, move the drive number to the register DL.
How to debug and test Operating Systems (the best and easiest way)
Figure 2 - Bochs in work (Bochs is running my Boot sector from my other article).
For debugging and testing an OS you must have an x86 emulator, we would use Bochs.
Bochs is a portable open source x86 and AMD64 PCs emulator mostly written in C++ a-
nd distributed under the GNU Lesser General Public License. It supports emulation of processor(s) (including protected mode), memory, disks, display, Ethernet,
BIOS and common hardware peripherals of PCs.
Many guest operating systems can be run using the emulator, including DOS, several versions of Windows, BSDs, and Linux. Bochs can run on many host operating
systems, including Windows, Linux, Mac OS X and the Xbox.
Bochs is mostly used for operating system development (when an emulated operating system crashes, it does not crash the host operating system, so the emulated
OS can be debugged) and to run other guest operating systems inside already running host operating systems. Some people use it to run old computer games inside
their non-compatible computers.
To use Bochs, follow these steps:
1. Download Bochs from here (it is free).
2. Install Bochs.
3. Open the directory were you installed Bochs.
4. Look for bochsdbg.exe (the emulator + debugger), and bochs.exe (emulator), and bximage.exe (disk image creator).
5. Start bximage.exe and follow the instructions to create a virtual 1.44 MB (1,474,560 by-
tes) floppy disk image.
6. Create a file name bochsrc.txt (this file is the initialization file for the emulator) and enter in this string: floppya: image="MyOS.img",
status=inserted. You can replace the file name MyOS.img with any file name you want (it must be the file that bximage.exe created (or any file of the right
size)).
7. Now, you need some kind of binaries to replace the image (you can take the BOOT.bin file from my first article and replace it in the first 512 bytes of the
image you created.
8. Now, run bochs.exe, and it would open two windows: a console window (for debugging) and a GUI window (this window simulates a screen of the emulated OS).
9. You can run your image with bochsdbg.exe for debugging.
10. You can create floppies' images, hard disk images, and CD-ROM (*.iso) images, and replace on them any Operating System you want (like WinXP etc.) and
debug them.
11. Read the documentation that comes with Bochs and learn how to set break points (lb 0x7c00), dump memory (x /100bx 0x7c00), single stepping (s 1), read
registers (r), con-
tinue execution (c), dump all CPU registers (dump_cpu) etc.
12. Enjoy!
Figure 3 - Bochs folder, and a simple configuration file.
A more advanced look at Bochs
Figure 4 - a typical mother-board.
All this you can build with Bochs by only writing a simple configuration to a text file. This is why Bochs is so wonderful:
You can configure and build a whole PC, all you need to do is write the PC configuration to some text file (for example, bochsrc.txt) and place it in the Bochs
folder. Here is an example of an advanced configuration file:
-
-
#========================================================
-
# ROM-IMAGE:
-
#========================================================
-
romimage: file=$BXSHARE/BIOS-bochs-latest, address=0xf0000
-
#========================================================
-
# CPU:
-
#========================================================
-
#========================================================
-
# Amount of RAM in MB
-
#========================================================
-
megs: 32
-
#========================================================
-
# VGA ROM IMAGE
-
#========================================================
-
vgaromimage: file= $BXSHARE/VGABIOS-lgpl-latest
-
#========================================================
-
# VGA:
-
#========================================================
-
vga: extension= vbe
-
#========================================================
-
# FLOPPY:
-
#========================================================
-
floppya: 1_44= "MyImg.img" , status=inserted
-
#========================================================
-
# ATA0, ATA1, ATA2, ATA3 (Set up Hard disk and CD-ROM IRQ's-
-
and I/O address)
-
#========================================================
-
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
-
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
-
ata2: enabled=0, ioaddr1=0x1e8, ioaddr2=0x3e0, irq=11
-
ata3: enabled=0, ioaddr1=0x168, ioaddr2=0x360, irq=9
-
-
#========================================================
-
# ATA[0-3]-MASTER, ATA[0-3]-SLAVE
-
#========================================================
-
ata0-master: type=disk, path="MyOS\c.img" , mode=flat,
-
cylinders=20, heads=16, spt=63, translation=none
-
ata1-master: type=disk, path="MyOS\d.img" , mode=flat,
-
cylinders=2, heads=16, spt=63, translation=none
-
ata0-slave: type=cdrom, path=MyOS\cdrom.iso, status=inserted
-
ata1-slave: type=cdrom, path=MyOS\E.iso, status=inserted
-
#========================================================
-
# BOOT from:
-
#========================================================
-
boot: disk
-
#========================================================
-
# COM1, COM2, COM3, COM4:
-
#========================================================
-
Com1: enabled=1, dev="COM1"
-
#========================================================
-
# Parallel ports
-
#========================================================
-
#========================================================
-
# SB16:
-
# This defines the SB16 sound emulation.
-
#========================================================
-
-
sb16: midimode=1, midi=/dev/midi00, wavemode=1, wave=/dev/dsp,
-
-
#========================================================
-
# VGA_UPDATE_INTERVAL:
-
#========================================================
-
vga_update_interval: 300000
-
-
#========================================================
-
# MOUSE: support:
-
#========================================================
-
mouse: enabled=0
-
#========================================================
-
# ne2k: NE2000 compatible ethernet adapter
-
# (Now you can connect to the Internet):
-
#========================================================
-
ne2k: ioaddr=0x240, irq=9, mac=b0:c4:20:00:00:01,
-
ethmod=vnet, ethdev="c:/temp"
-
-
#========================================================
-
# I440FXSUPPORT: PCI-Controller:
-
#========================================================
-
i440fxsupport: enabled=1
-
-
#========================================================
-
# USB1:
-
#========================================================
-
usb1: enabled=1
-
-
#========================================================
-
# CMOSIMAGE:
-
#========================================================
-
#cmosimage: file=cmos.img, rtc_init=time0
-
-
#-------------------------
-
# PCI host device mapping (Inserting a PCI device).
-
#-------------------------
-
pcidev: vendor=0x1234, device=0x5678
-
-
#========================================================
-
# GDBSTUB: (GDB debugger)
-
#========================================================
-
#gdbstub: enabled=0, port=1234, text_base=0, data_base=0, bss_base=0
-
#========================================================
-
# IPS: (Instruction Per seconds)
-
#========================================================
-
ips: 10000000
-
-
#========================================================
-
# FOR MORE INFORMATION !!!!!
-
#========================================================
-
#For more information see the Bches Documentation
-
#and "bochsrc-sample.txt" (this is in the Bochs directory).
-
Have you ever known how easy it is to build a PC, you only have to write a couple of lines and run Bochs, and you have your own PC.
Here are some very useful debug commands:
1. c (continue executing).
2. s [count] (execute count instructions, default is 1) - for example, s.
3. Ctrl+C (stop execution, and return to command line prompt).
4. lb addr (set a linear address instruction breakpoint) - for example, lb 0x7C00.
5. d n (delete a break point) - for example, d 1.
6. x /nuf addr (dump memory of a physical address) - for example, X /100bx 0x7C00 (dump 100 bytes (b) display in HEX format (X) at address 0x7c00).
7. r (list of CPU registers and their contents).
8. info tab (show paging address translation).
9. dump_cpu (dump complete CPU state).
10. set reg = expr (change a CPU register to the value of an expression) - for example, set esi = 2*eax+ebx.
For more information, check the documentation that comes with Bochs.
Conclusion
Now I am sure you feel like a PC engineer working for some mother-board company. This configuration is a very wonderful thing, because you can build any kind
of PC you want, and test your OS on it.
Another very good thing in Bochs is that it comes with source code, so it is like having all the hardware specification from the OS developer point of view.
Also, it can help a lot for debugging your OS, because from the source code, you can know exactly what is wrong.
This is a list of Terms that may be new for you:
1. ATA (the protocol for reading and writing to hard disks).
2. ATAPI (the protocol for reading and writing to CD-ROMs).
3. CMOS (a RAM chip on your mother board that is powered by a battery, this RAM saves all your PC settings that you see when entering the BIOS setup (what
shows up when you press the Delete key when you start you computer) - this is really called CMOS setup).
4. ROM Image (Read Only memory that holds your BIOS and permanent hardware settings).
5. IPS (Instruction Per Second that your CPU can execute).
6. VGA (Video Graphics Adapter).
7. VGA update interval
8. GDB (a debugger for debugging other Operating Systems from a different computer).
9. PCI (Peripheral Component Interconnect - this is a standard that describes how to connect the peripheral components of a system together in a structured and
controlled way).
Points of Interest
You can get the source code of Bochs (also for compiling with MSVC 6). I needed to do some hacking to get Bochs to compile with MSVC 6 and MSVS 2005. If you
have compiled it, how did it compile for you? And what happened if you changed some of the #define identifier values, for example, #define BX_DEBUGGER 1 (in
Config.h): did you successfully compile it?
Another good PC emulator (but it can't debug the OS) is Microsoft PC Emulator (you can download it from the Microsoft web site).
If you have any questions or you need help, feel comfortable to send me an e-mail. If you have a subject or a point you want me to write about, please note it
in the forums (this would help a lot for future articles).
Here you can download the new source code to my Boot sector program from my first article.
These are the fixes I made in the BOOT Sector:
1. When it finishes reading a track, it switches to the other side.
2. I added the BIOS Parameter Block to make the diskette (or the hard disk) a valid FAT diskette.
3. When resetting the drive with INT 13h, move the drive number to the register DL.
I would continue writing if I see this article interests people.
The next in this series of articles that I would write would go in to the details of developing your own OS, for example, details like OS design, programming
the file system, EXE format, setting up for Protected mode, switching to Protected mode, handling interrupts, programming the PIC, writing an ATA/ATAPI driver,
writing a floppy driver, DMA, using BIOS32 (a special BIOS interface for Protected mode), writing your kernel with MSVC, driver for graphics display, stage 1
and 2 of loading the OS etc.
These are the tools you would need:
1. A good Hex editor (I am using Hex workshop (but it is not free)). I'm sure you would find a free Hex editor very easily in the Internet.
2. MASM (v7-v8) (it is very easy to find a site that you can download it from).
3. MSVC 6 (or v7-v8) (Microsoft C++ compiler).
4. OllyDbg (a good Win32 debugger).
5. Bochs.
6. Tasm (Borland turbo assembler, (for 16 bit OS loader)) - if you have trouble finding one, send me an e-mail.
7. TC (Borland Turbo C++, (for 16 bit OS loader)) - if you have trouble finding one, send me an e-mail.
Links that would help you a lot
1. OS-Dev
-
this site is the best resource for OS - development, I ever saw.http://www.osdev.org/osfaq2/
2. These are the forums of
-
http://www.osdev.org/phpBB2/
OS-Dev.
3. The source code of the Linux Kernel can help you a lot, another link to the Linux source code.
4. Help and information on Linux Kernel
-
http://www.linuxhq.com/lkprogram.html
can also help a lot.
-
http://www.kernel.org/
About the Author
S Keller -
Occupation Software Engineer living in the United States



My tech info site

