The head is a needle-like magnetic device that can either touch the disk from the front of the diskette or touch the disk from the back of the floppy disk. Unlike discs, floppy disks are capable of recording data on both sides. So we have two heads on both front and back, the heads 1th and heads No. 0 respectively. After specifying the cylinder and the head, on the disk of this ring, can also record a lot of bits of information, according to the whole circle unit read and write, there is a bit more, so the ring evenly divided into several, floppy disk for 18 parts, each part called a sector. 1 floppy disks have 80 cylinders, 2 heads, 18 sectors, and one sector 512 bytes mov cx,[1234] In essence is MOV cx,[ds:1234] The default segment register is DS, so DS must be pre-specified as 0 before use, otherwise the value of the address to add this number 16 times times Will read and write to other places, causing confusion.
Save to disk Image: Use make install instruction, write disk image to disk open that disk in Windows, save Haribote.sys to disk use tool to back up disk as disk image
Typically when you save a file to an empty floppy disk: 1. The file name will be written in 0x002600 2. The contents of the files will be written in the place after 0x004200
After setting the screen information, the screen information will be stored in the memory,
Image files, according to my understanding, that is not the original thing, just a substitute form
HLT is I/o instruction, MOV is forwarding instruction, add is calculation instruction
Bootpack.c
/* tell the C compiler that there is a function in the other file */ void io_hlt (void); /* The function declaration does not use {}, but the function is in another function. */ void Harimain (void) { fin: io_hlt (); /* I want to write a hlt here, but not hlt! in the C language . */ Goto fin;}
Naskfunc.nas
;Naskfunc;tab=4[FORMAT"Wcoff"];the mode of making the target file[BITS +];make a mechanical language for 32-bit mode;information for making a target file[FILE"Naskfunc.nas"];source file name informationGLOBAL _io_hlt;the name of the function contained in the program;The following is the actual function[section. Text];after writing this in the destination file, write the program_io_hlt: ;void io_hlt (void); HLT RET
Ipl10.nas
;Hello-os;tab=4cyls EQUTenORG 0x7c00;indicates the loading address of the program;The following section is a standard FAT12 format floppy disk-specific code JMPEntry DB 0x90 db"Haribote" ;the name of the boot sector can make any stringDw + ;size of each sector (must be 512 bytes)Db1 ;the size of the cluster (must be 1 sectors)Dw1 ;Start position of fat (typically starting with the first sector)Db2 ;number of fat (must be 2)Dw224 ;the size of the root directory (typically set to 224)Dw2880 ;the size of the disk (must be 2880 sectors)DB 0xf0;type of disk (must be 0xf0)Dw9 ;fat Length (must be 9 sectors)Dw - ;1 tracks with several sectors (must be)Dw2 ;number of heads (must be 2)Dd0 ;do not try the partition (must be 0)Dd2880 ;override disk Size onceDb0,0, 0x29;fixedDD 0xFFFFFFFF;(may be) Volume code labelDb"Hariboteos" ;Name of the disk (11 bytes)Db"FAT12" ;the name of the disk format (8 bytes)Resb - ;empty 18 bytes First;Program CoreEntry: MOVAx0 ;Initializing Registers MOVSs,axMOVsp,0x7c00MOVDs,axMOVax,0x0820MOVEs,axMOVCh0 ;Cylinder 0 MOVDh0 ;Head 0 MOVCl2 ;Sector 2Readloop: MOVSI,0 ;registers that record the number of failuresRetry: MOVah,0x02;ah=0x02: Read the disk MOVAL,1 ;a Sector MOVBx0 MOVdl,0x00;a drive INT0x13;calling the disk BIOS JNCNext;jump to next if you don't make a mistake. ADDSI,1 CMPSI,5 JAEError;si>=5 jump to error MOVah,0x00MOVdl,0x00;a drive INT0x13;Resetting the drive JMPRetryNext: MOVAx,es;Move the memory address back 0x200 ADDax,0x0020MOVEs,ax;because there is no add es,0x200 directive ADDCl1 ;add 1 to CL CMPCl - JbeReadloop;if cl<=18, jump to Readloop MOVCl1 ADDDh1 CMPDh2 JBReadloop;if dh<=2, jump to Readloop MOVDh0 ADDCh1 CMPch,cylsJBReadloop;if ch<cyls, jump to Readloop MOV[0x0ff0],chJMP0xc200Error: MOVsi,msgPutloop: MOVAl,[si]ADDSI,1 ;add 1 to Si CMPAL,0 JEFinMOVah,0x0e;Display a text MOVBx the ;Specify character color INT0x10;calling the video card BIOS JMPPutloopFin: HLT ;let the CPU stop looping and wait for instructions JMPFin;Infinite Loopsmsg:DB 0x0a,0x0a;two-time line breakDb"Load Error"DB 0x0a db0Resb 0x7dfe-$;fill in 0x00 until 0x001feDB 0x55, 0xaa
30-Day homemade operating system (third day)