ASRCS += $(SRC_PROC_CC_DIR)/kexc_hdr.S
# %jp{C言語ファイルの追加}%en{C sources}
-CSRCS +=
+CSRCS += $(SRC_PROC_DIR)/val_int.c
# %jp{カーネル共通ソースの追加}%en{kernel common sources}
include $(KERNEL_MAKINC_DIR)/knlsrc.inc
--- /dev/null
+/**
+ * Hyper Operating System V4 Advance
+ *
+ * @file irc.h
+ * @brief %jp{Jelly FPGAシステム}%en{Jelly FPGA}
+ *
+ * Copyright (C) 1998-2008 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#ifndef _KERNEL__arch__irc__jelly__irc_h__
+#define _KERNEL__arch__irc__jelly__irc_h__
+
+
+/* %jp{メモリマップドレジスタ定義} */
+#define _KERNEL_IRC_BASE 0xf0000000
+
+#define _KERNEL_IRC_ENABLE ((volatile UW *)(_KERNEL_IRC_BASE + 0x00)) /* Enable Register */
+#define _KERNEL_IRC_MASK ((volatile UW *)(_KERNEL_IRC_BASE + 0x04)) /* Mask Register */
+#define _KERNEL_IRC_REQ_FACTOR_ID ((volatile const UW *)(_KERNEL_IRC_BASE + 0x08)) /* */
+#define _KERNEL_IRC_REQ_PRIORITY ((volatile const UW *)(_KERNEL_IRC_BASE + 0x0c))
+#define _KERNEL_IRC_FACTOR_ID_MAX ((volatile const UW *)(_KERNEL_IRC_BASE + 0x10))
+#define _KERNEL_IRC_PRIORITY_MAX ((volatile const UW *)(_KERNEL_IRC_BASE + 0x14))
+#define _KERNEL_IRC_FACTOR_ENABLE(n) ((volatile UW *)(_KERNEL_IRC_BASE + 0x20 + ((n) * 0x10)))
+#define _KERNEL_IRC_FACTOR_PENDING(n) ((volatile UW *)(_KERNEL_IRC_BASE + 0x24 + ((n) * 0x10)))
+#define _KERNEL_IRC_FACTOR_STATUS(n) ((volatile const UW *)(_KERNEL_IRC_BASE + 0x28 + ((n) * 0x10)))
+#define _KERNEL_IRC_FACTOR_PRIORITY(n) ((volatile UW *)(_KERNEL_IRC_BASE + 0x2c + ((n) * 0x10)))
+
+
+typedef struct _kernel_t_irccb
+{
+ UB ptr;
+ UB mask[8];
+} _KERNEL_T_IRCCB;
+
+extern _KERNEL_T_IRCCB _kernel_irccb;
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void _kernel_ini_irc(void); /**< %jp{割込みコントローラの初期化} */
+void _kernel_exe_irc(INHNO inhno); /**< %jp{割込み処理} */
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#define _KERNEL_INI_IRC() _kernel_ini_irc() /**< %jp{割込みコントローラの初期化} */
+#define _KERNEL_EXE_IRC(inhno) _kernel_exe_irc(inhno) /**< %jp{割込み処理} */
+
+
+#endif /* _KERNEL__arch__irc__jelly__irc_h__ */
+
+
+/* end of file */
--- /dev/null
+/**
+ * Hyper Operating System V4 Advance
+ *
+ * @file ircatr.h
+ * @brief %jp{Jelly FPGAシステム}%en{Jelly FPGA}
+ *
+ * Copyright (C) 1998-2008 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#ifndef _KERNEL__arch__irc__jelly__ircatr_h__
+#define _KERNEL__arch__irc__jelly__ircatr_h__
+
+
+#define _KERNEL_IRCATR_INC_PATH "mips/jelly"
+
+#define _KERNEL_IRCATR_IRC TRUE /**< %jp{IRCの有無} */
+
+#define _KERNEL_IRCATR_TMIN_INTNO 0 /**< %jp{割込み番号の最小値} */
+#define _KERNEL_IRCATR_TMAX_INTNO 255 /**< %jp{割込み番号の最大値} */
+
+
+#endif /* _KERNEL__arch__irc__jelly__ircatr_h__ */
+
+
+
+/* end of file */
--- /dev/null
+/**
+ * Hyper Operating System V4 Advance
+ *
+ * @file dis_int.c
+ * @brief %jp{Jelly FPGAシステム}%en{Jelly FPGA}
+ *
+ * Copyright (C) 1998-2008 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include "core/core.h"
+#include "object/inhobj.h"
+#include "object/isrobj.h"
+
+
+
+/* 割り込みの禁止 */
+ER dis_int(INTNO intno)
+{
+ if ( intno < _KERNEL_IRCATR_TMIN_INTNO || intno > *_KERNEL_IRC_FACTOR_ID_MAX )
+ {
+ return E_PAR;
+ }
+
+ *_KERNEL_IRC_FACTOR_ENABLE(intno) = 0;
+
+ return E_OK;
+}
+
+
+
+/* end of file */
--- /dev/null
+/**
+ * Hyper Operating System V4 Advance
+ *
+ * @file ena_int.c
+ * @brief %jp{Jelly FPGAシステム}%en{Jelly FPGA}
+ *
+ * Copyright (C) 1998-2008 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include "core/core.h"
+#include "object/inhobj.h"
+#include "object/isrobj.h"
+
+
+/* 割り込みの許可 */
+ER ena_int(INTNO intno)
+{
+ if ( intno < _KERNEL_IRCATR_TMIN_INTNO || intno > *_KERNEL_IRC_FACTOR_ID_MAX )
+ {
+ return E_PAR;
+ }
+
+ *_KERNEL_IRC_FACTOR_ENABLE(intno) = 1;
+
+ return E_OK;
+}
+
+
+/* end of file */
--- /dev/null
+/**
+ * Hyper Operating System V4 Advance
+ *
+ * @file exe_irc.h
+ * @brief %jp{Jelly FPGAシステム}%en{Jelly FPGA}
+ *
+ * Copyright (C) 1998-2008 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include "core/core.h"
+#include "object/inhobj.h"
+#include "object/isrobj.h"
+
+
+/** %jp{割込みコントローラの割込み処理} */
+void _kernel_exe_irc(INHNO inhno)
+{
+ INTNO intno;
+ UW mask;
+
+ /* %jp{前処理} */
+ *_KERNEL_IRC_ENABLE = 0;
+ intno = *_KERNEL_IRC_REQ_FACTOR_ID;
+ mask = *_KERNEL_IRC_MASK;
+ *_KERNEL_IRC_MASK = *_KERNEL_IRC_REQ_PRIORITY;
+ *_KERNEL_IRC_ENABLE = 1;
+
+ /* %jp{割込みサービスルーチン呼び出し} */
+ _kernel_exe_isr(intno);
+
+ /* %jp{割込み終了} */
+ *_KERNEL_IRC_ENABLE = 0;
+ *_KERNEL_IRC_MASK = mask;
+ *_KERNEL_IRC_ENABLE = 1;
+}
+
+
+/* end of file */
--- /dev/null
+/**
+ * Hyper Operating System V4 Advance
+ *
+ * @file ini_irc.c
+ * @brief %jp{Jelly FPGAシステム}%en{Jelly FPGA}
+ *
+ * Copyright (C) 1998-2008 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+
+#include "core/core.h"
+#include "object/inhobj.h"
+#include "object/isrobj.h"
+
+
+
+/** %jp{割込みコントローラの初期化} */
+void _kernel_ini_irc(void)
+{
+ UW maxid;
+ UW pri;
+ UW i;
+
+
+ *_KERNEL_IRC_ENABLE = 0;
+
+ maxid = *_KERNEL_IRC_FACTOR_ID_MAX;
+ pri = *_KERNEL_IRC_PRIORITY_MAX - 1;
+
+ for ( i = 0; i <= maxid; i++ )
+ {
+ *_KERNEL_IRC_FACTOR_ENABLE(i) = 0;
+ *_KERNEL_IRC_FACTOR_PENDING(i) = 0;
+ *_KERNEL_IRC_FACTOR_PRIORITY(i) = pri;
+ }
+ _kernel_irccb.ptr = 0;
+
+
+ *_KERNEL_IRC_ENABLE = 1;
+}
+
+
+/* end of file */
--- /dev/null
+/**
+ * Hyper Operating System V4 Advance
+ *
+ * @file vclr_int.h
+ * @brief %jp{Jelly FPGAシステム}%en{Jelly FPGA}
+ *
+ * Copyright (C) 1998-2008 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include "core/core.h"
+#include "object/inhobj.h"
+#include "object/isrobj.h"
+
+
+/* %jp{割り込みのクリア} */
+ER vclr_int(INTNO intno)
+{
+ if ( intno < _KERNEL_IRCATR_TMIN_INTNO || intno > *_KERNEL_IRC_FACTOR_ID_MAX )
+ {
+ return E_PAR;
+ }
+
+ *_KERNEL_IRC_FACTOR_PENDING(intno) = 0;
+
+ return E_OK;
+}
+
+
+/* end of file */
--- /dev/null
+/* ------------------------------------------------------------------------ */
+/* Hyper Operating System V4 Advance */
+/* Sample program for Jelly */
+/* */
+/* Copyright (C) 2008 by Project HOS */
+/* http://sourceforge.jp/projects/hos/ */
+/* ------------------------------------------------------------------------ */
+
+
+ .extern _kernel_int_isp
+ .extern _kernel_exc_hdr
+ .extern ___data
+ .extern ___data_end
+ .extern ___data_rom
+ .extern ___bss
+ .extern ___bss_end
+ .extern _gp
+ .extern main
+
+ .global _reset_handler
+ .global _exception_handler
+
+
+
+ .text
+ .set noreorder
+
+
+/************************************************
+ %jp{リセットハンドラ}
+************************************************/
+ .ent _reset_handler
+_reset_handler:
+ nop
+ nop
+
+ la $gp, _gp
+ la $sp, 0x01008000
+ // la $v0, _kernel_int_isp
+ // lw $sp, ($v0)
+
+ // test
+ la $8, 0x1234
+ la $9, 0x5678
+ mult $8, $9
+ mfhi $8
+ mflo $9
+
+
+ // BSS initialize
+ la $8, ___bss
+ la $9, ___bss_end
+ beq $8, $9, bss_loop_end
+ nop
+
+bss_loop:
+ sw $0, ($8)
+ addi $8, $8, 4
+ bne $8, $9, bss_loop
+ nop
+bss_loop_end:
+
+
+ // DATA copy
+ la $8, ___data
+ la $9, ___data_end
+ la $10, ___data_rom
+ beq $8, $9, data_loop_end
+ nop
+
+data_loop:
+ lw $11, ($10)
+ addi $10, $10, 4
+ sw $11, ($8)
+ addi $8, $8, 4
+ bne $8, $9, data_loop
+ nop
+data_loop_end:
+
+
+ la $8, main
+ jal $8
+ nop
+ j _reset_handler
+ nop
+
+ .end _reset_handler
+
+
+
+/************************************************
+ %jp{例外ハンドラ}
+************************************************/
+ .org 0x180
+ .ent _exception_handler
+_exception_handler:
+ la $26, _kernel_exc_hdr
+ jr $26
+ nop
+
+ .end _exception_handler
+
+
+
+/* end of file */
--- /dev/null
+# ----------------------------------------------------------------------------
+# Hyper Operating System V4 Advance
+#
+# Copyright (C) 1998-2008 by Project HOS
+# http://sourceforge.jp/projects/hos/
+# ----------------------------------------------------------------------------
+
+
+
+# --------------------------------------
+# %jp{各種設定}{setting}
+# --------------------------------------
+
+# %jp{ターゲット名}%en{target name}
+TARGET ?= sample
+
+
+# %jp{ツール定義}%en{tools}
+GCC_ARCH ?= mips-elf-
+CMD_CC ?= $(GCC_ARCH)gcc
+CMD_ASM ?= $(GCC_ARCH)gcc
+CMD_LINK ?= $(GCC_ARCH)gcc
+CMD_OBJCNV ?= $(GCC_ARCH)objcopy
+
+
+# %jp{アーキテクチャ定義}%en{architecture}
+ARCH_NAME ?= mips1
+ARCH_CC ?= gcc
+EXT_EXE ?= elf
+
+
+# %jp{ディレクトリ定義}%en{directories}
+TOP_DIR = ../../../..
+KERNEL_DIR = $(TOP_DIR)/kernel
+KERNEL_CFGRTR_DIR = $(TOP_DIR)/cfgrtr/build/gcc
+KERNEL_MAKINC_DIR = $(KERNEL_DIR)/build/common/gmake
+KERNEL_BUILD_DIR = $(KERNEL_DIR)/build/mips/mips1/gcc
+
+
+# %jp{コンフィギュレータ定義}
+KERNEL_CFGRTR = $(KERNEL_CFGRTR_DIR)/h4acfg-$(ARCH_NAME)
+
+
+# %jp{共通定義読込み}%jp{common setting}
+include $(KERNEL_MAKINC_DIR)/common.inc
+
+
+# %jp{リンカスクリプト}%en{linker script}
+LINK_SCRIPT = link.x
+
+
+# %jp{内蔵RAM}%en{internal RAM}
+ifeq ($(MEMMAP),ram)
+LINK_SCRIPT = linkram.x
+TARGET := $(TARGET)_ram
+endif
+
+
+# %jp{パス設定}%en{add source directories}
+INC_DIRS += . ..
+SRC_DIRS += . ..
+
+
+# %jp{オプションフラグ}%en{option flags}
+AFLAGS = -march=mips1
+CFLAGS = -march=mips1
+LNFLAGS = -march=mips1 -nostartfiles -Wl,-Map,$(TARGET).map,-T$(LINK_SCRIPT)
+
+
+# %jp{コンパイラ依存の設定読込み}%en{compiler dependent definitions}
+include $(KERNEL_MAKINC_DIR)/$(ARCH_CC)_d.inc
+
+# %jp{実行ファイル生成用設定読込み}%en{definitions for exection file}
+include $(KERNEL_MAKINC_DIR)/makexe_d.inc
+
+
+# %jp{出力ファイル名}%en{output files}
+TARGET_EXE = $(TARGET).$(EXT_EXE)
+TARGET_MOT = $(TARGET).$(EXT_MOT)
+TARGET_HEX = $(TARGET).$(EXT_HEX)
+TARGET_BIN = $(TARGET).$(EXT_BIN)
+
+
+
+# --------------------------------------
+# %jp{ソースファイル}%en{source files}
+# --------------------------------------
+
+# %jp{アセンブラファイルの追加}%en{assembry sources}
+ASRCS += ./crt0.S
+
+
+# %jp{C言語ファイルの追加}%en{C sources}
+CSRCS += ../main.c
+CSRCS += ../kernel_cfg.c
+CSRCS += ../sample.c
+CSRCS += ../uart.c
+CSRCS += ../ostimer.c
+
+
+
+# --------------------------------------
+# %jp{ルール定義}%en{rules}
+# --------------------------------------
+
+# %jp{ALL}%en{all}
+.PHONY : all
+all: kernel_make makeexe_all $(TARGET_EXE) $(TARGET_MOT) $(TARGET_HEX) $(TARGET_BIN)
+
+# %jp{クリーン}%en{clean}
+.PHONY : clean
+clean: makeexe_clean
+ rm -f $(TARGET_EXE) $(TARGET_EXE) $(OBJS) ../kernel_cfg.c ../kernel_id.h
+
+# %jp{依存関係更新}%en{depend}
+.PHONY : depend
+depend: makeexe_depend
+
+# %jp{ソース一括コピー}%en{source files copy}
+.PHONY : srccpy
+srccpy: makeexe_srccpy
+
+# %jp{カーネルごとクリーン}%en{mostlyclean}
+.PHONY : mostlyclean
+mostlyclean: clean kernel_clean
+
+
+# %jp{コンフィギュレータ実行}%en{configurator}
+../kernel_cfg.c ../kernel_id.h: ../system.cfg $(KERNEL_CFGRTR)
+ cpp -E ../system.cfg ../system.i
+ $(KERNEL_CFGRTR) ../system.i -c ../kernel_cfg.c -i ../kernel_id.h
+
+
+# %jp{実行ファイル生成用設定読込み}%en{rules for exection file}
+include $(KERNEL_MAKINC_DIR)/makexe_r.inc
+
+# %jp{コンパイラ依存のルール定義読込み}%en{rules for compiler}
+include $(KERNEL_MAKINC_DIR)/$(ARCH_CC)_r.inc
+
+
+
+
+# --------------------------------------
+# %jp{依存関係}%en{dependency}
+# --------------------------------------
+
+$(TARGET_EXE): $(LINK_SCRIPT)
+
+$(OBJS_DIR)/sample.$(EXT_OBJ) : ../kernel_id.h
+
+
+
+# end of file
+
--- /dev/null
+OUTPUT_ARCH(mips)
+ENTRY(_reset_handler)
+
+MEMORY
+{
+ rom : o = 0x00000000, l = 0x00010000
+ ram : o = 0x01000000, l = 0x00100000
+}
+
+SECTIONS
+{
+ .text :
+ {
+ ___text = . ;
+ */crt0.o(.text)
+ *(.text)
+ *(.strings)
+ *(.rodata*)
+ *(.glue*)
+ ___text_end = . ;
+ } > rom
+ .tors :
+ {
+ . = ALIGN(4);
+ ___ctors = . ;
+ *(.ctors)
+ ___ctors_end = . ;
+ ___dtors = . ;
+ *(.dtors)
+ ___dtors_end = . ;
+ } > rom
+ data : AT (ADDR(.tors) + SIZEOF(.tors))
+ {
+ ___data_rom = ADDR(.tors) + SIZEOF(.tors);
+ ___data = . ;
+ *(.data)
+ _gp = ALIGN(16) + 0x7ff0;
+ *(.sdata)
+ ___data_end = . ;
+ } > ram
+ .bss :
+ {
+ ___bss = . ;
+ *(.sbss)
+ *(.bss)
+ *(COMMON)
+ *(.scommon)
+ ___bss_end = . ;
+ } >ram
+}
+
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file main.c
+ * @brief %jp{メイン関数}%en{main}
+ *
+ * Copyright (C) 1998-2006 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include "kernel.h"
+
+
+
+/** %jp{メイン関数} */
+int main()
+{
+ /* %jp{カーネルの動作開始} */
+ vsta_knl();
+
+ return 0;
+}
+
+
+
+/* end of file */
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file ostimer.c
+ * @brief %jp{OSタイマ}%en{OS timer}
+ *
+ * Copyright (C) 1998-2008 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include "kernel.h"
+#include "ostimer.h"
+
+
+#define INTNO_TIMER0 0
+
+
+static void OsTimer_Inh(void); /**< %jp{タイマ割込みサービスルーチン} */
+
+
+/** %jp{OS用タイマ初期化ルーチン} */
+void OsTimer_Initialize(VP_INT exinf)
+{
+ T_DINH dinh;
+
+ dinh.inhatr = TA_HLNG;
+ dinh.inthdr = (FP)OsTimer_Inh;
+ def_inh(INTNO_TIMER0, &dinh);
+}
+
+
+/** %jp{タイマ割込みハンドラ} */
+void OsTimer_Inh(void)
+{
+ /* %jp{タイムティック供給} */
+ isig_tim();
+}
+
+
+
+/* end of file */
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file ostimer.c
+ * @brief %jp{OSタイマ}%en{OS timer}
+ *
+ * Copyright (C) 1998-2006 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#ifndef __ostimer_h__
+#define __ostimer_h__
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** %jp{OS用タイマ初期化ルーチン} */
+void OsTimer_Initialize(VP_INT exinf);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __ostimer_h__ */
+
+
+/* end of file */
--- /dev/null
+Ryuz が別途開発中の FPGA向けのMIPSライクなコア用のサンプル
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file sample.c
+ * @brief %jp{サンプルプログラム}%en{Sample program}
+ *
+ * Copyright (C) 1998-2006 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include "kernel.h"
+#include "kernel_id.h"
+#include "uart.h"
+
+
+#define LEFT(num) ((num) <= 1 ? 5 : (num) - 1)
+#define RIGHT(num) ((num) >= 5 ? 1 : (num) + 1)
+
+
+ID mbxid;
+ID mpfid;
+
+
+/** %jp{メッセージ構造体} */
+typedef struct t_print_msg
+{
+ T_MSG msg;
+ char text[32];
+} T_PRINT_MSG;
+
+
+/** %jp{初期化ハンドラ} */
+void Sample_Initialize(VP_INT exinf)
+{
+ T_CMPF cmpf;
+ T_CMBX cmbx;
+
+ /* %jp{UART初期化} */
+ Uart_Initialize();
+
+ /* %jp{固定長メモリプール生成} */
+ cmpf.mpfatr = TA_TFIFO;
+ cmpf.blkcnt = 3;
+ cmpf.blksz = sizeof(T_PRINT_MSG);
+ cmpf.mpf = NULL;
+ mpfid = acre_mpf(&cmpf);
+
+ /* %jp{メールボックス生成} */
+ cmbx.mbxatr = TA_TFIFO | TA_TFIFO;
+ cmbx.maxmpri = 1;
+ cmbx.mprihd = NULL;
+ mbxid = acre_mbx(&cmbx);
+
+ /* %jp{タスク起動} */
+ act_tsk(TSKID_PRINT);
+ act_tsk(TSKID_SAMPLE1);
+ act_tsk(TSKID_SAMPLE2);
+ act_tsk(TSKID_SAMPLE3);
+ act_tsk(TSKID_SAMPLE4);
+ act_tsk(TSKID_SAMPLE5);
+}
+
+
+/** %jp{適当な時間待つ} */
+void rand_wait(void)
+{
+ static unsigned long seed = 12345;
+ unsigned long r;
+
+ wai_sem(SEMID_RAND);
+ seed = seed * 22695477UL + 1;
+ r = seed;
+ sig_sem(SEMID_RAND);
+
+ dly_tsk((r % 1000) + 100);
+}
+
+
+/** %jp{状態表示} */
+void print_state(int num, char *text)
+{
+ T_PRINT_MSG *msg;
+ VP mem;
+ int i;
+
+ /* %jp{メモリ取得} */
+ get_mpf(mpfid, &mem);
+ msg = (T_PRINT_MSG *)mem;
+
+ /* %jp{文字列生成} */
+ msg->text[0] = '0' + num;
+ msg->text[1] = ' ';
+ msg->text[2] = ':';
+ msg->text[3] = ' ';
+ for ( i = 0; text[i] != '\0'; i++ )
+ {
+ msg->text[4+i] = text[i];
+ }
+ msg->text[4+i] = '\n';
+ msg->text[5+i] = '\0';
+
+ /* %jp{表示タスクに送信} */
+ snd_mbx(mbxid, (T_MSG *)msg);
+}
+
+
+/** %jp{サンプルタスク} */
+void Sample_Task(VP_INT exinf)
+{
+ int num;
+
+ num = (int)exinf;
+
+ /* %jp{いわゆる哲学者の食事の問題} */
+ for ( ; ; )
+ {
+ /* %jp{適当な時間考える} */
+ print_state(num, "thinking");
+ rand_wait();
+
+ /* %jp{左右のフォークを取るまでループ} */
+ for ( ; ; )
+ {
+ /* %jp{左から順に取る} */
+ wai_sem(LEFT(num));
+ if ( pol_sem(RIGHT(num)) == E_OK )
+ {
+ break; /* %jp{両方取れた} */
+ }
+ sig_sem(LEFT(num)); /* %jp{取れなければ離す} */
+
+ /* %jp{適当な時間待つ} */
+ print_state(num, "hungry");
+ rand_wait();
+
+ /* %jp{右から順に取る} */
+ wai_sem(RIGHT(num));
+ if ( pol_sem(LEFT(num)) == E_OK )
+ {
+ break; /* %jp{両方取れた} */
+ }
+ sig_sem(RIGHT(num)); /* %jp{取れなければ離す} */
+
+ /* %jp{適当な時間待つ} */
+ print_state(num, "hungry");
+ rand_wait();
+ }
+
+ /* %jp{適当な時間、食べる} */
+ print_state(num, "eating");
+ rand_wait();
+
+ /* %jp{フォークを置く} */
+ sig_sem(LEFT(num));
+ sig_sem(RIGHT(num));
+ }
+}
+
+
+/** %jp{表示タスク} */
+void Sample_Print(VP_INT exinf)
+{
+ T_PRINT_MSG *msg;
+
+ for ( ; ; )
+ {
+ rcv_mbx(mbxid, (T_MSG **)&msg);
+ Uart_PutString(msg->text);
+ rel_mpf(mpfid, msg);
+ }
+}
+
+
+
+/* end of file */
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file sample.c
+ * @brief %jp{サンプルプログラム}%en{Sample program}
+ *
+ * Copyright (C) 1998-2006 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+
+#ifndef __sample_h__
+#define __sample_h__
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void Sample_Initialize(VP_INT exinf);
+void Sample_Task(VP_INT exinf);
+void Sample_Print(VP_INT exinf);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __sample_h__ */
+
+
+/* end of file */
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file system.cfg
+ * @brief %jp{サンプルのコンフィギュレーション}
+ *
+ * Copyright (C) 1998-2006 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+
+/* %jp{カーネル独自の設定}%en{kernel} */
+KERNEL_HEP_MEM(4096, NULL);
+KERNEL_SYS_STK(512, NULL);
+KERNEL_INT_STK(512, NULL);
+KERNEL_MAX_TSKID(5);
+KERNEL_MAX_SEMID(6);
+KERNEL_MAX_FLGID(2);
+KERNEL_MAX_MBXID(2);
+KERNEL_MAX_MPFID(2);
+KERNEL_MAX_ISRID(4);
+
+
+/* %jp{OSタイマの設定}%en{OS timer} */
+INCLUDE("\"ostimer.h\"");
+ATT_INI({TA_HLNG, 0, OsTimer_Initialize});
+
+/* %jp{サンプル}%en{Sample program} */
+INCLUDE("\"sample.h\"");
+ATT_INI({TA_HLNG, 0, Sample_Initialize});
+CRE_TSK(TSKID_PRINT, {TA_HLNG, 1, Sample_Print, 1, 512, NULL});
+CRE_TSK(TSKID_SAMPLE1, {TA_HLNG, 1, Sample_Task, 2, 512, NULL});
+CRE_TSK(TSKID_SAMPLE2, {TA_HLNG, 2, Sample_Task, 2, 512, NULL});
+CRE_TSK(TSKID_SAMPLE3, {TA_HLNG, 3, Sample_Task, 2, 512, NULL});
+CRE_TSK(TSKID_SAMPLE4, {TA_HLNG, 4, Sample_Task, 2, 512, NULL});
+CRE_TSK(TSKID_SAMPLE5, {TA_HLNG, 5, Sample_Task, 2, 512, NULL});
+CRE_SEM(1, {TA_TFIFO, 1, 1});
+CRE_SEM(2, {TA_TFIFO, 1, 1});
+CRE_SEM(3, {TA_TFIFO, 1, 1});
+CRE_SEM(4, {TA_TFIFO, 1, 1});
+CRE_SEM(5, {TA_TFIFO, 1, 1});
+CRE_SEM(SEMID_RAND, {TA_TFIFO, 1, 1});
+
+
+
+/* end of file */
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file uart.c
+ * @brief %jp{UARTへの出力}%en{UART device driver}
+ *
+ * Copyright (C) 1998-2006 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#include "kernel.h"
+
+
+#define UART_DATA ((volatile UW *)0xf2000000)
+#define UART_STAT ((volatile UW *)0xf2000004)
+
+
+
+/* %jp{UARTの初期化} */
+void Uart_Initialize(void)
+{
+}
+
+
+/* %jp{1文字入力} */
+char Uart_GetChar(void)
+{
+ while ( !(*UART_STAT & 0x01) )
+ ;
+
+ return *UART_DATA;
+}
+
+
+/* %jp{1文字出力} */
+void Uart_PutChar(int c)
+{
+ while ( !(*UART_STAT & 0x02) )
+ ;
+
+ *UART_DATA = c;
+}
+
+
+/* %jp{文字列出力} */
+void Uart_PutString(const char *text)
+{
+ while ( *text != '\0' )
+ {
+ if ( *text == '\n' )
+ {
+ Uart_PutChar('\r');
+ Uart_PutChar('\n');
+ }
+ else
+ {
+ Uart_PutChar(*text);
+ }
+
+ text++;
+ }
+}
+
+
+char Uart_hex2asc(int a)
+{
+ if ( a < 10 )
+ {
+ return '0' + a;
+ }
+ return 'a' + a - 10;
+}
+
+
+void Uart_PutHexByte(char c)
+{
+ Uart_PutChar(Uart_hex2asc((c >> 4) & 0xf));
+ Uart_PutChar(Uart_hex2asc((c >> 0) & 0xf));
+}
+
+
+void Uart_PutHexWord(int i)
+{
+ Uart_PutHexByte((i >> 8) & 0xff);
+ Uart_PutHexByte((i >> 0) & 0xff);
+}
+
+
+
+/* end of file */
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file uart.h
+ * @brief %jp{UARTへの出力}%en{UART device driver}
+ *
+ * Copyright (C) 1998-2006 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+#ifndef __ostimer_h__
+#define __ostimer_h__
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void Uart_Initialize(void); /* %jp{UART の初期化} */
+void Uart_PutChar(int c); /* %jp{1文字出力} */
+void Uart_PutString(const char *text); /* %jp{文字列出力} */
+
+void Uart_PutHexByte(char c);
+void Uart_PutHexWord(int i);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __ostimer_h__ */
+
+
+/* end of file */