A simple bootstrap ----- 2004.11.1 (C) Gr1xTo make a long story short, and enough material can be found about the PC's POST procedure, I'll just show my code and explain sth important steps, I think my source code is self-explaining enough 'cause it's short and easy to understand I have tested it with a floppy disk, it's risky to test it with ur harddrive If u did do it, I am not responsible for any damage u made:..) Environment: (Window Platform) A.VMware (optional) .IF U Don't Want To Reboot Ur System Many Times, u beauty THIS. B: NASM. (Essential). AS U NEED IT TO Compile UR Code. U use ndisasm as well to disassemble the plain binary code compiled c:... Visual C 6 or Visual Stdio .Net As we have to write a EXE to write the bootstrap to floppy U may use WinHex to write bootstrap to floppy too instead of this Writing a programme.1> Write the bootstrap procedure ---------------------------- Boot Strap.asm ----------------------------------------------- -; ***************************************************** ****; bootstrap.asm: 2004-11-1 (c) GR1X; Email: Gr1x@sina.com; ********************** ***************************** [ORG 0] JMP 07C0H: start; Remember That Bios Loads this Procedure In 0: 7C00H, But Don't Count On Registers Like DS; WAS Initialized to 0. So We Jump To It Ourself. Msg DB 'Hello GR1X!', 0x0Start:; Update The Segment Registers Mov AX, CS MOV DS, AX MOV ES, AX MOV SI , MSG; Print Msgprint: LODSB; LOADS CHARATER AT 0x7C0H: MSG MOV AH, 0EH;
INT 10H CMP Al, 0; JNE Print; JMP $ TIMES 510 - ($ - $$) DB 0 dw 0000h; or dw 0aa55h, u can write anything here, it Seems That Bios Doesn't Check this 2 bytes by; IT Try to boot from a floppy disk --------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- -------- OK, NOW Compile It:> NASM Bootstrap.asm -o Bootstrap.bin2.Now, Copy this Bootstrap to Floppy's Boot Sector. If u Do It with WinHex, U CAN Omit Following. I wrote a Program which do this action. ---------------------------- Write_fd.cpp ----------- ----------------------------------- // ************ ******************************* / / WRITE_FD.CPP: 2004-11-1 (c) GR1X // Email : Gr1x@sian.com // ************************************************************* ***** # include
INT Main (int Argc, char ** argv) {hand = null; tchar szdevicename [64]; lptstr szbuff = null; disk_geometry geometry; Bool Bret; dword; bow, count; banner (); if (argc! = 2) {Printf ("USAGE:% s filename / n", * argv); exit (0);} __Try {hfile = cretefile (argv [1], generic_read, file_share_read, null, open_existing, 0, NULL); if (hdevice == invalid_handle_value) {Printf ("Error In Open File% S! / N", argv [1]); __leave;} WSPrintf (szdevicename, ".// A:"); hdevice = createfile (szDevicename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hDevice == INVALID_HANDLE_VALUE) {printf ( "Error in open floppy device!"); __leave;}
DeviceIoControl (hDevice, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, & count, NULL); DeviceIoControl (hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, & Geometry, sizeof (DISK_GEOMETRY), & count, NULL); szBuff = (LPSTR) HeapAlloc (GetProcessHeap ( ), Heap_zero_memory, geometry.bytespersector * 2); if (SZBuff == Null) {Printf ("Error In HeapAlloc!"); __LEAVE;} Bytes = 512 * 2; Bret = Readfile (Hfile, Szbuff, Bytes, & Bread, NULL); if (Bret == false || BREAD <512) {Printf ("Error In Read File!"); __Leave;} Printf ("% D Bytes Read from% S / N", Bread, Argv [1] ); Bret = Writefile (HDEVICE, SZBUFF, BYTES, & BREAD, NULL); if (Bret == False || BREAD <512) {Printf ("Error In Write File to Floppy!"); __LEAVE;} if (! Deviceiocontrol (hDevice, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, & count, NULL)) printf ( "DeviceIoControl (hDevice, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, & count, NULL) error / n!"); DeviceIoControl (hDevice, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, & Count, NULL); Printf ("Write Finished! / NBoot Sector in HEX: / N"); for (int J = 0, INT i = 0; I <512; i ) {Unsigned char CH = (unsigned char) SZBuff [i]; if (j == 8) Printf ("-"); if (j == 16) { Printf ("/ n"); j = 0;} J ; IF ("% 2X", CH); Else Printf ("% 2X", ch);} printf ("/ n") ;} __finally {if (szBuff = NULL!) HeapFree (GetProcessHeap (), HEAP_NO_SERIALIZE, szBuff); if (hDevice = NULL!) CloseHandle (hDevice); if (hFile = NULL!) CloseHandle (hFile);} return 0; } ------------------------------------- ------------------------------------------ DON '