📄 sys.h
字号:
/****************************************************************************** * sys.h * This file is part of "Assignment 2: Memory Management" * Copyright (C) 2008 - c506001 (email: c506001@cse.hcmut.edu.vn ) * * Note: * ----- * These codes are used for references, but not complete. Students can modified * them to satisfy the requirements. * * Content: * -------- * The include file: struct System, struct Task * * System and Networking Department * Faculty of Computer Science and Engineering * Ho Chi Minh City University of Technology ******************************************************************************/#ifndef __MEM_H__#define __MEM_H__#include <stdio.h>// Declaration format of virtual address#define N_SECTION_BITS 10 // 10 bits for Page table level 1#define N_PAGE_BITS 10 // 10 bits for Page table level 2#define N_OFFSET_BITS 12 // 12 bits for offset (pagesize = 4KB)#define FREE 0#define INUSE 1#define START 0#define ACCESS 1#define FINISH 2#define VALID 1#define INVALID 0#define MAX_TASKS 100#define ERR_NO_FREE_FRAME (-1)/** * struct PageStatus: management information of page * @frame: frame (physical) used for this page * @state: state of this page - INVALID / VALID **/ struct PageStatus { int frame; int state; int lastAccessTime;};/** * struct PageTable: page table * @elems: elements **/struct PageTable { struct PageStatus elems[1 << N_PAGE_BITS];};/** * struct SectionTable: Section table * @elems: elements **/struct SectionTable { int elems[1 << N_SECTION_BITS];};/** * struct Task: management information of task. This is the PCB of task. **/struct Task { struct Task *next; struct Task *prev; int pid; struct PageTable pageTbl[1 << N_SECTION_BITS]; struct SectionTable sectionTbl[1]; int memSize;};/** * struct TaskList: a list of tasks (2 ways) * @first: the pointer to the first task in list * @nTasks: the number of tasks in list **/ struct TaskList{ struct Task *first; int nTasks;};/** * struct FrameStatus: management information of frame * @state: FREE or INUSE **/struct FrameStatus{ int state;
int lastAccessTime;};/** * struct System: * @frameStatus: a list of frame-states * @nFrames: the number of elements in frameStatus list * @frameSize: usually 4KB. * @taskList: list of executable tasks **/struct System { struct FrameStatus* frameStatus; /* FREE or INUSE */ int nFrames; /* constant */ struct TaskList taskList; int clock;};int addTask2List(struct TaskList *taskList, struct Task *task);int removeTask(struct TaskList *taskList, struct Task *task);struct PageStatus* getFrameFromMem(struct Task *task, int memAddr);struct PageStatus* getFrameFromPage(struct Task *task, int section, int page);int updatePage(struct PageStatus *page, int frame, int pid, int memAddr, FILE *outFile);struct PageStatus *findUnusedPage(struct Task *task);int initTask(struct Task *task);int allocFrames4Task(struct System *system, int pid, int memSize, FILE *outFile);int access2Mem(struct System *system, int pid, int memAddr, FILE *outFile);int finishTask(struct System *system, int pid, FILE *outFile);struct PageStatus* chooseVictimFrame(struct System *system, struct Task *task);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -