I was going to borrow an embedded book from the library to go back to research, but I accidentally discovered the implementation of an operating system of orange's, which had been a long time ago.
At first glance, the language mainly changes to the C language, so it seems that I want to use an assembly book for reference. AI, on the Assembly, I want to say that it is just a bit of the syntax that will change in the embedded design, A child who has never learned assembly feels a little stressed, but it doesn't matter. I'm not afraid, ^_^.
The first two chapters are some introductions and big environment building. I feel that I have no need to study the selection of the development environment, but I still can't help reading the following. I personally feel that the author has written a good job, as a developer, you must use linux. computers use windows because of its low entry threshold, linux, oh, no, it should be said that gnu, although the entry route is steep, but after getting started, I will be very comfortable. I am deeply touched by this. Although I still use graphical interfaces from time to time, I have read an article about linux without virus, speaking of the linux virus, the first linux virus in the world is not used to destroy linux, but to prove that there is a virus in linux and no anti-virus software is required. ^_^.
In my spare time, I started my work. My system is debian7, the virtual machine uses bochs2.6.2, and the latest version. Click here to download it. Here is an article about three mainstream differences about virtual machines, you can check it out. Before installation, a gcc compiler is required. Of course, the complete installation file is as follows:
apt-get install build-essential xorg-dev bison libgtk2.0-dev libtool
For more information, see install bochs2.6 from debian. At the beginning, only build-essential was installed. make could not be executed, and all of them were installed for solution;
Next, write a boot sector:
org 07c00h ; tell the compile load data from 7c99 mov ax, cs mov ds, ax mov es, ax call DispStr ; monitor the example of show string jmp $DispStr: mov ax, BootMessage mov bp, ax ; ES:BP = the address of the serial mov cx, 16 ; CX = the length of the serial mov ax, 01301h ; AH = 13, AL = 01h mov bx, 000ch ; 0 page(BH = 0) red buttom and red word(BL = 0ch, highlig ht) mov dl, 0 int 10h ; 10h break retBootMessage: db "Hello, Crazy.J OS"times 510-($-$$) db 0 ; Fill the remain space,make the 2 binary file 512 byt esdw 0xaa55 ; end sign
If you want to add a configuration file by yourself, use-f to configure the file name and find it in the installation directory. bochsrc: Use vim to edit the image. Here, you need to change the File Location of the floppya image to the file location compiled by yourself.
nasm boot.asm -o boot.bin
OK, with the binfile, the following is to generate the imgfile through bximage. Enter bximage directly here, and change the disk type to fp. The image name can also be changed, in short, follow the prompts to perform the operation, which is very simple, then, use
dd -if=boot.bin of=boot.img bs=512 count=1 conv=notrunc
Because it is a virtual machine operation, add the parameter conv = notrunc to prevent being split. Next, comment out the boot disk in the configuration file and uncomment the boot floppy disk, the default key mapping configuration is commented out. Add the following section to locate the map file in the relative path:
keyboard_mapping:= enabled=1, map=gui/keymaps/x11-pc-us.map
For the cpu configuration part, comment it out for beginners, or an error will be reported: cpu ctictive malformed. If it is commented out, no error will be reported.
You can use bochs to get started with the operating system.
It was a little difficult to use at the beginning. After selecting 6, a window appears. If you click bochs, there is no response. Is it dead ??? With an attempt, I entered exit in the terminal. Wow, I quit. I used to control the exit in the terminal. This is easy to do. In this case, <bochs: 1> enter B 0x7c00. Here is the address in the program, and then c is:
<bochs:1> b 0x7c00<bochs:2> c(0) Breakpoint 1, 0x00007c00 in ?? ()Next at t=14040378(0) [0x000000007c00] 0000:7c00 (unk. ctxt): mov ax, cs ; 8cc8
The CPU information is displayed as needed. according to the syntax error in the usage of dump_cpu as described in the book, I have queried it. This post answered the reason, probably because Versions later than 2.3.5 do not support a command. OK, record the command and view it intuitively.
rfpmmxssedregsregcreg
The input and output information is as follows:
<bochs:11> x /64xb 0x7c00[bochs]:0x00007c00 <bogus+ 0>:0x8c0xc80x8e0xd80x8e0xc00xe80x020x00007c08 <bogus+ 8>:0x000xeb0xfe0xb80x1e0x7c0x890xc50x00007c10 <bogus+ 16>:0xb90x100x000xb80x010x130xbb0x0c0x00007c18 <bogus+ 24>:0x000xb20x000xcd0x100xc30x480x650x00007c20 <bogus+ 32>:0x6c0x6c0x6f0x2c0x200x430x720x610x00007c28 <bogus+ 40>:0x7a0x790x2e0x4a0x200x4f0x530x000x00007c30 <bogus+ 48>:0x000x000x000x000x000x000x000x000x00007c38 <bogus+ 56>:0x000x000x000x000x000x000x000x00<bochs:12> nNext at t=14040382(0) [0x000000007c02] 0000:7c02 (unk. ctxt): mov ds, ax ; 8ed8<bochs:13> trace-reg onRegister-Tracing enabled for CPU0<bochs:14> nNext at t=14040383eax: 0x00000000 0ecx: 0x00090000 589824edx: 0x00000000 0ebx: 0x00000000 0esp: 0x0000ffd6 65494ebp: 0x00000000 0esi: 0x000e0000 917504edi: 0x0000ffac 65452eip: 0x00007c04eflags 0x00000082: id vip vif ac vm rf nt IOPL=0 of df if tf SF zf af pf cf(0) [0x000000007c04] 0000:7c04 (unk. ctxt): mov es, ax ; 8ec0<bochs:15> c^CNext at t=75215074136eax: 0x00001301 4865ecx: 0x00090010 589840edx: 0x00000000 0ebx: 0x0000000c 12esp: 0x0000ffd6 65494ebp: 0x00007c1e 31774esi: 0x000e0000 917504edi: 0x0000ffac 65452eip: 0x00007c09eflags 0x00000082: id vip vif ac vm rf nt IOPL=0 of df if tf SF zf af pf cf(0) [0x000000007c09] 0000:7c09 (unk. ctxt): jmp .-2 (0x00007c09) ; ebfe<bochs:16> exiteax: 0x00001301 4865ecx: 0x00090010 589840edx: 0x00000000 0ebx: 0x0000000c 12esp: 0x0000ffd6 65494ebp: 0x00007c1e 31774esi: 0x000e0000 917504edi: 0x0000ffac 65452eip: 0x00007c09eflags 0x00000082: id vip vif ac vm rf nt IOPL=0 of df if tf SF zf af pf cf(0).[75215074136] [0x000000007c09] 0000:7c09 (unk. ctxt): jmp .-2 (0x00007c09) ; ebfe
OK. It shows the success. My output information is displayed above. I'm so excited. I want to write a compilation book to study this book well. During the winter vacation, I must stick to it!