• 大小: 1.63MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-15
  • 语言: 其他
  • 标签: nachos  实验四  

资源简介

本次实验的目的在于改造nachos内核以支持多道程序。熟悉nachos原有的内存分配机制,熟悉操作系统的虚存和内存的分页管理机制,熟悉系统调用。 附带实验报告,完整。

资源截图

代码片段和文件信息

/*
 Copyright (c) 1992 The Regents of the University of California.
 All rights reserved.  See copyright.h for copyright notice and limitation 
 of liability and disclaimer of warranty provisions.
 */

/* This program reads in a COFF format file and outputs a flat file --
 * the flat file can then be copied directly to virtual memory and executed.
 * In other words the various pieces of the object code are loaded at 
 * the appropriate offset in the flat file.
 *
 * Assumes coff file compiled with -N -T 0 to make sure it‘s not shared text.
 */

#define MAIN
#include “copyright.h“
#undef MAIN

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

/* NOTE -- once you have implemented large files it‘s ok to make this bigger! */
#define StackSize       1024      /* in bytes */
#define ReadStruct(fs)  Read(f(char *)&ssizeof(s))

extern char *malloc();

/* read and check for error */
void Read(int fd char *buf int nBytes)
{
    if (read(fd buf nBytes) != nBytes) {
fprintf(stderr “File is too short\n“);
exit(1);
    }
}

/* write and check for error */
void Write(int fd char *buf int nBytes)
{
    if (write(fd buf nBytes) != nBytes) {
fprintf(stderr “Unable to write file\n“);
exit(1);
    }
}

/* do the real work */
main (int argc char **argv)
{
    int fdIn fdOut numsections i top tmp;
    struct filehdr fileh;
    struct aouthdr systemh;
    struct scnhdr *sections;
    char *buffer;

    if (argc < 2) {
fprintf(stderr “Usage: %s  \n“ argv[0]);
exit(1);
    }
    
/* open the object file (input) */
    fdIn = open(argv[1] O_RDONLY 0);
    if (fdIn == -1) {
perror(argv[1]);
exit(1);
    }

/* open the flat file (output) */
    fdOut = open(argv[2] O_RDWR|O_CREAT|O_TRUNC 0666);
    if (fdIn == -1) {
perror(argv[2]);
exit(1);
    }
    
/* Read in the file header and check the magic number. */
    ReadStruct(fdInfileh);
    if (fileh.f_magic != MIPSELMAGIC) {
fprintf(stderr “File is not a MIPSEL COFF file\n“);
exit(1);
    }
    
/* Read in the system header and check the magic number */
    ReadStruct(fdInsystemh);
    if (systemh.magic != OMAGIC) {
fprintf(stderr “File is not a OMAGIC file\n“);
exit(1);
    }
    
/* Read in the section headers. */
    numsections = fileh.f_nscns;
    sections = (struct scnhdr *)malloc(fileh.f_nscns * sizeof(struct scnhdr));
    Read(fdIn (char *) sections fileh.f_nscns * sizeof(struct scnhdr));

 /* Copy the segments in */
    printf(“Loading %d sections:\n“ fileh.f_nscns);
    for (top = 0 i = 0; i < fileh.f_nscns; i++) {
printf(“\t\“%s\“ filepos 0x%x mempos 0x%x size 0x%x\n“
      sections[i].s_name sections[i].s_scnptr
      sections[i].s_paddr sections[i].s_size);
if ((sections[i].s_paddr + sections[i].s_size) > top)
    top = sections[i].s_paddr + sections[i].s_size;
if (strcm

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1132  2005-01-15 00:00  实验四\code\Makefile

     文件       4345  2009-07-11 10:37  实验四\code\Makefile.common

     文件        744  2002-01-09 00:00  实验四\code\Makefile.dep

     文件       2314  1993-11-19 00:00  实验四\code\bin\coff.h

     文件       3558  1993-10-04 00:00  实验四\code\bin\coff2flat.c

     文件      13158  2009-07-11 01:20  实验四\code\bin\coff2noff

     文件       6856  1994-01-12 00:00  实验四\code\bin\coff2noff.c

     文件       9740  2009-07-11 01:20  实验四\code\bin\coff2noff.o

     文件       3905  1993-10-04 00:00  实验四\code\bin\d.c

     文件       3652  1993-10-04 00:00  实验四\code\bin\disasm.c

     文件       1780  1993-10-04 00:00  实验四\code\bin\encode.h

     文件      11666  1993-10-04 00:00  实验四\code\bin\execute.c

     文件        120  1993-11-19 00:00  实验四\code\bin\halt

     文件        678  1993-10-04 00:00  实验四\code\bin\instr.h

     文件       1041  1993-10-04 00:00  实验四\code\bin\int.h

     文件       3607  1993-10-04 00:00  实验四\code\bin\main.c

     文件        965  2002-01-09 00:00  实验四\code\bin\Makefile

     文件        787  1993-11-20 00:00  实验四\code\bin\noff.h

     文件       1346  1993-10-04 00:00  实验四\code\bin\opstrings.c

     文件       5725  1994-03-02 00:00  实验四\code\bin\out.c

     文件       2703  1993-10-04 00:00  实验四\code\bin\system.c

     文件      50760  2009-07-11 10:56  实验四\code\filesys\addrspace.o

     文件      10312  2009-07-11 01:19  实验四\code\filesys\bitmap.o

     文件      11316  2009-07-11 10:57  实验四\code\filesys\console.o

     文件       6247  1994-02-01 00:00  实验四\code\filesys\directory.cc

     文件       2878  1993-11-19 00:00  实验四\code\filesys\directory.h

     文件      10392  2009-07-11 01:19  实验四\code\filesys\directory.o

     文件      15284  2009-07-11 10:57  实验四\code\filesys\disk.o

     文件      50672  2009-07-11 10:57  实验四\code\filesys\exception.o

     文件       5028  1994-02-01 00:00  实验四\code\filesys\filehdr.cc

............此处省略270个文件信息

评论

共有 条评论