Linux0.11 Study Notes-Technology-simple AB Task Switching Program (1)-implement a simple bootloaderUbuntu10.04 build a linux-0.11 compiling environment (1. bochs Installation and Use) Ubuntu10.

Source: Internet
Author: User

Looking at the Code directly, even if you have understood the code, there is still a feeling that you have not learned it. real mastery comes from practice and can be done by yourself. the purpose of the "simple AB Task Switching program" series is to implement switching between simple AB tasks under bochs.

1. bochs installation or compilation reference

Ubuntu10.04 build a linux-0.11 compiling environment (1. install and use bochs)

Ubuntu10.04 build a linux-0.11 compiling environment (2. bochs compilation)

2. Implement a simple bootloader

(1) bootloader, as the name suggests, boot + loader. Now we only implement boot. loader is actually a simple bios interrupt call, followed by contact.

(2) The assembly language is used here. The Assembly and connector are as86 and ld86 respectively, and sudo apt-get install bin86 under ubuntu.

(3) code boot. s

. Globl begtext, begdata, begbss, endtext, enddata, endbss
. Text
Begtext:
. Data
Begdata:
. Bss
Begbss:
. Text
BOOTSEG = 0x07c0

Entry start
Start:
Jmpi go, BOOTSEG

Go:
Mov ax, cs
Mov ds, ax
Mov es, ax

Mov ax, #0x0600
Mov cx, #0x0000
Mov dx, #0 xFFFF
Int 0x10

Mov cx, #20
Mov dx, #0x0000
Mov bx, # 0x000c
Mov bp, # msg1
Mov ax, #0x1301
Int 0x10

Loop0: jmp loop0

Msg1:. ascii "Loading system ..."
. Byte 13, 10

. Org 510
. Word 0xAA55

(4) Analysis

. Globl begtext, begdata, begbss, endtext, enddata, endbss
. Text
Begtext:
. Data
Begdata:
. Bss
Begbss:
. Text

The preceding statements indicate the global symbols to be declared by the assembler and connector, and indicate that all segments of the program start from a base address.

BOOTSEG = 0x07c0

Entry start
Start:
Jmpi go, BOOTSEG

Go:

Entry start indicates that the entry of the assembler program is the start symbol.

Because this section is the boot code, the boot code is in the designated position of the boot disk, and the bios will read it out and put it in the memory 0x7c00: 0x0 by default, so all the base segments are actually 0x7c00.

Jmpi do and BOOTSEG are executed at 0x7c00: go. go is actually an offset from the current jmpi do and BOOTSEG command. Assume It is 5, this sentence actually jumps to 0x7c00: 0x5 for execution, and implicitly sets cs to 0x7c00. In this case, you do not need to directly replace mov ax, cs:

Mov ax, # BOOTSEG or mov ax, 0x7c00

Mov ax, cs
Mov ds, ax
Mov es, ax

The ds and es segments are set to the same as cs, because the program declares that the code data appending segments are a base address.

Mov ax, #0x0600
Mov cx, #0x0000
Mov dx, #0 xFFFF
Int 0x10

The above statements call the bios 0x10 interrupt and clear the screen. You don't need to know much about the bios interrupt. You can check the manual for usage. There are many manuals on the network.

Mov cx, #20
Mov dx, #0x0000
Mov bx, # 0x000c
Mov bp, # msg1
Mov ax, #0x1301
Int 0x10

The above statements call the bios 0x10 interrupt and display a string msg1

Loop0: jmp loop0

It can be seen as an infinite loop.

Msg1:. ascii "Loading system ..."
. Byte 13, 10

Define a string

. Org 510
. Word 0xAA55

After, define 0xAA55 to start the sector flag.

3. Compile and debug bootloader

The as86 Assembler and ld86 connector used in the front side, and the bochs simulator.

Bochs supports Virtual floppy disks and hard disks. Because the floppy disk is simpler, We need to compile the program and start the program less on the floppy disk.

(1) Compile boot. s

As86-0-a-o boot. o boot. s

Boot. s is the source code, and boot. o is the compilation output.

(2) link boot. o

Ld86-0-s-o boot. o

Boot. o is the output of (1), and boot is the link output.

(3) create a virtual floppy disk

Dd bs = 32 if = boot of = boot. img skip = 1

Because the first 32 bytes of boot are file headers, skip this step and write all the following content into boot. img.

Now boot. img is a ready virtual floppy disk that can be started.


4. Run and debug bochs

(1) bochs Configuration

The bochsconfiguration file bochsrc.txt is as follows:

Config_interface: textconfig

Romimage: file =/usr/local/share/bochs/BIOS-bochs-latest

Megs: 16

Vgaromimage: file =/usr/local/share/bochs/VGABIOS-lgpl-latest

Floppya: 44 = "boot. img", status = inserted

Boot:

Vga_update_interval: 300000

Keyboard_paste_delay: 100000

Keyboard_serial_delay: 200

Cpu: count = 1, ips = 1000000

Mouse: enabled = 0

Private_colormap: enabled = 0

Fullscreen: enabled = 0

Screenmode: name = "sample"

I440fxsupport: enabled = 0

(2) Run

Run bochs in the current directory.

(3) bochs debugging command

C-continue

Pb 0x7c00-set a breakpoint at 0x7c00

N-execute the next step

U 0x10000-disassembly 0x10000 Area


This article is complete.

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.