30 days homemade OS USB boot

Source: Internet
Author: User

Before reading this book, think of doing a U disk boot, but then the knowledge is limited, but also with the help of the floppy disk drive from the USB flash drive, essentially floppy boot.

These two days to study the next USB drive to start, and finally succeeded. To get a picture, this picture is the binary value of the DX register that I read from the USB stick boot:


Method One:

Compile the code of the boot area, write it directly into the first sector of the USB drive, and plug it into the computer to start.

Method Two:

Write the boot area code, open our compiled image file with Winhex, copy the 512-byte code to the first sector of the USB drive (Winhex open the USB flash drive, copy our 512-byte code to the first sector, then save, boot up)

However, these two methods, the USB flash drive on the computer will become unusable status, can not open, and no longer store any files, but may be started.

Method Three:

The advantage of writing the FAT32 file system information to the boot code header and then compiling it into an image file and writing to the USB flash drive with the UltraISO (startup disk maker) is that because we have written the FAT32 file system information, the system can recognize that the device is a USB stick, So we can open the USB flash drive can also store other files inside without affecting the boot.

Note: There may be a large list of messages that cannot be started when restarting:

The system found unauthorized changes on the Fimware, operating system, or UEFI drivers .....

Enter the BIOS setup, the tab "boot" There is a column "Safe boot" option, set to other operating systems. As shown in figure:



Code:

; Mios ORG 0x7c00 JMP ENTRY NOP; file system settings; BIOS PARAMETER BLOCK DB "MSDOS5.0"; OEM DW 512; Bytes_per_sector DB 32; Sectors_per_cluster DW 38; Reserved_sectors DB 2; Number_of_fats DW 0; Root_entries DW 0; Sectors_small DB 0XF8 DW 0 DW + DW 255 DD 0 DD 65536000; FAT32 Section DD 15993 DW 0 DW 0 DD 2 DW 1 DW 6 RESB DB 0 db 0 db 0X2          
        9 DB 0X07 DB 0XD1 db 0x99 db 0x00 db "Hu-os" db "Fat32-hu" ENTRY: MOV ax,0 mov ss,ax mov sp,0x7c00 mov ds,ax mov es,ax mov S i,0 call Getdiskparam JMP FIN Getdiskparam:mov ah,0x 0X13 INT Push DX push ax push bx push si push si
        Call SHOW16 pop si pop bx pop ax pop DX ret SHOW16:     
            ROL dx,1 push ax MOV ax,dx and ax,1 CMP ax,1 JE AA1    
            MOV al,0x30 JMP BB1 aa1:mov al,0x31 Bb1:mov ah,0x0e MOV bx,15 INT 0X10 pop ax ADD ax,1 CMP ax,16 JB SHOW    
            RET fin:hlt JMP FIN resb 510-($-$$)    DB 0X55,0XAA
The head of the FAT32 file information is I through the Winhex view my own USB flash drive, I do not know you use your own U disk with this code can normally start, here only to teach to fish.

To view the method:

Open winhex= "view =" template management = "Boot sector FAT32, the popup is your own parameters of the U disk, the parameters are written into the code is good, can not write wrong, the wrong writing may cause the subsequent program does not work.



Another thing to note is that the head must have a jmp and a NOP, for what? Below is a look at the first sector of the USB flash drive (the code that identifies its own file system):


EB is jmp,58 is the offset of your function, 90 is NOP (null instruction), followed by which is the FAT32 parameters, so there must be a jmp and a NOP, otherwise the address of the argument is not on the problem.

When writing parameters, note that each parameter occupies a byte length that is not wrong, and that the error will be problematic, in front of the offset.

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.