分享
 
 
 

Windows下将linux启动代码写入磁盘

王朝system·作者佚名  2007-02-01
窄屏简体版  字體: |||超大  

1。write.c。此文件利用biosdisk可以写入软盘的任何指定扇区

#include<stdio.h>

#define SEC_MAX 1024

#define RETRY_MAX 5

#define TRACK_NUM 80 /*track number of a floppy disk*/

#define TR_SEC_NUM 18 /*sector number per track per head*/

main()

{

unsigned char buffer[512];

FILE *pFile=NULL;

int nReturn,nSec,nRetry; /*nSec is aready write sector number*/

unsigned char nSread,nTrack,nHead; /*where to write or read from floppy disk*/

if((pFile=fopen("sec3.exe","rb"))==NULL)

{

printf("\nfopen fail!");

return;

}

nSec=0;

nSread=6;

nTrack=0;

nHead=0;

while(nSec<SEC_MAX)

{

/*read sector data from file and if read error retry and then return*/

memset(buffer,0,512);

nRetry=0;

nReturn=0;

while(nReturn!=512)

{

fseek(pFile,0x200+512L*nSec,0); /*seek to where to read,there must be set long*/

nReturn=fread(buffer,1,512,pFile);

if(nRetry>RETRY_MAX) /*if error then return*/

{

if(nReturn>1)

{

;printf("\nRead file Error.Mybe get the end of file(sec=%d,nReturn=%x,nTrack=%x,nHead=%x,nSread=%x) !",nSec,nReturn,nTrack,nHead,nSread);

printf("\nRead file Error.Mybe get the end of file(sec=%d,nReturn=%x) !",nSec,nReturn);

nSec=SEC_MAX; /*get end of the file,so after write to disk,will return */

break;

}

else

{

printf("\nRead file Error.Mybe read error(sec=%d,nReturn=%x) !",nSec,nReturn);

fclose(pFile);

return;

}

}

nRetry++;

}

/*write data from buffer and if write error retry and then return*/

nRetry=0;

nReturn=1;

while(nReturn!=0)

{

nReturn=biosdisk(3, /*cmd=3,write*/

0, /*driver=0,A flopy disk*/

nHead, /*head*/

nTrack, /*track*/

nSread, /*setor*/

1,

buffer);

if(nRetry>RETRY_MAX) /*if error then return*/

{

printf("\nbiosdisk return:%d,head(%d),track(%d),sector(%d)",nReturn,nHead,nTrack,nSread);

fclose(pFile);

return;

}

nRetry++;

}

/*adjust the parameters*/

nSec++; /**/

if(++nSread>18)

{

nSread=1;

if(nHead==0) /*read current track on another head*/

{

nHead=1;

}

else /*nHead==1,read next track*/

{

nHead=0;

nTrack++;

}

}

}

fclose(pFile);

}

2。read.c.此文件利用biosdisk可以读软盘的任何指定扇区。

#include<stdio.h>

#define SEC_MAX 41

#define RETRY_MAX 5

#define TRACK_NUM 80 /*track number of a floppy disk*/

#define TR_SEC_NUM 18 /*sector number per track per head*/

main()

{

unsigned char buffer[512];

FILE *pFile=NULL;

int nReturn,nSec,nRetry; /*nSec is aready write sector number*/

unsigned char nSread,nTrack,nHead; /*where to write or read from floppy disk*/

if((pFile=fopen("sec3.bin","wb"))==NULL)

{

printf("\nfopen fail!");

return;

}

/*seek to head and write 0x200*/

fseek(pFile,0,0);

memset(buffer,0,512);

fwrite(buffer,1,512,pFile);

nSec=0;

nSread=6;

nTrack=0;

nHead=0;

while(nSec<SEC_MAX)

{

/*read data from disk and if write error retry and then return*/

memset(buffer,0,512);

nRetry=0;

nReturn=1;

while(nReturn!=0)

{

nReturn=biosdisk(2, /*cmd=3,read*/

0, /*driver=0,A flopy disk*/

nHead, /*head*/

nTrack, /*track*/

nSread, /*setor*/

1,

buffer);

if(nRetry>RETRY_MAX) /*if error then return*/

{

printf("\nbiosdisk return:%d,head(%d),track(%d),sector(%d)",nReturn,nHead,nTrack,nSread);

fclose(pFile);

return;

}

nRetry++;

}

/*read sector data from file and if read error retry and then return*/

nRetry=0;

nReturn=0;

while(nReturn!=512)

{

fseek(pFile,0x200+512*nSec,0); /*seek to where to read*/

nReturn=fwrite(buffer,1,512,pFile);

if(nRetry>RETRY_MAX) /*if error then return*/

{

if(nReturn>1)

{

printf("\nRead file Error.Mybe get the end of file(sec=%d,nReturn=%x,nTrack=%x,nHead=%x,nSread=%x) !",nSec,nReturn,nTrack,nHead,nSread);

nSec=SEC_MAX; /*get end of the file,so after write to disk,will return */

break;

}

else

{

printf("\nRead file Error.Mybe read error(sec=%d,nReturn=%x) !",nSec,nReturn);

fclose(pFile);

return;

}

}

nRetry++;

}

/*adjust the parameters*/

nSec++; /**/

if(++nSread>18)

{

nSread=1;

if(nHead==0) /*read current track on another head*/

{

nHead=1;

}

else /*nHead==1,read next track*/

{

nHead=0;

nTrack++;

}

}

}

fclose(pFile);

}

