Crear Un So

Páginas: 25 (6106 palabras) Publicado: 22 de octubre de 2012
Writing Your Own Toy OS
By
Krishnakumar R.
Raghu and Chitkala
Assembled by
Zhao Jiong
gohigh@sh163.net
2002-10-
Writing Your Own Toy OS (Part I)
By Krishnakumar R.
This article is a hands-on tutorial for building a small boot sector. The first
section provides the theory behind what happens at the time the computer is
switched on. It also explains our plan. The second section tellsall the things
you should have on hand before proceeding further, and the third section deals
with the programs. Our little startup program won't actually boot Linux, but
it will display something on the screen.
1. Background
1.1 The Fancy Dress
The microprocessor controls the computer. At startup, every microprocessor is
just another 8086. Even though you may have a brand new Pentium, itwill only
have the capabilities of an 8086. From this point, we can use some software and
switch processor to the infamous protected mode . Only then can we utilize the
processor's full power.
1.2 Our Role
Initially, control is in the hands of the BIOS. This is nothing but a collection
of programs that are stored in ROM. BIOS performs the POST (Power On Self Test).
This checks the integrity ofthe computer (whether the peripherals are working
properly, whether the keyboard is connected, etc.). This is when you hear those
beeps from the computer. If everything is okay, BIOS selects a boot device. It
copies the first sector (boot sector) from the device, to address location 0x7C00.
The control is then transferred to this location. The boot device may be a floppy
disk, CD-ROM, harddisk or some device of your choice. Here we will take the
boot device to be a floppy disk. If we had written some code into the boot sector
of the floppy, our code would be executed now. Our role is clear: just write
some programs to the boot sector of the floppy.
1.3 The Plan
First write a small program in 8086 assembly (don't be frightened; I will teach
you how to write it), and copy it tothe boot sector of the floppy. To copy,
we will code a C program. Boot the computer with that floppy, and then enjoy.
2. Things You Should Have
as86
This is an assembler. The assembly code we write is converted to an object
file by this tool.
ld86
This is the linker. The object code generated by as86 is converted to
actual machine language code by this tool. Machine language will be in
aform that 8086 understands.
gcc
The C compiler. For now we need to write a C program to transfer our OS
to the floppy.
A free floppy
A floppy will be used to store our operating system. This also is our boot
device.
Good Old Linux box
You know what this is for.
as86 and ld86 will be in most of the standard distributions. If not, you can
always get them from the sitehttp://www.cix.co.uk/~mayday/. Both of them are
included in single package, bin86. Good documentation is available at
www.linux.org/docs/ldp/howto/Assembly-HOWTO/as86.html.
3. 1, 2, 3, Start!
3.1 The Boot Sector
Grab your favourite editor and type in these few lines.
entry start.
start:
mov ax,#0xb800
mov es,ax
seg es
mov [0],#0x41
seg es
mov [1],#0x1f
loop1: jmp loop1
This is an assembly language thatas86 will understand. The first statement
specifies the entry point where the control should enter the program. We are
stating that control should initially go to label start. The 2nd line depicts
the location of the label start (don't forget to put ":" after the start). The
first statement that will be executed in this program is the statement just after
start.
0xb800 is the address of thevideo memory. The # is for representing an immediate
value. After the execution of
mov ax,#0xb800
register ax will contain the value 0xb800, that is, the address of the video
memory. Now we move this value to the es register. es stands for the extra segment
register. Remember that 8086 has a segmented architecture. It has segments like
code segments, data segments, extra segments,...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • mi que so
  • Eso so
  • El So
  • So Suse
  • So
  • la so
  • Que so
  • no so se

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS