Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
M
mkimage
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
mkimage
提交
6e63c5ce
提交
6e63c5ce
6月 29, 2020
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Initial commit
上级
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
162 行增加
和
0 行删除
+162
-0
console.c
console.c
+120
-0
console.h
console.h
+9
-0
mkimage.oslproj
mkimage.oslproj
+33
-0
mkimage.puo
mkimage.puo
+0
-0
没有找到文件。
console.c
0 → 100644
浏览文件 @
6e63c5ce
#include <memory.h>
#include <stdio.h>
#define BUFFER_SIZE 2048
#define SECTOR_SIZE 512 // 软盘扇区大小
unsigned
char
ucBuffer
[
BUFFER_SIZE
];
unsigned
char
ucBuffer2
[
SECTOR_SIZE
];
/*
*三个文件在软盘中的扇区分布图*
+-----------------------------------------------+
| | | |
| boot | loader | kernel.dll |
| | | |
+-----------------------------------------------+
扇区: 0 1-4 5-N
*/
int
main
(
int
argc
,
char
*
argv
[])
{
// 这里必须是 5
if
(
5
!=
argc
)
{
printf
(
"mkimage parameter error.
\n
Usage: mkimage.exe bootsect setup system.
\n
"
);
return
1
;
}
//
// 打开镜像文件
//
FILE
*
pImageFile
=
fopen
(
argv
[
4
],
"wb"
);
if
(
NULL
==
pImageFile
)
{
printf
(
"Createing %s failed
\n
"
,
argv
[
4
]);
return
1
;
}
//
// 读取第一个文件 boot.bin,并写入镜像的第 0 扇区
//
FILE
*
pBootFile
=
fopen
(
argv
[
1
],
"rb"
);
if
(
NULL
==
pBootFile
)
{
printf
(
"Unable to open %s file
\n
"
,
argv
[
1
]);
fclose
(
pImageFile
);
return
1
;
}
fread
(
ucBuffer
,
sizeof
(
unsigned
char
),
SECTOR_SIZE
,
pBootFile
);
int
iNum
=
fwrite
(
ucBuffer
,
sizeof
(
unsigned
char
),
SECTOR_SIZE
,
pImageFile
);
printf
(
"%s 被成功写入 %s! 一共写入 %d 字节
\n
"
,
argv
[
1
],
argv
[
4
],
iNum
);
fclose
(
pBootFile
);
//
// 读取第二个文件 loader.bin,并写入镜像的第 1 - 4 扇区
//
// 将缓冲区清空
memset
(
ucBuffer
,
0
,
BUFFER_SIZE
);
FILE
*
pLoaderFile
=
fopen
(
argv
[
2
],
"rb"
);
if
(
NULL
==
pLoaderFile
)
{
printf
(
"Unable to open file %s
\n
"
,
argv
[
2
]);
fclose
(
pImageFile
);
return
1
;
}
fread
(
ucBuffer
,
sizeof
(
unsigned
char
),
BUFFER_SIZE
,
pLoaderFile
);
iNum
=
fwrite
(
ucBuffer
,
sizeof
(
unsigned
char
),
BUFFER_SIZE
,
pImageFile
);
printf
(
"%s 被成功写入 %s! 一共写入 %d 字节
\n
"
,
argv
[
2
],
argv
[
4
],
iNum
);
fclose
(
pLoaderFile
);
//
// 读取第三个文件 kernel.dll,从镜像的第5扇区开始写
//
// 将缓冲区清空
memset
(
ucBuffer
,
0
,
BUFFER_SIZE
);
FILE
*
pSystemFile
=
fopen
(
argv
[
3
],
"rb"
);
if
(
NULL
==
pSystemFile
)
{
printf
(
"Unable to open file %s
\n
"
,
argv
[
3
]);
fclose
(
pImageFile
);
return
1
;
}
int
i
;
for
(
i
=
0
;
(
iNum
=
fread
(
ucBuffer
,
sizeof
(
unsigned
char
),
BUFFER_SIZE
,
pSystemFile
))
>
0
;
i
+=
iNum
)
fwrite
(
ucBuffer
,
sizeof
(
unsigned
char
),
iNum
,
pImageFile
);
printf
(
"%s 被成功写入 %s! 一共写入 %d 字节
\n
"
,
argv
[
3
],
argv
[
4
],
i
);
fclose
(
pSystemFile
);
// 因为Bochs要求加载的镜像文件必须是512字节的整数倍,因此需要计算,将kernel文件后面也填充大512字节的整数倍
// 因为kernel文件大小将近300k,因此计算出kernel与300k的差,然后进行字节填充即可
unsigned
char
s
=
0
;
int
j
=
0
;
int
fillcount
=
307200
-
i
;
for
(;
j
<
fillcount
;
j
++
)
{
fwrite
(
&
s
,
sizeof
(
unsigned
char
),
1
,
pImageFile
);
}
// Bochs 对加载的镜像大小有一定要求,因此将三个文件写到镜像后,再填充一些内容
// 如在文件后填充512个扇区的内容
memset
(
ucBuffer2
,
0
,
SECTOR_SIZE
);
int
m
=
0
;
for
(;
m
<
512
;
m
++
)
{
fwrite
(
ucBuffer2
,
512
,
1
,
pImageFile
);
}
fclose
(
pImageFile
);
return
0
;
}
console.h
0 → 100644
浏览文件 @
6e63c5ce
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
#include <stdio.h>
/* TODO: 在此处引用程序需要的其他头文件 */
#endif
/* _CONSOLE_H_ */
mkimage.oslproj
0 → 100644
浏览文件 @
6e63c5ce
<?xml version="1.0" encoding="gb2312"?>
<OSLProject
Version=
"1.00"
Name=
"mkimage"
SubjectID=
"1580a23c-aa04-4cf3-8cca-488dc577df8d"
IncrementalUpload=
"0"
>
<Configurations>
<Configuration
Name=
"Debug"
>
<Tool
Name=
"PreBuildEventTool"
/>
<Tool
Name=
"CustomBuildTool"
/>
<Tool
Name=
"GCCCompilerTool"
PreprocessorDefinitions=
"_DEBUG"
GenerateDebugInformation=
"-1"
/>
<Tool
Name=
"NASMAssemblerTool"
/>
<Tool
Name=
"PreLinkEventTool"
/>
<Tool
Name=
"GCCLinkerTool"
/>
<Tool
Name=
"PostBuildEventTool"
/>
</Configuration>
<Configuration
Name=
"Release"
>
<Tool
Name=
"PreBuildEventTool"
/>
<Tool
Name=
"CustomBuildTool"
/>
<Tool
Name=
"GCCCompilerTool"
PreprocessorDefinitions=
"NDEBUG"
/>
<Tool
Name=
"NASMAssemblerTool"
/>
<Tool
Name=
"PreLinkEventTool"
/>
<Tool
Name=
"GCCLinkerTool"
/>
<Tool
Name=
"PostBuildEventTool"
/>
</Configuration>
</Configurations>
<Files>
<Filter
Name=
"ͷļ"
Filter=
"h;hpp;hxx"
>
<File
RelativePath=
".\console.h"
>
</File>
</Filter>
<Filter
Name=
"Դļ"
Filter=
"cpp;c;cc;cxx"
>
<File
RelativePath=
".\console.c"
>
</File>
</Filter>
</Files>
</OSLProject>
mkimage.puo
0 → 100644
浏览文件 @
6e63c5ce
添加文件
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论