A simple BIOS program written by the assembler (based on ubuntu and Bochs2.2.1)

Source: Internet
Author: User
A simple BIOS Program (based on ubuntu and Bochs2.2.1) written by the assembler-Linux general technology-Linux programming and kernel information. The following is a detailed description.

See my blog http://blog.sina.com.cn/jhx0301 for detailed steps
Today, I suddenly came up with an idea to write the BIOS. Maybe it was a whim. I read some information and decided to write a simple BIOS program.
I. preparations:
1. I personally think Bochs simulation software is better, because Bochs simulate x86 hardware environment (CPU instructions) extremely peripheral devices, so it is easy to be transplanted to other platforms.
I downloaded Bochs2.2.1 from the Bochs official website http://bochs.sourceforge.net, now has released the 2.3.5 version, but I like to use the old, can not say why, purely personal liking.
2. ubuntu7.10 system, nothing to say.
Ii. Start:
1. Write the following code in ubuntu7.10 and save it as the bootsect. s file:
. Globl begtext, begdata, begbss, endtext, enddata, endbss
. Text! Body section
Begtext:
. Data! Data Segment
Begdata:
. Bss! Uninitialized data segment
Begbss:
. Text
BOOTSEG = 0x07c0! Original Segment address for BIOS to load bootsect code
Entry start
Start:
Jmpi go, BOOTSEG! Inter-segment jump
Go: mov ax, cs
Mov ds, ax
Mov es, ax
Mov [msg1 + 17], ah! 0x07-> replace a dot in the string and the Horn will be called
Mov cx, #20! A total of 20 characters are displayed, including carriage return and line feed.
Mov dx, #0x1010! The msg1 string will be displayed in 17th rows and 17th columns on the screen.
Mov bx, # 0x000c! The characters are displayed in red.
Mov bp, # msg1! Point to the string to be displayed (used for future interruptions)
Mov ax, #0x1301! Write a string and move the cursor to the end of the string
Int 0x10! BIOS interrupt call 0x10, function 0x13, sub-function 0x01
Mov ax, #10000.
Loop1: dec ax
Jnz loop1! Latency

Mov cx, #40
Mov dx, #0x1210
Mov bx, # 0x000c
Mov bp, # msg2
Mov ax, #0x1301
Int 0x10
Loop0: jmp loop0
Msg1:. ascii "Loading system ......"
. Byte 13, 10
Msg2:. ascii "Welcom To jhx0301's Space! ! ! "
. Byte 13, 10
. Org 510
. Word 0xAA55
. Text
Endtext:
. Data
Enddata:
. Bss
Endbss:
I have commented on the key code. I believe everyone can understand it.
2. Compile
Root @ jhx-ubuntu :~ # As86-0-a-o bootsect. o bootsect. s
This command uses the as86 assembler to compile bootsect. s to generate the bootsect. o file.
Root @ jhx-ubuntu :~ # Ld86-0-s-o bootsect. o
This command uses ld86 to execute the link operation on the target file, and finally generate the executable file bootsect in the minix structure.

Root @ jhx-ubuntu :~ # Ls
Bootsect. o bootsect. s bootsect. s ~ Whatsnew.txt
Root @ jhx-ubuntu :~ # Ls-l
Total usage 28
-Rwxr-xr-x 1 root 544 bootsect
-Rw-r -- 1 root 318 bootsect. o
-Rwxr-xr-x 1 root 654 bootsect. s
-Rw-r -- 1 root 641 2007-11-19 20:27 bootsect. s ~
-Rw-r -- 1 root 11789 whatsnew.txt
Because I started the boot through a floppy disk, the size cannot exceed 512 bytes,
The command found that bootsect now has 544 bytes, Which is 32 bytes long. In fact, the extra 32 bytes are the header structure of the minix executable file. I manually removed these 32 bytes, the command is as follows:
Root @ jhx-ubuntu :~ # Dd bs = 32 if = bootsect of = jhx skip = 1
Records 16 + 0 reads
Records write records of 16 + 0
512 bytes (512 B) Copied, 0.000338889 seconds, 1.5 MB/second
Use the dd command to delete the 32 bytes added by bootsect and output the 512-byte executable file in the jhx name. jhx is the abbreviation of my name, hey ......
Now you can use ls-l to view the jhx executable file, which is 512 bytes in size. What I want is it.
Root @ jhx-ubuntu :~ # Ls-l
Total usage 32
-Rwxr-xr-x 1 root 544 bootsect
-Rw-r -- 1 root 318 bootsect. o
-Rwxr-xr-x 1 root 654 bootsect. s
-Rw-r -- 1 root 641 2007-11-19 20:27 bootsect. s ~
-Rw-r -- 1 root 512 2007-11-19 20:31 jhx
-Rw-r -- 1 root 11789 whatsnew.txt
Because the virtual machine I installed on VMware does not start the samba service, I can only use shared folders.
Copy jhx to the shared folder:
Root @ jhx-ubuntu :~ # Cp jhx/mnt/hgfs/Untitled-1/
3. Configure Bochs
I installed Bochs in windows. Of course you can also use the linux version.
Note: First, you must copy the executable file jhx compiled in ubuntu to the installation directory of Bochs.
After successful bochsinstallation, there is a bochsrc-simpel.txt file in another installation directory. This is a configuration file template. You can crop it based on your needs. Generally, if you start it on the same floppy disk, you only need to retain the following necessary configurations:
Vgaromimage: file = $ BXSHARE/VGABIOS-elpin-2.40 // default
Romimage: file = $ BXSHARE/BIOS-bochs-latest, address = 0xf0000 // default
Megs: 16 // because my boot program is small, the memory application is 16 MB enough
Floppya: 44 = "jhx", status = inserted // The name of my startup code
Ata0-master: type = disk, path = "jhx", mode = flat, cylinders = 227, heads = 16, spt = 63 // some startup attributes, for example, the path started at startup is based on the installation directory

This configuration file is in txt format. You need to change its suffix to. bxrc, that is, bochsrc. bxrc, which can be correctly identified only when the system is running.
After the extension name is changed, you will find that bochsrc. bxrc has changed to an executable file. Double-click the file and then enter the system !!!


[Img = 594,321] http://album.sina.com.cn/pic_3/4b8f6be743f484b517a28#/img]


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.