桂林电子科技大学操作系统课程设计(project1)
一、项目设计目的 熟悉ELF文件格式,了解GeekOS系统如何将ELF格式的可执行程序装入到内存,建立内核进程并运行的实现技术。
二、项目设计要求
1、修改/geekos/elf.c文件:在函数Parse_ELF_Executable( )中添加代码,分析ELF格式的可执行文件(包括分析得出ELF文件头、程序头,获取可执行文件长度,代码段、数据段等信息),并填充Exe_Format数据结构中的域值。
2、在Linux环境下编译系统得到GeekOS镜像文件。
3、编写一个相应的bochs配置文件。
4、在bochs中运行GeekOS系统显示结果。
三、步骤
1、配置elf.c源文件,如下所示:
int Parse_ELF_Executable(char *exeFileData, ulong_t exeFileLength,struct Exe_Format *exeFormat)
{
int i;
elfHeader *head=(elfHeader*)exeFileData;
programHeader *proHeader=(programHeader *)(exeFileData+head->phoff);
KASSERT(exeFileData!=NULL);
KASSERT(exeFileLength>head->ehsize+head->phentsize*head->phnum);
KASSERT(head->entry%4==0);
exeFormat->numSegments=head->phnum;
exeFormat->entryAddr=head->entry;
for(i=0;i<head->phnum;i++)
{
exeFormat->segmentList[i].offsetInFile=proHeader->offset;
exeFormat->segmentList[i].lengthInFile=proHeader->fileSize;
exeFormat->segmentList[i].startAddress=proHeader->vaddr;
exeFormat->segmentList[i].sizeInMemory=proHeader->memSize;
exeFormat->segmentList[i].protFlags=proHeader->flags;
proHeader++;
}
return 0;
}
2.配置/build/.bochsrc文件,如下所示:
romimage:file=$BXSHARE/BIOS-bochs-latest
megs: 8
boot: a
floppya: 1_44=fd.img, status=inserted
ata0-master:type=disk, mode=flat, path="diskc.img", cylinders=0
log: ./bochs.out
3.按前一步骤配置segmet.h头文件下的参数,配置floppy.c 文件下的
static int Floppy_Get_Num_Blocks(struct Block_Device *dev)
{
struct Floppy_Drive *drive=NULL; //初始化变量
struct Floppy_Parameters *params;
KASSERT(dev->unit >= 0 && dev->unit <= 1);
drive = &s_driveTable[dev->unit];
params = drive->params;
KASSERT(params != 0);
return params->cylinders * params->heads * params->sectors;
}