3。merge.c.此文件可以合并exe文件。编写原因是:如果想把head.asm中的main函数分出来成为一个单独的文件,那么我想把这个分出来的文件编译连接后于head.exe和为一体写入软盘,就需要这个程序将二者合并、写入软盘。

#include <stdio.h>

#include <stdlib.h>

#define RETRY_MAX 5

#define SEC_MAX 1024

main()

{

unsigned char buffer[512];

FILE *pFile3=NULL,*pFileM=NULL,*pFileB=NULL;

int nReturn,nRetry,nSec,nByte;

unsigned char bRun;

/*+++++++++++ first,copy code from sec3.exe to sec3.bin ++++++++++++*/

/*=======open two file-sec3.exe and sec3.bin=======*/

if((pFile3=fopen("sec3.exe","rb"))==NULL)

{

printf("\nfopen fail---file:sec3.exe!");

return;

}

if((pFileB=fopen("sec3.bin","wb+"))==NULL)

{

printf("\nfopen fail***file:sec3.bin!");

fclose(pFile3);

return;

}

/*=======copy code from sec3.exe to sec3.bin========*/

nSec=0;

bRun=1; /*bRun control the read loop*/

while(bRun)

{

/*read 512 data from file and if read error retry and then return*/

memset(buffer,0,512);

nRetry=0;

nReturn=0;

while(nReturn!=512)

{

fseek(pFile3,0x0000+512L*nSec,0); /*seek to where to read,and there 512L must be long*/

nReturn=fread(buffer,1,512,pFile3);

if(nRetry>RETRY_MAX) /*if error then return*/

{

printf("\nRead file(sec3.exe).Get the end of file(sec=%d,nReturn=%x)!",nSec,nReturn);

bRun=0; /*get end of the file,so after write to file sec3.exe,will return */

break;

}

nRetry++;

}

nByte=nReturn;

/*write 512 data to file and if write error retry and then return*/

nRetry=0;

nReturn=0;

while(nReturn!=nByte)

{

fseek(pFileB,0x0000+512L*nSec,0); /*seek to where to write,and there 512L is long*/

nReturn=fwrite(buffer,1,nByte,pFileB); /*will write 512B or mor less*/

if(nRetry>RETRY_MAX) /*if error then return*/

{

if(nReturn>1)

{

printf("\n**Write file Error.Mybe get the end of file(sec=%d,nReturn=%x)!",nSec,nReturn);

break;

}

else

{

printf("\n**File write error(sec=%d,nReturn=%x)!",nSec,nReturn);

fclose(pFile3);

fclose(pFileB);

return;

}

}

nRetry++;

}

nSec++;

}

/*close sec3.exe file*/

fclose(pFile3);

/*+++++++++++ secode,merge code from main.exe to sec3.bin ++++++++++++*/

/*=======open file-main.exe and sec3.bin=======*/

if((pFileM=fopen("main.exe","rb"))==NULL)

{

printf("\nfopen fail++++file:main.exe!");

fclose(pFileB);

return;

}

/*=======copy code from main.exe to sec3.bin========*/

nSec=0;

bRun=1; /*bRun control the read loop*/

while(bRun)

{

/*read 512 data from file and if read error retry and then return*/

memset(buffer,0,512);

nRetry=0;

nReturn=0;

while(nReturn!=512)

{

fseek(pFileM,0x7200+512L*nSec,0); /*seek to where to read*/

nReturn=fread(buffer,1,512,pFileM);

if(nRetry>RETRY_MAX) /*if error then return*/

{

printf("\nRead file(main.exe).Get the end of file(sec=%d,nReturn=%x)!",nSec,nReturn);

bRun=0; /*get end of the file,so after write to file sec3.exe,will break while */

break;

}

nRetry++;

}

nByte=nReturn;

/*write 512 data to file and if write error retry and then return*/

nRetry=0;

nReturn=0;

while(nReturn!=nByte)

{

fseek(pFileB,0x7200+512L*nSec,0); /*seek to where to write*/

nReturn=fwrite(buffer,1,nByte,pFileB); /*will write 512B or mor less*/

if(nRetry>RETRY_MAX) /*if error then return*/

{

if(nReturn>1)

{

printf("\n**Write file Error.Mybe get the end of file(sec=%d,nReturn=%x)!\n",nSec,nReturn);

break;

}

else

{

printf("\n**File write error(sec=%d,nReturn=%x)!",nSec,nReturn);

fclose(pFileB);

fclose(pFileM);

return;

}

}

nRetry++;

}

nSec++;

}

/*close main.exe file*/

fclose(pFileM);

/*delete and rename*/

fclose(pFileB);

system("del SEC3.EXE");

system("rename sec3.bin sec3.exe");

system("write3");

return;

}

好了,到此为止,linux的启动汇编代码就可以在windows下用tasm+tlink编译连接,用写入程序写入软盘来运行了。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有