The corresponding executable files are compiled with Kernel.ASM with Kernel.ASM, compile LOAD.C with TC2.0 to get the executable, and put three executables under the same folder. Prepare a blank floppy disk, perform loading.exe under the console to get a boot flush; restart your computer, set a disk as the first start disk, you can boot the system from the A disk, you can do the only one after entering the system One thing is to enter characters from the keyboard and display it to cycle.
The specific operation process has a more detailed description in the Load.c file annotation below.
OBJECTIVE: Write a boot program and a super simple kernel. After the boot is successful, you can enter characters on the keyboard and display the tool: Masm5.0 compiler, TC2.0, a computer (if there is Virtual PC, do it above Experimental does not damage the machine). What you need: I simply talk about the process of power on the computer, after the computer is turned on, after the computer is turned on, including what self-test, BIOS is embolded into memory .... Final Bios 0 tracks 1 zone 1 512 bytes are placed in the memory 0000: 7C00, then handle the control to the boot program, the instant CS = 0000, IP = 7C00. (I think it should be like this), then everything can enter your master Thereon. We now use the compilation of the program after 7C00, put this program in the first sector, called boot, this program's role is to put in the second sector to transfer the memory 8000: 0000 Jump there to do it.
File: boot.asm
File: boot.asm; load.exe program Writes the binary of the following code to the A disk; 0 track 1 sector ;; When the boot, the BIOS boot will automatically load the content of this sector into memory; 07C0H Divide it;
Code segment assume cs: codeart:; cs = 0000, ip = 7C00 MOV AX, OFFSET START ADD AX, 07C0H; AX plus 07C0H to DS, MOV DS, AX; set data segment register DS,; make DS: 0000 0000: 7C00 MOV SI, OFFSET MSG; MSG Offset Si Call Display; Display; Initializing INT 13H's registers, load the kernel; for specific setup information, please refer to the BIOS Interrupt Manual) MOV AX, 8000H; KERNEL will be stored in the memory paragraph address MOV ES, AX; pass to ES MOV BX, 0; KERNEL offset address is 0 MOV DL, 0; the driver number is 0H, that is, the A disk MOV DH, 0; the magnetic head number is 0 MOV CH, 0; the track number is 0 MOV CL, 2; the sector number is 2 MOV Al, 1; the number of sectors to be read is 1 MOV AH, 2; call the interrupt program INT 13h of the read disk; the core is loaded with MOV Si, Offset OK; Display OK Call Display Mov BX, Offset Ker; Kernel is stored in address 8000: 0000; according to the front edge (ES: BX) settings. Jump to the KERNEL program. JMP DWORD PTR [BX]; Jump to the address of the BX pointer to the address. Display: Lodsb; loaded into Al or Al, Al; Al = 0 indicates that this string ends JZ DISEND; jump to the last return MOV AH, 0EH; 0EH is the display function number MOV BX, 7; color INT 10h JMP DisplayDisnd: Ret
MSG DB 'My OS Is Loading ..., 0; Display Information OK DB' OK ', 13, 10, 0 Ker DW 0,8000H; kernel's memory address 8000: 0000 Code ends end start
Document: kernel.asm
File: kernel.ASM; load.exe program writes the binary of the following code to the A disk; 0 track 2 sector ;; Boot code in the 0 track 1 sector will load this code into memory and Jump; go to the corresponding address to perform this code.
; Code function: Connect input from the keyboard, display it in the order. Kenergy Segment Assume CS: KernelStart: MOV AH, 0; the function of reading the character from the keyboard INT 16H MOV AH, 0EH; Display function int 10h CMP AL, 13; If it is a carriage return, wrap JNZ Start Mov Al, 10 INT 10h JMP Start; Infinite Circulation Kernel Endsend Start
Document: loading.c
/ * file: load.c * // * This program is so simple, the function is only two, accepts characters and display, and compiles the connection. Now we have generated two files boot.exe, kernel.exe. Where boot.exe is not executed, you can run the kernel.exe in DOS, you can see if you write it. The two files are now written to the 1, 2 sector of the floppy disk. But you will find a blame problem, boot has 603 bytes, KERNEL has 522 bytes, but there is only 512 bytes of sectors, how to write? I first confused this question, and later disconnected two exe files to know that the code we wrote in the 513-byte of the EXE file, the first 512 byte of the exe file is the prefix of the EXE file defined by mircosoft, where There are exe file identification, size, segment positioning pointer and other things, this 512-byte we don't need us as long as followed, then we will write a program to write boot.exe and kernel.exe to floppy, (note writing The last two bytes must be 55AA when booting the sector. This is the logo of the specified boot sector.
I choose to use TC2.0, of course, I can also write, below is writebt.c * / # include
"); exit (0);} else {printf (" ok ");} IF ((fp = fopen (" kernel.exe "," rb ")) == null) / * Open kernel.exe * / {PrintF ("Cannot Find Kernel.exe"); EXIT (0);} fseek (fp, 512L, 0); / * directly positioned to file 513 byte, ie 512L * / i = 0; while (1) {FREAD (& kernel_buf [i], 1, 1, fp); / * Read all the following content until end * / i ; if (Feof (fp)) {fclose (fp); Break;}} / * Setting: Write the program in the KERNEL to the 0th track 2 sector * / INREG.H.AH = 0x03; INREG.H.Al = 0x1; INREG.H.CH = 0; INREG.H.cl = 2; / * sector number 2 * / INREG.H.DH = 0; INREG.H.DL = 0; INREG.X.BX = fp_off (kernel_buf); segreg.es = fp_seg (kernel_buf); int86X (0x13 , & INREG, & OUTREG, & SegReg; if (_ah! = 0) {Printf ("Error Writing"); exit (0);} else {printf ("ok");}} / * Similarly compiled, now we There are boot.exe, kernel.exe and writebt.exe, copy them in the same directory, then insert the floppy disk, execute WriteBt.exe, if the error Writing indicates that the writing disc is wrong, you run a few more times until Okok appears Write successfully, but you don't switch to a disc right away. Press DIR so that the system will have unformatted information, you must format it. Because some of our information we have made to modify some of the information of Microsoft defined floppy disks, DOS naturally recognizes. Now you can restart, start from the floppy disk, you will see your results. Is this system too simple? For the true operating system, there is file management, memory management, and equipment management ... I don't understand these, learn slowly. My method may not be very good, the efficiency is not high, please ask your master criticism. My mailbox is cyxisgreat@sina.com three programs to compile running on my machine. Please do not change the contents of INREG.H. * In WriteBt without authorization, otherwise the consequences are at your own risk. * /