XINU
ptinit.c
Go to the documentation of this file.
1 
5 #include <xinu.h>
6 
8 struct ptnode *ptfree;
13 
25 {
26  int32 i; /* Runs through the port table */
27  struct ptnode *next, *curr; /* Used to build a free list */
28 
29  /* Allocate memory for all messages on all ports */
30 
31  ptfree = (struct ptnode *)getmem(maxmsgs * sizeof(struct ptnode));
32  if (ptfree == (struct ptnode *)SYSERR)
33  {
34  panic("ptinit - insufficient memory");
35  }
36 
37  /* Initialize all port table entries to free */
38 
39  for (i = 0; i < NPORTS; i++)
40  {
41  porttab[i].ptstate = PT_FREE;
42  porttab[i].ptseq = 0;
43  }
44  ptnextid = 0;
45 
46  /* Create a free list of message nodes linked together */
47 
48  for (curr = next = ptfree; --maxmsgs > 0; curr = next)
49  {
50  curr->ptnext = ++next;
51  }
52 
53  /* Set the pointer in the final node to NULL */
54 
55  curr->ptnext = NULL;
56  return OK;
57 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
struct ptentry porttab[NPORTS]
ポートテーブルエントリ
Definition: ptinit.c:10
ポートテーブルエントリ
Definition: ports.h:33
全てのシステムヘッダファイルをインクルードする。
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
メッセージリストのノード
Definition: ports.h:21
syscall ptinit(int32 maxmsgs)
全てのポートを初期化する。
Definition: ptinit.c:24
#define NPORTS
ポートの最大数
Definition: ports.h:7
struct ptnode * ptfree
フリーメッセージノードのリスト
Definition: ptinit.c:8
struct ptnode * ptnext
メッセージリストの次のノードへのポインタ
Definition: ports.h:26
uint16 ptstate
ポート状態(FREE/LIMBO/ALLOC)
Definition: ports.h:40
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
#define PT_FREE
ポートがFREE状態
Definition: ports.h:11
int32 syscall
システムコール関数 返り値の型
Definition: kernel.h:47
int32 ptnextid
次に試みるテーブルエントリ
Definition: ptinit.c:12
int32 ptseq
生成時に変更されたシーケンス
Definition: ports.h:44
char * getmem(uint32)
ヒープ領域を割り当て、最下位のワードアドレスを返す。
Definition: getmem.c:25