Dragon core software development: using the dragon core 2E simulator gxemul

Source: Internet
Author: User

By Falcon <wuzhangjin@gmail.com>
2008-01-13

If you want to develop loongson software without a Development Board, you can use its virtual machine gxemul (for loongson) to emulate. However, the latest gxemul that supports loongson is 0.4.3 and only supports loongson 2E. In addition, the network support is not good enough. Next we will introduce how to simulate a loongson basic software development environment through gxemul on the Ubuntu system on the X86 platform.

1. Introduction

Loongson [1] is a high-performance, low-power processor chip developed by the Chinese Emy of sciences and manufactured by Italian FA Semiconductor Corporation. It adopts the mips architecture as a general-purpose CPU. Loongson has been developing constantly, from the first generation to the present generation, as well as the three generations being developed. Currently, products on the market are mainly based on the 2E and 2f sequences.
The forlong mini PC is a personal computer made up of loongson processors by coolongmeng. It is exquisite and compact.
Forlong mini PC uses the pmon commonly used in embedded systems as its bios and boot loader, and Debian as its operating system.

To simulate a loongson basic development environment, we need a complete simulator of a processor and basic peripherals. qemu, as a very popular open source code simulator, supports the mips architecture, however, loongson has many extended commands that are not supported by qemu, and many other MIPS simulators have similar problems. So here we will introduce another transplanted command, simulator capable of basically simulating loongson 2E: gxemul [2].
With the simulator, we need to use it to load bios and bootloader, and guide the Linux operating system through bootloader. Since loongson-based products such as forlong mini PC use pmon [3] as their bios & bootloader, we also need to know how to compile pmon and load it in gxemul.
After the pmon is loaded, you can use it to guide a Debian [4] operating system. This section describes how to guide an existing Debian operating system and how to install a new Debian operating system through gxemul.
After that, we will introduce how to install basic software development tools in the Debian operating system, and introduce an example of assembly language development.

2. Use gxemul

The latest available loongson2e version is gxemul 0.4.3, which can be downloaded from http://www.lemote.com/upfiles.

$ Wget-C http://www.lemote.com/upfiles/gxemul-0.4.3.godson.tar.gz
$ Tar zxf gxemul-0.4.3.godson.tar.gz
$ Gxemul-0.4.3 CD
$ Dpkg-buildpackage
$ Dpkg-I gxemul_0.4.3-1_i386.deb

 

After installation, you can download a compiled pmon. Bin and a hard disk image file containing the Debian basic file system.

$ Wget-C http://www.lemote.com/upfiles/emulator.tar.gz
$ Tar zxf emulator.tar.gz
// Compiled pmon. bin. This is loongson's BIOS & bootloader.
$ Ls emulator/pmon. Bin
// This is loongson's Linux Kernel
$ Ls emulator/vmlinux
$ Wget-C http://www.lemote.com/upfiles/virtual-disk.tar.bz2
$ Tar jxf virtual-disk.tar.bz2
// This is the basic Debian system.
$ Ls hda

 

Start pmon. Bin through gxemul and guide the Debian system through pmon.

$ Gxemul-Xe bonito 0xbfc00000:/path/to/pmon. Bin-D/path/to/hda

 


After it is started, the pmon command line will be started first. We need to manually load the kernel and execute it.

// Load the Linux kernel from the virtual hard disk image file
Pmon> load/dev/fs/ext2 @ wd0/boot/vmlinux
// Pass a startup parameter root to the kernel, notify the partition where the file system is located, and use g commands to guide Linux
Pmon> g root =/dev/hda1

 

After a while, you will be able to see the familiar Linux logon prompt. Simply type "root" without a password.

In fact, we can also direct the Debian file system through gxemul instead of pmon. bin. The operations are as follows:

$ Gxemul-0.4.3/gxemul-Xe Bonito-D/path/to/hda-o "root =/dev/hda1"/path/to/vmlinux

 

Now let's describe the role of the parameter: X specifies to use X11, e specifies the machine type, Here Bonito is the loongson2e type,-D specifies to load a file as the disk image, -O specifies the parameters that are passed to the following executable files. Keeping up with vmlinux directly is a binary file that can be run on gxemul, and the preceding parameters are passed to it.
Another note: gxemul 0.4.2 for loongson 2E cannot work normally on Intel (r) core (TM) 2 Duo CPU machines. We recommend that you directly use 0.4.3 above.

3. Compile pmon

The reason for loading and guiding the Debian system through pmon. Bin is as follows: we can study pmon. If you just want to use gxemul to learn loongson2e compilation, you just need to start the Debian system through gxemul.
The following describes how to compile pmon.

Download the pmon source code. If there is no SVN, first install the subversion. If there is no git, remember to install it:

// It seems that the update has been stopped, but it can still be used.
$ SVN Co http://www.loongson.cn/svn/pmon-loongson/
// If you want to use the latest version, you are advised to use the GIT repository (see the official instructions in [6] for details ).
$ Git-clone http://www.loongson.cn/support/git/project/pmon

 

