Compilation of Linux0.11 kernel and establishment of the lab environment on bochs

Source: Internet
Author: User
I recently decided to read the source code of Linux0.11. The best way to learn the core concepts of Linux is to read the source code. The latest Linux source code package is about 70 MB, and the code is very huge. it is very difficult to read it in depth. In earlier versions of Linux 0.11...

 

Recently, I decided to read the source code of Linux 0.11.

The best way to learn the core concepts of Linux is to read the source code. The latest Linux source code package is about 70 MB, and the code is very huge. it is very difficult to read it in depth. Although the early version of Linux 0.11 has many limitations, it has complete functions of the modern operating system. some basic concepts have been followed by the current version, and the code is only KB, which is very suitable for reading.

Before reading the source code, you must first set up an experimental environment. since the Linux 0.11 code was compiled 20 years ago, the current version of the gcc compiler cannot be compiled normally, therefore, we need to first port the Linux 0.11 source code to gcc 4.3.4 + and build an experimental environment on the bochs virtual machine.

 

 

I. Linux 0.11 Kernel Compilation

1. compiling environment settings

My operating system is:

Linux ubuntu 2.6.32-32-generic # 62-Ubuntu SMP i686 GNU/Linux

Install the gcc compiler and use gcc-v to check that the gcc compiler version is later than 4.3.4.

 

 

Install the compilation tool:

Apt-get install build-essential

 

 

Install the software package:

Apt-get install bin86

 

 

2. modify the Makefile file

In the Linux 0.11 kernel source code, each subdirectory contains a Makefile. you need to modify each Makefile as follows:

A) replace gas with as and gld with ld. Now, gas and gld have been directly renamed as and ld;

B) remove the as-c option;

C) remove the gcc compilation options:-fcombine-regs and-mstring-insns.

D) remove the-O option of Makefile in the kernel subdirectory.

 

 

3. modify the align statement for memory location align

In the three assembler programs under the boot directory, the usage of the align statement has changed. The original value after align is the power value of the memory position. now we need to directly give the integer value of the starting address.

Align 3

Change

Align 8

 

 

4. modify the embedded macro assembler

Due to the continuous improvement of as, programmers do not need to specify registers manually. Therefore, we need to remove all _ asm _ ("ax") in the code. For example: "si",: "di",: "ax",: "cx ");

Change

:);

 

 

5. Reference expression of program variables in assembly statements

Remove the underlines before all variables:

. Globl _ idt, _ gdt

To:

. Globl idt, gdt

 

 

6. modify the copy_process function.

In the fork. c file under the kernel subdirectory, modify the following:

* P = * current;/* NOTE! This doesn' t copy the supervisor stack */

Changed:

Memcpy (struct task_struct *) p), (struct task_struct *) current), sizeof (struct task_struct ));

You can also download the modified source code from my github, the connection is: https://github.com/mengli/TinyOS

 

 

7. Compile the kernel

Download mengli-tinyos-v0.0.1-0-g182166e.zip, decompress the package, and run the following command:

Cd mengli-TinyOS-v0.0.1-0-g182166e

Make

After the compilation is complete, the image file of Linux kernel is generated: linux-kernel-image-0.11, so far Linux 0.11 has been transplanted and compiled.

 

 

II. establishment of the lab environment on bochs

1. install bochs

Download bochs 2.2.1 source package, address is: http://sourceforge.net/projects/bochs/files/bochs/2.2.1.tar.gz/download

Run the following command:

Tar xvfz bochs-2.2.1.tar.gz

Cd bochs-2.2.1

./Configure

Before compiling bochs, you must make some changes to the source file. Otherwise, the compilation will fail:

Delete sparse_image_t of lines 290 and lines 295 of the harddrv. h file in the iodev subdirectory ::

Make

Make install

 

 

2. bochs settings

My bochs configuration file is as follows:

# Gdbstub: enabled = 1, port = 1234, text_base = 0, data_base = 0, bss_base = 0

Romimage: file =/usr/local/share/bochs/BIOS-bochs-latest, address = 0xf0000

Megs: 16

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

Floppya: 44 = "linux-kernel-image-0.11", status = inserted

Ata0-master: type = disk, path = "hdc-0.11-new.img", mode = flat, cylinders = 410, heads = 16, spt = 38

Boot:

Log: bochsout.txt

Vga_update_interval: 300000

Keyboard_serial_delay: 200

Keyboard_paste_delay: 100000

Private_colormap: enabled = 0

Fullscreen: enabled = 0

Screenmode: name = "sample"

I440fxsupport: enabled = 0

The first sentence is the bochs debugging option. you can comment out this line without kernel debugging. In addition, the hdc-0.11-new.img file is the root file system loaded after the system starts.

This book is included in Dr. Zhao's book "Linux kernel full notes.

You can download the book: http://oldlinux.org/download/clk011c-2.0.1.pdf from here

Here you can download the compiled kernel image and disk File: http://www.oldlinux.org/Linux.old/bochs/

 

 

3. run bochs

The command to start the bochs virtual machine is: bochs-f bochsrc-gdb.bxrc, where the-f option is used to specify the configuration file.

 

 

The VM is successfully started as follows:

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.