XINU
Macros | Functions
prototypes.h File Reference

関数のプロトタイプ宣言を集約したヘッダ More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define htonl(x)
 
#define htons(x)   ((0xff & ((x) >> 8)) | ((0xff & (x)) << 8))
 
#define ntohl(x)
 
#define ntohs(x)   ((0xff & ((x) >> 8)) | ((0xff & (x)) << 8))
 

Functions

void _mkinit (void)
 
void _ptclear (struct ptentry *, uint16, int32(*)(int32))
 ポートを用いたメッセージと待機中プロセスを解放する。 More...
 
status addargs (pid32, int32, int32[], int32, char *, void *)
 XINUシェルが作成したコマンドプロセスのスタックに引数argv(任意個)のローカルコピーを追加する。 More...
 
int32 am335x_eth_init (struct ethcblk *)
 
int32 arp_alloc (void)
 
void arp_hton (struct arppacket *)
 
void arp_in (struct arppacket *)
 
void arp_init (void)
 
void arp_ntoh (struct arppacket *)
 
status arp_resolve (uint32, byte[])
 
status ascdate (uint32, char *)
 
status bufinit (void)
 バッファプールデータ構造を初期化する。 More...
 
pri16 chprio (pid32, pri16)
 プロセスのスケジューリング優先度を変更する。 More...
 
uint32 clkcount (void)
 
interrupt clkhandler (void)
 
void clkinit (void)
 
void clkint (void)
 
syscall close (did32)
 
syscall control (did32, int32, int32, int32)
 
pid32 create (void *, uint32, pri16, char *, uint32,...)
 関数の実行を開始するプロセスを作成する。 More...
 
void ctxsw (void *, void *)
 コンテキストスイッチを行う(ctxsw.S に定義がある) More...
 
pid32 dequeue (qid16)
 プロセスキューテーブルからキューを削除し、リスト先頭のプロセスIDを返す。 More...
 
intmask disable (void)
 割り込み禁止(intr.Sに定義がある) More...
 
uint32 dnslookup (char *)
 
uint32 dot2ip (char *, uint32 *)
 
void enable (void)
 割り込み許可(intr.Sに定義がある) More...
 
pid32 enqueue (pid32, qid16)
 プロセスをプロセスキューテーブルの末尾に挿入する。 More...
 
void eth_hton (struct netpacket *)
 
void eth_ntoh (struct netpacket *)
 
int32 ethcontrol (struct dentry *, int32, int32, int32)
 
interrupt ethhandler (uint32)
 
int32 ethinit (struct dentry *)
 
int32 ethread (struct dentry *, void *, uint32)
 
int32 ethwrite (struct dentry *, void *, uint32)
 
void exception (int32, int32 *)
 
syscall freebuf (char *)
 バッファプールから取得したバッファを解放する。 More...
 
syscall freemem (char *, uint32)
 メモリブロックを解放し、ブロックを空きリストに戻す。 More...
 
char * getbuf (bpid32)
 事前に確保されたバッファプールからバッファを取得する。 More...
 
syscall getc (did32)
 
pid32 getfirst (qid16)
 キューの先頭からプロセスを取り出す。 More...
 
pid32 getitem (pid32)
 キューの任意の位置からプロセスを取り出す。 More...
 
pid32 getlast (qid16)
 キューの末尾からプロセスを取り出す。 More...
 
uint32 getlocalip (void)
 
char * getmem (uint32)
 ヒープ領域を割り当て、最下位のワードアドレスを返す。 More...
 
pid32 getpid (void)
 現在実行中のプロセスIDを返す。 More...
 
uint16 getport (void)
 
syscall getprio (pid32)
 プロセスのスケジューリング優先度を取得する。 More...
 
char * getstk (uint32)
 スタックメモリを割り当て、最上位のワードアドレスを返す。 More...
 
uint32 getticks (void)
 CPUリセット以降のclock tick数を取得する。 More...
 
status gettime (uint32 *)
 1970年1月1日からの経過時間(秒単位)にロケーション(時差)を反映した時間を返す。 More...
 
status getutime (uint32 *)
 
devcall gpiocontrol (struct dentry *, int32, int32, int32)
 
void gpiohandler (uint32)
 
devcall gpioinit (struct dentry *)
 
devcall gpioread (struct dentry *, char *, int32)
 
devcall gpioselect (uint32, uint32, uint32)
 
devcall gpiowrite (struct dentry *, char *, int32)
 
void halt (void)
 システムを停止させる(intr.Sに定義がある) More...
 
uint16 icmp_cksum (char *, int32)
 
void icmp_hton (struct netpacket *)
 
void icmp_in (struct netpacket *)
 
void icmp_init (void)
 
struct netpacketicmp_mkpkt (uint32, uint16, uint16, uint16, char *, int32)
 
void icmp_ntoh (struct netpacket *)
 
int32 icmp_recv (int32, char *, int32, uint32)
 
int32 icmp_register (uint32)
 
status icmp_release (int32)
 
status icmp_send (uint32, uint16, uint16, uint16, char *, int32)
 
int32 inb (int32)
 
syscall init (did32)
 デバイスとデバイスドライバを初期化する。 More...
 
int32 initevec (void)
 
int32 initintc (void)
 
int32 inl (int32)
 
status insert (pid32, qid16, int32)
 優先度に基づいて、キューにプロセスを挿入する。 More...
 
status insertd (pid32, qid16, int32)
 
int32 insw (int32, int32, int32)
 
int32 inw (int32)
 
devcall ioerr (void)
 ステータスとしてエラーを返す(デバイステーブルの"error"エントリに対して使用する)。 More...
 
devcall ionull (void)
 何もしない(デバイステーブルの"don't care"エントリに使用する) More...
 
status ip_enqueue (struct netpacket *)
 
void ip_hton (struct netpacket *)
 
void ip_in (struct netpacket *)
 
void ip_local (struct netpacket *)
 
void ip_ntoh (struct netpacket *)
 
status ip_out (struct netpacket *)
 
int32 ip_route (uint32)
 
status ip_send (struct netpacket *)
 
uint16 ipcksum (struct netpacket *)
 
process ipout (void)
 
syscall kill (pid32)
 指定のプロセスを終了させ、システムから終了させたプロセス情報を取り除く。 More...
 
int32 lexan (char *, int32, char *, int32 *, int32[], int32[])
 
dbid32 lfdballoc (struct lfdbfree *)
 
status lfdbfree (did32, dbid32)
 
status lfflush (struct lflcblk *)
 
int32 lfgetmode (char *)
 
ibid32 lfiballoc (void)
 
void lfibclear (struct lfiblk *, int32)
 
void lfibget (did32, ibid32, struct lfiblk *)
 
status lfibput (did32, ibid32, struct lfiblk *)
 
devcall lflclose (struct dentry *)
 
devcall lflcontrol (struct dentry *, int32, int32, int32)
 
devcall lflgetc (struct dentry *)
 
devcall lflinit (struct dentry *)
 
devcall lflputc (struct dentry *, char)
 
devcall lflread (struct dentry *, char *, int32)
 
devcall lflseek (struct dentry *, uint32)
 
devcall lflwrite (struct dentry *, char *, int32)
 
status lfscheck (struct lfdir *)
 
status lfscreate (did32, ibid32, uint32)
 
status lfsetup (struct lflcblk *)
 
devcall lfsinit (struct dentry *)
 
devcall lfsopen (struct dentry *, char *, char *)
 
status lftruncate (struct lflcblk *)
 
devcall lpgetc (struct dentry *)
 
devcall lpinit (struct dentry *)
 
devcall lpopen (struct dentry *, char *, char *)
 
devcall lpputc (struct dentry *, char)
 
devcall lpread (struct dentry *, char *, int32)
 
devcall lpwrite (struct dentry *, char *, int32)
 
int32memcmp (void *, const void *, int32)
 
void * memcpy (void *, const void *, int32)
 メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。 More...
 
void * memset (void *, const int, int32)
 指定のByteブロックに対して、同じ値をNバイト分書き込む。 More...
 
bpid32 mkbufpool (int32, int32)
 バッファプール用のメモリを割り当て、バッファ同士をリンクする。 More...
 
syscall mount (char *, char *, did32)
 
status namcpy (char *, char *, int32)
 
status naminit (void)
 
int32 namlen (char *, int32)
 
devcall nammap (char *, char[], did32)
 
devcall namopen (struct dentry *, char *, char *)
 
did32 namrepl (char *, char[])
 
void net_init (void)
 
process netin (void)
 
process netout (void)
 
qid16 newqueue (void)
 グローバルキューテーブルにキューを割り当て、テーブルを初期化する。 More...
 
syscall open (did32, char *, char *)
 
int32 outb (int32, int32)
 
int32 outl (int32, int32)
 
int32 outsw (int32, int32, int32)
 
int32 outw (int32, int32)
 
void panic (char *)
 Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。 More...
 
int32 pci_init (void)
 
void pdump (struct netpacket *)
 
void pdumph (struct netpacket *)
 
void platinit (void)
 
int32 ptcount (int32)
 ポートを用いたメッセージ送受信において、メッセージ数を数える。 More...
 
syscall ptcreate (int32)
 未処理のメッセージを「カウント」できるポートを作成する。 More...
 
syscall ptdelete (int32, int32(*)(int32))
 ポートを削除し、待機中のプロセスとメッセージを解放する。 More...
 
syscall ptinit (int32)
 全てのポートを初期化する。 More...
 
uint32 ptrecv (int32)
 ポートからメッセージを受信する。受信前にメッセージが空の場合はブロッキングする。 More...
 
syscall ptreset (int32, int32(*)(int32))
 ポートをリセットを行う。 More...
 
syscall ptsend (int32, umsg32)
 メッセージをキューに追加する事によってポートへメッセージを送信する。 More...
 
syscall putc (did32, char)
 デバイスへ文字1Byteを送信する。 More...
 
devcall ramclose (struct dentry *)
 
devcall raminit (struct dentry *)
 
devcall ramopen (struct dentry *, char *, char *)
 
devcall ramread (struct dentry *, char *, int32)
 
devcall ramwrite (struct dentry *, char *, int32)
 
process rawin (void)
 
struct rdbuffrdsbufalloc (struct rdscblk *)
 
devcall rdsclose (struct dentry *)
 
status rdscomm (struct rd_msg_hdr *, int32, struct rd_msg_hdr *, int32, struct rdscblk *)
 
devcall rdscontrol (struct dentry *, int32, int32, int32)
 
devcall rdsinit (struct dentry *)
 
devcall rdsopen (struct dentry *, char *, char *)
 
void rdsprocess (struct rdscblk *)
 
devcall rdsread (struct dentry *, char *, int32)
 
devcall rdswrite (struct dentry *, char *, int32)
 
syscall read (did32, char *, uint32)
 
status ready (pid32)
 プロセスをCPUサービスの対象にする。 More...
 
umsg32 receive (void)
 メッセージの受信を待ち、受信後にreceive()の呼び出し者にメッセージを返す。 More...
 
umsg32 recvclr (void)
 受信メッセージをクリアし、待機している場合はメッセージを返す。 More...
 
umsg32 recvtime (int32)
 
void resched (void)
 最優先の適切なプロセスにCPU実行権を渡す。 More...
 
status resched_cntl (int32)
 再スケジューリングを延期させるか、もしくは許可させるかを制御する。 More...
 
void restore (intmask)
 
pri16 resume (pid32)
 プロセスを休止状態(サスペンド)からREADY状態に遷移させる。 More...
 
devcall rflclose (struct dentry *)
 
devcall rflgetc (struct dentry *)
 
devcall rflinit (struct dentry *)
 
devcall rflputc (struct dentry *, char)
 
devcall rflread (struct dentry *, char *, int32)
 
devcall rflseek (struct dentry *, uint32)
 
devcall rflwrite (struct dentry *, char *, int32)
 
int32 rfscomm (struct rf_msg_hdr *, int32, struct rf_msg_hdr *, int32)
 
devcall rfscontrol (struct dentry *, int32, int32, int32)
 
int32 rfsgetmode (char *)
 
devcall rfsinit (struct dentry *)
 
status rfsndmsg (uint16, char *)
 
devcall rfsopen (struct dentry *devptr, char *, char *)
 
syscall seek (did32, uint32)
 
syscall semcount (sid32)
 セマフォのカウント値を返す。 More...
 
sid32 semcreate (int32)
 未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。 More...
 
syscall semdelete (sid32)
 セマフォテーブルエントリを解放し、セマフォを削除する。 More...
 
syscall semreset (sid32, int32)
 セマフォカウントをリセットし、待機中のプロセスを全て解放する。 More...
 
syscall send (pid32, umsg32)
 プロセスにメッセージを送信し、受信側が待機状態の場合はREADY状態にする。 More...
 
int32 set_evec (uint32, uint32)
 
process shell (did32)
 
syscall signal (sid32)
 セマフォにシグナルを送り、待機プロセスがある場合は解除する。 More...
 
syscall signaln (sid32, int32)
 セマフォにシグナルをN回送り、N個の待機プロセスがある場合はそれらをREADY状態にする。 More...
 
syscall sleep (int32)
 
syscall sleepms (int32)
 
devcall spicontrol (struct dentry *, int32, int32, int32)
 
int32 spiinit (struct dentry *)
 
syscall suspend (pid32)
 プロセスを一時停止し、休止状態(サスペンド)に遷移させる。 More...
 
void trap (int32)
 
devcall ttycontrol (struct dentry *, int32, int32, int32)
 
devcall ttygetc (struct dentry *)
 
void ttyhandle_in (struct ttycblk *, struct uart_csreg *)
 
void ttyhandle_out (struct ttycblk *, struct uart_csreg *)
 
void ttyhandler (uint32)
 
devcall ttyinit (struct dentry *)
 
void ttykickout (struct uart_csreg *)
 
devcall ttyputc (struct dentry *, char)
 
devcall ttyread (struct dentry *, char *, int32)
 
devcall ttywrite (struct dentry *, char *, int32)
 
void udp_hton (struct netpacket *)
 
void udp_in (struct netpacket *)
 
void udp_init (void)
 
void udp_ntoh (struct netpacket *)
 
int32 udp_recv (uid32, char *, int32, uint32)
 
int32 udp_recvaddr (uid32, uint32 *, uint16 *, char *, int32, uint32)
 
uid32 udp_register (uint32, uint16, uint16)
 
status udp_release (uid32)
 
status udp_send (uid32, char *, int32)
 
status udp_sendto (uid32, uint32, uint16, char *, int32)
 
syscall unsleep (pid32)
 
void userret (void)
 プロセスが最上位の関数に戻る時に呼ばれる。現在のプロセスを終了させる。 More...
 
syscall wait (sid32)
 
void wakeup (void)
 
syscall write (did32, char *, uint32)
 
void xdone (void)
 最終プロセスの終了時、システム終了メッセージを表示する。 More...
 
syscall yield (void)
 CPU実行権を自発的に放棄する(タイムスライスを終了する)。 More...
 

Detailed Description

関数のプロトタイプ宣言を集約したヘッダ

Definition in file prototypes.h.

Macro Definition Documentation

◆ htonl

#define htonl (   x)
Value:
((((x) >> 24) & 0x000000ff) | (((x) >> 8) & 0x0000ff00) | \
(((x) << 8) & 0x00ff0000) | (((x) << 24) & 0xff000000))

Definition at line 620 of file prototypes.h.

Referenced by arp_hton(), dhcp_bld_bootp_msg(), ip_hton(), rdscomm(), rflread(), rflwrite(), rfscomm(), and rfsopen().

◆ htons

#define htons (   x)    ((0xff & ((x) >> 8)) | ((0xff & (x)) << 8))

◆ ntohl

#define ntohl (   x)
Value:
((((x) >> 24) & 0x000000ff) | (((x) >> 8) & 0x0000ff00) | \
(((x) << 8) & 0x00ff0000) | (((x) << 24) & 0xff000000))

Definition at line 623 of file prototypes.h.

Referenced by arp_ntoh(), dns_geta(), dnslookup(), getlocalip(), getutime(), ip_ntoh(), pdump(), rdscomm(), rflread(), rflwrite(), rfscomm(), rfscontrol(), and rfsndmsg().

◆ ntohs

#define ntohs (   x)    ((0xff & ((x) >> 8)) | ((0xff & (x)) << 8))

Function Documentation

◆ _mkinit()

void _mkinit ( void  )

◆ _ptclear()

void _ptclear ( struct ptentry ptptr,
uint16  newstate,
int32(*)(int32 dispose 
)

ポートを用いたメッセージと待機中プロセスを解放する。

Step1. ポートの状態をLIMBOとし、他のプロセスからポート使用不可とする。
Step2. ポートシーケンス番号をリセットする。
Step3. メッセージリストが空になるまで、各メッセージを処分する。
Step4. メッセージリスト全体をフリーリストとする。
Step5. 引数で指定されたポートクリア後の状態に応じて、処理を切り替える。
 ・PT_ALLOCの場合:ポートテーブルエントリの先頭と末尾をNULLを指す状態とし、送受信用セマフォをリセットする。
 ・上記以外の場合:送受信用セマフォを削除する。
Step6. ポート状態を引数で指定された状態に変更する。

Parameters
[in]ptptrクリア対象のポートテーブルエントリ
[in]newstateポートをクリアした後の新しい状態
[in]disposeメッセージ処分用の関数ポインタ
Note
ポート内部の関数をクリアまたはリセットするために、ptdeleteおよびreset経由で_ptclear()は使用される。
_ptclear()の呼び出しは、割り込みが無効であり、引数の有効性がチェックされている事を前提としている。

Definition at line 24 of file ptclear.c.

References NULL, PT_ALLOC, PT_LIMBO, ptfree, ptentry::pthead, ptentry::ptmaxcnt, ptnode::ptmsg, ptnode::ptnext, ptentry::ptrsem, ptentry::ptseq, ptentry::ptssem, ptentry::ptstate, ptentry::pttail, semdelete(), and semreset().

Referenced by ptdelete(), and ptreset().

25 {
26  struct ptnode *walk; /* Pointer to walk message list */
27 
28  /* Place port in limbo state while waiting processes are freed */
29 
30  ptptr->ptstate = PT_LIMBO;
31 
32  ptptr->ptseq++; /* Reset accession number */
33  walk = ptptr->pthead; /* First item on msg list */
34 
35  if (walk != NULL)
36  { /* If message list nonempty */
37 
38  /* Walk message list and dispose of each message */
39 
40  for (; walk != NULL; walk = walk->ptnext)
41  {
42  (*dispose)(walk->ptmsg);
43  }
44 
45  /* Link entire message list into the free list */
46 
47  (ptptr->pttail)->ptnext = ptfree;
48  ptfree = ptptr->pthead;
49  }
50 
51  if (newstate == PT_ALLOC)
52  {
53  ptptr->pttail = ptptr->pthead = NULL;
54  semreset(ptptr->ptssem, ptptr->ptmaxcnt);
55  semreset(ptptr->ptrsem, 0);
56  }
57  else
58  {
59  semdelete(ptptr->ptssem);
60  semdelete(ptptr->ptrsem);
61  }
62  ptptr->ptstate = newstate;
63  return;
64 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
#define PT_ALLOC
ポートが割り当てられた
Definition: ports.h:15
sid32 ptrsem
受信側セマフォ
Definition: ports.h:38
uint16 ptmaxcnt
ポートに挿入できる最大メッセージ数
Definition: ports.h:42
syscall semdelete(sid32)
セマフォテーブルエントリを解放し、セマフォを削除する。
Definition: semdelete.c:22
メッセージリストのノード
Definition: ports.h:21
#define PT_LIMBO
ポートが削除された、もしくはリセットされる
Definition: ports.h:13
struct ptnode * ptnext
メッセージリストの次のノードへのポインタ
Definition: ports.h:26
sid32 ptssem
送信側セマフォ
Definition: ports.h:36
uint16 ptstate
ポート状態(FREE/LIMBO/ALLOC)
Definition: ports.h:40
syscall semreset(sid32, int32)
セマフォカウントをリセットし、待機中のプロセスを全て解放する。
Definition: semreset.c:25
struct ptnode * pttail
メッセージリストの末尾ポインタ
Definition: ports.h:48
uint32 ptmsg
ワンワードのメッセージ
Definition: ports.h:24
struct ptnode * pthead
メッセージリストの先頭ポインタ
Definition: ports.h:46
int32 ptseq
生成時に変更されたシーケンス
Definition: ports.h:44
struct ptnode * ptfree
フリーノードリストのextern宣言
Definition: ptinit.c:8
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addargs()

status addargs ( pid32  pid,
int32  ntok,
int32  tok[],
int32  tlen,
char *  tokbuf,
void *  dummy 
)

XINUシェルが作成したコマンドプロセスのスタックに引数argv(任意個)のローカルコピーを追加する。

Step1. 割り込みを禁止する。
Step2. 「引数の数が0以下」もしくは「トークンバッファの中にあるデータの長さが0以下」であれば、
割り込み状態を復元し、処理を修正する。
Step3. args配列と引数文字列(トークンバッファ)を続けて格納するために、プロセススタックの最下位の場所を計算する。
4Byte単位での丸め計算も行うため、args配列はユーザスタック最下位かその次の4byteの倍数アドレスから始まる。
最下位アドレス:[トークン1へのポインタ][トークン2へのポインタ][NULL][トークン1][NULL][トークン2]...:最上位アドレス
Step4. 文字列は可変長のため、args配列を超えた最初の位置を計算する。
Step5. args配列に格納されたポインタ(各引数へのポインタ)に対して、文字列領域開始アドレスをオフセットとして加え、
スタック最下位から順に格納する。 Step6. args配列に格納されたポインタの後に、区切りとしてNULLを付与する。
Step7. 引数文字列をargs配列(+ NULL)を超えた位置にコピーする。
Step8. プロセススタック中の第2引数(XINUシェルがプロセスをcreate()した際にスタックに追加した引数であり、
引数dummyと同じアドレスを持つ)を探し、第2引数の内容をプロセススタック中のargs配列アドレスに置換する。
Step9. 割り込みを許可状態に復元する。

Parameters
[in]pid使用するプロセスID
[in]ntok引数の数
[in]tokトークンバッファの中にあるトークンのインデックス
[in]tlenトークンバッファの中にあるデータの長さ
[in]tokbufNULLで終わるトークン配列
[in,out]dummy生成時に使用されるダミー引数。引数の配列へのポインタで置き換える必要がある。
Returns

Definition at line 33 of file addargs.c.

References disable(), memcpy(), NULL, OK, proctab, procent::prstkbase, procent::prstklen, procent::prstkptr, restore(), and SYSERR.

Referenced by shell().

34 {
35  intmask mask; /* Saved interrupt mask */
36  struct procent *prptr; /* Ptr to process' table entry */
37  uint32 aloc; /* Argument location in process stack as an integer */
38  uint32 *argloc; /* Location in process's stack to place args vector */
39  char *argstr; /* Location in process's stack to place arg strings */
40  uint32 *search; /* pointer that searches for dummy argument on stack */
41  uint32 *aptr; /* Walks through args array */
42  int32 i; /* Index into tok array */
43 
44  mask = disable();
45 
46  /* Check argument count and data length */
47 
48  if ((ntok <= 0) || (tlen < 0))
49  {
50  restore(mask);
51  return SYSERR;
52  }
53 
54  prptr = &proctab[pid];
55 
56  /* Compute lowest location in the process stack where the */
57  /* args array will be stored followed by the argument */
58  /* strings */
59 
60  aloc = (uint32)(prptr->prstkbase - prptr->prstklen + sizeof(uint32));
61  argloc = (uint32 *)((aloc + 3) & ~0x3); /* round multiple of 4 */
62 
63  /* Compute the first location beyond args array for the strings */
64 
65  argstr = (char *)(argloc + (ntok + 1)); /* +1 for a null ptr */
66 
67  /* Set each location in the args vector to be the address of */
68  /* string area plus the offset of this argument */
69 
70  for (aptr = argloc, i = 0; i < ntok; i++)
71  {
72  *aptr++ = (uint32)(argstr + tok[i]);
73  }
74 
75  /* Add a null pointer to the args array */
76 
77  *aptr++ = (uint32)NULL;
78 
79  /* Copy the argument strings from tokbuf into process's stack */
80  /* just beyond the args vector */
81 
82  memcpy(aptr, tokbuf, tlen);
83 
84  /* Find the second argument in process's stack */
85 
86  for (search = (uint32 *)prptr->prstkptr;
87  search < (uint32 *)prptr->prstkbase; search++)
88  {
89 
90  /* If found, replace with the address of the args vector*/
91 
92  if (*search == (uint32)dummy)
93  {
94  *search = (uint32)argloc;
95  restore(mask);
96  return OK;
97  }
98  }
99 
100  /* Argument value not found on the stack - report an error */
101 
102  restore(mask);
103  return SYSERR;
104 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
uint32 prstklen
Bytesで表されたスタックの長さ(最大値。Byte)。
Definition: process.h:96
char * prstkbase
ランタイムスタックの基点(メモリ領域で最上位のアドレス)。
Definition: process.h:94
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
char * prstkptr
保存されたスタックポインタ。
Definition: process.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ am335x_eth_init()

int32 am335x_eth_init ( struct ethcblk )

◆ arp_alloc()

int32 arp_alloc ( void  )

Definition at line 298 of file arp.c.

References AR_FREE, AR_RESOLVED, ARP_SIZ, arpcache, arpentry::arstate, kprintf(), memset(), NULLCH, and SYSERR.

Referenced by arp_in(), and arp_resolve().

299 {
300  int32 slot; /* Slot in ARP cache */
301 
302  /* Search for a free slot */
303 
304  for (slot=0; slot < ARP_SIZ; slot++) {
305  if (arpcache[slot].arstate == AR_FREE) {
306  memset((char *)&arpcache[slot],
307  NULLCH, sizeof(struct arpentry));
308  return slot;
309  }
310  }
311 
312  /* Search for a resolved entry */
313 
314  for (slot=0; slot < ARP_SIZ; slot++) {
315  if (arpcache[slot].arstate == AR_RESOLVED) {
316  memset((char *)&arpcache[slot],
317  NULLCH, sizeof(struct arpentry));
318  return slot;
319  }
320  }
321 
322  /* At this point, all slots are pending (should not happen) */
323 
324  kprintf("ARP cache size exceeded\n");
325 
326  return SYSERR;
327 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define AR_FREE
ARPキャッシュエントリ状態:スロットが未使用
Definition: arp.h:27
#define ARP_SIZ
キャシュ中のエントリ数
Definition: arp.h:20
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct arpentry arpcache[ARP_SIZ]
ARPキャッシュエントリテーブル
Definition: arp.c:5
ARPキャッシュエントリ
Definition: arp.h:72
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
#define AR_RESOLVED
ARPキャッシュエントリ状態:エントリが正常
Definition: arp.h:31
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:
Here is the caller graph for this function:

◆ arp_hton()

void arp_hton ( struct arppacket )

Definition at line 348 of file arp.c.

References arppacket::arp_htype, arppacket::arp_op, arppacket::arp_ptype, arppacket::arp_sndpa, arppacket::arp_tarpa, htonl, and htons.

Referenced by arp_in(), and arp_resolve().

351 {
352  pktptr->arp_htype = htons(pktptr->arp_htype);
353  pktptr->arp_ptype = htons(pktptr->arp_ptype);
354  pktptr->arp_op = htons(pktptr->arp_op);
355  pktptr->arp_sndpa = htonl(pktptr->arp_sndpa);
356  pktptr->arp_tarpa = htonl(pktptr->arp_tarpa);
357 }
#define htonl(x)
Definition: prototypes.h:620
#define htons(x)
Definition: prototypes.h:619
Here is the caller graph for this function:

◆ arp_in()

void arp_in ( struct arppacket )

Definition at line 158 of file arp.c.

References AR_FREE, AR_PENDING, AR_RESOLVED, arpentry::arhaddr, arp_alloc(), arppacket::arp_ethdst, arppacket::arp_ethsrc, arppacket::arp_ethtype, ARP_HALEN, arppacket::arp_hlen, arp_hton(), ARP_HTYPE, arppacket::arp_htype, arp_ntoh(), arppacket::arp_op, ARP_OP_RPLY, ARP_PALEN, arppacket::arp_plen, ARP_PTYPE, arppacket::arp_ptype, ARP_SIZ, arppacket::arp_sndha, arppacket::arp_sndpa, arppacket::arp_tarha, arppacket::arp_tarpa, arpentry::arpaddr, arpcache, arpentry::arpid, arpentry::arstate, disable(), ETH_ARP, eth_hton(), ETHER0, network::ethucast, FALSE, freebuf(), network::ipucast, network::ipvalid, kprintf(), memcpy(), NetData, OK, restore(), send(), SYSERR, TRUE, and write().

Referenced by netin().

161 {
162  intmask mask; /* Saved interrupt mask */
163  struct arppacket apkt; /* Local packet buffer */
164  int32 slot; /* Slot in cache */
165  struct arpentry *arptr; /* Ptr to ARP cache entry */
166  bool8 found; /* Is the sender's address in */
167  /* the cache? */
168 
169  /* Convert packet from network order to host order */
170 
171  arp_ntoh(pktptr);
172 
173  /* Verify ARP is for IPv4 and Ethernet */
174 
175  if ( (pktptr->arp_htype != ARP_HTYPE) ||
176  (pktptr->arp_ptype != ARP_PTYPE) ) {
177  freebuf((char *)pktptr);
178  return;
179  }
180 
181  /* Ensure only one process uses ARP at a time */
182 
183  mask = disable();
184 
185  /* Search cache for sender's IP address */
186 
187  found = FALSE;
188 
189  for (slot=0; slot < ARP_SIZ; slot++) {
190  arptr = &arpcache[slot];
191 
192  /* Skip table entries that are unused */
193 
194  if (arptr->arstate == AR_FREE) {
195  continue;
196  }
197 
198  /* If sender's address matches, we've found it */
199 
200  if (arptr->arpaddr == pktptr->arp_sndpa) {
201  found = TRUE;
202  break;
203  }
204  }
205 
206  if (found) {
207 
208  /* Update sender's hardware address */
209 
210  memcpy(arptr->arhaddr, pktptr->arp_sndha, ARP_HALEN);
211 
212  /* If a process was waiting, inform the process */
213 
214  if (arptr->arstate == AR_PENDING) {
215  /* Mark resolved and notify waiting process */
216  arptr->arstate = AR_RESOLVED;
217  send(arptr->arpid, OK);
218  }
219  }
220 
221  /* For an ARP reply, processing is complete */
222 
223  if (pktptr->arp_op == ARP_OP_RPLY) {
224  freebuf((char *)pktptr);
225  restore(mask);
226  return;
227  }
228 
229  /* The following is for an ARP request packet: if the local */
230  /* machine is not the target or the local IP address is not */
231  /* yet known, ignore the request (i.e., processing is complete)*/
232 
233  if ((!NetData.ipvalid) ||
234  (pktptr->arp_tarpa != NetData.ipucast)) {
235  freebuf((char *)pktptr);
236  restore(mask);
237  return;
238  }
239 
240  /* Request has been sent to the local machine's address. So, */
241  /* add sender's info to cache, if not already present */
242 
243  if (!found) {
244  slot = arp_alloc();
245  if (slot == SYSERR) { /* Cache is full */
246  kprintf("ARP cache overflow on interface\n");
247  freebuf((char *)pktptr);
248  restore(mask);
249  return;
250  }
251  arptr = &arpcache[slot];
252  arptr->arpaddr = pktptr->arp_sndpa;
253  memcpy(arptr->arhaddr, pktptr->arp_sndha, ARP_HALEN);
254  arptr->arstate = AR_RESOLVED;
255  }
256 
257  /* Hand-craft an ARP reply packet and send back to requester */
258 
259  memcpy(apkt.arp_ethdst, pktptr->arp_sndha, ARP_HALEN);
260  memcpy(apkt.arp_ethsrc, NetData.ethucast, ARP_HALEN);
261  apkt.arp_ethtype= ETH_ARP; /* Frame carries ARP */
262  apkt.arp_htype = ARP_HTYPE; /* Hardware is Ethernet */
263  apkt.arp_ptype = ARP_PTYPE; /* Protocol is IP */
264  apkt.arp_hlen = ARP_HALEN; /* Ethernet address size*/
265  apkt.arp_plen = ARP_PALEN; /* IP address size */
266  apkt.arp_op = ARP_OP_RPLY; /* Type is Reply */
267 
268  /* Insert local Ethernet and IP address in sender fields */
269 
270  memcpy(apkt.arp_sndha, NetData.ethucast, ARP_HALEN);
271  apkt.arp_sndpa = NetData.ipucast;
272 
273  /* Copy target Ethernet and IP addresses from request packet */
274 
275  memcpy(apkt.arp_tarha, pktptr->arp_sndha, ARP_HALEN);
276  apkt.arp_tarpa = pktptr->arp_sndpa;
277 
278  /* Convert ARP packet from host to network byte order */
279 
280  arp_hton(&apkt);
281 
282  /* Convert the Ethernet header to network byte order */
283 
284  eth_hton((struct netpacket *)&apkt);
285 
286  /* Send the reply */
287 
288  write(ETHER0, (char *)&apkt, sizeof(struct arppacket));
289  freebuf((char *)pktptr);
290  restore(mask);
291  return;
292 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define AR_FREE
ARPキャッシュエントリ状態:スロットが未使用
Definition: arp.h:27
void eth_hton(struct netpacket *)
Definition: net.c:127
#define ARP_PALEN
IPアドレスサイズ
Definition: arp.h:10
uint32 ipucast
Definition: net.h:55
#define ARP_SIZ
キャシュ中のエントリ数
Definition: arp.h:20
void arp_ntoh(struct arppacket *pktptr)
Definition: arp.c:333
void restore(intmask)
#define ARP_PTYPE
IPプロトコルタイプ
Definition: arp.h:14
struct network NetData
Definition: net.c:6
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
void arp_hton(struct arppacket *pktptr)
Definition: arp.c:348
struct arpentry arpcache[ARP_SIZ]
ARPキャッシュエントリテーブル
Definition: arp.c:5
#define ARP_OP_RPLY
リプライオペコード
Definition: arp.h:18
#define OK
処理が成功した場合
Definition: kernel.h:77
syscall send(pid32, umsg32)
プロセスにメッセージを送信し、受信側が待機状態の場合はREADY状態にする。
Definition: send.c:21
byte bool8
Boolean値
Definition: kernel.h:36
int32 arstate
エントリの状態
Definition: arp.h:75
#define ARP_HTYPE
Ethernetハードウェアタイプ
Definition: arp.h:12
byte ethucast[ETH_ADDR_LEN]
Definition: net.h:64
syscall write(did32, char *, uint32)
Definition: write.c:9
int32 arp_alloc()
Definition: arp.c:298
uint32 arpaddr
エントリのIPアドレス
Definition: arp.h:77
#define FALSE
Boolean False(0)
Definition: kernel.h:63
#define TRUE
Boolean True(1)
Definition: kernel.h:65
IP&Ethernet用のARPパケットフォーマット
Definition: arp.h:39
#define ARP_HALEN
EthernetのMACアドレスサイズ
Definition: arp.h:8
ARPキャッシュエントリ
Definition: arp.h:72
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
#define ETH_ARP
Definition: net.h:9
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
byte arhaddr[ARP_HALEN]
エントリのEthernetアドレス
Definition: arp.h:81
Definition: net.h:16
#define AR_RESOLVED
ARPキャッシュエントリ状態:エントリが正常
Definition: arp.h:31
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
pid32 arpid
待機中プロセスか-1
Definition: arp.h:79
#define ETHER0
Definition: conf.h:34
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
bool8 ipvalid
Definition: net.h:63
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
#define AR_PENDING
ARPキャッシュエントリ状態:解決中
Definition: arp.h:29
Here is the call graph for this function:
Here is the caller graph for this function:

◆ arp_init()

void arp_init ( void  )

Definition at line 11 of file arp.c.

References AR_FREE, ARP_SIZ, arpcache, and arpentry::arstate.

Referenced by net_init().

12 {
13  int32 i; /* ARP cache index */
14 
15  for (i=1; i<ARP_SIZ; i++) { /* Initialize cache to empty */
17  }
18 }
#define AR_FREE
ARPキャッシュエントリ状態:スロットが未使用
Definition: arp.h:27
#define ARP_SIZ
キャシュ中のエントリ数
Definition: arp.h:20
struct arpentry arpcache[ARP_SIZ]
ARPキャッシュエントリテーブル
Definition: arp.c:5
int32 arstate
エントリの状態
Definition: arp.h:75
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
Here is the caller graph for this function:

◆ arp_ntoh()

void arp_ntoh ( struct arppacket )

Definition at line 333 of file arp.c.

References arppacket::arp_htype, arppacket::arp_op, arppacket::arp_ptype, arppacket::arp_sndpa, arppacket::arp_tarpa, ntohl, and ntohs.

Referenced by arp_in().

336 {
337  pktptr->arp_htype = ntohs(pktptr->arp_htype);
338  pktptr->arp_ptype = ntohs(pktptr->arp_ptype);
339  pktptr->arp_op = ntohs(pktptr->arp_op);
340  pktptr->arp_sndpa = ntohl(pktptr->arp_sndpa);
341  pktptr->arp_tarpa = ntohl(pktptr->arp_tarpa);
342 }
#define ntohl(x)
Definition: prototypes.h:623
#define ntohs(x)
Definition: prototypes.h:622
Here is the caller graph for this function:

◆ arp_resolve()

status arp_resolve ( uint32  ,
byte  [] 
)

Referenced by ip_send(), and ipout().

Here is the caller graph for this function:

◆ ascdate()

status ascdate ( uint32  ,
char *   
)

Definition at line 16 of file ascdate.c.

References DATE_DST_AUTO, DATE_DST_ON, dateinfo::dt_daylight, dateinfo::dt_dnam, dateinfo::dt_mnam, dateinfo::dt_msize, FALSE, isleap, OK, SECPERDY, SECPERHR, SECPERMN, sprintf(), TIMEZONE, and TRUE.

Referenced by xsh_date().

20 {
21  uint32 tmp; /* Counts remaining seconds */
22  /* during computations */
23  int32 year, month, day, /* Values for various parts of */
24  hour, minute, second; /* the date */
25  uint32 days; /* Number of days in a year */
26  uint32 leapyrs; /* Number of leap years between */
27  /* 1970 and now */
28  uint32 shift; /* Number of times the calendar */
29  /* shifted by a day */
30  uint32 dayofweek; /* Day of the week (0 - 6) */
31  /* For DST, day of the week for:*/
32  int32 jan1; /* January 1 this year */
33  int32 mar1; /* March 1 this year */
34  int32 nov1; /* November 1 this year */
35  int32 marss; /* Day of second sunday in march*/
36  int32 novfs; /* Day of second sunday in march*/
37  bool8 dst; /* Should we adjust for DST? */
38  int32 i; /* Indexes through months */
39 
40  char *zones[] = {"EST", "CST", "MST", "PST"};
41  char *dzones[] = {"EDT", "CDT", "MDT", "PDT"};
42 
43  /* Compute the year (1970-2099) */
44 
45  for (year=1970 ; TRUE ; year++) {
46  days = isleap(year) ? 366 : 365;
47  tmp = days * SECPERDY;
48  if (tmp > now)
49  break;
50  now -= tmp;
51  }
52 
53  /* Compute the number of whole days that have already passed */
54  /* during the current year (0 through 365) */
55 
56  days = now / SECPERDY;
57 
58  /* Compute the month (0-11) */
59 
60  for (month=0 ; month<12 ; month++) {
61  tmp = Date.dt_msize[month] * SECPERDY;
62  if ((month == 1) && isleap(year)) {
63  tmp += SECPERDY;
64  }
65  if (tmp > now)
66  break;
67  now -= tmp;
68  }
69 
70  /* Compute the day of month (1-31) */
71 
72  day = (int32)( now/SECPERDY ) + 1;
73  now %= SECPERDY;
74 
75  /* Compute the hour (0-23) */
76 
77  hour = (int32) ( now/SECPERHR );
78  now %= SECPERHR;
79 
80  /* Compute the minutes (0-59) */
81 
82  minute = now / SECPERMN;
83  now %= SECPERMN;
84 
85  /* Compute the seconds (0-59) */
86  second = (int32) now;
87 
88  /* Compute the day of the week (0-6) */
89  /* */
90  /* Note: Jan 1, 1970 was a Thursday (4 on a 0 to 6 range) */
91  /* Add one day of the week each full year (365%7 == 1) plus */
92  /* one extra day for each leap year */
93 
94  /* Compute number of leap years prior to current year */
95 
96  leapyrs = (year-1969)/4;
97 
98  /* Compute shift for all previous years (i.e., day of week of */
99  /* Jan 1 of the current year) */
100 
101  shift = 4 + (year - 1970) + leapyrs;
102 
103  /* Remember day of the week for Jan 1 this year (for DST) */
104 
105  jan1 = shift % 7;
106 
107  /* Add the number of days so far this year */
108 
109  shift += days;
110 
111  /* Convert to integer from 0 through 6 */
112 
113  dayofweek = shift % 7;
114 
115  /* */
116  /* Handle daylight savings time */
117  /* */
118  /* Date.dt_daylight specifies whether to set it on, off, */
119  /* or automatically compute the setting */
120  /* */
121 
122  dst = FALSE;
123  if (Date.dt_daylight == DATE_DST_ON) {
124  dst = TRUE;
125  } else if (Date.dt_daylight == DATE_DST_AUTO) {
126 
127  /* Automatic DST calculation: DST is on between 2:00 AM */
128  /* the second Sunday of March and 2:00 AM the first */
129  /* sunday in November */
130 
131  /* Calculate day of the week for March 1 */
132 
133  mar1 = (jan1 + Date.dt_msize[0] + Date.dt_msize[1] +
134  isleap(year)) % 7;
135 
136  /* Caculate day (1-31) of the second sunday in March */
137 
138  if (mar1 == 0) { /* Mar. 1 is a Sunday */
139  marss = 8;
140  } else { /* Mar. 1 is Monday - Saturday */
141  marss = 15 - mar1;
142  }
143 
144  /* Calculate day of the week for November 1 */
145 
146  nov1 = jan1;
147  for (i=0; i<10; i++) {
148  nov1 += Date.dt_msize[i];
149  }
150  if (isleap(year)) {
151  nov1++;
152  }
153  nov1 = nov1 % 7;
154  if (nov1 == 0) { /* Nov. 1 is a Sunday */
155  novfs = 1;
156  } else { /* Nov. 1 is Monday - Saturday */
157  novfs = 8 - nov1;
158  }
159 
160  /* Set dst based on time of the year */
161 
162  /* DST is off during December, January, and Feburary */
163 
164  if ( (month == 11) || (month == 0) || (month == 1) ) {
165  dst = FALSE;
166 
167  /* DST is on from April through October */
168 
169  } else if ( (month>2) && (month<10) ) {
170  dst = TRUE;
171 
172  /* DST is on in March past 2 AM on the second Sunday */
173 
174  } else if (month == 2) {
175 
176  dst = FALSE;
177  if (day > marss) {
178  dst = TRUE;
179  } else if ( (day == marss) && (hour >= 2) ) {
180  dst = TRUE;
181  }
182 
183  /* DST is on in November until 2 am on first Sunday */
184 
185 
186  } else if (month == 10) {
187 
188  dst = TRUE;
189  if (day > novfs) {
190  dst = FALSE;
191  } else if ( (day == novfs) && (hour >= 1) ) {
192  dst = FALSE;
193  }
194  }
195  }
196 
197  /* If we are doing DST, move ahead one hour and handle the */
198  /* case where we move to the next day or the next month */
199 
200  if (dst) {
201  hour++;
202 
203  /* If day exceeded, move to next day */
204 
205  if (hour > 23) {
206  hour = 0;
207  day++;
208 
209  /* If month exceeded, move to next month */
210 
211  if (day > Date.dt_msize[month]) {
212  day = 1;
213  month++;
214 
215  /* Stop here because DST does not occur */
216  /* during the year boundary */
217  }
218  }
219  }
220 
221  sprintf(str, "%3s %3s %2d %2d:%02d:%02d %s %d",
222  Date.dt_dnam[dayofweek], Date.dt_mnam[month],
223  day, hour, minute, second, dst? dzones[TIMEZONE-5]:
224  zones[TIMEZONE-5], year);
225  return OK;
226 }
struct dateinfo Date
Definition: ascdate.c:6
int32 dt_msize[12]
Definition: date.h:33
#define OK
処理が成功した場合
Definition: kernel.h:77
#define TIMEZONE
Definition: date.h:53
byte bool8
Boolean値
Definition: kernel.h:36
int32 sprintf(char *, char *,...)
Definition: sprintf.c:12
char * dt_mnam[12]
Definition: date.h:34
#define SECPERDY
Definition: date.h:43
char * dt_dnam[7]
Definition: date.h:35
#define FALSE
Boolean False(0)
Definition: kernel.h:63
#define TRUE
Boolean True(1)
Definition: kernel.h:65
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define isleap(x)
Definition: date.h:42
#define DATE_DST_AUTO
Definition: date.h:22
#define DATE_DST_ON
Definition: date.h:21
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
int32 dt_daylight
Definition: date.h:31
#define SECPERMN
Definition: date.h:45
#define SECPERHR
Definition: date.h:44
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bufinit()

status bufinit ( void  )

バッファプールデータ構造を初期化する。

現在のバッファプール数を0にする。

Returns
OKを返す。

Definition at line 17 of file bufinit.c.

References nbpools, and OK.

Referenced by sysinit().

18 {
19  nbpools = 0;
20  return OK;
21 }
#define OK
処理が成功した場合
Definition: kernel.h:77
bpid32 nbpools
割り当てられたバッファプールの現在の数
Definition: bufinit.c:10
Here is the caller graph for this function:

◆ chprio()

pri16 chprio ( pid32  pid,
pri16  newprio 
)

プロセスのスケジューリング優先度を変更する。

Step1. 割り込みを禁止する。
Step2. 不正なPIDの場合は割り込み許可状態に戻し、処理を終了する。
Step3. 引数で指定されたPIDからプロセス情報を取得し、新しい優先度に変更する。
Step4. 割り込み許可状態に戻し、処理を終了する。

Parameters
[in]pid優先度を変更したいプロセスのID
[in]newprio新しい優先度
Returns
優先度が変更できた場合は古い優先度、PIDが不正な場合はSYSERRを返す。

Definition at line 18 of file chprio.c.

References disable(), isbadpid, proctab, procent::prprio, restore(), and SYSERR.

19 {
20  intmask mask; /* Saved interrupt mask */
21  struct procent *prptr; /* Ptr to process's table entry */
22  pri16 oldprio; /* Priority to return */
23 
24  mask = disable();
25  if (isbadpid(pid))
26  {
27  restore(mask);
28  return (pri16)SYSERR;
29  }
30  prptr = &proctab[pid];
31  oldprio = prptr->prprio;
32  prptr->prprio = newprio;
33  restore(mask);
34  return oldprio;
35 }
void restore(intmask)
#define isbadpid(x)
プロセスIDを検証する。割り込みが無効になっている事を想定している。
Definition: process.h:71
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
int16 pri16
プロセス優先度
Definition: kernel.h:30
pri16 prprio
プロセスのスケジューリング優先度。
Definition: process.h:90
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:

◆ clkcount()

uint32 clkcount ( void  )

◆ clkhandler()

interrupt clkhandler ( void  )

Definition at line 9 of file clkhandler.c.

References AM335X_TIMER1MS_TISR_OVF_IT_FLAG, clktime, count1000, firstid, isempty, preempt, QUANTUM, queuetab, resched(), sleepq, am335x_timer1ms::tisr, and wakeup().

Referenced by clkinit().

10 {
11 
12 
13  volatile struct am335x_timer1ms *csrptr =
14  (struct am335x_timer1ms *)0x44E31000;
15  /* Set csrptr to address of timer CSR */
16 
17  /* If there is no interrupt, return */
18 
19  if((csrptr->tisr & AM335X_TIMER1MS_TISR_OVF_IT_FLAG) == 0) {
20  return;
21  }
22 
23  /* Acknowledge the interrupt */
24 
26 
27  /* Increment 1000ms counter */
28 
29  count1000++;
30 
31  /* After 1 sec, increment clktime */
32 
33  if(count1000 >= 1000) {
34  clktime++;
35  count1000 = 0;
36  }
37 
38  /* check if sleep queue is empty */
39 
40  if(!isempty(sleepq)) {
41 
42  /* sleepq nonempty, decrement the key of */
43  /* topmost process on sleepq */
44 
45  if((--queuetab[firstid(sleepq)].qkey) == 0) {
46 
47  wakeup();
48  }
49  }
50 
51  /* Decrement the preemption counter */
52  /* Reschedule if necessary */
53 
54  if((--preempt) == 0) {
55  preempt = QUANTUM;
56  resched();
57  }
58 }
struct qentry queuetab[]
Definition: queue.c:45
uint32 tisr
割り込みステータスレジスタ
Definition: clock.h:34
qid16 sleepq
スリープ中のプロセスキュー
Definition: clkinit.c:7
void wakeup(void)
Definition: wakeup.c:9
uint32 count1000
最後のクロックチックからのミリ秒
Definition: clkinit.c:6
#define isempty(q)
リストが空かどうかを返す。
Definition: queue.h:89
#define QUANTUM
ミリ秒単位のタイムスライス
Definition: kernel.h:93
#define firstid(q)
リストの最初のプロセスのIDを返す。
Definition: queue.h:70
#define AM335X_TIMER1MS_TISR_OVF_IT_FLAG
TCRRオーバーフロー発生時の設定
Definition: clock.h:80
void resched(void)
最優先の適切なプロセスにCPU実行権を渡す。
Definition: resched.c:22
uint32 preempt
プリエンプションカウンタ
Definition: clkinit.c:9
uint32 clktime
起動してからの現在の時間[s]
Definition: clkinit.c:5
AM335X SOCのタイマー(1[ms])
Definition: clock.h:23
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clkinit()

void clkinit ( void  )

Definition at line 15 of file clkinit.c.

References AM335X_TIMER1MS_ADDR, AM335X_TIMER1MS_CLKCTRL_ADDR, AM335X_TIMER1MS_CLKCTRL_EN, AM335X_TIMER1MS_IRQ, AM335X_TIMER1MS_TCLR_AR, AM335X_TIMER1MS_TCLR_ST, AM335X_TIMER1MS_TIER_OVF_IT_ENA, AM335X_TIMER1MS_TIOCP_CFG_SOFTRESET, AM335X_TIMER1MS_TISTAT_RESETDONE, clkhandler(), clktime, count1000, newqueue(), preempt, QUANTUM, set_evec(), sleepq, am335x_timer1ms::tclr, am335x_timer1ms::tier, am335x_timer1ms::tiocp_cfg, am335x_timer1ms::tistat, am335x_timer1ms::tldr, am335x_timer1ms::tnir, am335x_timer1ms::tpir, and am335x_timer1ms::ttgr.

Referenced by sysinit().

16 {
17  volatile struct am335x_timer1ms *csrptr =
18  (volatile struct am335x_timer1ms *)AM335X_TIMER1MS_ADDR;
19  /* Pointer to timer CSR in BBoneBlack */
20  volatile uint32 *clkctrl =
22 
23  *clkctrl = AM335X_TIMER1MS_CLKCTRL_EN;
24  while ((*clkctrl) != 0x2) /* Do nothing */
25  ;
26 
27  /* Reset the timer module */
28 
30 
31  /* Wait until the reset is complete */
32 
33  while ((csrptr->tistat & AM335X_TIMER1MS_TISTAT_RESETDONE) == 0)
34  /* Do nothing */;
35 
36  /* Set interrupt vector for clock to invoke clkint */
37 
39 
40  sleepq = newqueue(); /* Allocate a queue to hold the delta */
41  /* list of sleeping processes */
42 
43  preempt = QUANTUM; /* Set the preemption time */
44 
45  clktime = 0; /* Start counting seconds */
46  count1000 = 0;
47  /* The following values are calculated for a */
48  /* timer that generates 1ms tick rate */
49 
50  csrptr->tpir = 1000000;
51  csrptr->tnir = 0;
52  csrptr->tldr = 0xFFFFFFFF - 26000;
53 
54  /* Set the timer to auto reload */
55 
56  csrptr->tclr = AM335X_TIMER1MS_TCLR_AR;
57 
58  /* Start the timer */
59 
60  csrptr->tclr |= AM335X_TIMER1MS_TCLR_ST;
61 
62  /* Enable overflow interrupt which will generate */
63  /* an interrupt every 1 ms */
64 
66 
67  /* Kickstart the timer */
68 
69  csrptr->ttgr = 1;
70 
71  return;
72 }
uint32 preempt
プリエンプションカウンタ(クロックが一刻みする度に、クロック割り込みハンドラが値を繰り下げる) ...
Definition: clkinit.c:9
interrupt clkhandler(void)
Definition: clkhandler.c:9
#define AM335X_TIMER1MS_CLKCTRL_EN
1[ms]タイマーのクロック制御の許可
Definition: clock.h:96
uint32 tier
割り込み許可レジスタ
Definition: clock.h:36
#define AM335X_TIMER1MS_TCLR_AR
自動リロードモード
Definition: clock.h:92
uint32 clktime
起動してからの現在の時間[s]
Definition: clkinit.c:5
#define AM335X_TIMER1MS_ADDR
1[ms]タイマーのアドレス
Definition: clock.h:70
uint32 tistat
ステータスレジスタ
Definition: clock.h:32
uint32 ttgr
トリガレジスタ
Definition: clock.h:46
int32 set_evec(uint32, uint32)
Definition: evec.c:37
#define AM335X_TIMER1MS_TCLR_ST
Start/Stopタイマ制御
Definition: clock.h:90
uint32 count1000
最後のクロックチックからのミリ秒
Definition: clkinit.c:6
uint32 tnir
ネガティブインクリメントレジスタ
Definition: clock.h:60
#define QUANTUM
ミリ秒単位のタイムスライス
Definition: kernel.h:93
qid16 sleepq
スリープ中のプロセスキュー
Definition: clkinit.c:7
#define AM335X_TIMER1MS_CLKCTRL_ADDR
1[ms]タイマーのクロック制御アドレス
Definition: clock.h:94
#define AM335X_TIMER1MS_TISTAT_RESETDONE
1[ms]タイマーのリセット完了状態
Definition: clock.h:76
uint32 tpir
ポジティブインクリメントレジスタ
Definition: clock.h:58
#define AM335X_TIMER1MS_TIOCP_CFG_SOFTRESET
1[ms]タイマーのソフトリセットコンフィグ
Definition: clock.h:74
#define AM335X_TIMER1MS_TIER_OVF_IT_ENA
オーバーフロー割り込みの許可
Definition: clock.h:86
qid16 newqueue(void)
グローバルキューテーブルにキューを割り当て、テーブルを初期化する。
Definition: newqueue.c:15
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
#define AM335X_TIMER1MS_IRQ
1[ms]タイマーの割り込み番号
Definition: clock.h:72
uint32 tldr
タイマー読み込み値
Definition: clock.h:44
uint32 tclr
オプション機能
Definition: clock.h:40
AM335X SOCのタイマー(1[ms])
Definition: clock.h:23
uint32 tiocp_cfg
OCPインターフェースレジスタ
Definition: clock.h:30
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clkint()

void clkint ( void  )

◆ close()

syscall close ( did32  )

Definition at line 9 of file close.c.

References devtab, disable(), dentry::dvclose, isbaddev, restore(), and SYSERR.

Referenced by kill(), lfscreate(), xsh_cat(), and xsh_rdstest().

12 {
13  intmask mask; /* Saved interrupt mask */
14  struct dentry *devptr; /* Entry in device switch table */
15  int32 retval; /* Value to return to caller */
16 
17  mask = disable();
18  if (isbaddev(descrp)) {
19  restore(mask);
20  return SYSERR;
21  }
22  devptr = (struct dentry *) &devtab[descrp];
23  retval = (*devptr->dvclose) (devptr);
24  restore(mask);
25  return retval;
26 }
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
devcall(* dvclose)(struct dentry *)
Definition: conf.h:12
Definition: conf.h:6
struct dentry devtab[]
Definition: conf.c:11
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define isbaddev(f)
デバイスIDを検証するマクロ。
Definition: device.h:15
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ control()

syscall control ( did32  ,
int32  ,
int32  ,
int32   
)

Definition at line 9 of file control.c.

References devtab, disable(), dentry::dvcntl, isbaddev, restore(), and SYSERR.

Referenced by net_init(), and shell().

15 {
16  intmask mask; /* Saved interrupt mask */
17  struct dentry *devptr; /* Entry in device switch table */
18  int32 retval; /* Value to return to caller */
19 
20  mask = disable();
21  if (isbaddev(descrp)) {
22  restore(mask);
23  return SYSERR;
24  }
25  devptr = (struct dentry *) &devtab[descrp];
26  retval = (*devptr->dvcntl) (devptr, func, arg1, arg2);
27  restore(mask);
28  return retval;
29 }
devcall(* dvcntl)(struct dentry *, int32, int32, int32)
Definition: conf.h:18
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
Definition: conf.h:6
struct dentry devtab[]
Definition: conf.c:11
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define isbaddev(f)
デバイスIDを検証するマクロ。
Definition: device.h:15
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create()

pid32 create ( void *  procaddr,
uint32  ssize,
pri16  priority,
char *  name,
uint32  nargs,
  ... 
)

関数の実行を開始するプロセスを作成する。

Step1. 割り込みを禁止する。
Step2. スタックサイズがMINSTKを下回っていた場合、サイズをMINSTKまで引き上げ、丸めを行う。
Step3. 以下のいずれかを満たした場合は、割り込み許可状態に復元し、SYSERRを返す。
 ・スタックが確保できなかった場合
 ・全てのプロセスがFREE状態ではなかった場合(使用中だった場合)
 ・引数のプロセス優先度が1より小さかった場合
Step4. アクティブプロセス数を1増やす。 Step5. プロセステーブルエントリを以下の状態で初期化する。
 ・プロセス状態 = サスペンド
 ・プロセス優先度 = 引数で指定した優先度
 ・スタックアドレス = getstk()で取得したスタックアドレス( プロセススタックの最上位にオーバフロー検知マーカを付与)
 ・スタックサイズ = 引数で指定されたスタックサイズ(MINSTK以上のサイズ)
 ・プロセス名 = 引数で指定した名前(15文字 + NULL終端)
 ・セマフォとメッセージ = 未使用状態
 ・デバイスディスクリプタ = XINU Shell用に0:STDIN(標準入力)、1:STDOUT(標準出力)、2:STDERR(標準エラー)を設定
Step6. 可変長引数と関数ポインタをスタックに積む。前提として、ARMはr0〜r3レジスタが引数渡しに使用される。
可変長引数の5個目〜N個目をスタックに積んだ後、関数ポインタをスタックに積む。
引数をレジスタ渡しするためにスタックにr4〜r11用の情報(=0)を積み、r3〜r0用の情報(引数次第で変化)を積む。
Step7. 関数のリターンアドレス(INITRET = userret()であり、kill()を呼び出す)をスタックに積む。
Step8. CPSR F bitを有効化し、スーパバイザモードに移行するためのビットマスクをスタックに積む。
このビットマスクは、コンテキストスイッチ中のリストア時に使用される。
Step9. 新しいスタックアドレスをプロセステーブルにセットする。
Step10. 割り込み許可状態に復元する。

Parameters
[in]procaddr関数ポインタ(プロセスのエントリポイント)
[in]ssizeスタックサイズ(Byte)
[in]priorityプロセスの優先度(> 0)
[in]nameプロセス名(デバッグ用)
[in]nargs本引数より後にある引数の総数
[in]...可変長引数
Returns
成功時は作成したプロセスのID、以下の場合はSYSERRを返す。
 ・スタックが確保できなかった場合
 ・全てのプロセスがFREE状態ではなかった場合(使用中だった場合)
 ・引数のプロセス優先度が1より小さかった場合

Definition at line 55 of file create.c.

References CONSOLE, disable(), FALSE, getpid(), getstk(), INITRET, MINSTK, newpid(), NULLCH, PNMLEN, PR_SUSP, prcount, procent::prdesc, procent::prhasmsg, procent::prname, proctab, procent::prparent, procent::prprio, procent::prsem, procent::prstate, procent::prstkbase, procent::prstklen, procent::prstkptr, restore(), roundew, STACKMAGIC, and SYSERR.

Referenced by main(), net_init(), nulluser(), rdsinit(), shell(), and startup().

56 {
57  intmask mask; /* interrupt mask */
58  pid32 pid; /* stores new process id */
59  struct procent *prptr; /* pointer to proc. table entry */
60  int32 i;
61  uint32 *a; /* points to list of args */
62  uint32 *saddr; /* stack address */
63 
64  mask = disable();
65  if (ssize < MINSTK)
66  ssize = MINSTK;
67  ssize = (uint32)roundew(ssize);
68  if (((saddr = (uint32 *)getstk(ssize)) ==
69  (uint32 *)SYSERR) ||
70  (pid = newpid()) == SYSERR || priority < 1)
71  {
72  restore(mask);
73  return SYSERR;
74  }
75 
76  prcount++;
77  prptr = &proctab[pid];
78 
79  /* initialize process table entry for new process */
80  prptr->prstate = PR_SUSP; /* initial state is suspended */
81  prptr->prprio = priority;
82  prptr->prstkbase = (char *)saddr;
83  prptr->prstklen = ssize;
84  prptr->prname[PNMLEN - 1] = NULLCH;
85  for (i = 0; i < PNMLEN - 1 && (prptr->prname[i] = name[i]) != NULLCH; i++)
86  ;
87  prptr->prsem = -1;
88  prptr->prparent = (pid32)getpid();
89  prptr->prhasmsg = FALSE;
90 
91  /* set up initial device descriptors for the shell */
92  prptr->prdesc[0] = CONSOLE; /* stdin is CONSOLE device */
93  prptr->prdesc[1] = CONSOLE; /* stdout is CONSOLE device */
94  prptr->prdesc[2] = CONSOLE; /* stderr is CONSOLE device */
95 
96  /* Initialize stack as if the process was called */
97 
98  *saddr = STACKMAGIC;
99 
100  /* push arguments */
101  a = (uint32 *)(&nargs + 1); /* start of args */
102  a += nargs - 1; /* last argument */
103  for (; nargs > 4; nargs--) /* machine dependent; copy args */
104  *--saddr = *a--; /* onto created process's stack */
105  *--saddr = (long)procaddr;
106  for (i = 11; i >= 4; i--)
107  *--saddr = 0;
108  for (i = 4; i > 0; i--)
109  {
110  if (i <= nargs)
111  *--saddr = *a--;
112  else
113  *--saddr = 0;
114  }
115  *--saddr = (long)INITRET; /* push on return address */
116  *--saddr = (long)0x00000053; /* CPSR F bit set, */
117  /* Supervisor mode */
118  prptr->prstkptr = (char *)saddr;
119  restore(mask);
120  return pid;
121 }
pid32 prparent
このプロセスを作成したプロセスID(親プロセスID)。
Definition: process.h:102
void restore(intmask)
int32 prcount
現在アクティブのプロセス。
Definition: initialize.c:30
#define MINSTK
最小のスタックサイズ(Byte)
Definition: kernel.h:89
#define PR_SUSP
プロセスがサスペンド(休止)させられた状態。
Definition: process.h:45
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define roundew(x)
4の倍数でスタックサイズを丸める。
Definition: create.c:16
#define CONSOLE
Definition: conf.h:28
local int newpid()
新しいプロセスIDを取得するnewpid()の宣言
Definition: create.c:131
#define INITRET
プロセスが戻るアドレス。
Definition: process.h:61
uint32 prstklen
Bytesで表されたスタックの長さ(最大値。Byte)。
Definition: process.h:96
pri16 prprio
プロセスのスケジューリング優先度。
Definition: process.h:90
#define PNMLEN
プロセス名の長さ
Definition: process.h:52
#define FALSE
Boolean False(0)
Definition: kernel.h:63
sid32 prsem
プロセスが待機しているセマフォ。
Definition: process.h:100
char prname[PNMLEN]
プロセス名。
Definition: process.h:98
char * prstkbase
ランタイムスタックの基点(メモリ領域で最上位のアドレス)。
Definition: process.h:94
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int16 prdesc[NDESC]
プロセス用のデバイスディスクリプタ
Definition: process.h:108
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
#define STACKMAGIC
プロセススタックの最上位に配置するマーカ(オーバフロー検出に用いる)
Definition: process.h:112
pid32 getpid(void)
現在実行中のプロセスIDを返す。
Definition: getpid.c:11
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
int32 pid32
プロセスID
Definition: kernel.h:26
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
bool8 prhasmsg
有効(Valid)メッセージの場合、非0となる。
Definition: process.h:106
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
char * getstk(uint32)
スタックメモリを割り当て、最上位のワードアドレスを返す。
Definition: getstk.c:25
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
char * prstkptr
保存されたスタックポインタ。
Definition: process.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ctxsw()

void ctxsw ( void *  ,
void *   
)

コンテキストスイッチを行う(ctxsw.S に定義がある)

Referenced by resched().

Here is the caller graph for this function:

◆ dequeue()

pid32 dequeue ( qid16  q)

プロセスキューテーブルからキューを削除し、リスト先頭のプロセスIDを返す。

Parameters
[in]q使用するキューID
Returns
キューを削除した場合はリスト先頭のプロセスID、キューIDが不正の場合はSYSERR、
キューが空の場合はEMPTYを返す。

Definition at line 78 of file queue.c.

References EMPTY, getfirst(), isbadqid, isempty, qentry::qnext, qentry::qprev, queuetab, and SYSERR.

Referenced by resched(), signal(), signaln(), and wakeup().

81 {
82  pid32 pid; /* ID of process removed */
83 
84  if (isbadqid(q))
85  {
86  return SYSERR;
87  }
88  else if (isempty(q))
89  {
90  return EMPTY;
91  }
92 
93  pid = getfirst(q);
94  queuetab[pid].qprev = EMPTY;
95  queuetab[pid].qnext = EMPTY;
96  return pid;
97 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct qentry queuetab[NQENT]
Definition: queue.c:45
#define isbadqid(x)
キューIDが不正値かどうかをチェックする。
Definition: queue.h:132
#define EMPTY
次のキューインデックスもしくは前のキューインデックスがNULL値
Definition: queue.h:23
qid16 qnext
次のプロセスか末尾のプロセスのインデックス。
Definition: queue.h:39
#define isempty(q)
リストが空かどうかを返す。
Definition: queue.h:89
qid16 qprev
前のプロセスか先頭のプロセスのインデックス。
Definition: queue.h:41
pid32 getfirst(qid16)
キューの先頭からプロセスを取り出す。
Definition: getitem.c:13
int32 pid32
プロセスID
Definition: kernel.h:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disable()

intmask disable ( void  )

◆ dnslookup()

uint32 dnslookup ( char *  )

Definition at line 15 of file dns.c.

References currpid, dns_bldq(), dns_geta(), DNSLPORT, DNSPORT, DNSRETRY, network::dnsserver, DNSTIMEOUT, getlocalip(), htons, kprintf(), memset(), NetData, ntohl, NULL, SYSERR, TIMEOUT, udp_recv(), udp_register(), udp_release(), and udp_send().

Referenced by xsh_ping().

18 {
19  struct dnspkt qpkt; /* Query Packet buffer */
20  struct dnspkt rpkt; /* Response Packet buffer */
21  uint32 nsaddr; /* Name server IP address */
22  uint32 qlen; /* Query length */
23  uid32 slot; /* UDP Slot */
24  int32 rlen; /* Response length */
25  uint32 ipaddr; /* IP address from response */
26  int32 retval; /* Return value */
27  int32 i; /* Loop index */
28 
29  /* Check if we have a valid name pointer */
30 
31  if(dname == NULL) {
32  return (uint32)SYSERR;
33  }
34 
35  /* Obtain the IP address of a DNS server */
36 
37  retval = getlocalip();
38  nsaddr = NetData.dnsserver;
39  if ( (retval == SYSERR) || (NetData.dnsserver == 0) ) {
40  kprintf("Cannot find a DNS server\n");
41  return (uint32)SYSERR;
42  }
43 
44  /* Register a UDP Slot */
45 
46  slot = udp_register(nsaddr, DNSPORT, DNSLPORT);
47  if(slot == SYSERR) {
48  return (uint32)SYSERR;
49  }
50 
51  /* Build the Query message */
52 
53  memset((char *)&qpkt, 0, sizeof(struct dnspkt));
54 
55  qpkt.id = currpid;
56  qpkt.rd = 1;
57  qpkt.qucount = htons(1);
58 
59  qlen = dns_bldq(dname, qpkt.data);
60 
61  ipaddr = (uint32)SYSERR;
62  for(i = 0; (ipaddr==(uint32)SYSERR) && (i < DNSRETRY); i++) {
63 
64  /* Send the Query message */
65 
66  udp_send(slot, (char*)&qpkt, qlen);
67 
68  /* Wait for the response */
69 
70  rlen = udp_recv(slot, (char*)&rpkt, sizeof(struct dnspkt),
71  DNSTIMEOUT);
72  if ( (rlen == SYSERR) || (rlen == TIMEOUT) ) {
73  continue;
74  }
75  ipaddr = dns_geta(dname, &rpkt);
76  }
77  udp_release(slot);
78  return ntohl(ipaddr);
79 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
int32 udp_recv(uid32, char *, int32, uint32)
Definition: udp.c:146
status udp_send(uid32, char *, int32)
Definition: udp.c:316
pid32 currpid
現在実行中のプロセス。
Definition: initialize.c:32
struct network NetData
Definition: net.c:6
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
Definition: dns.h:14
#define DNSLPORT
Definition: dns.h:8
local uint32 dns_geta(char *, struct dnspkt *)
Definition: dns.c:155
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
#define ntohl(x)
Definition: prototypes.h:623
#define DNSTIMEOUT
Definition: dns.h:5
#define DNSRETRY
Definition: dns.h:6
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
local uint32 dns_bldq(char *, char *)
Definition: dns.c:85
uid32 udp_register(uint32, uint16, uint16)
Definition: udp.c:85
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
status udp_release(uid32)
Definition: udp.c:502
uint32 getlocalip(void)
Definition: dhcp.c:142
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
#define htons(x)
Definition: prototypes.h:619
int32 uid32
UDPテーブルディスクリプタのID.
Definition: kernel.h:44
uint32 dnsserver
Definition: net.h:61
#define DNSPORT
Definition: dns.h:7
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dot2ip()

uint32 dot2ip ( char *  ,
uint32  
)

Definition at line 9 of file dot2ip.c.

References NULLCH, OK, and SYSERR.

Referenced by getlocalip(), getutime(), rdsinit(), rfsinit(), xsh_ping(), and xsh_udpecho().

15 {
16  int32 seg; /* Counts segments */
17  int32 nch; /* Counts chars within segment */
18  char ch; /* Next character */
19  uint32 ipaddr; /* IP address in binary */
20  int32 val; /* Binary value of one segment */
21 
22  /* Input must have the form X.X.X.X, where X is 1 to 3 digits */
23 
24  ipaddr = 0;
25  for (seg=0 ; seg<4 ; seg++) { /* For each segment */
26  val = 0;
27  for (nch=0 ; nch<4; nch++) { /* Up to four chars per segment*/
28  ch = *dotted++;
29  if ( (ch==NULLCH) || (ch == '.') ) {
30  if (nch == 0) {
31  return SYSERR;
32  } else {
33  break;
34  }
35  }
36 
37  /* Non-digit is an error */
38 
39  if ( (ch<'0') || (ch>'9') ) {
40  return SYSERR;
41  }
42 
43  val = 10*val + (ch-'0');
44  }
45 
46  if (val > 255) { /* Out of valid range */
47  return SYSERR;
48  }
49  ipaddr = (ipaddr << 8) | val;
50 
51  if (ch == NULLCH) {
52  break;
53  }
54  }
55  if ( (seg != 3) || (ch != NULLCH) ) {
56  return SYSERR;
57  }
58  *result = ipaddr;
59  return OK;
60 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the caller graph for this function:

◆ enable()

void enable ( void  )

割り込み許可(intr.Sに定義がある)

Referenced by nulluser().

Here is the caller graph for this function:

◆ enqueue()

pid32 enqueue ( pid32  pid,
qid16  q 
)

プロセスをプロセスキューテーブルの末尾に挿入する。

Parameters
[in]pid挿入するプロセスID
[in]q使用するキューID
Returns
成功時はキューに挿入したプロセスID、引数不正時はSYSERRを返す。

Definition at line 53 of file queue.c.

References isbadpid, isbadqid, qentry::qnext, qentry::qprev, queuetab, queuetail, and SYSERR.

Referenced by wait().

54 {
55  qid16 tail, prev; /* Tail & previous node indexes */
56 
57  if (isbadqid(q) || isbadpid(pid))
58  {
59  return SYSERR;
60  }
61 
62  tail = queuetail(q);
63  prev = queuetab[tail].qprev;
64 
65  queuetab[pid].qnext = tail; /* Insert just before tail node */
66  queuetab[pid].qprev = prev;
67  queuetab[prev].qnext = pid;
68  queuetab[tail].qprev = pid;
69  return pid;
70 }
#define isbadpid(x)
プロセスIDを検証する。割り込みが無効になっている事を想定している。
Definition: process.h:71
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct qentry queuetab[NQENT]
Definition: queue.c:45
#define isbadqid(x)
キューIDが不正値かどうかをチェックする。
Definition: queue.h:132
qid16 qnext
次のプロセスか末尾のプロセスのインデックス。
Definition: queue.h:39
qid16 qprev
前のプロセスか先頭のプロセスのインデックス。
Definition: queue.h:41
int16 qid16
キューID
Definition: kernel.h:24
#define queuetail(q)
キューの末尾を返す。
Definition: queue.h:61
Here is the caller graph for this function:

◆ eth_hton()

void eth_hton ( struct netpacket )

Definition at line 127 of file net.c.

References htons, and netpacket::net_ethtype.

Referenced by arp_in(), arp_resolve(), and ip_out().

130 {
131  pktptr->net_ethtype = htons(pktptr->net_ethtype);
132 }
#define htons(x)
Definition: prototypes.h:619
Here is the caller graph for this function:

◆ eth_ntoh()

void eth_ntoh ( struct netpacket )

Definition at line 139 of file net.c.

References netpacket::net_ethtype, and ntohs.

Referenced by netin().

142 {
143  pktptr->net_ethtype = ntohs(pktptr->net_ethtype);
144 }
#define ntohs(x)
Definition: prototypes.h:622
Here is the caller graph for this function:

◆ ethcontrol()

int32 ethcontrol ( struct dentry ,
int32  ,
int32  ,
int32   
)

Definition at line 18 of file ethcontrol.c.

References ethcblk::devAddress, dentry::dvminor, ETH_ADDR_LEN, ETH_CTRL_GET_MAC, ethertab, memcpy(), OK, and SYSERR.

24 {
25  struct ethcblk *ethptr; /* Ethertab entry pointer */
26  int32 retval = OK; /* Return value of cntl function*/
27 
28  ethptr = &ethertab[devptr->dvminor];
29 
30  switch (func)
31  {
32 
33  /* Get MAC address */
34 
35  case ETH_CTRL_GET_MAC:
36  memcpy((byte *)arg1, ethptr->devAddress,
37  ETH_ADDR_LEN);
38  break;
39 
40  default:
41  return SYSERR;
42  }
43 
44  return retval;
45 }
unsigned char byte
符号なし8ビット値(unsigned char)
Definition: kernel.h:7
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
Definition: ether.h:68
#define OK
処理が成功した場合
Definition: kernel.h:77
byte devAddress[ETH_ADDR_LEN]
Definition: ether.h:96
#define ETH_CTRL_GET_MAC
Definition: ether.h:45
struct ethcblk ethertab[]
Definition: ethinit.c:7
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define ETH_ADDR_LEN
Definition: ether.h:10
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
Here is the call graph for this function:

◆ ethhandler()

interrupt ethhandler ( uint32  )

Definition at line 9 of file ethhandler.c.

References eth_a_csreg::cpdma, ethcblk::csr, DEFER_START, DEFER_STOP, eth_a_cpdma::eoi_vector, ETH_AM335X_RDS_OWN, ETH_AM335X_RXINT, ETH_AM335X_TDS_OWN, ETH_AM335X_TXINT, ethertab, ethcblk::isem, ethcblk::osem, resched_cntl(), eth_a_stateram::rx_cp, eth_a_stateram::rx_hdp, ethcblk::rxRing, ethcblk::rxRingSize, ethcblk::rxTail, semcount(), signal(), eth_a_rx_desc::stat, eth_a_tx_desc::stat, eth_a_csreg::stateram, eth_a_stateram::tx_cp, eth_a_stateram::tx_hdp, ethcblk::txHead, ethcblk::txRing, and ethcblk::txRingSize.

12 {
13  struct eth_a_csreg *csrptr; /* Ethernet CSR pointer */
14  struct eth_a_tx_desc *tdescptr; /* Tx desc pointer */
15  struct eth_a_rx_desc *rdescptr; /* Rx desc pointer */
16  struct ethcblk *ethptr = &ethertab[0]; /* Ethernet ctl blk ptr */
17 
18  csrptr = (struct eth_a_csreg *)ethptr->csr;
19 
20  if(xnum == ETH_AM335X_TXINT) { /* Transmit interrupt */
21 
22  /* Get pointer to first desc in queue */
23 
24  tdescptr = (struct eth_a_tx_desc *)ethptr->txRing +
25  ethptr->txHead;
26 
27  /* Defer scheduling until all descs are processed */
28 
30 
31  while(semcount(ethptr->osem) < (int32)ethptr->txRingSize) {
32 
33  /* If desc owned by DMA, check if we need to */
34  /* Restart the transmission */
35 
36  if(tdescptr->stat & ETH_AM335X_TDS_OWN) {
37  if(csrptr->stateram->tx_hdp[0] == 0) {
38  csrptr->stateram->tx_hdp[0] =
39  (uint32)tdescptr;
40  }
41  break;
42  }
43 
44  /* Acknowledge the interrupt */
45 
46  csrptr->stateram->tx_cp[0] = (uint32)tdescptr;
47 
48  /* Increment the head index of the queue */
49  /* And go to the next descriptor in queue */
50 
51  ethptr->txHead++;
52  tdescptr++;
53  if(ethptr->txHead >= ethptr->txRingSize) {
54  ethptr->txHead = 0;
55  tdescptr = (struct eth_a_tx_desc *)
56  ethptr->txRing;
57  }
58 
59  /* Signal the output semaphore */
60 
61  signal(ethptr->osem);
62  }
63 
64  /* Acknowledge the transmit interrupt */
65 
66  csrptr->cpdma->eoi_vector = 0x2;
67 
68  /* Resume rescheduling */
69 
71  }
72  else if(xnum == ETH_AM335X_RXINT) { /* Receive interrupt */
73 
74  /* Get the pointer to last desc in the queue */
75 
76  rdescptr = (struct eth_a_rx_desc *)ethptr->rxRing +
77  ethptr->rxTail;
78 
79  /* Defer scheduling until all descriptors are processed */
80 
82 
83  while(semcount(ethptr->isem) < (int32)ethptr->rxRingSize) {
84 
85  /* Check if we need to restart the DMA */
86 
87  if(rdescptr->stat & ETH_AM335X_RDS_OWN) {
88  if(csrptr->stateram->rx_hdp[0] == 0) {
89  csrptr->stateram->rx_hdp[0] =
90  (uint32)rdescptr;
91  }
92  break;
93  }
94 
95  /* Acknowledge the interrupt */
96 
97  csrptr->stateram->rx_cp[0] = (uint32)rdescptr;
98 
99  /* Increment the tail index of the queue */
100  /* And go to the next descriptor in the queue */
101 
102  ethptr->rxTail++;
103  rdescptr++;
104  if(ethptr->rxTail >= ethptr->rxRingSize) {
105  ethptr->rxTail = 0;
106  rdescptr = (struct eth_a_rx_desc *)
107  ethptr->rxRing;
108  }
109 
110  /* Signal the input semaphore */
111 
112  signal(ethptr->isem);
113  }
114 
115  /* Acknowledge the receive interrupt */
116 
117  csrptr->cpdma->eoi_vector = 0x1;
118 
119  /* Resume rescheduling */
120 
122  }
123 }
syscall semcount(sid32)
セマフォのカウント値を返す。
Definition: semcount.c:18
uint32 eoi_vector
CPDMA割り込み終了ベクタ
Definition: am335x_eth.h:94
void * rxRing
Definition: ether.h:82
uint16 stat
DMA状態
Definition: am335x_eth.h:363
uint32 txHead
Definition: ether.h:91
uint32 rx_hdp[8]
RX(受信) チャネル0〜7 先頭ディスクリプタへのポインタ
Definition: am335x_eth.h:128
#define ETH_AM335X_RDS_OWN
DMAが所持するディスクリプタ
Definition: am335x_eth.h:340
Ethernet subsystemレジスタ構造体
Definition: am335x_eth.h:297
DMA TX(送信)ディスクリプタ
Definition: am335x_eth.h:350
Definition: ether.h:68
volatile struct eth_a_cpdma * cpdma
CPSW_CPDMAレジスタ
Definition: am335x_eth.h:302
DMA RX(受信)ディスクリプタ
Definition: am335x_eth.h:319
status resched_cntl(int32)
再スケジューリングを延期させるか、もしくは許可させるかを制御する。
Definition: resched.c:81
struct ethcblk ethertab[]
Definition: ethinit.c:7
uint32 tx_hdp[8]
TX(送信) チャネル0〜7 先頭ディスクリプタへのポインタ
Definition: am335x_eth.h:126
uint16 stat
DMA状態
Definition: am335x_eth.h:332
volatile struct eth_a_stateram * stateram
CPSW_STATERANレジスタ
Definition: am335x_eth.h:304
#define DEFER_STOP
遅延リスケジューリングの停止
Definition: resched.h:10
uint32 rx_cp[8]
RX(受信) チャネル0〜7 完了ポインタレジスタ
Definition: am335x_eth.h:132
#define DEFER_START
遅延リスケジューリングの開始
Definition: resched.h:8
#define ETH_AM335X_TDS_OWN
DMAが所持するディスクリプタ
Definition: am335x_eth.h:371
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
void * txRing
Definition: ether.h:89
#define ETH_AM335X_RXINT
RX(受信)の割り込みベクタ
Definition: am335x_eth.h:396
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
void * csr
Definition: ether.h:76
uint32 rxRingSize
Definition: ether.h:86
uint32 txRingSize
Definition: ether.h:93
sid32 isem
Definition: ether.h:102
#define ETH_AM335X_TXINT
TX(送信)の割り込みベクタ
Definition: am335x_eth.h:398
uint32 tx_cp[8]
TX(送信) チャネル0〜7 完了ポインタレジスタ
Definition: am335x_eth.h:130
uint32 rxTail
Definition: ether.h:85
sid32 osem
Definition: ether.h:103
Here is the call graph for this function:

◆ ethinit()

int32 ethinit ( struct dentry )

Definition at line 173 of file ethinit.c.

References eth_a_csreg::ale, eth_a_rx_desc::buffer, eth_a_tx_desc::buffer, eth_a_rx_desc::buflen, eth_a_tx_desc::buflen, eth_a_rx_desc::bufoff, eth_a_tx_desc::bufoff, eth_a_wr::c0_rx_en, eth_a_wr::c0_tx_en, eth_a_csreg::cpdma, ethcblk::csr, eth_a_ale::ctrl, eth_a_mdio::ctrl, ethcblk::devAddress, dentry::dvintr, dentry::dvminor, eth_a_regs, ETH_AM335X_ALE_ADDR, ETH_AM335X_ALECTL_BY, ETH_AM335X_ALECTL_EN, ETH_AM335X_ALEPCTL_FWD, ETH_AM335X_CPDMA_ADDR, ETH_AM335X_MDIO_ADDR, ETH_AM335X_MDIOCTL_EN, ETH_AM335X_RDS_OWN, ETH_AM335X_RX_RING_SIZE, ETH_AM335X_RXINT, ETH_AM335X_SL1_ADDR, ETH_AM335X_SLCTL_EN, ETH_AM335X_SLCTL_FD, ETH_AM335X_SS_ADDR, ETH_AM335X_STATERAM_ADDR, ETH_AM335X_TDS_DIR, ETH_AM335X_TDS_EOP, ETH_AM335X_TDS_P1, ETH_AM335X_TDS_SOP, ETH_AM335X_TX_RING_SIZE, ETH_AM335X_TXINT, ETH_AM335X_WR_ADDR, ETH_BUF_SIZE, ETH_PHY_1000M, ETH_PHY_100M, ETH_PHY_10M, ETH_PHY_CTLREG, ETH_PHY_CTLREG_FD, ETH_PHY_CTLREG_SM, eth_phy_read(), eth_phy_reset(), ethertab, getmem(), ethcblk::isem, kprintf(), eth_a_sl::macctrl, eth_a_csreg::mdio, memset(), netpacket::net_ethdst, eth_a_rx_desc::next, eth_a_tx_desc::next, NULL, NULLCH, OK, ethcblk::osem, eth_a_ale::portctl, eth_a_cpdma::reset, eth_a_sl::reset, eth_a_ss::reset, eth_a_wr::reset, eth_a_cpdma::rx_ctrl, eth_a_stateram::rx_hdp, eth_a_cpdma::rx_intmask_set, ethcblk::rxBufs, ethcblk::rxHead, ethcblk::rxRing, ethcblk::rxRingSize, ethcblk::rxTail, semcreate(), set_evec(), eth_a_csreg::sl, eth_a_csreg::ss, eth_a_rx_desc::stat, eth_a_tx_desc::stat, eth_a_csreg::stateram, SYSERR, eth_a_cpdma::tx_ctrl, eth_a_stateram::tx_hdp, eth_a_cpdma::tx_intmask_set, ethcblk::txBufs, ethcblk::txHead, ethcblk::txRing, ethcblk::txRingSize, ethcblk::txTail, and eth_a_csreg::wr.

176 {
177  struct ethcblk *ethptr; /* Ethernet control blk pointer */
178  struct eth_a_tx_desc *tdescptr;/* Tx descriptor pointer */
179  struct eth_a_rx_desc *rdescptr;/* Rx descriptor pointer */
180  struct netpacket *pktptr; /* Packet pointer */
181  struct eth_a_csreg *csrptr; /* Ethernet CSR pointer */
182  uint32 phyreg; /* Variable to store PHY reg val*/
183  int32 retval; /* Return value */
184  int32 i; /* Index variable */
185 
186  /* Get the Ethernet control block address */
187  /* from the device table entry */
188 
189  ethptr = &ethertab[devptr->dvminor];
190 
191  /* Store the address of CSRs in the Ethernet control block */
192 
193  csrptr = &eth_a_regs;
194  ethptr->csr = csrptr;
195 
196  /* Initialize the addresses of all the submodules */
197 
198  csrptr->ale = (struct eth_a_ale *)ETH_AM335X_ALE_ADDR;
199  csrptr->cpdma = (struct eth_a_cpdma *)ETH_AM335X_CPDMA_ADDR;
200  csrptr->sl = (struct eth_a_sl *)ETH_AM335X_SL1_ADDR;
201  csrptr->stateram = (struct eth_a_stateram *)
203  csrptr->ss = (struct eth_a_ss *)ETH_AM335X_SS_ADDR;
204  csrptr->wr = (struct eth_a_wr *)ETH_AM335X_WR_ADDR;
205  csrptr->mdio = (struct eth_a_mdio *)ETH_AM335X_MDIO_ADDR;
206 
207  /* Reset all the submodules */
208 
209  csrptr->cpdma->reset = 1;
210  while(csrptr->cpdma->reset == 1);
211 
212  csrptr->sl->reset = 1;
213  while(csrptr->sl->reset == 1);
214 
215  csrptr->wr->reset = 1;
216  while(csrptr->wr->reset == 1) ;
217 
218  csrptr->ss->reset = 1;
219  while(csrptr->ss->reset == 1) ;
220 
221  /* Enable MDIO */
222 
223  csrptr->mdio->ctrl |= ETH_AM335X_MDIOCTL_EN;
224 
225  /* Reset the PHY */
226 
227  retval = eth_phy_reset(csrptr->mdio, 0);
228  if(retval == SYSERR) {
229  kprintf("Cannot reset Ethernet PHY\n");
230  return SYSERR;
231  }
232 
233  retval = eth_phy_read(csrptr->mdio, ETH_PHY_CTLREG, 0, &phyreg);
234  if(retval == SYSERR) {
235  return SYSERR;
236  }
237 
238  if( (phyreg & ETH_PHY_CTLREG_SM) == ETH_PHY_10M ) {
239  kprintf("Ethernet Link is Up. Speed is 10Mbps\n");
240  }
241  else if( (phyreg & ETH_PHY_CTLREG_SM) == ETH_PHY_100M ) {
242  kprintf("Ethernet Link is Up. Speed is 100Mbps\n");
243  }
244  else if( (phyreg & ETH_PHY_CTLREG_SM) == ETH_PHY_1000M ) {
245  kprintf("Ethernet Link is Up. Speed is 1000Mbps\n");
246  }
247  else {
248  return SYSERR;
249  }
250 
251  if(phyreg & ETH_PHY_CTLREG_FD) {
252  kprintf("Link is Full Duplex\n");
253  csrptr->sl->macctrl |= ETH_AM335X_SLCTL_FD;
254  }
255  else {
256  kprintf("Link is Half Duplex\n");
257  }
258 
259  /* Read the device MAC address */
260  for(i = 0; i < 2; i++) {
261  ethptr->devAddress[4+i] = *((byte *)(0x44e10630+i));
262  }
263  for(i = 0; i < 4; i++) {
264  ethptr->devAddress[i] = *((byte *)(0x44e10634+i));
265  }
266 
267  kprintf("MAC Address is: ");
268  for(i = 0; i < 5; i++) {
269  kprintf("%02X:", ethptr->devAddress[i]);
270  }
271  kprintf("%02X\n", ethptr->devAddress[5]);
272 
273  /* Initialize the rx ring size field */
275 
276  /* Allocate memory for the rx ring */
277  ethptr->rxRing = (void*)getmem(sizeof(struct eth_a_rx_desc)*
278  ethptr->rxRingSize);
279  if((int32)ethptr->rxRing == SYSERR) {
280  return SYSERR;
281  }
282 
283  /* Zero out the rx ring */
284  memset((char*)ethptr->rxRing, NULLCH,
285  sizeof(struct eth_a_rx_desc)*ethptr->rxRingSize);
286 
287  /* Allocate memory for rx buffers */
288  ethptr->rxBufs = (void*)getmem(ETH_BUF_SIZE *
289  ethptr->rxRingSize);
290  if((int32)ethptr->rxBufs == SYSERR) {
291  return SYSERR;
292  }
293 
294  /* Zero out the rx buffers */
295  memset((char *)ethptr->rxBufs, NULLCH, ETH_BUF_SIZE *
296  ethptr->rxRingSize);
297 
298  /* Initialize the rx ring */
299 
300  rdescptr = (struct eth_a_rx_desc *)ethptr->rxRing;
301  pktptr = (struct netpacket *)ethptr->rxBufs;
302 
303  for(i = 0; i < ethptr->rxRingSize; i++) {
304  rdescptr->next = rdescptr + 1;
305  rdescptr->buffer = (uint32)pktptr->net_ethdst;
306  rdescptr->buflen = ETH_BUF_SIZE;
307  rdescptr->bufoff = 0;
308  rdescptr->stat = ETH_AM335X_RDS_OWN;
309  rdescptr++;
310  pktptr++;
311  }
312  (--rdescptr)->next = NULL;
313 
314  ethptr->rxHead = 0;
315  ethptr->rxTail = 0;
316  ethptr->isem = semcreate(0);
317  if((int32)ethptr->isem == SYSERR) {
318  return SYSERR;
319  }
320 
321  /* initialize the tx ring size */
323 
324  /* Allocate memory for tx ring */
325  ethptr->txRing = (void*)getmem(sizeof(struct eth_a_tx_desc)*
326  ethptr->txRingSize);
327  if((int32)ethptr->txRing == SYSERR) {
328  return SYSERR;
329  }
330 
331  /* Zero out the tx ring */
332  memset((char*)ethptr->txRing, NULLCH,
333  sizeof(struct eth_a_tx_desc)*ethptr->txRingSize);
334 
335  /* Allocate memory for tx buffers */
336  ethptr->txBufs = (void*)getmem(ETH_BUF_SIZE *
337  ethptr->txRingSize);
338  if((int32)ethptr->txBufs == SYSERR) {
339  return SYSERR;
340  }
341 
342  /* Zero out the tx buffers */
343  memset((char*)ethptr->txBufs, NULLCH, ETH_BUF_SIZE *
344  ethptr->txRingSize);
345 
346  /* Initialize the tx ring */
347 
348  tdescptr = (struct eth_a_tx_desc *)ethptr->txRing;
349  pktptr = (struct netpacket *)ethptr->txBufs;
350 
351  for(i = 0; i < ethptr->txRingSize; i++) {
352  tdescptr->next = NULL;
353  tdescptr->buffer = (uint32)pktptr->net_ethdst;
354  tdescptr->buflen = ETH_BUF_SIZE;
355  tdescptr->bufoff = 0;
356  tdescptr->stat = (ETH_AM335X_TDS_SOP |
360  tdescptr++;
361  pktptr++;
362  }
363 
364  ethptr->txHead = 0;
365  ethptr->txTail = 0;
366  ethptr->osem = semcreate(ethptr->txRingSize);
367  if((int32)ethptr->osem == SYSERR) {
368  return SYSERR;
369  }
370 
371  /* Enable the ALE and put it into bypass mode */
372  csrptr->ale->ctrl = (ETH_AM335X_ALECTL_EN |
374 
375  /* Put the ports 0, 1 in forwarding state */
376  csrptr->ale->portctl[0] = ETH_AM335X_ALEPCTL_FWD;
377  csrptr->ale->portctl[1] = ETH_AM335X_ALEPCTL_FWD;
378 
379  /* Start the rx and tx processes in DMA */
380  csrptr->cpdma->tx_ctrl = 1;
381  csrptr->cpdma->rx_ctrl = 1;
382 
383  /* Initialize the head desc pointers for tx and rx */
384  csrptr->stateram->tx_hdp[0] = 0;
385  csrptr->stateram->rx_hdp[0] = (uint32)ethptr->rxRing;
386 
387  /* Enable Rx and Tx in MAC */
388  csrptr->sl->macctrl |= ETH_AM335X_SLCTL_EN;
389 
390  /* Set interrupt vectors */
391  set_evec(ETH_AM335X_TXINT, (uint32)devptr->dvintr);
392  set_evec(ETH_AM335X_RXINT, (uint32)devptr->dvintr);
393 
394  /* Enable the CPDMA interrupts */
395  csrptr->cpdma->tx_intmask_set = 0x1;
396  csrptr->cpdma->rx_intmask_set = 0x1;
397 
398  /* Route the interrupts to core 0 */
399  csrptr->wr->c0_tx_en = 0x1;
400  csrptr->wr->c0_rx_en = 0x1;
401 
402  return OK;
403 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
#define ETH_AM335X_SS_ADDR
SSの開始アドレス
Definition: am335x_eth.h:392
Address Lookup Engine(ALE)レジスタ用の構造体
Definition: am335x_eth.h:10
Cryptographic Processor RAM DMA(CPDMA、暗号化DMA)レジスタ用の構造体
Definition: am335x_eth.h:53
#define ETH_AM335X_ALECTL_EN
Address Lookup Engine(ALE)を有効化する
Definition: am335x_eth.h:43
uint16 buflen
DMAバッファの長さ
Definition: am335x_eth.h:357
unsigned char byte
符号なし8ビット値(unsigned char)
Definition: kernel.h:7
#define ETH_PHY_10M
Definition: ether.h:61
void * rxRing
Definition: ether.h:82
uint16 stat
DMA状態
Definition: am335x_eth.h:363
uint32 txTail
Definition: ether.h:92
uint32 c0_rx_en
サブシステム コア0 RX(受信)割り込み許可レジスタ
Definition: am335x_eth.h:225
uint32 txHead
Definition: ether.h:91
#define ETH_AM335X_TDS_SOP
TX(送信)パケットの開始
Definition: am335x_eth.h:367
uint32 tx_intmask_set
TX(送信)割り込みマスクセットレジスタ
Definition: am335x_eth.h:88
sid32 semcreate(int32)
未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。
Definition: semcreate.c:22
#define ETH_AM335X_MDIO_ADDR
Management Data Input/Output(MDIO)の開始アドレス
Definition: am335x_eth.h:390
volatile struct eth_a_mdio * mdio
MDIOレジスタ
Definition: am335x_eth.h:312
#define ETH_AM335X_SLCTL_EN
受信/送信の有効化
Definition: am335x_eth.h:170
uint32 rx_hdp[8]
RX(受信) チャネル0〜7 先頭ディスクリプタへのポインタ
Definition: am335x_eth.h:128
#define ETH_AM335X_ALEPCTL_FWD
Address Lookup Engine(ALE)制御をポートフォワード状態とする
Definition: am335x_eth.h:47
#define ETH_AM335X_RDS_OWN
DMAが所持するディスクリプタ
Definition: am335x_eth.h:340
uint32 ctrl
ALE制御レジスタ
Definition: am335x_eth.h:17
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define ETH_AM335X_ALE_ADDR
Address Lookup Engine(ALE)の開始アドレス
Definition: am335x_eth.h:382
uint32 reset
SLソフトリセットレジスタ
Definition: am335x_eth.h:148
Ethernet subsystemレジスタ構造体
Definition: am335x_eth.h:297
DMA TX(送信)ディスクリプタ
Definition: am335x_eth.h:350
byte net_ethdst[ETH_ADDR_LEN]
Definition: net.h:17
Definition: ether.h:68
uint32 rxHead
Definition: ether.h:84
volatile struct eth_a_sl * sl
CPSW_SLレジスタ
Definition: am335x_eth.h:306
#define ETH_PHY_1000M
Definition: ether.h:63
uint32 reset
WRソフトリセットレジスタ
Definition: am335x_eth.h:217
volatile struct eth_a_ss * ss
CPSW_SSレジスタ
Definition: am335x_eth.h:308
uint32 rx_ctrl
RX(受信) 制御レジスタ
Definition: am335x_eth.h:66
#define ETH_BUF_SIZE
Definition: ether.h:34
#define ETH_AM335X_MDIOCTL_EN
Management Data Input/Output(MDIO)制御を有効化
Definition: am335x_eth.h:283
struct eth_a_tx_desc * next
次のDMA TX(受信)ディスクリプタ
Definition: am335x_eth.h:353
#define ETH_AM335X_WR_ADDR
WRの開始アドレス
Definition: am335x_eth.h:394
volatile struct eth_a_cpdma * cpdma
CPSW_CPDMAレジスタ
Definition: am335x_eth.h:302
#define OK
処理が成功した場合
Definition: kernel.h:77
byte devAddress[ETH_ADDR_LEN]
Definition: ether.h:96
DMA RX(受信)ディスクリプタ
Definition: am335x_eth.h:319
#define ETH_AM335X_STATERAM_ADDR
STATERAMの開始アドレス
Definition: am335x_eth.h:386
void * txBufs
Definition: ether.h:90
#define ETH_AM335X_CPDMA_ADDR
Cryptographic Processor RAM DMA(CPDMA、暗号化DMA)の開始アドレス
Definition: am335x_eth.h:384
uint32 reset
SSソフトリセットレジスタ
Definition: am335x_eth.h:185
struct ethcblk ethertab[1]
Definition: ethinit.c:7
uint16 bufoff
DMAバッファのオフセット
Definition: am335x_eth.h:328
Management Data Input/Output(MDIO)レジスタ用の構造体
Definition: am335x_eth.h:246
struct eth_a_rx_desc * next
次のDMA RX(受信)ディスクリプタ
Definition: am335x_eth.h:322
uint32 tx_hdp[8]
TX(送信) チャネル0〜7 先頭ディスクリプタへのポインタ
Definition: am335x_eth.h:126
int32 set_evec(uint32, uint32)
Definition: evec.c:37
uint16 stat
DMA状態
Definition: am335x_eth.h:332
uint32 reset
CPDMAソフトリセットレジスタ
Definition: am335x_eth.h:70
CPSW_SLレジスタ用の構造体
Definition: am335x_eth.h:139
volatile struct eth_a_stateram * stateram
CPSW_STATERANレジスタ
Definition: am335x_eth.h:304
uint16 buflen
DMAバッファの長さ
Definition: am335x_eth.h:326
#define ETH_AM335X_TDS_DIR
不明
Definition: am335x_eth.h:375
CPDMA_STATERAMレジスタ用の構造体
Definition: am335x_eth.h:123
CPSW_SSレジスタ用の構造体
Definition: am335x_eth.h:178
CPSW_WRレジスタ用の構造体
Definition: am335x_eth.h:212
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define ETH_AM335X_TDS_P1
不明
Definition: am335x_eth.h:377
void * txRing
Definition: ether.h:89
int32 eth_phy_reset(volatile struct eth_a_mdio *mdio, byte phyadr)
Definition: ethinit.c:107
uint32 c0_tx_en
サブシステム コア0 TX(送信)割り込み許可レジスタ
Definition: am335x_eth.h:227
#define ETH_AM335X_TDS_EOP
TX(送信)パケットの終了
Definition: am335x_eth.h:369
uint32 ctrl
MDIO制御レジスタ
Definition: am335x_eth.h:251
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
volatile struct eth_a_wr * wr
CPSW_WRレジスタ
Definition: am335x_eth.h:310
#define ETH_AM335X_ALECTL_BY
Address Lookup Engine(ALE)制御をBypassモードとする
Definition: am335x_eth.h:45
uint32 buffer
DMAバッファ
Definition: am335x_eth.h:324
uint32 tx_ctrl
TX(送信) 制御レジスタ
Definition: am335x_eth.h:58
uint16 bufoff
DMAバッファのオフセット
Definition: am335x_eth.h:359
Definition: net.h:16
struct eth_a_csreg eth_a_regs
Definition: ethinit.c:5
void * rxBufs
Definition: ether.h:83
#define ETH_AM335X_RX_RING_SIZE
RX(受信)リングバッファサイズ
Definition: am335x_eth.h:344
#define ETH_AM335X_TX_RING_SIZE
TX(送信)リングバッファサイズ
Definition: am335x_eth.h:379
#define ETH_AM335X_RXINT
RX(受信)の割り込みベクタ
Definition: am335x_eth.h:396
#define ETH_PHY_CTLREG_SM
Definition: ether.h:60
uint32 macctrl
DMAC制御レジスタ
Definition: am335x_eth.h:144
#define ETH_PHY_100M
Definition: ether.h:62
uint32 rx_intmask_set
RX(受信)割り込みマスクセットレジスタ
Definition: am335x_eth.h:102
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
int32 eth_phy_read(volatile struct eth_a_mdio *mdio, byte regadr, byte phyadr, uint32 *value)
Definition: ethinit.c:13
void * csr
Definition: ether.h:76
uint32 rxRingSize
Definition: ether.h:86
uint32 txRingSize
Definition: ether.h:93
sid32 isem
Definition: ether.h:102
#define ETH_AM335X_TXINT
TX(送信)の割り込みベクタ
Definition: am335x_eth.h:398
#define ETH_PHY_CTLREG
Definition: ether.h:56
uint32 buffer
DMAバッファ
Definition: am335x_eth.h:355
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
volatile struct eth_a_ale * ale
CPSW_ALEレジスタ
Definition: am335x_eth.h:300
#define ETH_PHY_CTLREG_FD
Definition: ether.h:64
uint32 rxTail
Definition: ether.h:85
#define ETH_AM335X_SLCTL_FD
全二重通信
Definition: am335x_eth.h:166
#define ETH_AM335X_SL1_ADDR
SL1の開始アドレス
Definition: am335x_eth.h:388
uint32 portctl[6]
ALEポート0〜5制御レジスタ
Definition: am335x_eth.h:39
sid32 osem
Definition: ether.h:103
char * getmem(uint32)
ヒープ領域を割り当て、最下位のワードアドレスを返す。
Definition: getmem.c:25
Here is the call graph for this function:

◆ ethread()

int32 ethread ( struct dentry ,
void *  ,
uint32   
)

Definition at line 9 of file ethread.c.

References eth_a_rx_desc::buffer, eth_a_rx_desc::buflen, eth_a_rx_desc::bufoff, ethcblk::csr, dentry::dvminor, ETH_AM335X_RDS_OWN, ETH_BUF_SIZE, ethertab, ethcblk::isem, kprintf(), memcpy(), eth_a_rx_desc::next, NULL, eth_a_rx_desc::packlen, eth_a_stateram::rx_hdp, ethcblk::rxHead, ethcblk::rxRing, ethcblk::rxRingSize, eth_a_rx_desc::stat, eth_a_csreg::stateram, and wait().

14 {
15  struct ethcblk *ethptr; /* Ethernet ctl blk ptr */
16  struct eth_a_csreg *csrptr; /* Ethernet CSR pointer */
17  struct eth_a_rx_desc *rdescptr;/* Rx Desc. pointer */
18  struct eth_a_rx_desc *prev; /* Prev Rx desc pointer */
19  uint32 retval; /* Num of bytes returned*/
20 
21  ethptr = &ethertab[devptr->dvminor];
22 
23  /* Get the pointer to Ethernet CSR */
24  csrptr = (struct eth_a_csreg *)ethptr->csr;
25 
26  /* Wait for a packet */
27  wait(ethptr->isem);
28 
29  /* Get pointer to the descriptor */
30  rdescptr = (struct eth_a_rx_desc *)ethptr->rxRing +
31  ethptr->rxHead;
32 
33  /* Read the packet length */
34  retval = rdescptr->packlen;
35  if(retval > count) {
36  retval = count;
37  }
38 
39  /* Copy the packet into user provided buffer */
40  memcpy((char *)buf, (char *)rdescptr->buffer, retval);
41 
42  /* Initialize the descriptor for next packet */
43  rdescptr->stat = ETH_AM335X_RDS_OWN;
44  rdescptr->bufoff = 0;
45  rdescptr->buflen = ETH_BUF_SIZE;
46  rdescptr->packlen = 0;
47  rdescptr->next = NULL;
48 
49  /* Insert the descriptor into Rx queue */
50  prev = (struct eth_a_rx_desc *)csrptr->stateram->rx_hdp[0];
51  if(prev == NULL) {
52  kprintf("hdp 0, adding %x\n", rdescptr);
53  csrptr->stateram->rx_hdp[0] = (uint32)rdescptr;
54  }
55  else {
56  while(prev->next != NULL) {
57  prev = prev->next;
58  }
59  prev->next = rdescptr;
60  }
61 
62  /* Increment the head index of rx ring */
63  ethptr->rxHead++;
64  if(ethptr->rxHead >= ethptr->rxRingSize) {
65  ethptr->rxHead = 0;
66  }
67 
68  return retval;
69 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
uint16 packlen
DMAパケットの長さ
Definition: am335x_eth.h:330
void * rxRing
Definition: ether.h:82
uint32 rx_hdp[8]
RX(受信) チャネル0〜7 先頭ディスクリプタへのポインタ
Definition: am335x_eth.h:128
#define ETH_AM335X_RDS_OWN
DMAが所持するディスクリプタ
Definition: am335x_eth.h:340
Ethernet subsystemレジスタ構造体
Definition: am335x_eth.h:297
Definition: ether.h:68
uint32 rxHead
Definition: ether.h:84
#define ETH_BUF_SIZE
Definition: ether.h:34
DMA RX(受信)ディスクリプタ
Definition: am335x_eth.h:319
uint16 bufoff
DMAバッファのオフセット
Definition: am335x_eth.h:328
struct eth_a_rx_desc * next
次のDMA RX(受信)ディスクリプタ
Definition: am335x_eth.h:322
struct ethcblk ethertab[]
Definition: ethinit.c:7
uint16 stat
DMA状態
Definition: am335x_eth.h:332
volatile struct eth_a_stateram * stateram
CPSW_STATERANレジスタ
Definition: am335x_eth.h:304
uint16 buflen
DMAバッファの長さ
Definition: am335x_eth.h:326
uint32 buffer
DMAバッファ
Definition: am335x_eth.h:324
syscall wait(sid32)
Definition: wait.c:9
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
void * csr
Definition: ether.h:76
uint32 rxRingSize
Definition: ether.h:86
sid32 isem
Definition: ether.h:102
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
Here is the call graph for this function:

◆ ethwrite()

int32 ethwrite ( struct dentry ,
void *  ,
uint32   
)

Definition at line 9 of file ethwrite.c.

References eth_a_tx_desc::buffer, eth_a_tx_desc::buflen, eth_a_tx_desc::bufoff, ethcblk::csr, dentry::dvminor, ETH_AM335X_TDS_DIR, ETH_AM335X_TDS_EOP, ETH_AM335X_TDS_OWN, ETH_AM335X_TDS_P1, ETH_AM335X_TDS_SOP, ethertab, memcpy(), memset(), eth_a_tx_desc::next, NULL, ethcblk::osem, PACKLEN, eth_a_tx_desc::packlen, eth_a_tx_desc::stat, eth_a_csreg::stateram, eth_a_stateram::tx_hdp, ethcblk::txRing, ethcblk::txRingSize, ethcblk::txTail, and wait().

14 {
15  struct ethcblk *ethptr; /* Ether entry pointer */
16  struct eth_a_csreg *csrptr; /* Ethernet CSR pointer */
17  struct eth_a_tx_desc *tdescptr;/* Tx Desc. pointer */
18  struct eth_a_tx_desc *prev; /* Prev. Desc. pointer */
19 
20  ethptr = &ethertab[devptr->dvminor];
21 
22  /* Get the pointer to the Ethernet CSR */
23  csrptr = (struct eth_a_csreg *)ethptr->csr;
24 
25  /* Wait for an empty slot in the queue */
26  wait(ethptr->osem);
27 
28  /* Get the pointer to the next descriptor */
29  tdescptr = (struct eth_a_tx_desc *)ethptr->txRing +
30  ethptr->txTail;
31 
32  /* Adjust count if greater than max. possible packet size */
33  if(count > PACKLEN) {
34  count = PACKLEN;
35  }
36 
37  /* Initialize the descriptor */
38  tdescptr->next = NULL;
39  tdescptr->buflen = count;
40  tdescptr->bufoff = 0;
41  tdescptr->packlen = count;
42  tdescptr->stat = (ETH_AM335X_TDS_SOP | /* Start of packet */
43  ETH_AM335X_TDS_EOP | /* End of packet */
44  ETH_AM335X_TDS_OWN | /* Own flag set for DMA */
45  ETH_AM335X_TDS_DIR | /* Directed packet */
46  ETH_AM335X_TDS_P1); /* Output port is port1 */
47 
48  /* Copy the packet into the Tx buffer */
49  memcpy((char *)tdescptr->buffer, buf, count);
50 
51  /* TODO Figure out why we need this hack */
52  /* This ethernet device does not send packets smaller than 60 */
53  /* bytes; So pad a small packet to make it 60 bytes long */
54 
55  if(count < 60) {
56  memset((char *)tdescptr->buffer+count, 0, 60-count);
57  tdescptr->buflen = 60;
58  tdescptr->packlen = 60;
59  }
60 
61  /* Insert the descriptor into Tx queue */
62 
63  if(csrptr->stateram->tx_hdp[0] == 0) {
64  /* Tx queue is empty, this desc. will be the first */
65  csrptr->stateram->tx_hdp[0] = (uint32)tdescptr;
66  }
67  else {
68  /* Tx queue not empty, insert at end */
69  prev = (struct eth_a_tx_desc *)
70  csrptr->stateram->tx_hdp[0];
71  while(prev->next != NULL) {
72  prev = prev->next;
73  }
74  prev->next = tdescptr;
75  }
76 
77  /* Increment the tail index of the Tx ring */
78  ethptr->txTail++;
79  if(ethptr->txTail >= ethptr->txRingSize) {
80  ethptr->txTail = 0;
81  }
82 
83  return count;
84 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
uint16 buflen
DMAバッファの長さ
Definition: am335x_eth.h:357
uint16 stat
DMA状態
Definition: am335x_eth.h:363
uint32 txTail
Definition: ether.h:92
#define ETH_AM335X_TDS_SOP
TX(送信)パケットの開始
Definition: am335x_eth.h:367
Ethernet subsystemレジスタ構造体
Definition: am335x_eth.h:297
DMA TX(送信)ディスクリプタ
Definition: am335x_eth.h:350
Definition: ether.h:68
uint16 packlen
DMAパケットの長さ
Definition: am335x_eth.h:361
struct eth_a_tx_desc * next
次のDMA TX(受信)ディスクリプタ
Definition: am335x_eth.h:353
struct ethcblk ethertab[]
Definition: ethinit.c:7
uint32 tx_hdp[8]
TX(送信) チャネル0〜7 先頭ディスクリプタへのポインタ
Definition: am335x_eth.h:126
#define PACKLEN
Definition: net.h:50
volatile struct eth_a_stateram * stateram
CPSW_STATERANレジスタ
Definition: am335x_eth.h:304
#define ETH_AM335X_TDS_DIR
不明
Definition: am335x_eth.h:375
#define ETH_AM335X_TDS_OWN
DMAが所持するディスクリプタ
Definition: am335x_eth.h:371
#define ETH_AM335X_TDS_P1
不明
Definition: am335x_eth.h:377
void * txRing
Definition: ether.h:89
#define ETH_AM335X_TDS_EOP
TX(送信)パケットの終了
Definition: am335x_eth.h:369
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
uint16 bufoff
DMAバッファのオフセット
Definition: am335x_eth.h:359
syscall wait(sid32)
Definition: wait.c:9
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
void * csr
Definition: ether.h:76
uint32 txRingSize
Definition: ether.h:93
uint32 buffer
DMAバッファ
Definition: am335x_eth.h:355
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
sid32 osem
Definition: ether.h:103
Here is the call graph for this function:

◆ exception()

void exception ( int32  ,
int32  
)

◆ freebuf()

syscall freebuf ( char *  bufaddr)

バッファプールから取得したバッファを解放する。

Step1. 割り込みを禁止する。
Step2. 解放対象バッファアドレスの4Byte前に埋め込んだバッファプールIDが不正値かどうかを確認し、
不正値であれば割り込み状態を復元し、処理を終了する。
Step3. 解放対象バッファをバッファプールに戻す。
Step4. セマフォにシグナルを送り、待機プロセスがいれば待機解除とする。
Step5. 割り込み状態を復元する。

Parameters
[in]bufaddrgetbuf()で取得したバッファアドレス
Returns
バッファを解放した場合はOK、バッファプールIDが不正値の場合はSYSERRを返す。

Definition at line 19 of file freebuf.c.

References bpentry::bpnext, bpentry::bpsem, buftab, disable(), nbpools, OK, restore(), signal(), and SYSERR.

Referenced by arp_in(), icmp_in(), icmp_recv(), icmp_release(), ip_enqueue(), ip_in(), ip_local(), ip_out(), ip_send(), ipout(), netin(), udp_in(), udp_recv(), udp_recvaddr(), and udp_release().

20 {
21  intmask mask; /* Saved interrupt mask */
22  struct bpentry *bpptr; /* Pointer to entry in buftab */
23  bpid32 poolid; /* ID of buffer's pool */
24 
25  mask = disable();
26 
27  /* Extract pool ID from integer prior to buffer address */
28 
29  bufaddr -= sizeof(bpid32);
30  poolid = *(bpid32 *)bufaddr;
31  if (poolid < 0 || poolid >= nbpools)
32  {
33  restore(mask);
34  return SYSERR;
35  }
36 
37  /* Get address of correct pool entry in table */
38 
39  bpptr = &buftab[poolid];
40 
41  /* Insert buffer into list and signal semaphore */
42 
43  ((struct bpentry *)bufaddr)->bpnext = bpptr->bpnext;
44  bpptr->bpnext = (struct bpentry *)bufaddr;
45  signal(bpptr->bpsem);
46  restore(mask);
47  return OK;
48 }
struct bpentry buftab[]
バッファプールテーブルのextern宣言
Definition: bufinit.c:8
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
int32 bpid32
バッファプールID
Definition: kernel.h:34
bpid32 nbpools
割り当てられたバッファプールの現在の数
Definition: bufinit.c:10
sid32 bpsem
バッファプールで現在使用可能なバッファをカウントするセマフォ
Definition: bufpool.h:32
struct bpentry * bpnext
次のフリーバッファへのポインタ
Definition: bufpool.h:30
バッファプールテーブルエントリ
Definition: bufpool.h:27
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ freemem()

syscall freemem ( char *  blkaddr,
uint32  nbytes 
)

メモリブロックを解放し、ブロックを空きリストに戻す。

Step1. 割り込みを禁止する。
Step2. 以下のいずれかの場合は、割り込み状態を復元し、処理を終了する。
・メモリブロックのサイズが0の場合
・メモリブロックのポインタがヒープ開始アドレスより小さい場合
・メモリブロックのポインタがヒープ終了アドレスより大きい場合
Step4. メモリブロックのサイズを8の倍数で丸める。
Step5. フリーメモリリストから空きメモリブロックの位置を探す。
Step6. 「一つ前のメモリブロック」と「解放対象メモリブロック」の結合を試みるため、
一つ前のメモリブロックの最終アドレスを算出する(このアドレスはTOPとして扱う)。
Step7. 解放対象メモリブロックが前後のメモリブロックと重なっていた場合は、
割り込み状態を復元し、処理を終了する。
Step8. フリーメモリリストの使用可能メモリサイズに対して、今回解放するメモリブロックのサイズを加算する。
Step9. 解放対象のメモリブロックを一つ前のメモリブロックと結合するか、フリーメモリリストに追加する。
Step10. 解放対象のメモリブロックが次のメモリブロックと隣接している場合は、結合する。
Step11. 割り込み状態を復元する。

Parameters
[in]blkaddrメモリブロックのポインタ
[in]nbytesメモリブロックのサイズ(Byte)
Returns
メモリ解放時はOKを返し、以下のいずれかの場合はSYSERRを返す。
・メモリブロックのサイズが0の場合
・メモリブロックのポインタがヒープ開始アドレスより小さい場合
・メモリブロックのポインタがヒープ終了アドレスより大きい場合
・解放対象メモリブロックが前後のメモリブロックと重なっていた場合

Definition at line 33 of file freemem.c.

References disable(), maxheap, memlist, minheap, memblk::mlength, memblk::mnext, NULL, OK, restore(), roundmb, and SYSERR.

Referenced by mkbufpool().

34 {
35  intmask mask; /* Saved interrupt mask */
36  struct memblk *next, *prev, *block;
37  uint32 top;
38 
39  mask = disable();
40  if ((nbytes == 0) || ((uint32)blkaddr < (uint32)minheap) || ((uint32)blkaddr > (uint32)maxheap))
41  {
42  restore(mask);
43  return SYSERR;
44  }
45 
46  nbytes = (uint32)roundmb(nbytes); /* Use memblk multiples */
47  block = (struct memblk *)blkaddr;
48 
49  prev = &memlist; /* Walk along free list */
50  next = memlist.mnext;
51  while ((next != NULL) && (next < block))
52  {
53  prev = next;
54  next = next->mnext;
55  }
56 
57  if (prev == &memlist)
58  { /* Compute top of previous block*/
59  top = (uint32)NULL;
60  }
61  else
62  {
63  top = (uint32)prev + prev->mlength;
64  }
65 
66  /* Ensure new block does not overlap previous or next blocks */
67 
68  if (((prev != &memlist) && (uint32)block < top) || ((next != NULL) && (uint32)block + nbytes > (uint32)next))
69  {
70  restore(mask);
71  return SYSERR;
72  }
73 
74  memlist.mlength += nbytes;
75 
76  /* Either coalesce with previous block or add to free list */
77 
78  if (top == (uint32)block)
79  { /* Coalesce with previous block */
80  prev->mlength += nbytes;
81  block = prev;
82  }
83  else
84  { /* Link into list as new node */
85  block->mnext = next;
86  block->mlength = nbytes;
87  prev->mnext = block;
88  }
89 
90  /* Coalesce with next block if adjacent */
91 
92  if (((uint32)block + block->mlength) == (uint32)next)
93  {
94  block->mlength += next->mlength;
95  block->mnext = next->mnext;
96  }
97  restore(mask);
98  return OK;
99 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
メモリブロックを管理するための構造体。
Definition: memory.h:53
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define roundmb(x)
メモリブロックサイズ(8の倍数)にアドレスを変換するために、8の倍数で丸める。
Definition: memory.h:25
struct memblk * mnext
次のフリーメモリブロックへのポインタ
Definition: memory.h:56
#define OK
処理が成功した場合
Definition: kernel.h:77
struct memblk memlist
フリーメモリリストの先頭
Definition: initialize.c:27
void * maxheap
最上位かつ正常なヒープアドレス
Definition: meminit.c:10
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
void * minheap
ヒープの開始地点
Definition: meminit.c:8
uint32 mlength
memblk構造体のサイズを含むブロックサイズ
Definition: memory.h:58
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getbuf()

char* getbuf ( bpid32  poolid)

事前に確保されたバッファプールからバッファを取得する。

Step1. 割り込みを禁止する。
Step2. バッファプールIDが不正値の場合は、割り込み状態を復元し、処理を終了する。
Step3. バッファプールに使用できるバッファが用意されるまで、待機する。
Step4. 提供するバッファをプール(リスト)から切り離す。
Step5. 提供するバッファの先頭4byteにバッファプールIDを記録し、4Byte分だけバッファのポインタを進める。
Step6. 割り込み状態を復元する。

Parameters
[in]poolidバッファテーブル中のバッファプールID
Returns
成功時はバッファへのポインタ、バッファプールIDが不正の場合はSYSERRを返す。

Definition at line 19 of file getbuf.c.

References bpentry::bpnext, bpentry::bpsem, buftab, disable(), nbpools, restore(), SYSERR, and wait().

Referenced by icmp_mkpkt(), netin(), udp_send(), and udp_sendto().

20 {
21  intmask mask; /* Saved interrupt mask */
22  struct bpentry *bpptr; /* Pointer to entry in buftab */
23  struct bpentry *bufptr; /* Pointer to a buffer */
24 
25  mask = disable();
26 
27  /* Check arguments */
28 
29  if ((poolid < 0 || poolid >= nbpools))
30  {
31  restore(mask);
32  return (char *)SYSERR;
33  }
34  bpptr = &buftab[poolid];
35 
36  /* Wait for pool to have > 0 buffers and allocate a buffer */
37 
38  wait(bpptr->bpsem);
39  bufptr = bpptr->bpnext;
40 
41  /* Unlink buffer from pool */
42 
43  bpptr->bpnext = bufptr->bpnext;
44 
45  /* Record pool ID in first four bytes of buffer and skip */
46 
47  *(bpid32 *)bufptr = poolid;
48  bufptr = (struct bpentry *)(sizeof(bpid32) + (char *)bufptr);
49  restore(mask);
50  return (char *)bufptr;
51 }
struct bpentry buftab[]
バッファプールテーブルのextern宣言
Definition: bufinit.c:8
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
int32 bpid32
バッファプールID
Definition: kernel.h:34
bpid32 nbpools
割り当てられたバッファプールの現在の数
Definition: bufinit.c:10
sid32 bpsem
バッファプールで現在使用可能なバッファをカウントするセマフォ
Definition: bufpool.h:32
struct bpentry * bpnext
次のフリーバッファへのポインタ
Definition: bufpool.h:30
バッファプールテーブルエントリ
Definition: bufpool.h:27
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
syscall wait(sid32)
Definition: wait.c:9
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getc()

syscall getc ( did32  )

Definition at line 9 of file getc.c.

Referenced by xsh_cat().

12 {
13  intmask mask; /* Saved interrupt mask */
14  struct dentry *devptr; /* Entry in device switch table */
15  int32 retval; /* Value to return to caller */
16 
17  mask = disable();
18  if (isbaddev(descrp)) {
19  restore(mask);
20  return SYSERR;
21  }
22  devptr = (struct dentry *) &devtab[descrp];
23  retval = (*devptr->dvgetc) (devptr);
24  restore(mask);
25  return retval;
26 }
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
Definition: conf.h:6
struct dentry devtab[]
Definition: conf.c:11
devcall(* dvgetc)(struct dentry *)
Definition: conf.h:16
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define isbaddev(f)
デバイスIDを検証するマクロ。
Definition: device.h:15
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the caller graph for this function:

◆ getfirst()

pid32 getfirst ( qid16  q)

キューの先頭からプロセスを取り出す。

Parameters
[in]qプロセスを取り出すためのキューID(チェックなしで有効)
Returns
キューにプロセスがある場合はキューの先頭にあるプロセスID、
キューが空の場合はEMPTYを返す。

Definition at line 13 of file getitem.c.

References EMPTY, getitem(), isempty, queuehead, and queuetab.

Referenced by dequeue(), semdelete(), and semreset().

14 {
15  pid32 head;
16 
17  if (isempty(q))
18  {
19  return EMPTY;
20  }
21 
22  head = queuehead(q);
23  return getitem(queuetab[head].qnext);
24 }
struct qentry queuetab[]
Definition: queue.c:45
#define queuehead(q)
キューの先頭を返す。
Definition: queue.h:53
#define EMPTY
次のキューインデックスもしくは前のキューインデックスがNULL値
Definition: queue.h:23
#define isempty(q)
リストが空かどうかを返す。
Definition: queue.h:89
int32 pid32
プロセスID
Definition: kernel.h:26
pid32 getitem(pid32 pid)
キューの任意の位置からプロセスを取り出す。
Definition: getitem.c:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getitem()

pid32 getitem ( pid32  pid)

キューの任意の位置からプロセスを取り出す。

Parameters
[in]pid取り出すプロセスID
Returns
キューにプロセスがある場合はキューの末尾にあるプロセスID、
キューが空の場合はEMPTYを返す。

Definition at line 51 of file getitem.c.

References qentry::qnext, qentry::qprev, and queuetab.

Referenced by getfirst(), getlast(), kill(), suspend(), and unsleep().

54 {
55  pid32 prev, next;
56 
57  next = queuetab[pid].qnext; /* Following node in list */
58  prev = queuetab[pid].qprev; /* Previous node in list */
59  queuetab[prev].qnext = next;
60  queuetab[next].qprev = prev;
61  return pid;
62 }
struct qentry queuetab[]
Definition: queue.c:45
qid16 qnext
次のプロセスか末尾のプロセスのインデックス。
Definition: queue.h:39
qid16 qprev
前のプロセスか先頭のプロセスのインデックス。
Definition: queue.h:41
int32 pid32
プロセスID
Definition: kernel.h:26
Here is the caller graph for this function:

◆ getlast()

pid32 getlast ( qid16  q)

キューの末尾からプロセスを取り出す。

Parameters
[in]qプロセスを取り出すためのキューID(チェックなしで有効)
Returns
キューにプロセスがある場合はキューの末尾にあるプロセスID、
キューが空の場合はEMPTYを返す。

Definition at line 32 of file getitem.c.

References EMPTY, getitem(), isempty, queuetab, and queuetail.

33 {
34  pid32 tail;
35 
36  if (isempty(q))
37  {
38  return EMPTY;
39  }
40 
41  tail = queuetail(q);
42  return getitem(queuetab[tail].qprev);
43 }
struct qentry queuetab[]
Definition: queue.c:45
#define EMPTY
次のキューインデックスもしくは前のキューインデックスがNULL値
Definition: queue.h:23
#define isempty(q)
リストが空かどうかを返す。
Definition: queue.h:89
int32 pid32
プロセスID
Definition: kernel.h:26
pid32 getitem(pid32 pid)
キューの任意の位置からプロセスを取り出す。
Definition: getitem.c:51
#define queuetail(q)
キューの末尾を返す。
Definition: queue.h:61
Here is the call graph for this function:

◆ getlocalip()

uint32 getlocalip ( void  )

Definition at line 142 of file dhcp.c.

References network::bootfile, network::bootserver, dhcp_bld_disc(), dhcp_bld_req(), dhcp_get_opt_val(), DHCP_RETRY, DHCP_SERVER_ID, network::dnsserver, dot2ip(), IP_BCAST, network::ipbcast, network::ipmask, network::ipprefix, network::iprouter, network::ipucast, network::ipvalid, kprintf(), memcpy(), NetData, ntohl, network::ntpserver, OK, SYSERR, TIMEOUT, TRUE, UDP_DHCP_CPORT, UDP_DHCP_SPORT, udp_recv(), udp_register(), udp_release(), and udp_sendto().

Referenced by dnslookup(), getutime(), rdscomm(), startup(), xsh_netinfo(), and xsh_udpeserver().

143 {
144  int32 slot; /* UDP slot to use */
145  struct dhcpmsg dmsg_snd; /* Holds outgoing DHCP messages */
146  struct dhcpmsg dmsg_rvc; /* Holds incoming DHCP messages */
147 
148  int32 i, j; /* Retry counters */
149  int32 len; /* Length of data sent */
150  int32 inlen; /* Length of data received */
151  char *optptr; /* Pointer to options area */
152  char *eop; /* Address of end of packet */
153  int32 msgtype; /* Type of DCHP message */
154  uint32 addrmask; /* Address mask for network */
155  uint32 routeraddr; /* Default router address */
156  uint32 dnsaddr; /* DNS server address */
157  uint32 ntpaddr; /* NTP server address */
158  uint32 tmp; /* Used for byte conversion */
159  uint32* tmp_server_ip; /* Temporary DHCP server pointer*/
160 
162  if (slot == SYSERR) {
163  kprintf("getlocalip: cannot register with UDP\n");
164  return SYSERR;
165  }
166 
167  len = dhcp_bld_disc(&dmsg_snd);
168  if(len == SYSERR) {
169  kprintf("getlocalip: Unable to build DHCP discover\n");
170  return SYSERR;
171  }
172 
173  for (i = 0; i < DHCP_RETRY; i++) {
175  (char *)&dmsg_snd, len);
176 
177  /* Read 3 incoming DHCP messages and check for an offer */
178  /* or wait for three timeout periods if no message */
179  /* arrives. */
180 
181  for (j=0; j<3; j++) {
182  inlen = udp_recv(slot, (char *)&dmsg_rvc,
183  sizeof(struct dhcpmsg), 2000);
184  if (inlen == TIMEOUT) {
185  continue;
186  } else if (inlen == SYSERR) {
187  return SYSERR;
188  }
189  /* Check that incoming message is a valid */
190  /* response (ID matches our request) */
191 
192  if (dmsg_rvc.dc_xid != dmsg_snd.dc_xid) {
193  continue;
194  }
195 
196  eop = (char *)&dmsg_rvc + inlen - 1;
197  optptr = (char *)&dmsg_rvc.dc_opt;
198  msgtype = addrmask = routeraddr = dnsaddr = ntpaddr = 0;
199 
200  while (optptr < eop) {
201 
202  switch (*optptr) {
203  case 53: /* Message type */
204  msgtype = 0xff & *(optptr+2);
205  break;
206 
207  case 1: /* Subnet mask */
208  memcpy((void *)&tmp, optptr+2, 4);
209  addrmask = ntohl(tmp);
210  break;
211 
212  case 3: /* Router address */
213  memcpy((void *)&tmp, optptr+2, 4);
214  routeraddr = ntohl(tmp);
215  break;
216 
217  case 6: /* DNS server address */
218  memcpy((void *)&tmp, optptr+2, 4);
219  dnsaddr = ntohl(tmp);
220  break;
221 
222  case 42: /* NTP server address */
223  memcpy((void *)&tmp, optptr+2, 4);
224  ntpaddr = ntohl(tmp);
225  break;
226 
227  }
228  optptr++; /* Move to length octet */
229  optptr += (0xff & *optptr) + 1;
230  }
231 
232  if (msgtype == 0x02) { /* Offer - send request */
233  len = dhcp_bld_req(&dmsg_snd, &dmsg_rvc, inlen);
234  if(len == SYSERR) {
235  kprintf("getlocalip: %s\n",
236  "Unable to build DHCP request");
237  return SYSERR;
238  }
240  (char *)&dmsg_snd, len);
241  continue;
242 
243  } else if (dmsg_rvc.dc_opt[2] != 0x05) {
244  /* If not an ack skip it */
245  continue;
246  }
247  if (addrmask != 0) {
248  NetData.ipmask = addrmask;
249  }
250  if (routeraddr != 0) {
251  NetData.iprouter = routeraddr;
252  }
253  if (dnsaddr != 0) {
254  NetData.dnsserver = dnsaddr;
255  }
256  if (ntpaddr != 0) {
257  NetData.ntpserver = ntpaddr;
258  }
259 
260  NetData.ipucast = ntohl(dmsg_rvc.dc_yip);
263  NetData.ipvalid = TRUE;
264  udp_release(slot);
265 
266  /* Retrieve the boot server IP */
267  if (dot2ip((char*)dmsg_rvc.sname,
268  &NetData.bootserver) != OK) {
269  /* Could not retrieve the boot server from */
270  /* the BOOTP fields, so use the DHCP server */
271  /* address */
272  tmp_server_ip = (uint32*)dhcp_get_opt_val(
273  &dmsg_rvc, len, DHCP_SERVER_ID);
274  memcpy((char *)&tmp, tmp_server_ip, 4);
275  NetData.bootserver = ntohl(tmp);
276  }
277  memcpy(NetData.bootfile, dmsg_rvc.bootfile,
278  sizeof(dmsg_rvc.bootfile));
279  return NetData.ipucast;
280  }
281  }
282 
283  kprintf("DHCP failed to get a response\n");
284  udp_release(slot);
285  return (uint32)SYSERR;
286 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
int32 udp_recv(uid32, char *, int32, uint32)
Definition: udp.c:146
uint32 ipucast
Definition: net.h:55
#define UDP_DHCP_SPORT
Definition: udp.h:7
uint32 ipmask
Definition: net.h:57
#define IP_BCAST
IPローカルブロードキャストアドレス。
Definition: ip.h:7
struct network NetData
Definition: net.c:6
char bootfile[NETBOOTFILE]
Definition: net.h:66
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
int32 dhcp_bld_req(struct dhcpmsg *dmsg, const struct dhcpmsg *dmsg_offer, uint32 dsmg_offer_size)
Definition: dhcp.c:98
#define DHCP_SERVER_ID
Definition: dhcp.h:17
#define UDP_DHCP_CPORT
Definition: udp.h:6
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
Definition: dhcp.h:33
#define ntohl(x)
Definition: prototypes.h:623
uint32 iprouter
Definition: net.h:59
#define TRUE
Boolean True(1)
Definition: kernel.h:65
#define DHCP_RETRY
Definition: dhcp.h:5
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uid32 udp_register(uint32, uint16, uint16)
Definition: udp.c:85
uint32 ipprefix
Definition: net.h:58
uint32 ipbcast
Definition: net.h:56
status udp_release(uid32)
Definition: udp.c:502
int32 dhcp_bld_disc(struct dhcpmsg *dmsg)
Definition: dhcp.c:74
uint32 bootserver
Definition: net.h:60
status udp_sendto(uid32, uint32, uint16, char *, int32)
Definition: udp.c:417
uint32 ntpserver
Definition: net.h:62
char * dhcp_get_opt_val(const struct dhcpmsg *dmsg, uint32 dmsg_size, uint8 option_key)
Definition: dhcp.c:10
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
uint32 dot2ip(char *, uint32 *)
Definition: dot2ip.c:9
uint32 dnsserver
Definition: net.h:61
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
bool8 ipvalid
Definition: net.h:63
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getmem()

char* getmem ( uint32  nbytes)

ヒープ領域を割り当て、最下位のワードアドレスを返す。

Step1. 割り込みを禁止する。
Step2. 要求されたメモリのByte数が0の場合は、割り込み状態を復元し、処理を終了する。
Step3. 要求されたメモリのByte数を8の倍数で丸める。
Step4. フリーメモリリスト先頭の次のブロックから順番に、最適なメモリブロック探索を始める。
メモリブロック探索では、以下の3通りいずれかを行う。
・現在のメモリブロックがユーザの要求サイズと一致する場合、そのメモリブロックを返す。
・ユーザの要求よりメモリブロックサイズが大きい場合、必要なメモリブロックサイズ分だけを返す。
・ユーザの要求よりメモリブロックサイズが小さい場合、次のメモリブロックを探索対象とする。
メモリブロック提供時は、フリーメモリリストを連結し直し、メモリブロック合計サイズから提供サイズ分を引く。
また、割り込み状態を許可状態に復元する。

Parameters
[in]nbytes必要なメモリサイズ(Byte)
Returns
成功時はユーザ要求サイズ分のメモリへのアドレスを返し、「要求されたメモリのByte数が0の場合」や
「メモリに空きがない場合」はSYSERRを返す。
Note
フリーメモリブロックはリンクリストで保持され、各ブロックはアドレスの昇順で管理されている。

Definition at line 25 of file getmem.c.

References disable(), memlist, memblk::mlength, memblk::mnext, NULL, restore(), roundmb, and SYSERR.

Referenced by ethinit(), mkbufpool(), ptinit(), and rdsinit().

26 {
27  intmask mask; /* Saved interrupt mask */
28  struct memblk *prev, *curr, *leftover;
29 
30  mask = disable();
31  if (nbytes == 0)
32  {
33  restore(mask);
34  return (char *)SYSERR;
35  }
36 
37  nbytes = (uint32)roundmb(nbytes); /* Use memblk multiples */
38 
39  prev = &memlist;
40  curr = memlist.mnext;
41  while (curr != NULL)
42  { /* Search free list */
43 
44  if (curr->mlength == nbytes)
45  { /* Block is exact match */
46  prev->mnext = curr->mnext;
47  memlist.mlength -= nbytes;
48  restore(mask);
49  return (char *)(curr);
50  }
51  else if (curr->mlength > nbytes)
52  { /* Split big block */
53  leftover = (struct memblk *)((uint32)curr +
54  nbytes);
55  prev->mnext = leftover;
56  leftover->mnext = curr->mnext;
57  leftover->mlength = curr->mlength - nbytes;
58  memlist.mlength -= nbytes;
59  restore(mask);
60  return (char *)(curr);
61  }
62  else
63  { /* Move to next block */
64  prev = curr;
65  curr = curr->mnext;
66  }
67  }
68  restore(mask);
69  return (char *)SYSERR;
70 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
メモリブロックを管理するための構造体。
Definition: memory.h:53
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define roundmb(x)
メモリブロックサイズ(8の倍数)にアドレスを変換するために、8の倍数で丸める。
Definition: memory.h:25
struct memblk * mnext
次のフリーメモリブロックへのポインタ
Definition: memory.h:56
struct memblk memlist
フリーメモリリストの先頭
Definition: initialize.c:27
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
uint32 mlength
memblk構造体のサイズを含むブロックサイズ
Definition: memory.h:58
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getpid()

pid32 getpid ( void  )

現在実行中のプロセスIDを返す。

Returns
現在実行中のプロセスIDを返す(グローバル変数currpidをそのまま返す)

Definition at line 11 of file getpid.c.

References currpid.

Referenced by create(), exit(), rdscontrol(), rdsread(), rdswrite(), and userret().

12 {
13  return (currpid);
14 }
pid32 currpid
現在実行中のプロセス。
Definition: initialize.c:32
Here is the caller graph for this function:

◆ getport()

uint16 getport ( void  )

Definition at line 150 of file net.c.

References netportseed.

Referenced by tftpget_mb().

151 {
152  netportseed = 1103515245 * netportseed + 12345;
153  return 50000 + ((uint16)((netportseed >> 16)) % 15535);
154 }
unsigned short uint16
符号なし16ビット整数(unsigned short)
Definition: kernel.h:17
uint32 netportseed
Definition: net.c:8
Here is the caller graph for this function:

◆ getprio()

syscall getprio ( pid32  pid)

プロセスのスケジューリング優先度を取得する。

Step1. 割り込みを禁止する。
Step2. 不正なPIDの場合は割り込み許可状態に戻し、処理を終了する。
Step3. 引数で指定されたPIDからプロセス情報を取得し、そこから優先度を取得する。
Step4. 割り込み許可状態に戻し、処理を終了する。

Parameters
[in]pid優先度を取得したいプロセスのID
Returns
処理が成功した場合は引数で指定したPIDの優先度、PIDが不正な場合はSYSERRを返す。

Definition at line 17 of file getprio.c.

References disable(), isbadpid, proctab, procent::prprio, restore(), and SYSERR.

18 {
19  intmask mask; /* Saved interrupt mask */
20  uint32 prio; /* Priority to return */
21 
22  mask = disable();
23  if (isbadpid(pid))
24  {
25  restore(mask);
26  return SYSERR;
27  }
28  prio = proctab[pid].prprio;
29  restore(mask);
30  return prio;
31 }
void restore(intmask)
#define isbadpid(x)
プロセスIDを検証する。割り込みが無効になっている事を想定している。
Definition: process.h:71
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
pri16 prprio
プロセスのスケジューリング優先度。
Definition: process.h:90
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:

◆ getstk()

char* getstk ( uint32  nbytes)

スタックメモリを割り当て、最上位のワードアドレスを返す。

Step1. 割り込みを禁止する。
Step2. 要求メモリサイズが0の場合は、割り込み状態を復元し、処理を終了する。
Step3. 要求メモリサイズを8の倍数で丸める。
Step4. フリーメモリリストの先頭から、要求メモリサイズ以上のメモリブロックを探索する。
Step5. 要求メモリサイズを満たすメモリブロックがない場合は、割り込み状態を復元し、処理を終了する。
Step6. 要求メモリサイズとメモリブロックサイズが一致する場合は、そのブロックをメモリフリーリストから除く
Step7.要求メモリサイズよりメモリブロックサイズが大きい場合は、2つに分割し、
要求サイズと一致するブロックをスタックとし、残りをメモリフリーリストに残す。
Step8. 割り込み状態を復元する。
Step9. スタック(メモリブロックの最上位アドレス)を返す。

Parameters
[in]nbytes要求メモリサイズ(byte)
Returns
成功時はスタック(メモリブロックの最上位アドレス)を返し、以下の場合はSYSERRを返す。
 ・要求メモリサイズが0の場合
 ・要求メモリサイズを確保できなかった場合

Definition at line 25 of file getstk.c.

References disable(), memlist, memblk::mlength, memblk::mnext, NULL, restore(), roundmb, and SYSERR.

Referenced by create(), and sysinit().

26 {
27  intmask mask; /* Saved interrupt mask */
28  struct memblk *prev, *curr; /* Walk through memory list */
29  struct memblk *fits, *fitsprev; /* Record block that fits */
30 
31  mask = disable();
32  if (nbytes == 0)
33  {
34  restore(mask);
35  return (char *)SYSERR;
36  }
37 
38  nbytes = (uint32)roundmb(nbytes); /* Use mblock multiples */
39 
40  prev = &memlist;
41  curr = memlist.mnext;
42  fits = NULL;
43  fitsprev = NULL; /* Just to avoid a compiler warning */
44 
45  while (curr != NULL)
46  { /* Scan entire list */
47  if (curr->mlength >= nbytes)
48  { /* Record block address */
49  fits = curr; /* when request fits */
50  fitsprev = prev;
51  }
52  prev = curr;
53  curr = curr->mnext;
54  }
55 
56  if (fits == NULL)
57  { /* No block was found */
58  restore(mask);
59  return (char *)SYSERR;
60  }
61  if (nbytes == fits->mlength)
62  { /* Block is exact match */
63  fitsprev->mnext = fits->mnext;
64  }
65  else
66  { /* Remove top section */
67  fits->mlength -= nbytes;
68  fits = (struct memblk *)((uint32)fits + fits->mlength);
69  }
70  memlist.mlength -= nbytes;
71  restore(mask);
72  return (char *)((uint32)fits + nbytes - sizeof(uint32));
73 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
メモリブロックを管理するための構造体。
Definition: memory.h:53
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define roundmb(x)
メモリブロックサイズ(8の倍数)にアドレスを変換するために、8の倍数で丸める。
Definition: memory.h:25
struct memblk * mnext
次のフリーメモリブロックへのポインタ
Definition: memory.h:56
struct memblk memlist
フリーメモリリストの先頭
Definition: initialize.c:27
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
uint32 mlength
memblk構造体のサイズを含むブロックサイズ
Definition: memory.h:58
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getticks()

uint32 getticks ( void  )

CPUリセット以降のclock tick数を取得する。

Returns
CPUリセット以降のclock tick
Note
インラインアセンブラ部分はPMCNT0〜PMCNT3レジスタを読み込んでいる。
なお、CP15(コプロセッサ15、p15)は、システム制御機能を提供する。
c9はパフォーマンスモニターカウントレジスタ、c13はサイクルカウントレジスタである。

Definition at line 14 of file getticks.c.

Referenced by net_init().

15 {
16  uint32 ret;
17  asm volatile("MRC p15, 0, %0, c9, c13, 0\t\n"
18  : "=r"(ret));
19  return ret;
20 }
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
Here is the caller graph for this function:

◆ gettime()

status gettime ( uint32 timvar)

1970年1月1日からの経過時間(秒単位)にロケーション(時差)を反映した時間を返す。

UCT(協定世界時)からの経過時刻に対してロケーション(時差)を反映する。

Parameters
[in,out]timvarXINU時刻の取得結果の保存先
Returns
XINU時間を取得できた場合はOK、UCTからの経過時間が取得できなかった場合はSYSERRを返す。

Definition at line 13 of file gettime.c.

References getutime(), OK, SYSERR, and utim2ltim.

Referenced by xsh_date().

14 {
15  uint32 now; /* Current time (UCT) */
16  int32 retval; /* Return value from call */
17 
18  /* Get current time in UCT representation (GMT) */
19 
20  retval = getutime(&now);
21  if (retval == SYSERR)
22  {
23  return SYSERR;
24  }
25 
26  /* Adjust to xinu time and store result */
27 
28  *timvar = utim2ltim(now);
29  return OK;
30 }
#define utim2ltim(x)
Definition: date.h:57
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
status getutime(uint32 *)
Definition: getutime.c:10
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getutime()

status getutime ( uint32 )

Definition at line 10 of file getutime.c.

References clktime, Date, dot2ip(), dateinfo::dt_boot, dateinfo::dt_bootvalid, fprintf(), getlocalip(), memset(), NetData, ntim2xtim, ntohl, network::ntpserver, OK, stderr, SYSERR, TIMELPORT, TIMEOUT, TIMERPORT, TIMESERVER, TIMETIMEOUT, TRUE, udp_recv(), udp_register(), udp_release(), and udp_send().

Referenced by gettime().

13 {
14  uint32 now; /* Current time in xinu format */
15  int32 retval; /* Return value from call */
16  uid32 slot; /* Slot in UDP table */
17  struct ntp { /* Format of an NTP message */
18  byte livn; /* LI:2 VN:3 and mode:3 fields */
19  byte strat; /* Stratum */
20  byte poll; /* Poll interval */
21  byte precision; /* Precision */
22  uint32 rootdelay; /* Root delay */
23  uint32 rootdisp; /* Root dispersion */
24  uint32 refid; /* Reference identifier */
25  uint32 reftimestamp[2];/* Reference timestamp */
26  uint32 oritimestamp[2];/* Originate timestamp */
27  uint32 rectimestamp[2];/* Receive timestamp */
28  uint32 trntimestamp[2];/* Transmit timestamp */
29  } ntpmsg;
30 
31  if (Date.dt_bootvalid) { /* Return time from local info */
32  *timvar = Date.dt_boot + clktime;
33  return OK;
34  }
35 
36  /* Verify that we have obtained an IP address */
37 
38  if (getlocalip() == SYSERR) {
39  return SYSERR;
40  }
41 
42  /* If the DHCP response did not contain an NTP server address */
43  /* use the default server */
44 
45  if (NetData.ntpserver == 0) {
47  return SYSERR;
48  }
49  }
50 
51  /* Contact the time server to get the date and time */
52 
54  if (slot == SYSERR) {
55  fprintf(stderr,"getutime: cannot register a udp port %d\n",
56  TIMERPORT);
57  return SYSERR;
58  }
59 
60  /* Send a request message to the NTP server */
61 
62  memset((char *)&ntpmsg, 0x00, sizeof(ntpmsg));
63  ntpmsg.livn = 0x1b; /* Client request, protocol version 3 */
64  retval = udp_send(slot, (char *)&ntpmsg, sizeof(ntpmsg));
65  if (retval == SYSERR) {
66  fprintf(stderr,"getutime: cannot send to the server\n");
67  udp_release(slot);
68  return SYSERR;
69  }
70 
71  /* Read the response from the NTP server */
72 
73  retval = udp_recv(slot, (char *) &ntpmsg, sizeof(ntpmsg),
74  TIMETIMEOUT);
75  if ( (retval == SYSERR) || (retval == TIMEOUT) ) {
76  udp_release(slot);
77  return SYSERR;
78  }
79  udp_release(slot);
80 
81  /* Extract the seconds since Jan 1900 and convert */
82 
83  now = ntim2xtim( ntohl(ntpmsg.trntimestamp[0]) );
84  Date.dt_boot = now - clktime;
86  *timvar = now;
87  return OK;
88 }
int32 udp_recv(uid32, char *, int32, uint32)
Definition: udp.c:146
status udp_send(uid32, char *, int32)
Definition: udp.c:316
unsigned char byte
符号なし8ビット値(unsigned char)
Definition: kernel.h:7
bool8 dt_bootvalid
Definition: date.h:30
struct network NetData
Definition: net.c:6
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define TIMESERVER
Definition: date.h:64
#define stderr
Definition: stdio.h:17
#define OK
処理が成功した場合
Definition: kernel.h:77
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
#define TIMELPORT
Definition: date.h:61
#define ntim2xtim(x)
Definition: date.h:15
#define ntohl(x)
Definition: prototypes.h:623
#define TRUE
Boolean True(1)
Definition: kernel.h:65
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
struct dateinfo Date
Definition: ascdate.c:6
uint32 dt_boot
Definition: date.h:27
uid32 udp_register(uint32, uint16, uint16)
Definition: udp.c:85
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
#define TIMERPORT
Definition: date.h:60
status udp_release(uid32)
Definition: udp.c:502
uint32 getlocalip(void)
Definition: dhcp.c:142
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
uint32 clktime
起動してからの現在の時間[s]
Definition: clkinit.c:5
uint32 ntpserver
Definition: net.h:62
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
#define TIMETIMEOUT
Definition: date.h:67
uint32 dot2ip(char *, uint32 *)
Definition: dot2ip.c:9
int32 uid32
UDPテーブルディスクリプタのID.
Definition: kernel.h:44
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpiocontrol()

devcall gpiocontrol ( struct dentry ,
int32  ,
int32  ,
int32   
)

Definition at line 14 of file gpiocontrol.c.

References gpio_csreg::clear_data, gpio_csreg::datain, gpio_csreg::deb_ena, gpio_csreg::deb_time, dentry::dvcsr, dentry::dvminor, gpio_csreg::falling, gpiocblk::gphookfn, GPIO_DEB_SET_TIME, GPIO_INT_ALL_LINES, GPIO_INT_ALL_TRIG, GPIO_INT_FALL_TRIG, GPIO_INT_LINE0_EN, GPIO_INT_LINE1_EN, GPIO_INT_LVL0_TRIG, GPIO_INT_LVL1_TRIG, GPIO_INT_RISE_TRIG, GPIO_INTERRUPT_CTL, GPIO_OUTPUT_DISABLE, GPIO_OUTPUT_ENABLE, GPIO_READ_PIN, GPIO_REG_INT_HANDLER, GPIO_WRITE_PIN, gpiotab, gpio_csreg::irqclear0, gpio_csreg::irqclear1, gpio_csreg::irqset0, gpio_csreg::irqset1, gpio_csreg::level0, gpio_csreg::level1, gpio_csreg::oe, OK, PIN_MASK, gpio_csreg::rising, gpio_csreg::set_data, and SYSERR.

20 {
21  struct gpio_csreg *csrptr; /* Pointer ot the CSR for GPIO */
22  struct gpiocblk *gpioptr; /* Pointer to the control block */
23 
24  csrptr = (struct gpio_csreg *)(devptr->dvcsr);
25  gpioptr = &gpiotab[devptr->dvminor];
26 
27  /* Process the request */
28 
29  switch (func)
30  {
31 
32  /* Enable output capability for pins in arg1 */
33 
34  case GPIO_OUTPUT_ENABLE:
35  csrptr->oe &= (~arg1);
36  return (devcall)OK;
37 
38  /* Disable output capability for pins in arg1 */
39 
41  csrptr->oe |= arg1;
42  return (devcall)OK;
43 
44  /* Register arg1 function pointer to be called from interrupt */
45 
47  gpioptr->gphookfn = (gpiointhook)arg1;
48  return (devcall)OK;
49 
50  /* Configure debounce capability for pins in arg2 */
51 
52  case GPIO_DEB_SET_TIME:
53  if (arg1 > 0)
54  {
55  csrptr->deb_time = (arg1 - 1) & 0xFF;
56  csrptr->deb_ena |= arg2;
57  }
58  else
59  {
60  csrptr->deb_ena &= (~arg2);
61  }
62  return (devcall)OK;
63 
64  /* Configure interrupt capability for pins in arg2 */
65 
66  case GPIO_INTERRUPT_CTL:
67 
68  /* No lines affected */
69 
70  if ((arg1 & GPIO_INT_ALL_LINES) == 0)
71  {
72  return (devcall)SYSERR;
73  }
74 
75  /* Disable lines and triggers */
76 
77  if ((arg1 & GPIO_INT_ALL_TRIG) == 0)
78  {
79 
80  /* Flags affect line 0 */
81 
82  if ((arg1 & GPIO_INT_LINE0_EN) != 0)
83  {
84  csrptr->irqclear0 = arg2;
85  }
86 
87  /* Flags affect line 1 */
88 
89  if ((arg1 & GPIO_INT_LINE1_EN) != 0)
90  {
91  csrptr->irqclear1 = arg2;
92  }
93 
94  /* Disable all triggers */
95 
96  csrptr->rising &= (~arg2);
97  csrptr->falling &= (~arg2);
98  csrptr->level0 &= (~arg2);
99  csrptr->level1 &= (~arg2);
100 
101  return (devcall)OK;
102  }
103 
104  /* Enable lines and triggers */
105 
106  if ((arg1 & GPIO_INT_LINE0_EN) != 0)
107  {
108  csrptr->irqset0 = arg2;
109  }
110  if ((arg1 & GPIO_INT_LINE1_EN) != 0)
111  {
112  csrptr->irqset1 = arg2;
113  }
114  if ((arg1 & GPIO_INT_RISE_TRIG) != 0)
115  {
116  csrptr->rising |= arg2;
117  }
118  if ((arg1 & GPIO_INT_FALL_TRIG) != 0)
119  {
120  csrptr->falling |= arg2;
121  }
122  if ((arg1 & GPIO_INT_LVL0_TRIG) != 0)
123  {
124  csrptr->level0 |= arg2;
125  }
126  if ((arg1 & GPIO_INT_LVL1_TRIG) != 0)
127  {
128  csrptr->level1 |= arg2;
129  }
130 
131  return (devcall)OK;
132 
133  /* Read input from a single pin arg1 */
134 
135  case GPIO_READ_PIN:
136  arg2 = csrptr->datain & PIN_MASK(arg1);
137  return (arg2 > 0);
138 
139  /* Write value arg2 to a single output pin arg1 */
140 
141  case GPIO_WRITE_PIN:
142  if (arg2)
143  {
144  csrptr->set_data = PIN_MASK(arg1);
145  }
146  else
147  {
148  csrptr->clear_data = PIN_MASK(arg1);
149  }
150  return (devcall)OK;
151 
152  default:
153  return (devcall)SYSERR;
154  }
155 }
#define GPIO_INT_LINE1_EN
Definition: gpio.h:106
#define GPIO_OUTPUT_ENABLE
Definition: gpio.h:96
#define GPIO_INT_LINE0_EN
Definition: gpio.h:105
#define GPIO_DEB_SET_TIME
Definition: gpio.h:99
#define GPIO_INTERRUPT_CTL
Definition: gpio.h:98
struct gpiocblk gpiotab[]
Definition: gpioinit.c:5
volatile uint32 irqset1
Definition: gpio.h:23
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define GPIO_INT_RISE_TRIG
Definition: gpio.h:107
#define OK
処理が成功した場合
Definition: kernel.h:77
#define GPIO_INT_LVL1_TRIG
Definition: gpio.h:110
volatile uint32 deb_ena
Definition: gpio.h:39
volatile uint32 oe
Definition: gpio.h:32
volatile uint32 level1
Definition: gpio.h:36
gpiointhook gphookfn
Definition: gpio.h:49
#define GPIO_OUTPUT_DISABLE
Definition: gpio.h:95
#define GPIO_INT_FALL_TRIG
Definition: gpio.h:108
#define GPIO_REG_INT_HANDLER
Definition: gpio.h:97
volatile uint32 rising
Definition: gpio.h:37
volatile uint32 set_data
Definition: gpio.h:43
volatile uint32 clear_data
Definition: gpio.h:42
Definition: gpio.h:48
void(* gpiointhook)(uint32, uint32)
Definition: gpio.h:46
volatile uint32 irqset0
Definition: gpio.h:22
#define GPIO_INT_ALL_TRIG
Definition: gpio.h:112
volatile uint32 falling
Definition: gpio.h:38
volatile uint32 irqclear0
Definition: gpio.h:24
volatile uint32 datain
Definition: gpio.h:33
#define GPIO_READ_PIN
Definition: gpio.h:100
#define GPIO_WRITE_PIN
Definition: gpio.h:101
#define GPIO_INT_ALL_LINES
Definition: gpio.h:111
volatile uint32 deb_time
Definition: gpio.h:40
volatile uint32 irqclear1
Definition: gpio.h:25
int32 devcall
デバイスコール関数 返り値の型
Definition: kernel.h:49
#define PIN_MASK(pin)
Definition: gpio.h:55
#define GPIO_INT_LVL0_TRIG
Definition: gpio.h:109
volatile uint32 level0
Definition: gpio.h:35

◆ gpiohandler()

void gpiohandler ( uint32  )

Definition at line 9 of file gpiohandler.c.

References gpiocblk::gphookfn, GPIO0_BASE, GPIO0_INT_A, GPIO0_INT_B, GPIO1_BASE, GPIO1_INT_A, GPIO1_INT_B, GPIO2_BASE, GPIO2_INT_A, GPIO2_INT_B, GPIO3_BASE, GPIO3_INT_A, GPIO3_INT_B, gpiotab, gpio_csreg::irqstatus0, gpio_csreg::irqstatus1, and NULL.

12 {
13  struct gpio_csreg *csrptr; /* GPIO CSR pointer */
14  gpiointhook gphookfn; /* The inerrupt function */
15 
16  /* Clear all interrupts */
17 
18  if(xnum == GPIO0_INT_A) {
19  csrptr = (struct gpio_csreg *)(GPIO0_BASE);
20  gphookfn = gpiotab[0].gphookfn;
21  if(gphookfn != NULL)
22  gphookfn(xnum, csrptr->irqstatus0);
23  csrptr->irqstatus0 = 0xFFFFFFFF;
24  return;
25  }
26  if(xnum == GPIO0_INT_B) {
27  csrptr = (struct gpio_csreg *)(GPIO0_BASE);
28  gphookfn = gpiotab[0].gphookfn;
29  if(gphookfn != NULL)
30  gphookfn(xnum, csrptr->irqstatus1);
31  csrptr->irqstatus1 = 0xFFFFFFFF;
32  return;
33  }
34 
35  if(xnum == GPIO1_INT_A) {
36  csrptr = (struct gpio_csreg *)(GPIO1_BASE);
37  gphookfn = gpiotab[1].gphookfn;
38  if(gphookfn != NULL)
39  gphookfn(xnum, csrptr->irqstatus0);
40  csrptr->irqstatus0 = 0xFFFFFFFF;
41  return;
42  }
43  if(xnum == GPIO1_INT_B) {
44  csrptr = (struct gpio_csreg *)(GPIO1_BASE);
45  gphookfn = gpiotab[1].gphookfn;
46  if(gphookfn != NULL)
47  gphookfn(xnum, csrptr->irqstatus1);
48  csrptr->irqstatus1 = 0xFFFFFFFF;
49  return;
50  }
51 
52  if(xnum == GPIO2_INT_A) {
53  csrptr = (struct gpio_csreg *)(GPIO2_BASE);
54  gphookfn = gpiotab[2].gphookfn;
55  if(gphookfn != NULL)
56  gphookfn(xnum, csrptr->irqstatus0);
57  csrptr->irqstatus0 = 0xFFFFFFFF;
58  return;
59  }
60  if(xnum == GPIO2_INT_B) {
61  csrptr = (struct gpio_csreg *)(GPIO2_BASE);
62  gphookfn = gpiotab[2].gphookfn;
63  if(gphookfn != NULL)
64  gphookfn(xnum, csrptr->irqstatus1);
65  csrptr->irqstatus1 = 0xFFFFFFFF;
66  return;
67  }
68 
69  if(xnum == GPIO3_INT_A) {
70  csrptr = (struct gpio_csreg *)(GPIO3_BASE);
71  gphookfn = gpiotab[3].gphookfn;
72  if(gphookfn != NULL)
73  gphookfn(xnum, csrptr->irqstatus0);
74  csrptr->irqstatus0 = 0xFFFFFFFF;
75  return;
76  }
77  if(xnum == GPIO3_INT_B) {
78  csrptr = (struct gpio_csreg *)(GPIO3_BASE);
79  gphookfn = gpiotab[3].gphookfn;
80  if(gphookfn != NULL)
81  gphookfn(xnum, csrptr->irqstatus1);
82  csrptr->irqstatus1 = 0xFFFFFFFF;
83  return;
84  }
85 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
#define GPIO0_BASE
Definition: gpio.h:121
struct gpiocblk gpiotab[]
Definition: gpioinit.c:5
#define GPIO1_INT_B
Definition: gpio.h:131
#define GPIO3_INT_B
Definition: gpio.h:135
#define GPIO0_INT_A
Definition: gpio.h:128
#define GPIO3_BASE
Definition: gpio.h:124
gpiointhook gphookfn
Definition: gpio.h:49
#define GPIO2_INT_B
Definition: gpio.h:133
#define GPIO1_INT_A
Definition: gpio.h:130
#define GPIO2_BASE
Definition: gpio.h:123
void(* gpiointhook)(uint32, uint32)
Definition: gpio.h:46
#define GPIO0_INT_B
Definition: gpio.h:129
#define GPIO1_BASE
Definition: gpio.h:122
#define GPIO3_INT_A
Definition: gpio.h:134
volatile uint32 irqstatus1
Definition: gpio.h:21
#define GPIO2_INT_A
Definition: gpio.h:132
volatile uint32 irqstatus0
Definition: gpio.h:20

◆ gpioinit()

devcall gpioinit ( struct dentry )

Definition at line 11 of file gpioinit.c.

References gpio_csreg::clear_data, gpio_csreg::deb_ena, dentry::dvcsr, dentry::dvintr, dentry::dvirq, dentry::dvminor, gpio_csreg::falling, gpiocblk::gphookfn, GPIO1_BASE, GPIO2_BASE, GPIO3_BASE, gpiotab, gpio_csreg::irqclear0, gpio_csreg::irqclear1, gpio_csreg::irqstatus0, gpio_csreg::irqstatus1, gpio_csreg::irqwaken0, gpio_csreg::irqwaken1, gpio_csreg::level0, gpio_csreg::level1, NULL, gpio_csreg::oe, OK, PRCM_FCLK_BIT, PRCM_FCLK_GPIO1, PRCM_FCLK_GPIO2, PRCM_FCLK_GPIO3, gpio_csreg::rising, set_evec(), and gpio_csreg::sysconfig.

14 {
15  struct gpio_csreg *csrptr; /* Pointer ot GPIO CSRs */
16  struct gpiocblk *gpioptr; /* Pointer ot GPIO Control block*/
17  uint32 *fclkreg; /* FCLK Register for debounce */
18 
19  csrptr = (struct gpio_csreg *)(devptr->dvcsr);
20  gpioptr = &gpiotab[devptr->dvminor];
21 
22  /* Get the FCLK Register for the corresponding GPIO module */
23 
24  if(csrptr == GPIO1_BASE) {
25  fclkreg = PRCM_FCLK_GPIO1;
26  } else if(csrptr == GPIO2_BASE) {
27  fclkreg = PRCM_FCLK_GPIO2;
28  } else if(csrptr == GPIO3_BASE) {
29  fclkreg = PRCM_FCLK_GPIO3;
30  } else {
31  /* GPIO0 FCLK is ON by default */
32  fclkreg = NULL;
33  }
34 
35  /* Initialize register values */
36 
37  csrptr->sysconfig = 0x0;
38 
39  /* Disable output for all pins */
40 
41  csrptr->oe = 0xFFFFFFFF;
42 
43  /* Clear all pending interrupts */
44 
45  csrptr->irqstatus0 = 0xFFFFFFFF;
46  csrptr->irqstatus1 = 0xFFFFFFFF;
47 
48  /* Disable all interrupts */
49 
50  csrptr->irqclear0 = 0xFFFFFFFF;
51  csrptr->irqclear1 = 0xFFFFFFFF;
52 
53  /* Clear all pins */
54 
55  csrptr->clear_data = 0xFFFFFFFF;
56 
57  /* Clear wakeup settings */
58 
59  csrptr->irqwaken0 = 0x0;
60  csrptr->irqwaken1 = 0x0;
61 
62  /* Clear all interrupt trigger settings */
63 
64  csrptr->rising = 0x0;
65  csrptr->falling = 0x0;
66  csrptr->level0 = 0x0;
67  csrptr->level1 = 0x0;
68 
69  /* Disable debouncing */
70 
71  csrptr->deb_ena = 0x0;
72 
73  /* Setup debouncing clock */
74 
75  if(fclkreg != NULL) {
76  *fclkreg |= PRCM_FCLK_BIT;
77  }
78 
79  /* Interrupt A */
80 
81  set_evec( devptr->dvirq, (uint32)devptr->dvintr );
82 
83  /* Interrupt B is the next interrupt line */
84 
85  set_evec( (devptr->dvirq)+1, (uint32)devptr->dvintr );
86 
87  gpioptr->gphookfn = NULL;
88 
89  return OK;
90 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
volatile uint32 sysconfig
Definition: gpio.h:15
volatile uint32 irqwaken0
Definition: gpio.h:26
#define OK
処理が成功した場合
Definition: kernel.h:77
#define GPIO3_BASE
Definition: gpio.h:124
volatile uint32 deb_ena
Definition: gpio.h:39
volatile uint32 irqwaken1
Definition: gpio.h:27
volatile uint32 oe
Definition: gpio.h:32
#define PRCM_FCLK_GPIO1
Definition: gpio.h:139
volatile uint32 level1
Definition: gpio.h:36
gpiointhook gphookfn
Definition: gpio.h:49
#define PRCM_FCLK_GPIO2
Definition: gpio.h:140
int32 set_evec(uint32, uint32)
Definition: evec.c:37
#define PRCM_FCLK_GPIO3
Definition: gpio.h:141
#define GPIO2_BASE
Definition: gpio.h:123
volatile uint32 rising
Definition: gpio.h:37
volatile uint32 clear_data
Definition: gpio.h:42
Definition: gpio.h:48
volatile uint32 falling
Definition: gpio.h:38
volatile uint32 irqclear0
Definition: gpio.h:24
#define GPIO1_BASE
Definition: gpio.h:122
struct gpiocblk gpiotab[NGPIO]
Definition: gpioinit.c:5
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
volatile uint32 irqclear1
Definition: gpio.h:25
#define PRCM_FCLK_BIT
Definition: gpio.h:142
volatile uint32 level0
Definition: gpio.h:35
volatile uint32 irqstatus1
Definition: gpio.h:21
volatile uint32 irqstatus0
Definition: gpio.h:20
Here is the call graph for this function:

◆ gpioread()

devcall gpioread ( struct dentry ,
char *  ,
int32   
)

Definition at line 9 of file gpioread.c.

References gpio_csreg::datain, dentry::dvcsr, and OK.

14 {
15  struct gpio_csreg *csrptr; /* Pointer to GPIO CSRs */
16 
17  /* Obtain the address of the CSR from the device switch table */
18 
19  csrptr = (struct gpio_csreg *)(devptr->dvcsr);
20 
21  /* Access the GPIO pins, use the mask to select a subset, and */
22  /* store the result in the specified buffer */
23 
24  *((uint32 *)value) = csrptr->datain & pinmask;
25 
26  return OK;
27 }
#define OK
処理が成功した場合
Definition: kernel.h:77
volatile uint32 datain
Definition: gpio.h:33
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15

◆ gpioselect()

devcall gpioselect ( uint32  ,
uint32  ,
uint32   
)

Definition at line 8 of file gpioselect.c.

References OK, and PINMUXBASE.

13 {
14  volatile uint32* confreg; /* Pin configuration register */
15 
16  /* Pick up the pin configuration register address */
17 
18  confreg = &(((uint32*)PINMUXBASE)[pinreg]);
19 
20  /* Apply the specified settings to the pin */
21 
22  *confreg = pinmode|pinsettings;
23 
24  return OK;
25 }
#define OK
処理が成功した場合
Definition: kernel.h:77
#define PINMUXBASE
Definition: gpioselect.h:5
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15

◆ gpiowrite()

devcall gpiowrite ( struct dentry ,
char *  ,
int32   
)

Definition at line 9 of file gpiowrite.c.

References gpio_csreg::clear_data, dentry::dvcsr, OK, and gpio_csreg::set_data.

14 {
15  struct gpio_csreg *csrptr; /* Pointer to GPIO CSRs */
16  uint32 val; /* Value to be written */
17 
18  csrptr = (struct gpio_csreg *)(devptr->dvcsr);
19  val = * (uint32 *)value;
20 
21  /* Set bits that should become one */
22 
23  csrptr->set_data = pinmask & val;
24 
25  /* Clear bits that should become zero */
26 
27  csrptr->clear_data = pinmask & ~val;
28 
29  return OK;
30 }
#define OK
処理が成功した場合
Definition: kernel.h:77
volatile uint32 set_data
Definition: gpio.h:43
volatile uint32 clear_data
Definition: gpio.h:42
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15

◆ halt()

void halt ( void  )

システムを停止させる(intr.Sに定義がある)

Referenced by xdone().

Here is the caller graph for this function:

◆ icmp_cksum()

uint16 icmp_cksum ( char *  ,
int32   
)

Definition at line 359 of file icmp.c.

References ntohs.

Referenced by ip_in(), ip_out(), and pdumph().

363 {
364  int32 scount; /* Number of 16-bit values buf */
365  uint32 cksum; /* Checksum being computed */
366  uint16 *sptr; /* Walks along buffer */
367  uint16 word; /* One 16-bit word */
368 
369  /* Walk along buffer and sum all 16-bit values */
370 
371  scount = buflen >> 1; /* Divide by 2 and round down */
372  sptr = (uint16 *)buf;
373  cksum = 0;
374  for (; scount > 0; scount--) {
375  word = (uint32) *sptr++;
376  cksum += ntohs(word);
377  }
378 
379  /* If buffer lenght is odd, add last byte */
380 
381  if ( (buflen & 0x01) !=0 ) {
382  cksum += 0xFFFF & ((uint32) (*((byte *) sptr) << 8));
383  }
384  cksum += (cksum >> 16);
385  cksum = 0xffff & ~cksum;
386  return (uint16) (0xffff & cksum);
387 }
unsigned char byte
符号なし8ビット値(unsigned char)
Definition: kernel.h:7
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
unsigned short uint16
符号なし16ビット整数(unsigned short)
Definition: kernel.h:17
#define ntohs(x)
Definition: prototypes.h:622
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
Here is the caller graph for this function:

◆ icmp_hton()

void icmp_hton ( struct netpacket )

Definition at line 394 of file icmp.c.

References htons, netpacket::net_iccksum, netpacket::net_icident, and netpacket::net_icseq.

Referenced by ip_out().

397 {
398  pktptr->net_iccksum = htons(pktptr->net_iccksum);
399  pktptr->net_icident = htons(pktptr->net_icident);
400  pktptr->net_icseq = htons(pktptr->net_icseq);
401 }
#define htons(x)
Definition: prototypes.h:619
Here is the caller graph for this function:

◆ icmp_in()

void icmp_in ( struct netpacket )

Definition at line 26 of file icmp.c.

References disable(), freebuf(), icmpentry::iccount, ICMP_ECHOREPLY, ICMP_ECHOREQST, ICMP_FREE, ICMP_HDR_LEN, icmp_mkpkt(), ICMP_QSIZ, ICMP_RECV, ICMP_SLOTS, ICMP_USED, icmptab, icmpentry::icpid, icmpentry::icqueue, icmpentry::icremip, icmpentry::icstate, icmpentry::ictail, ip_enqueue(), IP_HDR_LEN, netpacket::net_icdata, netpacket::net_icident, netpacket::net_icseq, netpacket::net_ictype, netpacket::net_iplen, netpacket::net_ipsrc, OK, restore(), send(), and SYSERR.

Referenced by ip_local().

29 {
30  intmask mask; /* Saved interrupt mask */
31  int32 slot; /* Slot in ICMP table */
32  struct icmpentry *icmptr; /* Pointer to icmptab entry */
33  struct netpacket *replypkt; /* Pointer to reply packet */
34 
35  mask = disable();
36 
37  /* Discard all ICMP messages except ping */
38 
39  if ( (pkt->net_ictype != ICMP_ECHOREPLY) &&
40  (pkt->net_ictype != ICMP_ECHOREQST) ) {
41  freebuf((char *)pkt);
42  restore(mask);
43  return;
44  }
45 
46  /* Handle Echo Request message */
47 
48  if (pkt->net_ictype == ICMP_ECHOREQST) {
49 
50  /* Send echo reply message */
51 
52  replypkt = icmp_mkpkt(pkt->net_ipsrc,ICMP_ECHOREPLY,
53  pkt->net_icident, pkt->net_icseq,
54  (char *) &pkt->net_icdata,
55  pkt->net_iplen-IP_HDR_LEN-ICMP_HDR_LEN);
56  if ((int32)replypkt != SYSERR) {
57  ip_enqueue(replypkt);
58  }
59  freebuf((char *)pkt);
60  restore(mask);
61  return;
62  }
63 
64  /* Handle Echo Reply message: verify that ID is valid */
65 
66  slot = pkt->net_icident;
67  if ( (slot < 0) || (slot >= ICMP_SLOTS) ) {
68  freebuf((char *)pkt);
69  restore(mask);
70  return;
71  }
72 
73  /* Verify that slot in table is in use and IP address */
74  /* in incomming packet matches IP address in table */
75 
76  icmptr = &icmptab[slot];
77  if ( (icmptr->icstate == ICMP_FREE) ||
78  (pkt->net_ipsrc != icmptr->icremip) ) {
79  freebuf((char *)pkt); /* discard packet */
80  restore(mask);
81  return;
82  }
83 
84  /* Add packet to queue */
85 
86  icmptr->iccount++;
87  icmptr->icqueue[icmptr->ictail++] = pkt;
88  if (icmptr->ictail >= ICMP_QSIZ) {
89  icmptr->ictail = 0;
90  }
91  if (icmptr->icstate == ICMP_RECV) {
92  icmptr->icstate = ICMP_USED;
93  send (icmptr->icpid, OK);
94  }
95  restore(mask);
96  return;
97 }
#define ICMP_RECV
Definition: icmp.h:10
struct netpacket * icmp_mkpkt(uint32 remip, uint16 type, uint16 ident, uint16 seq, char *buf, int32 len)
Definition: icmp.c:259
void restore(intmask)
struct icmpentry icmptab[ICMP_SLOTS]
Definition: icmp.c:6
#define ICMP_ECHOREQST
Definition: icmp.h:17
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct netpacket * icqueue[ICMP_QSIZ]
Definition: icmp.h:28
uint32 icremip
Definition: icmp.h:23
#define IP_HDR_LEN
IPヘッダのバイト数。
Definition: ip.h:20
#define ICMP_SLOTS
Definition: icmp.h:3
#define ICMP_ECHOREPLY
Definition: icmp.h:16
#define OK
処理が成功した場合
Definition: kernel.h:77
syscall send(pid32, umsg32)
プロセスにメッセージを送信し、受信側が待機状態の場合はREADY状態にする。
Definition: send.c:21
#define ICMP_QSIZ
Definition: icmp.h:4
Definition: icmp.h:21
int32 ictail
Definition: icmp.h:25
int32 icstate
Definition: icmp.h:22
#define ICMP_FREE
Definition: icmp.h:8
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define ICMP_USED
Definition: icmp.h:9
int32 iccount
Definition: icmp.h:26
Definition: net.h:16
pid32 icpid
Definition: icmp.h:27
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
#define ICMP_HDR_LEN
Definition: icmp.h:12
status ip_enqueue(struct netpacket *)
Definition: ip.c:439
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ icmp_init()

void icmp_init ( void  )

Definition at line 12 of file icmp.c.

References ICMP_FREE, ICMP_SLOTS, icmptab, and icmpentry::icstate.

Referenced by net_init().

12  {
13 
14  int32 i; /* table index */
15 
16  for(i=0; i<ICMP_SLOTS; i++) {
18  }
19  return;
20 }
struct icmpentry icmptab[ICMP_SLOTS]
Definition: icmp.c:6
#define ICMP_SLOTS
Definition: icmp.h:3
int32 icstate
Definition: icmp.h:22
#define ICMP_FREE
Definition: icmp.h:8
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
Here is the caller graph for this function:

◆ icmp_mkpkt()

struct netpacket* icmp_mkpkt ( uint32  ,
uint16  ,
uint16  ,
uint16  ,
char *  ,
int32   
)

Definition at line 259 of file icmp.c.

References ETH_ADDR_LEN, network::ethucast, getbuf(), ICMP_HDR_LEN, IP_HDR_LEN, IP_ICMP, network::ipucast, memcpy(), netpacket::net_ethsrc, netpacket::net_ethtype, netpacket::net_iccksum, netpacket::net_iccode, netpacket::net_icdata, netpacket::net_icident, netpacket::net_icseq, netpacket::net_ictype, netpacket::net_ipcksum, netpacket::net_ipdst, netpacket::net_ipfrag, netpacket::net_ipid, netpacket::net_iplen, netpacket::net_ipproto, netpacket::net_ipsrc, netpacket::net_iptos, netpacket::net_ipttl, netpacket::net_ipvh, netbufpool, NetData, panic(), and SYSERR.

Referenced by icmp_in(), and icmp_send().

267 {
268  struct netpacket *pkt; /* pointer to packet buffer */
269  static uint32 ipident=32767; /* IP ident field */
270 
271  /* Allocate packet */
272 
273  pkt = (struct netpacket *)getbuf(netbufpool);
274 
275  if ((int32)pkt == SYSERR) {
276  panic("icmp_mkpkt: cannot get a network buffer\n");
277  }
278 
279  /* Create icmp packet in pkt */
280 
282  pkt->net_ethtype = 0x800; /* Type is IP */
283  pkt->net_ipvh = 0x45; /* IP version and hdr length */
284  pkt->net_iptos = 0x00; /* Type of service */
285  pkt->net_iplen= IP_HDR_LEN+ICMP_HDR_LEN+len;/* datagram length */
286  pkt->net_ipid = ipident++; /* Datagram gets next IDENT */
287  pkt->net_ipfrag = 0x0000; /* IP flags & fragment offset */
288  pkt->net_ipttl = 0xff; /* IP time-to-live */
289  pkt->net_ipproto = IP_ICMP; /* Datagram carries icmp */
290  pkt->net_ipcksum = 0x0000; /* Initial checksum */
291  pkt->net_ipsrc = NetData.ipucast; /* IP source address */
292  pkt->net_ipdst = remip; /* IP destination address */
293 
294 
295  pkt->net_ictype = type; /* ICMP type */
296  pkt->net_iccode = 0; /* Code is zero for ping */
297  pkt->net_iccksum = 0x0000; /* Temporarily zero the cksum */
298  pkt->net_icident = ident; /* ICMP identification */
299  pkt->net_icseq = seq; /* ICMP sequence number */
300  memcpy(pkt->net_icdata, buf, len);
301 
302  /* Return packet to caller */
303 
304  return pkt;
305 }
byte net_ictype
Definition: net.h:39
uint32 ipucast
Definition: net.h:55
uint16 net_ethtype
Definition: net.h:19
uint16 net_iccksum
Definition: net.h:41
struct network NetData
Definition: net.c:6
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
uint16 net_ipid
Definition: net.h:23
uint16 net_ipfrag
Definition: net.h:24
#define IP_HDR_LEN
IPヘッダのバイト数。
Definition: ip.h:20
byte net_ethsrc[ETH_ADDR_LEN]
Definition: net.h:18
uint16 net_iplen
Definition: net.h:22
byte net_iccode
Definition: net.h:40
byte net_icdata[1500-28]
Definition: net.h:44
#define IP_ICMP
IP向けのICMPプロトコルタイプ
Definition: ip.h:14
byte ethucast[ETH_ADDR_LEN]
Definition: net.h:64
uint16 net_icseq
Definition: net.h:43
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint16 net_ipcksum
Definition: net.h:27
bpid32 netbufpool
Definition: net.c:7
char * getbuf(bpid32)
事前に確保されたバッファプールからバッファを取得する。
Definition: getbuf.c:19
byte net_iptos
Definition: net.h:21
Definition: net.h:16
byte net_ipvh
Definition: net.h:20
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
uint32 net_ipsrc
Definition: net.h:28
uint32 net_ipdst
Definition: net.h:29
#define ICMP_HDR_LEN
Definition: icmp.h:12
uint16 net_icident
Definition: net.h:42
#define ETH_ADDR_LEN
Definition: ether.h:10
byte net_ipproto
Definition: net.h:26
byte net_ipttl
Definition: net.h:25
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
Here is the call graph for this function:
Here is the caller graph for this function:

◆ icmp_ntoh()

void icmp_ntoh ( struct netpacket )

Definition at line 408 of file icmp.c.

References netpacket::net_iccksum, netpacket::net_icident, netpacket::net_icseq, and ntohs.

Referenced by ip_in().

411 {
412  pktptr->net_iccksum = ntohs(pktptr->net_iccksum);
413  pktptr->net_icident = ntohs(pktptr->net_icident);
414  pktptr->net_icseq = ntohs(pktptr->net_icseq);
415 }
#define ntohs(x)
Definition: prototypes.h:622
Here is the caller graph for this function:

◆ icmp_recv()

int32 icmp_recv ( int32  ,
char *  ,
int32  ,
uint32   
)

Definition at line 150 of file icmp.c.

References currpid, disable(), freebuf(), icmpentry::iccount, icmpentry::ichead, ICMP_HDR_LEN, ICMP_RECV, ICMP_SLOTS, ICMP_USED, icmptab, icmpentry::icpid, icmpentry::icqueue, icmpentry::icstate, IP_HDR_LEN, netpacket::net_icdata, netpacket::net_iplen, OK, recvclr(), recvtime(), restore(), SYSERR, and TIMEOUT.

Referenced by xsh_ping().

156 {
157  intmask mask; /* Saved interrupt mask */
158  struct icmpentry *icmptr; /* Pointer to icmptab entry */
159  umsg32 msg; /* Message from recvtime() */
160  struct netpacket *pkt; /* Pointer to packet being read */
161  int32 datalen; /* Length of ICMP data area */
162  char *icdataptr; /* Pointer to icmp data */
163  int32 i; /* Counter for data copy */
164 
165  /* Verify that the ID is valid */
166 
167  if ( (icmpid < 0) || (icmpid >= ICMP_SLOTS) ) {
168  return SYSERR;
169  }
170 
171  /* Insure only one process touches the table at a time */
172 
173  mask = disable();
174 
175  /* Verify that the ID has been registered and is idle */
176 
177  icmptr = &icmptab[icmpid];
178  if (icmptr->icstate != ICMP_USED) {
179  restore(mask);
180  return SYSERR;
181  }
182 
183  if (icmptr->iccount == 0) { /* No packet is waiting */
184  icmptr->icstate = ICMP_RECV;
185  icmptr->icpid = currpid;
186  msg = recvclr();
187  msg = recvtime(timeout); /* Wait for a reply */
188  icmptr->icstate = ICMP_USED;
189  if (msg == TIMEOUT) {
190  restore(mask);
191  return TIMEOUT;
192  } else if (msg != OK) {
193  restore(mask);
194  return SYSERR;
195  }
196  }
197 
198  /* Packet has arrived -- dequeue it */
199 
200  pkt = icmptr->icqueue[icmptr->ichead++];
201  if (icmptr->ichead >= ICMP_SLOTS) {
202  icmptr->ichead = 0;
203  }
204  icmptr->iccount--;
205 
206  /* Copy data from ICMP message into caller's buffer */
207 
208  datalen = pkt->net_iplen - IP_HDR_LEN - ICMP_HDR_LEN;
209  icdataptr = (char *) &pkt->net_icdata;
210  for (i=0; i<datalen; i++) {
211  if (i >= len) {
212  break;
213  }
214  *buff++ = *icdataptr++;
215  }
216  freebuf((char *)pkt);
217  restore(mask);
218  return i;
219 }
#define ICMP_RECV
Definition: icmp.h:10
pid32 currpid
現在実行中のプロセス。
Definition: initialize.c:32
void restore(intmask)
struct icmpentry icmptab[ICMP_SLOTS]
Definition: icmp.c:6
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct netpacket * icqueue[ICMP_QSIZ]
Definition: icmp.h:28
#define IP_HDR_LEN
IPヘッダのバイト数。
Definition: ip.h:20
#define ICMP_SLOTS
Definition: icmp.h:3
#define OK
処理が成功した場合
Definition: kernel.h:77
uint16 net_iplen
Definition: net.h:22
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
byte net_icdata[1500-28]
Definition: net.h:44
uint32 umsg32
プロセス間で渡されるメッセージ
Definition: kernel.h:32
Definition: icmp.h:21
int32 icstate
Definition: icmp.h:22
umsg32 recvclr(void)
受信メッセージをクリアし、待機している場合はメッセージを返す。
Definition: recvclr.c:14
int32 ichead
Definition: icmp.h:24
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define ICMP_USED
Definition: icmp.h:9
int32 iccount
Definition: icmp.h:26
Definition: net.h:16
pid32 icpid
Definition: icmp.h:27
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
#define ICMP_HDR_LEN
Definition: icmp.h:12
umsg32 recvtime(int32)
Definition: recvtime.c:17
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ icmp_register()

int32 icmp_register ( uint32  )

Definition at line 103 of file icmp.c.

References disable(), icmpentry::iccount, icmpentry::ichead, ICMP_FREE, ICMP_SLOTS, ICMP_USED, icmptab, icmpentry::icpid, icmpentry::icremip, icmpentry::icstate, icmpentry::ictail, restore(), and SYSERR.

Referenced by xsh_ping().

106 {
107  intmask mask; /* Saved interrupt mask */
108  int32 i; /* Index into icmptab */
109  int32 freeslot; /* Index of slot to use */
110  struct icmpentry *icmptr; /* Pointer to icmptab entry */
111 
112  mask = disable();
113 
114  /* Find a free slot in the table */
115 
116  freeslot = -1;
117  for (i=0; i<ICMP_SLOTS; i++) {
118  icmptr = &icmptab[i];
119  if (icmptr->icstate == ICMP_FREE) {
120  if (freeslot == -1) {
121  freeslot = i;
122  }
123  } else if (icmptr->icremip == remip) {
124  restore(mask);
125  return SYSERR; /* Already registered */
126  }
127  }
128  if (freeslot == -1) { /* No free entries in table */
129 
130  restore(mask);
131  return SYSERR;
132  }
133 
134  /* Fill in table entry */
135 
136  icmptr = &icmptab[freeslot];
137  icmptr->icstate = ICMP_USED;
138  icmptr->icremip = remip;
139  icmptr->iccount = 0;
140  icmptr->ichead = icmptr->ictail = 0;
141  icmptr->icpid = -1;
142  restore(mask);
143  return freeslot;
144 }
void restore(intmask)
struct icmpentry icmptab[ICMP_SLOTS]
Definition: icmp.c:6
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
uint32 icremip
Definition: icmp.h:23
#define ICMP_SLOTS
Definition: icmp.h:3
Definition: icmp.h:21
int32 ictail
Definition: icmp.h:25
int32 icstate
Definition: icmp.h:22
#define ICMP_FREE
Definition: icmp.h:8
int32 ichead
Definition: icmp.h:24
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define ICMP_USED
Definition: icmp.h:9
int32 iccount
Definition: icmp.h:26
pid32 icpid
Definition: icmp.h:27
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ icmp_release()

status icmp_release ( int32  )

Definition at line 312 of file icmp.c.

References DEFER_START, DEFER_STOP, disable(), freebuf(), icmpentry::iccount, icmpentry::ichead, ICMP_FREE, ICMP_SLOTS, ICMP_USED, icmptab, icmpentry::icqueue, icmpentry::icstate, OK, resched_cntl(), restore(), and SYSERR.

Referenced by xsh_ping().

315 {
316  intmask mask; /* Saved interrupt mask */
317  struct icmpentry *icmptr; /* Pointer to icmptab entry */
318  struct netpacket *pkt; /* Pointer to packet */
319 
320  mask = disable();
321 
322  /* Check arg and insure entry in table is in use */
323 
324  if ( (icmpid < 0) || (icmpid >= ICMP_SLOTS) ) {
325  restore(mask);
326  return SYSERR;
327  }
328  icmptr = &icmptab[icmpid];
329  if (icmptr->icstate != ICMP_USED) {
330  restore(mask);
331  return SYSERR;
332  }
333 
334  /* Remove each packet from the queue and free the buffer */
335 
337  while (icmptr->iccount > 0) {
338  pkt = icmptr->icqueue[icmptr->ichead++];
339  if (icmptr->ichead >= ICMP_SLOTS) {
340  icmptr->ichead = 0;
341 
342  }
343  freebuf((char *)pkt);
344  icmptr->iccount--;
345  }
346 
347  /* Mark the entry free */
348 
349  icmptr->icstate = ICMP_FREE;
351  restore(mask);
352  return OK;
353 }
void restore(intmask)
struct icmpentry icmptab[ICMP_SLOTS]
Definition: icmp.c:6
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct netpacket * icqueue[ICMP_QSIZ]
Definition: icmp.h:28
#define ICMP_SLOTS
Definition: icmp.h:3
#define OK
処理が成功した場合
Definition: kernel.h:77
Definition: icmp.h:21
status resched_cntl(int32)
再スケジューリングを延期させるか、もしくは許可させるかを制御する。
Definition: resched.c:81
int32 icstate
Definition: icmp.h:22
#define ICMP_FREE
Definition: icmp.h:8
#define DEFER_STOP
遅延リスケジューリングの停止
Definition: resched.h:10
int32 ichead
Definition: icmp.h:24
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
#define DEFER_START
遅延リスケジューリングの開始
Definition: resched.h:8
#define ICMP_USED
Definition: icmp.h:9
int32 iccount
Definition: icmp.h:26
Definition: net.h:16
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ icmp_send()

status icmp_send ( uint32  ,
uint16  ,
uint16  ,
uint16  ,
char *  ,
int32   
)

Definition at line 225 of file icmp.c.

References disable(), icmp_mkpkt(), ip_send(), restore(), and SYSERR.

Referenced by xsh_ping().

233 {
234  intmask mask; /* Saved interrupt mask */
235  struct netpacket *pkt; /* Packet returned by icmp_mkpkt*/
236  int32 retval; /* Value returned by ip_send */
237 
238  mask = disable();
239 
240  /* Form a packet to send */
241 
242  pkt = icmp_mkpkt(remip, type, ident, seq, buf, len);
243  if ((int32)pkt == SYSERR) {
244  return SYSERR;
245  }
246 
247  /* Send the packet */
248 
249  retval = ip_send(pkt);
250  restore(mask);
251  return retval;
252 }
struct netpacket * icmp_mkpkt(uint32 remip, uint16 type, uint16 ident, uint16 seq, char *buf, int32 len)
Definition: icmp.c:259
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
Definition: net.h:16
status ip_send(struct netpacket *)
Definition: ip.c:103
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inb()

int32 inb ( int32  )

◆ init()

syscall init ( did32  descrp)

デバイスとデバイスドライバを初期化する。

Step1. 割り込みを禁止する。
Step2. デバイスディスクリプタが不正値の場合は、割り込み状態を復元し、処理を終了する。
Step3. デバイス固有の初期化処理を実施する。
Step4. 割り込み許可状態に復元する。

Parameters
[in]descrpデバイスディスクリプタ
Returns
成功時はデバイスに応じた返り値、デバイスディスクリプタが不正値の場合はSYSERRを返す。

Definition at line 17 of file init.c.

References devtab, disable(), dentry::dvinit, isbaddev, restore(), and SYSERR.

Referenced by sysinit().

18 {
19  intmask mask; /* Saved interrupt mask */
20  struct dentry *devptr; /* Entry in device switch table */
21  int32 retval; /* Value to return to caller */
22 
23  mask = disable();
24  if (isbaddev(descrp))
25  {
26  restore(mask);
27  return SYSERR;
28  }
29  devptr = (struct dentry *)&devtab[descrp];
30  retval = (*devptr->dvinit)(devptr);
31  restore(mask);
32  return retval;
33 }
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
devcall(* dvinit)(struct dentry *)
Definition: conf.h:10
Definition: conf.h:6
struct dentry devtab[]
Definition: conf.c:11
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define isbaddev(f)
デバイスIDを検証するマクロ。
Definition: device.h:15
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initevec()

int32 initevec ( void  )

Referenced by sysinit().

Here is the caller graph for this function:

◆ initintc()

int32 initintc ( void  )

Definition at line 18 of file evec.c.

References INTC_SYSCONFIG_SOFTRESET, INTC_SYSSTATUS_RESETDONE, OK, intc_csreg::sysconfig, and intc_csreg::sysstatus.

Referenced by platinit().

19 {
20  struct intc_csreg *csrptr = (struct intc_csreg *)0x48200000;
21 
22  /* Reset the interrupt controller */
23 
25 
26  /* Wait until reset is complete */
27 
28  while((csrptr->sysstatus & INTC_SYSSTATUS_RESETDONE) == 0);
29 
30  return OK;
31 }
#define INTC_SYSCONFIG_SOFTRESET
Definition: interrupt.h:38
uint32 sysstatus
Definition: interrupt.h:22
#define OK
処理が成功した場合
Definition: kernel.h:77
#define INTC_SYSSTATUS_RESETDONE
Definition: interrupt.h:39
uint32 sysconfig
Definition: interrupt.h:21
Here is the caller graph for this function:

◆ inl()

int32 inl ( int32  )

◆ insert()

status insert ( pid32  pid,
qid16  q,
int32  key 
)

優先度に基づいて、キューにプロセスを挿入する。

優先度の降順に並べたキューに対して、以下を行う。 Step1. キューを先頭から走査(whileループ部)
Step2. 挿入しようとしているプロセスIDの優先度より低い優先度を持つプロセスを探す。
Step3.「より低優先度なプロセスノード(Step2で見つけたノード)」と「その前にあるノード」との間に、 挿入したいプロセスを配置する。 なお、キューの末尾は有効な最小キーを下回るため、ループは必ず停止する。

Parameters
[in]pid挿入するプロセスID
[in]q使用するキューID
[in]key挿入するプロセスの優先度(キー)
Returns
成功時はOK、キューIDもしくはプロセスIDが不正の場合はSYSERRを返す。

Definition at line 20 of file insert.c.

References firstid, isbadpid, isbadqid, OK, qentry::qkey, qentry::qnext, qentry::qprev, queuetab, and SYSERR.

Referenced by ready(), and resched().

21 {
22  qid16 curr; /* Runs through items in a queue*/
23  qid16 prev; /* Holds previous node index */
24 
25  if (isbadqid(q) || isbadpid(pid))
26  {
27  return SYSERR;
28  }
29 
30  curr = firstid(q);
31  while (queuetab[curr].qkey >= key)
32  {
33  curr = queuetab[curr].qnext;
34  }
35 
36  /* Insert process between curr node and previous node */
37 
38  prev = queuetab[curr].qprev; /* Get index of previous node */
39  queuetab[pid].qnext = curr;
40  queuetab[pid].qprev = prev;
41  queuetab[pid].qkey = key;
42  queuetab[prev].qnext = pid;
43  queuetab[curr].qprev = pid;
44  return OK;
45 }
struct qentry queuetab[]
Definition: queue.c:45
#define isbadpid(x)
プロセスIDを検証する。割り込みが無効になっている事を想定している。
Definition: process.h:71
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
#define isbadqid(x)
キューIDが不正値かどうかをチェックする。
Definition: queue.h:132
qid16 qnext
次のプロセスか末尾のプロセスのインデックス。
Definition: queue.h:39
int32 qkey
キュー順序を決定するキー(優先度)。
Definition: queue.h:37
qid16 qprev
前のプロセスか先頭のプロセスのインデックス。
Definition: queue.h:41
#define firstid(q)
リストの最初のプロセスのIDを返す。
Definition: queue.h:70
int16 qid16
キューID
Definition: kernel.h:24
Here is the caller graph for this function:

◆ insertd()

status insertd ( pid32  ,
qid16  ,
int32   
)

Definition at line 9 of file insertd.c.

References isbadpid, isbadqid, OK, qentry::qkey, qentry::qnext, qentry::qprev, queuehead, queuetab, queuetail, and SYSERR.

Referenced by recvtime(), and sleepms().

14 {
15  int32 next; /* Runs through the delta list */
16  int32 prev; /* Follows next through the list*/
17 
18  if (isbadqid(q) || isbadpid(pid)) {
19  return SYSERR;
20  }
21 
22  prev = queuehead(q);
23  next = queuetab[queuehead(q)].qnext;
24  while ((next != queuetail(q)) && (queuetab[next].qkey <= key)) {
25  key -= queuetab[next].qkey;
26  prev = next;
27  next = queuetab[next].qnext;
28  }
29 
30  /* Insert new node between prev and next nodes */
31 
32  queuetab[pid].qnext = next;
33  queuetab[pid].qprev = prev;
34  queuetab[pid].qkey = key;
35  queuetab[prev].qnext = pid;
36  queuetab[next].qprev = pid;
37  if (next != queuetail(q)) {
38  queuetab[next].qkey -= key;
39  }
40 
41  return OK;
42 }
struct qentry queuetab[]
Definition: queue.c:45
#define isbadpid(x)
プロセスIDを検証する。割り込みが無効になっている事を想定している。
Definition: process.h:71
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define queuehead(q)
キューの先頭を返す。
Definition: queue.h:53
#define OK
処理が成功した場合
Definition: kernel.h:77
#define isbadqid(x)
キューIDが不正値かどうかをチェックする。
Definition: queue.h:132
qid16 qnext
次のプロセスか末尾のプロセスのインデックス。
Definition: queue.h:39
int32 qkey
キュー順序を決定するキー(優先度)。
Definition: queue.h:37
qid16 qprev
前のプロセスか先頭のプロセスのインデックス。
Definition: queue.h:41
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define queuetail(q)
キューの末尾を返す。
Definition: queue.h:61
Here is the caller graph for this function:

◆ insw()

int32 insw ( int32  ,
int32  ,
int32   
)

◆ inw()

int32 inw ( int32  )

◆ ioerr()

devcall ioerr ( void  )

ステータスとしてエラーを返す(デバイステーブルの"error"エントリに対して使用する)。

Returns
SYSERRを返す。

Definition at line 12 of file ioerr.c.

13 {
14  return SYSERR;
15 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79

◆ ionull()

devcall ionull ( void  )

何もしない(デバイステーブルの"don't care"エントリに使用する)

Returns
必ずOKを返す。

Definition at line 11 of file ionull.c.

12 {
13  return OK;
14 }
#define OK
処理が成功した場合
Definition: kernel.h:77

◆ ip_enqueue()

status ip_enqueue ( struct netpacket )

Definition at line 439 of file ip.c.

References disable(), freebuf(), IP_OQSIZ, ipoqueue, iqentry::iqbuf, iqentry::iqsem, iqentry::iqtail, kprintf(), OK, restore(), semcount(), signal(), and SYSERR.

Referenced by icmp_in().

442 {
443  intmask mask; /* Saved interrupt mask */
444  struct iqentry *iptr; /* Ptr. to network output queue */
445 
446  /* Ensure only one process accesses output queue at a time */
447 
448  mask = disable();
449 
450  /* Enqueue packet on network output queue */
451 
452  iptr = &ipoqueue;
453  if (semcount(iptr->iqsem) >= IP_OQSIZ) {
454  kprintf("ipout: output queue overflow\n");
455  freebuf((char *)pktptr);
456  restore(mask);
457  return SYSERR;
458  }
459  iptr->iqbuf[iptr->iqtail++] = pktptr;
460  if (iptr->iqtail >= IP_OQSIZ) {
461  iptr->iqtail = 0;
462  }
463  signal(iptr->iqsem);
464  restore(mask);
465  return OK;
466 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
syscall semcount(sid32)
セマフォのカウント値を返す。
Definition: semcount.c:18
void restore(intmask)
#define IP_OQSIZ
IPアウトプットキューのサイズ
Definition: ip.h:24
sid32 iqsem
パケット(pkts)をカウントするセマフォ
Definition: ip.h:37
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct netpacket * iqbuf[IP_OQSIZ]
循環パケットキュー
Definition: ip.h:39
#define OK
処理が成功した場合
Definition: kernel.h:77
struct iqentry ipoqueue
ネットワーク送信キュー
Definition: ip.c:6
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
ipout(IP送信)プロセスを待機している送信用IPパケットのキュー
Definition: ip.h:30
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
int32 iqtail
次の空きスロットのインデックス。
Definition: ip.h:35
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ip_hton()

void ip_hton ( struct netpacket )

Definition at line 338 of file ip.c.

References htonl, htons, netpacket::net_ipdst, netpacket::net_ipfrag, netpacket::net_ipid, netpacket::net_iplen, and netpacket::net_ipsrc.

Referenced by ip_out().

342 {
343  pktptr->net_iplen = htons(pktptr->net_iplen);
344  pktptr->net_ipid = htons(pktptr->net_ipid);
345  pktptr->net_ipfrag = htons(pktptr->net_ipfrag);
346  pktptr->net_ipsrc = htonl(pktptr->net_ipsrc);
347  pktptr->net_ipdst = htonl(pktptr->net_ipdst);
348 }
#define htonl(x)
Definition: prototypes.h:620
#define htons(x)
Definition: prototypes.h:619
Here is the caller graph for this function:

◆ ip_in()

void ip_in ( struct netpacket )

Definition at line 13 of file ip.c.

References freebuf(), icmp_cksum(), icmp_ntoh(), IP_BCAST, IP_HDR_LEN, IP_ICMP, ip_local(), ip_ntoh(), IP_UDP, network::ipbcast, ipcksum(), network::ipucast, network::ipvalid, kprintf(), netpacket::net_ictype, netpacket::net_ipdst, netpacket::net_iplen, netpacket::net_ipproto, netpacket::net_ipvh, NetData, and udp_ntoh().

Referenced by netin().

16 {
17  int32 icmplen; /* Length of ICMP message */
18 
19  /* Verify checksum */
20 
21  if (ipcksum(pktptr) != 0) {
22  kprintf("IP header checksum failed\n\r");
23  freebuf((char *)pktptr);
24  return;
25  }
26 
27  /* Convert IP header fields to host order */
28 
29  ip_ntoh(pktptr);
30 
31  /* Ensure version and length are valid */
32 
33  if (pktptr->net_ipvh != 0x45) {
34  kprintf("IP version failed\n\r");
35  freebuf((char *)pktptr);
36  return;
37  }
38 
39  /* Verify encapsulated prototcol checksums and then convert */
40  /* the encapsulated headers to host byte order */
41 
42  switch (pktptr->net_ipproto) {
43 
44  case IP_UDP:
45  /* Skipping UDP checksum for now */
46  udp_ntoh(pktptr);
47  break;
48 
49  case IP_ICMP:
50  icmplen = pktptr->net_iplen - IP_HDR_LEN;
51  if (icmp_cksum((char *)&pktptr->net_ictype,icmplen) != 0){
52  freebuf((char *)pktptr);
53  return;
54  }
55  icmp_ntoh(pktptr);
56  break;
57 
58  default:
59  break;
60  }
61 
62  /* Deliver 255.255.255.255 to local stack */
63 
64  if (pktptr->net_ipdst == IP_BCAST) {
65  ip_local(pktptr);
66  return;
67  }
68 
69  /* If we do not yet have a valid address, accept UDP packets */
70  /* (to get DHCP replies) and drop others */
71 
72  if (!NetData.ipvalid) {
73  if (pktptr->net_ipproto == IP_UDP) {
74  ip_local(pktptr);
75  return;
76  } else {
77  freebuf((char *)pktptr);
78  return;
79  }
80  }
81 
82  /* If packet is destined for us, accept it; otherwise, drop it */
83 
84  if ( (pktptr->net_ipdst == NetData.ipucast) ||
85  (pktptr->net_ipdst == NetData.ipbcast) ||
86  (pktptr->net_ipdst == IP_BCAST) ) {
87  ip_local(pktptr);
88  return;
89  } else {
90 
91  /* Drop the packet */
92  freebuf((char *)pktptr);
93  return;
94  }
95 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define IP_UDP
IP向けのUDPプロトコルタイプ
Definition: ip.h:16
uint32 ipucast
Definition: net.h:55
void ip_local(struct netpacket *pktptr)
Definition: ip.c:186
#define IP_BCAST
IPローカルブロードキャストアドレス。
Definition: ip.h:7
struct network NetData
Definition: net.c:6
void ip_ntoh(struct netpacket *pktptr)
Definition: ip.c:323
void icmp_ntoh(struct netpacket *)
Definition: icmp.c:408
#define IP_HDR_LEN
IPヘッダのバイト数。
Definition: ip.h:20
#define IP_ICMP
IP向けのICMPプロトコルタイプ
Definition: ip.h:14
uint16 icmp_cksum(char *, int32)
Definition: icmp.c:359
void udp_ntoh(struct netpacket *)
Definition: udp.c:553
uint16 ipcksum(struct netpacket *pkt)
Definition: ip.c:286
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint32 ipbcast
Definition: net.h:56
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
bool8 ipvalid
Definition: net.h:63
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ip_local()

void ip_local ( struct netpacket )

Definition at line 186 of file ip.c.

References freebuf(), icmp_in(), IP_ICMP, IP_UDP, netpacket::net_ipproto, and udp_in().

Referenced by ip_in(), ip_send(), and ipout().

189 {
190  /* Use datagram contents to determine how to process */
191 
192  switch (pktptr->net_ipproto) {
193 
194  case IP_UDP:
195  udp_in(pktptr);
196  return;
197 
198  case IP_ICMP:
199  icmp_in(pktptr);
200  return;
201 
202  default:
203  freebuf((char *)pktptr);
204  return;
205  }
206 }
#define IP_UDP
IP向けのUDPプロトコルタイプ
Definition: ip.h:16
#define IP_ICMP
IP向けのICMPプロトコルタイプ
Definition: ip.h:14
void icmp_in(struct netpacket *)
Definition: icmp.c:26
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
void udp_in(struct netpacket *)
Definition: udp.c:29
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ip_ntoh()

void ip_ntoh ( struct netpacket )

Definition at line 323 of file ip.c.

References netpacket::net_ipdst, netpacket::net_ipfrag, netpacket::net_ipid, netpacket::net_iplen, netpacket::net_ipsrc, ntohl, and ntohs.

Referenced by ip_in().

326 {
327  pktptr->net_iplen = ntohs(pktptr->net_iplen);
328  pktptr->net_ipid = ntohs(pktptr->net_ipid);
329  pktptr->net_ipfrag = ntohs(pktptr->net_ipfrag);
330  pktptr->net_ipsrc = ntohl(pktptr->net_ipsrc);
331  pktptr->net_ipdst = ntohl(pktptr->net_ipdst);
332 }
#define ntohl(x)
Definition: prototypes.h:623
#define ntohs(x)
Definition: prototypes.h:622
Here is the caller graph for this function:

◆ ip_out()

status ip_out ( struct netpacket )

Definition at line 213 of file ip.c.

References ETH_HDR_LEN, eth_hton(), ETHER0, freebuf(), htons, icmp_cksum(), icmp_hton(), IP_HDR_LEN, ip_hton(), IP_ICMP, IP_UDP, ipcksum(), netpacket::net_iccksum, netpacket::net_ictype, netpacket::net_ipcksum, netpacket::net_iplen, netpacket::net_ipproto, netpacket::net_udpcksum, OK, SYSERR, udp_hton(), and write().

Referenced by ip_send(), and ipout().

216 {
217  uint16 cksum; /* Checksum in host byte order */
218  int32 len; /* Length of ICMP message */
219  int32 pktlen; /* Length of entire packet */
220  int32 retval; /* Value returned by write */
221 
222  /* Compute total packet length */
223 
224  pktlen = pktptr->net_iplen + ETH_HDR_LEN;
225 
226  /* Convert encapsulated protocol to network byte order */
227 
228  switch (pktptr->net_ipproto) {
229 
230  case IP_UDP:
231 
232  pktptr->net_udpcksum = 0;
233  udp_hton(pktptr);
234 
235  /* ...skipping UDP checksum computation */
236 
237  break;
238 
239  case IP_ICMP:
240  icmp_hton(pktptr);
241 
242  /* Compute ICMP checksum */
243 
244  pktptr->net_iccksum = 0;
245  len = pktptr->net_iplen-IP_HDR_LEN;
246  cksum = icmp_cksum((char *)&pktptr->net_ictype,
247  len);
248  pktptr->net_iccksum = 0xffff & htons(cksum);
249  break;
250 
251  default:
252  break;
253  }
254 
255  /* Convert IP fields to network byte order */
256 
257  ip_hton(pktptr);
258 
259  /* Compute IP header checksum */
260 
261  pktptr->net_ipcksum = 0;
262  cksum = ipcksum(pktptr);
263  pktptr->net_ipcksum = 0xffff & htons(cksum);
264 
265  /* Convert Ethernet fields to network byte order */
266 
267  eth_hton(pktptr);
268 
269  /* Send packet over the Ethernet */
270 
271  retval = write(ETHER0, (char*)pktptr, pktlen);
272  freebuf((char *)pktptr);
273 
274  if (retval == SYSERR) {
275  return SYSERR;
276  } else {
277  return OK;
278  }
279 }
#define IP_UDP
IP向けのUDPプロトコルタイプ
Definition: ip.h:16
void eth_hton(struct netpacket *)
Definition: net.c:127
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define IP_HDR_LEN
IPヘッダのバイト数。
Definition: ip.h:20
void ip_hton(struct netpacket *pktptr)
Definition: ip.c:338
#define OK
処理が成功した場合
Definition: kernel.h:77
#define IP_ICMP
IP向けのICMPプロトコルタイプ
Definition: ip.h:14
uint16 icmp_cksum(char *, int32)
Definition: icmp.c:359
syscall write(did32, char *, uint32)
Definition: write.c:9
uint16 ipcksum(struct netpacket *pkt)
Definition: ip.c:286
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
unsigned short uint16
符号なし16ビット整数(unsigned short)
Definition: kernel.h:17
void udp_hton(struct netpacket *)
Definition: udp.c:567
#define ETH_HDR_LEN
Definition: ether.h:22
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
#define htons(x)
Definition: prototypes.h:619
#define ETHER0
Definition: conf.h:34
void icmp_hton(struct netpacket *)
Definition: icmp.c:394
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ip_route()

int32 ip_route ( uint32  )

◆ ip_send()

status ip_send ( struct netpacket )

Definition at line 103 of file ip.c.

References arp_resolve(), disable(), ETH_ADDR_LEN, network::ethbcast, freebuf(), IP_BCAST, ip_local(), ip_out(), network::ipbcast, network::ipmask, network::ipprefix, network::iprouter, network::ipucast, memcpy(), netpacket::net_ethdst, netpacket::net_ipdst, NetData, OK, restore(), and SYSERR.

Referenced by icmp_send(), udp_send(), and udp_sendto().

106 {
107  intmask mask; /* Saved interrupt mask */
108  uint32 dest; /* Destination of the datagram */
109  int32 retval; /* Return value from functions */
110  uint32 nxthop; /* Next-hop address */
111 
112  mask = disable();
113 
114  /* Pick up the IP destination address from the packet */
115 
116  dest = pktptr->net_ipdst;
117 
118  /* Loop back to local stack if destination 127.0.0.0/8 */
119 
120  if ((dest&0xff000000) == 0x7f000000) {
121  ip_local(pktptr);
122  restore(mask);
123  return OK;
124  }
125 
126  /* Loop back if the destination matches our IP unicast address */
127 
128  if (dest == NetData.ipucast) {
129  ip_local(pktptr);
130  restore(mask);
131  return OK;
132  }
133 
134  /* Broadcast if destination is 255.255.255.255 */
135 
136  if ( (dest == IP_BCAST) ||
137  (dest == NetData.ipbcast) ) {
138  memcpy(pktptr->net_ethdst, NetData.ethbcast,
139  ETH_ADDR_LEN);
140  retval = ip_out(pktptr);
141  restore(mask);
142  return retval;
143  }
144 
145  /* If destination is on the local network, next hop is the */
146  /* destination; otherwise, next hop is default router */
147 
148 
149  if ( (dest & NetData.ipmask) == NetData.ipprefix) {
150 
151  /* Next hop is the destination itself */
152  nxthop = dest;
153 
154  } else {
155 
156  /* Next hop is default router on the network */
157  nxthop = NetData.iprouter;
158 
159  }
160 
161  if (nxthop == 0) { /* Dest. invalid or no default route */
162  freebuf((char *)pktptr);
163  return SYSERR;
164  }
165 
166  /* Resolve the next-hop address to get a MAC address */
167 
168  retval = arp_resolve(nxthop, pktptr->net_ethdst);
169  if (retval != OK) {
170  freebuf((char *)pktptr);
171  return SYSERR;
172  }
173 
174  /* Send the packet */
175 
176  retval = ip_out(pktptr);
177  restore(mask);
178  return retval;
179 }
uint32 ipucast
Definition: net.h:55
uint32 ipmask
Definition: net.h:57
void restore(intmask)
void ip_local(struct netpacket *pktptr)
Definition: ip.c:186
#define IP_BCAST
IPローカルブロードキャストアドレス。
Definition: ip.h:7
struct network NetData
Definition: net.c:6
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
uint32 iprouter
Definition: net.h:59
status ip_out(struct netpacket *pktptr)
Definition: ip.c:213
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint32 ipprefix
Definition: net.h:58
uint32 ipbcast
Definition: net.h:56
byte ethbcast[ETH_ADDR_LEN]
Definition: net.h:65
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
status arp_resolve(uint32, byte[])
#define ETH_ADDR_LEN
Definition: ether.h:10
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ipcksum()

uint16 ipcksum ( struct netpacket )

Definition at line 286 of file ip.c.

References htons, and netpacket::net_ipvh.

Referenced by ip_in(), ip_out(), pdump(), and pdumph().

289 {
290  uint16 *hptr; /* Ptr to 16-bit header values */
291  int32 i; /* Counts 16-bit values in hdr */
292  uint16 word; /* One 16-bit word */
293  uint32 cksum; /* Computed value of checksum */
294 
295  hptr= (uint16 *) &pkt->net_ipvh;
296 
297  /* Sum 16-bit words in the packet */
298 
299  cksum = 0;
300  for (i=0; i<10; i++) {
301  word = *hptr++;
302  cksum += (uint32) htons(word);
303  }
304 
305  /* Add in carry, and take the ones-complement */
306 
307  cksum += (cksum >> 16);
308  cksum = 0xffff & ~cksum;
309 
310  /* Use all-1s for zero */
311 
312  if (cksum == 0xffff) {
313  cksum = 0;
314  }
315  return (uint16) (0xffff & cksum);
316 }
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
unsigned short uint16
符号なし16ビット整数(unsigned short)
Definition: kernel.h:17
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
#define htons(x)
Definition: prototypes.h:619
Here is the caller graph for this function:

◆ ipout()

process ipout ( void  )

Definition at line 356 of file ip.c.

References arp_resolve(), ETH_ADDR_LEN, network::ethucast, freebuf(), IP_BCAST, ip_local(), IP_OQSIZ, ip_out(), network::ipbcast, network::ipmask, ipoqueue, network::ipprefix, network::iprouter, network::ipucast, iqentry::iqbuf, iqentry::iqhead, iqentry::iqsem, kprintf(), memcpy(), netpacket::net_ethdst, netpacket::net_ethsrc, netpacket::net_ipdst, NetData, OK, and wait().

Referenced by net_init().

357 {
358  struct netpacket *pktptr; /* Pointer to next the packet */
359  struct iqentry *ipqptr; /* Pointer to IP output queue */
360  uint32 destip; /* Destination IP address */
361  uint32 nxthop; /* Next hop IP address */
362  int32 retval; /* Value returned by functions */
363 
364  ipqptr = &ipoqueue;
365 
366  while(1) {
367 
368  /* Obtain next packet from the IP output queue */
369 
370  wait(ipqptr->iqsem);
371  pktptr = ipqptr->iqbuf[ipqptr->iqhead++];
372  if (ipqptr->iqhead >= IP_OQSIZ) {
373  ipqptr->iqhead= 0;
374  }
375 
376  /* Fill in the MAC source address */
377 
379 
380  /* Extract destination address from packet */
381 
382  destip = pktptr->net_ipdst;
383 
384 
385  /* Sanity check: packets sent to ipout should *not* */
386  /* contain a broadcast address. */
387 
388  if ((destip == IP_BCAST)||(destip == NetData.ipbcast)) {
389  kprintf("ipout: encountered a broadcast\n");
390  freebuf((char *)pktptr);
391  continue;
392  }
393 
394  /* Check whether destination is the local computer */
395 
396  if (destip == NetData.ipucast) {
397  ip_local(pktptr);
398  continue;
399  }
400 
401  /* Check whether destination is on the local net */
402 
403  if ( (destip & NetData.ipmask) == NetData.ipprefix) {
404 
405  /* Next hop is the destination itself */
406 
407  nxthop = destip;
408  } else {
409 
410  /* Next hop is default router on the network */
411 
412  nxthop = NetData.iprouter;
413  }
414 
415  if (nxthop == 0) { /* Dest. invalid or no default route*/
416  freebuf((char *)pktptr);
417  continue;
418  }
419 
420  /* Use ARP to resolve next-hop address */
421 
422  retval = arp_resolve(nxthop, pktptr->net_ethdst);
423  if (retval != OK) {
424  freebuf((char *)pktptr);
425  continue;
426  }
427 
428  /* Use ipout to Convert byte order and send */
429 
430  ip_out(pktptr);
431  }
432 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
uint32 ipucast
Definition: net.h:55
uint32 ipmask
Definition: net.h:57
void ip_local(struct netpacket *pktptr)
Definition: ip.c:186
#define IP_OQSIZ
IPアウトプットキューのサイズ
Definition: ip.h:24
sid32 iqsem
パケット(pkts)をカウントするセマフォ
Definition: ip.h:37
#define IP_BCAST
IPローカルブロードキャストアドレス。
Definition: ip.h:7
struct network NetData
Definition: net.c:6
byte net_ethdst[ETH_ADDR_LEN]
Definition: net.h:17
struct netpacket * iqbuf[IP_OQSIZ]
循環パケットキュー
Definition: ip.h:39
#define OK
処理が成功した場合
Definition: kernel.h:77
struct iqentry ipoqueue
ネットワーク送信キュー
Definition: ip.c:6
byte net_ethsrc[ETH_ADDR_LEN]
Definition: net.h:18
int32 iqhead
次に送信するパケットのインデックス
Definition: ip.h:33
byte ethucast[ETH_ADDR_LEN]
Definition: net.h:64
uint32 iprouter
Definition: net.h:59
status ip_out(struct netpacket *pktptr)
Definition: ip.c:213
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint32 ipprefix
Definition: net.h:58
uint32 ipbcast
Definition: net.h:56
ipout(IP送信)プロセスを待機している送信用IPパケットのキュー
Definition: ip.h:30
Definition: net.h:16
uint32 net_ipdst
Definition: net.h:29
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
status arp_resolve(uint32, byte[])
#define ETH_ADDR_LEN
Definition: ether.h:10
syscall wait(sid32)
Definition: wait.c:9
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kill()

syscall kill ( pid32  pid)

指定のプロセスを終了させ、システムから終了させたプロセス情報を取り除く。

Step1. 割り込み禁止状態に移行する。
Step2. プロセスが以下の状態であれば、割り込み許可状態に復元してから処理を終了する。
 ・引数のPIDが不正
 ・引数のPIDがNULLプロセス
 ・引数のPIDで指定されるプロセスがFREE状態
Step3. 現在アクティブのプロセス数が1以下(NULLプロセスのみ動作中)の場合、
    全ユーザプロセスが終了したため、システム終了メッセージを表示する。
Step4. 親プロセスに終了させるプロセスのIDを通知する。
Step5. XINU Shell用に確保したSTDIN(標準入力)/STDOUT(標準出力)/STDERR(標準エラー)用のディスクリプタを閉じる。
Step6. 終了させるプロセスが使用していたスタックメモリを解放する。
Step7. 終了させるプロセスの状態に応じて、以下の処理を行う。
 ・実行中の場合、FREE状態に移行し、再スケジューリングを行う(二度と戻ってこない)。
 ・SLEEP状態やタイムアウト/メッセージ到着待ちの場合、休眠キューから終了させるプロセスを取り除く。
 ・WAIT状態の場合、終了させるプロセス分(1個分)だけセマフォカウンタを増やす。次に、READY状態用の処理を行う。
 ・READY状態の場合、終了させるプロセスをキューから取り出し、終了させるプロセス状態のをFREE状態に遷移する。
Step8. 割り込み許可状態に復元してから、OKを返す。

Parameters
[in]pid終了させたいプロセスのID
Returns
プロセスを終了させた場合はOKを返す。以下の場合はSYSERRを返す。
・引数のPIDが不正
・引数のPIDがNULLプロセスbr> ・引数のPIDで指定されるプロセスがFREE状態

Definition at line 31 of file kill.c.

References close(), disable(), freestk, getitem(), isbadpid, NULLPROC, OK, PR_CURR, PR_FREE, PR_READY, PR_RECTIM, PR_SLEEP, PR_WAIT, prcount, procent::prdesc, proctab, procent::prparent, procent::prsem, procent::prstate, procent::prstkbase, procent::prstklen, resched(), restore(), sentry::scount, semtab, send(), SYSERR, unsleep(), and xdone().

Referenced by exit(), userret(), and xsh_kill().

32 {
33  intmask mask; /* Saved interrupt mask */
34  struct procent *prptr; /* Ptr to process's table entry */
35  int32 i; /* Index into descriptors */
36 
37  mask = disable();
38  if (isbadpid(pid) || (pid == NULLPROC) || ((prptr = &proctab[pid])->prstate) == PR_FREE)
39  {
40  restore(mask);
41  return SYSERR;
42  }
43 
44  if (--prcount <= 1)
45  { /* Last user process completes */
46  xdone();
47  }
48 
49  send(prptr->prparent, pid);
50  for (i = 0; i < 3; i++)
51  {
52  close(prptr->prdesc[i]);
53  }
54  freestk(prptr->prstkbase, prptr->prstklen);
55 
56  switch (prptr->prstate)
57  {
58  case PR_CURR:
59  prptr->prstate = PR_FREE; /* Suicide */
60  resched();
61 
62  case PR_SLEEP:
63  case PR_RECTIM:
64  unsleep(pid);
65  prptr->prstate = PR_FREE;
66  break;
67 
68  case PR_WAIT:
69  semtab[prptr->prsem].scount++;
70  /* Fall through */
71 
72  case PR_READY:
73  getitem(pid); /* Remove from queue */
74  /* Fall through */
75 
76  default:
77  prptr->prstate = PR_FREE;
78  }
79 
80  restore(mask);
81  return OK;
82 }
pid32 prparent
このプロセスを作成したプロセスID(親プロセスID)。
Definition: process.h:102
#define PR_RECTIM
プロセスが「タイムアウト」か「メッセージの到着」のいずれか早い方で待機中の状態。
Definition: process.h:49
void restore(intmask)
int32 prcount
現在アクティブのプロセス。
Definition: initialize.c:30
#define PR_READY
プロセスが準備完了(READY)状態。
Definition: process.h:39
#define isbadpid(x)
プロセスIDを検証する。割り込みが無効になっている事を想定している。
Definition: process.h:71
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
syscall close(did32)
Definition: close.c:9
#define OK
処理が成功した場合
Definition: kernel.h:77
syscall send(pid32, umsg32)
プロセスにメッセージを送信し、受信側が待機状態の場合はREADY状態にする。
Definition: send.c:21
syscall unsleep(pid32)
Definition: unsleep.c:11
#define NULLPROC
NULLプロセスのID。NULLプロセスは、他に動かすプロセスがない時に動く空プロセス
Definition: process.h:54
uint32 prstklen
Bytesで表されたスタックの長さ(最大値。Byte)。
Definition: process.h:96
#define PR_CURR
プロセスが現在動作中。
Definition: process.h:37
#define PR_SLEEP
プロセスが休眠中(タイマー待機中)の状態。
Definition: process.h:43
sid32 prsem
プロセスが待機しているセマフォ。
Definition: process.h:100
char * prstkbase
ランタイムスタックの基点(メモリ領域で最上位のアドレス)。
Definition: process.h:94
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int16 prdesc[NDESC]
プロセス用のデバイスディスクリプタ
Definition: process.h:108
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
#define PR_FREE
プロセステーブルエントリが使用されていない状態。
Definition: process.h:35
void resched(void)
最優先の適切なプロセスにCPU実行権を渡す。
Definition: resched.c:22
pid32 getitem(pid32)
キューの任意の位置からプロセスを取り出す。
Definition: getitem.c:51
void xdone(void)
最終プロセスの終了時、システム終了メッセージを表示する。
Definition: xdone.c:10
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
int32 scount
セマフォカウント(負の値(-N)の場合は、キューにN個の待機プロセスがある。それ以外はキューが空である) ...
Definition: semaphore.h:24
#define freestk(p, len)
getstk()で割り当てたスタックメモリを解放する。
Definition: memory.h:46
struct sentry semtab[]
セマフォテーブルエントリのextern宣言
Definition: initialize.c:25
#define PR_WAIT
プロセスがセマフォ上で待機中の状態。
Definition: process.h:47
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lexan()

int32 lexan ( char *  ,
int32  ,
char *  ,
int32 ,
int32  [],
int32  [] 
)

Definition at line 10 of file lexan.c.

References NULLCH, SH_AMPER, SH_BLANK, SH_DQUOTE, SH_GREATER, SH_LESS, SH_NEWLINE, SH_SQUOTE, SH_TAB, SH_TOK_AMPER, SH_TOK_GREATER, SH_TOK_LESS, SH_TOK_OTHER, SHELL_MAXTOK, and SYSERR.

Referenced by shell().

25 {
26  char quote; /* Character for quoted string */
27  uint32 ntok; /* Number of tokens found */
28  char *p; /* Pointer that walks along the */
29  /* input line */
30  int32 tbindex; /* Index into tokbuf */
31  char ch; /* Next char from input line */
32 
33  /* Start at the beginning of the line with no tokens */
34 
35  ntok = 0;
36  p = line;
37  tbindex = 0;
38 
39  /* While not yet at end of line, get next token */
40 
41  while ( (*p != NULLCH) && (*p != SH_NEWLINE) ) {
42 
43  /* If too many tokens, return error */
44 
45  if (ntok >= SHELL_MAXTOK) {
46  return SYSERR;
47  }
48 
49  /* Skip whitespace before token */
50 
51  while ( (*p == SH_BLANK) || (*p == SH_TAB) ) {
52  p++;
53  }
54 
55  /* Stop parsing at end of line (or end of string) */
56 
57  ch = *p;
58  if ( (ch==SH_NEWLINE) || (ch==NULLCH) ) {
59  *tlen = tbindex;
60  return ntok;
61  }
62 
63  /* Set next entry in tok array to be an index to the */
64  /* current location in the token buffer */
65 
66  tok[ntok] = tbindex; /* the start of the token */
67 
68  /* Set the token type */
69 
70  switch (ch) {
71 
72  case SH_AMPER: toktyp[ntok] = SH_TOK_AMPER;
73  tokbuf[tbindex++] = ch;
74  tokbuf[tbindex++] = NULLCH;
75  ntok++;
76  p++;
77  continue;
78 
79  case SH_LESS: toktyp[ntok] = SH_TOK_LESS;
80  tokbuf[tbindex++] = ch;
81  tokbuf[tbindex++] = NULLCH;
82  ntok++;
83  p++;
84  continue;
85 
86  case SH_GREATER: toktyp[ntok] = SH_TOK_GREATER;
87  tokbuf[tbindex++] = ch;
88  tokbuf[tbindex++] = NULLCH;
89  ntok++;
90  p++;
91  continue;
92 
93  default: toktyp[ntok] = SH_TOK_OTHER;
94  };
95 
96  /* Handle quoted string (single or double quote) */
97 
98  if ( (ch==SH_SQUOTE) || (ch==SH_DQUOTE) ) {
99  quote = ch; /* remember opening quote */
100 
101  /* Copy quoted string to arg area */
102 
103  p++; /* Move past starting quote */
104 
105  while ( ((ch=*p++) != quote) && (ch != SH_NEWLINE)
106  && (ch != NULLCH) ) {
107  tokbuf[tbindex++] = ch;
108  }
109  if (ch != quote) { /* string missing end quote */
110  return SYSERR;
111  }
112 
113  /* Finished string - count token and go on */
114 
115  tokbuf[tbindex++] = NULLCH; /* terminate token */
116  ntok++; /* count string as one token */
117  continue; /* go to next token */
118  }
119 
120  /* Handle a token other than a quoted string */
121 
122  tokbuf[tbindex++] = ch; /* put first character in buffer*/
123  p++;
124 
125  while ( ((ch = *p) != SH_NEWLINE) && (ch != NULLCH)
126  && (ch != SH_LESS) && (ch != SH_GREATER)
127  && (ch != SH_BLANK) && (ch != SH_TAB)
128  && (ch != SH_AMPER) && (ch != SH_SQUOTE)
129  && (ch != SH_DQUOTE) ) {
130  tokbuf[tbindex++] = ch;
131  p++;
132  }
133 
134  /* Report error if other token is appended */
135 
136  if ( (ch == SH_SQUOTE) || (ch == SH_DQUOTE)
137  || (ch == SH_LESS) || (ch == SH_GREATER) ) {
138  return SYSERR;
139  }
140 
141  tokbuf[tbindex++] = NULLCH; /* terminate the token */
142 
143  ntok++; /* count valid token */
144 
145  }
146  *tlen = tbindex;
147  return ntok;
148 }
#define SH_TOK_GREATER
大なり&#39;>&#39;トークン
Definition: shell.h:79
#define SH_AMPER
アンパサンド文字&#39;&&#39;(字句解析時に用いる)
Definition: shell.h:60
#define SH_TAB
TAB文字(字句解析時に用いる)
Definition: shell.h:64
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define SH_BLANK
ブランク(空白)文字(字句解析時に用いる)
Definition: shell.h:62
#define SH_TOK_OTHER
その他(&#39;&&#39;、&#39;<&#39;、&#39;>以外&#39;)のトークン(例:英数字文字列)
Definition: shell.h:81
#define SH_SQUOTE
シングルクォート文字&#39;&#39;&#39;(字句解析時に用いる)
Definition: shell.h:66
#define SH_NEWLINE
LF改行コード&#39; &#39;(字句解析時に用いる)
Definition: shell.h:56
#define SHELL_MAXTOK
一行あたりの最大トークン数
Definition: shell.h:9
#define SH_DQUOTE
ダブルクォート文字&#39;"&#39;(字句解析時に用いる)
Definition: shell.h:68
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define SH_GREATER
大なり記号&#39;>&#39;
Definition: shell.h:72
#define SH_TOK_AMPER
アンパサンド&#39;&&#39;トークン
Definition: shell.h:75
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
#define SH_LESS
小なり記号&#39;<&#39;
Definition: shell.h:70
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
#define SH_TOK_LESS
小なり&#39;<&#39;トークン
Definition: shell.h:77
Here is the caller graph for this function:

◆ lfdballoc()

dbid32 lfdballoc ( struct lfdbfree )

Definition at line 19 of file lfdballoc.c.

References DFILL, FALSE, LF_AREA_DIR, LF_BLKSIZ, Lf_data, lfdata::lf_dir, lfdata::lf_dirdirty, LF_DNULL, lfdata::lf_dskdev, lfdir::lfd_dfree, memset(), panic(), read(), SYSERR, and write().

Referenced by lfsetup().

22 {
23  dbid32 dnum; /* ID of next d-block on the free list */
24  int32 retval; /* Return value */
25 
26  /* Get the ID of first data block on the free list */
27 
28  dnum = Lf_data.lf_dir.lfd_dfree;
29  if (dnum == LF_DNULL)
30  { /* Ran out of free data blocks */
31  panic("out of data blocks");
32  }
33  retval = read(Lf_data.lf_dskdev, (char *)dbuff, dnum);
34  if (retval == SYSERR)
35  {
36  panic("lfdballoc cannot read disk block\n\r");
37  }
38 
39  /* Unlink d-block from in-memory directory */
40 
41  Lf_data.lf_dir.lfd_dfree = dbuff->lf_nextdb;
44 
45  /* Fill data block to erase old data */
46 
47  memset((char *)dbuff, DFILL, LF_BLKSIZ);
48  return dnum;
49 }
int32 dbid32
データブロックID(ファイルシステムで使用する)
Definition: kernel.h:42
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct lfdata Lf_data
Definition: lfsinit.c:5
syscall read(did32, char *, uint32)
Definition: read.c:9
did32 lf_dskdev
Definition: lfilesys.h:131
#define LF_AREA_DIR
Definition: lfilesys.h:67
dbid32 lfd_dfree
Definition: lfilesys.h:120
syscall write(did32, char *, uint32)
Definition: write.c:9
#define LF_BLKSIZ
Definition: lfilesys.h:48
struct lfdir lf_dir
Definition: lfilesys.h:134
#define FALSE
Boolean False(0)
Definition: kernel.h:63
bool8 lf_dirdirty
Definition: lfilesys.h:137
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define LF_DNULL
Definition: lfilesys.h:56
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
#define DFILL
Definition: lfdballoc.c:12
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lfdbfree()

status lfdbfree ( did32  ,
dbid32   
)

Definition at line 10 of file lfdbfree.c.

References LF_AREA_DIR, Lf_data, lfdata::lf_dir, lfdbfree::lf_nextdb, OK, and write().

Referenced by lftruncate().

14 {
15  struct lfdir *dirptr; /* Pointer to directory */
16  struct lfdbfree buf; /* Buffer to hold data block */
17 
18  dirptr = &Lf_data.lf_dir;
19  buf.lf_nextdb = dirptr->lfd_dfree;
20  dirptr->lfd_dfree = dnum;
21  write(diskdev, (char *)&buf, dnum);
22  write(diskdev, (char *)dirptr, LF_AREA_DIR);
23 
24  return OK;
25 }
struct lfdata Lf_data
Definition: lfsinit.c:5
#define OK
処理が成功した場合
Definition: kernel.h:77
#define LF_AREA_DIR
Definition: lfilesys.h:67
dbid32 lfd_dfree
Definition: lfilesys.h:120
syscall write(did32, char *, uint32)
Definition: write.c:9
struct lfdir lf_dir
Definition: lfilesys.h:134
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lfflush()

status lfflush ( struct lflcblk )

Definition at line 10 of file lfflush.c.

References FALSE, LF_AREA_DIR, Lf_data, lfdata::lf_dir, lfdata::lf_dirdirty, lfdata::lf_dskdev, LF_FREE, lflcblk::lfdbdirty, lflcblk::lfdblock, lflcblk::lfdnum, lflcblk::lfibdirty, lflcblk::lfiblock, lfibput(), lflcblk::lfinum, lflcblk::lfstate, OK, SYSERR, and write().

Referenced by lflclose(), lfsetup(), and lftruncate().

13 {
14 
15  if (lfptr->lfstate == LF_FREE) {
16  return SYSERR;
17  }
18 
19  /* Write the directory if it has changed */
20 
21  if (Lf_data.lf_dirdirty) {
23  LF_AREA_DIR);
25  }
26 
27  /* Write data block if it has changed */
28 
29  if (lfptr->lfdbdirty) {
30  write(Lf_data.lf_dskdev, lfptr->lfdblock, lfptr->lfdnum);
31  lfptr->lfdbdirty = FALSE;
32  }
33 
34  /* Write i-block if it has changed */
35 
36  if (lfptr->lfibdirty) {
37  lfibput(Lf_data.lf_dskdev, lfptr->lfinum, &lfptr->lfiblock);
38  lfptr->lfibdirty = FALSE;
39  }
40 
41  return OK;
42 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct lfdata Lf_data
Definition: lfsinit.c:5
did32 lf_dskdev
Definition: lfilesys.h:131
#define OK
処理が成功した場合
Definition: kernel.h:77
#define LF_AREA_DIR
Definition: lfilesys.h:67
syscall write(did32, char *, uint32)
Definition: write.c:9
struct lfdir lf_dir
Definition: lfilesys.h:134
#define FALSE
Boolean False(0)
Definition: kernel.h:63
bool8 lf_dirdirty
Definition: lfilesys.h:137
#define LF_FREE
Definition: lfilesys.h:52
status lfibput(did32, ibid32, struct lfiblk *)
Definition: lfibput.c:10
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lfgetmode()

int32 lfgetmode ( char *  )

Definition at line 9 of file lfgetmode.c.

References LF_MODE_N, LF_MODE_O, LF_MODE_R, LF_MODE_RW, LF_MODE_W, NULLCH, and SYSERR.

Referenced by lfsopen().

12 {
13  int32 mbits; /* Mode bits to return */
14  char ch; /* Next char in mode string */
15 
16  mbits = 0;
17 
18  /* Mode string specifies: */
19  /* r - read */
20  /* w - write */
21  /* o - old (file must exist) */
22  /* n - new (create a new file) */
23 
24  while ( (ch = *mode++) != NULLCH) {
25  switch (ch) {
26 
27  case 'r': if (mbits&LF_MODE_R) {
28  return SYSERR;
29  }
30  mbits |= LF_MODE_R;
31  continue;
32 
33  case 'w': if (mbits&LF_MODE_W) {
34  return SYSERR;
35  }
36  mbits |= LF_MODE_W;
37  continue;
38 
39  case 'o': if (mbits&LF_MODE_O || mbits&LF_MODE_N) {
40  return SYSERR;
41  }
42  mbits |= LF_MODE_O;
43  break;
44 
45  case 'n': if (mbits&LF_MODE_O || mbits&LF_MODE_N) {
46  return SYSERR;
47  }
48  mbits |= LF_MODE_N;
49  break;
50 
51  default: return SYSERR;
52  }
53  }
54 
55  /* If neither read nor write specified, allow both */
56 
57  if ( (mbits&LF_MODE_RW) == 0 ) {
58  mbits |= LF_MODE_RW;
59  }
60  return mbits;
61 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define LF_MODE_O
Definition: lfilesys.h:45
#define LF_MODE_R
Definition: lfilesys.h:42
#define LF_MODE_N
Definition: lfilesys.h:46
#define LF_MODE_W
Definition: lfilesys.h:43
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define LF_MODE_RW
Definition: lfilesys.h:44
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the caller graph for this function:

◆ lfiballoc()

ibid32 lfiballoc ( void  )

Definition at line 10 of file lfiballoc.c.

References FALSE, lfiblk::ib_next, LF_AREA_DIR, Lf_data, lfdata::lf_dir, lfdata::lf_dirdirty, lfdata::lf_dskdev, LF_INULL, lfdir::lfd_ifree, lfibget(), panic(), and write().

Referenced by lfsetup().

11 {
12  ibid32 ibnum; /* ID of next block on the free list */
13  struct lfiblk iblock; /* Buffer to hold an index block */
14 
15  /* Get ID of first index block on free list */
16 
17  ibnum = Lf_data.lf_dir.lfd_ifree;
18  if (ibnum == LF_INULL) { /* Ran out of free index blocks */
19  panic("out of index blocks");
20  }
21  lfibget(Lf_data.lf_dskdev, ibnum, &iblock);
22 
23  /* Unlink index block from the directory free list */
24 
25  Lf_data.lf_dir.lfd_ifree = iblock.ib_next;
26 
27  /* Write a copy of the directory to disk after the change */
28 
31 
32  return ibnum;
33 }
int32 ibid32
ブロックIDのインデックス(ファイルシステムで使用する)
Definition: kernel.h:40
struct lfdata Lf_data
Definition: lfsinit.c:5
ibid32 lfd_ifree
Definition: lfilesys.h:121
did32 lf_dskdev
Definition: lfilesys.h:131
void lfibget(did32, ibid32, struct lfiblk *)
Definition: lfibget.c:10
#define LF_INULL
Definition: lfilesys.h:55
#define LF_AREA_DIR
Definition: lfilesys.h:67
syscall write(did32, char *, uint32)
Definition: write.c:9
struct lfdir lf_dir
Definition: lfilesys.h:134
#define FALSE
Boolean False(0)
Definition: kernel.h:63
bool8 lf_dirdirty
Definition: lfilesys.h:137
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lfibclear()

void lfibclear ( struct lfiblk ,
int32   
)

Definition at line 9 of file lfibclear.c.

References lfiblk::ib_dba, lfiblk::ib_next, lfiblk::ib_offset, LF_DNULL, LF_IBLEN, and LF_INULL.

Referenced by lfscreate(), and lfsetup().

13 {
14  int32 i; /* Index for data block array */
15 
16  ibptr->ib_offset = offset; /* Assign specified file offset */
17  for (i=0 ; i<LF_IBLEN ; i++) { /* Clear each data block pointer*/
18  ibptr->ib_dba[i] = LF_DNULL;
19  }
20  ibptr->ib_next = LF_INULL; /* Set next ptr to null */
21  return;
22 }
#define LF_IBLEN
Definition: lfilesys.h:57
#define LF_INULL
Definition: lfilesys.h:55
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define LF_DNULL
Definition: lfilesys.h:56
Here is the caller graph for this function:

◆ lfibget()

void lfibget ( did32  ,
ibid32  ,
struct lfiblk  
)

Definition at line 10 of file lfibget.c.

References ib2disp, ib2sect, LF_BLKSIZ, and read().

Referenced by lfiballoc(), lfsckfmt(), lfsetup(), and lftruncate().

15 {
16  char *from, *to; /* Pointers used in copying */
17  int32 i; /* Loop index used during copy */
18  char dbuff[LF_BLKSIZ]; /* Buffer to hold disk block */
19 
20  /* Read disk block that contains the specified index block */
21 
22  read(diskdev, dbuff, ib2sect(inum));
23 
24  /* Copy specified index block to caller's ibuff */
25 
26  from = dbuff + ib2disp(inum);
27  to = (char *)ibuff;
28  for (i=0 ; i<sizeof(struct lfiblk) ; i++)
29  *to++ = *from++;
30  return;
31 }
#define ib2sect(ib)
Definition: lfilesys.h:86
syscall read(did32, char *, uint32)
Definition: read.c:9
#define LF_BLKSIZ
Definition: lfilesys.h:48
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define ib2disp(ib)
Definition: lfilesys.h:91
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lfibput()

status lfibput ( did32  ,
ibid32  ,
struct lfiblk  
)

Definition at line 10 of file lfibput.c.

References ib2disp, ib2sect, LF_BLKSIZ, OK, read(), SYSERR, and write().

Referenced by lfflush(), lfscreate(), lfsetup(), and lftruncate().

15 {
16  dbid32 diskblock; /* ID of disk sector (block) */
17  char *from, *to; /* Pointers used in copying */
18  int32 i; /* Loop index used during copy */
19  char dbuff[LF_BLKSIZ]; /* Temp. buffer to hold d-block */
20 
21  /* Compute disk block number and offset of index block */
22 
23  diskblock = ib2sect(inum);
24  to = dbuff + ib2disp(inum);
25  from = (char *)ibuff;
26 
27  /* Read disk block */
28 
29  if (read(diskdev, dbuff, diskblock) == SYSERR) {
30  return SYSERR;
31  }
32 
33  /* Copy index block into place */
34 
35  for (i=0 ; i<sizeof(struct lfiblk) ; i++) {
36  *to++ = *from++;
37  }
38 
39  /* Write the block back to disk */
40 
41  write(diskdev, dbuff, diskblock);
42  return OK;
43 }
#define ib2sect(ib)
Definition: lfilesys.h:86
int32 dbid32
データブロックID(ファイルシステムで使用する)
Definition: kernel.h:42
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
syscall read(did32, char *, uint32)
Definition: read.c:9
#define OK
処理が成功した場合
Definition: kernel.h:77
syscall write(did32, char *, uint32)
Definition: write.c:9
#define LF_BLKSIZ
Definition: lfilesys.h:48
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define ib2disp(ib)
Definition: lfilesys.h:91
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lflclose()

devcall lflclose ( struct dentry )

Definition at line 9 of file lflclose.c.

References dentry::dvminor, Lf_data, lfdata::lf_dirdirty, LF_FREE, LF_USED, lflcblk::lfdbdirty, lfflush(), lflcblk::lfibdirty, lfltab, lflcblk::lfmutex, lflcblk::lfstate, OK, signal(), SYSERR, and wait().

12 {
13  struct lflcblk *lfptr; /* Ptr to open file table entry */
14 
15  /* Obtain exclusive use of the file */
16 
17  lfptr = &lfltab[devptr->dvminor];
18  wait(lfptr->lfmutex);
19 
20  /* If file is not open, return an error */
21 
22  if (lfptr->lfstate != LF_USED) {
23  signal(lfptr->lfmutex);
24  return SYSERR;
25  }
26 
27  /* Write index or data blocks to disk if they have changed */
28 
29  if (Lf_data.lf_dirdirty || lfptr->lfdbdirty || lfptr->lfibdirty) {
30  lfflush(lfptr);
31  }
32 
33  /* Set device state to FREE and return to caller */
34 
35  lfptr->lfstate = LF_FREE;
36  signal(lfptr->lfmutex);
37  return OK;
38 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct lfdata Lf_data
Definition: lfsinit.c:5
#define LF_USED
Definition: lfilesys.h:53
struct lflcblk lfltab[]
Definition: lflinit.c:5
#define OK
処理が成功した場合
Definition: kernel.h:77
sid32 lfmutex
Definition: lfilesys.h:146
byte lfstate
Definition: lfilesys.h:144
bool8 lfdbdirty
Definition: lfilesys.h:166
bool8 lf_dirdirty
Definition: lfilesys.h:137
#define LF_FREE
Definition: lfilesys.h:52
bool8 lfibdirty
Definition: lfilesys.h:165
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
status lfflush(struct lflcblk *)
Definition: lfflush.c:10
Here is the call graph for this function:

◆ lflcontrol()

devcall lflcontrol ( struct dentry ,
int32  ,
int32  ,
int32   
)

Definition at line 9 of file lflcontrol.c.

References dentry::dvminor, kprintf(), LF_CTL_TRUNC, Lf_data, lfdata::lf_mutex, LF_USED, lfltab, lflcblk::lfmutex, lflcblk::lfstate, lftruncate(), signal(), SYSERR, and wait().

15 {
16  struct lflcblk *lfptr; /* Ptr to open file table entry */
17  int32 retval; /* Return value from func. call */
18 
19  /* Obtain exclusive use of the file */
20 
21  lfptr = &lfltab[devptr->dvminor];
22  wait(lfptr->lfmutex);
23 
24  /* If file is not open, return an error */
25 
26  if (lfptr->lfstate != LF_USED) {
27  signal(lfptr->lfmutex);
28  return SYSERR;
29  }
30 
31  switch (func) {
32 
33  /* Truncate a file */
34 
35  case LF_CTL_TRUNC:
37  retval = lftruncate(lfptr);
39  signal(lfptr->lfmutex);
40  return retval;
41 
42  default:
43  kprintf("lfcontrol: function %d not valid\n\r", func);
44  signal(lfptr->lfmutex);
45  return SYSERR;
46  }
47 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
sid32 lf_mutex
Definition: lfilesys.h:132
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct lfdata Lf_data
Definition: lfsinit.c:5
#define LF_USED
Definition: lfilesys.h:53
struct lflcblk lfltab[]
Definition: lflinit.c:5
sid32 lfmutex
Definition: lfilesys.h:146
#define LF_CTL_TRUNC
Definition: lfilesys.h:175
status lftruncate(struct lflcblk *)
Definition: lftruncate.c:10
byte lfstate
Definition: lfilesys.h:144
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
Here is the call graph for this function:

◆ lflgetc()

devcall lflgetc ( struct dentry )

Definition at line 9 of file lflgetc.c.

References dentry::dvminor, EOF, ldentry::ld_size, LF_BLKSIZ, LF_USED, lflcblk::lfbyte, lflcblk::lfdblock, lflcblk::lfdirptr, lfltab, lflcblk::lfmutex, lflcblk::lfpos, lfsetup(), lflcblk::lfstate, signal(), SYSERR, and wait().

Referenced by lflread().

12 {
13  struct lflcblk *lfptr; /* Ptr to open file table entry */
14  struct ldentry *ldptr; /* Ptr to file's entry in the */
15  /* in-memory directory */
16  int32 onebyte; /* Next data byte in the file */
17 
18  /* Obtain exclusive use of the file */
19 
20  lfptr = &lfltab[devptr->dvminor];
21  wait(lfptr->lfmutex);
22 
23  /* If file is not open, return an error */
24 
25  if (lfptr->lfstate != LF_USED) {
26  signal(lfptr->lfmutex);
27  return SYSERR;
28  }
29 
30  /* Return EOF for any attempt to read beyond the end-of-file */
31 
32  ldptr = lfptr->lfdirptr;
33  if (lfptr->lfpos >= ldptr->ld_size) {
34  signal(lfptr->lfmutex);
35  return EOF;
36  }
37 
38  /* If byte pointer is beyond the current data block, set up */
39  /* a new data block */
40 
41  if (lfptr->lfbyte >= &lfptr->lfdblock[LF_BLKSIZ]) {
42  lfsetup(lfptr);
43  }
44 
45  /* Extract the next byte from block, update file position, and */
46  /* return the byte to the caller */
47 
48  onebyte = 0xff & *lfptr->lfbyte++;
49  lfptr->lfpos++;
50  signal(lfptr->lfmutex);
51  return onebyte;
52 }
char * lfbyte
Definition: lfilesys.h:161
struct ldentry * lfdirptr
Definition: lfilesys.h:147
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define LF_USED
Definition: lfilesys.h:53
struct lflcblk lfltab[]
Definition: lflinit.c:5
#define EOF
ファイルの終端(End of File)に達した場合(読み込み処理に用いる)
Definition: kernel.h:81
sid32 lfmutex
Definition: lfilesys.h:146
status lfsetup(struct lflcblk *)
Definition: lfsetup.c:10
#define LF_BLKSIZ
Definition: lfilesys.h:48
byte lfstate
Definition: lfilesys.h:144
uint32 ld_size
Definition: lfilesys.h:98
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
uint32 lfpos
Definition: lfilesys.h:150
char lfdblock[LF_BLKSIZ]
Definition: lfilesys.h:159
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lflinit()

devcall lflinit ( struct dentry )

Definition at line 11 of file lflinit.c.

References dentry::dvminor, dentry::dvnum, FALSE, LF_BLKSIZ, LF_FREE, LF_INULL, LF_NAME_LEN, lflcblk::lfbyte, lflcblk::lfdbdirty, lflcblk::lfdblock, lflcblk::lfdev, lflcblk::lfdirptr, lflcblk::lfdnum, lflcblk::lfibdirty, lflcblk::lfiblock, lflcblk::lfinum, lfltab, lflcblk::lfmutex, lflcblk::lfname, lflcblk::lfpos, lflcblk::lfstate, memset(), NULL, NULLCH, OK, and semcreate().

14 {
15  struct lflcblk *lfptr; /* Ptr. to control block entry */
16  int32 i; /* Walks through name array */
17 
18  lfptr = &lfltab[ devptr->dvminor ];
19 
20  /* Initialize control block entry */
21 
22  lfptr->lfstate = LF_FREE; /* Device is currently unused */
23  lfptr->lfdev = devptr->dvnum; /* Set device ID */
24  lfptr->lfmutex = semcreate(1); /* Create the mutex semaphore */
25 
26  /* Initialize the directory and file position */
27 
28  lfptr->lfdirptr = (struct ldentry *) NULL;
29  lfptr->lfpos = 0;
30  for (i=0; i<LF_NAME_LEN; i++) {
31  lfptr->lfname[i] = NULLCH;
32  }
33 
34  /* Zero the in-memory index block and data block */
35 
36  lfptr->lfinum = LF_INULL;
37  memset((char *) &lfptr->lfiblock, NULLCH, sizeof(struct lfiblk));
38  lfptr->lfdnum = 0;
39  memset((char *) &lfptr->lfdblock, NULLCH, LF_BLKSIZ);
40 
41  /* Start with the byte beyond the current data block */
42 
43  lfptr->lfbyte = &lfptr->lfdblock[LF_BLKSIZ];
44  lfptr->lfibdirty = lfptr->lfdbdirty = FALSE;
45  return OK;
46 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
char * lfbyte
Definition: lfilesys.h:161
struct ldentry * lfdirptr
Definition: lfilesys.h:147
sid32 semcreate(int32)
未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。
Definition: semcreate.c:22
#define LF_NAME_LEN
Definition: lfilesys.h:49
#define OK
処理が成功した場合
Definition: kernel.h:77
sid32 lfmutex
Definition: lfilesys.h:146
struct lfiblk lfiblock
Definition: lfilesys.h:155
#define LF_INULL
Definition: lfilesys.h:55
char lfname[LF_NAME_LEN]
Definition: lfilesys.h:152
ibid32 lfinum
Definition: lfilesys.h:153
struct lflcblk lfltab[Nlfl]
Definition: lflinit.c:5
#define LF_BLKSIZ
Definition: lfilesys.h:48
#define FALSE
Boolean False(0)
Definition: kernel.h:63
byte lfstate
Definition: lfilesys.h:144
dbid32 lfdnum
Definition: lfilesys.h:157
bool8 lfdbdirty
Definition: lfilesys.h:166
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
#define LF_FREE
Definition: lfilesys.h:52
did32 lfdev
Definition: lfilesys.h:145
bool8 lfibdirty
Definition: lfilesys.h:165
uint32 lfpos
Definition: lfilesys.h:150
char lfdblock[LF_BLKSIZ]
Definition: lfilesys.h:159
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:

◆ lflputc()

devcall lflputc ( struct dentry ,
char   
)

Definition at line 9 of file lflputc.c.

References dentry::dvminor, ldentry::ld_size, LF_BLKSIZ, Lf_data, lfdata::lf_dirdirty, LF_USED, lflcblk::lfbyte, lflcblk::lfdbdirty, lflcblk::lfdblock, lflcblk::lfdirptr, lfltab, lflcblk::lfmutex, lflcblk::lfpos, lfsetup(), lflcblk::lfstate, OK, signal(), SYSERR, TRUE, and wait().

Referenced by lflwrite().

13 {
14  struct lflcblk *lfptr; /* Ptr to open file table entry */
15  struct ldentry *ldptr; /* Ptr to file's entry in the */
16  /* in-memory directory */
17 
18  /* Obtain exclusive use of the file */
19 
20  lfptr = &lfltab[devptr->dvminor];
21  wait(lfptr->lfmutex);
22 
23  /* If file is not open, return an error */
24 
25  if (lfptr->lfstate != LF_USED) {
26  signal(lfptr->lfmutex);
27  return SYSERR;
28  }
29 
30  /* Return SYSERR for an attempt to skip bytes beyond the byte */
31  /* that is currently the end of the file */
32 
33  ldptr = lfptr->lfdirptr;
34  if (lfptr->lfpos > ldptr->ld_size) {
35  signal(lfptr->lfmutex);
36  return SYSERR;
37  }
38 
39  /* If pointer is outside current block, set up new block */
40 
41  if (lfptr->lfbyte >= &lfptr->lfdblock[LF_BLKSIZ]) {
42 
43  /* Set up block for current file position */
44 
45  lfsetup(lfptr);
46  }
47 
48  /* If appending a byte to the file, increment the file size. */
49  /* Note: comparison might be equal, but should not be greater.*/
50 
51  if (lfptr->lfpos >= ldptr->ld_size) {
52  ldptr->ld_size++;
54  }
55 
56  /* Place byte in buffer and mark buffer "dirty" */
57 
58  *lfptr->lfbyte++ = ch;
59  lfptr->lfpos++;
60  lfptr->lfdbdirty = TRUE;
61 
62  signal(lfptr->lfmutex);
63  return OK;
64 }
char * lfbyte
Definition: lfilesys.h:161
struct ldentry * lfdirptr
Definition: lfilesys.h:147
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct lfdata Lf_data
Definition: lfsinit.c:5
#define LF_USED
Definition: lfilesys.h:53
struct lflcblk lfltab[]
Definition: lflinit.c:5
#define OK
処理が成功した場合
Definition: kernel.h:77
sid32 lfmutex
Definition: lfilesys.h:146
status lfsetup(struct lflcblk *)
Definition: lfsetup.c:10
#define LF_BLKSIZ
Definition: lfilesys.h:48
byte lfstate
Definition: lfilesys.h:144
#define TRUE
Boolean True(1)
Definition: kernel.h:65
uint32 ld_size
Definition: lfilesys.h:98
bool8 lfdbdirty
Definition: lfilesys.h:166
bool8 lf_dirdirty
Definition: lfilesys.h:137
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
uint32 lfpos
Definition: lfilesys.h:150
char lfdblock[LF_BLKSIZ]
Definition: lfilesys.h:159
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lflread()

devcall lflread ( struct dentry ,
char *  ,
int32   
)

Definition at line 9 of file lflread.c.

References EOF, lflgetc(), and SYSERR.

14 {
15  uint32 numread; /* Number of bytes read */
16  int32 nxtbyte; /* Character or SYSERR/EOF */
17 
18  if (count < 0) {
19  return SYSERR;
20  }
21 
22  /* Iterate and use lflgetc to read individual bytes */
23 
24  for (numread=0 ; numread < count ; numread++) {
25  nxtbyte = lflgetc(devptr);
26  if (nxtbyte == SYSERR) {
27  return SYSERR;
28  } else if (nxtbyte == EOF) { /* EOF before finished */
29  if (numread == 0) {
30  return EOF;
31  } else {
32  return numread;
33  }
34  } else {
35  *buff++ = (char) (0xff & nxtbyte);
36  }
37  }
38  return numread;
39 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define EOF
ファイルの終端(End of File)に達した場合(読み込み処理に用いる)
Definition: kernel.h:81
devcall lflgetc(struct dentry *)
Definition: lflgetc.c:9
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
Here is the call graph for this function:

◆ lflseek()

devcall lflseek ( struct dentry ,
uint32   
)

Definition at line 9 of file lflseek.c.

References dentry::dvminor, ldentry::ld_size, LF_BLKSIZ, LF_USED, lflcblk::lfbyte, lflcblk::lfdblock, lflcblk::lfdirptr, lfltab, lflcblk::lfmutex, lflcblk::lfpos, lflcblk::lfstate, OK, signal(), SYSERR, and wait().

13 {
14  struct lflcblk *lfptr; /* Ptr to open file table entry */
15 
16  /* If file is not open, return an error */
17 
18  lfptr = &lfltab[devptr->dvminor];
19  wait(lfptr->lfmutex);
20  if (lfptr->lfstate != LF_USED) {
21  signal(lfptr->lfmutex);
22  return SYSERR;
23  }
24 
25  /* Verify offset is within current file size */
26 
27  if (offset > lfptr->lfdirptr->ld_size) {
28  signal(lfptr->lfmutex);
29  return SYSERR;
30  }
31 
32  /* Record new offset and invalidate byte pointer (i.e., force */
33  /* the index and data blocks to be replaced if a successive */
34  /* call is made to read or write) */
35 
36  lfptr->lfpos = offset;
37  lfptr->lfbyte = &lfptr->lfdblock[LF_BLKSIZ];
38 
39  signal(lfptr->lfmutex);
40  return OK;
41 }
char * lfbyte
Definition: lfilesys.h:161
struct ldentry * lfdirptr
Definition: lfilesys.h:147
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define LF_USED
Definition: lfilesys.h:53
struct lflcblk lfltab[]
Definition: lflinit.c:5
#define OK
処理が成功した場合
Definition: kernel.h:77
sid32 lfmutex
Definition: lfilesys.h:146
#define LF_BLKSIZ
Definition: lfilesys.h:48
byte lfstate
Definition: lfilesys.h:144
uint32 ld_size
Definition: lfilesys.h:98
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
uint32 lfpos
Definition: lfilesys.h:150
char lfdblock[LF_BLKSIZ]
Definition: lfilesys.h:159
Here is the call graph for this function:

◆ lflwrite()

devcall lflwrite ( struct dentry ,
char *  ,
int32   
)

Definition at line 9 of file lflwrite.c.

References lflputc(), and SYSERR.

14 {
15  int32 i; /* Number of bytes written */
16 
17  if (count < 0) {
18  return SYSERR;
19  }
20 
21  /* Iteratate and write one byte at a time */
22 
23  for (i=0; i<count; i++) {
24  if (lflputc(devptr, *buff++) == SYSERR) {
25  return SYSERR;
26  }
27  }
28  return count;
29 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
devcall lflputc(struct dentry *, char)
Definition: lflputc.c:9
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
Here is the call graph for this function:

◆ lfscheck()

status lfscheck ( struct lfdir )

Definition at line 10 of file lfscheck.c.

References lfdir::lfd_allones, lfdir::lfd_allzeros, lfdir::lfd_fsysid, lfdir::lfd_nfiles, lfdir::lfd_revid, LFS_ID, OK, and SYSERR.

Referenced by lfsckfmt(), lfsopen(), and xsh_ls().

13 {
14  uint32 reverse; /* LFS_ID in reverse byte order */
15 
16  /* Verify the File System ID, all 0's and all 1's fields */
17 
18  if ( (dirptr->lfd_fsysid != LFS_ID) ||
19  (dirptr->lfd_allzeros != 0x00000000) ||
20  (dirptr->lfd_allones != 0xffffffff) ) {
21  return SYSERR;
22  }
23 
24  /* Check the reverse-order File System ID field */
25 
26  reverse = ((LFS_ID>>24) & 0x000000ff) |
27  ((LFS_ID>> 8) & 0x0000ff00) |
28  ((LFS_ID<< 8) & 0x00ff0000) |
29  ((LFS_ID<<24) & 0xff000000) ;
30 
31  if (dirptr->lfd_revid != reverse) {
32  return SYSERR;
33  }
34 
35  /* Extra sanity check - verify file count is positive */
36  if (dirptr->lfd_nfiles < 0){
37  return SYSERR;
38  }
39  return OK;
40 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
#define LFS_ID
Definition: lfilesys.h:80
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
Here is the caller graph for this function:

◆ lfscreate()

status lfscreate ( did32  ,
ibid32  ,
uint32   
)

Definition at line 10 of file lfscreate.c.

References close(), lfiblk::ib_next, LF_AREA_DIR, LF_BLKSIZ, LF_DNULL, LF_INULL, lfibclear(), lfibput(), LFS_ID, memset(), NULLCH, OK, SYSERR, and write().

15 {
16  uint32 sectors; /* Number of sectors to use */
17  uint32 ibsectors; /* Number of sectors of i-blocks*/
18  uint32 ibpersector; /* Number of i-blocks per sector*/
19  struct lfdir dir; /* Buffer to hold the directory */
20  uint32 dblks; /* Total free data blocks */
21  struct lfiblk iblock; /* Space for one i-block */
22  struct lfdbfree dblock; /* Data block on the free list */
23  dbid32 dbindex; /* Index for data blocks */
24  int32 retval; /* Return value from func call */
25  int32 i; /* Loop index */
26 
27  /* Compute total sectors on disk */
28 
29  sectors = dsiz / LF_BLKSIZ; /* Truncate to full sector */
30 
31  /* Compute number of sectors comprising i-blocks */
32 
33  ibpersector = LF_BLKSIZ / sizeof(struct lfiblk);
34  ibsectors = (lfiblks+(ibpersector-1)) / ibpersector;/* Round up */
35  lfiblks = ibsectors * ibpersector;
36  if (ibsectors > sectors/2) { /* Invalid arguments */
37  return SYSERR;
38  }
39 
40  /* Create an initial directory */
41 
42  memset((char *)&dir, NULLCH, sizeof(struct lfdir));
43  dir.lfd_fsysid = LFS_ID;
44  dir.lfd_nfiles = 0;
45  dir.lfd_allzeros = 0;
46  dir.lfd_allones = 0xffffffff;
47  dir.lfd_revid = ((LFS_ID>>24) & 0x000000ff) |
48  ((LFS_ID>> 8) & 0x0000ff00) |
49  ((LFS_ID<< 8) & 0x00ff0000) |
50  ((LFS_ID<<24) & 0xff000000) ;
51  dbindex= (dbid32)(ibsectors + 1);
52  dir.lfd_dfree = dbindex;
53  dblks = sectors - ibsectors - 1;
54  retval = write(disk,(char *)&dir, LF_AREA_DIR);
55  if (retval == SYSERR) {
56  return SYSERR;
57  }
58 
59  /* Create list of free i-blocks on disk */
60 
61  lfibclear(&iblock, 0);
62  for (i=0; i<lfiblks-1; i++) {
63  iblock.ib_next = (ibid32)(i + 1);
64  lfibput(disk, i, &iblock);
65  }
66  iblock.ib_next = LF_INULL;
67  lfibput(disk, i, &iblock);
68 
69  /* Create list of free data blocks on disk */
70 
71  memset((char*)&dblock, NULLCH, LF_BLKSIZ);
72  for (i=0; i<dblks-1; i++) {
73  dblock.lf_nextdb = dbindex + 1;
74  write(disk, (char *)&dblock, dbindex);
75  dbindex++;
76  }
77  dblock.lf_nextdb = LF_DNULL;
78  write(disk, (char *)&dblock, dbindex);
79  close(disk);
80  return OK;
81 }
int32 dbid32
データブロックID(ファイルシステムで使用する)
Definition: kernel.h:42
int32 ibid32
ブロックIDのインデックス(ファイルシステムで使用する)
Definition: kernel.h:40
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
syscall close(did32)
Definition: close.c:9
void lfibclear(struct lfiblk *, int32)
Definition: lfibclear.c:9
#define OK
処理が成功した場合
Definition: kernel.h:77
#define LF_INULL
Definition: lfilesys.h:55
#define LF_AREA_DIR
Definition: lfilesys.h:67
syscall write(did32, char *, uint32)
Definition: write.c:9
#define LF_BLKSIZ
Definition: lfilesys.h:48
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define LF_DNULL
Definition: lfilesys.h:56
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
#define LFS_ID
Definition: lfilesys.h:80
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
status lfibput(did32, ibid32, struct lfiblk *)
Definition: lfibput.c:10
Here is the call graph for this function:

◆ lfsetup()

status lfsetup ( struct lflcblk )

Definition at line 10 of file lfsetup.c.

References FALSE, lfiblk::ib_dba, lfiblk::ib_next, lfiblk::ib_offset, ldentry::ld_ilist, Lf_data, LF_DMASK, LF_DNULL, lfdata::lf_dskdev, LF_IDATA, LF_IMASK, LF_INULL, lfdata::lf_mutex, lflcblk::lfbyte, lfdballoc(), lflcblk::lfdbdirty, lflcblk::lfdblock, lflcblk::lfdirptr, lflcblk::lfdnum, lfflush(), lfiballoc(), lfibclear(), lflcblk::lfibdirty, lfibget(), lflcblk::lfiblock, lfibput(), lflcblk::lfinum, lflcblk::lfpos, OK, read(), signal(), TRUE, and wait().

Referenced by lflgetc(), and lflputc().

13 {
14  dbid32 dnum; /* Data block to fetch */
15  ibid32 ibnum; /* I-block number during search */
16  struct ldentry *ldptr; /* Ptr to file entry in dir. */
17  struct lfiblk *ibptr; /* Ptr to in-memory index block */
18  uint32 newoffset; /* Computed data offset for */
19  /* next index block */
20  int32 dindex; /* Index into array in an index */
21  /* block */
22 
23 
24  /* Obtain exclusive access to the directory */
25 
27 
28  /* Get pointers to in-memory directory, file's entry in the */
29  /* directory, and the in-memory index block */
30 
31  ldptr = lfptr->lfdirptr;
32  ibptr = &lfptr->lfiblock;
33 
34  /* If existing index block or data block changed, write to disk */
35 
36  if (lfptr->lfibdirty || lfptr->lfdbdirty) {
37  lfflush(lfptr);
38  }
39  ibnum = lfptr->lfinum; /* Get ID of curr. index block */
40 
41  /* If there is no index block in memory (e.g., because the file */
42  /* was just opened), either load the first index block of */
43  /* the file or allocate a new first index block */
44 
45  if (ibnum == LF_INULL) {
46 
47  /* Check directory entry to see if index block exists */
48 
49  ibnum = ldptr->ld_ilist;
50  if (ibnum == LF_INULL) { /* Empty file - get new i-block*/
51  ibnum = lfiballoc();
52  lfibclear(ibptr, 0);
53  ldptr->ld_ilist = ibnum;
54  lfptr->lfibdirty = TRUE;
55  } else { /* Nonempty - read first i-block*/
56  lfibget(Lf_data.lf_dskdev, ibnum, ibptr);
57  }
58  lfptr->lfinum = ibnum;
59 
60  /* Otherwise, if current file position has been moved to an */
61  /* offset before the current index block, start at the */
62  /* beginning of the index list for the file */
63 
64  } else if (lfptr->lfpos < ibptr->ib_offset) {
65 
66  /* Load initial index block for the file (we know that */
67  /* at least one index block exists) */
68 
69  ibnum = ldptr->ld_ilist;
70  lfibget(Lf_data.lf_dskdev, ibnum, ibptr);
71  lfptr->lfinum = ibnum;
72  }
73 
74  /* At this point, an index block is in memory, but may cover */
75  /* an offset less than the current file position. Loop until */
76  /* the index block covers the current file position. */
77 
78  while ((lfptr->lfpos & ~LF_IMASK) > ibptr->ib_offset ) {
79  ibnum = ibptr->ib_next;
80  if (ibnum == LF_INULL) {
81  /* Allocate new index block to extend file */
82  ibnum = lfiballoc();
83  ibptr->ib_next = ibnum;
84  lfibput(Lf_data.lf_dskdev, lfptr->lfinum, ibptr);
85  lfptr->lfinum = ibnum;
86  newoffset = ibptr->ib_offset + LF_IDATA;
87  lfibclear(ibptr, newoffset);
88  lfptr->lfibdirty = TRUE;
89  } else {
90  lfibget(Lf_data.lf_dskdev, ibnum, ibptr);
91  lfptr->lfinum = ibnum;
92  }
93  lfptr->lfdnum = LF_DNULL; /* Invalidate old data block */
94  }
95 
96  /* At this point, the index block in lfiblock covers the */
97  /* current file position (i.e., position lfptr->lfpos). The */
98  /* next step consists of loading the correct data block. */
99 
100  dindex = (lfptr->lfpos & LF_IMASK) >> 9;
101 
102  /* If data block index does not match current data block, read */
103  /* the correct data block from disk */
104 
105  dnum = lfptr->lfiblock.ib_dba[dindex];
106  if (dnum == LF_DNULL) { /* Allocate new data block */
107  dnum = lfdballoc((struct lfdbfree *)&lfptr->lfdblock);
108  lfptr->lfiblock.ib_dba[dindex] = dnum;
109  lfptr->lfibdirty = TRUE;
110  } else if ( dnum != lfptr->lfdnum) {
111  read(Lf_data.lf_dskdev, (char *)lfptr->lfdblock, dnum);
112  lfptr->lfdbdirty = FALSE;
113  }
114  lfptr->lfdnum = dnum;
115 
116  /* Use current file offset to set the pointer to the next byte */
117  /* within the data block */
118 
119  lfptr->lfbyte = &lfptr->lfdblock[lfptr->lfpos & LF_DMASK];
121  return OK;
122 }
int32 dbid32
データブロックID(ファイルシステムで使用する)
Definition: kernel.h:42
dbid32 lfdballoc(struct lfdbfree *)
Definition: lfdballoc.c:19
int32 ibid32
ブロックIDのインデックス(ファイルシステムで使用する)
Definition: kernel.h:40
ibid32 ld_ilist
Definition: lfilesys.h:99
sid32 lf_mutex
Definition: lfilesys.h:132
struct lfdata Lf_data
Definition: lfsinit.c:5
syscall read(did32, char *, uint32)
Definition: read.c:9
did32 lf_dskdev
Definition: lfilesys.h:131
void lfibclear(struct lfiblk *, int32)
Definition: lfibclear.c:9
#define OK
処理が成功した場合
Definition: kernel.h:77
void lfibget(did32, ibid32, struct lfiblk *)
Definition: lfibget.c:10
#define LF_INULL
Definition: lfilesys.h:55
#define LF_IMASK
Definition: lfilesys.h:60
#define FALSE
Boolean False(0)
Definition: kernel.h:63
#define LF_IDATA
Definition: lfilesys.h:58
#define TRUE
Boolean True(1)
Definition: kernel.h:65
ibid32 ib_next
Definition: lfilesys.h:72
#define LF_DMASK
Definition: lfilesys.h:63
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define LF_DNULL
Definition: lfilesys.h:56
uint32 ib_offset
Definition: lfilesys.h:73
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
status lfflush(struct lflcblk *)
Definition: lfflush.c:10
ibid32 lfiballoc(void)
Definition: lfiballoc.c:10
status lfibput(did32, ibid32, struct lfiblk *)
Definition: lfibput.c:10
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lfsinit()

devcall lfsinit ( struct dentry )

Definition at line 11 of file lfsinit.c.

References FALSE, Lf_data, lfdata::lf_dir, lfdata::lf_dirdirty, lfdata::lf_dirpresent, LF_DISK_DEV, lfdata::lf_dskdev, lfdata::lf_mutex, memset(), NULLCH, OK, and semcreate().

14 {
15  /* Assign ID of disk device that will be used */
16 
18 
19  /* Create a mutual exclusion semaphore */
20 
22 
23  /* Zero directory area (for debugging) */
24 
25  memset((char *)&Lf_data.lf_dir, NULLCH, sizeof(struct lfdir));
26 
27  /* Initialize directory to "not present" in memory */
28 
30 
31  return OK;
32 }
sid32 semcreate(int32)
未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。
Definition: semcreate.c:22
sid32 lf_mutex
Definition: lfilesys.h:132
did32 lf_dskdev
Definition: lfilesys.h:131
#define OK
処理が成功した場合
Definition: kernel.h:77
#define LF_DISK_DEV
Definition: conf.h:86
bool8 lf_dirpresent
Definition: lfilesys.h:135
struct lfdir lf_dir
Definition: lfilesys.h:134
#define FALSE
Boolean False(0)
Definition: kernel.h:63
bool8 lf_dirdirty
Definition: lfilesys.h:137
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
struct lfdata Lf_data
Definition: lfsinit.c:5
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:

◆ lfsopen()

devcall lfsopen ( struct dentry ,
char *  ,
char *   
)

Definition at line 9 of file lfsopen.c.

References FALSE, kprintf(), ldentry::ld_ilist, ldentry::ld_name, ldentry::ld_size, LF_AREA_DIR, LF_BLKSIZ, Lf_data, lfdata::lf_dir, lfdata::lf_dirpresent, LF_DNULL, lfdata::lf_dskdev, LF_FREE, LF_INULL, LF_MODE_N, LF_MODE_O, LF_MODE_RW, lfdata::lf_mutex, LF_NAME_LEN, LF_NUM_DIR_ENT, LF_USED, lflcblk::lfbyte, lfdir::lfd_files, lfdir::lfd_nfiles, lflcblk::lfdbdirty, lflcblk::lfdblock, lflcblk::lfdev, lflcblk::lfdirptr, lflcblk::lfdnum, lfgetmode(), lflcblk::lfibdirty, lflcblk::lfinum, lfltab, lflcblk::lfmode, lflcblk::lfname, lflcblk::lfpos, lfscheck(), lflcblk::lfstate, Nlfl, NULLCH, read(), signal(), SYSERR, TRUE, and wait().

14 {
15  struct lfdir *dirptr; /* Ptr to in-memory directory */
16  char *from, *to; /* Ptrs used during copy */
17  char *nam, *cmp; /* Ptrs used during comparison */
18  int32 i; /* General loop index */
19  did32 lfnext; /* Minor number of an unused */
20  /* file pseudo-device */
21  struct ldentry *ldptr; /* Ptr to an entry in directory */
22  struct lflcblk *lfptr; /* Ptr to open file table entry */
23  bool8 found; /* Was the name found? */
24  int32 retval; /* Value returned from function */
25  int32 mbits; /* Mode bits */
26 
27  /* Check length of name file (leaving space for NULLCH */
28 
29  from = name;
30  for (i=0; i< LF_NAME_LEN; i++) {
31  if (*from++ == NULLCH) {
32  break;
33  }
34  }
35  if (i >= LF_NAME_LEN) { /* Name is too long */
36  return SYSERR;
37  }
38 
39  /* Parse mode argument and convert to binary */
40 
41  mbits = lfgetmode(mode);
42  if (mbits == SYSERR) {
43  return SYSERR;
44  }
45 
46  /* If named file is already open, return SYSERR */
47 
48  lfnext = SYSERR;
49  for (i=0; i<Nlfl; i++) { /* Search file pseudo-devices */
50  lfptr = &lfltab[i];
51  if (lfptr->lfstate == LF_FREE) {
52  if (lfnext == SYSERR) {
53  lfnext = i; /* Record index */
54  }
55  continue;
56  }
57 
58  /* Compare requested name to name of open file */
59 
60  nam = name;
61  cmp = lfptr->lfname;
62  while(*nam != NULLCH) {
63  if (*nam != *cmp) {
64  break;
65  }
66  nam++;
67  cmp++;
68  }
69 
70  /* See if comparison succeeded */
71 
72  if ( (*nam==NULLCH) && (*cmp == NULLCH) ) {
73  return SYSERR;
74  }
75  }
76  if (lfnext == SYSERR) { /* No slave file devices are available */
77  return SYSERR;
78  }
79 
80  /* Obtain copy of directory if not already present in memory */
81 
82  dirptr = &Lf_data.lf_dir;
84  if (! Lf_data.lf_dirpresent) {
85  retval = read(Lf_data.lf_dskdev,(char *)dirptr,LF_AREA_DIR);
86  if (retval == SYSERR ) {
88  return SYSERR;
89  }
90  if (lfscheck(dirptr) == SYSERR ) {
91  kprintf("Disk does not contain a Xinu file system\n");
93  return SYSERR;
94  }
96  }
97 
98  /* Search directory to see if file exists */
99 
100  found = FALSE;
101  for (i=0; i<dirptr->lfd_nfiles; i++) {
102  ldptr = &dirptr->lfd_files[i];
103  nam = name;
104  cmp = ldptr->ld_name;
105  while(*nam != NULLCH) {
106  if (*nam != *cmp) {
107  break;
108  }
109  nam++;
110  cmp++;
111  }
112  if ( (*nam==NULLCH) && (*cmp==NULLCH) ) { /* Name found */
113  found = TRUE;
114  break;
115  }
116  }
117 
118  /* Case #1 - file is not in directory (i.e., does not exist) */
119 
120  if (! found) {
121  if (mbits & LF_MODE_O) { /* File *must* exist */
123  return SYSERR;
124  }
125 
126  /* Take steps to create new file and add to directory */
127 
128  /* Verify that space remains in the directory */
129 
130  if (dirptr->lfd_nfiles >= LF_NUM_DIR_ENT) {
132  return SYSERR;
133  }
134 
135  /* Allocate next dir. entry & initialize to empty file */
136 
137  ldptr = &dirptr->lfd_files[dirptr->lfd_nfiles++];
138  ldptr->ld_size = 0;
139  from = name;
140  to = ldptr->ld_name;
141  while ( (*to++ = *from++) != NULLCH ) {
142  ;
143  }
144  ldptr->ld_ilist = LF_INULL;
145 
146  /* Case #2 - file is in directory (i.e., already exists) */
147 
148  } else if (mbits & LF_MODE_N) { /* File must not exist */
150  return SYSERR;
151  }
152 
153  /* Initialize the local file pseudo-device */
154 
155  lfptr = &lfltab[lfnext];
156  lfptr->lfstate = LF_USED;
157  lfptr->lfdirptr = ldptr; /* Point to directory entry */
158  lfptr->lfmode = mbits & LF_MODE_RW;
159 
160  /* File starts at position 0 */
161 
162  lfptr->lfpos = 0;
163 
164  to = lfptr->lfname;
165  from = name;
166  while ( (*to++ = *from++) != NULLCH ) {
167  ;
168  }
169 
170  /* Neither index block nor data block are initially valid */
171 
172  lfptr->lfinum = LF_INULL;
173  lfptr->lfdnum = LF_DNULL;
174 
175  /* Initialize byte pointer to address beyond the end of the */
176  /* buffer (i.e., invalid pointer triggers setup) */
177 
178  lfptr->lfbyte = &lfptr->lfdblock[LF_BLKSIZ];
179  lfptr->lfibdirty = FALSE;
180  lfptr->lfdbdirty = FALSE;
181 
183 
184  return lfptr->lfdev;
185 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
struct ldentry lfd_files[LF_NUM_DIR_ENT]
Definition: lfilesys.h:123
char * lfbyte
Definition: lfilesys.h:161
struct ldentry * lfdirptr
Definition: lfilesys.h:147
#define Nlfl
Definition: conf.h:70
ibid32 ld_ilist
Definition: lfilesys.h:99
sid32 lf_mutex
Definition: lfilesys.h:132
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct lfdata Lf_data
Definition: lfsinit.c:5
#define LF_USED
Definition: lfilesys.h:53
syscall read(did32, char *, uint32)
Definition: read.c:9
did32 lf_dskdev
Definition: lfilesys.h:131
struct lflcblk lfltab[]
Definition: lflinit.c:5
#define LF_NAME_LEN
Definition: lfilesys.h:49
byte bool8
Boolean値
Definition: kernel.h:36
#define LF_MODE_O
Definition: lfilesys.h:45
bool8 lf_dirpresent
Definition: lfilesys.h:135
#define LF_INULL
Definition: lfilesys.h:55
#define LF_AREA_DIR
Definition: lfilesys.h:67
char lfname[LF_NAME_LEN]
Definition: lfilesys.h:152
ibid32 lfinum
Definition: lfilesys.h:153
#define LF_BLKSIZ
Definition: lfilesys.h:48
struct lfdir lf_dir
Definition: lfilesys.h:134
char ld_name[LF_NAME_LEN]
Definition: lfilesys.h:101
#define LF_MODE_N
Definition: lfilesys.h:46
#define FALSE
Boolean False(0)
Definition: kernel.h:63
byte lfstate
Definition: lfilesys.h:144
#define TRUE
Boolean True(1)
Definition: kernel.h:65
dbid32 lfdnum
Definition: lfilesys.h:157
uint32 ld_size
Definition: lfilesys.h:98
bool8 lfdbdirty
Definition: lfilesys.h:166
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define LF_DNULL
Definition: lfilesys.h:56
int32 lfd_nfiles
Definition: lfilesys.h:122
int32 did32
デバイスID
Definition: kernel.h:28
#define LF_FREE
Definition: lfilesys.h:52
did32 lfdev
Definition: lfilesys.h:145
int32 lfmode
Definition: lfilesys.h:149
bool8 lfibdirty
Definition: lfilesys.h:165
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
uint32 lfpos
Definition: lfilesys.h:150
char lfdblock[LF_BLKSIZ]
Definition: lfilesys.h:159
status lfscheck(struct lfdir *)
Definition: lfscheck.c:10
int32 lfgetmode(char *)
Definition: lfgetmode.c:9
#define LF_MODE_RW
Definition: lfilesys.h:44
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
#define LF_NUM_DIR_ENT
Definition: lfilesys.h:50
Here is the call graph for this function:

◆ lftruncate()

status lftruncate ( struct lflcblk )

Definition at line 10 of file lftruncate.c.

References lfiblk::ib_dba, lfiblk::ib_next, lfiblk::ib_offset, ldentry::ld_ilist, ldentry::ld_size, LF_BLKSIZ, Lf_data, lfdata::lf_dir, lfdata::lf_dirdirty, LF_DNULL, lfdata::lf_dskdev, LF_IBLEN, LF_INULL, lflcblk::lfbyte, lfdir::lfd_ifree, lflcblk::lfdbdirty, lfdbfree(), lflcblk::lfdblock, lflcblk::lfdirptr, lflcblk::lfdnum, lfflush(), lflcblk::lfibdirty, lfibget(), lfibput(), lflcblk::lfinum, lflcblk::lfpos, OK, and TRUE.

Referenced by lflcontrol().

13 {
14  struct ldentry *ldptr; /* Pointer to file's dir. entry */
15  struct lfiblk iblock; /* Buffer for one index block */
16  ibid32 ifree; /* Start of index blk free list */
17  ibid32 firstib; /* First index blk of the file */
18  ibid32 nextib; /* Walks down list of the */
19  /* file's index blocks */
20  dbid32 nextdb; /* Next data block to free */
21  int32 i; /* Moves through data blocks in */
22  /* a given index block */
23 
24  ldptr = lfptr->lfdirptr; /* Get pointer to dir. entry */
25  if (ldptr->ld_size == 0) { /* File is already empty */
26  return OK;
27  }
28 
29  /* Clean up the open local file first */
30 
31  if ( (lfptr->lfibdirty) || (lfptr->lfdbdirty) ) {
32  lfflush(lfptr);
33  }
34  lfptr->lfpos = 0;
35  lfptr->lfinum = LF_INULL;
36  lfptr->lfdnum = LF_DNULL;
37  lfptr->lfbyte = &lfptr->lfdblock[LF_BLKSIZ];
38 
39  /* Obtain ID of first index block on free list */
40 
41  ifree = Lf_data.lf_dir.lfd_ifree;
42 
43  /* Record file's first i-block and clear directory entry */
44 
45  firstib = ldptr->ld_ilist;
46  ldptr->ld_ilist = LF_INULL;
47  ldptr->ld_size = 0;
49 
50  /* Walk along index block list, disposing of each data block */
51  /* and clearing the corresponding pointer. A note on loop */
52  /* termination: last pointer is set to ifree below. */
53 
54  for (nextib=firstib; nextib!=ifree; nextib=iblock.ib_next) {
55 
56  /* Obtain a copy of current index block from disk */
57 
58  lfibget(Lf_data.lf_dskdev, nextib, &iblock);
59 
60  /* Free each data block in the index block */
61 
62  for (i=0; i<LF_IBLEN; i++) { /* For each d-block */
63 
64  /* Free the data block */
65 
66  nextdb = iblock.ib_dba[i];
67  if (nextdb != LF_DNULL) {
68  lfdbfree(Lf_data.lf_dskdev, nextdb);
69  }
70 
71  /* Clear entry in i-block for this d-block */
72 
73  iblock.ib_dba[i] = LF_DNULL;
74  }
75 
76  /* Clear offset (just to make debugging easier) */
77 
78  iblock.ib_offset = 0;
79 
80  /* For the last index block on the list, make it point */
81  /* to the current free list */
82 
83  if (iblock.ib_next == LF_INULL) {
84  iblock.ib_next = ifree;
85  }
86 
87  /* Write cleared i-block back to disk */
88 
89  lfibput(Lf_data.lf_dskdev, nextib, &iblock);
90  }
91 
92  /* Last index block on the file list now points to first node */
93  /* on the current free list. Once we make the free list */
94  /* point to the first index block on the file list, the */
95  /* entire set of index blocks will be on the free list */
96 
97  Lf_data.lf_dir.lfd_ifree = firstib;
98 
99  /* Indicate that directory has changed and return */
100 
102 
103  return OK;
104 }
int32 dbid32
データブロックID(ファイルシステムで使用する)
Definition: kernel.h:42
int32 ibid32
ブロックIDのインデックス(ファイルシステムで使用する)
Definition: kernel.h:40
ibid32 ld_ilist
Definition: lfilesys.h:99
struct lfdata Lf_data
Definition: lfsinit.c:5
ibid32 lfd_ifree
Definition: lfilesys.h:121
did32 lf_dskdev
Definition: lfilesys.h:131
#define OK
処理が成功した場合
Definition: kernel.h:77
#define LF_IBLEN
Definition: lfilesys.h:57
void lfibget(did32, ibid32, struct lfiblk *)
Definition: lfibget.c:10
#define LF_INULL
Definition: lfilesys.h:55
status lfdbfree(did32, dbid32)
Definition: lfdbfree.c:10
#define LF_BLKSIZ
Definition: lfilesys.h:48
struct lfdir lf_dir
Definition: lfilesys.h:134
#define TRUE
Boolean True(1)
Definition: kernel.h:65
uint32 ld_size
Definition: lfilesys.h:98
bool8 lf_dirdirty
Definition: lfilesys.h:137
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define LF_DNULL
Definition: lfilesys.h:56
status lfflush(struct lflcblk *)
Definition: lfflush.c:10
status lfibput(did32, ibid32, struct lfiblk *)
Definition: lfibput.c:10
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lpgetc()

devcall lpgetc ( struct dentry )

◆ lpinit()

devcall lpinit ( struct dentry )

◆ lpopen()

devcall lpopen ( struct dentry ,
char *  ,
char *   
)

◆ lpputc()

devcall lpputc ( struct dentry ,
char   
)

◆ lpread()

devcall lpread ( struct dentry ,
char *  ,
int32   
)

◆ lpwrite()

devcall lpwrite ( struct dentry ,
char *  ,
int32   
)

◆ memcmp()

int32* memcmp ( void *  ,
const void *  ,
int32   
)

◆ memcpy()

void* memcpy ( void *  s,
const void *  ct,
int  n 
)

メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。

Parameters
[in,out]sコピー先のアドレス(Destination address)
[in]ctコピー元のアドレス(Source address)
[in]nコピーサイズ(Byte)
Returns
コピー完了後のコピー先アドレス

Definition at line 13 of file memcpy.c.

Referenced by addargs(), arp_in(), arp_resolve(), dhcp_bld_bootp_msg(), dhcp_bld_req(), dns_bldq(), dns_geta(), dns_getrname(), ethcontrol(), ethread(), ethwrite(), getlocalip(), icmp_mkpkt(), ip_send(), ipout(), raminit(), ramread(), ramwrite(), rdsread(), rdswrite(), udp_send(), and udp_sendto().

14 {
15  register int i;
16  char *dst = (char *)s;
17  char *src = (char *)ct;
18 
19  for (i = 0; i < n; i++)
20  {
21  *dst++ = *src++;
22  }
23  return s;
24 }
Here is the caller graph for this function:

◆ memset()

void* memset ( void *  s,
int  c,
int  n 
)

指定のByteブロックに対して、同じ値をNバイト分書き込む。

Parameters
[in,out]sByteブロックへのポインタ(例:文字列)
[in]c書き込む値(1Byte)
[in]n書き込むサイズ(Byte)
Returns
書き込み完了後のByteブロックへのポインタ

Definition at line 13 of file memset.c.

Referenced by arp_alloc(), arp_resolve(), dhcp_bld_bootp_msg(), dnslookup(), ethinit(), ethwrite(), getutime(), if(), lfdballoc(), lflinit(), lfscreate(), lfsinit(), net_init(), rdscontrol(), rdsopen(), rdsprocess(), rflread(), rflwrite(), rfscontrol(), rfsopen(), tftpget_mb(), and xsh_rdstest().

14 {
15  register int i;
16  char *cp = (char *)s;
17 
18  for (i = 0; i < n; i++)
19  {
20  *cp = (unsigned char)c;
21  cp++;
22  }
23  return s;
24 }
Here is the caller graph for this function:

◆ mkbufpool()

bpid32 mkbufpool ( int32  bufsiz,
int32  numbufs 
)

バッファプール用のメモリを割り当て、バッファ同士をリンクする。

Step1. 割り込みを禁止する。
Step2. 以下のいずれかの場合は、割り込み状態を復元し、処理を終了する。
 ・バッファサイズがバッファ最小値を下回る場合
 ・バッファサイズがバッファ最大値を超えた場合
 ・バッファ数が0以下の場合
 ・バッファ数がバッファ最大数を超えた場合
 ・割り当て済みのバッファプール数が最大数を超えた場合
Step3. 要求されたバッファサイズを4の倍数で丸める。
Step4. 要求されたバッファサイズ + バッファプールID分のメモリをバッファ数分、割り当てる。
メモリ確保に失敗した場合は割り込み状態を復元し、処理を終了する。 Step5. 新しいバッファプールIDを割り当て、バッファプールの総数を1増加させる。
Step6. 割り当てたバッファとバッファプールをリンクする。
Step7. 割り当てたバッファにセマフォを割り当てる。
セマフォ割り当てに失敗した場合は割り当てたバッファを解放し、バッファプール総数を元に戻し、
割り込み状態を復元し、処理を終了する。
Step8. 割り当てたバッファ同士をリンクする。
Step9. 割り込み状態を復元する。

Parameters
[in]bufsizバッファプール中のバッファサイズ
[in]numbufsバッファプール中のバッファ数
Returns
バッファプールを割り当てた場合はバッファプールIDを返し、以下の場合はSYSERRを返す。
 ・バッファサイズがバッファ最小値を下回る場合
 ・バッファサイズがバッファ最大値を超えた場合
 ・バッファ数が0以下の場合
 ・バッファ数がバッファ最大数を超えた場合
 ・割り当て済みのバッファプール数が最大数を超えた場合
 ・バッファを確保できなかった場合
 ・セマフォを作成できなかった場合

Definition at line 38 of file mkbufpool.c.

References BP_MAXB, BP_MAXN, bpentry::bpnext, bpentry::bpsem, bpentry::bpsize, buftab, disable(), freemem(), getmem(), NBPOOLS, nbpools, NULL, restore(), semcreate(), and SYSERR.

Referenced by net_init().

39 {
40  intmask mask; /* Saved interrupt mask */
41  bpid32 poolid; /* ID of pool that is created */
42  struct bpentry *bpptr; /* Pointer to entry in buftab */
43  char *buf; /* Pointer to memory for buffer */
44 
45  mask = disable();
46  if (bufsiz < BP_MINB || bufsiz > BP_MAXB || numbufs < 1 || numbufs > BP_MAXN || nbpools >= NBPOOLS)
47  {
48  restore(mask);
49  return (bpid32)SYSERR;
50  }
51  /* Round request to a multiple of 4 bytes */
52 
53  bufsiz = ((bufsiz + 3) & (~3));
54 
55  buf = (char *)getmem(numbufs * (bufsiz + sizeof(bpid32)));
56  if ((int32)buf == SYSERR)
57  {
58  restore(mask);
59  return (bpid32)SYSERR;
60  }
61  poolid = nbpools++;
62  bpptr = &buftab[poolid];
63  bpptr->bpnext = (struct bpentry *)buf;
64  bpptr->bpsize = bufsiz;
65  if ((bpptr->bpsem = semcreate(numbufs)) == SYSERR)
66  {
67  freemem(buf, numbufs * (bufsiz + sizeof(bpid32)));
68  nbpools--;
69  restore(mask);
70  return (bpid32)SYSERR;
71  }
72  bufsiz += sizeof(bpid32);
73  for (numbufs--; numbufs > 0; numbufs--)
74  {
75  bpptr = (struct bpentry *)buf;
76  buf += bufsiz;
77  bpptr->bpnext = (struct bpentry *)buf;
78  }
79  bpptr = (struct bpentry *)buf;
80  bpptr->bpnext = (struct bpentry *)NULL;
81  restore(mask);
82  return poolid;
83 }
struct bpentry buftab[]
バッファプールテーブルのextern宣言
Definition: bufinit.c:8
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
#define BP_MAXN
バッファプールに存在するバッファの最大数
Definition: bufpool.h:20
sid32 semcreate(int32)
未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。
Definition: semcreate.c:22
void restore(intmask)
syscall freemem(char *, uint32)
メモリブロックを解放し、ブロックを空きリストに戻す。
Definition: freemem.c:33
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define NBPOOLS
バッファプール数の最大数
Definition: bufpool.h:8
#define BP_MAXB
最大バッファサイズ(Byte)
Definition: bufpool.h:13
int32 bpid32
バッファプールID
Definition: kernel.h:34
bpid32 nbpools
割り当てられたバッファプールの現在の数
Definition: bufinit.c:10
sid32 bpsem
バッファプールで現在使用可能なバッファをカウントするセマフォ
Definition: bufpool.h:32
struct bpentry * bpnext
次のフリーバッファへのポインタ
Definition: bufpool.h:30
バッファプールテーブルエントリ
Definition: bufpool.h:27
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
uint32 bpsize
本バッファプール内のバッファサイズ
Definition: bufpool.h:34
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
char * getmem(uint32)
ヒープ領域を割り当て、最下位のワードアドレスを返す。
Definition: getmem.c:25
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mount()

syscall mount ( char *  ,
char *  ,
did32   
)

Definition at line 9 of file mount.c.

References disable(), isbaddev, nametab, namlen(), nmentry::ndevice, NM_PRELEN, NM_REPLLEN, NNAMES, nnames, nmentry::nprefix, nmentry::nreplace, OK, restore(), and SYSERR.

Referenced by naminit().

14 {
15  intmask mask; /* Saved interrupt mask */
16  struct nmentry *namptr; /* Pointer to unused table entry*/
17  int32 psiz, rsiz; /* Sizes of prefix & replacement*/
18  int32 i; /* Counter for copy loop */
19 
20  mask = disable();
21 
22  psiz = namlen(prefix, NM_PRELEN);
23  rsiz = namlen(replace, NM_REPLLEN);
24 
25  /* If arguments are invalid or table is full, return error */
26 
27  if ( (psiz == SYSERR) || (rsiz == SYSERR) ||
28  (isbaddev(device)) || (nnames >= NNAMES) ) {
29  restore(mask);
30  return SYSERR;
31  }
32 
33  /* Allocate a slot in the table */
34 
35  namptr = &nametab[nnames]; /* Next unused entry in table */
36 
37  /* copy prefix and replacement strings and record device ID */
38 
39  for (i=0; i<psiz; i++) { /* Copy prefix into table entry */
40  namptr->nprefix[i] = *prefix++;
41  }
42 
43  for (i=0; i<rsiz; i++) { /* Copy replacement into entry */
44  namptr->nreplace[i] = *replace++;
45  }
46 
47  namptr->ndevice = device; /* Record the device ID */
48 
49  nnames++; /* Increment number of names */
50 
51  restore(mask);
52  return OK;
53 }
int32 namlen(char *name, int32 maxlen)
Definition: mount.c:60
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define NNAMES
プレフィックス定義の数
Definition: name.h:13
#define OK
処理が成功した場合
Definition: kernel.h:77
#define NM_REPLLEN
置換(1個)の最大サイズ
Definition: name.h:9
int32 nnames
割り当てられたネームテーブルエントリの数
Definition: naminit.c:23
struct nmentry nametab[]
名前マッピングのテーブル
Definition: naminit.c:22
did32 ndevice
プレフィックス用のデバイスディスクリプタ
Definition: name.h:26
全ての名前マッピングを定義する名前プレフィックステーブルの定義(ネームテーブルエントリ) ...
Definition: name.h:19
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
#define NM_PRELEN
プレフィックス文字列の最大サイズ
Definition: name.h:7
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define isbaddev(f)
デバイスIDを検証するマクロ。
Definition: device.h:15
char nprefix[NM_PRELEN]
NULL終端のプレフィックス
Definition: name.h:22
char nreplace[NM_REPLLEN]
NULL終端置換
Definition: name.h:24
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ namcpy()

status namcpy ( char *  newname,
char *  oldname,
int32  buflen 
)

Definition at line 116 of file nammap.c.

References NULLCH, OK, and SYSERR.

Referenced by nammap().

121 {
122  char *nptr; /* Point to new name */
123  char *optr; /* Point to old name */
124  int32 cnt; /* Count of characters copied */
125 
126  nptr = newname;
127  optr = oldname;
128 
129  for (cnt=0; cnt<buflen; cnt++) {
130  if ( (*nptr++ = *optr++) == NULLCH) {
131  return OK;
132  }
133  }
134  return SYSERR; /* Buffer filled before copy completed */
135 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the caller graph for this function:

◆ naminit()

status naminit ( void  )

Definition at line 29 of file naminit.c.

References devtab, dentry::dvname, dentry::dvnum, kprintf(), LFILESYS, mount(), NDEVS, NM_MAXLEN, nnames, NULLCH, NULLDEV, NULLSTR, OK, RFILESYS, and SYSERR.

30 {
31  did32 i; /* Index into devtab */
32  struct dentry *devptr; /* Pointer to device table entry*/
33  char tmpstr[NM_MAXLEN]; /* String to hold a name */
34  status retval; /* Return value */
35  char *tptr; /* Pointer into tempstring */
36  char *nptr; /* Pointer to device name */
37  char devprefix[] = "/dev/"; /* Prefix to use for devices */
38  int32 len; /* Length of created name */
39  char ch; /* Storage for a character */
40 
41  /* Set prefix table to empty */
42 
43  nnames = 0;
44 
45  for (i = 0; i < NDEVS; i++)
46  {
47  tptr = tmpstr;
48  nptr = devprefix;
49 
50  /* Copy prefix into tmpstr */
51 
52  len = 0;
53  while ((*tptr++ = *nptr++) != NULLCH)
54  {
55  len++;
56  }
57  tptr--; /* Move pointer to position before NULLCH */
58  devptr = &devtab[i];
59  nptr = devptr->dvname; /* Move to device name */
60 
61  /* Map device name to lower case and append */
62 
63  while (++len < NM_MAXLEN)
64  {
65  ch = *nptr++;
66  if ((ch >= 'A') && (ch <= 'Z'))
67  {
68  ch += 'a' - 'A';
69  }
70  if ((*tptr++ = ch) == NULLCH)
71  {
72  break;
73  }
74  }
75 
76  if (len > NM_MAXLEN)
77  {
78  kprintf("namespace: device name %s too long\r\n",
79  devptr->dvname);
80  continue;
81  }
82 
83  retval = mount(tmpstr, NULLSTR, devptr->dvnum);
84  if (retval == SYSERR)
85  {
86  kprintf("namespace: cannot mount device %d\r\n",
87  devptr->dvname);
88  continue;
89  }
90  }
91 
92  /* Add other prefixes (longest prefix first) */
93 
94  mount("/dev/null", "", NULLDEV);
95  mount("/remote/", "remote:", RFILESYS);
96  mount("/local/", NULLSTR, LFILESYS);
97  mount("/dev/", NULLSTR, SYSERR);
98  mount("~/", NULLSTR, LFILESYS);
99  mount("/", "root:", RFILESYS);
100  mount("", "", LFILESYS);
101 
102  return OK;
103 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define NULLSTR
空文字
Definition: kernel.h:72
#define NDEVS
Definition: conf.h:74
syscall mount(char *, char *, did32)
Definition: mount.c:9
int32 nnames
割り当てられたネームテーブルエントリの数
Definition: naminit.c:23
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define RFILESYS
Definition: naminit.c:11
#define OK
処理が成功した場合
Definition: kernel.h:77
int32 status
ステータスを意味する返り値の型(OK/SYSERR)
Definition: kernel.h:57
Definition: conf.h:6
#define NM_MAXLEN
ファイル名の最大サイズ
Definition: name.h:11
#define LFILESYS
Definition: naminit.c:19
struct dentry devtab[]
Definition: conf.c:11
#define NULLDEV
Definition: conf.h:33
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 dvnum
Definition: conf.h:7
int32 did32
デバイスID
Definition: kernel.h:28
char * dvname
Definition: conf.h:9
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:

◆ namlen()

int32 namlen ( char *  ,
int32   
)

Definition at line 60 of file mount.c.

References NULLCH, and SYSERR.

Referenced by dns_geta(), mount(), and namrepl().

65 {
66  int32 i; /* Count of characters found */
67 
68  /* Search until a null terminator or length reaches max */
69 
70  for (i=0; i < maxlen; i++) {
71  if (*name++ == NULLCH) {
72  return i+1; /* Include NULLCH in length */
73  }
74  }
75  return SYSERR;
76 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the caller graph for this function:

◆ nammap()

devcall nammap ( char *  ,
char  [],
did32   
)

Referenced by namopen().

Here is the caller graph for this function:

◆ namopen()

devcall namopen ( struct dentry ,
char *  ,
char *   
)

Definition at line 9 of file namopen.c.

References dentry::dvnum, nammap(), newdev(), NM_MAXLEN, open(), and SYSERR.

14 {
15  char newname[NM_MAXLEN]; /* Name with prefix replaced */
16  did32 newdev; /* Device ID after mapping */
17 
18  /* Use namespace to map name to a new name and new descriptor */
19 
20  newdev = nammap(name, newname, devptr->dvnum);
21 
22  if (newdev == SYSERR) {
23  return SYSERR;
24  }
25 
26  /* Open underlying device and return status */
27 
28  return open(newdev, newname, mode);
29 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
devcall nammap(char *, char[], did32)
void newdev(char *)
Definition: y.tab.c:2163
#define NM_MAXLEN
ファイル名の最大サイズ
Definition: name.h:11
int32 did32
デバイスID
Definition: kernel.h:28
syscall open(did32, char *, char *)
Definition: open.c:9
Here is the call graph for this function:

◆ namrepl()

did32 namrepl ( char *  ,
char  [] 
)

◆ net_init()

void net_init ( void  )

Definition at line 15 of file net.c.

References arp_init(), control(), create(), ETH_ADDR_LEN, ETH_CTRL_GET_MAC, ETHER0, getticks(), icmp_init(), ICMP_QSIZ, ICMP_SLOTS, ipoqueue, ipout(), iqentry::iqhead, iqentry::iqsem, iqentry::iqtail, memset(), mkbufpool(), netbufpool, NetData, netin(), netportseed, NETPRIO, NETSTK, NULL, NULLCH, PACKLEN, panic(), resume(), semcreate(), SYSERR, udp_init(), UDP_QSIZ, and UDP_SLOTS.

Referenced by nulluser().

16 {
17  int32 nbufs; /* Total no of buffers */
18 
19  /* Initialize the network data structure */
20 
21  memset((char *)&NetData, NULLCH, sizeof(struct network));
22 
23  /* Obtain the Ethernet MAC address */
24 
25  control(ETHER0, ETH_CTRL_GET_MAC, (int32)NetData.ethucast, 0);
26 
27  memset((char *)NetData.ethbcast, 0xFF, ETH_ADDR_LEN);
28 
29  /* Initialize the random port seed */
30 
32 
33  /* Create the network buffer pool */
34 
35  nbufs = UDP_SLOTS * UDP_QSIZ + ICMP_SLOTS * ICMP_QSIZ + 1;
36 
37  netbufpool = mkbufpool(PACKLEN, nbufs);
38 
39  /* Initialize the ARP cache */
40 
41  arp_init();
42 
43  /* Initialize UDP */
44 
45  udp_init();
46 
47  /* Initialize ICMP */
48 
49  icmp_init();
50 
51  /* Initialize the IP output queue */
52 
53  ipoqueue.iqhead = 0;
54  ipoqueue.iqtail = 0;
56  if((int32)ipoqueue.iqsem == SYSERR) {
57  panic("Cannot create ip output queue semaphore");
58  return;
59  }
60 
61  /* Create the IP output process */
62 
63  resume(create(ipout, NETSTK, NETPRIO, "ipout", 0, NULL));
64 
65  /* Create a network input process */
66 
67  resume(create(netin, NETSTK, NETPRIO, "netin", 0, NULL));
68 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
sid32 semcreate(int32)
未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。
Definition: semcreate.c:22
sid32 iqsem
パケット(pkts)をカウントするセマフォ
Definition: ip.h:37
#define NETSTK
Definition: net.h:3
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
process netin()
Definition: net.c:76
#define ICMP_SLOTS
Definition: icmp.h:3
#define UDP_SLOTS
Definition: udp.h:3
void icmp_init(void)
Definition: icmp.c:12
bpid32 mkbufpool(int32, int32)
バッファプール用のメモリを割り当て、バッファ同士をリンクする。
Definition: mkbufpool.c:38
syscall control(did32, int32, int32, int32)
Definition: control.c:9
int32 iqhead
次に送信するパケットのインデックス
Definition: ip.h:33
void udp_init(void)
Definition: udp.c:12
Definition: net.h:54
#define ETH_CTRL_GET_MAC
Definition: ether.h:45
#define ICMP_QSIZ
Definition: icmp.h:4
uint32 getticks(void)
CPUリセット以降のclock tick数を取得する。
Definition: getticks.c:14
struct iqentry ipoqueue
ネットワーク送信キュー
Definition: ip.c:6
#define UDP_QSIZ
Definition: udp.h:4
#define PACKLEN
Definition: net.h:50
struct network NetData
Definition: net.c:6
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
pri16 resume(pid32)
プロセスを休止状態(サスペンド)からREADY状態に遷移させる。
Definition: resume.c:20
#define NETPRIO
Definition: net.h:4
pid32 create(void *, uint32, pri16, char *, uint32,...)
関数の実行を開始するプロセスを作成する。
Definition: create.c:55
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
uint32 netportseed
Definition: net.c:8
#define ETH_ADDR_LEN
Definition: ether.h:10
int32 iqtail
次の空きスロットのインデックス。
Definition: ip.h:35
void arp_init(void)
Definition: arp.c:11
#define ETHER0
Definition: conf.h:34
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
bpid32 netbufpool
Definition: net.c:7
process ipout(void)
Definition: ip.c:356
Here is the call graph for this function:
Here is the caller graph for this function:

◆ netin()

process netin ( void  )

Definition at line 76 of file net.c.

References arp_in(), ETH_ARP, ETH_IP, ETH_IPv6, eth_ntoh(), ETHER0, freebuf(), getbuf(), ip_in(), netbufpool, PACKLEN, panic(), read(), and SYSERR.

Referenced by net_init().

77 {
78  struct netpacket *pkt; /* Ptr to current packet */
79  int32 retval; /* Return value from read */
80 
81  /* Do forever: read a packet from the network and process */
82 
83  while(1) {
84 
85  /* Allocate a buffer */
86 
87  pkt = (struct netpacket *)getbuf(netbufpool);
88 
89  /* Obtain next packet that arrives */
90 
91  retval = read(ETHER0, (char *)pkt, PACKLEN);
92  if(retval == SYSERR) {
93  panic("Cannot read from Ethernet\n");
94  }
95 
96  /* Convert Ethernet Type to host order */
97 
98  eth_ntoh(pkt);
99 
100  /* Demultiplex on Ethernet type */
101 
102  switch (pkt->net_ethtype) {
103 
104  case ETH_ARP: /* Handle ARP */
105  arp_in((struct arppacket *)pkt);
106  continue;
107 
108  case ETH_IP: /* Handle IP */
109  ip_in(pkt);
110  continue;
111 
112  case ETH_IPv6: /* Handle IPv6 */
113  freebuf((char *)pkt);
114  continue;
115 
116  default: /* Ignore all other incoming packets */
117  freebuf((char *)pkt);
118  continue;
119  }
120  }
121 }
void arp_in(struct arppacket *)
Definition: arp.c:158
void ip_in(struct netpacket *)
Definition: ip.c:13
uint16 net_ethtype
Definition: net.h:19
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
syscall read(did32, char *, uint32)
Definition: read.c:9
#define ETH_IPv6
Definition: net.h:11
void eth_ntoh(struct netpacket *pktptr)
Definition: net.c:139
#define PACKLEN
Definition: net.h:50
IP&Ethernet用のARPパケットフォーマット
Definition: arp.h:39
#define ETH_ARP
Definition: net.h:9
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
char * getbuf(bpid32)
事前に確保されたバッファプールからバッファを取得する。
Definition: getbuf.c:19
Definition: net.h:16
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
#define ETH_IP
Definition: net.h:10
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
#define ETHER0
Definition: conf.h:34
bpid32 netbufpool
Definition: net.c:7
Here is the call graph for this function:
Here is the caller graph for this function:

◆ netout()

process netout ( void  )

◆ newqueue()

qid16 newqueue ( void  )

グローバルキューテーブルにキューを割り当て、テーブルを初期化する。

newqueue()は、キューテーブルのインデックスNPROC以降にリストの先頭/末尾を作成し、
そのリストに要素を追加できる状態にする。
次にnewqueue()を呼び出された時、キューテーブルの位置に新しいリストの先頭/末尾を配置すべきかは、
newqueue()内のstatic変数nextqidを参照すれば判断できる。

Returns
成功時はリストの先頭ノードインデックス、キューテーブルがオーバフローした場合はSYSERRを返す。

Definition at line 15 of file newqueue.c.

References EMPTY, MAXKEY, MINKEY, NPROC, NQENT, qentry::qkey, qentry::qnext, qentry::qprev, queuehead, queuetab, queuetail, and SYSERR.

Referenced by clkinit(), and sysinit().

16 {
17  static qid16 nextqid = NPROC; /* Next list in queuetab to use */
18  qid16 q; /* ID of allocated queue */
19 
20  q = nextqid;
21  if (q >= NQENT)
22  { /* Check for table overflow */
23  return SYSERR;
24  }
25 
26  nextqid += 2; /* Increment index for next call*/
27 
28  /* Initialize head and tail nodes to form an empty queue */
29 
36  return q;
37 }
struct qentry queuetab[]
Definition: queue.c:45
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define MINKEY
キューの中に格納できるキーの最小値
Definition: queue.h:27
#define queuehead(q)
キューの先頭を返す。
Definition: queue.h:53
#define EMPTY
次のキューインデックスもしくは前のキューインデックスがNULL値
Definition: queue.h:23
qid16 qnext
次のプロセスか末尾のプロセスのインデックス。
Definition: queue.h:39
int32 qkey
キュー順序を決定するキー(優先度)。
Definition: queue.h:37
qid16 qprev
前のプロセスか先頭のプロセスのインデックス。
Definition: queue.h:41
#define NPROC
Definition: conf.h:79
#define NQENT
Definition: queue.h:19
int16 qid16
キューID
Definition: kernel.h:24
#define queuetail(q)
キューの末尾を返す。
Definition: queue.h:61
#define MAXKEY
キューの中に格納できるキーの最大値
Definition: queue.h:25
Here is the caller graph for this function:

◆ open()

syscall open ( did32  ,
char *  ,
char *   
)

Definition at line 9 of file open.c.

References devtab, disable(), dentry::dvopen, isbaddev, restore(), and SYSERR.

Referenced by namopen(), shell(), xsh_cat(), and xsh_rdstest().

14 {
15  intmask mask; /* Saved interrupt mask */
16  struct dentry *devptr; /* Entry in device switch table */
17  int32 retval; /* Value to return to caller */
18 
19  mask = disable();
20  if (isbaddev(descrp)) {
21  restore(mask);
22  return SYSERR;
23  }
24  devptr = (struct dentry *) &devtab[descrp];
25  retval = (*devptr->dvopen) (devptr, name, mode);
26  restore(mask);
27  return retval;
28 }
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
Definition: conf.h:6
struct dentry devtab[]
Definition: conf.c:11
devcall(* dvopen)(struct dentry *, char *, char *)
Definition: conf.h:11
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define isbaddev(f)
デバイスIDを検証するマクロ。
Definition: device.h:15
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ outb()

int32 outb ( int32  ,
int32   
)

◆ outl()

int32 outl ( int32  ,
int32   
)

◆ outsw()

int32 outsw ( int32  ,
int32  ,
int32   
)

◆ outw()

int32 outw ( int32  ,
int32   
)

◆ panic()

void panic ( char *  msg)

Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。

割り込み禁止後にPanicメッセージを表示し、無限ループを行う。

Parameters
[in]msg表示するメッセージ

Definition at line 12 of file panic.c.

References disable(), kprintf(), and TRUE.

Referenced by icmp_mkpkt(), irq_dispatch(), lfdballoc(), lfiballoc(), lfsckfmt(), net_init(), netin(), ptinit(), ptsend(), rdsbufalloc(), rdsinit(), rdsprocess(), and rfsinit().

13 {
14  disable(); /* Disable interrupts */
15  kprintf("\n\n\rpanic: %s\n\n", msg);
16  while (TRUE)
17  {
18  ;
19  } /* Busy loop forever */
20 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define TRUE
Boolean True(1)
Definition: kernel.h:65
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pci_init()

int32 pci_init ( void  )

◆ pdump()

void pdump ( struct netpacket )

Definition at line 9 of file pdump.c.

References arppacket::arp_hlen, ARP_HTYPE, arppacket::arp_htype, arppacket::arp_op, ARP_OP_REQ, ARP_OP_RPLY, arppacket::arp_plen, ARP_PTYPE, arppacket::arp_ptype, arppacket::arp_sndha, arppacket::arp_sndpa, arppacket::arp_tarpa, ETH_HDR_LEN, ICMP_ECHOREPLY, ICMP_ECHOREQST, IP_ICMP, IP_UDP, ipcksum(), kprintf(), netpacket::net_ethdst, netpacket::net_ethsrc, netpacket::net_ethtype, netpacket::net_icident, netpacket::net_icseq, netpacket::net_ictype, netpacket::net_ipdst, netpacket::net_ipfrag, netpacket::net_ipid, netpacket::net_iplen, netpacket::net_ipproto, netpacket::net_ipsrc, netpacket::net_iptos, netpacket::net_ipttl, netpacket::net_udpdport, netpacket::net_udplen, netpacket::net_udpsport, ntohl, ntohs, and UDP_HDR_LEN.

10 {
11  struct arppacket *aptr;
12 
13  kprintf("%02x:%02x:%02x:%02x:%02x:%02x >",
14  pptr->net_ethsrc[0],
15  pptr->net_ethsrc[1],
16  pptr->net_ethsrc[2],
17  pptr->net_ethsrc[3],
18  pptr->net_ethsrc[4],
19  pptr->net_ethsrc[5]
20  );
21  kprintf(" %02x:%02x:%02x:%02x:%02x:%02x, ",
22  pptr->net_ethdst[0],
23  pptr->net_ethdst[1],
24  pptr->net_ethdst[2],
25  pptr->net_ethdst[3],
26  pptr->net_ethdst[4],
27  pptr->net_ethdst[5]
28  );
29 
30  kprintf("ethertype ");
31 
32  switch (ntohs(pptr->net_ethtype)) {
33 
34  case 0x0806:
35  kprintf("ARP (0x%04x), length %d: ",
36  ntohs(pptr->net_ethtype),
37  sizeof(struct arppacket));
38  aptr = (struct arppacket *)pptr;
39 
40  if ( (ntohs(aptr->arp_htype) != ARP_HTYPE) ||
41  (ntohs(aptr->arp_ptype) != ARP_PTYPE) ) {
42  break;
43  }
44 
45  kprintf("hard addr len=%d), proto addr len=%d), ",
46  aptr->arp_hlen,
47  aptr->arp_plen);
48 
49  if (ntohs(aptr->arp_op) == ARP_OP_REQ) {
50  kprintf("Request who-has %d.%d.%d.%d tell %d.%d.%d.%d, ",
51  (ntohl(aptr->arp_tarpa)>>24)&0xff,
52  (ntohl(aptr->arp_tarpa)>>16)&0xff,
53  (ntohl(aptr->arp_tarpa)>>8)&0xff,
54  ntohl(aptr->arp_tarpa)&0xff,
55  (ntohl(aptr->arp_sndpa)>>24)&0xff,
56  (ntohl(aptr->arp_sndpa)>>16)&0xff,
57  (ntohl(aptr->arp_sndpa)>>8)&0xff,
58  ntohl(aptr->arp_sndpa)&0xff);
59  } else if (ntohs(aptr->arp_op) == ARP_OP_RPLY) {
60  kprintf("Reply %d.%d.%d.%d is-at %02x:%02x:%02x:%02x:%02x:%02x, ",
61  (ntohl(aptr->arp_sndpa)>>24)&0xff,
62  (ntohl(aptr->arp_sndpa)>>16)&0xff,
63  (ntohl(aptr->arp_sndpa)>>8)&0xff,
64  ntohl(aptr->arp_sndpa)&0xff,
65  aptr->arp_sndha[0],
66  aptr->arp_sndha[1],
67  aptr->arp_sndha[2],
68  aptr->arp_sndha[3],
69  aptr->arp_sndha[4],
70  aptr->arp_sndha[5]);
71  } else {
72  break;
73  }
74 
75  kprintf("length %d\n", sizeof(struct arppacket) - ETH_HDR_LEN);
76  break;
77 
78  case 0x0800:
79  kprintf("IPv4 (0x%04x), length %d: ",
80  ntohs(pptr->net_ethtype),
81  ntohs(pptr->net_iplen) + ETH_HDR_LEN);
82 
83  kprintf("(");
84  kprintf("tos 0x%01x, ttl %d, id %d, offset %d ",
85  pptr->net_iptos,
86  pptr->net_ipttl,
87  ntohs(pptr->net_ipid),
88  (ntohs(pptr->net_ipfrag) & 0x1fff));
89 
90  kprintf("flags ");
91  if (ntohs(pptr->net_ipfrag) & 0x4000)
92  kprintf("[DF], ");
93  else if (ntohs(pptr->net_ipfrag) & 0x2000)
94  kprintf("[MF], " );
95  else
96  kprintf("[none], ");
97 
98  kprintf("[ip checksum %s], ",
99  ipcksum(pptr) == 0 ? "ok" : "fail");
100 
101  if (pptr->net_ipproto == IP_UDP) {
102  kprintf("proto UDP (%d), length %d",
103  pptr->net_ipproto, ntohs(pptr->net_iplen));
104  kprintf(")\n");
105  kprintf("\t%d.%d.%d.%d > ",
106  (ntohl(pptr->net_ipsrc)>>24)&0xff,
107  (ntohl(pptr->net_ipsrc)>>16)&0xff,
108  (ntohl(pptr->net_ipsrc)>>8)&0xff,
109  (ntohl(pptr->net_ipsrc)&0xff));
110  kprintf("%d.%d.%d.%d: ",
111  (ntohl(pptr->net_ipdst)>>24)&0xff,
112  (ntohl(pptr->net_ipdst)>>16)&0xff,
113  (ntohl(pptr->net_ipdst)>>8)&0xff,
114  (ntohl(pptr->net_ipdst)&0xff));
115  kprintf("[udp checksum none] ");
116  kprintf("UDP, src port %d, dst port %d, length %d\n",
117  ntohs(pptr->net_udpsport),
118  ntohs(pptr->net_udpdport),
119  ntohs(pptr->net_udplen) - UDP_HDR_LEN);
120  break;
121  } else if (pptr->net_ipproto == IP_ICMP) {
122  kprintf("proto ICMP (%d), length %d",
123  pptr->net_ipproto, ntohs(pptr->net_iplen));
124  kprintf(")\n");
125  kprintf("\t%d.%d.%d.%d > ",
126  (ntohl(pptr->net_ipsrc)>>24)&0xff,
127  (ntohl(pptr->net_ipsrc)>>16)&0xff,
128  (ntohl(pptr->net_ipsrc)>>8)&0xff,
129  (ntohl(pptr->net_ipsrc)&0xff));
130  kprintf("%d.%d.%d.%d: ",
131  (ntohl(pptr->net_ipdst)>>24)&0xff,
132  (ntohl(pptr->net_ipdst)>>16)&0xff,
133  (ntohl(pptr->net_ipdst)>>8)&0xff,
134  (ntohl(pptr->net_ipdst)&0xff));
135 
136  if (pptr->net_ictype == ICMP_ECHOREQST)
137  kprintf("ICMP echo request, ");
138  else if (pptr->net_ictype == ICMP_ECHOREPLY)
139  kprintf("ICMP echo reply, ");
140  else
141  break;
142 
143  kprintf("id %d, seq %d\n",
144  ntohs(pptr->net_icident),
145  ntohs(pptr->net_icseq));
146 
147  break;
148  }
149  else
150  break;
151  default:
152  kprintf("unknown\n");
153  break;
154 
155  }
156 
157  return;
158 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define IP_UDP
IP向けのUDPプロトコルタイプ
Definition: ip.h:16
byte arp_plen
ARPプロトコルアドレス長さ
Definition: arp.h:54
#define ARP_PTYPE
IPプロトコルタイプ
Definition: arp.h:14
#define ICMP_ECHOREQST
Definition: icmp.h:17
byte arp_hlen
ARPハードウェアアドレス長さ
Definition: arp.h:52
#define ARP_OP_RPLY
リプライオペコード
Definition: arp.h:18
#define ICMP_ECHOREPLY
Definition: icmp.h:16
uint16 arp_ptype
ARPプロトコルタイプ
Definition: arp.h:50
uint16 ipcksum(struct netpacket *)
Definition: ip.c:286
#define ARP_HTYPE
Ethernetハードウェアタイプ
Definition: arp.h:12
#define IP_ICMP
IP向けのICMPプロトコルタイプ
Definition: ip.h:14
byte arp_sndha[ARP_HALEN]
ARP送信者のEthernetアドレス
Definition: arp.h:58
#define ntohl(x)
Definition: prototypes.h:623
IP&Ethernet用のARPパケットフォーマット
Definition: arp.h:39
#define ntohs(x)
Definition: prototypes.h:622
#define ETH_HDR_LEN
Definition: ether.h:22
#define ARP_OP_REQ
リクエストオペコード
Definition: arp.h:16
uint32 arp_tarpa
ARPターゲットのIPアドレス
Definition: arp.h:64
uint16 arp_htype
ARPハードウェアタイプ
Definition: arp.h:48
uint32 arp_sndpa
ARP送信者のIPアドレス
Definition: arp.h:60
uint16 arp_op
ARPオペレーション
Definition: arp.h:56
#define UDP_HDR_LEN
Definition: udp.h:18
Here is the call graph for this function:

◆ pdumph()

void pdumph ( struct netpacket )

Definition at line 164 of file pdump.c.

References arppacket::arp_hlen, ARP_HTYPE, arppacket::arp_htype, arppacket::arp_op, ARP_OP_REQ, ARP_OP_RPLY, arppacket::arp_plen, ARP_PTYPE, arppacket::arp_ptype, arppacket::arp_sndha, arppacket::arp_sndpa, arppacket::arp_tarpa, ETH_HDR_LEN, icmp_cksum(), ICMP_ECHOREPLY, ICMP_ECHOREQST, IP_HDR_LEN, IP_ICMP, IP_UDP, ipcksum(), kprintf(), netpacket::net_ethdst, netpacket::net_ethsrc, netpacket::net_ethtype, netpacket::net_icident, netpacket::net_icseq, netpacket::net_ictype, netpacket::net_ipdst, netpacket::net_ipfrag, netpacket::net_ipid, netpacket::net_iplen, netpacket::net_ipproto, netpacket::net_ipsrc, netpacket::net_iptos, netpacket::net_ipttl, netpacket::net_udpdport, netpacket::net_udplen, netpacket::net_udpsport, ntohs, and UDP_HDR_LEN.

165 {
166  struct arppacket *aptr;
167 
168  kprintf("%02x:%02x:%02x:%02x:%02x:%02x >",
169  pptr->net_ethsrc[0],
170  pptr->net_ethsrc[1],
171  pptr->net_ethsrc[2],
172  pptr->net_ethsrc[3],
173  pptr->net_ethsrc[4],
174  pptr->net_ethsrc[5]
175  );
176  kprintf(" %02x:%02x:%02x:%02x:%02x:%02x, ",
177  pptr->net_ethdst[0],
178  pptr->net_ethdst[1],
179  pptr->net_ethdst[2],
180  pptr->net_ethdst[3],
181  pptr->net_ethdst[4],
182  pptr->net_ethdst[5]
183  );
184 
185  kprintf("ethertype ");
186 
187  switch (pptr->net_ethtype) {
188 
189  case 0x0806:
190  kprintf("ARP (0x%04x), length %d: ",
191  pptr->net_ethtype,
192  sizeof(struct arppacket));
193  aptr = (struct arppacket *)pptr;
194 
195  if ( (aptr->arp_htype != ARP_HTYPE) ||
196  (aptr->arp_ptype != ARP_PTYPE) ) {
197  break;
198  }
199 
200  kprintf("hard addr len=%d), proto addr len=%d), ",
201  aptr->arp_hlen,
202  aptr->arp_plen);
203 
204  if (aptr->arp_op == ARP_OP_REQ) {
205  kprintf("Request who-has %d.%d.%d.%d tell %d.%d.%d.%d, ",
206  (aptr->arp_tarpa>>24)&0xff,
207  (aptr->arp_tarpa>>16)&0xff,
208  (aptr->arp_tarpa>>8)&0xff,
209  aptr->arp_tarpa&0xff,
210  (aptr->arp_sndpa>>24)&0xff,
211  (aptr->arp_sndpa>>16)&0xff,
212  (aptr->arp_sndpa>>8)&0xff,
213  aptr->arp_sndpa&0xff);
214  } else if (aptr->arp_op == ARP_OP_RPLY) {
215  kprintf("Reply %d.%d.%d.%d is-at %02x:%02x:%02x:%02x:%02x:%02x, ",
216  (aptr->arp_sndpa>>24)&0xff,
217  (aptr->arp_sndpa>>16)&0xff,
218  (aptr->arp_sndpa>>8)&0xff,
219  aptr->arp_sndpa&0xff,
220  aptr->arp_sndha[0],
221  aptr->arp_sndha[1],
222  aptr->arp_sndha[2],
223  aptr->arp_sndha[3],
224  aptr->arp_sndha[4],
225  aptr->arp_sndha[5]);
226  } else {
227  break;
228  }
229 
230  kprintf("length %d\n", sizeof(struct arppacket) - ETH_HDR_LEN);
231  break;
232 
233  case 0x0800:
234  kprintf("IPv4 (0x%04x), length %d: ",
235  pptr->net_ethtype,
236  pptr->net_iplen + ETH_HDR_LEN);
237 
238  kprintf("(");
239  kprintf("tos 0x%01x, ttl %d, id %d, offset %d ",
240  pptr->net_iptos,
241  pptr->net_ipttl,
242  pptr->net_ipid,
243  pptr->net_ipfrag & 0x1fff);
244 
245  kprintf("flags ");
246  if (pptr->net_ipfrag & 0x4000)
247  kprintf("[DF], ");
248  else if (pptr->net_ipfrag & 0x2000)
249  kprintf("[MF], " );
250  else
251  kprintf("[none], ");
252 
253  kprintf("[ip checksum %s], ",
254  ipcksum(pptr) == 0 ? "ok" : "fail");
255 
256  if (pptr->net_ipproto == IP_UDP) {
257  kprintf("proto UDP (%d), length %d",
258  pptr->net_ipproto, pptr->net_iplen);
259  kprintf(")\n");
260  kprintf("\t%d.%d.%d.%d > ",
261  (pptr->net_ipsrc>>24)&0xff,
262  (pptr->net_ipsrc>>16)&0xff,
263  (pptr->net_ipsrc>>8)&0xff,
264  (pptr->net_ipsrc&0xff));
265  kprintf("%d.%d.%d.%d: ",
266  (pptr->net_ipdst>>24)&0xff,
267  (pptr->net_ipdst>>16)&0xff,
268  (pptr->net_ipdst>>8)&0xff,
269  (pptr->net_ipdst&0xff));
270  kprintf("[udp checksum none] ");
271  kprintf("UDP, src port %d, dst port %d, length %d\n",
272  pptr->net_udpsport,
273  pptr->net_udpdport,
274  pptr->net_udplen - UDP_HDR_LEN);
275  break;
276  } else if (pptr->net_ipproto == IP_ICMP) {
277  kprintf("proto ICMP (%d), length %d",
278  pptr->net_ipproto, pptr->net_iplen);
279  kprintf(")\n");
280  kprintf("\t%d.%d.%d.%d > ",
281  (pptr->net_ipsrc>>24)&0xff,
282  (pptr->net_ipsrc>>16)&0xff,
283  (pptr->net_ipsrc>>8)&0xff,
284  (pptr->net_ipsrc&0xff));
285  kprintf("%d.%d.%d.%d: ",
286  (pptr->net_ipsrc>>24)&0xff,
287  (pptr->net_ipsrc>>16)&0xff,
288  (pptr->net_ipsrc>>8)&0xff,
289  (pptr->net_ipsrc&0xff));
290 
291  if (pptr->net_ictype == ICMP_ECHOREQST)
292  kprintf("ICMP echo request, ");
293  else if (pptr->net_ictype == ICMP_ECHOREPLY)
294  kprintf("ICMP echo reply, ");
295  else
296  break;
297 
298  kprintf("id %d, seq %d\n",
299  pptr->net_icident,
300  pptr->net_icseq);
301  kprintf("icmp ckeckcum %s\n",
302  icmp_cksum((char *)&pptr->net_ictype,
303  ntohs(pptr->net_iplen)-IP_HDR_LEN)==0?
304  "OK":"failed");
305  break;
306  }
307  else
308  break;
309  default:
310  kprintf("unknown\n");
311  break;
312 
313  }
314 
315  return;
316 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define IP_UDP
IP向けのUDPプロトコルタイプ
Definition: ip.h:16
byte arp_plen
ARPプロトコルアドレス長さ
Definition: arp.h:54
#define ARP_PTYPE
IPプロトコルタイプ
Definition: arp.h:14
#define ICMP_ECHOREQST
Definition: icmp.h:17
byte arp_hlen
ARPハードウェアアドレス長さ
Definition: arp.h:52
#define ARP_OP_RPLY
リプライオペコード
Definition: arp.h:18
#define IP_HDR_LEN
IPヘッダのバイト数。
Definition: ip.h:20
#define ICMP_ECHOREPLY
Definition: icmp.h:16
uint16 arp_ptype
ARPプロトコルタイプ
Definition: arp.h:50
uint16 ipcksum(struct netpacket *)
Definition: ip.c:286
#define ARP_HTYPE
Ethernetハードウェアタイプ
Definition: arp.h:12
#define IP_ICMP
IP向けのICMPプロトコルタイプ
Definition: ip.h:14
uint16 icmp_cksum(char *, int32)
Definition: icmp.c:359
byte arp_sndha[ARP_HALEN]
ARP送信者のEthernetアドレス
Definition: arp.h:58
IP&Ethernet用のARPパケットフォーマット
Definition: arp.h:39
#define ntohs(x)
Definition: prototypes.h:622
#define ETH_HDR_LEN
Definition: ether.h:22
#define ARP_OP_REQ
リクエストオペコード
Definition: arp.h:16
uint32 arp_tarpa
ARPターゲットのIPアドレス
Definition: arp.h:64
uint16 arp_htype
ARPハードウェアタイプ
Definition: arp.h:48
uint32 arp_sndpa
ARP送信者のIPアドレス
Definition: arp.h:60
uint16 arp_op
ARPオペレーション
Definition: arp.h:56
#define UDP_HDR_LEN
Definition: udp.h:18
Here is the call graph for this function:

◆ platinit()

void platinit ( void  )

Definition at line 31 of file platinit.c.

References am335x_padctl, AM335X_PADCTL_RXTX, AM335X_PADCTL_TX, CONSOLE, counterinit(), devtab, initintc(), uart_csreg::sysc, uart_csreg::syss, UART0_PADRX_ADDR, UART0_PADRX_MODE, UART0_PADTX_ADDR, UART0_PADTX_MODE, UART_SYSC_SOFTRESET, UART_SYSS_RESETDONE, WDTADDR, watchdog_csreg::wspr, and watchdog_csreg::wwps.

Referenced by sysinit().

32 {
33 
34  struct uart_csreg *uptr; /* Address of UART's CSRs */
35  struct watchdog_csreg *wdtptr; /* Watchdog registers */
36 
37  /* Disable the watchdog timer */
38 
39  wdtptr = (struct watchdog_csreg *)WDTADDR;
40  wdtptr->wspr = 0x0000aaaa;
41  while(wdtptr->wwps & 0x00000010);
42  wdtptr->wspr = 0x00005555;
43  while(wdtptr->wwps & 0x00000010);
44 
45  /* Initialize the Interrupt Controller */
46 
47  initintc();
48 
49  /* Initialize the Performance Counters */
50 
51  counterinit();
52 
53  /* Pad control for CONSOLE */
54 
59 
60  /* Reset the UART device */
61 
62  uptr = (struct uart_csreg *)devtab[CONSOLE].dvcsr;
63  uptr->sysc |= UART_SYSC_SOFTRESET;
64  while((uptr->syss & UART_SYSS_RESETDONE) == 0);
65 }
volatile uint32 wspr
開始/終了レジスタ
#define UART0_PADRX_ADDR
Definition: uart.h:126
volatile uint32 wwps
ポストBitレジスタの書き込み
void counterinit()
Definition: platinit.c:9
#define UART0_PADTX_ADDR
Definition: uart.h:127
int32 initintc(void)
Definition: evec.c:18
#define CONSOLE
Definition: conf.h:28
#define AM335X_PADCTL_TX
出力限定モード
struct dentry devtab[]
Definition: conf.c:11
#define UART0_PADRX_MODE
Definition: uart.h:128
#define am335x_padctl(addr, val)
引数で指定されたアドレスに値を代入する。
Watchdog CSREG(制御/状態)レジスタ操作用の構造体
#define UART0_PADTX_MODE
Definition: uart.h:129
volatile uint32 syss
Definition: uart.h:28
#define AM335X_PADCTL_RXTX
入力モードもしくは出力モード
#define WDTADDR
Watchdogタイマに割り当てられたアドレス
#define UART_SYSS_RESETDONE
Definition: uart.h:119
volatile uint32 sysc
Definition: uart.h:27
#define UART_SYSC_SOFTRESET
Definition: uart.h:115
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ptcount()

int32 ptcount ( int32  portid)

ポートを用いたメッセージ送受信において、メッセージ数を数える。

Step1. 割り込みを禁止する。
Step2. ポートIDが不正値もしくはポートが未割り当ての場合は、割り込み状態を復元し、
処理を終了する。 Step3. 受信メッセージ数(受信用セマフォ数)を数える。
Step4. 受信メッセージ数が0以上の場合は、送信メッセージ数(送信用セマフォ数)を数える。
Step5. 送信メッセージが0以下の場合は、受信メッセージ数にその数(送信者がブロックされた数)を
加算する。
Step6. 割り込み状態を復元する。

Parameters
[in]portidポートID
Returns
成功時は現在ポートで待機中のメッセージ数を返し、ポートIDが不正値もしくは
ポートが未割り当ての場合はSYSERRを返す。
Note
正の値Kは、ポートにK個のメッセージ(送信者がブロックされて送信待機中のメッセージ含む)が
ある事を意味する。負の値Kはポートが空であり、K個のプロセスがメッセージ受信のために
大気中である事を意味する。

Definition at line 25 of file ptcount.c.

References disable(), isbadport, porttab, PT_ALLOC, ptentry::ptrsem, ptentry::ptssem, ptentry::ptstate, restore(), semcount(), and SYSERR.

26 {
27  intmask mask; /* Saved interrupt mask */
28  int32 count; /* Count of messages available */
29  int32 sndcnt; /* Count of sender semaphore */
30  struct ptentry *ptptr; /* Pointer to port table entry */
31 
32  mask = disable();
33  if (isbadport(portid) ||
34  (ptptr = &porttab[portid])->ptstate != PT_ALLOC)
35  {
36  restore(mask);
37  return SYSERR;
38  }
39 
40  /* Get count of messages available */
41 
42  count = semcount(ptptr->ptrsem);
43 
44  /* If messages are waiting, check for blocked senders */
45 
46  if (count >= 0)
47  {
48  sndcnt = semcount(ptptr->ptssem);
49  if (sndcnt < 0)
50  { /* -sndcnt senders blocked */
51  count += -sndcnt;
52  }
53  }
54  restore(mask);
55  return count;
56 }
syscall semcount(sid32)
セマフォのカウント値を返す。
Definition: semcount.c:18
void restore(intmask)
ポートテーブルエントリ
Definition: ports.h:33
#define isbadport(portid)
ポートIDが不正値かどうかを確認する。
Definition: ports.h:64
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define PT_ALLOC
ポートが割り当てられた
Definition: ports.h:15
sid32 ptrsem
受信側セマフォ
Definition: ports.h:38
struct ptentry porttab[]
ポートテーブルエントリのextern宣言
Definition: ptinit.c:10
sid32 ptssem
送信側セマフォ
Definition: ports.h:36
uint16 ptstate
ポート状態(FREE/LIMBO/ALLOC)
Definition: ports.h:40
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:

◆ ptcreate()

syscall ptcreate ( int32  count)

未処理のメッセージを「カウント」できるポートを作成する。

Step1. 割り込みを禁止する。
Step2. ポートサイズが0より小さい場合は割り込み状態を復元し、処理を終了する。
Step3. 0〜NPORTS(30)の中で、空きポートIDを探す。
Step4. 空きポートに以下の対応を行う。
 ・状態をALLOCに変更
 ・送受信セマフォを作成
 ・メッセージリストを初期化(先頭と末尾をNULLとする)
 ・シーケンス番号を1増加
 ・最大待機メッセージ数を設定
Step5. 割り込み状態を復元する。

Parameters
[in]countポートサイズ(未処理メッセージの最大数)
Returns
成功時は割り当てたポートID、ポートサイズが不正な場合はSYSERRを返す。

Definition at line 23 of file ptcreate.c.

References disable(), NPORTS, NULL, porttab, PT_ALLOC, PT_FREE, ptentry::pthead, ptentry::ptmaxcnt, ptnextid, ptentry::ptrsem, ptentry::ptseq, ptentry::ptssem, ptentry::ptstate, ptentry::pttail, restore(), semcreate(), and SYSERR.

24 {
25  intmask mask; /* Saved interrupt mask */
26  int32 i; /* Counts all possible ports */
27  int32 ptnum; /* Candidate port number to try */
28  struct ptentry *ptptr; /* Pointer to port table entry */
29 
30  mask = disable();
31  if (count < 0)
32  {
33  restore(mask);
34  return SYSERR;
35  }
36 
37  for (i = 0; i < NPORTS; i++)
38  { /* Count all table entries */
39  ptnum = ptnextid; /* Get an entry to check */
40  if (++ptnextid >= NPORTS)
41  {
42  ptnextid = 0; /* Reset for next iteration */
43  }
44 
45  /* Check table entry that corresponds to ID ptnum */
46 
47  ptptr = &porttab[ptnum];
48  if (ptptr->ptstate == PT_FREE)
49  {
50  ptptr->ptstate = PT_ALLOC;
51  ptptr->ptssem = semcreate(count);
52  ptptr->ptrsem = semcreate(0);
53  ptptr->pthead = ptptr->pttail = NULL;
54  ptptr->ptseq++;
55  ptptr->ptmaxcnt = count;
56  restore(mask);
57  return ptnum;
58  }
59  }
60  restore(mask);
61  return SYSERR;
62 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
sid32 semcreate(int32)
未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。
Definition: semcreate.c:22
void restore(intmask)
ポートテーブルエントリ
Definition: ports.h:33
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define PT_ALLOC
ポートが割り当てられた
Definition: ports.h:15
sid32 ptrsem
受信側セマフォ
Definition: ports.h:38
uint16 ptmaxcnt
ポートに挿入できる最大メッセージ数
Definition: ports.h:42
#define NPORTS
ポートの最大数
Definition: ports.h:7
struct ptentry porttab[]
ポートテーブルエントリのextern宣言
Definition: ptinit.c:10
sid32 ptssem
送信側セマフォ
Definition: ports.h:36
uint16 ptstate
ポート状態(FREE/LIMBO/ALLOC)
Definition: ports.h:40
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 ptnextid
空きスロットを探す際に試みる次のポートID
Definition: ptinit.c:12
struct ptnode * pttail
メッセージリストの末尾ポインタ
Definition: ports.h:48
#define PT_FREE
ポートがFREE状態
Definition: ports.h:11
struct ptnode * pthead
メッセージリストの先頭ポインタ
Definition: ports.h:46
int32 ptseq
生成時に変更されたシーケンス
Definition: ports.h:44
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:

◆ ptdelete()

syscall ptdelete ( int32  portid,
int32(*)(int32 disp 
)

ポートを削除し、待機中のプロセスとメッセージを解放する。

Step1. 割り込みを禁止する。
Step2. ポートIDが不正、もしくはポートがALLOC状態でなければ割り込み状態を復元し、処理を終了する。
Step3. ポートを用いたメッセージと待機中プロセスを解放し、セマフォを削除する。
Step4. 次回のポート作成時には、今回削除したポートIDを使用するように設定する。
Step5. 割り込み状態を復元する。

Parameters
[in]portid削除対象のポート
[in]disp待機メッセージ処分用の関数ポインタ
Returns
成功時はOK、ポートIDが不正もしくはポートがALLOC状態以外の場合はSYSERRを返す。

Definition at line 19 of file ptdelete.c.

References _ptclear(), disable(), isbadport, OK, porttab, PT_ALLOC, PT_FREE, ptnextid, ptentry::ptstate, restore(), and SYSERR.

20 {
21  intmask mask; /* Saved interrupt mask */
22  struct ptentry *ptptr; /* Pointer to port table entry */
23 
24  mask = disable();
25  if (isbadport(portid) ||
26  (ptptr = &porttab[portid])->ptstate != PT_ALLOC)
27  {
28  restore(mask);
29  return SYSERR;
30  }
31  _ptclear(ptptr, PT_FREE, disp);
32  ptnextid = portid;
33  restore(mask);
34  return OK;
35 }
void _ptclear(struct ptentry *, uint16, int32(*)(int32))
ポートを用いたメッセージと待機中プロセスを解放する。
Definition: ptclear.c:24
void restore(intmask)
ポートテーブルエントリ
Definition: ports.h:33
#define isbadport(portid)
ポートIDが不正値かどうかを確認する。
Definition: ports.h:64
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define PT_ALLOC
ポートが割り当てられた
Definition: ports.h:15
#define OK
処理が成功した場合
Definition: kernel.h:77
struct ptentry porttab[]
ポートテーブルエントリのextern宣言
Definition: ptinit.c:10
uint16 ptstate
ポート状態(FREE/LIMBO/ALLOC)
Definition: ports.h:40
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int32 ptnextid
空きスロットを探す際に試みる次のポートID
Definition: ptinit.c:12
#define PT_FREE
ポートがFREE状態
Definition: ports.h:11
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:

◆ ptinit()

syscall ptinit ( int32  maxmsgs)

全てのポートを初期化する。

Step1. 全てのポート中の最大メッセージ数分だけメモリを確保する。
メモリが確保できなかった場合はpanic状態となり、再起動が必要となる。
Step2. 全てのポートテーブルエントリをFREE状態として初期化する。
Step3. フリーメッセージリストをリンクさせる。

Parameters
[in]maxmsgs全てのポート中の最大メッセージ数
Returns
初期化成功時はOK、メモリ確保失敗時はpanic状態となって再起動が必須となる。

Definition at line 24 of file ptinit.c.

References getmem(), NPORTS, NULL, OK, panic(), porttab, PT_FREE, ptnode::ptnext, ptnextid, ptentry::ptseq, ptentry::ptstate, and SYSERR.

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
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
メッセージリストのノード
Definition: ports.h:21
#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 ptnextid
次に試みるテーブルエントリ
Definition: ptinit.c:12
int32 ptseq
生成時に変更されたシーケンス
Definition: ports.h:44
char * getmem(uint32)
ヒープ領域を割り当て、最下位のワードアドレスを返す。
Definition: getmem.c:25
Here is the call graph for this function:

◆ ptrecv()

uint32 ptrecv ( int32  portid)

ポートからメッセージを受信する。受信前にメッセージが空の場合はブロッキングする。

Step1. 割り込みを禁止する。
Step2. ポートIDが不正、もしくはポートがALLOC状態でなければ割り込み状態を復元し、処理を終了する。
Step3. 送信側セマフォに空きが出るまで待機する。
セマフォ待機後、以下の状態のいずれかであれば割り込み状態を復元し、処理を終了する。
 ・セマフォ待機結果がエラー
 ・ポートがALLOC状態以外
 ・シーケンス番号が変化した場合
Step4. ポートフリーノードがNULL状態であれば(メッセージを使い果たした場合)、Panic状態とする。
Step5. ポートフリーノードからメッセージノード1個を切り出し、メッセージノードにメッセージを追加する。
Step6. メッセージノードをメッセージリストの末尾に追加する。
Step7. 受信セマフォにシグナルを送る。
Step8. 割り込み状態を復元する。

Parameters
[in]portid使用するポートのID
Returns
メッセージ送信時はOKを返し、以下の場合はSYSERRを返す。
 ・引数のポートIDが不正
・セマフォ待機結果がエラー
 ・ポートがALLOC状態以外
 ・シーケンス番号が変化した場合

Definition at line 29 of file ptrecv.c.

References disable(), isbadport, NULL, porttab, PT_ALLOC, ptfree, ptentry::pthead, ptnode::ptmsg, ptnode::ptnext, ptentry::ptrsem, ptentry::ptseq, ptentry::ptssem, ptentry::ptstate, ptentry::pttail, restore(), signal(), SYSERR, and wait().

30 {
31  intmask mask; /* Saved interrupt mask */
32  struct ptentry *ptptr; /* Pointer to table entry */
33  int32 seq; /* Local copy of sequence num. */
34  umsg32 msg; /* Message to return */
35  struct ptnode *msgnode; /* First node on message list */
36 
37  mask = disable();
38  if (isbadport(portid) ||
39  (ptptr = &porttab[portid])->ptstate != PT_ALLOC)
40  {
41  restore(mask);
42  return (uint32)SYSERR;
43  }
44 
45  /* Wait for message and verify that the port is still allocated */
46 
47  seq = ptptr->ptseq; /* Record orignal sequence */
48  if (wait(ptptr->ptrsem) == SYSERR || ptptr->ptstate != PT_ALLOC || ptptr->ptseq != seq)
49  {
50  restore(mask);
51  return (uint32)SYSERR;
52  }
53 
54  /* Dequeue first message that is waiting in the port */
55 
56  msgnode = ptptr->pthead;
57  msg = msgnode->ptmsg;
58  if (ptptr->pthead == ptptr->pttail) /* Delete last item */
59  ptptr->pthead = ptptr->pttail = NULL;
60  else
61  ptptr->pthead = msgnode->ptnext;
62  msgnode->ptnext = ptfree; /* Return to free list */
63  ptfree = msgnode;
64  signal(ptptr->ptssem);
65  restore(mask);
66  return msg;
67 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
void restore(intmask)
ポートテーブルエントリ
Definition: ports.h:33
#define isbadport(portid)
ポートIDが不正値かどうかを確認する。
Definition: ports.h:64
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define PT_ALLOC
ポートが割り当てられた
Definition: ports.h:15
sid32 ptrsem
受信側セマフォ
Definition: ports.h:38
メッセージリストのノード
Definition: ports.h:21
uint32 umsg32
プロセス間で渡されるメッセージ
Definition: kernel.h:32
struct ptentry porttab[]
ポートテーブルエントリのextern宣言
Definition: ptinit.c:10
struct ptnode * ptnext
メッセージリストの次のノードへのポインタ
Definition: ports.h:26
sid32 ptssem
送信側セマフォ
Definition: ports.h:36
uint16 ptstate
ポート状態(FREE/LIMBO/ALLOC)
Definition: ports.h:40
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
struct ptnode * pttail
メッセージリストの末尾ポインタ
Definition: ports.h:48
uint32 ptmsg
ワンワードのメッセージ
Definition: ports.h:24
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
struct ptnode * pthead
メッセージリストの先頭ポインタ
Definition: ports.h:46
int32 ptseq
生成時に変更されたシーケンス
Definition: ports.h:44
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
struct ptnode * ptfree
フリーノードリストのextern宣言
Definition: ptinit.c:8
Here is the call graph for this function:

◆ ptreset()

syscall ptreset ( int32  portid,
int32(*)(int32 disp 
)

ポートをリセットを行う。

待機中のプロセスとメッセージを解放した後、ポートを再利用できるようにする。
Step1. 割り込みを禁止する。
Step2. ポートIDが不正、もしくはポートがALLOC状態でなければ割り込み状態を復元し、処理を終了する。
Step3. ポートを用いたメッセージと待機中プロセスを解放し、セマフォはリセットする。
Step4. 割り込み状態を復元する。

Parameters
[in]portid削除対象のポート
[in]disp待機メッセージ処分用の関数ポインタ
Returns
成功時はOK、ポートIDが不正もしくはポートがALLOC状態以外の場合はSYSERRを返す。

Definition at line 21 of file ptreset.c.

References _ptclear(), disable(), isbadport, OK, porttab, PT_ALLOC, ptentry::ptstate, restore(), and SYSERR.

22 {
23  intmask mask; /* Saved interrupt mask */
24  struct ptentry *ptptr; /* Pointer to port table entry */
25 
26  mask = disable();
27  if (isbadport(portid) ||
28  (ptptr = &porttab[portid])->ptstate != PT_ALLOC)
29  {
30  restore(mask);
31  return SYSERR;
32  }
33  _ptclear(ptptr, PT_ALLOC, disp);
34  restore(mask);
35  return OK;
36 }
void _ptclear(struct ptentry *, uint16, int32(*)(int32))
ポートを用いたメッセージと待機中プロセスを解放する。
Definition: ptclear.c:24
void restore(intmask)
ポートテーブルエントリ
Definition: ports.h:33
#define isbadport(portid)
ポートIDが不正値かどうかを確認する。
Definition: ports.h:64
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define PT_ALLOC
ポートが割り当てられた
Definition: ports.h:15
#define OK
処理が成功した場合
Definition: kernel.h:77
struct ptentry porttab[]
ポートテーブルエントリのextern宣言
Definition: ptinit.c:10
uint16 ptstate
ポート状態(FREE/LIMBO/ALLOC)
Definition: ports.h:40
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:

◆ ptsend()

syscall ptsend ( int32  portid,
umsg32  msg 
)

メッセージをキューに追加する事によってポートへメッセージを送信する。

Step1. 割り込みを禁止する。
Step2. ポートIDが不正、もしくはポートがALLOC状態でなければ割り込み状態を復元し、処理を終了する。
Step3. 送信側セマフォに空きが出るまで待機する。
セマフォ待機後、以下の状態のいずれかであれば割り込み状態を復元し、処理を終了する。
 ・セマフォ待機結果がエラー
 ・ポートがALLOC状態以外
 ・シーケンス番号が変化した場合
Step4. ポートフリーノードがNULL状態であれば(メッセージを使い果たした場合)、Panic状態とする。
Step5. ポートフリーノードからメッセージノード1個を切り出し、メッセージノードにメッセージを追加する。
Step6. メッセージノードをメッセージリストの末尾に追加する。
Step7. 受信セマフォにシグナルを送る。
Step8. 割り込み状態を復元する。

Parameters
[in]portid使用するポートのID
[in]msg送信するメッセージ
Returns
メッセージ送信時はOKを返し、以下の場合はSYSERRを返す。
 ・引数のポートIDが不正
・セマフォ待機結果がエラー
 ・ポートがALLOC状態以外
 ・シーケンス番号が変化した場合
Note
ポートのメッセージノードが枯渇した場合は、システム再起動が必要となる。

Definition at line 31 of file ptsend.c.

References disable(), isbadport, NULL, OK, panic(), porttab, PT_ALLOC, ptfree, ptentry::pthead, ptnode::ptmsg, ptnode::ptnext, ptentry::ptrsem, ptentry::ptseq, ptentry::ptssem, ptentry::ptstate, ptentry::pttail, restore(), signal(), SYSERR, and wait().

32 {
33  intmask mask; /* Saved interrupt mask */
34  struct ptentry *ptptr; /* Pointer to table entry */
35  int32 seq; /* Local copy of sequence num. */
36  struct ptnode *msgnode; /* Allocated message node */
37  struct ptnode *tailnode; /* Last node in port or NULL */
38 
39  mask = disable();
40  if (isbadport(portid) ||
41  (ptptr = &porttab[portid])->ptstate != PT_ALLOC)
42  {
43  restore(mask);
44  return SYSERR;
45  }
46 
47  /* Wait for space and verify port has not been reset */
48  seq = ptptr->ptseq; /* Record original sequence */
49  if (wait(ptptr->ptssem) == SYSERR || ptptr->ptstate != PT_ALLOC || ptptr->ptseq != seq)
50  {
51  restore(mask);
52  return SYSERR;
53  }
54  if (ptfree == NULL)
55  {
56  panic("Port system ran out of message nodes");
57  }
58 
59  /* Obtain node from free list by unlinking */
60 
61  msgnode = ptfree; /* Point to first free node */
62  ptfree = msgnode->ptnext; /* Unlink from the free list */
63  msgnode->ptnext = NULL; /* Set fields in the node */
64  msgnode->ptmsg = msg;
65 
66  /* Link into queue for the specified port */
67 
68  tailnode = ptptr->pttail;
69  if (tailnode == NULL)
70  { /* Queue for port was empty */
71  ptptr->pttail = ptptr->pthead = msgnode;
72  }
73  else
74  { /* Insert new node at tail */
75  tailnode->ptnext = msgnode;
76  ptptr->pttail = msgnode;
77  }
78  signal(ptptr->ptrsem);
79  restore(mask);
80  return OK;
81 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
void restore(intmask)
ポートテーブルエントリ
Definition: ports.h:33
#define isbadport(portid)
ポートIDが不正値かどうかを確認する。
Definition: ports.h:64
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define PT_ALLOC
ポートが割り当てられた
Definition: ports.h:15
sid32 ptrsem
受信側セマフォ
Definition: ports.h:38
#define OK
処理が成功した場合
Definition: kernel.h:77
メッセージリストのノード
Definition: ports.h:21
struct ptentry porttab[]
ポートテーブルエントリのextern宣言
Definition: ptinit.c:10
struct ptnode * ptnext
メッセージリストの次のノードへのポインタ
Definition: ports.h:26
sid32 ptssem
送信側セマフォ
Definition: ports.h:36
uint16 ptstate
ポート状態(FREE/LIMBO/ALLOC)
Definition: ports.h:40
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
struct ptnode * pttail
メッセージリストの末尾ポインタ
Definition: ports.h:48
uint32 ptmsg
ワンワードのメッセージ
Definition: ports.h:24
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
struct ptnode * pthead
メッセージリストの先頭ポインタ
Definition: ports.h:46
int32 ptseq
生成時に変更されたシーケンス
Definition: ports.h:44
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
struct ptnode * ptfree
フリーノードリストのextern宣言
Definition: ptinit.c:8
Here is the call graph for this function:

◆ putc()

syscall putc ( did32  descrp,
char  ch 
)

デバイスへ文字1Byteを送信する。

Step1. 割り込みを禁止する。
Step2. デバイスディスクリプタが不正値の場合は、割り込み状態を復元し、処理を終了する。
Step3. デバイスに応じたputc()処理を行う。
Step4. 割り込み状態を復元する。

Parameters
[in]descrpデバイスディスクリプタ
[in]ch送信したい文字
Returns
成功時はデバイスに応じた返り値、デバイスディスクリプタが不正値の場合はSYSERRを返す。

Definition at line 18 of file putc.c.

Referenced by fprintf(), printf(), and xsh_cat().

19 {
20  intmask mask; /* Saved interrupt mask */
21  struct dentry *devptr; /* Entry in device switch table */
22  int32 retval; /* Value to return to caller */
23 
24  mask = disable();
25  if (isbaddev(descrp))
26  {
27  restore(mask);
28  return SYSERR;
29  }
30  devptr = (struct dentry *)&devtab[descrp];
31  retval = (*devptr->dvputc)(devptr, ch);
32  restore(mask);
33  return retval;
34 }
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
devcall(* dvputc)(struct dentry *, char)
Definition: conf.h:17
Definition: conf.h:6
struct dentry devtab[]
Definition: conf.c:11
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define isbaddev(f)
デバイスIDを検証するマクロ。
Definition: device.h:15
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the caller graph for this function:

◆ ramclose()

devcall ramclose ( struct dentry )

Definition at line 9 of file ramclose.c.

References OK.

12 {
13  return OK;
14 }
#define OK
処理が成功した場合
Definition: kernel.h:77

◆ raminit()

devcall raminit ( struct dentry )

Definition at line 17 of file raminit.c.

References ramdisk::disk, memcpy(), OK, Ram, RM_BLKS, and RM_BLKSIZ.

20 {
21  memcpy(Ram.disk, "hopeless", 8);
22  memcpy(&Ram.disk[8], Ram.disk, RM_BLKSIZ * RM_BLKS - 8);
23  return OK;
24 }
struct ramdisk Ram
RAMディスク操作用の構造体のextern宣言
Definition: raminit.c:11
#define OK
処理が成功した場合
Definition: kernel.h:77
char disk[RM_BLKSIZ *RM_BLKS]
RAMディスク操作用の配列
Definition: ramdisk.h:18
#define RM_BLKS
RAMディスクのブロック数
Definition: ramdisk.h:9
#define RM_BLKSIZ
RAMディスクのブロックサイズ
Definition: ramdisk.h:7
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
Here is the call graph for this function:

◆ ramopen()

devcall ramopen ( struct dentry ,
char *  ,
char *   
)

Definition at line 10 of file ramopen.c.

References dentry::dvnum.

15 {
16  /* No action -- just return the device descriptor */
17 
18  return devptr->dvnum;
19 }

◆ ramread()

devcall ramread ( struct dentry ,
char *  ,
int32   
)

Definition at line 10 of file ramread.c.

References ramdisk::disk, memcpy(), OK, Ram, and RM_BLKSIZ.

15 {
16  int32 bpos; /* Byte position of blk */
17 
18  bpos = RM_BLKSIZ * blk;
19  memcpy(buff, &Ram.disk[bpos], RM_BLKSIZ);
20  return OK;
21 }
#define OK
処理が成功した場合
Definition: kernel.h:77
struct ramdisk Ram
RAMディスク操作用の構造体のextern宣言
Definition: raminit.c:11
char disk[RM_BLKSIZ *RM_BLKS]
RAMディスク操作用の配列
Definition: ramdisk.h:18
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define RM_BLKSIZ
RAMディスクのブロックサイズ
Definition: ramdisk.h:7
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
Here is the call graph for this function:

◆ ramwrite()

devcall ramwrite ( struct dentry ,
char *  ,
int32   
)

Definition at line 10 of file ramwrite.c.

References ramdisk::disk, memcpy(), OK, Ram, and RM_BLKSIZ.

15 {
16  int32 bpos; /* Byte position of blk */
17 
18  bpos = RM_BLKSIZ * blk;
19  memcpy(&Ram.disk[bpos], buff, RM_BLKSIZ);
20  return OK;
21 }
#define OK
処理が成功した場合
Definition: kernel.h:77
struct ramdisk Ram
RAMディスク操作用の構造体のextern宣言
Definition: raminit.c:11
char disk[RM_BLKSIZ *RM_BLKS]
RAMディスク操作用の配列
Definition: ramdisk.h:18
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define RM_BLKSIZ
RAMディスクのブロックサイズ
Definition: ramdisk.h:7
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
Here is the call graph for this function:

◆ rawin()

process rawin ( void  )

◆ rdsbufalloc()

struct rdbuff * rdsbufalloc ( struct rdscblk )

Definition at line 9 of file rdsbufalloc.c.

References NULL, panic(), rdscblk::rd_availsem, rdscblk::rd_chnext, rdscblk::rd_ctprev, rdscblk::rd_free, rdbuff::rd_next, rdbuff::rd_prev, rdbuff::rd_refcnt, SYSERR, and wait().

Referenced by rdscontrol(), rdsread(), and rdswrite().

12 {
13  struct rdbuff *bptr; /* Pointer to a buffer */
14  struct rdbuff *pptr; /* Pointer to previous buffer */
15  struct rdbuff *nptr; /* Pointer to next buffer */
16 
17  /* Wait for an available buffer */
18 
19  wait(rdptr->rd_availsem);
20 
21  /* If free list contains a buffer, extract it */
22 
23  bptr = rdptr->rd_free;
24 
25  if ( bptr != (struct rdbuff *)NULL ) {
26  rdptr->rd_free = bptr->rd_next;
27  return bptr;
28  }
29 
30  /* Extract oldest item in cache that has ref count zero (at */
31  /* least one such entry must exist because the semaphore */
32  /* had a nonzero count) */
33 
34  bptr = rdptr->rd_ctprev;
35  while (bptr != (struct rdbuff *) &rdptr->rd_chnext) {
36  if (bptr->rd_refcnt <= 0) {
37 
38  /* Remove from cache and return to caller */
39 
40  pptr = bptr->rd_prev;
41  nptr = bptr->rd_next;
42  pptr->rd_next = nptr;
43  nptr->rd_prev = pptr;
44  return bptr;
45  }
46  bptr = bptr->rd_prev;
47  }
48  panic("Remote disk cannot find an available buffer");
49  return (struct rdbuff *)SYSERR;
50 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct rdbuff * rd_prev
Definition: rdisksys.h:57
int32 rd_refcnt
Definition: rdisksys.h:59
struct rdbuff * rd_next
Definition: rdisksys.h:56
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
syscall wait(sid32)
Definition: wait.c:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdsclose()

devcall rdsclose ( struct dentry )

Definition at line 9 of file rdsclose.c.

References dentry::dvminor, OK, rdscblk::rd_chnext, rdscblk::rd_ctnext, RD_FREE, rdscblk::rd_free, RD_INVALID, rdbuff::rd_next, RD_OPEN, rdbuff::rd_prev, rdscblk::rd_rhnext, rdscblk::rd_rtnext, rdscblk::rd_state, rdbuff::rd_status, rdstab, and SYSERR.

Referenced by rdscontrol().

12 {
13  struct rdscblk *rdptr; /* Ptr to control block entry */
14  struct rdbuff *bptr; /* Ptr to buffer on a list */
15  struct rdbuff *nptr; /* Ptr to next buff on the list */
16  int32 nmoved; /* Number of buffers moved */
17 
18  /* Device must be open */
19 
20  rdptr = &rdstab[devptr->dvminor];
21  if (rdptr->rd_state != RD_OPEN) {
22  return SYSERR;
23  }
24 
25  /* Request queue must be empty */
26 
27  if (rdptr->rd_rhnext != (struct rdbuff *)&rdptr->rd_rtnext) {
28  return SYSERR;
29  }
30 
31  /* Move all buffers from the cache to the free list */
32 
33  bptr = rdptr->rd_chnext;
34  nmoved = 0;
35  while (bptr != (struct rdbuff *)&rdptr->rd_ctnext) {
36  nmoved++;
37 
38  /* Unlink buffer from cache */
39 
40  nptr = bptr->rd_next;
41  (bptr->rd_prev)->rd_next = nptr;
42  nptr->rd_prev = bptr->rd_prev;
43 
44  /* Insert buffer into free list */
45 
46  bptr->rd_next = rdptr->rd_free;
47 
48  rdptr->rd_free = bptr;
49  bptr->rd_status = RD_INVALID;
50 
51  /* Move to next buffer in the cache */
52 
53  bptr = nptr;
54  }
55 
56  /* Set the state to indicate the device is closed */
57 
58  rdptr->rd_state = RD_FREE;
59  return OK;
60 }
#define RD_OPEN
Definition: rdisksys.h:37
#define RD_FREE
Definition: rdisksys.h:36
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct rdbuff * rd_rtnext
Definition: rdisksys.h:75
int32 rd_status
Definition: rdisksys.h:62
#define OK
処理が成功した場合
Definition: kernel.h:77
struct rdbuff * rd_free
Definition: rdisksys.h:87
struct rdbuff * rd_prev
Definition: rdisksys.h:57
struct rdbuff * rd_rhnext
Definition: rdisksys.h:73
struct rdscblk rdstab[]
Definition: rdsinit.c:11
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
struct rdbuff * rd_next
Definition: rdisksys.h:56
struct rdbuff * rd_ctnext
Definition: rdisksys.h:82
struct rdbuff * rd_chnext
Definition: rdisksys.h:80
int32 rd_state
Definition: rdisksys.h:69
#define RD_INVALID
Definition: rdisksys.h:49
Here is the caller graph for this function:

◆ rdscomm()

status rdscomm ( struct rd_msg_hdr ,
int32  ,
struct rd_msg_hdr ,
int32  ,
struct rdscblk  
)

Definition at line 11 of file rdscomm.c.

References disable(), FALSE, getlocalip(), htonl, network::ipvalid, kprintf(), NetData, ntohl, ntohs, OK, rdscblk::rd_loc_port, RD_MSG_RESPONSE, rdscblk::rd_registered, RD_RETRIES, rdscblk::rd_seq, rdscblk::rd_ser_ip, rdscblk::rd_ser_port, RD_TIMEOUT, rdscblk::rd_udpslot, restore(), SYSERR, TIMEOUT, TRUE, udp_recv(), udp_register(), and udp_sendto().

Referenced by rdscontrol(), rdsopen(), and rdsprocess().

18 {
19  intmask mask; /* Saved interrupt mask */
20  int32 i; /* Counts retries */
21  int32 retval; /* Return value */
22  int32 seq; /* Sequence for this exchange */
23  uint32 localip; /* Local IP address */
24  int16 rtype; /* Reply type in host byte order*/
25  bool8 xmit; /* Should we transmit again? */
26  int32 slot; /* UDP slot */
27 
28  /* Disable interrupts while testing status */
29 
30  mask = disable();
31 
32  /* Register the server port, if not registered */
33 
34  if ( ! rdptr->rd_registered ) {
35  slot = udp_register(0, rdptr->rd_ser_port,
36  rdptr->rd_loc_port);
37  if(slot == SYSERR) {
38  restore(mask);
39  return SYSERR;
40  }
41  rdptr->rd_udpslot = slot;
42  rdptr->rd_registered = TRUE;
43  }
44 
45  /* Get the local IP address */
46 
47  if ( NetData.ipvalid == FALSE ) {
48  localip = getlocalip();
49  if((int32)localip == SYSERR) {
50  restore(mask);
51  return SYSERR;
52  }
53  }
54  restore(mask);
55 
56  /* Retrieve the saved UDP slot number */
57 
58  slot = rdptr->rd_udpslot;
59 
60  /* Assign message next sequence number */
61 
62  seq = rdptr->rd_seq++;
63  msg->rd_seq = htonl(seq);
64 
65  /* Repeat RD_RETRIES times: send message and receive reply */
66 
67  xmit = TRUE;
68  for (i=0; i<RD_RETRIES; i++) {
69  if (xmit) {
70 
71  /* Send a copy of the message */
72 
73  retval = udp_sendto(slot, rdptr->rd_ser_ip, rdptr->rd_ser_port,
74  (char *)msg, mlen);
75  if (retval == SYSERR) {
76  kprintf("Cannot send to remote disk server\n\r");
77  return SYSERR;
78  }
79  } else {
80  xmit = TRUE;
81  }
82 
83  /* Receive a reply */
84 
85  retval = udp_recv(slot, (char *)reply, rlen,
86  RD_TIMEOUT);
87 
88  if (retval == TIMEOUT) {
89  continue;
90  } else if (retval == SYSERR) {
91  kprintf("Error reading remote disk reply\n\r");
92  return SYSERR;
93  }
94 
95  /* Verify that sequence in reply matches request */
96 
97 
98  if (ntohl(reply->rd_seq) < seq) {
99  xmit = FALSE;
100  } else if (ntohl(reply->rd_seq) != seq) {
101  continue;
102  }
103 
104  /* Verify the type in the reply matches the request */
105 
106  rtype = ntohs(reply->rd_type);
107  if (rtype != ( ntohs(msg->rd_type) | RD_MSG_RESPONSE) ) {
108  continue;
109  }
110 
111  /* Check the status */
112 
113  if (ntohs(reply->rd_status) != 0) {
114  return SYSERR;
115  }
116 
117  return OK;
118  }
119 
120  /* Retries exhausted without success */
121 
122  kprintf("Timeout on exchange with remote disk server\n\r");
123  return TIMEOUT;
124 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
int32 udp_recv(uid32, char *, int32, uint32)
Definition: udp.c:146
void restore(intmask)
struct network NetData
Definition: net.c:6
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define RD_MSG_RESPONSE
Definition: rdisksys.h:118
#define OK
処理が成功した場合
Definition: kernel.h:77
byte bool8
Boolean値
Definition: kernel.h:36
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
#define RD_RETRIES
Definition: rdisksys.h:105
#define ntohl(x)
Definition: prototypes.h:623
#define FALSE
Boolean False(0)
Definition: kernel.h:63
#define RD_TIMEOUT
Definition: rdisksys.h:106
#define TRUE
Boolean True(1)
Definition: kernel.h:65
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
short int16
符号あり16ビット整数(short)
Definition: kernel.h:13
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uid32 udp_register(uint32, uint16, uint16)
Definition: udp.c:85
#define ntohs(x)
Definition: prototypes.h:622
uint32 getlocalip(void)
Definition: dhcp.c:142
status udp_sendto(uid32, uint32, uint16, char *, int32)
Definition: udp.c:417
#define htonl(x)
Definition: prototypes.h:620
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
bool8 ipvalid
Definition: net.h:63
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdscontrol()

devcall rdscontrol ( struct dentry ,
int32  ,
int32  ,
int32   
)

Definition at line 9 of file rdscontrol.c.

References dentry::dvminor, getpid(), htons, kprintf(), memset(), ntohs, NULLCH, OK, rdbuff::rd_blknum, rdscblk::rd_comproc, rdscblk::rd_comruns, rdscblk::rd_id, RD_IDLEN, RD_INVALID, RD_MSG_DREQ, rdbuff::rd_next, rdbuff::rd_op, RD_OP_SYNC, RD_OPEN, rdbuff::rd_pid, rdbuff::rd_prev, rdbuff::rd_refcnt, rdscblk::rd_reqsem, rdscblk::rd_rtprev, rdscblk::rd_state, rdbuff::rd_status, RDS_CTL_DEL, RDS_CTL_SYNC, rdsbufalloc(), rdsclose(), rdscomm(), rdstab, receive(), recvclr(), resume(), signal(), SYSERR, TIMEOUT, and TRUE.

15 {
16  struct rdscblk *rdptr; /* Pointer to control block */
17  struct rdbuff *bptr; /* Ptr to buffer that will be */
18  /* placed on the req. queue */
19  struct rdbuff *pptr; /* Ptr to "previous" node on */
20  /* a list */
21  struct rd_msg_dreq msg; /* Buffer for delete request */
22  struct rd_msg_dres resp; /* Buffer for delete response */
23  char *to, *from; /* Used during name copy */
24  int32 retval; /* Return value */
25 
26  /* Verify that device is currently open */
27 
28  rdptr = &rdstab[devptr->dvminor];
29  if (rdptr->rd_state != RD_OPEN) {
30  return SYSERR;
31  }
32 
33  /* Ensure rdsprocess is runnning */
34 
35  if ( ! rdptr->rd_comruns ) {
36  rdptr->rd_comruns = TRUE;
37  resume(rdptr->rd_comproc);
38  }
39 
40  switch (func) {
41 
42  /* Synchronize writes */
43 
44  case RDS_CTL_SYNC:
45 
46  /* Allocate a buffer to use for the request list */
47 
48  bptr = rdsbufalloc(rdptr);
49  if (bptr == (struct rdbuff *)SYSERR) {
50  return SYSERR;
51  }
52 
53  /* Form a sync request */
54 
55  bptr->rd_op = RD_OP_SYNC;
56  bptr->rd_refcnt = 1;
57  bptr->rd_blknum = 0; /* Unused */
58  bptr->rd_status = RD_INVALID;
59  bptr->rd_pid = getpid();
60 
61  /* Insert new request into list just before tail */
62 
63  pptr = rdptr->rd_rtprev;
64  rdptr->rd_rtprev = bptr;
65  bptr->rd_next = pptr->rd_next;
66  bptr->rd_prev = pptr;
67  pptr->rd_next = bptr;
68 
69  /* Prepare to wait until item is processed */
70 
71  recvclr();
72 
73  /* Signal then semaphore to start communication */
74 
75  signal(rdptr->rd_reqsem);
76 
77  /* Block to wait for a message */
78 
79  bptr = (struct rdbuff *)receive();
80  if (bptr == (struct rdbuff *)SYSERR) {
81  return SYSERR;
82  }
83  break;
84 
85  /* Delete the remote disk (entirely remove it) */
86 
87  case RDS_CTL_DEL:
88 
89  /* Handcraft a message for the server that requests */
90  /* deleting the disk with the specified ID */
91 
92  msg.rd_type = htons(RD_MSG_DREQ);/* Request deletion */
93  msg.rd_status = htons(0);
94  msg.rd_seq = 0; /* rdscomm will insert sequence # later */
95  to = msg.rd_id;
96  memset(to, NULLCH, RD_IDLEN); /* Initialize to zeroes */
97  from = rdptr->rd_id;
98  while ( (*to++ = *from++) != NULLCH ) { /* copy ID */
99  ;
100  }
101 
102  /* Send message and receive response */
103 
104  retval = rdscomm((struct rd_msg_hdr *)&msg,
105  sizeof(struct rd_msg_dreq),
106  (struct rd_msg_hdr *)&resp,
107  sizeof(struct rd_msg_dres),
108  rdptr);
109 
110  /* Check response */
111 
112  if (retval == SYSERR) {
113  return SYSERR;
114  } else if (retval == TIMEOUT) {
115  kprintf("Timeout during remote file delete\n\r");
116  return SYSERR;
117  } else if (ntohs(resp.rd_status) != 0) {
118  return SYSERR;
119  }
120 
121  /* Close local device */
122 
123  return rdsclose(devptr);
124 
125  default:
126  kprintf("rfsControl: function %d not valid\n\r", func);
127  return SYSERR;
128  }
129 
130  return OK;
131 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define RD_OPEN
Definition: rdisksys.h:37
sid32 rd_reqsem
Definition: rdisksys.h:92
#define RDS_CTL_DEL
Definition: rdisksys.h:110
int32 rd_op
Definition: rdisksys.h:58
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define RD_IDLEN
Definition: rdisksys.h:29
int32 rd_status
Definition: rdisksys.h:62
#define OK
処理が成功した場合
Definition: kernel.h:77
umsg32 receive(void)
メッセージの受信を待ち、受信後にreceive()の呼び出し者にメッセージを返す。
Definition: receive.c:17
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
pid32 rd_comproc
Definition: rdisksys.h:89
bool8 rd_comruns
Definition: rdisksys.h:90
struct rdbuff * rd_prev
Definition: rdisksys.h:57
devcall rdsclose(struct dentry *)
Definition: rdsclose.c:9
#define TRUE
Boolean True(1)
Definition: kernel.h:65
umsg32 recvclr(void)
受信メッセージをクリアし、待機している場合はメッセージを返す。
Definition: recvclr.c:14
#define RD_OP_SYNC
Definition: rdisksys.h:44
struct rdscblk rdstab[]
Definition: rdsinit.c:11
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 rd_refcnt
Definition: rdisksys.h:59
struct rdbuff * rd_next
Definition: rdisksys.h:56
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
pri16 resume(pid32)
プロセスを休止状態(サスペンド)からREADY状態に遷移させる。
Definition: resume.c:20
#define ntohs(x)
Definition: prototypes.h:622
pid32 getpid(void)
現在実行中のプロセスIDを返す。
Definition: getpid.c:11
#define RD_MSG_DREQ
Definition: rdisksys.h:132
pid32 rd_pid
Definition: rdisksys.h:63
struct rdbuff * rdsbufalloc(struct rdscblk *)
Definition: rdsbufalloc.c:9
struct rdbuff * rd_rtprev
Definition: rdisksys.h:76
status rdscomm(struct rd_msg_hdr *, int32, struct rd_msg_hdr *, int32, struct rdscblk *)
Definition: rdscomm.c:11
#define RDS_CTL_SYNC
Definition: rdisksys.h:111
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
int32 rd_state
Definition: rdisksys.h:69
char rd_id[RD_IDLEN]
Definition: rdisksys.h:70
#define htons(x)
Definition: prototypes.h:619
uint32 rd_blknum
Definition: rdisksys.h:61
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
#define RD_INVALID
Definition: rdisksys.h:49
Here is the call graph for this function:

◆ rdsinit()

devcall rdsinit ( struct dentry )

Definition at line 17 of file rdsinit.c.

References create(), dot2ip(), dentry::dvminor, FALSE, getmem(), NULL, NULLCH, OK, panic(), rdscblk::rd_availsem, RD_BUFFS, rdscblk::rd_chnext, rdscblk::rd_chprev, rdscblk::rd_comproc, rdscblk::rd_comruns, rdscblk::rd_ctnext, rdscblk::rd_ctprev, RD_FREE, rdscblk::rd_free, rdscblk::rd_id, RD_INVALID, RD_LOC_PORT, rdscblk::rd_loc_port, rdbuff::rd_next, RD_PRIO, rdscblk::rd_registered, rdscblk::rd_reqsem, rdscblk::rd_rhnext, rdscblk::rd_rhprev, rdscblk::rd_rtnext, rdscblk::rd_rtprev, rdscblk::rd_seq, rdscblk::rd_ser_ip, rdscblk::rd_ser_port, RD_SERVER_IP, RD_SERVER_PORT, RD_STACK, rdscblk::rd_state, rdbuff::rd_status, rdsprocess(), rdstab, semcreate(), and SYSERR.

20 {
21  struct rdscblk *rdptr; /* Ptr to device contol block */
22  struct rdbuff *bptr; /* Ptr to buffer in memory */
23  /* used to form linked list */
24  struct rdbuff *pptr; /* Ptr to previous buff on list */
25  struct rdbuff *buffend; /* Last address in buffer memory*/
26  uint32 size; /* Total size of memory needed */
27  /* buffers */
28 
29  /* Obtain address of control block */
30 
31  rdptr = &rdstab[devptr->dvminor];
32 
33  /* Set control block to unused */
34 
35  rdptr->rd_state = RD_FREE;
36 
37  /* Create the resprocess and leave it suspended. */
38  /* Note: the process cannot be resumed because */
39  /* device initialization occurs before interrupts */
40  /* are enabled. */
41 
43  "rdsproc", 1, rdptr);
44  if (rdptr->rd_comproc == SYSERR)
45  {
46  panic("Cannot create remote disk process");
47  }
48  rdptr->rd_comruns = FALSE;
49 
50  rdptr->rd_id[0] = NULLCH;
51 
52  /* Set initial message sequence number */
53 
54  rdptr->rd_seq = 1;
55 
56  /* Initialize request queue and cache to empty */
57 
58  rdptr->rd_rhnext = (struct rdbuff *)&rdptr->rd_rtnext;
59  rdptr->rd_rhprev = (struct rdbuff *)NULL;
60 
61  rdptr->rd_rtnext = (struct rdbuff *)NULL;
62  rdptr->rd_rtprev = (struct rdbuff *)&rdptr->rd_rhnext;
63 
64  rdptr->rd_chnext = (struct rdbuff *)&rdptr->rd_ctnext;
65  rdptr->rd_chprev = (struct rdbuff *)NULL;
66 
67  rdptr->rd_ctnext = (struct rdbuff *)NULL;
68  rdptr->rd_ctprev = (struct rdbuff *)&rdptr->rd_chnext;
69 
70  /* Allocate memory for a set of buffers (actually request */
71  /* blocks and link them to form the initial free list */
72 
73  size = sizeof(struct rdbuff) * RD_BUFFS;
74 
75  bptr = (struct rdbuff *)getmem(size);
76  rdptr->rd_free = bptr;
77 
78  if ((int32)bptr == SYSERR)
79  {
80  panic("Cannot allocate memory for remote disk buffers");
81  }
82 
83  pptr = (struct rdbuff *)NULL; /* To avoid a compiler warning */
84  buffend = (struct rdbuff *)((char *)bptr + size);
85  while (bptr < buffend)
86  { /* walk through memory */
87  pptr = bptr;
88  bptr = (struct rdbuff *)(sizeof(struct rdbuff) + (char *)bptr);
89  pptr->rd_status = RD_INVALID; /* Buffer is empty */
90  pptr->rd_next = bptr; /* Point to next buffer */
91  }
92  pptr->rd_next = (struct rdbuff *)NULL; /* Last buffer on list */
93 
94  /* Create the request list and available buffer semaphores */
95 
96  rdptr->rd_availsem = semcreate(RD_BUFFS);
97  rdptr->rd_reqsem = semcreate(0);
98 
99  /* Set the server IP address, server port, and local port */
100 
101  if (dot2ip(RD_SERVER_IP, &rdptr->rd_ser_ip) == SYSERR)
102  {
103  panic("invalid IP address for remote disk server");
104  }
105 
106  /* Set the port numbers */
107 
108  rdptr->rd_ser_port = RD_SERVER_PORT;
109  rdptr->rd_loc_port = RD_LOC_PORT + devptr->dvminor;
110 
111  /* Specify that the server port is not yet registered */
112 
113  rdptr->rd_registered = FALSE;
114 
115  return OK;
116 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
#define RD_FREE
Definition: rdisksys.h:36
uint16 rd_loc_port
Definition: rdisksys.h:95
uint32 rd_ser_ip
Definition: rdisksys.h:93
#define RD_SERVER_IP
Definition: rdisksys.h:14
sid32 rd_reqsem
Definition: rdisksys.h:92
sid32 semcreate(int32)
未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。
Definition: semcreate.c:22
#define RD_SERVER_PORT
Definition: rdisksys.h:18
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
bool8 rd_registered
Definition: rdisksys.h:96
struct rdbuff * rd_rtnext
Definition: rdisksys.h:75
int32 rd_status
Definition: rdisksys.h:62
#define OK
処理が成功した場合
Definition: kernel.h:77
sid32 rd_availsem
Definition: rdisksys.h:91
pid32 rd_comproc
Definition: rdisksys.h:89
bool8 rd_comruns
Definition: rdisksys.h:90
struct rdbuff * rd_chprev
Definition: rdisksys.h:81
uint16 rd_ser_port
Definition: rdisksys.h:94
struct rdbuff * rd_free
Definition: rdisksys.h:87
struct rdscblk rdstab[Nrds]
Definition: rdsinit.c:11
#define FALSE
Boolean False(0)
Definition: kernel.h:63
struct rdbuff * rd_rhnext
Definition: rdisksys.h:73
#define RD_STACK
Definition: rdisksys.h:31
struct rdbuff * rd_rhprev
Definition: rdisksys.h:74
#define RD_BUFFS
Definition: rdisksys.h:30
#define RD_LOC_PORT
Definition: rdisksys.h:22
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
struct rdbuff * rd_next
Definition: rdisksys.h:56
void rdsprocess(struct rdscblk *)
Definition: rdsprocess.c:12
pid32 create(void *, uint32, pri16, char *, uint32,...)
関数の実行を開始するプロセスを作成する。
Definition: create.c:55
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
struct rdbuff * rd_rtprev
Definition: rdisksys.h:76
int32 rd_seq
Definition: rdisksys.h:71
#define RD_PRIO
Definition: rdisksys.h:32
struct rdbuff * rd_ctnext
Definition: rdisksys.h:82
struct rdbuff * rd_ctprev
Definition: rdisksys.h:83
struct rdbuff * rd_chnext
Definition: rdisksys.h:80
int32 rd_state
Definition: rdisksys.h:69
char rd_id[RD_IDLEN]
Definition: rdisksys.h:70
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
uint32 dot2ip(char *, uint32 *)
Definition: dot2ip.c:9
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
#define RD_INVALID
Definition: rdisksys.h:49
char * getmem(uint32)
ヒープ領域を割り当て、最下位のワードアドレスを返す。
Definition: getmem.c:25
Here is the call graph for this function:

◆ rdsopen()

devcall rdsopen ( struct dentry ,
char *  ,
char *   
)

Definition at line 10 of file rdsopen.c.

References dentry::dvminor, dentry::dvnum, htons, kprintf(), memset(), ntohs, NULLCH, RD_FREE, rdscblk::rd_id, RD_IDLEN, RD_MSG_OREQ, RD_OPEN, RD_PEND, rdscblk::rd_state, rdscomm(), rdstab, SYSERR, and TIMEOUT.

15 {
16  struct rdscblk *rdptr; /* Ptr to control block entry */
17  struct rd_msg_oreq msg; /* Message to be sent */
18  struct rd_msg_ores resp; /* Buffer to hold response */
19  int32 retval; /* Return value from rdscomm */
20  int32 len; /* Counts chars in diskid */
21  char *idto; /* Ptr to ID string copy */
22  char *idfrom; /* Pointer into ID string */
23 
24  rdptr = &rdstab[devptr->dvminor];
25 
26  /* Reject if device is already open */
27 
28  if (rdptr->rd_state != RD_FREE) {
29  return SYSERR;
30  }
31  rdptr->rd_state = RD_PEND;
32 
33  /* Copy disk ID into free table slot */
34 
35  idto = rdptr->rd_id;
36  idfrom = diskid;
37  len = 0;
38  while ( (*idto++ = *idfrom++) != NULLCH) {
39  len++;
40  if (len >= RD_IDLEN) { /* ID string is too long */
41  return SYSERR;
42  }
43  }
44 
45  /* Verify that name is non-null */
46 
47  if (len == 0) {
48  return SYSERR;
49  }
50 
51  /* Hand-craft an open request message to be sent to the server */
52 
53  msg.rd_type = htons(RD_MSG_OREQ);/* Request an open */
54  msg.rd_status = htons(0);
55  msg.rd_seq = 0; /* Rdscomm fills in an entry */
56  idto = msg.rd_id;
57  memset(idto, NULLCH, RD_IDLEN);/* initialize ID to zero bytes */
58 
59  idfrom = diskid;
60  while ( (*idto++ = *idfrom++) != NULLCH ) { /* Copy ID to req. */
61  ;
62  }
63 
64  /* Send message and receive response */
65 
66  retval = rdscomm((struct rd_msg_hdr *)&msg,
67  sizeof(struct rd_msg_oreq),
68  (struct rd_msg_hdr *)&resp,
69  sizeof(struct rd_msg_ores),
70  rdptr );
71 
72  /* Check response */
73 
74  if (retval == SYSERR) {
75  rdptr->rd_state = RD_FREE;
76  return SYSERR;
77  } else if (retval == TIMEOUT) {
78  kprintf("Timeout during remote file open\n\r");
79  rdptr->rd_state = RD_FREE;
80  return SYSERR;
81  } else if (ntohs(resp.rd_status) != 0) {
82  rdptr->rd_state = RD_FREE;
83  return SYSERR;
84  }
85 
86  /* Change state of device to indicate currently open */
87 
88  rdptr->rd_state = RD_OPEN;
89 
90  /* Return device descriptor */
91 
92  return devptr->dvnum;
93 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define RD_OPEN
Definition: rdisksys.h:37
#define RD_FREE
Definition: rdisksys.h:36
#define RD_PEND
Definition: rdisksys.h:38
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define RD_IDLEN
Definition: rdisksys.h:29
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
struct rdscblk rdstab[]
Definition: rdsinit.c:11
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
#define ntohs(x)
Definition: prototypes.h:622
#define RD_MSG_OREQ
Definition: rdisksys.h:126
status rdscomm(struct rd_msg_hdr *, int32, struct rd_msg_hdr *, int32, struct rdscblk *)
Definition: rdscomm.c:11
int32 rd_state
Definition: rdisksys.h:69
char rd_id[RD_IDLEN]
Definition: rdisksys.h:70
#define htons(x)
Definition: prototypes.h:619
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:

◆ rdsprocess()

void rdsprocess ( struct rdscblk )

Definition at line 12 of file rdsprocess.c.

References htons, memset(), ntohs, NULLCH, OK, panic(), rdscblk::rd_availsem, rdbuff::rd_blknum, RD_BLKSIZ, rdbuff::rd_block, rdscblk::rd_chnext, rdscblk::rd_free, rdscblk::rd_id, RD_IDLEN, RD_MSG_RREQ, RD_MSG_WREQ, rdbuff::rd_next, rdbuff::rd_op, RD_OP_READ, RD_OP_SYNC, RD_OP_WRITE, rdbuff::rd_pid, rdbuff::rd_prev, rdbuff::rd_refcnt, rdscblk::rd_reqsem, rdscblk::rd_rhnext, rdscblk::rd_rtnext, rdscomm(), send(), signal(), SYSERR, TIMEOUT, TRUE, and wait().

Referenced by rdsinit().

15 {
16  struct rd_msg_wreq msg; /* Message to be sent */
17  /* (includes data area) */
18  struct rd_msg_rres resp; /* Buffer to hold response */
19  /* (includes data area) */
20  int32 retval; /* Return value from rdscomm */
21  char *idto; /* Ptr to ID string copy */
22  char *idfrom; /* Ptr into ID string */
23  struct rdbuff *bptr; /* Ptr to buffer at the head of */
24  /* the request queue */
25  struct rdbuff *nptr; /* Ptr to next buffer on the */
26  /* request queue */
27  struct rdbuff *pptr; /* Ptr to previous buffer */
28  struct rdbuff *qptr; /* Ptr that runs along the */
29  /* request queue */
30  int32 i; /* Loop index */
31 
32  while (TRUE) { /* Do forever */
33 
34  /* Wait until the request queue contains a node */
35  wait(rdptr->rd_reqsem);
36  bptr = rdptr->rd_rhnext;
37 
38  /* Use operation in request to determine action */
39 
40  switch (bptr->rd_op) {
41 
42  case RD_OP_READ:
43 
44  /* Build a read request message for the server */
45 
46  msg.rd_type = htons(RD_MSG_RREQ); /* Read request */
47  msg.rd_status = htons(0);
48  msg.rd_seq = 0; /* Rdscomm fills in an entry */
49  idto = msg.rd_id;
50  memset(idto, NULLCH, RD_IDLEN);/* Initialize ID to zero */
51  idfrom = rdptr->rd_id;
52  while ( (*idto++ = *idfrom++) != NULLCH ) { /* Copy ID */
53  ;
54  }
55 
56  /* Send the message and receive a response */
57 
58  retval = rdscomm((struct rd_msg_hdr *)&msg,
59  sizeof(struct rd_msg_rreq),
60  (struct rd_msg_hdr *)&resp,
61  sizeof(struct rd_msg_rres),
62  rdptr );
63 
64  /* Check response */
65 
66  if ( (retval == SYSERR) || (retval == TIMEOUT) ||
67  (ntohs(resp.rd_status) != 0) ) {
68  panic("Failed to contact remote disk server");
69  }
70 
71  /* Copy data from the reply into the buffer */
72 
73  for (i=0; i<RD_BLKSIZ; i++) {
74  bptr->rd_block[i] = resp.rd_data[i];
75  }
76 
77  /* Unlink buffer from the request queue */
78 
79  nptr = bptr->rd_next;
80  pptr = bptr->rd_prev;
81  nptr->rd_prev = bptr->rd_prev;
82  pptr->rd_next = bptr->rd_next;
83 
84  /* Insert buffer in the cache */
85 
86  pptr = (struct rdbuff *) &rdptr->rd_chnext;
87  nptr = pptr->rd_next;
88  bptr->rd_next = nptr;
89  bptr->rd_prev = pptr;
90  pptr->rd_next = bptr;
91  nptr->rd_prev = bptr;
92 
93  /* Initialize reference count */
94 
95  bptr->rd_refcnt = 1;
96 
97  /* Signal the available semaphore */
98 
99  signal(rdptr->rd_availsem);
100 
101  /* Send a message to waiting process */
102 
103  send(bptr->rd_pid, (uint32)bptr);
104 
105  /* If other processes are waiting to read the */
106  /* block, notify them and remove the request */
107 
108  qptr = rdptr->rd_rhnext;
109  while (qptr != (struct rdbuff *)&rdptr->rd_rtnext) {
110  if (qptr->rd_blknum == bptr->rd_blknum) {
111  bptr->rd_refcnt++;
112  send(qptr->rd_pid,(uint32)bptr);
113 
114  /* Unlink request from queue */
115 
116  pptr = qptr->rd_prev;
117  nptr = qptr->rd_next;
118  pptr->rd_next = bptr->rd_next;
119  nptr->rd_prev = bptr->rd_prev;
120 
121  /* Move buffer to the free list */
122 
123  qptr->rd_next = rdptr->rd_free;
124  rdptr->rd_free = qptr;
125  signal(rdptr->rd_availsem);
126  break;
127  }
128  qptr = qptr->rd_next;
129  }
130  break;
131 
132  case RD_OP_WRITE:
133 
134  /* Build a write request message for the server */
135 
136  msg.rd_type = htons(RD_MSG_WREQ); /* Write request*/
137  msg.rd_blk = bptr->rd_blknum;
138  msg.rd_status = htons(0);
139  msg.rd_seq = 0; /* Rdscomb fills in an entry */
140  idto = msg.rd_id;
141  memset(idto, NULLCH, RD_IDLEN);/* Initialize ID to zero */
142  idfrom = rdptr->rd_id;
143  while ( (*idto++ = *idfrom++) != NULLCH ) { /* Copy ID */
144  ;
145  }
146  for (i=0; i<RD_BLKSIZ; i++) {
147  msg.rd_data[i] = bptr->rd_block[i];
148  }
149 
150  /* Unlink buffer from request queue */
151 
152  nptr = bptr->rd_next;
153  pptr = bptr->rd_prev;
154  pptr->rd_next = nptr;
155  nptr->rd_prev = pptr;
156 
157  /* Insert buffer in the cache */
158 
159  pptr = (struct rdbuff *) &rdptr->rd_chnext;
160  nptr = pptr->rd_next;
161  bptr->rd_next = nptr;
162  bptr->rd_prev = pptr;
163  pptr->rd_next = bptr;
164  nptr->rd_prev = bptr;
165 
166  /* Declare that buffer is eligible for reuse */
167 
168  bptr->rd_refcnt = 0;
169  signal(rdptr->rd_availsem);
170 
171  /* Send the message and receive a response */
172 
173  retval = rdscomm((struct rd_msg_hdr *)&msg,
174  sizeof(struct rd_msg_wreq),
175  (struct rd_msg_hdr *)&resp,
176  sizeof(struct rd_msg_wres),
177  rdptr );
178 
179  /* Check response */
180 
181  if ( (retval == SYSERR) || (retval == TIMEOUT) ||
182  (ntohs(resp.rd_status) != 0) ) {
183  panic("failed to contact remote disk server");
184  }
185  break;
186 
187  case RD_OP_SYNC:
188 
189  /* Send a message to the waiting process */
190 
191  send(bptr->rd_pid, OK);
192 
193  /* Unlink buffer from the request queue */
194 
195  nptr = bptr->rd_next;
196  pptr = bptr->rd_prev;
197  nptr->rd_prev = bptr->rd_prev;
198  pptr->rd_next = bptr->rd_next;
199 
200  /* Insert buffer into the free list */
201 
202  bptr->rd_next = rdptr->rd_free;
203  rdptr->rd_free = bptr;
204  signal(rdptr->rd_availsem);
205  break;
206  }
207  }
208 }
#define RD_OP_WRITE
Definition: rdisksys.h:43
#define RD_MSG_RREQ
Definition: rdisksys.h:120
#define RD_BLKSIZ
Definition: rdisksys.h:9
int32 rd_op
Definition: rdisksys.h:58
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define RD_IDLEN
Definition: rdisksys.h:29
#define OK
処理が成功した場合
Definition: kernel.h:77
syscall send(pid32, umsg32)
プロセスにメッセージを送信し、受信側が待機状態の場合はREADY状態にする。
Definition: send.c:21
#define RD_OP_READ
Definition: rdisksys.h:42
#define RD_MSG_WREQ
Definition: rdisksys.h:123
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
struct rdbuff * rd_prev
Definition: rdisksys.h:57
#define TRUE
Boolean True(1)
Definition: kernel.h:65
#define RD_OP_SYNC
Definition: rdisksys.h:44
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 rd_refcnt
Definition: rdisksys.h:59
struct rdbuff * rd_next
Definition: rdisksys.h:56
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
#define ntohs(x)
Definition: prototypes.h:622
pid32 rd_pid
Definition: rdisksys.h:63
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
status rdscomm(struct rd_msg_hdr *, int32, struct rd_msg_hdr *, int32, struct rdscblk *)
Definition: rdscomm.c:11
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
#define htons(x)
Definition: prototypes.h:619
char rd_block[RD_BLKSIZ]
Definition: rdisksys.h:65
uint32 rd_blknum
Definition: rdisksys.h:61
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdsread()

devcall rdsread ( struct dentry ,
char *  ,
int32   
)

Definition at line 9 of file rdsread.c.

References dentry::dvminor, getpid(), memcpy(), OK, rdbuff::rd_blknum, RD_BLKSIZ, rdbuff::rd_block, rdscblk::rd_chnext, rdscblk::rd_comproc, rdscblk::rd_comruns, rdscblk::rd_ctnext, rdscblk::rd_free, RD_INVALID, rdbuff::rd_next, rdbuff::rd_op, RD_OP_READ, RD_OP_WRITE, RD_OPEN, rdbuff::rd_pid, rdbuff::rd_prev, rdbuff::rd_refcnt, rdscblk::rd_reqsem, rdscblk::rd_rhnext, rdscblk::rd_rtprev, rdscblk::rd_state, rdbuff::rd_status, rdsbufalloc(), rdstab, receive(), recvclr(), resume(), signal(), SYSERR, and TRUE.

14 {
15  struct rdscblk *rdptr; /* Pointer to control block */
16  struct rdbuff *bptr; /* Pointer to buffer possibly */
17  /* in the request list */
18  struct rdbuff *nptr; /* Pointer to "next" node on a */
19  /* list */
20  struct rdbuff *pptr; /* Pointer to "previous" node */
21  /* on a list */
22  struct rdbuff *cptr; /* Pointer that walks the cache */
23 
24  /* If device not currently in use, report an error */
25 
26  rdptr = &rdstab[devptr->dvminor];
27  if (rdptr->rd_state != RD_OPEN) {
28  return SYSERR;
29  }
30 
31  /* Ensure rdsprocess is runnning */
32 
33  if ( ! rdptr->rd_comruns ) {
34  rdptr->rd_comruns = TRUE;
35  resume(rdptr->rd_comproc);
36  }
37 
38  /* Search the cache for specified block */
39 
40  bptr = rdptr->rd_chnext;
41  while (bptr != (struct rdbuff *)&rdptr->rd_ctnext) {
42  if (bptr->rd_blknum == blk) {
43  if (bptr->rd_status == RD_INVALID) {
44  break;
45  }
46  memcpy(buff, bptr->rd_block, RD_BLKSIZ);
47  return OK;
48  }
49  bptr = bptr->rd_next;
50  }
51 
52  /* Search the request list for most recent occurrence of block */
53 
54  bptr = rdptr->rd_rtprev; /* Start at tail of list */
55 
56  while (bptr != (struct rdbuff *)&rdptr->rd_rhnext) {
57  if (bptr->rd_blknum == blk) {
58 
59  /* If most recent request for block is write, copy data */
60 
61  if (bptr->rd_op == RD_OP_WRITE) {
62  memcpy(buff, bptr->rd_block, RD_BLKSIZ);
63  return OK;
64  }
65  break;
66  }
67  bptr = bptr->rd_prev;
68  }
69 
70  /* Allocate a buffer and add read request to tail of req. queue */
71 
72  bptr = rdsbufalloc(rdptr);
73  bptr->rd_op = RD_OP_READ;
74  bptr->rd_refcnt = 1;
75  bptr->rd_blknum = blk;
76  bptr->rd_status = RD_INVALID;
77  bptr->rd_pid = getpid();
78 
79  /* Insert new request into list just before tail */
80 
81  pptr = rdptr->rd_rtprev;
82  rdptr->rd_rtprev = bptr;
83  bptr->rd_next = pptr->rd_next;
84  bptr->rd_prev = pptr;
85  pptr->rd_next = bptr;
86 
87  /* Prepare to receive message when read completes */
88 
89  recvclr();
90 
91  /* Signal the semaphore to start communication */
92 
93  signal(rdptr->rd_reqsem);
94 
95  /* Block to wait for a message */
96 
97  bptr = (struct rdbuff *)receive();
98  if (bptr == (struct rdbuff *)SYSERR) {
99  return SYSERR;
100  }
101  memcpy(buff, bptr->rd_block, RD_BLKSIZ);
102  bptr->rd_refcnt--;
103  if (bptr->rd_refcnt <= 0) {
104 
105  /* Look for previous item in cache with the same block */
106  /* number to see if this item was only being kept */
107  /* until pending read completed */
108 
109  cptr = rdptr->rd_chnext;
110  while (cptr != bptr) {
111  if (cptr->rd_blknum == blk) {
112 
113  /* Unlink from cache */
114 
115  pptr = bptr->rd_prev;
116  nptr = bptr->rd_next;
117  pptr->rd_next = nptr;
118  nptr->rd_prev = pptr;
119 
120  /* Add to the free list */
121 
122  bptr->rd_next = rdptr->rd_free;
123  rdptr->rd_free = bptr;
124  break;
125  }
126  cptr = cptr->rd_next;
127  }
128  }
129  return OK;
130 }
#define RD_OP_WRITE
Definition: rdisksys.h:43
#define RD_OPEN
Definition: rdisksys.h:37
#define RD_BLKSIZ
Definition: rdisksys.h:9
sid32 rd_reqsem
Definition: rdisksys.h:92
int32 rd_op
Definition: rdisksys.h:58
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
int32 rd_status
Definition: rdisksys.h:62
#define OK
処理が成功した場合
Definition: kernel.h:77
#define RD_OP_READ
Definition: rdisksys.h:42
umsg32 receive(void)
メッセージの受信を待ち、受信後にreceive()の呼び出し者にメッセージを返す。
Definition: receive.c:17
pid32 rd_comproc
Definition: rdisksys.h:89
bool8 rd_comruns
Definition: rdisksys.h:90
struct rdbuff * rd_free
Definition: rdisksys.h:87
struct rdbuff * rd_prev
Definition: rdisksys.h:57
struct rdbuff * rd_rhnext
Definition: rdisksys.h:73
#define TRUE
Boolean True(1)
Definition: kernel.h:65
umsg32 recvclr(void)
受信メッセージをクリアし、待機している場合はメッセージを返す。
Definition: recvclr.c:14
struct rdscblk rdstab[]
Definition: rdsinit.c:11
int32 rd_refcnt
Definition: rdisksys.h:59
struct rdbuff * rd_next
Definition: rdisksys.h:56
pri16 resume(pid32)
プロセスを休止状態(サスペンド)からREADY状態に遷移させる。
Definition: resume.c:20
pid32 getpid(void)
現在実行中のプロセスIDを返す。
Definition: getpid.c:11
pid32 rd_pid
Definition: rdisksys.h:63
struct rdbuff * rdsbufalloc(struct rdscblk *)
Definition: rdsbufalloc.c:9
struct rdbuff * rd_rtprev
Definition: rdisksys.h:76
struct rdbuff * rd_ctnext
Definition: rdisksys.h:82
struct rdbuff * rd_chnext
Definition: rdisksys.h:80
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
int32 rd_state
Definition: rdisksys.h:69
char rd_block[RD_BLKSIZ]
Definition: rdisksys.h:65
uint32 rd_blknum
Definition: rdisksys.h:61
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
#define RD_INVALID
Definition: rdisksys.h:49
Here is the call graph for this function:

◆ rdswrite()

devcall rdswrite ( struct dentry ,
char *  ,
int32   
)

Definition at line 9 of file rdswrite.c.

References dentry::dvminor, FALSE, getpid(), memcpy(), OK, rdscblk::rd_availsem, rdbuff::rd_blknum, RD_BLKSIZ, rdbuff::rd_block, rdscblk::rd_chnext, rdscblk::rd_comproc, rdscblk::rd_comruns, rdscblk::rd_ctnext, rdbuff::rd_next, rdbuff::rd_op, RD_OP_WRITE, RD_OPEN, rdbuff::rd_pid, rdbuff::rd_prev, rdbuff::rd_refcnt, rdscblk::rd_reqsem, rdscblk::rd_rhnext, rdscblk::rd_rtnext, rdscblk::rd_rtprev, rdscblk::rd_state, rdbuff::rd_status, RD_VALID, rdsbufalloc(), rdstab, resume(), semcount(), semreset(), signal(), SYSERR, and TRUE.

14 {
15  struct rdscblk *rdptr; /* Pointer to control block */
16  struct rdbuff *bptr; /* Pointer to buffer on a list */
17  struct rdbuff *pptr; /* Ptr to previous buff on list */
18  struct rdbuff *nptr; /* Ptr to next buffer on list */
19  bool8 found; /* Was buff found during search?*/
20 
21  /* If device not currently in use, report an error */
22 
23  rdptr = &rdstab[devptr->dvminor];
24  if (rdptr->rd_state != RD_OPEN) {
25  return SYSERR;
26  }
27 
28  /* Ensure rdsprocess is runnning */
29 
30  if ( ! rdptr->rd_comruns ) {
31  rdptr->rd_comruns = TRUE;
32  resume(rdptr->rd_comproc);
33  }
34 
35  /* If request queue already contains a write request */
36  /* for the block, replace the contents */
37 
38  bptr = rdptr->rd_rhnext;
39  while (bptr != (struct rdbuff *)&rdptr->rd_rtnext) {
40  if ( (bptr->rd_blknum == blk) &&
41  (bptr->rd_op == RD_OP_WRITE) ) {
42  memcpy(bptr->rd_block, buff, RD_BLKSIZ);
43  return OK;
44  }
45  bptr = bptr->rd_next;
46  }
47 
48  /* Search cache for cached copy of block */
49 
50  bptr = rdptr->rd_chnext;
51  found = FALSE;
52  while (bptr != (struct rdbuff *)&rdptr->rd_ctnext) {
53  if (bptr->rd_blknum == blk) {
54  if (bptr->rd_refcnt <= 0) {
55  pptr = bptr->rd_prev;
56  nptr = bptr->rd_next;
57 
58  /* Unlink node from cache list and reset*/
59  /* the available semaphore accordingly*/
60 
61  pptr->rd_next = bptr->rd_next;
62  nptr->rd_prev = bptr->rd_prev;
63  semreset(rdptr->rd_availsem,
64  semcount(rdptr->rd_availsem) - 1);
65  found = TRUE;
66  }
67  break;
68  }
69  bptr = bptr->rd_next;
70  }
71 
72  if ( !found ) {
73  bptr = rdsbufalloc(rdptr);
74  }
75 
76  /* Create a write request */
77 
78  memcpy(bptr->rd_block, buff, RD_BLKSIZ);
79  bptr->rd_op = RD_OP_WRITE;
80  bptr->rd_refcnt = 0;
81  bptr->rd_blknum = blk;
82  bptr->rd_status = RD_VALID;
83  bptr->rd_pid = getpid();
84 
85  /* Insert new request into list just before tail */
86 
87  pptr = rdptr->rd_rtprev;
88  rdptr->rd_rtprev = bptr;
89  bptr->rd_next = pptr->rd_next;
90  bptr->rd_prev = pptr;
91  pptr->rd_next = bptr;
92 
93  /* Signal semaphore to start communication process */
94 
95  signal(rdptr->rd_reqsem);
96  return OK;
97 }
#define RD_OP_WRITE
Definition: rdisksys.h:43
syscall semcount(sid32)
セマフォのカウント値を返す。
Definition: semcount.c:18
#define RD_OPEN
Definition: rdisksys.h:37
#define RD_VALID
Definition: rdisksys.h:48
#define RD_BLKSIZ
Definition: rdisksys.h:9
sid32 rd_reqsem
Definition: rdisksys.h:92
int32 rd_op
Definition: rdisksys.h:58
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct rdbuff * rd_rtnext
Definition: rdisksys.h:75
int32 rd_status
Definition: rdisksys.h:62
#define OK
処理が成功した場合
Definition: kernel.h:77
sid32 rd_availsem
Definition: rdisksys.h:91
byte bool8
Boolean値
Definition: kernel.h:36
pid32 rd_comproc
Definition: rdisksys.h:89
bool8 rd_comruns
Definition: rdisksys.h:90
struct rdbuff * rd_prev
Definition: rdisksys.h:57
#define FALSE
Boolean False(0)
Definition: kernel.h:63
struct rdbuff * rd_rhnext
Definition: rdisksys.h:73
#define TRUE
Boolean True(1)
Definition: kernel.h:65
struct rdscblk rdstab[]
Definition: rdsinit.c:11
int32 rd_refcnt
Definition: rdisksys.h:59
struct rdbuff * rd_next
Definition: rdisksys.h:56
pri16 resume(pid32)
プロセスを休止状態(サスペンド)からREADY状態に遷移させる。
Definition: resume.c:20
pid32 getpid(void)
現在実行中のプロセスIDを返す。
Definition: getpid.c:11
pid32 rd_pid
Definition: rdisksys.h:63
syscall semreset(sid32, int32)
セマフォカウントをリセットし、待機中のプロセスを全て解放する。
Definition: semreset.c:25
struct rdbuff * rdsbufalloc(struct rdscblk *)
Definition: rdsbufalloc.c:9
struct rdbuff * rd_rtprev
Definition: rdisksys.h:76
struct rdbuff * rd_ctnext
Definition: rdisksys.h:82
struct rdbuff * rd_chnext
Definition: rdisksys.h:80
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
int32 rd_state
Definition: rdisksys.h:69
char rd_block[RD_BLKSIZ]
Definition: rdisksys.h:65
uint32 rd_blknum
Definition: rdisksys.h:61
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
Here is the call graph for this function:

◆ read()

syscall read ( did32  ,
char *  ,
uint32   
)

Definition at line 9 of file read.c.

References devtab, disable(), dentry::dvread, isbaddev, restore(), and SYSERR.

Referenced by lfdballoc(), lfibget(), lfibput(), lfsckfmt(), lfsetup(), lfsopen(), netin(), shell(), xsh_ls(), and xsh_rdstest().

14 {
15  intmask mask; /* Saved interrupt mask */
16  struct dentry *devptr; /* Entry in device switch table */
17  int32 retval; /* Value to return to caller */
18 
19  mask = disable();
20  if (isbaddev(descrp)) {
21  restore(mask);
22  return SYSERR;
23  }
24  devptr = (struct dentry *) &devtab[descrp];
25  retval = (*devptr->dvread) (devptr, buffer, count);
26  restore(mask);
27  return retval;
28 }
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
Definition: conf.h:6
struct dentry devtab[]
Definition: conf.c:11
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define isbaddev(f)
デバイスIDを検証するマクロ。
Definition: device.h:15
devcall(* dvread)(struct dentry *, void *, uint32)
Definition: conf.h:13
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ready()

status ready ( pid32  pid)

プロセスをCPUサービスの対象にする。

Step1. PIDが正常値かどうかを確認する。
Step2. プロセス情報を取得し、ステータスをREADY状態に移行する。
Step3. プロセスをREADYリストに挿入する。
Step4. 再スケジューリングを行う。

Parameters
[in]pidREADY状態に遷移させるプロセスのID
Returns
プロセスがREADY状態となった場合はOK、引数が不正なPIDの場合はSYSERRを返す。

Definition at line 21 of file ready.c.

References insert(), isbadpid, OK, PR_READY, proctab, procent::prprio, procent::prstate, readylist, resched(), and SYSERR.

Referenced by resume(), semdelete(), semreset(), send(), signal(), signaln(), and wakeup().

24 {
25  register struct procent *prptr;
26 
27  if (isbadpid(pid))
28  {
29  return SYSERR;
30  }
31 
32  /* Set process state to indicate ready and add to ready list */
33 
34  prptr = &proctab[pid];
35  prptr->prstate = PR_READY;
36  insert(pid, readylist, prptr->prprio);
37  resched();
38 
39  return OK;
40 }
#define PR_READY
プロセスが準備完了(READY)状態。
Definition: process.h:39
#define isbadpid(x)
プロセスIDを検証する。割り込みが無効になっている事を想定している。
Definition: process.h:71
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
pri16 prprio
プロセスのスケジューリング優先度。
Definition: process.h:90
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
void resched(void)
最優先の適切なプロセスにCPU実行権を渡す。
Definition: resched.c:22
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
status insert(pid32, qid16, int32)
優先度に基づいて、キューにプロセスを挿入する。
Definition: insert.c:20
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
qid16 readylist
READYリストのインデックス
Definition: ready.c:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ receive()

umsg32 receive ( void  )

メッセージの受信を待ち、受信後にreceive()の呼び出し者にメッセージを返す。

Step1. 割り込みを禁止する。
Step2. 現在のプロセスが有効なメッセージを受信していない場合は受信待ち状態に移行し、
再スケジューリングを行う。
Step3. プロセスが復帰後、メッセージを取得し、メッセージフラグをリセットする。
Step4. 割り込み状態を復元する。

Returns
取得したメッセージを返す。

Definition at line 17 of file receive.c.

References currpid, disable(), FALSE, PR_RECV, procent::prhasmsg, procent::prmsg, proctab, procent::prstate, resched(), and restore().

Referenced by main(), rdscontrol(), rdsread(), and shell().

18 {
19  intmask mask; /* Saved interrupt mask */
20  struct procent *prptr; /* Ptr to process's table entry */
21  umsg32 msg; /* Message to return */
22 
23  mask = disable();
24  prptr = &proctab[currpid];
25  if (prptr->prhasmsg == FALSE)
26  {
27  prptr->prstate = PR_RECV;
28  resched(); /* Block until message arrives */
29  }
30  msg = prptr->prmsg; /* Retrieve message */
31  prptr->prhasmsg = FALSE; /* Reset message flag */
32  restore(mask);
33  return msg;
34 }
pid32 currpid
現在実行中のプロセス。
Definition: initialize.c:32
void restore(intmask)
#define PR_RECV
プロセスがメッセージで待機中の状態。
Definition: process.h:41
uint32 umsg32
プロセス間で渡されるメッセージ
Definition: kernel.h:32
#define FALSE
Boolean False(0)
Definition: kernel.h:63
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
void resched(void)
最優先の適切なプロセスにCPU実行権を渡す。
Definition: resched.c:22
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
bool8 prhasmsg
有効(Valid)メッセージの場合、非0となる。
Definition: process.h:106
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
umsg32 prmsg
このプロセスに送信されたメッセージ。
Definition: process.h:104
Here is the call graph for this function:
Here is the caller graph for this function:

◆ recvclr()

umsg32 recvclr ( void  )

受信メッセージをクリアし、待機している場合はメッセージを返す。

Returns
現在のプロセスが有効なメッセージを持っている場合はその内容を返し、
現在のプロセスが有効なメッセージを持っていない場合はOKを返す。
Note
receive()と異なり、メッセージ受信を待ち続けず、即座にリターンする。

Definition at line 14 of file recvclr.c.

References currpid, disable(), FALSE, OK, procent::prhasmsg, procent::prmsg, proctab, restore(), and TRUE.

Referenced by arp_resolve(), icmp_recv(), main(), rdscontrol(), rdsread(), shell(), udp_recv(), and udp_recvaddr().

15 {
16  intmask mask; /* Saved interrupt mask */
17  struct procent *prptr; /* Ptr to process's table entry */
18  umsg32 msg; /* Message to return */
19 
20  mask = disable();
21  prptr = &proctab[currpid];
22  if (prptr->prhasmsg == TRUE)
23  {
24  msg = prptr->prmsg; /* Retrieve message */
25  prptr->prhasmsg = FALSE; /* Reset message flag */
26  }
27  else
28  {
29  msg = OK;
30  }
31  restore(mask);
32  return msg;
33 }
pid32 currpid
現在実行中のプロセス。
Definition: initialize.c:32
void restore(intmask)
#define OK
処理が成功した場合
Definition: kernel.h:77
uint32 umsg32
プロセス間で渡されるメッセージ
Definition: kernel.h:32
#define FALSE
Boolean False(0)
Definition: kernel.h:63
#define TRUE
Boolean True(1)
Definition: kernel.h:65
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
bool8 prhasmsg
有効(Valid)メッセージの場合、非0となる。
Definition: process.h:106
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
umsg32 prmsg
このプロセスに送信されたメッセージ。
Definition: process.h:104
Here is the call graph for this function:
Here is the caller graph for this function:

◆ recvtime()

umsg32 recvtime ( int32  maxwait)
Parameters
[in]maxwait
Returns

Definition at line 17 of file recvtime.c.

References currpid, disable(), FALSE, insertd(), PR_RECTIM, procent::prhasmsg, procent::prmsg, proctab, procent::prstate, resched(), restore(), sleepq, SYSERR, and TIMEOUT.

Referenced by arp_resolve(), icmp_recv(), udp_recv(), and udp_recvaddr().

20 {
21  intmask mask; /* Saved interrupt mask */
22  struct procent *prptr; /* Tbl entry of current process */
23  umsg32 msg; /* Message to return */
24 
25  if (maxwait < 0)
26  {
27  return SYSERR;
28  }
29  mask = disable();
30 
31  /* Schedule wakeup and place process in timed-receive state */
32 
33  prptr = &proctab[currpid];
34  if (prptr->prhasmsg == FALSE)
35  { /* Delay if no message waiting */
36  if (insertd(currpid, sleepq, maxwait) == SYSERR)
37  {
38  restore(mask);
39  return SYSERR;
40  }
41  prptr->prstate = PR_RECTIM;
42  resched();
43  }
44 
45  /* Either message arrived or timer expired */
46 
47  if (prptr->prhasmsg)
48  {
49  msg = prptr->prmsg; /* Retrieve message */
50  prptr->prhasmsg = FALSE; /* Reset message indicator */
51  }
52  else
53  {
54  msg = TIMEOUT;
55  }
56  restore(mask);
57  return msg;
58 }
pid32 currpid
現在実行中のプロセス。
Definition: initialize.c:32
#define PR_RECTIM
プロセスが「タイムアウト」か「メッセージの到着」のいずれか早い方で待機中の状態。
Definition: process.h:49
void restore(intmask)
qid16 sleepq
スリープ中のプロセスキュー
Definition: clkinit.c:7
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
uint32 umsg32
プロセス間で渡されるメッセージ
Definition: kernel.h:32
status insertd(pid32, qid16, int32)
Definition: insertd.c:9
#define FALSE
Boolean False(0)
Definition: kernel.h:63
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
void resched(void)
最優先の適切なプロセスにCPU実行権を渡す。
Definition: resched.c:22
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
bool8 prhasmsg
有効(Valid)メッセージの場合、非0となる。
Definition: process.h:106
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
umsg32 prmsg
このプロセスに送信されたメッセージ。
Definition: process.h:104
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resched()

void resched ( void  )

最優先の適切なプロセスにCPU実行権を渡す。

resched()は、割り込みが禁止された区間で使用される事を想定している。
Step1. 再スケジューリングを遅延させられている場合、再スケジュールを試みた事を記録して終了する。
Step2. カレント(古い)プロセスのプロセステーブルを取得する
Step3. 「カレントプロセスが現在動作中」かつ「READYリスト先頭プロセスより高優先度」の場合は終了する。
Step4. カレントプロセスの状態を実行中からREADY状態に遷移させ、READYリストに挿入する。
Step5. カレントPIDをREADYリストの先頭プロセスとし、そのプロセスをREADY状態から実行状態に遷移させる。
Step6. プリエンプション(実行中のタスクを一時的に中断する動作)のためのタイムスライスを設定する。
Step7. 古いプロセスから新しいプロセスへコンテキストスイッチを行う。
Step8. 古いプロセスはresume()後に、resched()を即座にリターンする。

Definition at line 22 of file resched.c.

References defer::attempt, ctxsw(), currpid, Defer, dequeue(), firstkey, insert(), defer::ndefers, PR_CURR, PR_READY, preempt, proctab, procent::prprio, procent::prstate, procent::prstkptr, QUANTUM, readylist, and TRUE.

Referenced by clkhandler(), kill(), ready(), receive(), recvtime(), resched_cntl(), sleepms(), suspend(), wait(), and yield().

23 {
24  struct procent *ptold; /* Ptr to table entry for old process */
25  struct procent *ptnew; /* Ptr to table entry for new process */
26 
27  /* If rescheduling is deferred, record attempt and return */
28 
29  if (Defer.ndefers > 0)
30  {
31  Defer.attempt = TRUE;
32  return;
33  }
34 
35  /* Point to process table entry for the current (old) process */
36 
37  ptold = &proctab[currpid];
38 
39  if (ptold->prstate == PR_CURR)
40  { /* Process remains eligible */
41  if (ptold->prprio > firstkey(readylist))
42  {
43  return;
44  }
45 
46  /* Old process will no longer remain current */
47 
48  ptold->prstate = PR_READY;
49  insert(currpid, readylist, ptold->prprio);
50  }
51 
52  /* Force context switch to highest priority ready process */
53 
55  ptnew = &proctab[currpid];
56  ptnew->prstate = PR_CURR;
57  preempt = QUANTUM; /* Reset time slice for process */
58  ctxsw(&ptold->prstkptr, &ptnew->prstkptr);
59 
60  /* Old process returns here when resumed */
61 
62  return;
63 }
pid32 currpid
現在実行中のプロセス。
Definition: initialize.c:32
#define PR_READY
プロセスが準備完了(READY)状態。
Definition: process.h:39
void ctxsw(void *, void *)
コンテキストスイッチを行う(ctxsw.S に定義がある)
bool8 attempt
延期中に再スケジューリングが実行されたかどうか
Definition: resched.h:21
#define firstkey(q)
リスト中の最初のプロセスのキーを返す。
pid32 dequeue(qid16)
プロセスキューテーブルからキューを削除し、リスト先頭のプロセスIDを返す。
Definition: queue.c:78
qid16 readylist
READY状態のプロセスリストに対するグローバルID.
Definition: ready.c:9
pri16 prprio
プロセスのスケジューリング優先度。
Definition: process.h:90
#define PR_CURR
プロセスが現在動作中。
Definition: process.h:37
#define TRUE
Boolean True(1)
Definition: kernel.h:65
#define QUANTUM
ミリ秒単位のタイムスライス
Definition: kernel.h:93
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
struct defer Defer
遅延リスケジューリングに関連する項目を集約した構造体
Definition: resched.c:8
int32 ndefers
未処理の延期プロセスの数
Definition: resched.h:19
uint32 preempt
プリエンプションカウンタ
Definition: clkinit.c:9
status insert(pid32, qid16, int32)
優先度に基づいて、キューにプロセスを挿入する。
Definition: insert.c:20
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
char * prstkptr
保存されたスタックポインタ。
Definition: process.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resched_cntl()

status resched_cntl ( int32  defer)

再スケジューリングを延期させるか、もしくは許可させるかを制御する。

Parameters
[in]deferDEFER_START(延期開始)か、DEFER_STOP(延期終了)を指定する。

resched_cntl()は、割り込みが禁止された区間で使用される事を想定している。
引数がDEFER_STARTの場合、以下を実行後にOKを返して終了する。
 ・延期されたプロセス数が0の場合は、その数を1に変更
 ・延期されたプロセス数が0の場合は、延期中の再スケジューリングは未実施に変更
引数がDEFER_STOPの場合、以下を実行する。
 ・延期されたプロセス数が負の値の場合は、SYSERRを返す。
 ・「延期されたプロセスが1の場合」かつ「延期中に再スケジューリング実施済み」の場合は再スケジューリングを実施し、OKを返す。 引数が不正な値の場合は、SYSERRを返す。

Definition at line 81 of file resched.c.

References defer::attempt, Defer, DEFER_START, DEFER_STOP, FALSE, defer::ndefers, OK, resched(), and SYSERR.

Referenced by ethhandler(), icmp_release(), irq_dispatch(), semdelete(), semreset(), signaln(), ttyhandler(), udp_release(), and wakeup().

82 {
83  switch (defer)
84  {
85 
86  case DEFER_START: /* Handle a deferral request */
87 
88  if (Defer.ndefers++ == 0)
89  {
91  }
92  return OK;
93 
94  case DEFER_STOP: /* Handle end of deferral */
95  if (Defer.ndefers <= 0)
96  {
97  return SYSERR;
98  }
99  if ((--Defer.ndefers == 0) && Defer.attempt)
100  {
101  resched();
102  }
103  return OK;
104 
105  default:
106  return SYSERR;
107  }
108 }
bool8 attempt
延期中に再スケジューリングが実行されたかどうか
Definition: resched.h:21
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
#define FALSE
Boolean False(0)
Definition: kernel.h:63
#define DEFER_STOP
遅延リスケジューリングの停止
Definition: resched.h:10
#define DEFER_START
遅延リスケジューリングの開始
Definition: resched.h:8
遅延リスケジューリングに関連する項目を集約した構造体
Definition: resched.h:16
struct defer Defer
遅延リスケジューリングに関連する項目を集約した構造体
Definition: resched.c:8
int32 ndefers
未処理の延期プロセスの数
Definition: resched.h:19
void resched(void)
最優先の適切なプロセスにCPU実行権を渡す。
Definition: resched.c:22
Here is the call graph for this function:
Here is the caller graph for this function:

◆ restore()

void restore ( intmask  )

◆ resume()

pri16 resume ( pid32  pid)

プロセスを休止状態(サスペンド)からREADY状態に遷移させる。

Step1. 割り込み禁止状態とし、割り込みマスクを保持する。
Step2. PIDが正常値かどうかを確認する。
Step3. レジューム対象プロセス情報を取得する。
Step4. レジューム対象プロセス情報は、休止状態(サスペンド状態)かどうかを確認する。
Step5. 現在の優先度を取得する。
Step6. プロセスをREADY状態(CPUサービス対象)にする。
Step7. 割り込み状態(割り込みマスク)を元に戻す。

Parameters
[in]pid休止状態からREADY状態に遷移させるプロセスのID
Returns
READY状態となったプロセスの優先度

Definition at line 20 of file resume.c.

References disable(), isbadpid, PR_SUSP, proctab, procent::prprio, procent::prstate, ready(), restore(), and SYSERR.

Referenced by main(), net_init(), nulluser(), rdscontrol(), rdsread(), rdswrite(), shell(), and startup().

21 {
22  intmask mask; /* Saved interrupt mask */
23  struct procent *prptr; /* Ptr to process's table entry */
24  pri16 prio; /* Priority to return */
25 
26  mask = disable();
27  if (isbadpid(pid))
28  {
29  restore(mask);
30  return (pri16)SYSERR;
31  }
32  prptr = &proctab[pid];
33  if (prptr->prstate != PR_SUSP)
34  {
35  restore(mask);
36  return (pri16)SYSERR;
37  }
38  prio = prptr->prprio; /* Record priority to return */
39  ready(pid);
40  restore(mask);
41  return prio;
42 }
void restore(intmask)
#define PR_SUSP
プロセスがサスペンド(休止)させられた状態。
Definition: process.h:45
#define isbadpid(x)
プロセスIDを検証する。割り込みが無効になっている事を想定している。
Definition: process.h:71
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
status ready(pid32)
プロセスをCPUサービスの対象にする。
Definition: ready.c:21
int16 pri16
プロセス優先度
Definition: kernel.h:30
pri16 prprio
プロセスのスケジューリング優先度。
Definition: process.h:90
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rflclose()

devcall rflclose ( struct dentry )

Definition at line 9 of file rflclose.c.

References dentry::dvminor, OK, Rf_data, RF_FREE, rfdata::rf_mutex, rfltab, rflcblk::rfstate, signal(), SYSERR, and wait().

12 {
13  struct rflcblk *rfptr; /* Pointer to control block */
14 
15  /* Wait for exclusive access */
16 
18 
19  /* Verify remote file device is open */
20 
21  rfptr = &rfltab[devptr->dvminor];
22  if (rfptr->rfstate == RF_FREE) {
24  return SYSERR;
25  }
26 
27  /* Mark device closed */
28 
29  rfptr->rfstate = RF_FREE;
31  return OK;
32 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
struct rflcblk rfltab[]
Definition: rflinit.c:5
int32 rfstate
Definition: rfilesys.h:50
struct rfdata Rf_data
Definition: rfsinit.c:10
sid32 rf_mutex
Definition: rfilesys.h:38
#define RF_FREE
Definition: rfilesys.h:46
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
Here is the call graph for this function:

◆ rflgetc()

devcall rflgetc ( struct dentry )

Definition at line 9 of file rflgetc.c.

References rflread(), and SYSERR.

12 {
13  char ch; /* Character to read */
14  int32 retval; /* Return value */
15 
16  retval = rflread(devptr, &ch, 1);
17 
18  if (retval != 1) {
19  return SYSERR;
20  }
21 
22  return (devcall)ch;
23 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
devcall rflread(struct dentry *, char *, int32)
Definition: rflread.c:9
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 devcall
デバイスコール関数 返り値の型
Definition: kernel.h:49
Here is the call graph for this function:

◆ rflinit()

devcall rflinit ( struct dentry )

Definition at line 11 of file rflinit.c.

References dentry::dvminor, dentry::dvnum, NULLCH, OK, RF_FREE, RF_NAMLEN, rflcblk::rfdev, rfltab, rflcblk::rfmode, rflcblk::rfname, rflcblk::rfpos, and rflcblk::rfstate.

14 {
15  struct rflcblk *rflptr; /* Ptr. to control block entry */
16  int32 i; /* Walks through name arrary */
17 
18  rflptr = &rfltab[ devptr->dvminor ];
19 
20  /* Initialize entry to unused */
21 
22  rflptr->rfstate = RF_FREE;
23  rflptr->rfdev = devptr->dvnum;
24  for (i=0; i<RF_NAMLEN; i++) {
25  rflptr->rfname[i] = NULLCH;
26  }
27  rflptr->rfpos = rflptr->rfmode = 0;
28  return OK;
29 }
#define OK
処理が成功した場合
Definition: kernel.h:77
int32 rfstate
Definition: rfilesys.h:50
uint32 rfmode
Definition: rfilesys.h:54
char rfname[RF_NAMLEN]
Definition: rfilesys.h:52
#define RF_NAMLEN
Definition: rfilesys.h:9
struct rflcblk rfltab[Nrfl]
Definition: rflinit.c:5
#define RF_FREE
Definition: rfilesys.h:46
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint32 rfpos
Definition: rfilesys.h:53
int32 rfdev
Definition: rfilesys.h:51
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70

◆ rflputc()

devcall rflputc ( struct dentry ,
char   
)

Definition at line 9 of file rflputc.c.

References OK, rflwrite(), and SYSERR.

13 {
14  if (rflwrite(devptr, &ch, 1) != 1) {
15  return SYSERR;
16  }
17 
18  return OK;
19 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
devcall rflwrite(struct dentry *, char *, int32)
Definition: rflwrite.c:9
#define OK
処理が成功した場合
Definition: kernel.h:77
Here is the call graph for this function:

◆ rflread()

devcall rflread ( struct dentry ,
char *  ,
int32   
)

Definition at line 9 of file rflread.c.

References dentry::dvminor, htonl, htons, kprintf(), memset(), ntohl, ntohs, NULLCH, Rf_data, RF_DATALEN, RF_FREE, rf_msg_rreq::rf_len, RF_MODE_R, RF_MSG_RREQ, rfdata::rf_mutex, RF_NAMLEN, rf_msg_rreq::rf_pos, rfltab, rflcblk::rfmode, rflcblk::rfname, rflcblk::rfpos, rfscomm(), rflcblk::rfstate, signal(), SYSERR, TIMEOUT, and wait().

Referenced by rflgetc().

14 {
15  struct rflcblk *rfptr; /* Pointer to control block */
16  int32 retval; /* Return value */
17  struct rf_msg_rreq msg; /* Request message to send */
18  struct rf_msg_rres resp; /* Buffer for response */
19  int32 i; /* Counts bytes copied */
20  char *from, *to; /* Used during name copy */
21  int32 len; /* Length of name */
22 
23  /* Wait for exclusive access */
24 
26 
27  /* Verify count is legitimate */
28 
29  if ( (count <= 0) || (count > RF_DATALEN) ) {
31  return SYSERR;
32  }
33 
34  /* Verify pseudo-device is in use */
35 
36  rfptr = &rfltab[devptr->dvminor];
37 
38  /* If device not currently in use, report an error */
39 
40  if (rfptr->rfstate == RF_FREE) {
42  return SYSERR;
43  }
44 
45  /* Verify pseudo-device allows reading */
46 
47  if ((rfptr->rfmode & RF_MODE_R) == 0) {
49  return SYSERR;
50  }
51 
52  /* Form read request */
53 
54  msg.rf_type = htons(RF_MSG_RREQ);
55  msg.rf_status = htons(0);
56  msg.rf_seq = 0; /* Rfscomm will set sequence */
57  from = rfptr->rfname;
58  to = msg.rf_name;
59  memset(to, NULLCH, RF_NAMLEN); /* Start name as all zero bytes */
60  len = 0;
61  while ( (*to++ = *from++) ) { /* Copy name to request */
62  if (++len >= RF_NAMLEN) {
64  return SYSERR;
65  }
66  }
67  msg.rf_pos = htonl(rfptr->rfpos);/* Set file position */
68  msg.rf_len = htonl(count); /* Set count of bytes to read */
69 
70  /* Send message and receive response */
71 
72  retval = rfscomm((struct rf_msg_hdr *)&msg,
73  sizeof(struct rf_msg_rreq),
74  (struct rf_msg_hdr *)&resp,
75  sizeof(struct rf_msg_rres) );
76 
77  /* Check response */
78 
79  if (retval == SYSERR) {
81  return SYSERR;
82  } else if (retval == TIMEOUT) {
83  kprintf("Timeout during remote file read\n");
85  return SYSERR;
86  } else if (ntohs(resp.rf_status) != 0) {
88  return SYSERR;
89  }
90 
91  /* Copy data to application buffer and update file position */
92 
93  for (i=0; i<ntohl(resp.rf_len); i++) {
94  *buff++ = resp.rf_data[i];
95  }
96  rfptr->rfpos += ntohl(resp.rf_len);
97 
99  return ntohl(resp.rf_len);
100 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define RF_MODE_R
Definition: rfilesys.h:11
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct rflcblk rfltab[]
Definition: rflinit.c:5
int32 rfstate
Definition: rfilesys.h:50
#define RF_DATALEN
Definition: rfilesys.h:10
uint32 rfmode
Definition: rfilesys.h:54
int32 rfscomm(struct rf_msg_hdr *, int32, struct rf_msg_hdr *, int32)
Definition: rfscomm.c:10
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
char rfname[RF_NAMLEN]
Definition: rfilesys.h:52
#define RF_NAMLEN
Definition: rfilesys.h:9
#define ntohl(x)
Definition: prototypes.h:623
struct rfdata Rf_data
Definition: rfsinit.c:10
sid32 rf_mutex
Definition: rfilesys.h:38
#define RF_FREE
Definition: rfilesys.h:46
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint32 rfpos
Definition: rfilesys.h:53
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
#define ntohs(x)
Definition: prototypes.h:622
#define RF_MSG_RREQ
Definition: rfilesys.h:83
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
#define htonl(x)
Definition: prototypes.h:620
#define htons(x)
Definition: prototypes.h:619
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rflseek()

devcall rflseek ( struct dentry ,
uint32   
)

Definition at line 9 of file rflseek.c.

References dentry::dvminor, OK, Rf_data, RF_FREE, rfdata::rf_mutex, rfltab, rflcblk::rfpos, rflcblk::rfstate, signal(), SYSERR, and wait().

13 {
14  struct rflcblk *rfptr; /* Pointer to control block */
15 
16  /* Wait for exclusive access */
17 
19 
20  /* Verify remote file device is open */
21 
22  rfptr = &rfltab[devptr->dvminor];
23  if (rfptr->rfstate == RF_FREE) {
25  return SYSERR;
26  }
27 
28  /* Set the new position */
29 
30  rfptr->rfpos = pos;
32  return OK;
33 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
struct rflcblk rfltab[]
Definition: rflinit.c:5
int32 rfstate
Definition: rfilesys.h:50
struct rfdata Rf_data
Definition: rfsinit.c:10
sid32 rf_mutex
Definition: rfilesys.h:38
#define RF_FREE
Definition: rfilesys.h:46
uint32 rfpos
Definition: rfilesys.h:53
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
Here is the call graph for this function:

◆ rflwrite()

devcall rflwrite ( struct dentry ,
char *  ,
int32   
)

Definition at line 9 of file rflwrite.c.

References dentry::dvminor, htonl, htons, kprintf(), memset(), ntohl, ntohs, NULLCH, Rf_data, rf_msg_wreq::rf_data, RF_DATALEN, RF_FREE, rf_msg_wreq::rf_len, RF_MODE_W, RF_MSG_WREQ, rfdata::rf_mutex, RF_NAMLEN, rf_msg_wreq::rf_pos, rfltab, rflcblk::rfmode, rflcblk::rfname, rflcblk::rfpos, rfscomm(), rflcblk::rfstate, signal(), SYSERR, TIMEOUT, and wait().

Referenced by rflputc().

14 {
15  struct rflcblk *rfptr; /* Pointer to control block */
16  int32 retval; /* Return value */
17  struct rf_msg_wreq msg; /* Request message to send */
18  struct rf_msg_wres resp; /* Buffer for response */
19  char *from, *to; /* Used to copy name */
20  int i; /* Counts bytes copied into req */
21  int32 len; /* Length of name */
22 
23  /* Wait for exclusive access */
24 
26 
27  /* Verify count is legitimate */
28 
29  if ( (count <= 0) || (count > RF_DATALEN) ) {
31  return SYSERR;
32  }
33 
34  /* Verify pseudo-device is in use and mode allows writing */
35 
36  rfptr = &rfltab[devptr->dvminor];
37  if ( (rfptr->rfstate == RF_FREE) ||
38  ! (rfptr->rfmode & RF_MODE_W) ) {
40  return SYSERR;
41  }
42 
43  /* Form write request */
44 
45  msg.rf_type = htons(RF_MSG_WREQ);
46  msg.rf_status = htons(0);
47  msg.rf_seq = 0; /* Rfscomm will set sequence */
48  from = rfptr->rfname;
49  to = msg.rf_name;
50  memset(to, NULLCH, RF_NAMLEN); /* Start name as all zero bytes */
51  len = 0;
52  while ( (*to++ = *from++) ) { /* Copy name to request */
53  if (++len >= RF_NAMLEN) {
55  return SYSERR;
56  }
57  }
58  while ( (*to++ = *from++) ) { /* Copy name into request */
59  ;
60  }
61  msg.rf_pos = htonl(rfptr->rfpos);/* Set file position */
62  msg.rf_len = htonl(count); /* Set count of bytes to write */
63  for (i=0; i<count; i++) { /* Copy data into message */
64  msg.rf_data[i] = *buff++;
65  }
66  while (i < RF_DATALEN) {
67  msg.rf_data[i++] = NULLCH;
68  }
69 
70  /* Send message and receive response */
71 
72  retval = rfscomm((struct rf_msg_hdr *)&msg,
73  sizeof(struct rf_msg_wreq),
74  (struct rf_msg_hdr *)&resp,
75  sizeof(struct rf_msg_wres) );
76 
77  /* Check response */
78 
79  if (retval == SYSERR) {
81  return SYSERR;
82  } else if (retval == TIMEOUT) {
83  kprintf("Timeout during remote file read\n");
85  return SYSERR;
86  } else if (ntohs(resp.rf_status) != 0) {
88  return SYSERR;
89  }
90 
91  /* Report results to caller */
92 
93  rfptr->rfpos += ntohl(resp.rf_len);
94 
96  return ntohl(resp.rf_len);
97 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define RF_MODE_W
Definition: rfilesys.h:12
struct rflcblk rfltab[]
Definition: rflinit.c:5
int32 rfstate
Definition: rfilesys.h:50
#define RF_DATALEN
Definition: rfilesys.h:10
uint32 rfmode
Definition: rfilesys.h:54
int32 rfscomm(struct rf_msg_hdr *, int32, struct rf_msg_hdr *, int32)
Definition: rfscomm.c:10
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
char rfname[RF_NAMLEN]
Definition: rfilesys.h:52
#define RF_MSG_WREQ
Definition: rfilesys.h:86
#define RF_NAMLEN
Definition: rfilesys.h:9
#define ntohl(x)
Definition: prototypes.h:623
struct rfdata Rf_data
Definition: rfsinit.c:10
sid32 rf_mutex
Definition: rfilesys.h:38
#define RF_FREE
Definition: rfilesys.h:46
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint32 rfpos
Definition: rfilesys.h:53
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
#define ntohs(x)
Definition: prototypes.h:622
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
#define htonl(x)
Definition: prototypes.h:620
#define htons(x)
Definition: prototypes.h:619
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rfscomm()

int32 rfscomm ( struct rf_msg_hdr ,
int32  ,
struct rf_msg_hdr ,
int32   
)

Definition at line 10 of file rfscomm.c.

References htonl, kprintf(), ntohl, ntohs, Rf_data, rfdata::rf_loc_port, RF_MSG_RESPONSE, rfdata::rf_registered, RF_RETRIES, rfdata::rf_seq, rfdata::rf_ser_ip, rfdata::rf_ser_port, RF_TIMEOUT, rfdata::rf_udp_slot, SYSERR, TIMEOUT, TRUE, udp_recv(), udp_register(), and udp_send().

Referenced by rflread(), rflwrite(), rfscontrol(), rfsndmsg(), and rfsopen().

16 {
17  int32 i; /* Counts retries */
18  int32 retval; /* Return value */
19  int32 seq; /* Sequence for this exchange */
20  int16 rtype; /* Reply type in host byte order*/
21  int32 slot; /* UDP slot */
22 
23  /* For the first time after reboot, register the server port */
24 
25  if ( ! Rf_data.rf_registered ) {
26  if ( (slot = udp_register(Rf_data.rf_ser_ip,
28  Rf_data.rf_loc_port)) == SYSERR) {
29  return SYSERR;
30  }
31  Rf_data.rf_udp_slot = slot;
33  }
34 
35  /* Assign message next sequence number */
36 
37  seq = Rf_data.rf_seq++;
38  msg->rf_seq = htonl(seq);
39 
40  /* Repeat RF_RETRIES times: send message and receive reply */
41 
42  for (i=0; i<RF_RETRIES; i++) {
43 
44  /* Send a copy of the message */
45 
46  retval = udp_send(Rf_data.rf_udp_slot, (char *)msg,
47  mlen);
48  if (retval == SYSERR) {
49  kprintf("Cannot send to remote file server\n");
50  return SYSERR;
51  }
52 
53  /* Receive a reply */
54 
55  retval = udp_recv(Rf_data.rf_udp_slot, (char *)reply,
56  rlen, RF_TIMEOUT);
57 
58  if (retval == TIMEOUT) {
59  continue;
60  } else if (retval == SYSERR) {
61  kprintf("Error reading remote file reply\n");
62  return SYSERR;
63  }
64 
65  /* Verify that sequence in reply matches request */
66 
67  if (ntohl(reply->rf_seq) != seq) {
68  continue;
69  }
70 
71  /* Verify the type in the reply matches the request */
72 
73  rtype = ntohs(reply->rf_type);
74  if (rtype != ( ntohs(msg->rf_type) | RF_MSG_RESPONSE) ) {
75  continue;
76  }
77 
78  return retval; /* Return length to caller */
79  }
80 
81  /* Retries exhausted without success */
82 
83  kprintf("Timeout on exchange with remote file server\n");
84  return TIMEOUT;
85 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
int32 rf_seq
Definition: rfilesys.h:33
int32 udp_recv(uid32, char *, int32, uint32)
Definition: udp.c:146
status udp_send(uid32, char *, int32)
Definition: udp.c:316
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
uint16 rf_ser_port
Definition: rfilesys.h:35
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
bool8 rf_registered
Definition: rfilesys.h:39
#define ntohl(x)
Definition: prototypes.h:623
struct rfdata Rf_data
Definition: rfsinit.c:10
#define RF_MSG_RESPONSE
Definition: rfilesys.h:81
int32 rf_udp_slot
Definition: rfilesys.h:37
#define RF_TIMEOUT
Definition: rfilesys.h:63
#define TRUE
Boolean True(1)
Definition: kernel.h:65
short int16
符号あり16ビット整数(short)
Definition: kernel.h:13
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uid32 udp_register(uint32, uint16, uint16)
Definition: udp.c:85
#define ntohs(x)
Definition: prototypes.h:622
uint32 rf_ser_ip
Definition: rfilesys.h:34
uint16 rf_loc_port
Definition: rfilesys.h:36
#define htonl(x)
Definition: prototypes.h:620
#define RF_RETRIES
Definition: rfilesys.h:62
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rfscontrol()

devcall rfscontrol ( struct dentry ,
int32  ,
int32  ,
int32   
)

Definition at line 9 of file rfscontrol.c.

References htons, kprintf(), memset(), ntohl, NULLCH, OK, Rf_data, RF_MSG_DREQ, RF_MSG_MREQ, RF_MSG_SREQ, RF_MSG_TREQ, RF_MSG_XREQ, rfdata::rf_mutex, RF_NAMLEN, RFS_CTL_DEL, RFS_CTL_MKDIR, RFS_CTL_RMDIR, RFS_CTL_SIZE, RFS_CTL_TRUNC, rfscomm(), rfsndmsg(), signal(), SYSERR, TIMEOUT, and wait().

15 {
16  int32 len; /* Length of name */
17  struct rf_msg_sreq msg; /* Buffer for size request */
18  struct rf_msg_sres resp; /* Buffer for size response */
19  char *to, *from; /* Used during name copy */
20  int32 retval; /* Return value */
21 
22  /* Wait for exclusive access */
23 
25 
26  /* Check length of name (copy during the check even though the */
27  /* copy is only used for a size request) */
28 
29  from = (char *)arg1;
30  to = msg.rf_name;
31  len = 0;
32  memset(to, NULLCH, RF_NAMLEN); /* Start name as all zeroes */
33  while ( (*to++ = *from++) ) { /* Copy name to message */
34  len++;
35  if (len >= (RF_NAMLEN - 1) ) {
37  return SYSERR;
38  }
39  }
40 
41  switch (func) {
42 
43  /* Delete a file */
44 
45  case RFS_CTL_DEL:
46  if (rfsndmsg(RF_MSG_DREQ, (char *)arg1) == SYSERR) {
48  return SYSERR;
49  }
50  break;
51 
52  /* Truncate a file */
53 
54  case RFS_CTL_TRUNC:
55  if (rfsndmsg(RF_MSG_TREQ, (char *)arg1) == SYSERR) {
57  return SYSERR;
58  }
59  break;
60 
61 
62 
63  /* Make a directory */
64 
65  case RFS_CTL_MKDIR:
66  if (rfsndmsg(RF_MSG_MREQ, (char *)arg1) == SYSERR) {
68  return SYSERR;
69  }
70  break;
71 
72  /* Remove a directory */
73 
74  case RFS_CTL_RMDIR:
75  if (rfsndmsg(RF_MSG_XREQ, (char *)arg1) == SYSERR) {
77  return SYSERR;
78  }
79  break;
80 
81  /* Obtain current file size (cannot use rfsndmsg because a */
82  /* response contains a value in addition to the header) */
83 
84  case RFS_CTL_SIZE:
85 
86  /* Hand-craft a size request message */
87 
88  msg.rf_type = htons(RF_MSG_SREQ);
89  msg.rf_status = htons(0);
90  msg.rf_seq = 0; /* Rfscomm will set the seq num */
91 
92  /* Send the request to server and obtain a response */
93 
94  retval = rfscomm( (struct rf_msg_hdr *)&msg,
95  sizeof(struct rf_msg_sreq),
96  (struct rf_msg_hdr *)&resp,
97  sizeof(struct rf_msg_sres) );
98  if ( (retval == SYSERR) || (retval == TIMEOUT) ) {
100  return SYSERR;
101  } else {
103  return ntohl(resp.rf_size);
104  }
105 
106  default:
107  kprintf("rfscontrol: function %d not valid\n", func);
109  return SYSERR;
110  }
111 
113  return OK;
114 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define RF_MSG_DREQ
Definition: rfilesys.h:92
#define RF_MSG_SREQ
Definition: rfilesys.h:98
status rfsndmsg(uint16, char *)
Definition: rfsndmsg.c:9
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define RFS_CTL_DEL
Definition: rfilesys.h:67
#define OK
処理が成功した場合
Definition: kernel.h:77
#define RFS_CTL_MKDIR
Definition: rfilesys.h:69
int32 rfscomm(struct rf_msg_hdr *, int32, struct rf_msg_hdr *, int32)
Definition: rfscomm.c:10
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
#define RF_MSG_XREQ
Definition: rfilesys.h:104
#define RF_NAMLEN
Definition: rfilesys.h:9
#define RFS_CTL_RMDIR
Definition: rfilesys.h:70
#define ntohl(x)
Definition: prototypes.h:623
struct rfdata Rf_data
Definition: rfsinit.c:10
#define RFS_CTL_SIZE
Definition: rfilesys.h:71
#define RF_MSG_MREQ
Definition: rfilesys.h:101
#define RFS_CTL_TRUNC
Definition: rfilesys.h:68
sid32 rf_mutex
Definition: rfilesys.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
#define RF_MSG_TREQ
Definition: rfilesys.h:95
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
#define htons(x)
Definition: prototypes.h:619
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:

◆ rfsgetmode()

int32 rfsgetmode ( char *  )

Definition at line 10 of file rfsgetmode.c.

References NULLCH, RF_MODE_N, RF_MODE_O, RF_MODE_R, RF_MODE_RW, RF_MODE_W, and SYSERR.

Referenced by rfsopen().

13 {
14  int32 mbits; /* Mode bits to return (in host */
15  /* byte order) */
16  char ch; /* Next character in mode string*/
17 
18  mbits = 0;
19 
20  /* Mode string specifies: */
21  /* r - read */
22  /* w - write */
23  /* o - old (file must exist) */
24  /* n - new (create a new file) */
25 
26  while ( (ch = *mode++) != NULLCH) {
27  switch (ch) {
28 
29  case 'r': if (mbits&RF_MODE_R) {
30  return SYSERR;
31  }
32  mbits |= RF_MODE_R;
33  continue;
34 
35  case 'w': if (mbits&RF_MODE_W) {
36  return SYSERR;
37  }
38  mbits |= RF_MODE_W;
39  continue;
40 
41  case 'o': if (mbits&RF_MODE_O || mbits&RF_MODE_N) {
42  return SYSERR;
43  }
44  mbits |= RF_MODE_O;
45  break;
46 
47  case 'n': if (mbits&RF_MODE_O || mbits&RF_MODE_N) {
48  return SYSERR;
49  }
50  mbits |= RF_MODE_N;
51  break;
52 
53  default: return SYSERR;
54  }
55  }
56 
57  /* If neither read nor write specified, allow both */
58 
59  if ( (mbits&RF_MODE_RW) == 0 ) {
60  mbits |= RF_MODE_RW;
61  }
62  return mbits;
63 }
#define RF_MODE_N
Definition: rfilesys.h:14
#define RF_MODE_R
Definition: rfilesys.h:11
#define RF_MODE_RW
Definition: rfilesys.h:13
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define RF_MODE_W
Definition: rfilesys.h:12
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define RF_MODE_O
Definition: rfilesys.h:15
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the caller graph for this function:

◆ rfsinit()

devcall rfsinit ( struct dentry )

Definition at line 16 of file rfsinit.c.

References dot2ip(), FALSE, OK, panic(), Rf_data, RF_LOC_PORT, rfdata::rf_loc_port, rfdata::rf_mutex, rfdata::rf_registered, rfdata::rf_seq, rfdata::rf_ser_ip, rfdata::rf_ser_port, RF_SERVER_IP, RF_SERVER_PORT, semcreate(), and SYSERR.

19 {
20 
21  /* Choose an initial message sequence number */
22 
23  Rf_data.rf_seq = 1;
24 
25  /* Set the server IP address, server port, and local port */
26 
28  {
29  panic("invalid IP address for remote file server");
30  }
33 
34  /* Create a mutual exclusion semaphore */
35 
36  if ((Rf_data.rf_mutex = semcreate(1)) == SYSERR)
37  {
38  panic("Cannot create remote file system semaphore");
39  }
40 
41  /* Specify that the server port is not yet registered */
42 
44 
45  return OK;
46 }
int32 rf_seq
Definition: rfilesys.h:33
sid32 semcreate(int32)
未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。
Definition: semcreate.c:22
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
uint16 rf_ser_port
Definition: rfilesys.h:35
#define OK
処理が成功した場合
Definition: kernel.h:77
bool8 rf_registered
Definition: rfilesys.h:39
struct rfdata Rf_data
Definition: rfsinit.c:10
#define RF_SERVER_IP
Definition: rfilesys.h:21
#define FALSE
Boolean False(0)
Definition: kernel.h:63
sid32 rf_mutex
Definition: rfilesys.h:38
#define RF_SERVER_PORT
Definition: rfilesys.h:25
#define RF_LOC_PORT
Definition: rfilesys.h:29
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
uint32 rf_ser_ip
Definition: rfilesys.h:34
uint16 rf_loc_port
Definition: rfilesys.h:36
uint32 dot2ip(char *, uint32 *)
Definition: dot2ip.c:9
Here is the call graph for this function:

◆ rfsndmsg()

status rfsndmsg ( uint16  ,
char *   
)

Definition at line 9 of file rfsndmsg.c.

References htons, kprintf(), ntohl, OK, rfscomm(), SYSERR, and TIMEOUT.

Referenced by rfscontrol().

13 {
14  struct rf_msg_hdr req; /* Request message to send */
15  struct rf_msg_hdr resp; /* Buffer for response */
16  int32 retval; /* Return value */
17  char *to; /* Used during name copy */
18 
19  /* Form a request */
20 
21  req.rf_type = htons(type);
22  req.rf_status = htons(0);
23  req.rf_seq = 0; /* Rfscomm will set sequence */
24  to = req.rf_name;
25  while ( (*to++ = *name++) ) { /* Copy name to request */
26  ;
27  }
28 
29  /* Send message and receive response */
30 
31  retval = rfscomm(&req, sizeof(struct rf_msg_hdr),
32  &resp, sizeof(struct rf_msg_hdr) );
33 
34  /* Check response */
35 
36  if (retval == SYSERR) {
37  return SYSERR;
38  } else if (retval == TIMEOUT) {
39  kprintf("Timeout during remote file server access\n");
40  return SYSERR;
41  } else if (ntohl(resp.rf_status) != 0) {
42  return SYSERR;
43  }
44 
45  return OK;
46 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
int32 rfscomm(struct rf_msg_hdr *, int32, struct rf_msg_hdr *, int32)
Definition: rfscomm.c:10
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
#define ntohl(x)
Definition: prototypes.h:623
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define htons(x)
Definition: prototypes.h:619
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rfsopen()

devcall rfsopen ( struct dentry devptr,
char *  ,
char *   
)

Definition at line 10 of file rfsopen.c.

References htonl, htons, kprintf(), memset(), Nrfl, ntohs, NULLCH, Rf_data, RF_FREE, rf_msg_oreq::rf_mode, RF_MSG_OREQ, rfdata::rf_mutex, RF_NAMLEN, RF_USED, rflcblk::rfdev, rfltab, rflcblk::rfmode, rflcblk::rfname, rflcblk::rfpos, rfscomm(), rfsgetmode(), rflcblk::rfstate, signal(), SYSERR, TIMEOUT, and wait().

15 {
16  struct rflcblk *rfptr; /* Ptr to control block entry */
17  struct rf_msg_oreq msg; /* Message to be sent */
18  struct rf_msg_ores resp; /* Buffer to hold response */
19  int32 retval; /* Return value from rfscomm */
20  int32 len; /* Counts chars in name */
21  char *nptr; /* Pointer into name string */
22  char *fptr; /* Pointer into file name */
23  int32 i; /* General loop index */
24 
25  /* Wait for exclusive access */
26 
28 
29  /* Search control block array to find a free entry */
30 
31  for(i=0; i<Nrfl; i++) {
32  rfptr = &rfltab[i];
33  if (rfptr->rfstate == RF_FREE) {
34  break;
35  }
36  }
37  if (i >= Nrfl) { /* No free table slots remain */
39  return SYSERR;
40  }
41 
42  /* Copy name into free table slot */
43 
44  nptr = name;
45  fptr = rfptr->rfname;
46  len = 0;
47  while ( (*fptr++ = *nptr++) != NULLCH) {
48  len++;
49  if (len >= RF_NAMLEN) { /* File name is too long */
51  return SYSERR;
52  }
53  }
54 
55  /* Verify that name is non-null */
56 
57  if (len==0) {
59  return SYSERR;
60  }
61 
62  /* Parse mode string */
63 
64  if ( (rfptr->rfmode = rfsgetmode(mode)) == SYSERR ) {
66  return SYSERR;
67  }
68 
69  /* Form an open request to create a new file or open an old one */
70 
71  msg.rf_type = htons(RF_MSG_OREQ);/* Request a file open */
72  msg.rf_status = htons(0);
73  msg.rf_seq = 0; /* Rfscomm fills in seq. number */
74  nptr = msg.rf_name;
75  memset(nptr, NULLCH, RF_NAMLEN);/* Initialize name to zero bytes*/
76  while ( (*nptr++ = *name++) != NULLCH ) { /* Copy name to req. */
77  ;
78  }
79  msg.rf_mode = htonl(rfptr->rfmode); /* Set mode in request */
80 
81  /* Send message and receive response */
82 
83  retval = rfscomm((struct rf_msg_hdr *)&msg,
84  sizeof(struct rf_msg_oreq),
85  (struct rf_msg_hdr *)&resp,
86  sizeof(struct rf_msg_ores) );
87 
88  /* Check response */
89 
90  if (retval == SYSERR) {
92  return SYSERR;
93  } else if (retval == TIMEOUT) {
94  kprintf("Timeout during remote file open\n\r");
96  return SYSERR;
97  } else if (ntohs(resp.rf_status) != 0) {
99  return SYSERR;
100  }
101 
102  /* Set initial file position */
103 
104  rfptr->rfpos = 0;
105 
106  /* Mark state as currently used */
107 
108  rfptr->rfstate = RF_USED;
109 
110  /* Return device descriptor of newly created pseudo-device */
111 
113  return rfptr->rfdev;
114 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct rflcblk rfltab[]
Definition: rflinit.c:5
int32 rfstate
Definition: rfilesys.h:50
uint32 rfmode
Definition: rfilesys.h:54
int32 rfscomm(struct rf_msg_hdr *, int32, struct rf_msg_hdr *, int32)
Definition: rfscomm.c:10
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
#define RF_MSG_OREQ
Definition: rfilesys.h:89
char rfname[RF_NAMLEN]
Definition: rfilesys.h:52
#define RF_USED
Definition: rfilesys.h:47
#define RF_NAMLEN
Definition: rfilesys.h:9
struct rfdata Rf_data
Definition: rfsinit.c:10
int32 rfsgetmode(char *)
Definition: rfsgetmode.c:10
sid32 rf_mutex
Definition: rfilesys.h:38
#define RF_FREE
Definition: rfilesys.h:46
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint32 rfpos
Definition: rfilesys.h:53
void * memset(void *, const int, int32)
指定のByteブロックに対して、同じ値をNバイト分書き込む。
Definition: memset.c:13
#define ntohs(x)
Definition: prototypes.h:622
int32 rfdev
Definition: rfilesys.h:51
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
#define Nrfl
Definition: conf.h:68
#define htonl(x)
Definition: prototypes.h:620
#define htons(x)
Definition: prototypes.h:619
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:

◆ seek()

syscall seek ( did32  ,
uint32   
)

Definition at line 9 of file seek.c.

References devtab, disable(), dentry::dvseek, isbaddev, restore(), and SYSERR.

13 {
14  intmask mask; /* Saved interrupt mask */
15  struct dentry *devptr; /* Entry in device switch table */
16  int32 retval; /* Value to return to caller */
17 
18  mask = disable();
19  if (isbaddev(descrp)) {
20  restore(mask);
21  return SYSERR;
22  }
23  devptr = (struct dentry *) &devtab[descrp];
24  retval = (*devptr->dvseek) (devptr, pos);
25  restore(mask);
26  return retval;
27 }
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
Definition: conf.h:6
struct dentry devtab[]
Definition: conf.c:11
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define isbaddev(f)
デバイスIDを検証するマクロ。
Definition: device.h:15
devcall(* dvseek)(struct dentry *, int32)
Definition: conf.h:15
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:

◆ semcount()

syscall semcount ( sid32  semid)

セマフォのカウント値を返す。

Step1. 割り込みを禁止する。
Step2. 「セマフォIDが不正値」か「セマフォがFREE状態」の場合、割り込み許可状態に復元して、処理を終了する。
Step3. 引数で渡されたセマフォIDを基に、セマフォテーブルからセマフォのカウント値を取得する。
Step4. 割り込み許可状態に復元する。

Parameters
[in]semidセマフォカウンタを確認したいセマフォのID
Returns
成功時はセマフォのカウント値、「不正なセマフォID」や「セマフォがFREE状態の場合はSYSERR」を返す。
Note
セマフォカウンタ値が整数値(正負問わず)のため、SYSERR(-1)と同じ値になる可能性がある。

Definition at line 18 of file semcount.c.

References disable(), isbadsem, restore(), S_FREE, sentry::scount, semtab, and SYSERR.

Referenced by ethhandler(), ip_enqueue(), ptcount(), rdswrite(), ttycontrol(), ttyhandle_in(), ttyhandle_out(), and ttyread().

19 {
20  intmask mask; /* Saved interrupt mask */
21  int32 count; /* Current sempahore count */
22 
23  mask = disable();
24 
25  if (isbadsem(semid) || semtab[semid].sstate == S_FREE)
26  {
27  restore(mask);
28  return SYSERR;
29  }
30  count = semtab[semid].scount;
31  restore(mask);
32  return count;
33 }
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define isbadsem(s)
セマフォIDが不適切かどうかを確認する。
Definition: semaphore.h:40
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 scount
セマフォカウント(負の値(-N)の場合は、キューにN個の待機プロセスがある。それ以外はキューが空である) ...
Definition: semaphore.h:24
#define S_FREE
セマフォテーブルエントリが利用可能
Definition: semaphore.h:11
struct sentry semtab[]
セマフォテーブルエントリのextern宣言
Definition: initialize.c:25
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ semcreate()

sid32 semcreate ( int32  count)

未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。

Step1. 割り込みを禁止する
Step2. セマフォカウント初期値が負の値、もしくは未使用のセマフォがない場合は、割り込みを許可状態に復元し、処理を終了する。
Step3. newsem()で取得したセマフォIDを用いて、セマフォテーブルからセマフォを取り出し、セマフォカウントの初期値を設定する。
Step4. 割り込みを許可状態に復元する。

Parameters
[in]countセマフォカウントの初期値
Returns
セマフォが生成できた場合は生成したセマフォのID、
「セマフォカウント初期値が負の値」もしくは「未使用のセマフォがない」場合はSYSERRを返す。
Note
セマフォの状態は、newsem()内で未使用→使用に変更されている。

Definition at line 22 of file semcreate.c.

References disable(), newsem(), restore(), sentry::scount, semtab, and SYSERR.

Referenced by ethinit(), lflinit(), lfsinit(), markinit(), mkbufpool(), net_init(), ptcreate(), rdsinit(), rfsinit(), and ttyinit().

23 {
24  intmask mask; /* Saved interrupt mask */
25  sid32 sem; /* Semaphore ID to return */
26 
27  mask = disable();
28 
29  if (count < 0 || ((sem = newsem()) == SYSERR))
30  {
31  restore(mask);
32  return SYSERR;
33  }
34  semtab[sem].scount = count; /* Initialize table entry */
35 
36  restore(mask);
37  return sem;
38 }
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
local sid32 newsem(void)
未使用のセマフォIDを返す。
Definition: semcreate.c:49
int32 scount
セマフォカウント(負の値(-N)の場合は、キューにN個の待機プロセスがある。それ以外はキューが空である) ...
Definition: semaphore.h:24
int32 sid32
セマフォID
Definition: kernel.h:22
struct sentry semtab[]
セマフォテーブルエントリのextern宣言
Definition: initialize.c:25
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ semdelete()

syscall semdelete ( sid32  sem)

セマフォテーブルエントリを解放し、セマフォを削除する。

Step1. 割り込みを禁止する。
Step2. セマフォIDが不正の場合は割り込みを許可状態に復元し、処理を終了する。
Step3. 削除したいセマフォの状態がFREEの場合は、割り込みを許可状態に復元し、処理を終了する。
Step4. セマフォの状態をFREEにする。
Step5. 待機状態プロセスを全てREADY状態に移行するまで、再スケジューリングを遅延(Defer)させる。
Step6. キュー操作API(getfirst())でキューの先頭から順番にプロセスIDを取り出し、READY状態にする。
Step7. 再スケジューリングの遅延を解除する。
Step8. 割り込みを許可状態に戻す。

Parameters
[in]sem削除したいセマフォのID
Returns
セマフォの削除を成功した時はOK、
「セマフォIDが不正の場合」や「セマフォ削除前にセマフォがFREE状態の場合」はSYSERRを返す。

Definition at line 22 of file semdelete.c.

References DEFER_START, DEFER_STOP, disable(), getfirst(), isbadsem, OK, ready(), resched_cntl(), restore(), S_FREE, sentry::scount, semtab, sentry::squeue, sentry::sstate, and SYSERR.

Referenced by _ptclear().

23 {
24  intmask mask; /* Saved interrupt mask */
25  struct sentry *semptr; /* Ptr to semaphore table entry */
26 
27  mask = disable();
28  if (isbadsem(sem))
29  {
30  restore(mask);
31  return SYSERR;
32  }
33 
34  semptr = &semtab[sem];
35  if (semptr->sstate == S_FREE)
36  {
37  restore(mask);
38  return SYSERR;
39  }
40  semptr->sstate = S_FREE;
41 
43  while (semptr->scount++ < 0)
44  { /* Free all waiting processes */
45  ready(getfirst(semptr->squeue));
46  }
48  restore(mask);
49  return OK;
50 }
void restore(intmask)
byte sstate
エントリ状態が利用可能(S_FREE)か、利用中(S_USED)かを表す。
Definition: semaphore.h:22
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
セマフォテーブルエントリであり、本構造体の配列(長さNSEM)が静的に確保される。
Definition: semaphore.h:19
#define isbadsem(s)
セマフォIDが不適切かどうかを確認する。
Definition: semaphore.h:40
#define OK
処理が成功した場合
Definition: kernel.h:77
status ready(pid32)
プロセスをCPUサービスの対象にする。
Definition: ready.c:21
status resched_cntl(int32)
再スケジューリングを延期させるか、もしくは許可させるかを制御する。
Definition: resched.c:81
#define DEFER_STOP
遅延リスケジューリングの停止
Definition: resched.h:10
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
#define DEFER_START
遅延リスケジューリングの開始
Definition: resched.h:8
qid16 squeue
セマフォ待機中プロセスのキュー
Definition: semaphore.h:26
pid32 getfirst(qid16)
キューの先頭からプロセスを取り出す。
Definition: getitem.c:13
int32 scount
セマフォカウント(負の値(-N)の場合は、キューにN個の待機プロセスがある。それ以外はキューが空である) ...
Definition: semaphore.h:24
#define S_FREE
セマフォテーブルエントリが利用可能
Definition: semaphore.h:11
struct sentry semtab[]
セマフォテーブルエントリのextern宣言
Definition: initialize.c:25
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ semreset()

syscall semreset ( sid32  sem,
int32  count 
)

セマフォカウントをリセットし、待機中のプロセスを全て解放する。

Step1. 割り込みを禁止する。
Step2. 以下のいずれかを満たす場合、割り込みを許可状態に復元し、処理を終了する。
 ・引数で渡されたセマフォカウンタのリセット値が負の値の場合
 ・引数で渡されたセマフォIDが不整値の場合
 ・セマフォがFREE状態の場合
Step3. 待機状態プロセスを全てREADY状態に移行するまで、再スケジューリングを遅延(Defer)させる。
Step4. キュー操作API(getfirst())でキューの先頭から順番にプロセスIDを取り出し、READY状態にする。
Step5. 再スケジューリングの遅延を解除する。
Step6. 割り込みを許可状態に戻す。

Parameters
[in]semリセット対象のセマフォID
[in]count新しいセマフォカウント(0以上の値)
Returns
セマフォカウンタがリセットできた場合はOK、以下の場合はSYSERRを返す。
 ・引数で渡されたセマフォカウンタのリセット値が負の値の場合
 ・引数で渡されたセマフォIDが不整値の場合
 ・セマフォがFREE状態の場合

Definition at line 25 of file semreset.c.

References DEFER_START, DEFER_STOP, disable(), EMPTY, getfirst(), isbadsem, OK, ready(), resched_cntl(), restore(), S_FREE, sentry::scount, semtab, sentry::squeue, sentry::sstate, and SYSERR.

Referenced by _ptclear(), and rdswrite().

26 {
27  intmask mask; /* Saved interrupt mask */
28  struct sentry *semptr; /* Ptr to semaphore table entry */
29  qid16 semqueue; /* Semaphore's process queue ID */
30  pid32 pid; /* ID of a waiting process */
31 
32  mask = disable();
33 
34  if (count < 0 || isbadsem(sem) || semtab[sem].sstate == S_FREE)
35  {
36  restore(mask);
37  return SYSERR;
38  }
39 
40  semptr = &semtab[sem];
41  semqueue = semptr->squeue; /* Free any waiting processes */
43  while ((pid = getfirst(semqueue)) != EMPTY)
44  ready(pid);
45  semptr->scount = count; /* Reset count as specified */
47  restore(mask);
48  return OK;
49 }
void restore(intmask)
byte sstate
エントリ状態が利用可能(S_FREE)か、利用中(S_USED)かを表す。
Definition: semaphore.h:22
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
セマフォテーブルエントリであり、本構造体の配列(長さNSEM)が静的に確保される。
Definition: semaphore.h:19
#define isbadsem(s)
セマフォIDが不適切かどうかを確認する。
Definition: semaphore.h:40
#define OK
処理が成功した場合
Definition: kernel.h:77
status ready(pid32)
プロセスをCPUサービスの対象にする。
Definition: ready.c:21
#define EMPTY
次のキューインデックスもしくは前のキューインデックスがNULL値
Definition: queue.h:23
status resched_cntl(int32)
再スケジューリングを延期させるか、もしくは許可させるかを制御する。
Definition: resched.c:81
#define DEFER_STOP
遅延リスケジューリングの停止
Definition: resched.h:10
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
#define DEFER_START
遅延リスケジューリングの開始
Definition: resched.h:8
int16 qid16
キューID
Definition: kernel.h:24
qid16 squeue
セマフォ待機中プロセスのキュー
Definition: semaphore.h:26
pid32 getfirst(qid16)
キューの先頭からプロセスを取り出す。
Definition: getitem.c:13
int32 pid32
プロセスID
Definition: kernel.h:26
int32 scount
セマフォカウント(負の値(-N)の場合は、キューにN個の待機プロセスがある。それ以外はキューが空である) ...
Definition: semaphore.h:24
#define S_FREE
セマフォテーブルエントリが利用可能
Definition: semaphore.h:11
struct sentry semtab[]
セマフォテーブルエントリのextern宣言
Definition: initialize.c:25
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send()

syscall send ( pid32  pid,
umsg32  msg 
)

プロセスにメッセージを送信し、受信側が待機状態の場合はREADY状態にする。

Step1. 割り込みを禁止する。
Step2. 引数で渡されたプロセスのIDが不正値の場合は、割り込みを許可状態に復元し、処理を終了する。
Step3. 受信側プロセスが過去のメッセージを未処理の場合は、割り込みを許可状態に復元し、処理を終了する。
Step4. メッセージを受信側プロセスに送信(セット)し、受信側プロセスのメッセージ所持フラグを有効化する。
Step5. 受信側プロセスが受信待ち状態の場合はREADY状態とし、
受信待ちかタイムアウト待ちの場合はプロセスの休眠状態を解除してからREADY状態に変更する。
Step6. 割り込みを許可状態に復元する。

Parameters
[in]pidメッセージを受信するプロセスのID
[in]msgメッセージ内容(整数かポインタ)
Returns
メッセージを送信した場合はOK、受信側プロセスIDが不正値の場合や受信側プロセスが過去メッセージ未処理の場合はSYSERRを返す。

Definition at line 21 of file send.c.

References disable(), isbadpid, OK, PR_RECTIM, PR_RECV, procent::prhasmsg, procent::prmsg, proctab, procent::prstate, ready(), restore(), SYSERR, TRUE, and unsleep().

Referenced by arp_in(), icmp_in(), kill(), rdsprocess(), and udp_in().

22 {
23  intmask mask; /* Saved interrupt mask */
24  struct procent *prptr; /* Ptr to process's table entry */
25 
26  mask = disable();
27  if (isbadpid(pid))
28  {
29  restore(mask);
30  return SYSERR;
31  }
32 
33  prptr = &proctab[pid];
34  if (prptr->prhasmsg)
35  {
36  restore(mask);
37  return SYSERR;
38  }
39  prptr->prmsg = msg; /* Deliver message */
40  prptr->prhasmsg = TRUE; /* Indicate message is waiting */
41 
42  /* If recipient waiting or in timed-wait make it ready */
43 
44  if (prptr->prstate == PR_RECV)
45  {
46  ready(pid);
47  }
48  else if (prptr->prstate == PR_RECTIM)
49  {
50  unsleep(pid);
51  ready(pid);
52  }
53  restore(mask); /* Restore interrupts */
54  return OK;
55 }
#define PR_RECTIM
プロセスが「タイムアウト」か「メッセージの到着」のいずれか早い方で待機中の状態。
Definition: process.h:49
void restore(intmask)
#define isbadpid(x)
プロセスIDを検証する。割り込みが無効になっている事を想定している。
Definition: process.h:71
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
status ready(pid32)
プロセスをCPUサービスの対象にする。
Definition: ready.c:21
#define PR_RECV
プロセスがメッセージで待機中の状態。
Definition: process.h:41
syscall unsleep(pid32)
Definition: unsleep.c:11
#define TRUE
Boolean True(1)
Definition: kernel.h:65
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
bool8 prhasmsg
有効(Valid)メッセージの場合、非0となる。
Definition: process.h:106
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
umsg32 prmsg
このプロセスに送信されたメッセージ。
Definition: process.h:104
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_evec()

int32 set_evec ( uint32  ,
uint32   
)

Definition at line 37 of file evec.c.

References intc_csreg::banks, intc_vector, intc_bank::mir, OK, and SYSERR.

Referenced by clkinit(), ethinit(), gpioinit(), and ttyinit().

38 {
39  struct intc_csreg *csrptr = (struct intc_csreg *)0x48200000;
40  uint32 bank; /* bank number in int controller */
41  uint32 mask; /* used to set bits in bank */
42 
43  /* There are only 127 interrupts allowed 0-126 */
44 
45  if(xnum > 127) {
46  return SYSERR;
47  }
48 
49  /* Install the handler */
50 
51  intc_vector[xnum] = handler;
52 
53  /* Get the bank number based on interrupt number */
54 
55  bank = (xnum/32);
56 
57  /* Get the bit inside the bank */
58 
59  mask = (0x00000001 << (xnum%32));
60 
61  /* Reset the bit to enable that interrupt number */
62 
63  csrptr->banks[bank].mir &= (~mask);
64 
65  return OK;
66 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
uint32 mir
Definition: interrupt.h:9
struct intc_bank banks[4]
Definition: interrupt.h:34
#define OK
処理が成功した場合
Definition: kernel.h:77
uint32 intc_vector[128]
Definition: evec.c:11
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
Here is the caller graph for this function:

◆ shell()

process shell ( did32  )

Definition at line 54 of file shell.c.

References addargs(), cmdent::cbuiltin, cmdent::cfunc, cmdent::cname, control(), create(), EOF, F_CTL_TRUNC, FALSE, fprintf(), lexan(), NAMESPACE, ncmd, NULL, NULLCH, OK, open(), procent::prdesc, proctab, read(), receive(), recvclr(), resume(), SH_NEWLINE, SH_TOK_AMPER, SH_TOK_GREATER, SH_TOK_LESS, SH_TOK_OTHER, SHELL_BAN0, SHELL_BAN1, SHELL_BAN2, SHELL_BAN3, SHELL_BAN4, SHELL_BAN5, SHELL_BAN6, SHELL_BAN7, SHELL_BAN8, SHELL_BAN9, SHELL_BGERRMSG, SHELL_BUFLEN, SHELL_CMDPRIO, SHELL_CMDSTK, SHELL_CREATMSG, SHELL_EXIT, SHELL_EXITMSG, SHELL_INERRMSG, SHELL_MAXTOK, SHELL_OUTERRMSG, SHELL_PROMPT, SHELL_STRTMSG, SHELL_SYNERRMSG, SYSERR, and TRUE.

Referenced by main().

57 {
58  char buf[SHELL_BUFLEN]; /* Input line (large enough for */
59  /* one line from a tty device */
60  int32 len; /* Length of line read */
61  char tokbuf[SHELL_BUFLEN + /* Buffer to hold a set of */
62  SHELL_MAXTOK]; /* Contiguous null-terminated */
63  /* Strings of tokens */
64  int32 tlen; /* Current length of all data */
65  /* in array tokbuf */
66  int32 tok[SHELL_MAXTOK]; /* Index of each token in */
67  /* array tokbuf */
68  int32 toktyp[SHELL_MAXTOK]; /* Type of each token in tokbuf */
69  int32 ntok; /* Number of tokens on line */
70  pid32 child; /* Process ID of spawned child */
71  bool8 backgnd; /* Run command in background? */
72  char *outname, *inname; /* Pointers to strings for file */
73  /* names that follow > and < */
74  did32 stdinput, stdoutput; /* Descriptors for redirected */
75  /* input and output */
76  int32 i; /* Index into array of tokens */
77  int32 j; /* Index into array of commands */
78  int32 msg; /* Message from receive() for */
79  /* child termination */
80  int32 tmparg; /* Address of this var is used */
81  /* when first creating child */
82  /* process, but is replaced */
83  char *src, *cmp; /* Pointers used during name */
84  /* comparison */
85  bool8 diff; /* Was difference found during */
86  /* comparison */
87  char *args[SHELL_MAXTOK]; /* Argument vector passed to */
88  /* builtin commands */
89 
90  /* Print shell banner and startup message */
91 
92  fprintf(dev, "\n\n%s%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
95 
96  fprintf(dev, "%s\n\n", SHELL_STRTMSG);
97 
98  /* Continually prompt the user, read input, and execute command */
99 
100  while (TRUE) {
101 
102  /* Display prompt */
103 
104  fprintf(dev, SHELL_PROMPT);
105 
106  /* Read a command */
107 
108  len = read(dev, buf, sizeof(buf));
109 
110  /* Exit gracefully on end-of-file */
111 
112  if (len == EOF) {
113  break;
114  }
115 
116  /* If line contains only NEWLINE, go to next line */
117 
118  if (len <= 1) {
119  continue;
120  }
121 
122  buf[len] = SH_NEWLINE; /* terminate line */
123 
124  /* Parse input line and divide into tokens */
125 
126  ntok = lexan(buf, len, tokbuf, &tlen, tok, toktyp);
127 
128  /* Handle parsing error */
129 
130  if (ntok == SYSERR) {
131  fprintf(dev,"%s\n", SHELL_SYNERRMSG);
132  continue;
133  }
134 
135  /* If line is empty, go to next input line */
136 
137  if (ntok == 0) {
138  fprintf(dev, "\n");
139  continue;
140  }
141 
142  /* If last token is '&', set background */
143 
144  if (toktyp[ntok-1] == SH_TOK_AMPER) {
145  ntok-- ;
146  tlen-= 2;
147  backgnd = TRUE;
148  } else {
149  backgnd = FALSE;
150  }
151 
152 
153  /* Check for input/output redirection (default is none) */
154 
155  outname = inname = NULL;
156  if ( (ntok >=3) && ( (toktyp[ntok-2] == SH_TOK_LESS)
157  ||(toktyp[ntok-2] == SH_TOK_GREATER))){
158  if (toktyp[ntok-1] != SH_TOK_OTHER) {
159  fprintf(dev,"%s\n", SHELL_SYNERRMSG);
160  continue;
161  }
162  if (toktyp[ntok-2] == SH_TOK_LESS) {
163  inname = &tokbuf[tok[ntok-1]];
164  } else {
165  outname = &tokbuf[tok[ntok-1]];
166  }
167  ntok -= 2;
168  tlen = tok[ntok];
169  }
170 
171 
172  if ( (ntok >=3) && ( (toktyp[ntok-2] == SH_TOK_LESS)
173  ||(toktyp[ntok-2] == SH_TOK_GREATER))){
174  if (toktyp[ntok-1] != SH_TOK_OTHER) {
175  fprintf(dev,"%s\n", SHELL_SYNERRMSG);
176  continue;
177  }
178  if (toktyp[ntok-2] == SH_TOK_LESS) {
179  if (inname != NULL) {
180  fprintf(dev,"%s\n", SHELL_SYNERRMSG);
181  continue;
182  }
183  inname = &tokbuf[tok[ntok-1]];
184  } else {
185  if (outname != NULL) {
186  fprintf(dev,"%s\n", SHELL_SYNERRMSG);
187  continue;
188  }
189  outname = &tokbuf[tok[ntok-1]];
190  }
191  ntok -= 2;
192  tlen = tok[ntok];
193  }
194 
195  /* Verify remaining tokens are type "other" */
196 
197  for (i=0; i<ntok; i++) {
198  if (toktyp[i] != SH_TOK_OTHER) {
199  break;
200  }
201  }
202  if ((ntok == 0) || (i < ntok)) {
203  fprintf(dev, SHELL_SYNERRMSG);
204  continue;
205  }
206 
207  stdinput = stdoutput = dev;
208 
209  /* Lookup first token in the command table */
210 
211  for (j = 0; j < ncmd; j++) {
212  src = cmdtab[j].cname;
213  cmp = tokbuf;
214  diff = FALSE;
215  while (*src != NULLCH) {
216  if (*cmp != *src) {
217  diff = TRUE;
218  break;
219  }
220  src++;
221  cmp++;
222  }
223  if (diff || (*cmp != NULLCH)) {
224  continue;
225  } else {
226  break;
227  }
228  }
229 
230  /* Handle command not found */
231 
232  if (j >= ncmd) {
233  fprintf(dev, "command %s not found\n", tokbuf);
234  continue;
235  }
236 
237  /* Handle built-in command */
238 
239  if (cmdtab[j].cbuiltin) { /* No background or redirect. */
240  if (inname != NULL || outname != NULL || backgnd){
241  fprintf(dev, SHELL_BGERRMSG);
242  continue;
243  } else {
244  /* Set up arg vector for call */
245 
246  for (i=0; i<ntok; i++) {
247  args[i] = &tokbuf[tok[i]];
248  }
249 
250  /* Call builtin shell function */
251 
252  if ((*cmdtab[j].cfunc)(ntok, args)
253  == SHELL_EXIT) {
254  break;
255  }
256  }
257  continue;
258  }
259 
260  /* Open files and redirect I/O if specified */
261 
262  if (inname != NULL) {
263  stdinput = open(NAMESPACE,inname,"ro");
264  if (stdinput == SYSERR) {
265  fprintf(dev, SHELL_INERRMSG, inname);
266  continue;
267  }
268  }
269  if (outname != NULL) {
270  stdoutput = open(NAMESPACE,outname,"w");
271  if (stdoutput == SYSERR) {
272  fprintf(dev, SHELL_OUTERRMSG, outname);
273  continue;
274  } else {
275  control(stdoutput, F_CTL_TRUNC, 0, 0);
276  }
277  }
278 
279  /* Spawn child thread for non-built-in commands */
280 
281  child = create(cmdtab[j].cfunc,
283  cmdtab[j].cname, 2, ntok, &tmparg);
284 
285  /* If creation or argument copy fails, report error */
286 
287  if ((child == SYSERR) ||
288  (addargs(child, ntok, tok, tlen, tokbuf, &tmparg)
289  == SYSERR) ) {
290  fprintf(dev, SHELL_CREATMSG);
291  continue;
292  }
293 
294  /* Set stdinput and stdoutput in child to redirect I/O */
295 
296  proctab[child].prdesc[0] = stdinput;
297  proctab[child].prdesc[1] = stdoutput;
298 
299  msg = recvclr();
300  resume(child);
301  if (! backgnd) {
302  msg = receive();
303  while (msg != child) {
304  msg = receive();
305  }
306  }
307  }
308 
309  /* Terminate the shell process by returning from the top level */
310 
311  fprintf(dev,SHELL_EXITMSG);
312  return OK;
313 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
#define F_CTL_TRUNC
ファイルを切り捨てる。
Definition: file.h:23
#define SHELL_EXITMSG
XINUシェル終了時のメッセージ
Definition: shell.h:43
#define SH_TOK_GREATER
大なり&#39;>&#39;トークン
Definition: shell.h:79
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define SHELL_BAN5
シェル起動時のバナー その5
Definition: shell.h:28
syscall read(did32, char *, uint32)
Definition: read.c:9
#define OK
処理が成功した場合
Definition: kernel.h:77
#define EOF
ファイルの終端(End of File)に達した場合(読み込み処理に用いる)
Definition: kernel.h:81
#define SHELL_CMDPRIO
コマンドに対するプロセス優先度
Definition: shell.h:15
byte bool8
Boolean値
Definition: kernel.h:36
int32 lexan(char *, int32, char *, int32 *, int32[], int32[])
Definition: lexan.c:10
syscall control(did32, int32, int32, int32)
Definition: control.c:9
umsg32 receive(void)
メッセージの受信を待ち、受信後にreceive()の呼び出し者にメッセージを返す。
Definition: receive.c:17
#define SH_TOK_OTHER
その他(&#39;&&#39;、&#39;<&#39;、&#39;>以外&#39;)のトークン(例:英数字文字列)
Definition: shell.h:81
#define SHELL_INERRMSG
インプットとして用いるファイルが開けなかった場合のエラーメッセージ
Definition: shell.h:49
#define SHELL_BAN0
シェル起動時のバナー その0(文字色を赤くするANSIエスケープシーケンス)
Definition: shell.h:18
#define SHELL_BAN6
シェル起動時のバナー その6
Definition: shell.h:30
#define SHELL_EXIT
XINUシェルを終了させる返り値
Definition: shell.h:88
#define SHELL_BAN7
シェル起動時のバナー その7
Definition: shell.h:32
#define SHELL_CMDSTK
コマンドを実行するプロセスに対するスタックサイズ
Definition: shell.h:11
status addargs(pid32, int32, int32[], int32, char *, void *)
XINUシェルが作成したコマンドプロセスのスタックに引数argv(任意個)のローカルコピーを追加する。 ...
Definition: addargs.c:33
char * cname
コマンド名称
Definition: shell.h:100
#define FALSE
Boolean False(0)
Definition: kernel.h:63
#define SH_NEWLINE
LF改行コード&#39; &#39;(字句解析時に用いる)
Definition: shell.h:56
#define TRUE
Boolean True(1)
Definition: kernel.h:65
umsg32 recvclr(void)
受信メッセージをクリアし、待機している場合はメッセージを返す。
Definition: recvclr.c:14
#define SHELL_BAN3
シェル起動時のバナー その3
Definition: shell.h:24
#define SHELL_BAN1
シェル起動時のバナー その1
Definition: shell.h:20
#define SHELL_MAXTOK
一行あたりの最大トークン数
Definition: shell.h:9
#define SHELL_PROMPT
コマンドプロンプト
Definition: shell.h:39
int16 prdesc[NDESC]
プロセス用のデバイスディスクリプタ
Definition: process.h:108
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 did32
デバイスID
Definition: kernel.h:28
pri16 resume(pid32)
プロセスを休止状態(サスペンド)からREADY状態に遷移させる。
Definition: resume.c:20
pid32 create(void *, uint32, pri16, char *, uint32,...)
関数の実行を開始するプロセスを作成する。
Definition: create.c:55
#define SHELL_STRTMSG
Welcomeメッセージ
Definition: shell.h:41
#define SHELL_CREATMSG
コマンド実行時にプロセスを生成できなかった場合のエラーメッセージ
Definition: shell.h:47
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
int32 pid32
プロセスID
Definition: kernel.h:26
#define SHELL_BGERRMSG
I/Oリダイレクトできなかった場合もしくはバックグラウンドのXINUシェルビルトインコマンドエラー用のメッセ...
Definition: shell.h:53
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
#define SH_TOK_AMPER
アンパサンド&#39;&&#39;トークン
Definition: shell.h:75
syscall open(did32, char *, char *)
Definition: open.c:9
#define SHELL_BAN2
シェル起動時のバナー その2
Definition: shell.h:22
#define SHELL_BAN4
シェル起動時のバナー その4
Definition: shell.h:26
#define NAMESPACE
Definition: conf.h:35
#define SHELL_OUTERRMSG
アウトプットとして用いるファイルが開けなかった場合のエラーメッセージ
Definition: shell.h:51
const struct cmdent cmdtab[]
XINUシェルが提供するコマンドを管理する配列
Definition: shell.c:10
uint32 ncmd
XINUシェルが提供するコマンドの数
Definition: shell.c:35
#define SHELL_SYNERRMSG
シンタックスエラー時のメッセージ
Definition: shell.h:45
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
#define SHELL_BUFLEN
インプットバッファの長さ
Definition: shell.h:7
#define SHELL_BAN9
シェル起動時のバナー その9(文字色をデフォルトに戻すANSIエスケープシーケンス)
Definition: shell.h:36
#define SHELL_BAN8
シェル起動時のバナー その8
Definition: shell.h:34
#define SH_TOK_LESS
小なり&#39;<&#39;トークン
Definition: shell.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ signal()

syscall signal ( sid32  sem)

セマフォにシグナルを送り、待機プロセスがある場合は解除する。

Step1. 割り込みを禁止する。
Step2. 不正なセマフォIDの場合は、割り込みを許可状態に復元し、処理を終了する。
Step3. 引数で渡されたセマフォがFREE状態の場合は、割り込みを許可状態に復元し、処理を終了する。
Step4. セマフォ待ち状態のプロセスがある場合、キューの先頭にあるプロセスをREADY状態にする。
Step5. 割り込みを許可状態に復元する。

Parameters
[in]semシグナルを送信したいセマフォのID
Returns
シグナルを送信した場合はOK、「セマフォIDが不正な場合」や「引数で渡されたセマフォがFREE状態の場合」はSYSERRを返す。

Definition at line 18 of file signal.c.

References dequeue(), disable(), isbadsem, OK, ready(), restore(), S_FREE, sentry::scount, semtab, sentry::squeue, sentry::sstate, and SYSERR.

Referenced by ethhandler(), freebuf(), ip_enqueue(), lflclose(), lflcontrol(), lflgetc(), lflputc(), lflseek(), lfsetup(), lfsopen(), mark(), ptrecv(), ptsend(), rdscontrol(), rdsprocess(), rdsread(), rdswrite(), rflclose(), rflread(), rflseek(), rflwrite(), rfscontrol(), rfsopen(), ttycontrol(), ttyhandle_in(), and xsh_ls().

19 {
20  intmask mask; /* Saved interrupt mask */
21  struct sentry *semptr; /* Ptr to sempahore table entry */
22 
23  mask = disable();
24  if (isbadsem(sem))
25  {
26  restore(mask);
27  return SYSERR;
28  }
29  semptr = &semtab[sem];
30  if (semptr->sstate == S_FREE)
31  {
32  restore(mask);
33  return SYSERR;
34  }
35  if ((semptr->scount++) < 0)
36  { /* Release a waiting process */
37  ready(dequeue(semptr->squeue));
38  }
39  restore(mask);
40  return OK;
41 }
void restore(intmask)
byte sstate
エントリ状態が利用可能(S_FREE)か、利用中(S_USED)かを表す。
Definition: semaphore.h:22
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
セマフォテーブルエントリであり、本構造体の配列(長さNSEM)が静的に確保される。
Definition: semaphore.h:19
#define isbadsem(s)
セマフォIDが不適切かどうかを確認する。
Definition: semaphore.h:40
#define OK
処理が成功した場合
Definition: kernel.h:77
status ready(pid32)
プロセスをCPUサービスの対象にする。
Definition: ready.c:21
pid32 dequeue(qid16)
プロセスキューテーブルからキューを削除し、リスト先頭のプロセスIDを返す。
Definition: queue.c:78
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
qid16 squeue
セマフォ待機中プロセスのキュー
Definition: semaphore.h:26
int32 scount
セマフォカウント(負の値(-N)の場合は、キューにN個の待機プロセスがある。それ以外はキューが空である) ...
Definition: semaphore.h:24
#define S_FREE
セマフォテーブルエントリが利用可能
Definition: semaphore.h:11
struct sentry semtab[]
セマフォテーブルエントリのextern宣言
Definition: initialize.c:25
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ signaln()

syscall signaln ( sid32  sem,
int32  count 
)

セマフォにシグナルをN回送り、N個の待機プロセスがある場合はそれらをREADY状態にする。

基本的な仕様は signal()と同様であり、差異は以下の通りである。
 ・待機プロセスがある限り、シグナル送信を続ける事(送信上限は引数で指定された回数)
 ・プロセスをREADY状態にする間は再スケジューリングを遅延(Defer)させる事

Parameters
[in]semシグナルを送信したいセマフォのID
[in]countシグナルを送信する数(最大)
Returns
シグナルを送信した場合はOK、「セマフォIDが不正な場合」や「引数で渡されたセマフォがFREE状態の場合」はSYSERRを返す。

Definition at line 16 of file signaln.c.

References DEFER_START, DEFER_STOP, dequeue(), disable(), isbadsem, OK, ready(), resched_cntl(), restore(), S_FREE, sentry::scount, semtab, sentry::squeue, sentry::sstate, and SYSERR.

Referenced by ttyhandle_in(), and ttyhandle_out().

17 {
18  intmask mask; /* Saved interrupt mask */
19  struct sentry *semptr; /* Ptr to sempahore table entry */
20 
21  mask = disable();
22  if (isbadsem(sem) || (count < 0))
23  {
24  restore(mask);
25  return SYSERR;
26  }
27  semptr = &semtab[sem];
28  if (semptr->sstate == S_FREE)
29  {
30  restore(mask);
31  return SYSERR;
32  }
33 
35  for (; count > 0; count--)
36  {
37  if ((semptr->scount++) < 0)
38  {
39  ready(dequeue(semptr->squeue));
40  }
41  }
43  restore(mask);
44  return OK;
45 }
void restore(intmask)
byte sstate
エントリ状態が利用可能(S_FREE)か、利用中(S_USED)かを表す。
Definition: semaphore.h:22
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
セマフォテーブルエントリであり、本構造体の配列(長さNSEM)が静的に確保される。
Definition: semaphore.h:19
#define isbadsem(s)
セマフォIDが不適切かどうかを確認する。
Definition: semaphore.h:40
#define OK
処理が成功した場合
Definition: kernel.h:77
status ready(pid32)
プロセスをCPUサービスの対象にする。
Definition: ready.c:21
status resched_cntl(int32)
再スケジューリングを延期させるか、もしくは許可させるかを制御する。
Definition: resched.c:81
pid32 dequeue(qid16)
プロセスキューテーブルからキューを削除し、リスト先頭のプロセスIDを返す。
Definition: queue.c:78
#define DEFER_STOP
遅延リスケジューリングの停止
Definition: resched.h:10
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
#define DEFER_START
遅延リスケジューリングの開始
Definition: resched.h:8
qid16 squeue
セマフォ待機中プロセスのキュー
Definition: semaphore.h:26
int32 scount
セマフォカウント(負の値(-N)の場合は、キューにN個の待機プロセスがある。それ以外はキューが空である) ...
Definition: semaphore.h:24
#define S_FREE
セマフォテーブルエントリが利用可能
Definition: semaphore.h:11
struct sentry semtab[]
セマフォテーブルエントリのextern宣言
Definition: initialize.c:25
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sleep()

syscall sleep ( int32  )

Definition at line 11 of file sleep.c.

References MAXSECONDS, OK, sleepms(), and SYSERR.

Referenced by xsh_sleep().

14 {
15  if ( (delay < 0) || (delay > MAXSECONDS) ) {
16  return SYSERR;
17  }
18  sleepms(1000*delay);
19  return OK;
20 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
int32 delay(int n)
マイクロ秒単位で処理を遅らせる。
Definition: initialize.c:262
#define MAXSECONDS
Definition: sleep.c:5
syscall sleepms(int32 delay)
Definition: sleep.c:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sleepms()

syscall sleepms ( int32  )

Definition at line 26 of file sleep.c.

References currpid, disable(), insertd(), OK, PR_SLEEP, proctab, procent::prstate, resched(), restore(), sleepq, SYSERR, and yield().

Referenced by main(), and sleep().

29 {
30  intmask mask; /* Saved interrupt mask */
31 
32  if (delay < 0) {
33  return SYSERR;
34  }
35 
36  if (delay == 0) {
37  yield();
38  return OK;
39  }
40 
41  /* Delay calling process */
42 
43  mask = disable();
44  if (insertd(currpid, sleepq, delay) == SYSERR) {
45  restore(mask);
46  return SYSERR;
47  }
48 
50  resched();
51  restore(mask);
52  return OK;
53 }
pid32 currpid
現在実行中のプロセス。
Definition: initialize.c:32
void restore(intmask)
qid16 sleepq
スリープ中のプロセスキュー
Definition: clkinit.c:7
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
status insertd(pid32, qid16, int32)
Definition: insertd.c:9
syscall yield(void)
CPU実行権を自発的に放棄する(タイムスライスを終了する)。
Definition: yield.c:12
#define PR_SLEEP
プロセスが休眠中(タイマー待機中)の状態。
Definition: process.h:43
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int32 delay(int n)
マイクロ秒単位で処理を遅らせる。
Definition: initialize.c:262
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
void resched(void)
最優先の適切なプロセスにCPU実行権を渡す。
Definition: resched.c:22
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ spicontrol()

devcall spicontrol ( struct dentry ,
int32  ,
int32  ,
int32   
)

Definition at line 9 of file spicontrol.c.

References spi_csreg::ch, spi_csreg::chconf, spi_csreg::chrx, spi_csreg::chstat, spi_csreg::chtx, dentry::dvcsr, spi_transfer::length, OK, spi_transfer::rxbuf, SPI_CHCONF_FORCE, SPI_CHSTAT_RXS, SPI_CHSTAT_TXS, SPI_CTRL_TRANSFER, and spi_transfer::txbuf.

15 {
16  struct spi_csreg *csrptr; /* SPI control and status regs */
17  struct spi_transfer *msg; /* Message pointer */
18  int i; /* For loop index */
19 
20  /* Get the pointer to the SPI CSRs */
21 
22  csrptr = (struct spi_csreg *)devptr->dvcsr;
23 
24  /* Get the pointer to the message */
25 
26  msg = (struct spi_transfer *)arg1;
27 
28  switch(func) {
29 
30  /* This is a SPI transfer */
31 
32  case SPI_CTRL_TRANSFER:
33 
34  for(i = 0; i < msg->length; i++) {
35 
36  /* Wait while the transmit register is not empty */
37 
38  while((csrptr->ch[0].chstat & SPI_CHSTAT_TXS) == 0);
39 
40  /* Send a byte */
41 
42  csrptr->ch[0].chtx = msg->txbuf[i];
43 
44  /* Wait until there is a byte in the receive register */
45 
46  while((csrptr->ch[0].chstat & SPI_CHSTAT_RXS) == 0);
47 
48  /* Read the byte from the receive register */
49 
50  msg->rxbuf[i] = csrptr->ch[0].chrx;
51  }
52 
53  /* End the transfer by changing CS level */
54 
55  csrptr->ch[0].chconf &= ~SPI_CHCONF_FORCE;
56  csrptr->ch[0].chconf |= SPI_CHCONF_FORCE;
57 
58  break;
59  }
60 
61  return OK;
62 }
struct spi_csreg::@14 ch[3]
byte * txbuf
Definition: spi.h:74
#define SPI_CHSTAT_TXS
Definition: spi.h:71
#define OK
処理が成功した場合
Definition: kernel.h:77
volatile uint32 chrx
Definition: spi.h:18
#define SPI_CHCONF_FORCE
Definition: spi.h:60
Definition: spi.h:3
#define SPI_CTRL_TRANSFER
Definition: spi.h:79
byte * rxbuf
Definition: spi.h:75
volatile uint32 chtx
Definition: spi.h:17
volatile uint32 chconf
Definition: spi.h:14
int32 length
Definition: spi.h:76
#define SPI_CHSTAT_RXS
Definition: spi.h:70
volatile uint32 chstat
Definition: spi.h:15

◆ spiinit()

int32 spiinit ( struct dentry )

Definition at line 14 of file spiinit.c.

References am335x_padctl, AM335X_PADCTL_PEN, AM335X_PADCTL_PUP, AM335X_PADCTL_RXTX, AM335X_PADCTL_TX, spi_csreg::ch, spi_csreg::chconf, spi_csreg::chctrl, dentry::dvminor, spi_csreg::modulctrl, OK, SPI_0_ADDR, SPI_0_PADCTL_CS0, SPI_0_PADCTL_D0, SPI_0_PADCTL_D1, SPI_0_PADCTL_SCLK, SPI_1_ADDR, SPI_1_PADCTL_CS0, SPI_1_PADCTL_D0, SPI_1_PADCTL_D1, SPI_1_PADCTL_SCLK, SPI_CHCONF_CLKD, SPI_CHCONF_DPE1, SPI_CHCONF_EPOL, SPI_CHCONF_FORCE, SPI_CHCONF_IS, SPI_CHCONF_WL, SPI_CHCTRL_EN, SPI_MODULCTRL_SINGLE, SPI_SYSCONFIG_SOFTRESET, SPI_SYSSTATUS_RESETDONE, spi_csreg::sysconfig, and spi_csreg::sysstatus.

16 {
17  struct spi_csreg *csrptr; /* SPI control and status regs */
18 
19  /* Set the CSR address and the pads */
20 
21  if (devptr->dvminor == 0)
22  {
23  csrptr = (struct spi_csreg *)SPI_0_ADDR;
27  0);
31  0);
35  0);
39  0);
40  }
41  else
42  {
43  *((uint32 *)0x44E00050) = 0x2;
44  csrptr = (struct spi_csreg *)SPI_1_ADDR;
48  3);
52  3);
56  3);
60  3);
61  }
62 
63  /* Reset the SPI device */
64 
66  while ((csrptr->sysstatus & SPI_SYSSTATUS_RESETDONE) == 0)
67  ;
68 
69  /* Put the device in single channel mode */
70 
72 
73  /* Set the default frequency and CS level */
74 
75  csrptr->ch[0].chconf = SPI_CHCONF_CLKD | SPI_CHCONF_EPOL |
76  (SPI_CHCONF_WL & 0x00000380) |
79 
80  /* Enable the channel */
81 
82  csrptr->ch[0].chctrl |= SPI_CHCTRL_EN;
83 
84  return OK;
85 }
struct spi_csreg::@14 ch[3]
#define SPI_CHCONF_DPE1
Definition: spi.h:57
#define SPI_1_PADCTL_D1
Definition: spi.h:35
#define AM335X_PADCTL_PEN
プルアップダウンが有効
Definition: am335x_control.h:7
#define SPI_CHCONF_CLKD
Definition: spi.h:50
volatile uint32 sysconfig
Definition: spi.h:6
#define SPI_MODULCTRL_SINGLE
Definition: spi.h:44
#define SPI_0_PADCTL_SCLK
Definition: spi.h:28
#define SPI_CHCONF_IS
Definition: spi.h:58
#define SPI_0_PADCTL_D1
Definition: spi.h:30
#define SPI_0_PADCTL_D0
Definition: spi.h:29
#define OK
処理が成功した場合
Definition: kernel.h:77
#define SPI_1_PADCTL_D0
Definition: spi.h:34
#define SPI_1_PADCTL_SCLK
Definition: spi.h:33
#define AM335X_PADCTL_PUP
プルアップが選択された
Definition: am335x_control.h:9
#define SPI_CHCTRL_EN
Definition: spi.h:68
#define SPI_SYSSTATUS_RESETDONE
Definition: spi.h:42
#define AM335X_PADCTL_TX
出力限定モード
#define SPI_SYSCONFIG_SOFTRESET
Definition: spi.h:40
volatile uint32 chctrl
Definition: spi.h:16
#define SPI_0_ADDR
Definition: spi.h:25
#define SPI_CHCONF_FORCE
Definition: spi.h:60
Definition: spi.h:3
#define SPI_CHCONF_EPOL
Definition: spi.h:51
#define am335x_padctl(addr, val)
引数で指定されたアドレスに値を代入する。
#define SPI_CHCONF_WL
Definition: spi.h:52
#define SPI_1_PADCTL_CS0
Definition: spi.h:36
volatile uint32 modulctrl
Definition: spi.h:12
#define SPI_0_PADCTL_CS0
Definition: spi.h:31
volatile uint32 sysstatus
Definition: spi.h:7
#define AM335X_PADCTL_RXTX
入力モードもしくは出力モード
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
volatile uint32 chconf
Definition: spi.h:14
#define SPI_1_ADDR
Definition: spi.h:26

◆ suspend()

syscall suspend ( pid32  pid)

プロセスを一時停止し、休止状態(サスペンド)に遷移させる。

Step1. 割り込み禁止状態とし、割り込みマスクを保持する。
Step2. PIDが正常値か、NULLプロセスではないかを確認する。
NULLプロセスが休止状態になった場合、動かすプロセスがREADYリストから無くなる可能性がある。
Step3. サスペンド対象プロセス情報を取得する。
Step4. サスペンド可能なプロセスは、現在実行中かREADY状態のプロセスだけである。
READY状態の場合:READYリストからサスペンド対象プロセスを除外し、サスペンド状態とする。
実行中の場合:サスペンド状態とし、再スケジューリングを行う。
それ以外:割り込み状態(割り込みマスク)を元に戻し、エラー終了
Step5. 現在の優先度を取得する。 Step6. 割り込み状態(割り込みマスク)を元に戻す。

Parameters
[in]pid休止状態に移行させるプロセスのID
Returns
一時休止(サスペンド)されたプロセスの優先度

Definition at line 23 of file suspend.c.

References disable(), getitem(), isbadpid, NULLPROC, PR_CURR, PR_READY, PR_SUSP, proctab, procent::prprio, procent::prstate, resched(), restore(), and SYSERR.

24 {
25  intmask mask; /* Saved interrupt mask */
26  struct procent *prptr; /* Ptr to process's table entry */
27  pri16 prio; /* Priority to return */
28 
29  mask = disable();
30  if (isbadpid(pid) || (pid == NULLPROC))
31  {
32  restore(mask);
33  return SYSERR;
34  }
35 
36  /* Only suspend a process that is current or ready */
37 
38  prptr = &proctab[pid];
39  if ((prptr->prstate != PR_CURR) && (prptr->prstate != PR_READY))
40  {
41  restore(mask);
42  return SYSERR;
43  }
44  if (prptr->prstate == PR_READY)
45  {
46  getitem(pid); /* Remove a ready process */
47  /* from the ready list */
48  prptr->prstate = PR_SUSP;
49  }
50  else
51  {
52  prptr->prstate = PR_SUSP; /* Mark the current process */
53  resched(); /* suspended and resched. */
54  }
55  prio = prptr->prprio;
56  restore(mask);
57  return prio;
58 }
void restore(intmask)
#define PR_READY
プロセスが準備完了(READY)状態。
Definition: process.h:39
#define PR_SUSP
プロセスがサスペンド(休止)させられた状態。
Definition: process.h:45
#define isbadpid(x)
プロセスIDを検証する。割り込みが無効になっている事を想定している。
Definition: process.h:71
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
int16 pri16
プロセス優先度
Definition: kernel.h:30
#define NULLPROC
NULLプロセスのID。NULLプロセスは、他に動かすプロセスがない時に動く空プロセス
Definition: process.h:54
pri16 prprio
プロセスのスケジューリング優先度。
Definition: process.h:90
#define PR_CURR
プロセスが現在動作中。
Definition: process.h:37
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
void resched(void)
最優先の適切なプロセスにCPU実行権を渡す。
Definition: resched.c:22
pid32 getitem(pid32)
キューの任意の位置からプロセスを取り出す。
Definition: getitem.c:51
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:

◆ trap()

void trap ( int32  )

Referenced by irq_dispatch().

Here is the caller graph for this function:

◆ ttycontrol()

devcall ttycontrol ( struct dentry ,
int32  ,
int32  ,
int32   
)

Definition at line 9 of file ttycontrol.c.

References dentry::dvminor, FALSE, OK, semcount(), signal(), SYSERR, TC_ECHO, TC_ICHARS, TC_MODEC, TC_MODEK, TC_MODER, TC_NEXTC, TC_NOECHO, TRUE, ttytab, TY_IMCBREAK, TY_IMCOOKED, TY_IMRAW, ttycblk::tyiecho, ttycblk::tyimode, ttycblk::tyisem, ttycblk::tyitail, and wait().

15 {
16  struct ttycblk *typtr; /* Pointer to tty control block */
17  char ch; /* Character for lookahead */
18 
19  typtr = &ttytab[devptr->dvminor];
20 
21  /* Process the request */
22 
23  switch ( func ) {
24 
25  case TC_NEXTC:
26  wait(typtr->tyisem);
27  ch = *typtr->tyitail;
28  signal(typtr->tyisem);
29  return (devcall)ch;
30 
31  case TC_MODER:
32  typtr->tyimode = TY_IMRAW;
33  return (devcall)OK;
34 
35  case TC_MODEC:
36  typtr->tyimode = TY_IMCOOKED;
37  return (devcall)OK;
38 
39  case TC_MODEK:
40  typtr->tyimode = TY_IMCBREAK;
41  return (devcall)OK;
42 
43  case TC_ICHARS:
44  return(semcount(typtr->tyisem));
45 
46  case TC_ECHO:
47  typtr->tyiecho = TRUE;
48  return (devcall)OK;
49 
50  case TC_NOECHO:
51  typtr->tyiecho = FALSE;
52  return (devcall)OK;
53 
54  default:
55  return (devcall)SYSERR;
56  }
57 }
syscall semcount(sid32)
セマフォのカウント値を返す。
Definition: semcount.c:18
#define TC_MODEC
Definition: tty.h:80
#define TC_ECHO
Definition: tty.h:83
#define TC_MODER
Definition: tty.h:79
bool8 tyiecho
Definition: tty.h:39
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define TC_ICHARS
Definition: tty.h:82
#define TY_IMCBREAK
Definition: tty.h:23
#define OK
処理が成功した場合
Definition: kernel.h:77
#define TC_NEXTC
Definition: tty.h:78
#define TC_MODEK
Definition: tty.h:81
Definition: tty.h:26
#define FALSE
Boolean False(0)
Definition: kernel.h:63
#define TRUE
Boolean True(1)
Definition: kernel.h:65
struct ttycblk ttytab[]
Definition: ttyinit.c:11
#define TC_NOECHO
Definition: tty.h:84
char tyimode
Definition: tty.h:38
#define TY_IMCOOKED
Definition: tty.h:22
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
int32 devcall
デバイスコール関数 返り値の型
Definition: kernel.h:49
sid32 tyisem
Definition: tty.h:30
#define TY_IMRAW
Definition: tty.h:21
char * tyitail
Definition: tty.h:28
Here is the call graph for this function:

◆ ttygetc()

devcall ttygetc ( struct dentry )

Definition at line 9 of file ttygetc.c.

References dentry::dvminor, EOF, ttytab, TY_IBUFLEN, TY_IMCOOKED, ttycblk::tyeof, ttycblk::tyeofch, ttycblk::tyibuff, ttycblk::tyihead, ttycblk::tyimode, ttycblk::tyisem, and wait().

Referenced by ttyread().

12 {
13  char ch; /* Character to return */
14  struct ttycblk *typtr; /* Pointer to ttytab entry */
15 
16  typtr = &ttytab[devptr->dvminor];
17 
18  /* Wait for a character in the buffer and extract one character */
19 
20  wait(typtr->tyisem);
21  ch = *typtr->tyihead++;
22 
23  /* Wrap around to beginning of buffer, if needed */
24 
25  if (typtr->tyihead >= &typtr->tyibuff[TY_IBUFLEN]) {
26  typtr->tyihead = typtr->tyibuff;
27  }
28 
29  /* In cooked mode, check for the EOF character */
30 
31  if ( (typtr->tyimode == TY_IMCOOKED) && (typtr->tyeof) &&
32  (ch == typtr->tyeofch) ) {
33  return (devcall)EOF;
34  }
35 
36  return (devcall)ch;
37 }
char tyeofch
Definition: tty.h:48
char tyibuff[TY_IBUFLEN]
Definition: tty.h:29
#define EOF
ファイルの終端(End of File)に達した場合(読み込み処理に用いる)
Definition: kernel.h:81
Definition: tty.h:26
char * tyihead
Definition: tty.h:27
struct ttycblk ttytab[]
Definition: ttyinit.c:11
char tyimode
Definition: tty.h:38
#define TY_IMCOOKED
Definition: tty.h:22
syscall wait(sid32)
Definition: wait.c:9
#define TY_IBUFLEN
Definition: tty.h:13
bool8 tyeof
Definition: tty.h:47
int32 devcall
デバイスコール関数 返り値の型
Definition: kernel.h:49
sid32 tyisem
Definition: tty.h:30
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttyhandle_in()

void ttyhandle_in ( struct ttycblk ,
struct uart_csreg  
)

Definition at line 13 of file ttyhandle_in.c.

References uart_csreg::buffer, echoch(), eputc(), erase1(), FALSE, semcount(), signal(), signaln(), TRUE, ttykickout(), TY_IBUFLEN, TY_IMCBREAK, TY_IMRAW, TY_NEWLINE, TY_RETURN, ttycblk::tyeof, ttycblk::tyeofch, ttycblk::tyibuff, ttycblk::tyicrlf, ttycblk::tyicursor, ttycblk::tyiecho, ttycblk::tyierase, ttycblk::tyierasec, ttycblk::tyierasec2, ttycblk::tyifullc, ttycblk::tyikill, ttycblk::tyikillc, ttycblk::tyimode, ttycblk::tyisem, ttycblk::tyitail, ttycblk::tyoflow, ttycblk::tyoheld, ttycblk::tyostart, and ttycblk::tyostop.

Referenced by ttyhandler().

17 {
18  char ch; /* Next char from device */
19  int32 avail; /* Chars available in buffer */
20 
21  ch = csrptr->buffer;
22 
23  /* Compute chars available */
24 
25  avail = semcount(typtr->tyisem);
26  if (avail < 0) { /* One or more processes waiting*/
27  avail = 0;
28  }
29 
30  /* Handle raw mode */
31 
32  if (typtr->tyimode == TY_IMRAW) {
33  if (avail >= TY_IBUFLEN) { /* No space => ignore input */
34  return;
35  }
36 
37  /* Place char in buffer with no editing */
38 
39  *typtr->tyitail++ = ch;
40 
41  /* Wrap buffer pointer */
42 
43  if (typtr->tyitail >= &typtr->tyibuff[TY_IBUFLEN]) {
44  typtr->tyitail = typtr->tyibuff;
45  }
46 
47  /* Signal input semaphore and return */
48  signal(typtr->tyisem);
49  return;
50  }
51 
52  /* Handle cooked and cbreak modes (common part) */
53 
54  if ( (ch == TY_RETURN) && typtr->tyicrlf ) {
55  ch = TY_NEWLINE;
56  }
57 
58  /* If flow control is in effect, handle ^S and ^Q */
59 
60  if (typtr->tyoflow) {
61  if (ch == typtr->tyostart) { /* ^Q starts output */
62  typtr->tyoheld = FALSE;
63  ttykickout(csrptr);
64  return;
65  } else if (ch == typtr->tyostop) { /* ^S stops output */
66  typtr->tyoheld = TRUE;
67  return;
68  }
69  }
70 
71  typtr->tyoheld = FALSE; /* Any other char starts output */
72 
73  if (typtr->tyimode == TY_IMCBREAK) { /* Just cbreak mode */
74 
75  /* If input buffer is full, send bell to user */
76 
77  if (avail >= TY_IBUFLEN) {
78  eputc(typtr->tyifullc, typtr, csrptr);
79  } else { /* Input buffer has space for this char */
80  *typtr->tyitail++ = ch;
81 
82  /* Wrap around buffer */
83 
84  if (typtr->tyitail>=&typtr->tyibuff[TY_IBUFLEN]) {
85  typtr->tyitail = typtr->tyibuff;
86  }
87  if (typtr->tyiecho) { /* Are we echoing chars?*/
88  echoch(ch, typtr, csrptr);
89  }
90  signal(typtr->tyisem);
91  }
92  return;
93 
94  } else { /* Just cooked mode (see common code above) */
95 
96  /* Line kill character arrives - kill entire line */
97 
98  if (ch == typtr->tyikillc && typtr->tyikill) {
99  typtr->tyitail -= typtr->tyicursor;
100  if (typtr->tyitail < typtr->tyibuff) {
101  typtr->tyitail += TY_IBUFLEN;
102  }
103  typtr->tyicursor = 0;
104  eputc(TY_RETURN, typtr, csrptr);
105  eputc(TY_NEWLINE, typtr, csrptr);
106  return;
107  }
108 
109  /* Erase (backspace) character */
110 
111  if ( ((ch==typtr->tyierasec) || (ch==typtr->tyierasec2))
112  && typtr->tyierase) {
113  if (typtr->tyicursor > 0) {
114  typtr->tyicursor--;
115  erase1(typtr, csrptr);
116  }
117  return;
118  }
119 
120  /* End of line */
121 
122  if ( (ch == TY_NEWLINE) || (ch == TY_RETURN) ) {
123  if (typtr->tyiecho) {
124  echoch(ch, typtr, csrptr);
125  }
126  *typtr->tyitail++ = ch;
127  if (typtr->tyitail>=&typtr->tyibuff[TY_IBUFLEN]) {
128  typtr->tyitail = typtr->tyibuff;
129  }
130  /* Make entire line (plus \n or \r) available */
131  signaln(typtr->tyisem, typtr->tyicursor + 1);
132  typtr->tyicursor = 0; /* Reset for next line */
133  return;
134  }
135 
136  /* Character to be placed in buffer - send bell if */
137  /* buffer has overflowed */
138 
139  avail = semcount(typtr->tyisem);
140  if (avail < 0) {
141  avail = 0;
142  }
143  if ((avail + typtr->tyicursor) >= TY_IBUFLEN-1) {
144  eputc(typtr->tyifullc, typtr, csrptr);
145  return;
146  }
147 
148  /* EOF character: recognize at beginning of line, but */
149  /* print and ignore otherwise. */
150 
151  if (ch == typtr->tyeofch && typtr->tyeof) {
152  if (typtr->tyiecho) {
153  echoch(ch, typtr, csrptr);
154  }
155  if (typtr->tyicursor != 0) {
156  return;
157  }
158  *typtr->tyitail++ = ch;
159  signal(typtr->tyisem);
160  return;
161  }
162 
163 
164  /* Echo the character */
165 
166  if (typtr->tyiecho) {
167  echoch(ch, typtr, csrptr);
168  }
169 
170  /* Insert in the input buffer */
171 
172  typtr->tyicursor++;
173  *typtr->tyitail++ = ch;
174 
175  /* Wrap around if needed */
176 
177  if (typtr->tyitail >= &typtr->tyibuff[TY_IBUFLEN]) {
178  typtr->tyitail = typtr->tyibuff;
179  }
180  return;
181  }
182 }
syscall semcount(sid32)
セマフォのカウント値を返す。
Definition: semcount.c:18
local void erase1(struct ttycblk *, struct uart_csreg *)
Definition: ttyhandle_in.c:188
syscall signaln(sid32, int32)
セマフォにシグナルをN回送り、N個の待機プロセスがある場合はそれらをREADY状態にする。 ...
Definition: signaln.c:16
local void echoch(char, struct ttycblk *, struct uart_csreg *)
Definition: ttyhandle_in.c:231
#define TY_IMCBREAK
Definition: tty.h:23
local void eputc(char, struct ttycblk *, struct uart_csreg *)
Definition: ttyhandle_in.c:252
#define FALSE
Boolean False(0)
Definition: kernel.h:63
#define TRUE
Boolean True(1)
Definition: kernel.h:65
#define TY_RETURN
Definition: tty.h:69
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
#define TY_NEWLINE
Definition: tty.h:68
#define TY_IBUFLEN
Definition: tty.h:13
void ttykickout(struct uart_csreg *)
Definition: ttykickout.c:10
#define TY_IMRAW
Definition: tty.h:21
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttyhandle_out()

void ttyhandle_out ( struct ttycblk ,
struct uart_csreg  
)

Definition at line 10 of file ttyhandle_out.c.

References uart_csreg::buffer, uart_csreg::ier, semcount(), signaln(), uart_csreg::txfifo_lvl, TY_EBUFLEN, TY_OBUFLEN, ttycblk::tyebuff, ttycblk::tyehead, ttycblk::tyetail, ttycblk::tyobuff, ttycblk::tyohead, ttycblk::tyoheld, ttycblk::tyosem, UART_FIFO_SIZE, and UART_IER_ETBEI.

Referenced by ttyhandler().

14 {
15 
16  int32 ochars; /* Number of output chars sent */
17  /* to the UART */
18  int32 avail; /* Available chars in output buf*/
19  int32 uspace; /* Space left in onboard UART */
20  /* output FIFO */
21  uint32 ier = 0;
22 
23  /* If output is currently held, simply ignore the call */
24 
25  if (typtr->tyoheld) {
26  return;
27  }
28 
29  /* If echo and output queues empty, turn off interrupts */
30 
31  if ( (typtr->tyehead == typtr->tyetail) &&
32  (semcount(typtr->tyosem) >= TY_OBUFLEN) ) {
33  ier = csrptr->ier;
34  csrptr->ier = ier & ~UART_IER_ETBEI;
35  return;
36  }
37 
38  /* Initialize uspace to the available space in the Tx FIFO */
39 
40  uspace = UART_FIFO_SIZE - csrptr->txfifo_lvl;
41 
42  /* While onboard FIFO is not full and the echo queue is */
43  /* nonempty, xmit chars from the echo queue */
44 
45  while ( (uspace>0) && typtr->tyehead != typtr->tyetail) {
46  csrptr->buffer = *typtr->tyehead++;
47  if (typtr->tyehead >= &typtr->tyebuff[TY_EBUFLEN]) {
48  typtr->tyehead = typtr->tyebuff;
49  }
50  uspace--;
51  }
52 
53  /* While onboard FIFO is not full and the output queue is */
54  /* nonempty, transmit chars from the output queue */
55 
56  ochars = 0;
57  avail = TY_OBUFLEN - semcount(typtr->tyosem);
58  while ( (uspace>0) && (avail > 0) ) {
59  csrptr->buffer = *typtr->tyohead++;
60  if (typtr->tyohead >= &typtr->tyobuff[TY_OBUFLEN]) {
61  typtr->tyohead = typtr->tyobuff;
62  }
63  avail--;
64  uspace--;
65  ochars++;
66  }
67  if (ochars > 0) {
68  signaln(typtr->tyosem, ochars);
69  }
70 
71  if ( (typtr->tyehead == typtr->tyetail) &&
72  (semcount(typtr->tyosem) >= TY_OBUFLEN) ) {
73  ier = csrptr->ier;
74  csrptr->ier = (ier & ~UART_IER_ETBEI);
75  }
76  return;
77 }
syscall semcount(sid32)
セマフォのカウント値を返す。
Definition: semcount.c:18
#define TY_EBUFLEN
Definition: tty.h:5
#define UART_IER_ETBEI
Definition: uart.h:66
syscall signaln(sid32, int32)
セマフォにシグナルをN回送り、N個の待機プロセスがある場合はそれらをREADY状態にする。 ...
Definition: signaln.c:16
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define TY_OBUFLEN
Definition: tty.h:16
#define UART_FIFO_SIZE
Definition: uart.h:5
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttyhandler()

void ttyhandler ( uint32  )

Definition at line 9 of file ttyhandler.c.

References uart_csreg::buffer, CONSOLE, DEFER_START, DEFER_STOP, devtab, dentry::dvcsr, dentry::dvminor, if(), uart_csreg::iir, uart_csreg::lsr, resched_cntl(), ttyhandle_in(), ttyhandle_out(), ttytab, UART_IIR_IDMASK, UART_IIR_IRQ, UART_IIR_MSC, UART_IIR_RDA, UART_IIR_RLSI, UART_IIR_RTO, UART_IIR_THRE, UART_LSR_BI, and UART_LSR_DR.

9  {
10  struct dentry *devptr; /* Address of device control blk*/
11  struct ttycblk *typtr; /* Pointer to ttytab entry */
12  struct uart_csreg *csrptr; /* Address of UART's CSR */
13  uint32 iir = 0; /* Interrupt identification */
14  uint32 lsr = 0; /* Line status */
15 
16 
17  /* Get CSR address of the device (assume console for now) */
18 
19  devptr = (struct dentry *) &devtab[CONSOLE];
20  csrptr = (struct uart_csreg *) devptr->dvcsr;
21 
22  /* Obtain a pointer to the tty control block */
23 
24  typtr = &ttytab[ devptr->dvminor ];
25 
26  /* Decode hardware interrupt request from UART device */
27 
28  /* Check interrupt identification register */
29  iir = csrptr->iir;
30  if (iir & UART_IIR_IRQ) {
31  return;
32  }
33 
34  /* Decode the interrupt cause based upon the value extracted */
35  /* from the UART interrupt identification register. Clear */
36  /* the interrupt source and perform the appropriate handling */
37  /* to coordinate with the upper half of the driver */
38 
39  /* Decode the interrupt cause */
40 
41  iir &= UART_IIR_IDMASK; /* Mask off the interrupt ID */
42  switch (iir) {
43 
44  /* Receiver line status interrupt (error) */
45 
46  case UART_IIR_RLSI:
47  lsr = csrptr->lsr;
48  if(lsr & UART_LSR_BI) { /* Break Interrupt */
49 
50  /* Read the RHR register to acknowledge */
51 
52  lsr = csrptr->buffer;
53  }
54  return;
55 
56  /* Receiver data available or timed out */
57 
58  case UART_IIR_RDA:
59  case UART_IIR_RTO:
60 
62 
63  /* While chars avail. in UART buffer, call ttyhandle_in */
64 
65  while ( (csrptr->lsr & UART_LSR_DR) != 0) {
66  ttyhandle_in(typtr, csrptr);
67  }
68 
70 
71  return;
72 
73  /* Transmitter output FIFO is empty (i.e., ready for more) */
74 
75  case UART_IIR_THRE:
76  ttyhandle_out(typtr, csrptr);
77  return;
78 
79  /* Modem status change (simply ignore) */
80 
81  case UART_IIR_MSC:
82  return;
83  }
84 }
volatile uint32 lsr
Definition: uart.h:22
if(!(yy_init))
Definition: lex.yy.c:679
volatile uint32 buffer
Definition: uart.h:15
int32 dvminor
Definition: conf.h:8
#define CONSOLE
Definition: conf.h:28
#define UART_IIR_RTO
Definition: uart.h:78
#define UART_IIR_MSC
Definition: uart.h:74
#define UART_IIR_RDA
Definition: uart.h:76
status resched_cntl(int32)
再スケジューリングを延期させるか、もしくは許可させるかを制御する。
Definition: resched.c:81
Definition: conf.h:6
Definition: tty.h:26
struct dentry devtab[]
Definition: conf.c:11
#define UART_IIR_RLSI
Definition: uart.h:77
#define UART_LSR_BI
Definition: uart.h:102
#define DEFER_STOP
遅延リスケジューリングの停止
Definition: resched.h:10
#define DEFER_START
遅延リスケジューリングの開始
Definition: resched.h:8
#define UART_IIR_IDMASK
Definition: uart.h:73
struct ttycblk ttytab[]
Definition: ttyinit.c:11
#define UART_IIR_IRQ
Definition: uart.h:72
void ttyhandle_in(struct ttycblk *, struct uart_csreg *)
Definition: ttyhandle_in.c:13
volatile uint32 iir
Definition: uart.h:18
#define UART_IIR_THRE
Definition: uart.h:75
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
void ttyhandle_out(struct ttycblk *, struct uart_csreg *)
Definition: ttyhandle_out.c:10
void * dvcsr
Definition: conf.h:19
#define UART_LSR_DR
Definition: uart.h:101
Here is the call graph for this function:

◆ ttyinit()

devcall ttyinit ( struct dentry )

Definition at line 17 of file ttyinit.c.

References dentry::dvcsr, dentry::dvintr, dentry::dvirq, dentry::dvminor, FALSE, uart_csreg::lcr, uart_csreg::mdr1, OK, semcreate(), set_evec(), TRUE, ttykickout(), ttytab, TY_BACKSP, TY_BACKSP2, TY_EOFCH, TY_FULLCH, TY_IMCOOKED, TY_KILLCH, TY_OBUFLEN, TY_STOPCH, TY_STRTCH, ttycblk::tyebuff, ttycblk::tyecrlf, ttycblk::tyehead, ttycblk::tyeof, ttycblk::tyeofch, ttycblk::tyetail, ttycblk::tyevis, ttycblk::tyibuff, ttycblk::tyicrlf, ttycblk::tyicursor, ttycblk::tyieback, ttycblk::tyiecho, ttycblk::tyierase, ttycblk::tyierasec, ttycblk::tyierasec2, ttycblk::tyifullc, ttycblk::tyihead, ttycblk::tyikill, ttycblk::tyikillc, ttycblk::tyimode, ttycblk::tyisem, ttycblk::tyitail, ttycblk::tyobuff, ttycblk::tyocrlf, ttycblk::tyoflow, ttycblk::tyohead, ttycblk::tyoheld, ttycblk::tyosem, ttycblk::tyostart, ttycblk::tyostop, ttycblk::tyotail, UART_DLL, UART_DLM, UART_FCR_EFIFO, UART_FCR_RRESET, UART_FCR_TRESET, UART_FCR_TRIG2, UART_LCR_8N1, UART_LCR_DLAB, and UART_MDR1_16X.

20 {
21  struct ttycblk *typtr; /* Pointer to ttytab entry */
22  struct uart_csreg *uptr; /* Address of UART's CSRs */
23 
24  typtr = &ttytab[devptr->dvminor];
25 
26  /* Initialize values in the tty control block */
27 
28  typtr->tyihead = typtr->tyitail = /* Set up input queue */
29  &typtr->tyibuff[0]; /* as empty */
30  typtr->tyisem = semcreate(0); /* Input semaphore */
31  typtr->tyohead = typtr->tyotail = /* Set up output queue */
32  &typtr->tyobuff[0]; /* as empty */
33  typtr->tyosem = semcreate(TY_OBUFLEN); /* Output semaphore */
34  typtr->tyehead = typtr->tyetail = /* Set up echo queue */
35  &typtr->tyebuff[0]; /* as empty */
36  typtr->tyimode = TY_IMCOOKED; /* Start in cooked mode */
37  typtr->tyiecho = TRUE; /* Echo console input */
38  typtr->tyieback = TRUE; /* Honor erasing bksp */
39  typtr->tyevis = TRUE; /* Visual control chars */
40  typtr->tyecrlf = TRUE; /* Echo CRLF for NEWLINE*/
41  typtr->tyicrlf = TRUE; /* Map CR to NEWLINE */
42  typtr->tyierase = TRUE; /* Do erasing backspace */
43  typtr->tyierasec = TY_BACKSP; /* Primary erase char */
44  typtr->tyierasec2 = TY_BACKSP2; /* Alternate erase char */
45  typtr->tyeof = TRUE; /* Honor eof on input */
46  typtr->tyeofch = TY_EOFCH; /* End-of-file character*/
47  typtr->tyikill = TRUE; /* Allow line kill */
48  typtr->tyikillc = TY_KILLCH; /* Set line kill to ^U */
49  typtr->tyicursor = 0; /* Start of input line */
50  typtr->tyoflow = TRUE; /* Handle flow control */
51  typtr->tyoheld = FALSE; /* Output not held */
52  typtr->tyostop = TY_STOPCH; /* Stop char is ^S */
53  typtr->tyostart = TY_STRTCH; /* Start char is ^Q */
54  typtr->tyocrlf = TRUE; /* Send CRLF for NEWLINE*/
55  typtr->tyifullc = TY_FULLCH; /* Send ^G when buffer */
56  /* is full */
57 
58  /* Initialize the UART */
59 
60  uptr = (struct uart_csreg *)devptr->dvcsr;
61 
62  /* Set baud rate */
63  uptr->lcr = UART_LCR_DLAB;
64  uptr->dlm = UART_DLM;
65  uptr->dll = UART_DLL;
66 
67  uptr->lcr = UART_LCR_8N1; /* 8 bit char, No Parity, 1 Stop*/
68  uptr->fcr = 0x00; /* Disable FIFO for now */
69 
70  /* Register the interrupt dispatcher for the tty device */
71 
72  set_evec(devptr->dvirq, (uint32)devptr->dvintr);
73 
74  /* Enable interrupts on the device: reset the transmit and */
75  /* receive FIFOS, and set the interrupt trigger level */
76 
77  uptr->fcr = UART_FCR_EFIFO | UART_FCR_RRESET |
79 
80  /* UART must be in 16x mode (TI AM335X specific) */
81 
82  uptr->mdr1 = UART_MDR1_16X;
83 
84  /* Start the device */
85 
86  ttykickout(uptr);
87  return OK;
88 }
#define TY_BACKSP
Definition: tty.h:63
bool8 tyocrlf
Definition: tty.h:56
sid32 semcreate(int32)
未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。
Definition: semcreate.c:22
#define TY_STOPCH
Definition: tty.h:70
bool8 tyiecho
Definition: tty.h:39
char tyeofch
Definition: tty.h:48
char tyierasec
Definition: tty.h:45
char tyifullc
Definition: tty.h:57
char tyibuff[TY_IBUFLEN]
Definition: tty.h:29
#define UART_FCR_TRESET
Definition: uart.h:84
char tyierasec2
Definition: tty.h:46
bool8 tyicrlf
Definition: tty.h:43
bool8 tyieback
Definition: tty.h:40
#define UART_DLM
Definition: uart.h:55
bool8 tyoheld
Definition: tty.h:53
#define OK
処理が成功した場合
Definition: kernel.h:77
#define UART_MDR1_16X
Definition: uart.h:109
volatile uint32 mdr1
Definition: uart.h:25
#define TY_STRTCH
Definition: tty.h:71
bool8 tyikill
Definition: tty.h:49
#define UART_LCR_8N1
Definition: uart.h:61
bool8 tyecrlf
Definition: tty.h:42
bool8 tyoflow
Definition: tty.h:52
Definition: tty.h:26
int32 set_evec(uint32, uint32)
Definition: evec.c:37
#define TY_FULLCH
Definition: tty.h:74
char * tyehead
Definition: tty.h:35
#define TY_EOFCH
Definition: tty.h:66
char tyobuff[TY_OBUFLEN]
Definition: tty.h:33
#define FALSE
Boolean False(0)
Definition: kernel.h:63
#define TY_KILLCH
Definition: tty.h:72
#define TRUE
Boolean True(1)
Definition: kernel.h:65
char tyostop
Definition: tty.h:54
#define TY_BACKSP2
Definition: tty.h:64
char * tyetail
Definition: tty.h:36
char * tyohead
Definition: tty.h:31
bool8 tyevis
Definition: tty.h:41
char * tyihead
Definition: tty.h:27
#define TY_OBUFLEN
Definition: tty.h:16
char * tyotail
Definition: tty.h:32
char tyikillc
Definition: tty.h:50
char tyimode
Definition: tty.h:38
volatile uint32 lcr
Definition: uart.h:20
#define UART_FCR_RRESET
Definition: uart.h:83
#define TY_IMCOOKED
Definition: tty.h:22
#define UART_FCR_EFIFO
Definition: uart.h:82
bool8 tyierase
Definition: tty.h:44
struct ttycblk ttytab[Ntty]
Definition: ttyinit.c:11
bool8 tyeof
Definition: tty.h:47
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
void ttykickout(struct uart_csreg *)
Definition: ttykickout.c:10
#define UART_FCR_TRIG2
Definition: uart.h:87
#define UART_LCR_DLAB
Definition: uart.h:60
char tyebuff[TY_EBUFLEN]
Definition: tty.h:37
int32 tyicursor
Definition: tty.h:51
char tyostart
Definition: tty.h:55
sid32 tyisem
Definition: tty.h:30
#define UART_DLL
Definition: uart.h:53
sid32 tyosem
Definition: tty.h:34
char * tyitail
Definition: tty.h:28
Here is the call graph for this function:

◆ ttykickout()

void ttykickout ( struct uart_csreg )

Definition at line 10 of file ttykickout.c.

References uart_csreg::ier, UART_IER_ERBFI, and UART_IER_ETBEI.

Referenced by eputc(), ttyhandle_in(), ttyinit(), and ttyputc().

13 {
14  /* Force the UART hardware generate an output interrupt */
15 
16  csrptr->ier = UART_IER_ERBFI | UART_IER_ETBEI;
17 
18  return;
19 }
#define UART_IER_ERBFI
Definition: uart.h:65
#define UART_IER_ETBEI
Definition: uart.h:66
Here is the caller graph for this function:

◆ ttyputc()

devcall ttyputc ( struct dentry ,
char   
)

Definition at line 9 of file ttyputc.c.

References dentry::dvcsr, dentry::dvminor, OK, ttykickout(), ttytab, TY_NEWLINE, TY_OBUFLEN, TY_RETURN, ttycblk::tyobuff, ttycblk::tyocrlf, ttycblk::tyosem, ttycblk::tyotail, and wait().

Referenced by ttywrite().

13 {
14  struct ttycblk *typtr; /* Pointer to tty control block */
15 
16  typtr = &ttytab[devptr->dvminor];
17 
18  /* Handle output CRLF by sending CR first */
19 
20  if ( ch==TY_NEWLINE && typtr->tyocrlf ) {
21  ttyputc(devptr, TY_RETURN);
22  }
23 
24  wait(typtr->tyosem); /* Wait for space in queue */
25  *typtr->tyotail++ = ch;
26 
27  /* Wrap around to beginning of buffer, if needed */
28 
29  if (typtr->tyotail >= &typtr->tyobuff[TY_OBUFLEN]) {
30  typtr->tyotail = typtr->tyobuff;
31  }
32 
33  /* Start output in case device is idle */
34 
35  ttykickout((struct uart_csreg *)devptr->dvcsr);
36 
37  return OK;
38 }
bool8 tyocrlf
Definition: tty.h:56
#define OK
処理が成功した場合
Definition: kernel.h:77
Definition: tty.h:26
char tyobuff[TY_OBUFLEN]
Definition: tty.h:33
#define TY_RETURN
Definition: tty.h:69
devcall ttyputc(struct dentry *devptr, char ch)
Definition: ttyputc.c:9
#define TY_OBUFLEN
Definition: tty.h:16
struct ttycblk ttytab[]
Definition: ttyinit.c:11
char * tyotail
Definition: tty.h:32
syscall wait(sid32)
Definition: wait.c:9
#define TY_NEWLINE
Definition: tty.h:68
void ttykickout(struct uart_csreg *)
Definition: ttykickout.c:10
sid32 tyosem
Definition: tty.h:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttyread()

devcall ttyread ( struct dentry ,
char *  ,
int32   
)

Definition at line 9 of file ttyread.c.

References dentry::dvminor, EOF, semcount(), SYSERR, ttygetc(), ttytab, TY_IMCOOKED, TY_NEWLINE, TY_RETURN, ttycblk::tyimode, and ttycblk::tyisem.

14 {
15  struct ttycblk *typtr; /* Pointer to tty control block */
16  int32 avail; /* Characters available in buff.*/
17  int32 nread; /* Number of characters read */
18  int32 firstch; /* First input character on line*/
19  char ch; /* Next input character */
20 
21  if (count < 0) {
22  return SYSERR;
23  }
24  typtr= &ttytab[devptr->dvminor];
25 
26  if (typtr->tyimode != TY_IMCOOKED) {
27 
28  /* For count of zero, return all available characters */
29 
30  if (count == 0) {
31  avail = semcount(typtr->tyisem);
32  if (avail == 0) {
33  return 0;
34  } else {
35  count = avail;
36  }
37  }
38  for (nread = 0; nread < count; nread++) {
39  *buff++ = (char) ttygetc(devptr);
40  }
41  return nread;
42  }
43 
44  /* Block until input arrives */
45 
46  firstch = ttygetc(devptr);
47 
48  /* Check for End-Of-File */
49 
50  if (firstch == EOF) {
51  return EOF;
52  }
53 
54  /* Read up to a line */
55 
56  ch = (char) firstch;
57  *buff++ = ch;
58  nread = 1;
59  while ( (nread < count) && (ch != TY_NEWLINE) &&
60  (ch != TY_RETURN) ) {
61  ch = ttygetc(devptr);
62  *buff++ = ch;
63  nread++;
64  }
65  return nread;
66 }
syscall semcount(sid32)
セマフォのカウント値を返す。
Definition: semcount.c:18
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define EOF
ファイルの終端(End of File)に達した場合(読み込み処理に用いる)
Definition: kernel.h:81
Definition: tty.h:26
devcall ttygetc(struct dentry *)
Definition: ttygetc.c:9
#define TY_RETURN
Definition: tty.h:69
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
struct ttycblk ttytab[]
Definition: ttyinit.c:11
char tyimode
Definition: tty.h:38
#define TY_IMCOOKED
Definition: tty.h:22
#define TY_NEWLINE
Definition: tty.h:68
sid32 tyisem
Definition: tty.h:30
Here is the call graph for this function:

◆ ttywrite()

devcall ttywrite ( struct dentry ,
char *  ,
int32   
)

Definition at line 9 of file ttywrite.c.

References OK, SYSERR, and ttyputc().

14 {
15  /* Handle negative and zero counts */
16 
17  if (count < 0) {
18  return SYSERR;
19  } else if (count == 0){
20  return OK;
21  }
22 
23  /* Write count characters one at a time */
24 
25  for (; count>0 ; count--) {
26  ttyputc(devptr, *buff++);
27  }
28  return OK;
29 }
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
devcall ttyputc(struct dentry *, char)
Definition: ttyputc.c:9
Here is the call graph for this function:

◆ udp_hton()

void udp_hton ( struct netpacket )

Definition at line 567 of file udp.c.

References htons, netpacket::net_udpdport, netpacket::net_udplen, and netpacket::net_udpsport.

Referenced by ip_out().

570 {
571  pktptr->net_udpsport = htons(pktptr->net_udpsport);
572  pktptr->net_udpdport = htons(pktptr->net_udpdport);
573  pktptr->net_udplen = htons(pktptr->net_udplen);
574  return;
575 }
#define htons(x)
Definition: prototypes.h:619
Here is the caller graph for this function:

◆ udp_in()

void udp_in ( struct netpacket )

Definition at line 29 of file udp.c.

References disable(), freebuf(), netpacket::net_ipsrc, netpacket::net_udpdport, netpacket::net_udpsport, OK, restore(), send(), udpentry::udcount, udpentry::udlocport, UDP_FREE, UDP_QSIZ, UDP_RECV, UDP_SLOTS, UDP_USED, udpentry::udpid, udptab, udpentry::udqueue, udpentry::udremip, udpentry::udremport, udpentry::udstate, and udpentry::udtail.

Referenced by ip_local().

32 {
33  intmask mask; /* Saved interrupt mask */
34  int32 i; /* Index into udptab */
35  struct udpentry *udptr; /* Pointer to a udptab entry */
36 
37 
38  /* Ensure only one process can access the UDP table at a time */
39 
40  mask = disable();
41 
42  for (i=0; i<UDP_SLOTS; i++) {
43  udptr = &udptab[i];
44  if (udptr->udstate == UDP_FREE) {
45  continue;
46  }
47 
48  if ((pktptr->net_udpdport == udptr->udlocport) &&
49  ((udptr->udremport == 0) ||
50  (pktptr->net_udpsport == udptr->udremport)) &&
51  ( ((udptr->udremip==0) ||
52  (pktptr->net_ipsrc == udptr->udremip))) ) {
53 
54  /* Entry matches incoming packet */
55 
56  if (udptr->udcount < UDP_QSIZ) {
57  udptr->udcount++;
58  udptr->udqueue[udptr->udtail++] = pktptr;
59  if (udptr->udtail >= UDP_QSIZ) {
60  udptr->udtail = 0;
61  }
62  if (udptr->udstate == UDP_RECV) {
63  udptr->udstate = UDP_USED;
64  send (udptr->udpid, OK);
65  }
66  restore(mask);
67  return;
68  }
69  }
70  }
71 
72  /* No match - simply discard packet */
73 
74  freebuf((char *) pktptr);
75  restore(mask);
76  return;
77 }
uint16 udremport
Definition: udp.h:24
void restore(intmask)
struct netpacket * udqueue[UDP_QSIZ]
Definition: udp.h:30
#define UDP_USED
Definition: udp.h:12
uint32 udremip
Definition: udp.h:22
int32 udcount
Definition: udp.h:28
int32 udtail
Definition: udp.h:27
#define UDP_RECV
Definition: udp.h:13
#define OK
処理が成功した場合
Definition: kernel.h:77
#define UDP_SLOTS
Definition: udp.h:3
syscall send(pid32, umsg32)
プロセスにメッセージを送信し、受信側が待機状態の場合はREADY状態にする。
Definition: send.c:21
pid32 udpid
Definition: udp.h:29
struct udpentry udptab[UDP_SLOTS]
Definition: udp.c:6
Definition: udp.h:20
#define UDP_QSIZ
Definition: udp.h:4
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint16 udlocport
Definition: udp.h:25
int32 udstate
Definition: udp.h:21
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
#define UDP_FREE
Definition: udp.h:11
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_init()

void udp_init ( void  )

Definition at line 12 of file udp.c.

References UDP_FREE, UDP_SLOTS, udptab, and udpentry::udstate.

Referenced by net_init().

13 {
14 
15  int32 i; /* Index into the UDP table */
16 
17  for(i=0; i<UDP_SLOTS; i++) {
18  udptab[i].udstate = UDP_FREE;
19  }
20 
21  return;
22 }
#define UDP_SLOTS
Definition: udp.h:3
struct udpentry udptab[UDP_SLOTS]
Definition: udp.c:6
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 udstate
Definition: udp.h:21
#define UDP_FREE
Definition: udp.h:11
Here is the caller graph for this function:

◆ udp_ntoh()

void udp_ntoh ( struct netpacket )

Definition at line 553 of file udp.c.

References netpacket::net_udpdport, netpacket::net_udplen, netpacket::net_udpsport, and ntohs.

Referenced by ip_in().

556 {
557  pktptr->net_udpsport = ntohs(pktptr->net_udpsport);
558  pktptr->net_udpdport = ntohs(pktptr->net_udpdport);
559  pktptr->net_udplen = ntohs(pktptr->net_udplen);
560  return;
561 }
#define ntohs(x)
Definition: prototypes.h:622
Here is the caller graph for this function:

◆ udp_recv()

int32 udp_recv ( uid32  ,
char *  ,
int32  ,
uint32   
)

Definition at line 146 of file udp.c.

References currpid, disable(), freebuf(), if(), netpacket::net_udpdata, netpacket::net_udplen, OK, recvclr(), recvtime(), restore(), SYSERR, TIMEOUT, udpentry::udcount, udpentry::udhead, UDP_HDR_LEN, UDP_QSIZ, UDP_RECV, UDP_SLOTS, UDP_USED, udpentry::udpid, udptab, udpentry::udqueue, and udpentry::udstate.

Referenced by dnslookup(), getlocalip(), getutime(), rdscomm(), rfscomm(), and xsh_udpecho().

152 {
153  intmask mask; /* Saved interrupt mask */
154  struct udpentry *udptr; /* Pointer to udptab entry */
155  umsg32 msg; /* Message from recvtime() */
156  struct netpacket *pkt; /* Pointer to packet being read */
157  int32 i; /* Counts bytes copied */
158  int32 msglen; /* Length of UDP data in packet */
159  char *udataptr; /* Pointer to UDP data */
160 
161  /* Ensure only one process can access the UDP table at a time */
162 
163  mask = disable();
164 
165  /* Verify that the slot is valid */
166 
167  if ((slot < 0) || (slot >= UDP_SLOTS)) {
168  restore(mask);
169  return SYSERR;
170  }
171 
172  /* Get pointer to table entry */
173 
174  udptr = &udptab[slot];
175 
176  /* Verify that the slot has been registered and is valid */
177 
178  if (udptr->udstate != UDP_USED) {
179  restore(mask);
180  return SYSERR;
181  }
182 
183  /* Wait for a packet to arrive */
184 
185  if (udptr->udcount == 0) { /* No packet is waiting */
186  udptr->udstate = UDP_RECV;
187  udptr->udpid = currpid;
188  msg = recvclr();
189  msg = recvtime(timeout); /* Wait for a packet */
190  udptr->udstate = UDP_USED;
191  if (msg == TIMEOUT) {
192  restore(mask);
193  return TIMEOUT;
194  } else if (msg != OK) {
195  restore(mask);
196  return SYSERR;
197  }
198  }
199 
200  /* Packet has arrived -- dequeue it */
201 
202  pkt = udptr->udqueue[udptr->udhead++];
203  if (udptr->udhead >= UDP_QSIZ) {
204  udptr->udhead = 0;
205  }
206  udptr->udcount--;
207 
208  /* Copy UDP data from packet into caller's buffer */
209 
210  msglen = pkt->net_udplen - UDP_HDR_LEN;
211  udataptr = (char *)pkt->net_udpdata;
212  if (len < msglen) {
213  msglen = len;
214  }
215  for (i=0; i<msglen; i++) {
216  *buff++ = *udataptr++;
217  }
218  freebuf((char *)pkt);
219  restore(mask);
220  return msglen;
221 }
pid32 currpid
現在実行中のプロセス。
Definition: initialize.c:32
void restore(intmask)
int32 udhead
Definition: udp.h:26
struct netpacket * udqueue[UDP_QSIZ]
Definition: udp.h:30
if(!(yy_init))
Definition: lex.yy.c:679
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define UDP_USED
Definition: udp.h:12
int32 udcount
Definition: udp.h:28
#define UDP_RECV
Definition: udp.h:13
#define OK
処理が成功した場合
Definition: kernel.h:77
#define UDP_SLOTS
Definition: udp.h:3
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
pid32 udpid
Definition: udp.h:29
uint32 umsg32
プロセス間で渡されるメッセージ
Definition: kernel.h:32
struct udpentry udptab[UDP_SLOTS]
Definition: udp.c:6
Definition: udp.h:20
#define UDP_QSIZ
Definition: udp.h:4
umsg32 recvclr(void)
受信メッセージをクリアし、待機している場合はメッセージを返す。
Definition: recvclr.c:14
uint16 net_udplen
Definition: net.h:34
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
byte net_udpdata[1500-28]
Definition: net.h:36
int32 udstate
Definition: udp.h:21
Definition: net.h:16
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
umsg32 recvtime(int32)
Definition: recvtime.c:17
#define UDP_HDR_LEN
Definition: udp.h:18
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_recvaddr()

int32 udp_recvaddr ( uid32  ,
uint32 ,
uint16 ,
char *  ,
int32  ,
uint32   
)

Definition at line 227 of file udp.c.

References currpid, disable(), freebuf(), if(), netpacket::net_ipsrc, netpacket::net_udpdata, netpacket::net_udplen, netpacket::net_udpsport, OK, recvclr(), recvtime(), restore(), SYSERR, TIMEOUT, udpentry::udcount, udpentry::udhead, UDP_HDR_LEN, UDP_QSIZ, UDP_RECV, UDP_SLOTS, UDP_USED, udpentry::udpid, udptab, udpentry::udqueue, and udpentry::udstate.

Referenced by tftp_send1(), and xsh_udpeserver().

235 {
236  intmask mask; /* Saved interrupt mask */
237  struct udpentry *udptr; /* Pointer to udptab entry */
238  umsg32 msg; /* Message from recvtime() */
239  struct netpacket *pkt; /* Pointer to packet being read */
240  int32 msglen; /* Length of UDP data in packet */
241  int32 i; /* Counts bytes copied */
242  char *udataptr; /* Pointer to UDP data */
243 
244  /* Ensure only one process can access the UDP table at a time */
245 
246  mask = disable();
247 
248  /* Verify that the slot is valid */
249 
250  if ((slot < 0) || (slot >= UDP_SLOTS)) {
251  restore(mask);
252  return SYSERR;
253  }
254 
255  /* Get pointer to table entry */
256 
257  udptr = &udptab[slot];
258 
259  /* Verify that the slot has been registered and is valid */
260 
261  if (udptr->udstate != UDP_USED) {
262  restore(mask);
263  return SYSERR;
264  }
265 
266  /* Wait for a packet to arrive */
267 
268  if (udptr->udcount == 0) { /* No packet is waiting */
269  udptr->udstate = UDP_RECV;
270  udptr->udpid = currpid;
271  msg = recvclr();
272  msg = recvtime(timeout); /* Wait for a packet */
273  udptr->udstate = UDP_USED;
274  if (msg == TIMEOUT) {
275  restore(mask);
276  return TIMEOUT;
277  } else if (msg != OK) {
278  restore(mask);
279  return SYSERR;
280  }
281  }
282 
283  /* Packet has arrived -- dequeue it */
284 
285  pkt = udptr->udqueue[udptr->udhead++];
286  if (udptr->udhead >= UDP_QSIZ) {
287  udptr->udhead = 0;
288  }
289 
290  /* Record sender's IP address and UDP port number */
291 
292  *remip = pkt->net_ipsrc;
293  *remport = pkt->net_udpsport;
294 
295  udptr->udcount--;
296 
297  /* Copy UDP data from packet into caller's buffer */
298 
299  msglen = pkt->net_udplen - UDP_HDR_LEN;
300  udataptr = (char *)pkt->net_udpdata;
301  if (len < msglen) {
302  msglen = len;
303  }
304  for (i=0; i<msglen; i++) {
305  *buff++ = *udataptr++;
306  }
307  freebuf((char *)pkt);
308  restore(mask);
309  return msglen;
310 }
pid32 currpid
現在実行中のプロセス。
Definition: initialize.c:32
void restore(intmask)
int32 udhead
Definition: udp.h:26
struct netpacket * udqueue[UDP_QSIZ]
Definition: udp.h:30
if(!(yy_init))
Definition: lex.yy.c:679
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define UDP_USED
Definition: udp.h:12
int32 udcount
Definition: udp.h:28
#define UDP_RECV
Definition: udp.h:13
uint16 net_udpsport
Definition: net.h:32
#define OK
処理が成功した場合
Definition: kernel.h:77
#define UDP_SLOTS
Definition: udp.h:3
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
pid32 udpid
Definition: udp.h:29
uint32 umsg32
プロセス間で渡されるメッセージ
Definition: kernel.h:32
struct udpentry udptab[UDP_SLOTS]
Definition: udp.c:6
Definition: udp.h:20
#define UDP_QSIZ
Definition: udp.h:4
umsg32 recvclr(void)
受信メッセージをクリアし、待機している場合はメッセージを返す。
Definition: recvclr.c:14
uint16 net_udplen
Definition: net.h:34
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
byte net_udpdata[1500-28]
Definition: net.h:36
int32 udstate
Definition: udp.h:21
Definition: net.h:16
uint32 net_ipsrc
Definition: net.h:28
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
umsg32 recvtime(int32)
Definition: recvtime.c:17
#define UDP_HDR_LEN
Definition: udp.h:18
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_register()

uid32 udp_register ( uint32  ,
uint16  ,
uint16   
)

Definition at line 85 of file udp.c.

References disable(), restore(), SYSERR, udpentry::udcount, udpentry::udhead, udpentry::udlocport, UDP_FREE, UDP_SLOTS, UDP_USED, udpentry::udpid, udptab, udpentry::udremip, udpentry::udremport, udpentry::udstate, and udpentry::udtail.

Referenced by dnslookup(), getlocalip(), getutime(), rdscomm(), rfscomm(), tftpget_mb(), xsh_udpecho(), and xsh_udpeserver().

90 {
91  intmask mask; /* Saved interrupt mask */
92  int32 slot; /* Index into udptab */
93  struct udpentry *udptr; /* Pointer to udptab entry */
94 
95  /* Ensure only one process can access the UDP table at a time */
96 
97  mask = disable();
98 
99  /* See if request already registered */
100 
101  for (slot=0; slot<UDP_SLOTS; slot++) {
102  udptr = &udptab[slot];
103  if (udptr->udstate == UDP_FREE) {
104  continue;
105  }
106 
107  /* Look at this entry in table */
108 
109  if ( (remport == udptr->udremport) &&
110  (locport == udptr->udlocport) &&
111  (remip == udptr->udremip ) ) {
112 
113  /* Request is already in the table */
114 
115  restore(mask);
116  return SYSERR;
117  }
118  }
119 
120  /* Find a free slot and allocate it */
121 
122  for (slot=0; slot<UDP_SLOTS; slot++) {
123  udptr = &udptab[slot];
124  if (udptr->udstate != UDP_FREE) {
125  continue;
126  }
127  udptr->udlocport = locport;
128  udptr->udremport = remport;
129  udptr->udremip = remip;
130  udptr->udcount = 0;
131  udptr->udhead = udptr->udtail = 0;
132  udptr->udpid = -1;
133  udptr->udstate = UDP_USED;
134  restore(mask);
135  return slot;
136  }
137 
138  restore(mask);
139  return SYSERR;
140 }
uint16 udremport
Definition: udp.h:24
void restore(intmask)
int32 udhead
Definition: udp.h:26
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define UDP_USED
Definition: udp.h:12
uint32 udremip
Definition: udp.h:22
int32 udcount
Definition: udp.h:28
int32 udtail
Definition: udp.h:27
#define UDP_SLOTS
Definition: udp.h:3
pid32 udpid
Definition: udp.h:29
struct udpentry udptab[UDP_SLOTS]
Definition: udp.c:6
Definition: udp.h:20
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint16 udlocport
Definition: udp.h:25
int32 udstate
Definition: udp.h:21
#define UDP_FREE
Definition: udp.h:11
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_release()

status udp_release ( uid32  )

Definition at line 502 of file udp.c.

References DEFER_START, DEFER_STOP, disable(), freebuf(), OK, resched_cntl(), restore(), SYSERR, udpentry::udcount, udpentry::udhead, UDP_FREE, UDP_QSIZ, UDP_SLOTS, udptab, udpentry::udqueue, and udpentry::udstate.

Referenced by dnslookup(), getlocalip(), getutime(), tftpget_mb(), and xsh_udpecho().

505 {
506  intmask mask; /* Saved interrupt mask */
507  struct udpentry *udptr; /* Pointer to udptab entry */
508  struct netpacket *pkt; /* pointer to packet being read */
509 
510  /* Ensure only one process can access the UDP table at a time */
511 
512  mask = disable();
513 
514  /* Verify that the slot is valid */
515 
516  if ( (slot < 0) || (slot >= UDP_SLOTS) ) {
517  restore(mask);
518  return SYSERR;
519  }
520 
521  /* Get pointer to table entry */
522 
523  udptr = &udptab[slot];
524 
525  /* Verify that the slot has been registered and is valid */
526 
527  if (udptr->udstate == UDP_FREE) {
528  restore(mask);
529  return SYSERR;
530  }
531 
532  /* Defer rescheduling to prevent freebuf from switching context */
533 
535  while (udptr->udcount > 0) {
536  pkt = udptr->udqueue[udptr->udhead++];
537  if (udptr->udhead >= UDP_QSIZ) {
538  udptr->udhead = 0;
539  }
540  freebuf((char *)pkt);
541  udptr->udcount--;
542  }
543  udptr->udstate = UDP_FREE;
545  restore(mask);
546  return OK;
547 }
void restore(intmask)
int32 udhead
Definition: udp.h:26
struct netpacket * udqueue[UDP_QSIZ]
Definition: udp.h:30
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
int32 udcount
Definition: udp.h:28
#define OK
処理が成功した場合
Definition: kernel.h:77
#define UDP_SLOTS
Definition: udp.h:3
status resched_cntl(int32)
再スケジューリングを延期させるか、もしくは許可させるかを制御する。
Definition: resched.c:81
struct udpentry udptab[UDP_SLOTS]
Definition: udp.c:6
Definition: udp.h:20
#define UDP_QSIZ
Definition: udp.h:4
#define DEFER_STOP
遅延リスケジューリングの停止
Definition: resched.h:10
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
#define DEFER_START
遅延リスケジューリングの開始
Definition: resched.h:8
int32 udstate
Definition: udp.h:21
Definition: net.h:16
syscall freebuf(char *)
バッファプールから取得したバッファを解放する。
Definition: freebuf.c:19
#define UDP_FREE
Definition: udp.h:11
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_send()

status udp_send ( uid32  ,
char *  ,
int32   
)

Definition at line 316 of file udp.c.

References disable(), ETH_ADDR_LEN, ETH_HDR_LEN, network::ethucast, getbuf(), ip_send(), IP_UDP, network::ipucast, memcpy(), netpacket::net_ethsrc, netpacket::net_ethtype, netpacket::net_ipcksum, netpacket::net_ipdst, netpacket::net_ipfrag, netpacket::net_ipid, netpacket::net_iplen, netpacket::net_ipproto, netpacket::net_ipsrc, netpacket::net_iptos, netpacket::net_ipttl, netpacket::net_ipvh, netpacket::net_udpcksum, netpacket::net_udpdata, netpacket::net_udpdport, netpacket::net_udplen, netpacket::net_udpsport, netbufpool, NetData, OK, restore(), SYSERR, udpentry::udlocport, UDP_FREE, UDP_HDR_LEN, UDP_SLOTS, udptab, udpentry::udremip, udpentry::udremport, and udpentry::udstate.

Referenced by dnslookup(), getutime(), rfscomm(), and xsh_udpecho().

321 {
322  intmask mask; /* Saved interrupt mask */
323  struct netpacket *pkt; /* Pointer to packet buffer */
324  int32 pktlen; /* Total packet length */
325  static uint16 ident = 1; /* Datagram IDENT field */
326  char *udataptr; /* Pointer to UDP data */
327  uint32 remip; /* Remote IP address to use */
328  uint16 remport; /* Remote protocol port to use */
329  uint16 locport; /* Local protocol port to use */
330  uint32 locip; /* Local IP address taken from */
331  /* the interface */
332  struct udpentry *udptr; /* Pointer to table entry */
333 
334  /* Ensure only one process can access the UDP table at a time */
335 
336  mask = disable();
337 
338  /* Verify that the slot is valid */
339 
340  if ( (slot < 0) || (slot >= UDP_SLOTS) ) {
341  restore(mask);
342  return SYSERR;
343  }
344 
345  /* Get pointer to table entry */
346 
347  udptr = &udptab[slot];
348 
349  /* Verify that the slot has been registered and is valid */
350 
351  if (udptr->udstate == UDP_FREE) {
352  restore(mask);
353  return SYSERR;
354  }
355 
356  /* Verify that the slot has a specified remote address */
357 
358  remip = udptr->udremip;
359  if (remip == 0) {
360  restore(mask);
361  return SYSERR;
362  }
363 
364  locip = NetData.ipucast;
365  remport = udptr->udremport;
366  locport = udptr->udlocport;
367 
368  /* Allocate a network buffer to hold the packet */
369 
370  pkt = (struct netpacket *)getbuf(netbufpool);
371 
372  if ((int32)pkt == SYSERR) {
373  restore(mask);
374  return SYSERR;
375  }
376 
377  /* Compute packet length as UDP data size + fixed header size */
378 
379  pktlen = ((char *)&pkt->net_udpdata - (char *)pkt) + len;
380 
381  /* Create a UDP packet in pkt */
382 
384  pkt->net_ethtype = 0x0800; /* Type is IP */
385  pkt->net_ipvh = 0x45; /* IP version and hdr length */
386  pkt->net_iptos = 0x00; /* Type of service */
387  pkt->net_iplen= pktlen - ETH_HDR_LEN;/* Total IP datagram length*/
388  pkt->net_ipid = ident++; /* Datagram gets next IDENT */
389  pkt->net_ipfrag = 0x0000; /* IP flags & fragment offset */
390  pkt->net_ipttl = 0xff; /* IP time-to-live */
391  pkt->net_ipproto = IP_UDP; /* Datagram carries UDP */
392  pkt->net_ipcksum = 0x0000; /* initial checksum */
393  pkt->net_ipsrc = locip; /* IP source address */
394  pkt->net_ipdst = remip; /* IP destination address */
395 
396  pkt->net_udpsport = locport; /* Local UDP protocol port */
397  pkt->net_udpdport = remport; /* Remote UDP protocol port */
398  pkt->net_udplen = (uint16)(UDP_HDR_LEN+len); /* UDP length */
399  pkt->net_udpcksum = 0x0000; /* Ignore UDP checksum */
400  udataptr = (char *) pkt->net_udpdata;
401  for (; len>0; len--) {
402  *udataptr++ = *buff++;
403  }
404 
405  /* Call ipsend to send the datagram */
406 
407  ip_send(pkt);
408  restore(mask);
409  return OK;
410 }
#define IP_UDP
IP向けのUDPプロトコルタイプ
Definition: ip.h:16
uint16 net_udpcksum
Definition: net.h:35
uint32 ipucast
Definition: net.h:55
uint16 udremport
Definition: udp.h:24
uint16 net_ethtype
Definition: net.h:19
void restore(intmask)
struct network NetData
Definition: net.c:6
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
uint32 udremip
Definition: udp.h:22
uint16 net_ipid
Definition: net.h:23
uint16 net_ipfrag
Definition: net.h:24
uint16 net_udpsport
Definition: net.h:32
#define OK
処理が成功した場合
Definition: kernel.h:77
#define UDP_SLOTS
Definition: udp.h:3
byte net_ethsrc[ETH_ADDR_LEN]
Definition: net.h:18
uint16 net_iplen
Definition: net.h:22
struct udpentry udptab[UDP_SLOTS]
Definition: udp.c:6
byte ethucast[ETH_ADDR_LEN]
Definition: net.h:64
Definition: udp.h:20
uint16 net_udplen
Definition: net.h:34
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint16 udlocport
Definition: udp.h:25
uint16 net_ipcksum
Definition: net.h:27
byte net_udpdata[1500-28]
Definition: net.h:36
bpid32 netbufpool
Definition: net.c:7
unsigned short uint16
符号なし16ビット整数(unsigned short)
Definition: kernel.h:17
char * getbuf(bpid32)
事前に確保されたバッファプールからバッファを取得する。
Definition: getbuf.c:19
int32 udstate
Definition: udp.h:21
#define ETH_HDR_LEN
Definition: ether.h:22
byte net_iptos
Definition: net.h:21
Definition: net.h:16
byte net_ipvh
Definition: net.h:20
uint32 net_ipsrc
Definition: net.h:28
uint32 net_ipdst
Definition: net.h:29
uint16 net_udpdport
Definition: net.h:33
status ip_send(struct netpacket *)
Definition: ip.c:103
#define ETH_ADDR_LEN
Definition: ether.h:10
byte net_ipproto
Definition: net.h:26
byte net_ipttl
Definition: net.h:25
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
#define UDP_HDR_LEN
Definition: udp.h:18
#define UDP_FREE
Definition: udp.h:11
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_sendto()

status udp_sendto ( uid32  ,
uint32  ,
uint16  ,
char *  ,
int32   
)

Definition at line 417 of file udp.c.

References disable(), ETH_ADDR_LEN, ETH_HDR_LEN, network::ethucast, getbuf(), ip_send(), IP_UDP, network::ipucast, memcpy(), netpacket::net_ethsrc, netpacket::net_ethtype, netpacket::net_ipcksum, netpacket::net_ipdst, netpacket::net_ipfrag, netpacket::net_ipid, netpacket::net_iplen, netpacket::net_ipproto, netpacket::net_ipsrc, netpacket::net_iptos, netpacket::net_ipttl, netpacket::net_ipvh, netpacket::net_udpcksum, netpacket::net_udpdata, netpacket::net_udpdport, netpacket::net_udplen, netpacket::net_udpsport, netbufpool, NetData, OK, restore(), SYSERR, udpentry::udlocport, UDP_FREE, UDP_HDR_LEN, UDP_SLOTS, udptab, and udpentry::udstate.

Referenced by getlocalip(), rdscomm(), tftp_send1(), tftpget_mb(), and xsh_udpeserver().

424 {
425  intmask mask; /* Saved interrupt mask */
426  struct netpacket *pkt; /* Pointer to a packet buffer */
427  int32 pktlen; /* Total packet length */
428  static uint16 ident = 1; /* Datagram IDENT field */
429  struct udpentry *udptr; /* Pointer to a UDP table entry */
430  char *udataptr; /* Pointer to UDP data */
431 
432  /* Ensure only one process can access the UDP table at a time */
433 
434  mask = disable();
435 
436  /* Verify that the slot is valid */
437 
438  if ( (slot < 0) || (slot >= UDP_SLOTS) ) {
439  restore(mask);
440  return SYSERR;
441  }
442 
443  /* Get pointer to table entry */
444 
445  udptr = &udptab[slot];
446 
447  /* Verify that the slot has been registered and is valid */
448 
449  if (udptr->udstate == UDP_FREE) {
450  restore(mask);
451  return SYSERR;
452  }
453 
454  /* Allocate a network buffer to hold the packet */
455 
456  pkt = (struct netpacket *)getbuf(netbufpool);
457 
458  if ((int32)pkt == SYSERR) {
459  restore(mask);
460  return SYSERR;
461  }
462 
463  /* Compute packet length as UDP data size + fixed header size */
464 
465  pktlen = ((char *)&pkt->net_udpdata - (char *)pkt) + len;
466 
467  /* Create UDP packet in pkt */
468 
470  pkt->net_ethtype = 0x0800; /* Type is IP */
471  pkt->net_ipvh = 0x45; /* IP version and hdr length */
472  pkt->net_iptos = 0x00; /* Type of service */
473  pkt->net_iplen= pktlen - ETH_HDR_LEN;/* total IP datagram length*/
474  pkt->net_ipid = ident++; /* Datagram gets next IDENT */
475  pkt->net_ipfrag = 0x0000; /* IP flags & fragment offset */
476  pkt->net_ipttl = 0xff; /* IP time-to-live */
477  pkt->net_ipproto = IP_UDP; /* Datagram carries UDP */
478  pkt->net_ipcksum = 0x0000; /* Initial checksum */
479  pkt->net_ipsrc = NetData.ipucast;/* IP source address */
480  pkt->net_ipdst = remip; /* IP destination address */
481  pkt->net_udpsport = udptr->udlocport;/* local UDP protocol port */
482  pkt->net_udpdport = remport; /* Remote UDP protocol port */
483  pkt->net_udplen = (uint16)(UDP_HDR_LEN+len); /* UDP length */
484  pkt->net_udpcksum = 0x0000; /* Ignore UDP checksum */
485  udataptr = (char *) pkt->net_udpdata;
486  for (; len>0; len--) {
487  *udataptr++ = *buff++;
488  }
489 
490  /* Call ipsend to send the datagram */
491 
492  ip_send(pkt);
493  restore(mask);
494  return OK;
495 }
#define IP_UDP
IP向けのUDPプロトコルタイプ
Definition: ip.h:16
uint16 net_udpcksum
Definition: net.h:35
uint32 ipucast
Definition: net.h:55
uint16 net_ethtype
Definition: net.h:19
void restore(intmask)
struct network NetData
Definition: net.c:6
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
uint16 net_ipid
Definition: net.h:23
uint16 net_ipfrag
Definition: net.h:24
uint16 net_udpsport
Definition: net.h:32
#define OK
処理が成功した場合
Definition: kernel.h:77
#define UDP_SLOTS
Definition: udp.h:3
byte net_ethsrc[ETH_ADDR_LEN]
Definition: net.h:18
uint16 net_iplen
Definition: net.h:22
struct udpentry udptab[UDP_SLOTS]
Definition: udp.c:6
byte ethucast[ETH_ADDR_LEN]
Definition: net.h:64
Definition: udp.h:20
uint16 net_udplen
Definition: net.h:34
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint16 udlocport
Definition: udp.h:25
uint16 net_ipcksum
Definition: net.h:27
byte net_udpdata[1500-28]
Definition: net.h:36
bpid32 netbufpool
Definition: net.c:7
unsigned short uint16
符号なし16ビット整数(unsigned short)
Definition: kernel.h:17
char * getbuf(bpid32)
事前に確保されたバッファプールからバッファを取得する。
Definition: getbuf.c:19
int32 udstate
Definition: udp.h:21
#define ETH_HDR_LEN
Definition: ether.h:22
byte net_iptos
Definition: net.h:21
Definition: net.h:16
byte net_ipvh
Definition: net.h:20
uint32 net_ipsrc
Definition: net.h:28
uint32 net_ipdst
Definition: net.h:29
uint16 net_udpdport
Definition: net.h:33
status ip_send(struct netpacket *)
Definition: ip.c:103
#define ETH_ADDR_LEN
Definition: ether.h:10
byte net_ipproto
Definition: net.h:26
byte net_ipttl
Definition: net.h:25
void * memcpy(void *, const void *, int32)
メモリAの領域(source)からメモリBの領域(Destination)にN Byteコピーする。
Definition: memcpy.c:13
#define UDP_HDR_LEN
Definition: udp.h:18
#define UDP_FREE
Definition: udp.h:11
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unsleep()

syscall unsleep ( pid32  )

Definition at line 11 of file unsleep.c.

References disable(), getitem(), isbadpid, NPROC, OK, PR_RECTIM, PR_SLEEP, proctab, procent::prstate, qentry::qkey, qentry::qnext, queuetab, restore(), and SYSERR.

Referenced by kill(), and send().

14 {
15  intmask mask; /* Saved interrupt mask */
16  struct procent *prptr; /* Ptr to process's table entry */
17 
18  pid32 pidnext; /* ID of process on sleep queue */
19  /* that follows the process */
20  /* which is being removed */
21 
22  mask = disable();
23 
24  if (isbadpid(pid)) {
25  restore(mask);
26  return SYSERR;
27  }
28 
29  /* Verify that candidate process is on the sleep queue */
30 
31  prptr = &proctab[pid];
32  if ((prptr->prstate!=PR_SLEEP) && (prptr->prstate!=PR_RECTIM)) {
33  restore(mask);
34  return SYSERR;
35  }
36 
37  /* Increment delay of next process if such a process exists */
38 
39  pidnext = queuetab[pid].qnext;
40  if (pidnext < NPROC) {
41  queuetab[pidnext].qkey += queuetab[pid].qkey;
42  }
43 
44  getitem(pid); /* Unlink process from queue */
45  restore(mask);
46  return OK;
47 }
struct qentry queuetab[]
Definition: queue.c:45
#define PR_RECTIM
プロセスが「タイムアウト」か「メッセージの到着」のいずれか早い方で待機中の状態。
Definition: process.h:49
void restore(intmask)
#define isbadpid(x)
プロセスIDを検証する。割り込みが無効になっている事を想定している。
Definition: process.h:71
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
qid16 qnext
次のプロセスか末尾のプロセスのインデックス。
Definition: queue.h:39
int32 qkey
キュー順序を決定するキー(優先度)。
Definition: queue.h:37
#define PR_SLEEP
プロセスが休眠中(タイマー待機中)の状態。
Definition: process.h:43
#define NPROC
Definition: conf.h:79
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
pid32 getitem(pid32)
キューの任意の位置からプロセスを取り出す。
Definition: getitem.c:51
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
int32 pid32
プロセスID
Definition: kernel.h:26
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ userret()

void userret ( void  )

プロセスが最上位の関数に戻る時に呼ばれる。現在のプロセスを終了させる。

Note
プロセス作成時に、戻りアドレスとしてuserret()がスタックに積まれる。

Definition at line 11 of file userret.c.

12 {
13  kill(getpid()); /* Force process to exit */
14 }
syscall kill(pid32)
指定のプロセスを終了させ、システムから終了させたプロセス情報を取り除く。
Definition: kill.c:31
pid32 getpid(void)
現在実行中のプロセスIDを返す。
Definition: getpid.c:11

◆ wait()

syscall wait ( sid32  )

Definition at line 9 of file wait.c.

References currpid, disable(), enqueue(), isbadsem, OK, PR_WAIT, proctab, procent::prsem, procent::prstate, resched(), restore(), S_FREE, sentry::scount, semtab, sentry::squeue, sentry::sstate, and SYSERR.

Referenced by ethread(), ethwrite(), getbuf(), ipout(), lflclose(), lflcontrol(), lflgetc(), lflputc(), lflseek(), lfsetup(), lfsopen(), mark(), ptrecv(), ptsend(), rdsbufalloc(), rdsprocess(), rflclose(), rflread(), rflseek(), rflwrite(), rfscontrol(), rfsopen(), ttycontrol(), ttygetc(), ttyputc(), and xsh_ls().

12 {
13  intmask mask; /* Saved interrupt mask */
14  struct procent *prptr; /* Ptr to process's table entry */
15  struct sentry *semptr; /* Ptr to sempahore table entry */
16 
17  mask = disable();
18  if (isbadsem(sem)) {
19  restore(mask);
20  return SYSERR;
21  }
22 
23  semptr = &semtab[sem];
24  if (semptr->sstate == S_FREE) {
25  restore(mask);
26  return SYSERR;
27  }
28 
29  if (--(semptr->scount) < 0) { /* If caller must block */
30  prptr = &proctab[currpid];
31  prptr->prstate = PR_WAIT; /* Set state to waiting */
32  prptr->prsem = sem; /* Record semaphore ID */
33  enqueue(currpid,semptr->squeue);/* Enqueue on semaphore */
34  resched(); /* and reschedule */
35  }
36 
37  restore(mask);
38  return OK;
39 }
pid32 currpid
現在実行中のプロセス。
Definition: initialize.c:32
pid32 enqueue(pid32, qid16)
プロセスをプロセスキューテーブルの末尾に挿入する。
Definition: queue.c:53
void restore(intmask)
byte sstate
エントリ状態が利用可能(S_FREE)か、利用中(S_USED)かを表す。
Definition: semaphore.h:22
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
セマフォテーブルエントリであり、本構造体の配列(長さNSEM)が静的に確保される。
Definition: semaphore.h:19
#define isbadsem(s)
セマフォIDが不適切かどうかを確認する。
Definition: semaphore.h:40
#define OK
処理が成功した場合
Definition: kernel.h:77
sid32 prsem
プロセスが待機しているセマフォ。
Definition: process.h:100
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
void resched(void)
最優先の適切なプロセスにCPU実行権を渡す。
Definition: resched.c:22
qid16 squeue
セマフォ待機中プロセスのキュー
Definition: semaphore.h:26
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
int32 scount
セマフォカウント(負の値(-N)の場合は、キューにN個の待機プロセスがある。それ以外はキューが空である) ...
Definition: semaphore.h:24
#define S_FREE
セマフォテーブルエントリが利用可能
Definition: semaphore.h:11
struct sentry semtab[]
セマフォテーブルエントリのextern宣言
Definition: initialize.c:25
#define PR_WAIT
プロセスがセマフォ上で待機中の状態。
Definition: process.h:47
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wakeup()

void wakeup ( void  )

Definition at line 9 of file wakeup.c.

References DEFER_START, DEFER_STOP, dequeue(), firstkey, nonempty, ready(), resched_cntl(), and sleepq.

Referenced by clkhandler().

10 {
11  /* Awaken all processes that have no more time to sleep */
12 
14  while (nonempty(sleepq) && (firstkey(sleepq) <= 0)) {
16  }
17 
19  return;
20 }
qid16 sleepq
スリープ中のプロセスキュー
Definition: clkinit.c:7
#define firstkey(q)
リスト中の最初のプロセスのキーを返す。
status ready(pid32)
プロセスをCPUサービスの対象にする。
Definition: ready.c:21
status resched_cntl(int32)
再スケジューリングを延期させるか、もしくは許可させるかを制御する。
Definition: resched.c:81
pid32 dequeue(qid16)
プロセスキューテーブルからキューを削除し、リスト先頭のプロセスIDを返す。
Definition: queue.c:78
#define DEFER_STOP
遅延リスケジューリングの停止
Definition: resched.h:10
#define DEFER_START
遅延リスケジューリングの開始
Definition: resched.h:8
#define nonempty(q)
リストに中身(プロセス)があるかどうかを返す。
Definition: queue.h:99
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write()

syscall write ( did32  ,
char *  ,
uint32   
)

Definition at line 9 of file write.c.

References devtab, disable(), dentry::dvwrite, isbaddev, restore(), and SYSERR.

Referenced by arp_in(), arp_resolve(), ip_out(), lfdballoc(), lfdbfree(), lfflush(), lfiballoc(), lfibput(), lfscreate(), and xsh_rdstest().

14 {
15  intmask mask; /* Saved interrupt mask */
16  struct dentry *devptr; /* Entry in device switch table */
17  int32 retval; /* Value to return to caller */
18 
19  mask = disable();
20  if (isbaddev(descrp)) {
21  restore(mask);
22  return SYSERR;
23  }
24  devptr = (struct dentry *) &devtab[descrp];
25  retval = (*devptr->dvwrite) (devptr, buffer, count);
26  restore(mask);
27  return retval;
28 }
void restore(intmask)
devcall(* dvwrite)(struct dentry *, void *, uint32)
Definition: conf.h:14
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
Definition: conf.h:6
struct dentry devtab[]
Definition: conf.c:11
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define isbaddev(f)
デバイスIDを検証するマクロ。
Definition: device.h:15
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ xdone()

void xdone ( void  )

最終プロセスの終了時、システム終了メッセージを表示する。

Definition at line 10 of file xdone.c.

References halt(), and kprintf().

Referenced by kill().

11 {
12  kprintf("\n\nAll user processes have completed.\n\n");
13  halt(); /* Halt the processor */
14 }
syscall kprintf(char *fmt,...)
ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。
Definition: kprintf.c:98
void halt(void)
システムを停止させる(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ yield()

syscall yield ( void  )

CPU実行権を自発的に放棄する(タイムスライスを終了する)。

割り込みを禁止して再スケジューリングを行う。復帰後、割り込み状態を復元する。

Returns
OKを返す。

Definition at line 12 of file yield.c.

References disable(), OK, resched(), and restore().

Referenced by sleepms().

13 {
14  intmask mask; /* Saved interrupt mask */
15 
16  mask = disable();
17  resched();
18  restore(mask);
19  return OK;
20 }
void restore(intmask)
#define OK
処理が成功した場合
Definition: kernel.h:77
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
void resched(void)
最優先の適切なプロセスにCPU実行権を渡す。
Definition: resched.c:22
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function: