Write the operating system by yourself (1) and write the operating system by yourself
Taking the opportunity of taking the kernel course of the operating system now, I borrowed "write the operating system by myself" from Yuanyuan in the library and prepared to write it manually, improve your understanding of the operating system. Start with a technical blog to record your learning history. The younger brother wrote a blog for the first time. Please ask Hai Han for anything else.
The platforms you choose are Ubuntu14 and Bochs. For more information about how to install Bochs, see OS .51cto.com/art/201407/446838_all.htm.
The first program is of course a classic Entry Program "hello world", but this is a hello world at the bootloader level written in assembly language. Based on your own operation process, I will explain my general steps so that you can have a clear understanding:
1. Install bochs.
2. Go to the installation directory of bochs and run the "./bximage" command to create an empty floppy disk.
3. Write your own source file (boot. asm) in your project directory, and use the following command to compile the source file to obtain the image. Nasm boot. asm-o boot. bin
4. Copy a. img (default name), a floppy disk created in part 3, to the current project directory.
5. Write the system image. Dd if = your image path (that is, the compiled boot. bin path) of = a. img
6. Write your own configuration file (bochsrc ).
7. Execute bochs according to your own configuration file. Bochs-f bochsrc
The project directory should contain the following files:
The following figure shows the page after Step 7 is executed.
C
Press ENTER directly, and the following interface will appear, black, and nothing
However, entering C in the terminal will correctly display what we want.
Below we will paste the source file code involved in the above operations so that you can easily demonstrate it on your own machine;
The following is my Bochs configuration file, bochsrc
1 ####################################### ######################## 2 # Configuration file for Bochs 3 ######### ######################################## ############ 4 5 # how much memory the emulated machine will have 6 megs: 32 7 8 # filename of ROM images 9 romimage: file =/usr/share/bochs/BIOS-bochs-latest10 vgaromimage: file =/usr/share/vgabios. bin11 12 # what disk images will be used13 f Loppya: Route 44 = a. img, status = inserted14 15 # choose the boot disk.16 boot: floppy17 18 # where do we send log messages? 19 # log: bochsout.txt 20 21 # disable the mouse22 mouse: enabled = 023 24 # enable key mapping, using US layout as default.25 # keyboard_mapping: enabled = 1, map =/usr/share/bochs/keymaps/x11-pc-us.mapView Code
Source code of boot. asm
Org 07c00h; tells the compiler program to load at 7c00 mov ax, cs mov ds, ax mov es, ax call DispStr; call the display string routine jmp $; infinite loop $ represents the current address DispStr: mov ax, BootMessage mov bp, ax; ES: BP = string address mov cx, 16; CX = String Length mov ax, 01301 h; AH = 13, AL = 01 h mov bx, 000ch; page number: 0 (BH = 0) Black Bottom red letter (BL = 0Ch, highlighted) mov dl, 0; display the ASCII code in DL to the screen, send '\ 0' to DL and display int 10 h; ret interrupted at 10 h; return to call position BootMessage: db "Hello, OS world! "Times 510-($-$) db 0; fill in the remaining space to make the generated binary code exactly 512 bytes dw 0xaa55; End markView Code
This time, we will introduce the environment and have an intuitive understanding. In the future, we should focus more on the code.