Series catalog
- Preface
- Ready to work
- BIOS boots to real mode
- GDT and Protected Mode
- A Preliminary Study of Virtual Memory
- Load and enter the kernel
- display and print
- Global Descriptor Table GDT
- interrupt handling
- Perfect virtual memory
- Implement heap and malloc
- first kernel thread
- Multi-thread switching
- Locks and Multithreading Synchronization
- enter user mode
- realization of the process
- system call
- simple file system
- load executable program
- keyboard driver
- run shell
Install Bochs
Bochs is a hardware simulator, the kernel we wrote will run on it, and all subsequent development and debugging work will also be done on it, so the first step is to install it. My development environment is Linux Mint system, you can use Ubuntu as well, you can install it directly:
sudo apt install bochs
If this method does not work, you can go directly to the official website to download the source code package to compile and install. I have also tried this method and it is ok. However, during the installation process, there will be some problems that the third-party dependent libraries are not complete. Then you can build a bridge between mountains and rivers, and install all the dependencies. I won't go into details here, you need to find a solution by yourself. , it will not be difficult, and there are some tutorials on the Internet that you can refer to.
As for other systems, I haven't tried it, but the way of compiling the source package and installing it must work. I tried it myself.
Run Bochs
First of all you need a configuration file for Bochs running bochsrc.txt
, this is what I use:
# RAM size
megs: 32
# Change to your Bochs installation path
romimage: file=/usr/share/bochs/BIOS-bochs-latest
vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest
# Disk
boot: disk
ata0: enabled=1, ioaddr1=0x01f0, ioaddr2=0x03f0, irq=14
ata0-master: type=disk, path="scroll.img", mode=flat, cylinders=6, heads=16, spt=63
log: bochsout.txt
mouse: enabled=0
keyboard_mapping: enabled=1, map=/usr/share/bochs/keymaps/x11-pc-us.map
clock: sync=realtime
cpu: ips=1000000
The most important part here is the Disk-related configuration. We use a disk here, which is also the boot loader and kernel image disk behind, and the system is started with this disk. Of course this is not a real disk. is a mirror file.
Among them path="scroll.img"
is the image file, here and the configuration file bochsrc.txt
are in the same path, so it is very simple. You can choose the name you want, mine is scroll
, I'll talk about why later. cylinders
, heads
, spt
are some parameters related to hard disk hardware, what kind of cylinder cylinder head is not necessary.
Of course, we don't have a kernel image file yet. Bochs comes with a command-line tool bximage
, which can make an image file full of 0 for you, and help you determine the above parameters. Just tell it how big your image file needs to be, in MB:
>> bximage
========================================================================
bximage
Disk Image Creation Tool for Bochs
$Id: bximage.c 11315 2012-08-05 18:13:38Z vruppert $
========================================================================
Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd] hd
What kind of image should I create?
Please type flat, sparse or growing. [flat] flat
Enter the hard disk size in megabytes, between 1 and 8257535
[10] 1
I will create a 'flat' hard disk image with
cyl=2
heads=16
sectors per track=63
total sectors=2016
total size=0.98 megabytes
What should I name the image?
[c.img] test
Writing: [] Done.
I wrote 1032192 bytes to test.
The following line should appear in your bochsrc:
ata0-master: type=disk, path="test", mode=flat, cylinders=2, heads=16, spt=63
Everything is ready to run Bochs:
bochs -f bochsrc.txt
If you are lucky, you can see this interface, indicating that the startup was successful:
create project
In other words, our project has not been built so far, so let's go to Git to build one. I will give the address of my Git project first, you can refer to it first, or you can download and run the ./start.sh
script to see the effect.
I named this project scroll
, which means scroll in Chinese, which is this thing:
A scroll is a piece of paper, a picture. In our case it's memory, disk, starting from a blank, and that brush is the CPU. The startup and operation of the entire kernel is essentially a dialogue between the CPU and the memory. The CPU jumps back and forth on the memory, flips and moves, and outlines a huge and complex engineering system, which is the OS.
At the beginning of the next article, we will officially enter the boot of the OS: BIOS boots to real mode .
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。