Operating system-Hello, DTOS!

1. Hello, the creation of DTOS

Q: Is the main bootloader software or firmware? If it is software, who develops it? How to develop?
A. The main boot program
1. A piece of valid code stored in the main boot area
2. It is not solidified in the hardware and is part of the operating system code
3. Starts the operating system kernel Bridge, written by assembler
4. The total amount of code cannot exceed 512 bytes (including 0x55aa)
We can see the comparison between the BIOS entry and the C/C++ entry from the picture
< img alt="Operating system-Hello, the creation of DTOS!" src="/wp-content/uploads/images/os/ostheory/1626797031727.jpg" >
Experiment-write a master boot program (assembly language), It can run independently on the host of the x86 architecture (no operating system), and print “Hello, DTOS!” on the screen after running.
A. Implementation ideas
1. Change the value of the key register Set to 0(mov ax,0)
2. Define the data to be printed (db “Hello,DTOS!”)
3. Print the predefined character data (int 0x10)
here What you need to know is
mov: Assignment operation, assign the right operand to the left operand
Operating system-Hello, DTOS! Creation
int:Trigger interrupt
Operating system-Hello, the creation of DTOS!
hlt: stop running, the CPU enters a suspended state, no operation is performed
Operating system-Hello, the creation of DTOS!
Access method of address in assembly: segment address: segment Internal offset address
Operating system-Hello, DTOS! CreationTag
Operating system-Hello, the creation of DTOS!< br>Operating system-Hello, the creation of DTOS!
B. Interrupt calling VS function Call
Operating system-Hello, DTOS! Creation
Design of the experimental solution
1. Compile the assembly source code into binary machine code (nasm)

Operating system-Hello, the creation of DTOS!Create a virtual network disk
2. Create a virtual disk (bximage)
operating system-Hello,DTOS The creation of !Set the size
3. Write the binary code to the starting position of the virtual disk (dd)
Operating system-Hello, the creation of DTOS!if is input, of is output, bs is size There is no interval between continuous writing
4. Execute the virtual disk as the boot disk in the virtual machine (vmware)
B. The implementation process is as follows
a. Writing assembly language

org 0x7c00

start:
mov ax, cs//Key register address is 0
mov ss, ax
mov ds, ax
mov es, ax

mov si, msg//The assignment operation assigns the address of the first line of msg to the si register

print:
mov al, [si]//[] means fetching data
add si, 1//The address value saved by si+1
cmp al, 0x00//End position
je last//jump for comparison
mov ah, 0x0e
mov bx, 0x0f
int 0x10//trigger interrupt, print character
jmp print//equivalent to while loop

last:
hlt
jmp last//unconditional jump

msg:
db 0x0a, 0x0a//define two consecutive data 0x0a wrap
db "Hello, DTOS!"//define string data
db 0x0a, 0x0a//define newline
times 510-($-$$) db 0x00//fill 0 meets 512 bytes
db 0x55, 0xaa//occupies two bytes

b. Compile it into binary under Linux
Operating system-Hello, the creation of DTOS!Operating system-Hello, the creation of DTOS!
1-2. Binary compilation through nasm command, if nasm is not installed, install through prompts
3-4. Through bximage Command to set the network disk, if bximage is not installed, install through the prompts
5-8. Set the virtual virtual disk respectively, and then set it to the standard size of 1.44 MB, and name it a.img
9. Write the binary code to the starting position of the virtual disk through the dd command, and the uninterrupted write size is 512
generated The a.img as shown in the picture
Operating system-Hello, DTOS! Creation
c. Create a new operating system on the virtual machine. After setting it, set the startup disk and copy the generated a.img to the newly created virtual machine for setting
< img alt="Operating system-Hello, the creation of DTOS!" src="/wp-content/uploads/images/os/ostheory/1626797031728.jpg" >
d. Start the operating system after setting up , We can get the print result we need as shown in the figure
Operating system-Hello, DTOS! Creation
Summary 1. The code size of the main boot program cannot exceed 512 bytes 2. The main boot program needs to be developed in assembly language 3. The main boot program can be used by BIOS interruption Hardware function 4. The main boot program runs in real mode (the addresses are all actual physical addresses)

Leave a Comment

Your email address will not be published.