--- /dev/null
+/* ------------------------------------------------------------------------ */
+/* Hyper Operating System V4 Advance */
+/* Sample program for MicroBlaze */
+/* */
+/* Copyright (C) 1998-2011 by Project HOS */
+/* http://sourceforge.jp/projects/hos/ */
+/* ------------------------------------------------------------------------ */
+
+
+ .extern _kernel_int_isp
+ .extern ___data
+ .extern ___data_end
+ .extern ___bss
+ .extern ___bss_end
+ .extern main
+
+ .global _reset_handler
+
+ .text
+
+
+
+/************************************************
+ リセットハンドラ
+************************************************/
+ .align 2
+_reset_handler:
+ /* スタック設定 */
+ lwi r1, r0, _kernel_int_isp
+
+ addik r3, r0, ___data
+ addik r4, r0, ___data_end
+ addik r5, r0, ___data_ro
+
+ /* DATA領域のコピー */
+ cmpu r18, r4, r3
+ bgei r18, data_loop_end
+data_loop:
+ lwi r6, r5, 0
+ swi r6, r3, 0
+ addik r3, r3, 4
+ cmpu r18, r4, r3
+ bltid r18, data_loop
+ addik r5, r5, 4
+data_loop_end:
+
+ /* BSS領域の初期化 */
+ addik r3, r0, ___bss
+ addik r4, r0, ___bss_end
+ cmpu r18,r4, r3
+ bgei r18, bss_loop_end
+bss_loop:
+ swi r0, r3, 0
+ addik r3, r3, 4
+ cmpu r18, r4, r3
+ blti r18, bss_loop
+bss_loop_end:
+
+
+ /* main関数の呼び出し */
+ brlid r15, main
+ nop
+
+exit_loop:
+ bri exit_loop
+
+
+
+/* end of file */
--- /dev/null
+ENTRY(_reset_handler)
+
+MEMORY
+{
+ ro : o = 0x00000100, l = 0x00003f00
+ rw : o = 0x00004000, l = 0x00004000
+}
+
+SECTIONS
+{
+ .vectors.reset 0x00000000 :
+ {
+ *(.vectors.reset)
+ }
+ .vectors.sw_exception 0x00000008 :
+ {
+ *(.vectors.sw_exception)
+ }
+ .vectors.interrupt 0x00000010 :
+ {
+ *(.vectors.interrupt)
+ }
+ .vectors.hw_exception 0x00000020 :
+ {
+ *(.vectors.hw_exception)
+ }
+
+ .text :
+ {
+ ___text = . ;
+ *(.text)
+ *(.strings)
+ *(.rodata*)
+ *(.glue*)
+ ___text_end = . ;
+ } > ro
+ .tors :
+ {
+ . = ALIGN(4);
+ ___ctors = . ;
+ *(.ctors)
+ ___ctors_end = . ;
+ ___dtors = . ;
+ *(.dtors)
+ ___dtors_end = . ;
+ } > ro
+ data : AT (ADDR(.tors) + SIZEOF(.tors))
+ {
+ ___data_ro = ADDR(.tors) + SIZEOF(.tors);
+ ___data = . ;
+ *(.data)
+ ___data_end = . ;
+ } > rw
+ .bss :
+ {
+ ___bss = . ;
+ *(.bss)
+ *(COMMON)
+ ___bss_end = . ;
+ } >rw
+}
+
--- /dev/null
+/* ------------------------------------------------------------------------ */
+/* Hyper Operating System V4 サンプルプログラム */
+/* ベクタテーブル */
+/* */
+/* Copyright (C) 1998-2011 by Project HOS */
+/* http://sourceforge.jp/projects/hos/ */
+/* ------------------------------------------------------------------------ */
+
+
+ /* --- 外部定数宣言 */
+ .global _reset_handler
+ .global _kernel_exc_hdr
+ .global _kernel_int_hdr
+ .global _kernel_brk_hdr
+ .global _kernel_hwe_hdr
+
+
+ .align 2
+
+/* --------------------------------------- */
+/* ベクタ定義 */
+/* --------------------------------------- */
+
+ .section .vectors.reset, "ax"
+ brai _reset_handler
+
+ .section .vectors.sw_exception, "ax"
+ bri _kernel_exc_hdr
+
+ .section .vectors.interrupt, "ax"
+ bri _kernel_int_hdr
+
+ .section .vectors.hw_exception, "ax"
+ bri _kernel_hwe_hdr
+
+
+
+/* end of file */
--- /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"
+#include "uart.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_TIMER 0
+
+#define REG_TIMER_BASE 0x41c00000
+#define REG_TIMER_TCSR0 ((volatile unsigned long *)(REG_TIMER_BASE + 0x00))
+#define REG_TIMER_TLR0 ((volatile unsigned long *)(REG_TIMER_BASE + 0x04))
+#define REG_TIMER_TCR0 ((volatile unsigned long *)(REG_TIMER_BASE + 0x08))
+#define REG_TIMER_TCSR1 ((volatile unsigned long *)(REG_TIMER_BASE + 0x10))
+#define REG_TIMER_TLR1 ((volatile unsigned long *)(REG_TIMER_BASE + 0x14))
+#define REG_TIMER_TCR1 ((volatile unsigned long *)(REG_TIMER_BASE + 0x18))
+
+
+static void OsTimer_Isr(VP_INT exinf); /**< %jp{タイマ割込みサービスルーチン} */
+
+
+/** %jp{OS用タイマ初期化ルーチン} */
+void OsTimer_Initialize(VP_INT exinf)
+{
+ T_CISR cisr;
+
+ /* %jp{割込みサービスルーチン生成} */
+ cisr.isratr = TA_HLNG;
+ cisr.exinf = 0;
+ cisr.intno = INTNO_TIMER;
+ cisr.isr = (FP)OsTimer_Isr;
+ acre_isr(&cisr);
+
+ /* 開始 */
+ *REG_TIMER_TLR0 = 100000 - 1; /* 1ms 100MHz */
+ *REG_TIMER_TCSR0 = 0x0132; /* clear int, load counter */
+ *REG_TIMER_TCSR0 = 0x00d2; /* start */
+
+ /* 割込み許可 */
+ ena_int(INTNO_TIMER);
+}
+
+
+/** %jp{タイマ割込みハンドラ} */
+void OsTimer_Isr(VP_INT exinf)
+{
+ *REG_TIMER_TCSR0 |= 0x0100; /* clear int */
+ vclr_int(INTNO_TIMER);
+
+ /* %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
+==============================================================================
+ Hyper Operating System V4 Advance
+ 用サンプル
+
+ Copyright (C) 2008-2011 by Project HOS
+==============================================================================
+
+
+<概要>
+ お題は例によって、「哲学者の食事の問題」です。
+ 5つのタスクを哲学者、5つのセマフォをフォークに見立てて、
+動作します。
+
+ 哲学者はランダムな時間考え事をするとおもむろに両サイドの
+フォークを取って食事を始めます。しかし左右どちらかの哲学者が
+すでにフォークを使って食事をしていると、フォークが使えず
+空腹状態になります。
+
+
+<環境>
+ XILINX EDK12
+
+<使い方>
+ GNU make が利用できる環境で
+
+ gcc の場合: hos-v4a/sample/mb/mb_v8/gcc
+
+ に移動して、gmake
+
+ と打ち込みます。
+
+ 出来上がった、sample.bin をROMに配置して合成することで動作します。
+
+ 5人の哲学者がそれぞれ、考えたり、お腹を空かせたり、食事したりする様子が
+シリアルに表示されれば成功です。
+
+<備考>
+ gmake MEMMAP=ram
+
+ としすると、RAMを0番地に配置したモデルで sample_ram.bin を生成します。
+ ROM化せずにRAMをマッピングしてデバッグする場合にご利用ください。
+
+
+==============================================================================
+ end of file
+==============================================================================
--- /dev/null
+/**
+ * Sample program for Hyper Operating System V4 Advance
+ *
+ * @file sample.c
+ * @brief %jp{サンプルプログラム}%en{Sample program}
+ *
+ * Copyright (C) 1998-2009 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)
+
+
+/** %jp{初期化ハンドラ} */
+void Sample_Initialize(VP_INT exinf)
+{
+ /* %jp{UART初期化} */
+ Uart_Initialize();
+
+ /* %jp{タスク起動} */
+ act_tsk(TSKID_SAMPLE1);
+ act_tsk(TSKID_SAMPLE2);
+ act_tsk(TSKID_SAMPLE3);
+ act_tsk(TSKID_SAMPLE4);
+ act_tsk(TSKID_SAMPLE5);
+}
+
+
+/** %jp{適当な時間待つ} */
+void Sample_RandWait(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 Sample_PrintSatet(int num, const char *text)
+{
+ int i;
+
+ wai_sem(SEMID_UART);
+
+ /* %jp{文字列出力} */
+ Uart_PutChar('0' + num);
+ Uart_PutChar(' ');
+ Uart_PutChar(':');
+ Uart_PutChar(' ');
+ for ( i = 0; text[i] != '\0'; i++ )
+ {
+ Uart_PutChar(text[i]);
+ }
+ Uart_PutChar('\r');
+ Uart_PutChar('\n');
+
+ sig_sem(SEMID_UART);
+}
+
+
+
+/** %jp{サンプルタスク} */
+void Sample_Task(VP_INT exinf)
+{
+ int num;
+
+ num = (int)exinf;
+
+ /* %jp{いわゆる哲学者の食事の問題} */
+ for ( ; ; )
+ {
+ /* %jp{適当な時間考える} */
+ Sample_PrintSatet(num, "thinking");
+ Sample_RandWait();
+
+ /* %jp{左右のフォークを取るまでループ} */
+ for ( ; ; )
+ {
+ /* %jp{左から順に取る} */
+ wai_sem(LEFT(num));
+ if ( pol_sem(RIGHT(num)) == E_OK )
+ {
+ break; /* %jp{両方取れた} */
+ }
+ sig_sem(LEFT(num)); /* %jp{取れなければ離す} */
+
+ /* %jp{適当な時間待つ} */
+ Sample_PrintSatet(num, "hungry");
+ Sample_RandWait();
+
+ /* %jp{右から順に取る} */
+ wai_sem(RIGHT(num));
+ if ( pol_sem(LEFT(num)) == E_OK )
+ {
+ break; /* %jp{両方取れた} */
+ }
+ sig_sem(RIGHT(num)); /* %jp{取れなければ離す} */
+
+ /* %jp{適当な時間待つ} */
+ Sample_PrintSatet(num, "hungry");
+ Sample_RandWait();
+ }
+
+ /* %jp{適当な時間、食べる} */
+ Sample_PrintSatet(num, "eating");
+ Sample_RandWait();
+
+ /* %jp{フォークを置く} */
+ sig_sem(LEFT(num));
+ sig_sem(RIGHT(num));
+ }
+}
+
+
+/* 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-2009 by Project HOS
+ * http://sourceforge.jp/projects/hos/
+ */
+
+
+/* %jp{カーネル独自の設定}%en{kernel} */
++KERNEL_IRC_REGBASE(0x41200000);
+KERNEL_HEP_MEM(512, NULL);
+KERNEL_SYS_STK(512, NULL);
+KERNEL_INT_STK(512, NULL);
+KERNEL_MAX_TSKID(6);
+KERNEL_MAX_SEMID(7);
+KERNEL_MAX_FLGID(0);
+KERNEL_MAX_MBXID(0);
+KERNEL_MAX_MPFID(0);
+KERNEL_MAX_MTXID(1);
+KERNEL_MAX_ISRID(2);
+
+
+/* %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_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});
+CRE_SEM(SEMID_UART, {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 REG_UART_BASE 0x80000000
+#define REG_UART_RBR ((volatile unsigned long *)(REG_UART_BASE + 0x1000))
+#define REG_UART_THR ((volatile unsigned long *)(REG_UART_BASE + 0x1000))
+#define REG_UART_IER ((volatile unsigned long *)(REG_UART_BASE + 0x1004))
+#define REG_UART_IIR ((volatile unsigned long *)(REG_UART_BASE + 0x1008))
+#define REG_UART_LCR ((volatile unsigned long *)(REG_UART_BASE + 0x100c))
+#define REG_UART_MCR ((volatile unsigned long *)(REG_UART_BASE + 0x1010))
+#define REG_UART_LSR ((volatile unsigned long *)(REG_UART_BASE + 0x1014))
+#define REG_UART_MSR ((volatile unsigned long *)(REG_UART_BASE + 0x1018))
+#define REG_UART_SCR ((volatile unsigned long *)(REG_UART_BASE + 0x101c))
+#define REG_UART_DLL ((volatile unsigned long *)(REG_UART_BASE + 0x1000))
+#define REG_UART_DLM ((volatile unsigned long *)(REG_UART_BASE + 0x1004))
+
+
+/* %jp{UARTの初期化} */
+void Uart_Initialize(void)
+{
+ *REG_UART_IER = 0x00;
+ *REG_UART_LCR = 0x03;
+ *REG_UART_MCR = 0x03;
+ *REG_UART_LCR |= 0x80;
+ *REG_UART_DLL = 80; /* 50000000 / 38400 / 16 - 1 */
+ *REG_UART_DLM = 0x00;
+ *REG_UART_LCR &= 0x7f;
+}
+
+
+/* %jp{1文字入力} */
+char Uart_GetChar(void)
+{
+ return 0;
+}
+
+
+/* %jp{1文字出力} */
+void Uart_PutChar(int c)
+{
+ while ( !(*REG_UART_LSR & 0x20) )
+ ;
+
+ *REG_UART_THR = 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_PutHexHalfWord(unsigned short h)
+{
+ Uart_PutHexByte((h >> 8) & 0xff);
+ Uart_PutHexByte((h >> 0) & 0xff);
+}
+
+void Uart_PutHexWord(unsigned long w)
+{
+ Uart_PutHexHalfWord((w >> 16) & 0xffff);
+ Uart_PutHexHalfWord((w >> 0) & 0xffff);
+}
+
+
+
+/* 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_PutHexHalfWord(unsigned short h);
+void Uart_PutHexWord(unsigned long w);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __ostimer_h__ */
+
+
+/* end of file */