Download and install the MIPs cross-tool chain (good old, good old, haha, GCC is only 2.x, but keep up with the above Code. If you use the latest toolchain [6], instead, there is no way to compile the above pmon ).

$ Wget http://www.loongson.cn/svn/pmon-loongson/toolchain/toolchain-pmon.tgz
$ Tar-C/-zxvf toolchain-pmon.tgz

 

Set the environment variables, add the following two rows to/etc/profile, and run "Source/etc/profile" to apply the changes.

Export mkdep = makedepend
Export Path =/usr/local/COMP/MIPS-elf/gcc-2.95.3/bin/: $ path

 

Compile pmoncfg. This tool is used to analyze the configuration file for different compilation actions. If it is not installed, pmon cannot be compiled.

$ CD tools/pmoncfg
// I cannot compile it directly because the new version of GCC is "picky" for loop-like labels [5]. You have to add an empty statement at the end, if an error occurs, modify it as prompted.
$ Make
$ CP pmoncfg/usr/bin/

 

Compile pmon (for loongson2e ).

$ CD zloader.2edev/
$ Make cfg
$ Make TGT = Rom
$ Make TGT = Ram
// Generated pmon
$ Ls pmon.bin.gz
$ Gunzip pmon.bin.gz

 


Now you can use your own pmon to guide the Debian system.
Note: if an error occurs during compilation, check the error message. Generally, the header file is missing and the corresponding software package can be installed.

4. install a new Debian operating system on gxemul

To be continued ......
(No installation program for loong2e has been found. For details about the basic installation process, refer to [].)

5. Install basic development environment tools

After the basic Debian system in the above hard disk image file is started, the network is not supported (you must solve this problem first if you have time ), otherwise, you can directly install the required tools through the network (basically install build-essential, csloud, and ctags ). However, on this system, tools such as GCC already exist and can be used. (If you do not think it is enough and only want to learn MIPS assembly, you can use qemu to combine it, for more information, see my previous blog [14].
The following describes how to add files to the hard disk image file system.

This hard disk image file contains a basic file system. We can use fdisk to view the starting position of the file system in this file [10] And then mount it.

$ Fdisk-l-u-C1 hda

Disk hda: 0 MB, 0 bytes
16 Heads, 63 sectors/track, 1 cylinders, total 0 sectors
Units = sectors of 1*512 = 512 bytes
Disk identifier: 0x00000000

Device boot start end blocks ID system
Hda1 63 1968623 984280 + 83 Linux
Partition 1 has different physical/logical endings:
Phys = (1023, 15, 63) logical = (1952, 15, 63)

 

As you can see, the starting position of the hda1 partition in this file is 63rd sectors, and each sector is 512 bytes. In this way, the file system offset is 63*512 = 32256. Mount the partition below.

$ Mount-O and offset = 32256 hda/mnt
$ Ls/mnt/
Bin boot Dev etc home initrd lib lost + found media MNT opt proc root sbin SRV sys tmp usr VaR

 


In this way, we can add files to the file system.

6. Development Instance

C language development has little to do with the underlying architecture, but compilation language development is quite different. Because I wrote a hello world example in document [13], I will not introduce it here. Please refer to [13] for details. this example can also be correctly compiled and executed in the Debian system.

This article references a lot of relevant materials, most of which are listed below. If you encounter any problems when reading this article, please directly find the corresponding reference materials or reply to them later.

References

[1] loongson from Wikipedia
Http://en.wikipedia.org/wiki/Loongson
[2] gxemul
Http://gavare.se/gxemul/
[3] pmon 2000
Http://www.opsycon.se/
[4] Debian
Http://www.debian.org/
[5] compilartion error: Label at end of compound statement
Http://www.linux-mips.org/archives/linux-mips/2006-03/msg00234.html
[6] loongson-related git software Repository
Http://www.loongson.cn/support/cgi-bin/gitweb/gitweb.cgi?
Http://www.loongson.cn/support/public/
[7] official gxemul document
Http://gavare.se/gxemul/gxemul-stable/doc/guestoses.html
[8] gxemul_loongson install NetBSD
Http://www.lemote.com/bbs/viewthread.php? Tid = 12391 & Highlight = gxemul
[9] relatively stable dragon core gxemul-0.4.2
Http://www.lemote.com/bbs/viewthread.php? Tid = 1957 & extra = Page % 3d
[10] mount of the complete disk image
Http://www.anheng.com/news/html/net_admin_blog/dd_hda_mount_loop.html
[11] pmon Compilation Method
Http://www.lemote.com/bbs/viewthread.php? Tid = 7448 &
[12] pmon Compilation Guide
Http://blog.csdn.net/caimouse/archive/2006/12/24/1458074.aspx
[13] Hello, world in MIPS Assembly Language Programming!
Http://oss.lzu.edu.cn/blog/blog.php? /Do_showone/tid_1674.html
[14] Using qemu in unbuntu8.04 to build the MIPs-Linux development environment
Http://oss.lzu.edu.cn/blog/blog.php? /Do_showone/tid_1646.html

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.