1. Hello world-level Boot Code

Source: Internet
Author: User
The OS development environment has been set up in the previous section. Now let's write a simple guide Code Right

First, let's talk about the operating system boot process:
After the PC power-on self-check, the content of 0 head, 0 track, and 1 Sector of the boot device will be loaded to the memory 0x7c00, and then the Boot Code will be directed to it. I just briefly said, please google for details. Boot. s
1 . Code16
2 . Text
3 . Globl _ start:
4 _ Start:
5 CLI
6 Ljmp $ 0x7c00 , $ 0
7 Go:
8 Movw % CS, % Ax
9 Movw % Ax, % DS
10 Movw % Ax, % SS
11 Movw $ 0xff00 , % SP
12 STI
13
14 Movw $ Zero X 0007 , % BX
15 Movw $ 16 , % CX
16 Movw $ 0 , % DX
17 Movw $ MSG, % BP
18 Movw $ Zero X 1301 , % Ax
19 Int $ 0x10
20
21 JMP.
22 MSG:. ASCII " Hello, OS world! "
23 . Org 510
24 . Word 0xaa55

Boot. s uses the at&t format Assembly syntax. The task is to set the value of the relevant segment register first, and then call the 10 h interrupt display string

To load it to bochs, we also need to use make to compile it into pure binary code and write the corresponding configuration file. Makefile
1 As = As
2 LD = LD
3 Objcopy = Objcopy
4  
5 ALL: floppy. img
6
7 Floppy. IMG: boot
8 Dd If =/ Dev / Zero / Of = Floppy. IMG BS = 1024 Count = 1440
9 Dd If = Boot = Floppy. IMG BS = 512 Count = 1 Conv = Notrunc
10  
11 Boot: boot. o
12 $ (LD) - N - E _ start - Ttext 0   - O $ @. Elf $ ^
13 $ (Objcopy) - S - O binary $ @. Elf $ @
14  
15 Boot. O: boot. s
16 $ () - O $ @ $ ^
17
18 Clean:
19 Rm - RF * . O * . Img * . Elf bochs. Log boot

Google 1 Megs: 32
2 Romimage: File = $ Bxshare / Bios - Bochs - Latest #, address = 0xf0000
3 Vgaromimage: File = $ Bxshare / Vgabios - Lgpl - Latest
4 Floppya: 44 = Floppy. IMG, status = Inserted
5 Boot:

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.