📄 fm.c
字号:
/************************************************************************/
/* */
/* Copyright 1990-1992 by Accelerated Technology */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are */
/* governed by the license agreement. The buyer or recipient of this */
/* package, implicitly accepts the terms of the license. */
/* */
/************************************************************************/
/************************************************************************/
/* */
/* FILE DESCRIPTION */
/* */
/* This file contains routines that facilitate memory partition */
/* management. */
/* */
/* ROUTINES */
/* */
/* FM_Initialize Fixed Memory Initialization */
/* FM_Place_On_List Place on a list */
/* FM_Remove_From_List Remove from a list */
/* FM_Allocate_Partition Get a partition */
/* FM_Deallocate_Partition Free a partition */
/* FM_Wait_For_Partition Wait to get a partition */
/* FM_Max_Partitions Returns maximum partition ID*/
/* FM_Available Returns free partition count*/
/* */
/* NOTES */
/* */
/* Routines except for FM_Max_partitions and FM_Available expect */
/* interrupts are locked out upon invocation. */
/* */
/************************************************************************/
/* Define necessary include files. */
#include "nu_defs.h" /* General constants */
#include "in_extr.h" /* Initialize references */
#include "fm_defs.h" /* Data structure defns */
#include "sk_extr.h" /* Scheduler routine defs */
/* Define global data structures to the partition manager. */
/* The pointer "FM_PCB_List" is used to point to the list of
sequentially allocated Partition Control blocks. */
struct FM_BLOCK_CONTROL_STRUCT *FM_PCB_List;
/* The signed variable "FM_Total_Partitions" contains the total number of
system partition types, as derived from the partition definition list. */
signed int FM_Total_Partitions;
/* Define internal function prototypes. */
void FM_Place_On_List(struct FM_LIST_STRUCT **ptr_head_ptr,
struct FM_LIST_STRUCT **ptr_tail_ptr,
struct FM_LIST_STRUCT *block_ptr);
void FM_Remove_From_List(struct FM_LIST_STRUCT **ptr_head_ptr,
struct FM_LIST_STRUCT **ptr_tail_ptr,
struct FM_LIST_STRUCT *block_ptr);
/************************************************************************/
/* */
/* FUNCTION "FM_Initialize" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function is used to allocate and initialize all of the */
/* partition control blocks and the total number of partitions */
/* variable. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* INP_Initialize High level initialization */
/* */
/* ROUTINES CALLED */
/* */
/* FM_Place_On_List Put on a linked list */
/* INP_Memory_Alloc Allocate initial memory */
/* IND_Major_System_Error System error */
/* */
/* INPUTS */
/* */
/* IN_System_Partitions Partition definitions */
/* */
/* OUTPUTS */
/* */
/* FM_PCB_List[] Partition Control Blocks */
/* FM_Total_Partitions Total number of partitions */
/* */
/************************************************************************/
void FM_Initialize(struct IN_FIXED_PARTITION_STRUCT *partition_list)
{
int i; /* Working variable */
int j; /* Working variable */
int bytes; /* Number of bytes to alloc */
struct FM_BLOCK_HEADER_STRUCT
*partition_ptr; /* Pointer to the partition */
void FM_Place_On_List(); /* Defn of procedure */
/* Initialize the partition management variables. */
FM_Total_Partitions = 0; /* Initially, no partitions */
/* Figure out how many partitions there are in the system. */
while (partition_list[FM_Total_Partitions].in_partition_size !=
END_OF_LIST)
{
/* Increment the total partition type count. */
FM_Total_Partitions++;
}
if (FM_Total_Partitions)
{
/* Allocate memory for all of the PCBs. */
bytes = sizeof(struct FM_BLOCK_CONTROL_STRUCT) * FM_Total_Partitions;
FM_PCB_List = (struct FM_BLOCK_CONTROL_STRUCT *)
INP_Memory_Alloc(bytes);
}
/* Initialize each PCB. This includes allocation of the actual partition
area. */
for (i = 0; i < FM_Total_Partitions; i++)
{
/* Initialize the PCB entry. Initially, there are no tasks waiting
for the partition and there are no partitions yet available. */
FM_PCB_List[i].fm_available_head = NU_NULL;
FM_PCB_List[i].fm_available_tail = NU_NULL;
FM_PCB_List[i].fm_alloc_wait_head = NU_NULL;
FM_PCB_List[i].fm_alloc_wait_tail = NU_NULL;
/* Check for an invalid partition size. */
if (partition_list[i].in_partition_size == 0)
IND_Major_System_Error(NU_PARTITION_SIZE);
/* Save off the number of partitions. */
FM_PCB_List[i].fm_free_partitions =
partition_list[i].in_partition_count;
/* Allocate the memory required for all of the partitions. */
for (j = 0; j < partition_list[i].in_partition_count; j++)
{
/* Allocate the memory for the partition. */
bytes = sizeof(struct FM_BLOCK_HEADER_STRUCT) +
(partition_list[i].in_partition_size * sizeof(unsigned int));
partition_ptr = (struct FM_BLOCK_HEADER_STRUCT *)
INP_Memory_Alloc(bytes);
/* Initialize the partition header. */
partition_ptr -> fm_pattern_1 = TOP_PATTERN;
partition_ptr -> fm_next_block = NU_NULL;
partition_ptr -> fm_prev_block = NU_NULL;
partition_ptr -> fm_task_id = NU_SYSTEM;
partition_ptr -> fm_in_use = NU_FALSE;
partition_ptr -> fm_partition_id= i;
partition_ptr -> fm_pattern_2 = BOTTOM_PATTERN;
/* Place the partition on the available list by calling
FM_Place_On_List. */
FM_Place_On_List(
(struct FM_LIST_STRUCT **) &(FM_PCB_List[i].fm_available_head),
(struct FM_LIST_STRUCT **) &(FM_PCB_List[i].fm_available_tail),
(struct FM_LIST_STRUCT *) partition_ptr);
}
}
} /* end of FM_Initialize */
/************************************************************************/
/* */
/* FUNCTION "FM_Place_On_List" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function is used to link a structure on a specified */
/* linked list. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* FM_Wait_For_Partition Wait for a partition */
/* FM_Deallocate_Partition Deallocate partition */
/* */
/* ROUTINES CALLED */
/* */
/* None */
/* */
/* INPUTS */
/* */
/* ptr_head_ptr Pointer to list head ptr */
/* ptr_tail_ptr Pointer to list tail ptr */
/* block_ptr Pointer to suspend block */
/* */
/* OUTPUTS */
/* */
/* Linked List */
/* */
/************************************************************************/
void FM_Place_On_List(struct FM_LIST_STRUCT **ptr_head_ptr,
struct FM_LIST_STRUCT **ptr_tail_ptr,
struct FM_LIST_STRUCT *block_ptr)
{
/* Determine if there is another link block to update. */
if (*ptr_tail_ptr != NU_NULL)
{
/* Yup, there are others currently on the list, place the new
block request at the end. */
(*ptr_tail_ptr) -> fm_next_ptr = block_ptr;
block_ptr -> fm_prev_ptr = *ptr_tail_ptr;
block_ptr -> fm_next_ptr = NU_NULL;
*ptr_tail_ptr = block_ptr;
}
else
{
/* Place the request right up front. */
*ptr_head_ptr = block_ptr;
*ptr_tail_ptr = block_ptr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -