├── COPYRIGHT
├── Makefile
├── README.md
├── bin
├── cfg-lib.sh
├── m-cfg.sh
└── m-fmt.sh
├── include
├── cfg.h
├── clk-cpu.h
├── clk.h
├── core.h
├── cpu-arm
│ ├── _cpu.h
│ ├── _irq.h
│ ├── _task.h
│ ├── asm.h
│ ├── cache-vmsa.h
│ ├── cache.h
│ ├── gic.h
│ ├── hyper.h
│ └── reg.h
├── cpu-armm
│ ├── _cpu.h
│ ├── _irq.h
│ ├── _task.h
│ ├── asm.h
│ ├── cache-pmsa.h
│ ├── cache.h
│ ├── nvic.h
│ └── reg.h
├── cpu.h
├── dbg.h
├── io.h
├── irq.h
├── ll.h
├── mq.h
├── mut.h
├── sem.h
├── soc.h
├── task.h
├── tmr.h
└── wait.h
├── share
└── Makefile.rule
├── src-hello
├── Makefile
├── dbg.c
├── main.c
├── mod-ex.c
├── qemu.gdb
├── ram.ld
├── rom.ld
└── startup.S
├── src-soc-sim
├── Makefile
├── include
│ ├── _soc.h
│ └── uart.h
├── soc-fs.c
├── soc.c
└── uart.c
└── src
├── core.c
├── cpu-arm
├── Makefile
├── asm-off.c
├── cache-pmsa.c
├── cache-vmsa.c
├── cpu.c
├── cpum.c
├── gic-cfg.h
├── gic.c
├── mut-cpu-c.c
├── mut-cpu.S
├── sem-cpu-c.c
├── sem-cpu.S
├── task-cpu.S
├── task-cpum.S
├── vector5.S
├── vector7.S
└── vector7m.S
├── init.c
├── irq.c
├── mq.c
├── mut.c
├── sch.h
├── sch_pq.c
├── sem.c
├── task.c
├── tmr.c
└── tmr_impl.h
/COPYRIGHT:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | NAME :=hcos
2 | TARGET :=arm-none-eabi
3 | CROSS :=$(TARGET)-
4 | PREFIX :=$(shell pwd)/../prefix/$(CROSS:%-=%)
5 | CPU :=arm
6 | INCLUDE:=-Iinclude
7 |
8 | # -march=armv5t -msoft-float
9 | # -march=armv5t -mthumb -msoft-float
10 | # -march=armv7-a -mthumb -msoft-float
11 | # -march=armv7-m -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion
12 | COPTS ?=-march=armv5t
13 | AARCH :=$(shell echo $(COPTS) | sed -e 's/.*armv\([0-9]\).*/\1/g')
14 | AARCHX :=
15 | ifeq ($(shell echo $(COPTS) | sed -e 's/.*armv[0-9]-\([amr]\).*/\1/g'),m)
16 | AARCHX :=m
17 | endif
18 | MOPTS :=$(COPTS) \
19 | -DCFG_AARCH=$(AARCH) \
20 | -fno-builtin -fno-common \
21 | -ffunction-sections -fdata-sections -fshort-enums
22 | CONFIG ?=
23 | ASFLAGS:=$(MOPTS) $(CONFIG) -O2 -g -Wall -Werror -D __ASSEMBLY__
24 | CFLAGS :=$(MOPTS) $(CONFIG) -O2 -g -Wall -Werror
25 | LDFLAGS:=$(MOPTS)
26 | MSCRIPT:=share/mod.ld
27 | LIB :=lib$(NAME).a
28 |
29 | ALL :=include/cpu \
30 | include/mcfg.h \
31 | _cpu \
32 | _lib \
33 | _header \
34 | install \
35 | soc-sim.sub
36 | CLEAN :=soc-sim.subc _clean
37 |
38 | VPATH :=src src-test src/cpu-$(CPU)
39 | VOBJ :=$(patsubst %.S,%.o, \
40 | $(patsubst %.c,%.o, \
41 | $(patsubst %.cpp, %.o, \
42 | $(notdir $(foreach DIR,src src-test,\
43 | $(wildcard $(DIR)/*.S) \
44 | $(wildcard $(DIR)/*.c) \
45 | $(wildcard $(DIR)/*.cpp))))))
46 | default:all
47 |
48 | include src/cpu-$(CPU)/Makefile
49 | include share/Makefile.rule
50 |
51 | .PHONY:include/cpu
52 | include/cpu:
53 | rm -f $@
54 | ln -sf cpu-$(CPU)$(AARCHX) $@
55 |
56 | .PHONY:include/mcfg.h
57 | include/mcfg.h:
58 | bin/m-cfg.sh $(CONFIG) > $@
59 |
60 | _lib:
61 | $(MAKE) lib
62 |
63 | _header:
64 | install -d $(PREFIX)/include/hcos/cpu
65 | install -Dp include/cpu-$(CPU)$(AARCHX)/*.h $(PREFIX)/include/$(NAME)/cpu
66 | install -Dp include/cfg.h $(PREFIX)/include/hcos/cpu
67 |
68 | _clean:
69 | rm -f src-test/*loadable*-src.c
70 |
71 | src-test/t-mod-loadable-src.c:t-mod-loadable.o.mod.img
72 | echo "char _mod_src[] = {" >$@
73 | xxd -g 1 $^ | sed -e 's/ .*//g' -e 's/.*://g' -e 's/^ /0x/g' -e 's/ /,0x/g' -e 's/$$/,/g' >>$@
74 | echo "}; " >>$@
75 | echo "unsigned _mod_src_sz = sizeof(_mod_src); " >>$@
76 |
77 | src-test/t-mod-loadable2-src.c:t-mod-loadable2.o.mod.img
78 | echo "char _mod_src2[] = {" >$@
79 | xxd -g 1 $^ | sed -e 's/ .*//g' -e 's/.*://g' -e 's/^ /0x/g' -e 's/ /,0x/g' -e 's/$$/,/g' >>$@
80 | echo "}; " >>$@
81 | echo "unsigned _mod_src2_sz = sizeof(_mod_src2); " >>$@
82 |
83 | %.sub:
84 | cd src-$(@:%.sub=%) && $(MAKE) && $(MAKE) install
85 |
86 | %.subc:
87 | cd src-$(@:%.subc=%) && $(MAKE) clean
88 |
89 | copyright:
90 | $(PREFIX)/bin/m-copyright.sh .
91 |
92 | fmt:
93 | bin/m-fmt.sh .
94 |
95 | utest: all
96 | cd src-hello && \
97 | $(MAKE) clean && \
98 | $(MAKE) CONFIG= && \
99 | $(MAKE) run F="test.elf.pack" QF="-serial stdio -serial null"
100 |
101 | hello: all
102 | cd src-hello && \
103 | $(MAKE) clean && \
104 | $(MAKE) CONFIG= && \
105 | $(MAKE) sim F="main.elf" QF="-serial stdio -serial null"
106 |
107 | gdbs: all
108 | cd src-hello && \
109 | $(MAKE) clean && \
110 | $(MAKE) tstgdb.elf && \
111 | $(MAKE) run F="tstgdb.elf" QF="-serial stdio -serial tcp::8888,server"
112 |
113 | gdbc:
114 | cd src-hello && \
115 | $(MAKE) gdb F="tstgdb.elf"
116 |
117 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### This repository provide a strip version, request a complete version [HERE](http://socware.net/?page_id=300)
2 |
3 | ### Subscribe the mailing list [HERE](http://www.freelists.org/list/hypercos)
4 |
5 | ### Visit our web [HERE](http://socware.net))
6 |
7 | #hyperC OS#
8 |
9 | ## This repository provide a strip version, request a complete version
10 | http://socware.net/?page_id=300
11 |
12 | http://www.freelists.org/list/hypercos
13 |
14 | The hyperC OS is a real time-operating system (RTOS) designed for various IoT applications.
15 |
16 | While most of the commercial RTOSs focus on standards and features of general
17 | CPUs, the hyperCOS have narrowed down the scope of its design in order to build
18 | a solid and niche foundation for our software. All the designs are aimed at the
19 | optimization of ARM Cortex CPUs. The software architecture supports and utilizes
20 | the specific features of ARM Cortex CPUs, the Cortex-M, Cortex-R and Cortex-A series.
21 | It's the specialty on Cortex CPU that brings the competitive advantage over the others.
22 |
23 | The HyperCOS design disciplines are:
24 |
25 | * Optimizing over general
26 | * Simplifying over complex
27 |
28 | socware.help@gmail.com
29 |
30 |
31 |
--------------------------------------------------------------------------------
/bin/cfg-lib.sh:
--------------------------------------------------------------------------------
1 | function cfg_gcc
2 | {
3 | unset CLANG
4 | }
5 |
6 | function cfg_clang
7 | {
8 | eval `cat Makefile | grep TARGET.*= | sed -e 's/[: ]//g'`
9 | a=`which $TARGET-gcc`
10 | a=${a%/*}
11 | a=${a%/*}
12 | b=`find $a -name "string.h" | grep -v "sys"`
13 | b=${b%/*}
14 | export CLANG="clang -target $TARGET -I$b"
15 | export CC=$CLANG
16 | # echo CC=\"$CC\"
17 | }
18 |
19 | function cfg_v5t
20 | {
21 | export COPTS="-march=armv5t -msoft-float"
22 | echo "COPTS=$COPTS"
23 | }
24 |
25 | function cfg_v5tT
26 | {
27 | export COPTS="-march=armv5t -mthumb -msoft-float"
28 | echo "COPTS=$COPTS"
29 | }
30 |
31 | function cfg_v7aT
32 | {
33 | export COPTS="-march=armv7-a -mthumb -msoft-float"
34 | echo "COPTS=$COPTS"
35 | }
36 |
37 | function cfg_v7mTF_core
38 | {
39 | export COPTS="-march=armv7-m -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion"
40 | echo "COPTS=$COPTS"
41 | }
42 |
43 | function cfg_v7mTF
44 | {
45 | cfg_v7mTF_core
46 | export CONFIG="-DCFG_STACK_IRQ=0x4096 -DCFG_TICKLESS=0 -DCFG_OSUTIL=0 -DCFG_CACHE_VMSA=0 -DCFG_IRQ_VECTS=1"
47 | echo "CONFIG=\"-DCFG_STACK_IRQ=0x4096 -DCFG_TICKLESS=0 -DCFG_OSUTIL=0 -DCFG_CACHE_VMSA=0 -DCFG_IRQ_VECTS=1"
48 | }
49 |
50 | function cfg_v7mT_core
51 | {
52 | export COPTS="-march=armv7-m -mthumb -mfloat-abi=soft "
53 | echo "COPTS=$COPTS"
54 | }
55 |
56 | function cfg_v7mT
57 | {
58 | cfg_v7mT_core
59 | export CONFIG="-DCFG_STACK_IRQ=0x4096 -DCFG_TICKLESS=1 -DCFG_OSUTIL=0 -DCFG_CACHE_VMSA=0 -DCFG_IRQ_VECTS=1 -DCFG_HFLOAT=0"
60 | echo "CONFIG=\"-DCFG_STACK_IRQ=0x4096 -DCFG_TICKLESS=1 -DCFG_OSUTIL=0 -DCFG_CACHE_VMSA=0 -DCFG_IRQ_VECTS=1 -DCFG_HFLOAT=0"
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/bin/m-cfg.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo "#ifndef MCFG161688"
3 | echo "#define MCFG161688"
4 | for c in $@ ; do
5 | echo -n "#define "
6 | echo $c|sed -e 's/-D//g' -e 's/=/\t/g'
7 | done
8 | echo "#endif"
9 |
--------------------------------------------------------------------------------
/bin/m-fmt.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | function fmt
3 | {
4 | sed -e 's/^\t$//g' -i $1
5 | sed -e "s/[ \t]*$//g" -i $1
6 | t=$1
7 | t=${t##*.}
8 | if [ "$t" == "c" ]; then
9 | indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1 -il0 $1
10 | fi
11 | if [ "$t" == "h" ]; then
12 | if cat $1 | grep __ASSEMBLY__; then
13 | echo "skip $1"
14 | else
15 | indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1 -il0 $1
16 | fi
17 | fi
18 | }
19 |
20 | dir=$1
21 | if [ ! -d "$dir" ]; then
22 | echo "usage $0
"
23 | return
24 | fi
25 |
26 | for f in $(find $dir -name "*.[hHSc]") ; do
27 | sed -e 's/^\t$//g' -i $f
28 | sed -e "s/[ \t]*$//g" -i $f
29 | done
30 |
31 | for f in $(find $dir -name "*.ld") ; do
32 | sed -e 's/^\t$//g' -i $f
33 | sed -e "s/[ \t]*$//g" -i $f
34 | done
35 |
36 | for f in $(find $dir -name "*.[hHc]") ; do
37 | fmt $f
38 | done
39 |
--------------------------------------------------------------------------------
/include/clk-cpu.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) 2013 by SOCware Inc. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of SOCware, Inc.*/
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of SOCware, Inc. The source code is for FREE short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of SOCware, Inc. */
17 | /*- */
18 | /*- SOCWare, Inc. reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- socware.help@gmail.com */
22 | /*- http://socware.net */
23 | /*- */
24 | /*-****************************************************************************/
25 | #ifndef DVFS1705DD
26 | #define DVFS1705DD
27 |
28 | #include "clk.h"
29 |
30 | clk_t *clk_cpu_init(int cpu);
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/include/clk.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) 2013 by SOCware Inc. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of SOCware, Inc.*/
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of SOCware, Inc. The source code is for FREE short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of SOCware, Inc. */
17 | /*- */
18 | /*- SOCWare, Inc. reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- socware.help@gmail.com */
22 | /*- http://socware.net */
23 | /*- */
24 | /*-****************************************************************************/
25 | #ifndef CLK1605GG
26 | #define CLK1605GG
27 |
28 | #include "ll.h"
29 |
30 | typedef enum { CLK_EN, CLK_EN_POST, CLK_SETF, CLK_SETF_POST } clk_evt_t;
31 |
32 | struct clk;
33 |
34 | typedef struct clk clk_t;
35 |
36 | typedef struct clk_listener {
37 | void (*evt) (struct clk_listener * o, clk_t * clk, clk_evt_t type);
38 | lle_t ll;
39 | void *priv;
40 | } clk_listener_t;
41 |
42 | struct clk {
43 | char *name;
44 | clk_t *parent;
45 | ///< @return 0 on success
46 | int (*setf) (clk_t * o, int idx);
47 | ///< @return 0 on success
48 | int (*en) (clk_t * o, int enabled);
49 | int (*is_en) (clk_t * o);
50 | unsigned (*getf) (clk_t * o);
51 | ll_t listeners;
52 | void *priv;
53 | int idx;
54 | unsigned short freq_n;
55 | unsigned short *freq;
56 | unsigned short *pwr;
57 | };
58 |
59 | static inline int clk_setf(clk_t * o, int idx)
60 | {
61 | return o->setf(o, idx);
62 | }
63 |
64 | static inline int clk_en(clk_t * o, int enabled)
65 | {
66 | if (!o->en)
67 | return 0;
68 | return o->en(o, enabled);
69 | }
70 |
71 | static inline int clk_is_en(clk_t * o)
72 | {
73 | return !o->is_en || o->is_en(o);
74 | }
75 |
76 | static inline unsigned clk_getf(clk_t * o)
77 | {
78 | return o->getf(o);
79 | }
80 |
81 | static inline void clk_listen(clk_t * o, clk_listener_t * listener)
82 | {
83 | ll_addt(&o->listeners, &listener->ll);
84 | }
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/include/core.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef HTOS
28 | #define HTOS
29 |
30 | #include "ll.h"
31 | #include "cpu/reg.h"
32 | #include "cpu/_irq.h"
33 |
34 | extern ll_t core_gc_task;
35 |
36 | /// mandatory initialize before any APIs could be used
37 | void core_init(void);
38 |
39 | /// start the OS
40 | /// \note this function does not return
41 | void core_start(void);
42 |
43 | /// allocate memory block from the start heap
44 | /// \param sz
45 | /// \param align_bits number of bits the required memory should align to
46 | void *core_alloc(unsigned sz, int align_bits);
47 |
48 | #define _alloc(_sz) core_alloc(_sz, 3)
49 |
50 | typedef struct {
51 | unsigned *idles, idle_sz;
52 | unsigned idle, all;
53 | } core_ut_t;
54 |
55 | void core_ut_init(int sample_ticks);
56 |
57 | extern core_ut_t core_ut;
58 |
59 | extern void (*core_abt) (void *ctx);
60 |
61 | typedef struct core_idle {
62 | lle_t ll;
63 | void (*notify) (struct core_idle * o);
64 | void *priv;
65 | } core_idle_t;
66 |
67 | void core_idle_listen(core_idle_t * o);
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/include/cpu-arm/_cpu.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef CPU150822
28 | #define CPU150822
29 |
30 | #include "cfg.h"
31 | #include "reg.h"
32 |
33 | static inline void cpu_idle()
34 | {
35 | #if CFG_ASM_WFI
36 | asm volatile ("" asm_beg(r0) "wfi\n" asm_end(r0)
37 | :::"r0");
38 | #else
39 | asm volatile ("" asm_beg(r0) "mcr p15, 0, r0, c7, c0, 4\n" asm_end(r0)
40 | :::"r0");
41 | #if CFG_TICKLESS
42 | asm volatile (""
43 | asm_beg(r0)
44 | "1:\n"
45 | "ldr r0,=tmr_rtcs\n"
46 | "ldr r0, [r0]\n" "cmp r0, #0\n" "bne 1b\n" asm_end(r0)
47 | :::"r0");
48 | #endif
49 | #endif
50 |
51 | }
52 |
53 | void cpu_init(void);
54 |
55 | enum {
56 | _IRQ = 0x12,
57 | _SVC = 0x13,
58 | _ABT = 0x17,
59 | _MON = 0x16
60 | };
61 |
62 | /// \param mode cpu mode
63 | /// \param stack
64 | void cpu_set_stack(unsigned mode, void *stack);
65 |
66 | #define cpu_req_switch()
67 |
68 | static inline void cpu_abt()
69 | {
70 | *((volatile unsigned *)0xffffffff) = 1;
71 | }
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/include/cpu-arm/_irq.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef IRQ_CPU150313
28 | #define IRQ_CPU150313
29 |
30 | #include "asm.h"
31 |
32 | #ifdef __ASSEMBLY__
33 |
34 | .macro .irq_lock iflag, tmp
35 | mrs \iflag, cpsr
36 | orr \tmp, \iflag, #0x80
37 | msr cpsr, \tmp
38 | .endm
39 |
40 | .macro .irq_restore iflag
41 | msr cpsr, \iflag
42 | .endm
43 | #else
44 | #include "../dbg.h"
45 |
46 | #define irq_dep_chk(_exp) _assert(_exp)
47 |
48 | #define irq_act() irq_depth
49 |
50 | inline static void irq_restore(unsigned flag)
51 | {
52 | asm volatile(""
53 | asm_beg(r2)
54 | "msr cpsr, %0 \n"
55 | asm_end(r2)
56 | :
57 | :"r"(flag)
58 | :"r2", "memory");
59 | }
60 |
61 | #define _cpsr(_op, _msk) \
62 | { \
63 | unsigned ori, tmp; \
64 | asm volatile ("" \
65 | asm_beg(r2) \
66 | "mrs %0, cpsr\n" \
67 | #_op " %1, %0,"#_msk"\n" \
68 | "msr cpsr, %1\n" \
69 | asm_end(r2) \
70 | :"=r"(ori),"=r"(tmp) \
71 | : \
72 | :"memory","r2"); \
73 | return ori;\
74 | }
75 |
76 | /// lock IRQ, keep FIQ
77 | /// \return saved flag
78 | inline static unsigned irq_lock() _cpsr(orr, #0x80)
79 |
80 | inline static unsigned irq_unlock() _cpsr(bic, #0x80)
81 |
82 | /// lock IRQ & FIQ
83 | /// \return saved flag
84 | inline static unsigned irq_lock_all() _cpsr(orr, #0xc0)
85 |
86 | inline static unsigned irq_unlock_all() _cpsr(bic, #0xc0)
87 |
88 | typedef enum {
89 | IRQ_NA = 0x1ff,
90 | IRQ_DONE = 0x2ff
91 | } irq_sta_t;
92 |
93 | /// \return IRQ_DONE if irq_eoi has already been called
94 | typedef irq_sta_t (*irq_t) (unsigned irq, void *ctx, int depth);
95 |
96 | #define irq_handler(_name) \
97 | irq_sta_t _name (unsigned irq, void *reg_irq, int depth)
98 |
99 | #define irq_handler_decl(_name) \
100 | irq_handler(_name)
101 |
102 | #endif
103 | #endif
104 |
105 |
--------------------------------------------------------------------------------
/include/cpu-arm/_task.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef _TASK0418
28 | #define _TASK0418
29 |
30 | #define task_load(_t) _task_load((_t)->context)
31 |
32 | #define _task_switch_sync(_tn, _rc) _task_switch((_tn)->context, _rc)
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/include/cpu-arm/asm.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | ///
28 | /// \file asm.h
29 | /// \brief assembly macro supports arm mode in-line assembly
30 | ///
31 | #ifndef ASM150815
32 | #define ASM150815
33 |
34 | #include "../cfg.h"
35 |
36 | #if CFG_ASM_STUB
37 | #define asm_beg(_tmp) "adr " #_tmp ",1f\n" \
38 | "bx " #_tmp "\n" \
39 | ".code 32\n" \
40 | "1:\n"
41 | #define asm_end(_tmp) "adr " #_tmp ", 2f+1\n" \
42 | "bx " #_tmp "\n" \
43 | ".code 16\n" \
44 | "2:\n"
45 | #else
46 | #define asm_beg(_tmp) ""
47 |
48 | #define asm_end(_tmp) ""
49 | #endif
50 |
51 | #define asm_mb() asm volatile ("" ::: "memory")
52 |
53 | #ifdef __ASSEMBLY__
54 |
55 | #if CFG_ASM_UNIFY
56 | .macro .asm_syn
57 | .syntax unified
58 | .arch armv7-a
59 | #if CFG_HFLOAT
60 | .fpu vfp
61 | #else
62 | .fpu softvfp
63 | #endif
64 | .thumb
65 | .endm
66 |
67 | .macro .asm_fun name
68 | .global \name
69 | .thumb
70 | .thumb_func
71 | .type \name, %function
72 | .endm
73 | #else
74 | .macro .asm_syn
75 | .code 32
76 | .endm
77 |
78 | .macro .asm_fun name
79 | .global \name
80 | .type \name, %function
81 | .endm
82 | #endif
83 |
84 | #endif
85 |
86 | #endif
87 |
88 |
--------------------------------------------------------------------------------
/include/cpu-arm/cache-vmsa.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef VMSA150426
28 | #define VMSA150426
29 |
30 | #include "asm.h"
31 |
32 | typedef enum {
33 | CACHE_PERM_RO_RO = 0,
34 | CACHE_PERM_RW_NONE = 1,
35 | CACHE_PERM_RW_RO = 2,
36 | CACHE_PERM_RW_RW = 3,
37 | } cache_perm_t;
38 |
39 | void cache_init(void);
40 |
41 | /// \param pa physical address
42 | /// \param va virtual address
43 | /// \param c cache-able
44 | /// \param b buffer-able
45 | /// \param perm permission
46 | /// \param sz section size
47 | void cache_mmu_section(unsigned pa, unsigned va,
48 | unsigned c, unsigned b, cache_perm_t perm, unsigned sz);
49 |
50 | unsigned cache_mmu_on(void);
51 |
52 | static inline unsigned cache_mmu_off(void)
53 | {
54 | register unsigned ov, tmp;
55 | asm volatile (""
56 | asm_beg(r2)
57 | "mrc p15,0,%0,c1,c0,0 \n"
58 | "bic %1,%0,#1 \n"
59 | "mcr p15,0,%1,c1,c0,0 \n" asm_end(r2)
60 | :"=r"(ov), "=r"(tmp)
61 | ::"r2");
62 | return ov;
63 | }
64 |
65 | #endif
66 |
--------------------------------------------------------------------------------
/include/cpu-arm/cache.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef CACH150426
28 | #define CACH150426
29 |
30 | #include "../cfg.h"
31 |
32 | #if CFG_CACHE_VMSA
33 | #include "cache-vmsa.h"
34 | #else
35 | #include "cache-pmsa.h"
36 | #endif
37 |
38 | void cache_i_inv(unsigned sta, unsigned sz);
39 |
40 | void cache_d_flu(unsigned sta, unsigned sz);
41 |
42 | #define cache_i_inva() cache_i_inv(-1, -1)
43 |
44 | #define cache_d_flua() cache_d_flu(-1, -1)
45 |
46 | #endif
47 |
--------------------------------------------------------------------------------
/include/cpu-arm/gic.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef GIC150303
28 | #define GIC150303
29 |
30 | #include "../io.h"
31 |
32 | #define DIST_ENABLE_SET 0x100
33 | #define DIST_ENABLE_CLEAR 0x180
34 |
35 | extern unsigned gic_dist_base, gic_cpu_base;
36 |
37 | void gic_init(unsigned dist_base, unsigned cpu_base);
38 |
39 | int gic_set_type(unsigned irq, int is_level);
40 |
41 | /// set an IRQ for none-secure world to use
42 | void gic_set_ns(int irq, int ns);
43 |
44 | static inline unsigned gic_irq_mask(unsigned irq)
45 | {
46 | unsigned en, reg, msk;
47 |
48 | msk = 1 << (irq & 0x1f);
49 | reg = gic_dist_base + DIST_ENABLE_CLEAR + ((irq >> 5) << 2);
50 | en = readl(reg) & msk;
51 | writel(msk, (void *)reg);
52 | return en ? 1 : 0;
53 | }
54 |
55 | static inline void gic_irq_unmask(unsigned irq)
56 | {
57 | unsigned mask = 1 << (irq & 0x1f);
58 | writel(mask,
59 | (void *)(gic_dist_base + DIST_ENABLE_SET + ((irq >> 5) << 2)));
60 | }
61 |
62 | static inline unsigned gic_get_irq()
63 | {
64 | unsigned b, v;
65 | b = (gic_cpu_base + 0xc);
66 | v = readl(b) & 0x1ff;
67 | return v == 0x1ff ? 0xffffffff : v;
68 | }
69 |
70 | static inline void gic_eoi(unsigned irq)
71 | {
72 | unsigned b = (gic_cpu_base + 0x10);
73 | writel(irq, (void *)b);
74 | }
75 |
76 | static inline void gic_sgi(int id)
77 | {
78 | unsigned v = id | (0x2 << 24);
79 | writel(v, (void *)gic_dist_base + 0xF00);
80 | }
81 |
82 | #endif
83 |
--------------------------------------------------------------------------------
/include/cpu-arm/hyper.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef HYPER150811
28 | #define HYPER150811
29 |
30 | #include "cfg.h"
31 |
32 | /// start a thread to start none-secure world
33 | /// \param ns_ints an array containing all none-secure IRQs, 0 ended
34 | /// \param sta_addr none-secure world boot address
35 | void hyper_boot_ns(unsigned *ns_ints, unsigned sta_addr);
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/include/cpu-arm/reg.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef REG150313
28 | #define REG150313
29 |
30 | #include "cfg.h"
31 |
32 | typedef struct reg {
33 | unsigned r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12;
34 | unsigned lr;
35 | #if CFG_ASM_RFE
36 | unsigned pc, cpsr;
37 | #else
38 | unsigned cpsr, pc;
39 | #endif
40 | } reg_t;
41 |
42 | typedef struct {
43 | unsigned r0, r1, r2, r3, r12;
44 | #if CFG_ASM_RFE
45 | unsigned pc, cpsr;
46 | #else
47 | unsigned cpsr, pc;
48 | #endif
49 | } reg_irq_t;
50 |
51 | typedef struct {
52 | unsigned r0, r1, r2, r3;
53 | #if CFG_ASM_RFE
54 | unsigned pc, cpsr;
55 | #else
56 | unsigned cpsr, pc;
57 | #endif
58 | } reg_fiq_t;
59 |
60 | #define REG_FIQ_T_DEF
61 |
62 | /// skip one instruction in context
63 | static inline void reg_skip(reg_t * context, int off)
64 | {
65 | context->pc += off;
66 | context->pc += 4;
67 | context->pc -= 2 * ((context->cpsr >> 5) & 0x1);
68 | }
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/include/cpu-armm/_cpu.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef CPU150822
28 | #define CPU150822
29 |
30 | #include "cfg.h"
31 | #include "reg.h"
32 | #include "asm.h"
33 | #include "../dbg.h"
34 | #include "../io.h"
35 |
36 | static inline void cpu_idle()
37 | {
38 | asm volatile ("wfi":::"r0");
39 | }
40 |
41 | static inline void cpu_stick_init(unsigned ticks)
42 | {
43 | reg(STICK + 0x4) = ticks - 1;
44 | reg(STICK + 0x8) = 0;
45 | reg(STICK + 0x0) = 0x7;
46 | // [2]internal-src| [1]enable-int| [0]kick-off
47 | }
48 |
49 | static inline unsigned cpu_stick_read()
50 | {
51 | return readl(STICK + 0x8);
52 | }
53 |
54 | static inline void cpu_stick_en(unsigned on)
55 | {
56 | reg(STICK + 0x0) = on ? 0x7 : 0x4;
57 | }
58 |
59 | static inline void cpu_req_switch()
60 | {
61 | reg(ICSR) |= (1 << 28);
62 | asm_mb();
63 | }
64 |
65 | static inline unsigned cpu_fpu_sta()
66 | {
67 | return reg(CPACR) & (0xF << 20);
68 | }
69 |
70 | static inline void cpu_fpu_en(unsigned sta)
71 | {
72 | reg(CPACR) &= ~(0xF << 20);
73 | reg(CPACR) |= (sta << 20);
74 | asm_mb();
75 | }
76 |
77 | #define cpu_fpu_on() cpu_fpu_en(0xF)
78 |
79 | typedef enum {
80 | E_NMI = 2,
81 | E_HARD = 3,
82 | E_MEM = 4,
83 | E_BUS = 5,
84 | E_USE = 6,
85 | E_SVC = 11,
86 | E_PENDSV = 14,
87 | E_STICK = 15,
88 | E_INT = 16,
89 | } cpu_exc_t;
90 |
91 | extern unsigned cpu_pbits;
92 |
93 | #define cpu_pri_max() ((1<> 5) * 4) = (1 << (irq & 0x1f));
50 | return reg(ISER + (irq >> 5) * 4) & (1 << (irq & 0x1f));
51 | }
52 |
53 | static inline void nvic_irq_unmask(unsigned irq)
54 | {
55 | reg(ISER + (irq >> 5) * 4) = (1 << (irq & 0x1f));
56 | }
57 |
58 | static inline void nvic_set_pri(unsigned irq, unsigned pri)
59 | {
60 | void *b = (void *)(IPR + (irq));
61 | writeb((pri << cpu_pbits) & 0xff, b);
62 | }
63 |
64 | static inline void nvic_sgi(int id)
65 | {
66 | reg(STIR) = id;
67 | }
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/include/cpu-armm/reg.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef REG150313
28 | #define REG150313
29 |
30 | #include "cfg.h"
31 |
32 | enum {
33 | ICSR = 0xE000ED04,
34 | VTOR = 0xE000ED08,
35 | STICK = 0xE000E010,
36 | CCR = 0xE000ED14,
37 | SHPR = 0xE000ED18,
38 | CFSR = 0xE000ED28,
39 | CPACR = 0xE000ED88,
40 | FPCCR = 0xE000EF34,
41 | FPCAR = 0xE000EF38,
42 | };
43 |
44 | typedef struct reg_irq {
45 | unsigned r0, r1, r2, r3, r12;
46 | unsigned lr;
47 | unsigned pc, cpsr;
48 | } reg_irq_t;
49 |
50 | typedef struct {
51 | unsigned fpscr[2];
52 | unsigned s[16];
53 | } reg_fhard_t;
54 |
55 | typedef struct {
56 | unsigned sh[16];
57 | reg_fhard_t h;
58 | } reg_f_t;
59 |
60 | typedef struct reg {
61 | unsigned eret;
62 | unsigned r4, r5, r6, r7, r8, r9, r10, r11;
63 | unsigned r0, r1, r2, r3, r12;
64 | unsigned lr;
65 | unsigned pc, cpsr;
66 | } reg_t;
67 |
68 | static inline void reg_skip(reg_t * context, int off)
69 | {
70 | context->pc += 2;
71 | }
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/include/cpu.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef CPU150325
28 | #define CPU150325
29 |
30 | /// provided by cpu specific code and is called by OS core
31 | /// \param t
32 | /// \param the call back after the t->ent exits
33 | /// reg_t* _cpu_task_init(struct task* t, void* priv, void* dest);
34 |
35 | /// \return return current pc address
36 | void *cpu_cur_pc();
37 |
38 | /// the CPU register names
39 | extern char *cpu_reg_names[];
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/include/dbg.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef DBG150308
28 | #define DBG150308
29 |
30 | #include "cfg.h"
31 | #include "cpu.h"
32 |
33 | struct task;
34 | struct reg;
35 |
36 | #if CFG_ASSERT == 1
37 | #define _assert(_exp) if(!(_exp)) _fail(cpu_cur_pc(),0,__LINE__)
38 | #elif CFG_ASSERT == 2
39 | #define _assert(_exp) if(!(_exp)) _fail(cpu_cur_pc(),__FILE__,__LINE__)
40 | #else
41 | #define _assert(_exp)
42 | #endif
43 |
44 | #define _test(_exp) if(!(_exp)) _fail(cpu_cur_pc(),__FILE__,__LINE__)
45 |
46 | int _printf(const char *fmt, ...);
47 |
48 | #if _DBG
49 | #define dbg(_fmt, _args...) _printf(_fmt , ##_args)
50 | #else
51 | #define dbg(_fmt, __args...)
52 | #endif
53 |
54 | /// provided by APP and is called by OS on fatal error
55 | /// \param addr failure address
56 | /// \param f source file name
57 | /// \param line source line number
58 | void _fail(void *addr, const char *f, unsigned line);
59 |
60 | /// provided by APP and is called when main exits
61 | /// \param the return code
62 | void _exit(int);
63 |
64 | /// provided by APP and is called by OS on CPU hardware abort
65 | void _abt(void *ctx);
66 |
67 | /// provided by APP and is called by OS when stack overflow is detected
68 | void _stackov(struct task *t);
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/include/io.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef IO150303
28 | #define IO150303
29 |
30 | #define BI_TMSK(_n) ((1U<<(_n))-1)
31 |
32 | #define BI_FMSK(_ms,_ls) (BI_TMSK((_ms)-(_ls)+1)<<(_ls))
33 |
34 | #define BI_BMSK(_n) (1U << (_n))
35 |
36 | #define BI_WID(_ms,_ls) ((_ms)-(_ls)+1)
37 |
38 | #define BI_ALN(_i, _n) ((_i) & ~BI_TMSK(_n))
39 |
40 | #define BI_RUP(_i, _n) BI_ALN((_i)+BI_TMSK(_n), _n)
41 |
42 | #define BI_TRU(_i, _n) ((_i) & BI_TMSK(_n))
43 |
44 | #define BI_G_FLD(_i,_ms,_ls) \
45 | (((_i)<<(31-(_ms))) >> (31- (_ms) + (_ls)))
46 |
47 | #define BI_O_FLD(_i,_ms,_ls,_v) \
48 | ((_i)|((BI_TRU(_v,BI_WID(_ms,_ls))<<(_ls))))
49 |
50 | #define BI_C_FLD(_i,_ms,_ls) ((_i) & ~BI_FMSK(_ms,_ls))
51 |
52 | #define BI_R_FLD(_i,_ms,_ls,_v) \
53 | ((((_i)&~BI_FMSK(_ms,_ls)))|((BI_TRU(_v,BI_WID(_ms,_ls))<<(_ls))))
54 |
55 | #define BI_G_BIT(_i,_n) BI_G_FLD(_i, _n, _n)
56 |
57 | #define BI_O_BIT(_i,_n) ((_i) |(1 << (_n)))
58 |
59 | #define BI_Z_BIT(_i,_n) ((_i) & ~BI_BMSK(_n))
60 |
61 | #define BI_R_BIT(_i,_n,_v) \
62 | (((_i)&~BI_BMSK(_n))|(((_v)&0x1)<<(_n)))
63 |
64 | static inline void writel(unsigned v, void *a)
65 | {
66 | (*((volatile unsigned *)(a)) = (v));
67 | }
68 |
69 | #define readl(_a) _readl((void*)(_a))
70 |
71 | static inline unsigned _readl(void *a)
72 | {
73 | return *((volatile unsigned *)(a));
74 | }
75 |
76 | static inline void writew(unsigned v, void *a)
77 | {
78 | (*((volatile unsigned short *)(a)) = (v));
79 | }
80 |
81 | #define readw(_a) _readw((void*)(_a))
82 |
83 | static inline unsigned _readw(void *a)
84 | {
85 | return *((volatile unsigned short *)(a));
86 | }
87 |
88 | static inline void writeb(unsigned v, void *a)
89 | {
90 | (*((volatile unsigned char *)(a)) = (v));
91 | }
92 |
93 | #define readb(_a) _readb((void*)(_a))
94 |
95 | static inline unsigned _readb(void *a)
96 | {
97 | return *((volatile unsigned char *)(a));
98 | }
99 |
100 | #define reg(_a) *((volatile unsigned*)(_a))
101 |
102 | #define regb(_a) *((volatile unsigned char*)(_a))
103 |
104 | #define regh(_a) *((volatile unsigned short*)(_a))
105 |
106 | #endif
107 |
--------------------------------------------------------------------------------
/include/irq.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef IRQ150303
28 | #define IRQ150303
29 |
30 | #include "cfg.h"
31 | #include "cpu/_irq.h"
32 |
33 | /// the irq vector
34 | extern irq_t *irqs;
35 |
36 | /// number of IRQs after bootup
37 | extern volatile unsigned irq_cnt;
38 |
39 | /// the nested depth of IRQ
40 | extern volatile unsigned irq_depth;
41 |
42 | void irq_init(unsigned irq, irq_t f);
43 |
44 | void irq_dest(unsigned irq);
45 |
46 | void irq_bind(unsigned irq, void *data);
47 |
48 | void *irq_data(void);
49 |
50 | /// @return the active irq number or IRQ_NA
51 | int irq_actn();
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/include/ll.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef LL0320
28 | #define LL0320
29 |
30 | /// linked list entry
31 | typedef struct lle {
32 | struct lle *n, *p;
33 | } lle_t;
34 |
35 | #define LLE_INIT(le) {&le, &le}
36 |
37 | inline static void lle_init(lle_t * le)
38 | {
39 | le->n = le->p = le;
40 | }
41 |
42 | inline static char *_lle_get(lle_t * le)
43 | {
44 | return (char *)le;
45 | }
46 |
47 | #define lle_get(l, type, mem) \
48 | ((type *)(_lle_get(l)-(unsigned)(&((type *)0)->mem)))
49 |
50 | inline static void lle_add_before(lle_t * le, lle_t * newe)
51 | {
52 | lle_t *t = le->n;
53 |
54 | le->n = newe;
55 | le->p = newe;
56 | newe->n = t;
57 | newe->p = le;
58 | }
59 |
60 | inline static void lle_del(lle_t * le)
61 | {
62 | le->p->n = le->n;
63 | le->n->p = le->p;
64 | le->n = le->p = le;
65 | }
66 |
67 | /// linked list head
68 | typedef struct ll {
69 | lle_t *n, *p;
70 | } ll_t;
71 |
72 | #define LL_INIT(le) {(void*)&le, (void*)&le}
73 |
74 | #define ll_dec(_l) ll_t _l = {(void*)&_l, (void*)&_l};
75 |
76 | #define ll_for_each(_ll, _lle) \
77 | for((_lle) = ll_head(_ll);(_lle) != (void*)(_ll); (_lle) = (_lle)->n)
78 |
79 | #define ll_for_each_mod(_ll, _lle, _tmp) \
80 | for((_lle) = ll_head(_ll);(_lle) != (void*)(_ll) && ((_tmp)=(_lle)->n);(_lle) = (_tmp))
81 |
82 | inline static void ll_init(ll_t * l)
83 | {
84 | l->n = (void *)l;
85 | l->p = (void *)l;
86 | }
87 |
88 | #define ll_empty(_l) ((_l)->n == (void*)(_l))
89 |
90 | inline static void ll_addh(ll_t * l, lle_t * newe)
91 | {
92 | lle_t *p = l->p;
93 |
94 | p->n = newe;
95 | l->p = newe;
96 | newe->p = p;
97 | newe->n = (void *)l;
98 | }
99 |
100 | inline static void ll_addt(ll_t * l, lle_t * newe)
101 | {
102 | lle_t *t = l->n;
103 |
104 | l->n = newe;
105 | t->p = newe;
106 | newe->n = t;
107 | newe->p = (void *)l;
108 | }
109 |
110 | inline static lle_t *ll_head(ll_t * l)
111 | {
112 | return l->n;
113 | }
114 |
115 | #endif
116 |
--------------------------------------------------------------------------------
/include/mq.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef MQ150313
28 | #define MQ150313
29 |
30 | #include "wait.h"
31 | #include "ll.h"
32 |
33 | typedef struct {
34 | char *b, *h, *t;
35 | short bsz; ///< size of the whole buffer
36 | short isz; ///< bytes in a msg
37 | short sz; ///< max msgs
38 | short n; ///< current enqueued msgs
39 | ll_t waitp; ///< wait queue for put
40 | ll_t waitg; ///< wait queue for get
41 | } mq_t;
42 |
43 | /// \param no_words number of words within a single message
44 | mq_t *mq_init(mq_t * m, int no_words, unsigned *buf, int buf_sz);
45 |
46 | /// \return 0 on success
47 | int mq_get(mq_t * m, unsigned *msg, wait_t w);
48 |
49 | int mq_peek(mq_t * m, unsigned *msg, wait_t w);
50 |
51 | /// \note support irq context
52 | /// \return 0 on success
53 | int mq_put(mq_t * m, unsigned *msg, wait_t w);
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/include/mut.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef MUT150429
28 | #define MUT150429
29 |
30 | #include "wait.h"
31 | #include "ll.h"
32 | #include "task.h"
33 |
34 | typedef struct {
35 | int val; ///< 0:unlock, 1+:lock
36 | task_t *own; ///< owner thread
37 | ll_t wait; ///< wait queue
38 | short own_pri; ///< owner thread original priority
39 | short dummy;
40 | } mut_t;
41 |
42 | mut_t *mut_init(mut_t * u);
43 |
44 | /// \return 0 on success
45 | int mut_lock(mut_t * u, wait_t w);
46 |
47 | /// \note **NOT** support irq context
48 | void mut_unlock(mut_t * u);
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/include/sem.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef SEM150313
28 | #define SEM150313
29 |
30 | #include "wait.h"
31 | #include "ll.h"
32 | #include "cfg.h"
33 |
34 | typedef struct {
35 | int val;
36 | ll_t wait;
37 | } sem_t;
38 |
39 | /// \param init_val the initial value of the semaphore
40 | sem_t *sem_init(sem_t * s, int init_val);
41 |
42 | /// \return 0 on success
43 | int sem_get(sem_t * s, wait_t w);
44 |
45 | /// \note support irq context
46 | int sem_post_n(sem_t * s, int n);
47 |
48 | int sem_post(sem_t * s);
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/include/soc.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef SOC150408
28 | #define SOC150408
29 |
30 | #include "irq.h"
31 |
32 | /// APIs provided by SOC back-end and called by OS
33 |
34 | unsigned irq_mask(unsigned irq);
35 |
36 | void irq_unmask(unsigned irq);
37 |
38 | /// \param is_level 0:level triggered, 1:edge triggered
39 | void irq_cfg(unsigned irq, int is_level);
40 |
41 | /// \return irq number or IRQ_NA
42 | irq_sta_t irq_ack(void);
43 |
44 | #ifndef irq_eoi
45 | /// end of interrupt
46 | void irq_eoi(unsigned irq);
47 | #endif
48 |
49 | /// trigger software interrupt
50 | void irq_sgi(unsigned irq);
51 |
52 | /// initial a hardware timer to trigger interrupt periodically
53 | /// provided by SOC back-end and called by OS
54 | /// \param [output] log2(rtcs_freq/tick_freq)
55 | /// \param [output] hz
56 | /// \return timer irq
57 | int tmr_init_soc(unsigned *rtcs2tick, unsigned *hz);
58 |
59 | /// \return get the Real Time Counter value
60 | unsigned soc_rtcs();
61 |
62 | /// \return return the freq of high resolution ticks
63 | unsigned soc_hrt_init(void);
64 |
65 | /// \return return high resolution ticks
66 | unsigned soc_hrt(void);
67 |
68 | /// \param next_expire left ticks to the next timer event
69 | /// \note the implementation may set wake up time less than
70 | void tmr_tickless_soc(unsigned next_expire);
71 |
72 | void tmr_enable(int on);
73 |
74 | void soc_idle(int next_expire);
75 |
76 | void soc_init(void);
77 |
78 | unsigned dbm_irq(void);
79 |
80 | int _dbm_get(void);
81 |
82 | void dbm_put(char c);
83 |
84 | void udelay(int us);
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/include/task.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef TASK150313
28 | #define TASK150313
29 |
30 | #include "cfg.h"
31 | #include "ll.h"
32 | #include "wait.h"
33 | #include "tmr.h"
34 | #include "core.h"
35 | #include "irq.h"
36 | #include "dbg.h"
37 | #include "cpu/reg.h"
38 | #include "cpu/_cpu.h"
39 |
40 | typedef void (*task_ent) (void *priv);
41 |
42 | typedef enum {
43 | TASK_READY,
44 | TASK_WAIT,
45 | TASK_DEST,
46 | } task_status_t;
47 |
48 | typedef struct task {
49 | task_ent ent; ///< thread function
50 | const char *name;
51 | unsigned *stack;
52 | int stack_sz; ///< stack size requirements in bytes
53 | short slice; ///< initial timeslice
54 | short slice_cur; ///< available time slice before yield
55 | void *priv;
56 | lle_t ll;
57 | reg_t *context;
58 | tmr_t to;
59 | char status; ///< task_status_t
60 | char tm_out;
61 | short pri; ///< initial thread priority
62 | unsigned sch;
63 | unsigned ut;
64 | } task_t;
65 |
66 | extern void (*task_gc) (task_t * t);
67 |
68 | /// \arg pri, 1~ (CFG_TPRI_NUM-1), less value has higher priority, 0 is invalid
69 | /// \arg slice, -1 for no time-slice
70 | task_t *task_init(task_t * t,
71 | const char *name,
72 | task_ent e,
73 | int pri,
74 | unsigned *stack, int stack_sz, int slice, void *priv);
75 |
76 | #define task_new(_n,_e,_p,_sz,_sl,_pr) \
77 | task_init(_alloc(sizeof(task_t)), _n, _e, _p, _alloc(_sz), _sz, _sl, _pr)
78 |
79 | void _task_dest();
80 |
81 | extern task_t *_task_cur, *_task_pend;
82 |
83 | /// requirecritical section protection
84 | /// \return -1 on timeout
85 | int task_suspend(ll_t * wq, wait_t w);
86 |
87 | /// \param w sleep ticks
88 | void task_sleep(wait_t w);
89 |
90 | void _task_pri(task_t * t, short pri);
91 |
92 | /// \param t task
93 | /// \param pri priority
94 | void task_pri(task_t * t, short pri);
95 |
96 | /// \param hint notify the scheduler to bypass thread with
97 | /// priority higher than hint
98 | void sch_schedule(unsigned hint);
99 |
100 | static inline void task_pri_self(short pri)
101 | {
102 | task_t *t = _task_cur;
103 | short opri = t->pri;
104 | t->pri = pri;
105 | if (pri > opri)
106 | sch_schedule(opri);
107 | }
108 |
109 | /// \param yield the control to threads with the same priority
110 | static inline void task_yield()
111 | {
112 | sch_schedule(_task_cur->pri);
113 | }
114 |
115 | int _task_wakeq(ll_t * wq, unsigned iflag);
116 |
117 | static inline void task_wakeq(ll_t * wq)
118 | {
119 | unsigned iflag = irq_lock();
120 | _task_wakeq(wq, iflag);
121 | }
122 |
123 | void _task_load(reg_t * reg_next);
124 |
125 | void _task_switch(reg_t * reg_next, reg_t ** reg_cur);
126 |
127 | void _task_switch_pend(task_t * tn);
128 |
129 | /// \return pointer to original context
130 | reg_t **_task_switch_status(task_t * tn);
131 |
132 | extern void (*task_ov) (task_t * t);
133 |
134 | #include "cpu/_task.h"
135 |
136 | #endif
137 |
--------------------------------------------------------------------------------
/include/tmr.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef TIMER150423
28 | #define TIMER150423
29 |
30 | #include "ll.h"
31 | #include "irq.h"
32 |
33 | typedef int (*tmr_do) (void *p);
34 |
35 | typedef struct {
36 | lle_t ll;
37 | tmr_do f;
38 | void *p;
39 | unsigned expire;
40 | unsigned irq_mode;
41 | } tmr_t;
42 |
43 | /// total ticks since boot up
44 | extern unsigned tmr_ticks, tmr_hz;
45 |
46 | /// timer irq number
47 | extern unsigned tmr_irq;
48 |
49 | /// log2(rtcs_freq/tick_freq)
50 | extern unsigned tmr_rtcs2tick;
51 |
52 | tmr_t *tmr_init(tmr_t * t, void *p, tmr_do f);
53 |
54 | void _tmr_on(tmr_t * t, unsigned expire, unsigned irq_mode);
55 |
56 | static inline void tmr_on(tmr_t * t, unsigned expire)
57 | {
58 | _tmr_on(t, expire, 0);
59 | }
60 |
61 | static inline void tmr_on_irq(tmr_t * t, unsigned expire)
62 | {
63 | _tmr_on(t, expire, 1);
64 | }
65 |
66 | static inline void _tmr_of(tmr_t * t)
67 | {
68 | lle_del(&t->ll);
69 | }
70 |
71 | static inline void tmr_of(tmr_t * t)
72 | {
73 | unsigned iflag = irq_lock();
74 | _tmr_of(t);
75 | irq_restore(iflag);
76 | }
77 |
78 | static inline int tmr_active(tmr_t * t)
79 | {
80 | return t->ll.n != t->ll.p;
81 | }
82 |
83 | irq_handler_decl(_tmr_tickf);
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/include/wait.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef WAIT150313
28 | #define WAIT150313
29 |
30 | typedef unsigned wait_t;
31 |
32 | enum {
33 | WAIT_NO = 0,
34 | WAIT = 0xffffffff,
35 | };
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/share/Makefile.rule:
--------------------------------------------------------------------------------
1 | GCC :=$(CROSS)gcc
2 | LD :=$(CROSS)ld
3 | ifeq ($(CLANG),)
4 | CC :=$(GCC)
5 | endif
6 | CXX :=$(CROSS)g++
7 | OBJDUMP:=$(CROSS)objdump
8 | OBJCOPY:=$(CROSS)objcopy
9 | AR :=$(CROSS)ar
10 | NM :=$(CROSS)nm
11 |
12 | COBJ?=$(patsubst %.c,%.o, \
13 | $(patsubst %.cpp, %.o, \
14 | $(notdir $(foreach DIR,$(VPATH),\
15 | $(wildcard $(DIR)/*.c) \
16 | $(wildcard $(DIR)/*.cpp)))))
17 | DEP :=$(COBJ:%.o=%.d)
18 |
19 | %.d:%.cpp
20 | @$(CC) -M $(INCLUDE) -D _UNIT_ -D _EXE_ $(CXXFLAGS) $< > $@
21 |
22 | %.d:%.c
23 | @$(CC) -M $(INCLUDE) -D _UNIT_ -D _EXE_ $(CFLAGS) $< > $@
24 |
25 | %.e:%.cpp %.d
26 | $(CXX) $(CXXFLAGS) $(INCLUDE) $(CONFIG) -E $< > $(notdir $(<:%.cpp=%.e.cpp))
27 |
28 | %.e:%.c %.d
29 | $(CC) $(CFLAGS) $(INCLUDE) -E $< > $(notdir $(<:%.c=%.e.c))
30 |
31 | %.o:%.cpp %.d
32 | $(CXX) $(CXXFLAGS) $(INCLUDE) -c $<
33 |
34 | %.o:%.c %.d
35 | $(CC) $(CFLAGS) $(INCLUDE) -c $<
36 |
37 | %.o:%.S
38 | $(GCC) $(ASFLAGS) $(INCLUDE) $(CONFIG) -c $<
39 |
40 | %.o:%.s
41 | $(GCC) $(ASFLAGS) $(INCLUDE) $(CONFIG) -c -x assembler-with-cpp $<
42 |
43 | %.o.text:%.o
44 | $(CROSS)objdump -dS $^ > $@
45 |
46 | %.o.img:%.o
47 | $(OBJCOPY) --strip-debug --strip-unneeded $^ $@
48 |
49 | %.o.mod:%.o
50 | $(LD) -r -T$(MSCRIPT) -o$@ $^
51 |
52 | %.o.mod.img:%.o.mod
53 | $(OBJCOPY) --strip-debug --strip-unneeded $^ $@
54 |
55 | %.o.bin:%.o.img
56 | $(OBJCOPY) -O binary $^ $@
57 |
58 | %.elf:%.c $(LIB)
59 | $(CC) $(CFLAGS) $(INCLUDE) -D _EXE_ -o $(notdir $(<:%.c=%.e.o)) -c $<
60 | $(CC) -o $@ $(notdir $(<:%.c=%.e.o)) $(LDFLAGS)
61 |
62 | %.elf:%.cpp $(LIB)
63 | $(CC) $(CXXFLAGS) $(INCLUDE) $(CONFIG) -D _EXE_ -o $(notdir $(<:%.cpp=%.e.o)) -c $<
64 | $(CC) -o $@ $(notdir $(<:%.cpp=%.e.o)) $(LDFLAGS)
65 |
66 | %.elf.run:
67 | @echo ""
68 | @printf "%s%-8s%s\n" "-----[ " "$(@:%.elf.run=%)" " ]------------------------------------------------------"
69 | @echo ""
70 | $(RUN)$(@:%.elf.run=%.elf)
71 |
72 | %.elf.debug:%.elf
73 | ddd --debugger $(CROSS)gdb $^
74 |
75 | %.elf.text:%.elf
76 | $(CROSS)objdump -dS $^ > $@
77 |
78 | %.elf.img:%.elf
79 | $(OBJCOPY) --strip-debug $^ $@
80 |
81 | %.elf.bin:%.elf.img
82 | $(OBJCOPY) -O binary $^ $@
83 |
84 | %.elf.sym:%.elf.img
85 | $(NM) $^ | sed -e '/ [wtbdaV] /d' -e 's/.*[WBTDRA] //g' >$@
86 |
87 | %.elf.sym.src:%.elf.sym
88 | $(PREFIX)/bin/m-gen-msym-src.sh $^ > $@
89 |
90 | %.elf.sym.o:%.elf.sym.src
91 | @cp $^ ${^:%.src=%.c}
92 | $(CC) $(CFLAGS) $(INCLUDE) -c ${^:%.src=%.c};
93 | @rm ${^:%.src=%.c}
94 |
95 | %.elf.pack:%.o $(LIB) %.elf.sym.o
96 | $(CC) -o $@ $(notdir $(<:%.o=%.e.o)) $(notdir $(<:%.o=%.elf.sym.o)) $(LDFLAGS)
97 |
98 | %.x:%.c $(LIB)
99 | $(CC) $(CFLAGS) $(INCLUDE) -D _UNIT_ -o $(notdir $(<:%.c=%.x.o)) -c $<
100 | $(CROSS)nm $(notdir $(<:%.c=%.x.o)) | grep main
101 | $(CC) -o $@ $(notdir $(<:%.c=%.x.o)) $(LDFLAGS)
102 |
103 | %.x:%.cpp $(LIB)
104 | $(CC) $(CXXFLAGS) $(INCLUDE) $(CONFIG) -D _UNIT_ -o $(notdir $(<:%.cpp=%.x.o)) -c $<
105 | $(CXX) -o $@ $(notdir $(<:%.cpp=%.x.o)) $(LDFLAGS)
106 |
107 | %.x.run:
108 | @echo ""
109 | @printf "%s%-8s%s\n" "-----[ " "$(@:%.x.run=%)" " ]------------------------------------------------------"
110 | @echo ""
111 | $(RUN)$(@:%.x.run=%.x)
112 |
113 | %.x.text:%.x
114 | $(CROSS)objdump -dS $^ > $@
115 |
116 | %.x.img:%.x
117 | $(OBJCOPY) --strip-debug $< $@
118 |
119 | %.x.bin:%.x.img
120 | $(OBJCOPY) -O binary $< $@
121 |
122 | sinclude $(DEP)
123 |
124 | lib$(NAME).a:$(VOBJ)
125 | $(AR) r $@ $?
126 |
127 | .PHONY:all install lib clean indent
128 | all: $(ALL)
129 | @echo
130 |
131 | install:
132 | install -d $(PREFIX)/bin $(PREFIX)/lib $(PREFIX)/include/$(NAME) $(PREFIX)/doc $(PREFIX)/share
133 | install -Dp $(LIB) $(PREFIX)/lib/
134 | install -Dp include/*.h $(PREFIX)/include/$(NAME)/;echo -n ""
135 | find -name "*.[hcS]" > $(PREFIX)/doc/$(NAME).files
136 | find -name "*.cpp" >> $(PREFIX)/doc/$(NAME).files
137 | sed -e 's/^\./$(shell pwd|sed -e 's/\//\\\//g')/g' -i $(PREFIX)/doc/$(NAME).files
138 | install -Dp bin/* $(PREFIX)/bin ;echo -n ""
139 | install -Dp share/* $(PREFIX)/share;echo -n ""
140 |
141 | lib:$(LIB)
142 | @echo "[lib ] done"
143 |
144 | clean:$(CLEAN)
145 | rm -f `find -name "*~"`
146 | rm -f include/conf_$(NAME).h *.*log *.o *.so *.files *.a *.x *.lib *.def *.dll *.elf* *.d *.text *.img *.srec *.bin *.hex *.short *.hex8 *.mod *.pack
147 | rm -rf index
148 |
149 | indent:
150 | indent -kr -i8 `find -name "*.[h,c]"`
151 |
152 | CSCOPE=$(wildcard $(PREFIX)/doc/*.files)
153 | cscope.out:install $(CSCOPE)
154 | cat $(CSCOPE) > all.files
155 | cscope -b -c -iall.files
156 |
157 |
--------------------------------------------------------------------------------
/src-hello/Makefile:
--------------------------------------------------------------------------------
1 | NAME :=hello
2 | TARGET :=arm-none-eabi
3 | CROSS :=$(TARGET)-
4 | PREFIX ?=$(shell pwd)/../../prefix/$(CROSS:%-=%)#TEMPLATE
5 | SOC ?=soc-sim
6 | CPU :=arm
7 | INCLUDE:=-Iinclude -I$(PREFIX)/include/$(SOC) -I$(PREFIX)/include
8 | COPTS ?=-march=armv7-a -mthumb
9 | AARCH :=$(shell echo $(COPTS) | sed -e 's/.*armv\([0-9]\).*/\1/g')
10 | MOPTS :=$(COPTS) \
11 | -DCFG_AARCH=$(AARCH) \
12 | -fno-builtin -fno-common \
13 | -ffunction-sections -fdata-sections -fshort-enums
14 | CONFIG ?=
15 | ASFLAGS:=$(MOPTS) $(CONFIG) -O2 -g -Wall -Werror -D __ASSEMBLY__
16 | CFLAGS :=$(MOPTS) $(CONFIG) -O2 -g -Wall -Werror
17 | LSCRIPT:=rom.ld
18 | LDFLAGS:=$(MOPTS) -g -nostartfiles -nodefaultlibs -L $(PREFIX)/lib -T$(LSCRIPT) dbg.o
19 | MSCRIPT:=$(PREFIX)/share/mod.ld
20 | LIB :=lib$(NAME).a
21 |
22 | ALL :=startup.o main.elf
23 | CLEAN :=
24 | CPU :=arm
25 |
26 | VPATH :=.
27 | VOBJ :=$(patsubst %.S,%.o, \
28 | $(patsubst %.c,%.o, \
29 | $(patsubst %.cpp, %.o, \
30 | $(notdir $(foreach DIR,$(VPATH),\
31 | $(wildcard $(DIR)/*.S) \
32 | $(wildcard $(DIR)/*.c) \
33 | $(wildcard $(DIR)/*.cpp))))))
34 | default:all
35 |
36 | include $(PREFIX)/share/Makefile.rule
37 |
38 | QF?=-serial stdio -serial null
39 | sim:
40 | qemu-system-arm -display none -M gbb $(QF) -kernel $(F) -gdb tcp::16888
41 |
42 | sim-dbg:
43 | qemu-system-arm -display none -M gbb $(QF) -kernel $(F) -S -gdb tcp::16888
44 |
45 | ddd:
46 | ddd --debugger $(CROSS)gdb -x qemu.gdb $(F)
47 |
48 | gdb:
49 | echo "target remote 127.0.0.1:8888" > dbm.gdb
50 | $(CROSS)gdb -x dbm.gdb $(F)
51 |
--------------------------------------------------------------------------------
/src-hello/dbg.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 |
32 | void _exit(int status)
33 | {
34 | unsigned *p = (unsigned *)0xB0100004;
35 | *p = status;
36 | while (1) ;
37 | }
38 |
39 | void _fail(void *addr, const char *f, unsigned line)
40 | {
41 | printf("_fail 0x%08x %s:%d\n", (unsigned)addr, f, line);
42 | _exit(-1);
43 | }
44 |
45 | void _abt(void *_ctx)
46 | {
47 | reg_t *ctx = (reg_t *) _ctx;
48 | int i, n = sizeof(reg_t) / sizeof(unsigned);
49 | unsigned *p = (unsigned *)ctx;
50 | for (i = 0; i < n; i++)
51 | printf("%6s: 0x%08x\n", cpu_reg_names[i], *p++);
52 | // only skip the abort instruction
53 | reg_skip(ctx, -8);
54 | }
55 |
56 | void _stackov(task_t * t)
57 | {
58 | printf("stack ov\n");
59 | }
60 |
--------------------------------------------------------------------------------
/src-hello/main.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 |
32 | #if ARM_HYPER
33 | #include
34 | unsigned ns_ints[] = {
35 | 0xffffffff
36 | };
37 | #endif
38 |
39 | #if _EXE_
40 |
41 | static void hellof(void *priv)
42 | {
43 | unsigned ts = (unsigned)priv;
44 | while (1) {
45 | printf("%s %d\n", _task_cur->name, tmr_ticks);
46 | task_sleep(ts);
47 | }
48 | }
49 |
50 | int main(void)
51 | {
52 | core_init();
53 | task_new("hello-1", hellof, 56, 1024, -1, (void *)(tmr_hz / 2));
54 | task_new("hello-2", hellof, 10, 1024, -1, (void *)(tmr_hz));
55 | core_start();
56 | return 0;
57 | }
58 | #endif
59 |
--------------------------------------------------------------------------------
/src-hello/mod-ex.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | char *hello = "hello";
28 |
29 | int ghihi = 0x10881088;
30 |
31 | static int lhihi = 0x10891089;
32 |
33 | int gbhi;
34 |
35 | static int lbhi;
36 |
37 | void hellof(void *priv);
38 |
39 | int addi(int a, int b)
40 | {
41 | return a + b + (unsigned)hellof;
42 | }
43 |
44 | void *getf()
45 | {
46 | lhihi++;
47 | lbhi++;
48 | return hellof;
49 | }
50 |
--------------------------------------------------------------------------------
/src-hello/qemu.gdb:
--------------------------------------------------------------------------------
1 | define bs
2 | set logging file brestore.text
3 | set logging on
4 | info break
5 | set logging off
6 | # reformat on-the-fly to a valid gdb command file
7 | shell perl -n -e 'print "break $1\n" if /^\d+.+?(\S+)$/g' brestore.text|uniq > bs.gdb
8 | shell rm -f brestore.text
9 | end
10 | define T
11 | p ($cpsr>>5)&1
12 | end
13 | define I
14 | p ($cpsr>>7)&1
15 | end
16 | define M
17 | p ($cpsr&0x1f)
18 | end
19 |
20 | define adump
21 | set $pc=$r0
22 | p $r1
23 | end
24 |
25 | target remote 127.0.0.1:16888
26 | source bs.gdb
27 |
--------------------------------------------------------------------------------
/src-hello/ram.ld:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 | OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
27 | OUTPUT_ARCH(arm)
28 | ENTRY(_start)
29 | STARTUP(startup.o)
30 | GROUP( libc.a libgcc.a libhcos.a libsoc-sim.a)
31 | SECTIONS
32 | {
33 | . = 0;
34 | .vectors : { KEEP(*(.vectors))}
35 | .vectors.mon : { KEEP(*(.vectors.mon))}
36 | .text : { *(.text .text.* .rodata*)} =0
37 | _data_load= . ;
38 | _data_sta = .;
39 | .data : { *(.data .data.* )}
40 | _data_end = . ;
41 | . = ALIGN(4);
42 | _bss_sta = .;
43 | .bss : { *(.bss .bss.* ) }
44 | _bss_end = .;
45 | _end = . ;
46 |
47 | PROVIDE(_stack = _end + 2024 );
48 |
49 | .comment 0 : { *(.comment) }
50 | .debug 0 : { *(.debug) }
51 | .line 0 : { *(.line) }
52 | .debug_srcinfo 0 : { *(.debug_srcinfo) }
53 | .debug_sfnames 0 : { *(.debug_sfnames) }
54 | .debug_aranges 0 : { *(.debug_aranges) }
55 | .debug_pubnames 0 : { *(.debug_pubnames) }
56 | .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
57 | .debug_abbrev 0 : { *(.debug_abbrev) }
58 | .debug_line 0 : { *(.debug_line) }
59 | .debug_frame 0 : { *(.debug_frame) }
60 | .debug_str 0 : { *(.debug_str) }
61 | .debug_loc 0 : { *(.debug_loc) }
62 | .debug_macinfo 0 : { *(.debug_macinfo) }
63 | .debug_weaknames 0 : { *(.debug_weaknames) }
64 | .debug_funcnames 0 : { *(.debug_funcnames) }
65 | .debug_typenames 0 : { *(.debug_typenames) }
66 | .debug_varnames 0 : { *(.debug_varnames) }
67 | .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
68 | .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) }
69 | /DISCARD/ : { *(.note.GNU-stack) *(.note.gnu*)}
70 | }
71 |
72 |
--------------------------------------------------------------------------------
/src-hello/rom.ld:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 | OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
27 | OUTPUT_ARCH(arm)
28 | ENTRY(_start)
29 | STARTUP(startup.o)
30 | GROUP( libc.a libgcc.a libhcos.a libsoc-sim.a)
31 | SECTIONS
32 | {
33 | . = 0;
34 | .vectors : { KEEP(*(.vectors))}
35 | .vectors.mon : { KEEP(*(.vectors.mon))}
36 | .text : { *(.text .text.* .rodata*)} =0
37 | .atext : { .ARM.exidx.*}
38 | _data_load = . ;
39 | . = 0x200000;
40 | _data_sta = .;
41 | /* .data : { *(.data .data.* )}*/
42 | .data : AT( _data_load) { *(.data .data.* ) }
43 | _data_end = . ;
44 | . = ALIGN(4);
45 | _bss_sta = .;
46 | .bss : { *(.bss .bss.* ) }
47 | _bss_end = .;
48 | _end = . ;
49 |
50 | PROVIDE(_stack = _end + 2024 );
51 |
52 | .comment 0 : { *(.comment) }
53 | .debug 0 : { *(.debug) }
54 | .line 0 : { *(.line) }
55 | .debug_srcinfo 0 : { *(.debug_srcinfo) }
56 | .debug_sfnames 0 : { *(.debug_sfnames) }
57 | .debug_aranges 0 : { *(.debug_aranges) }
58 | .debug_pubnames 0 : { *(.debug_pubnames) }
59 | .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
60 | .debug_abbrev 0 : { *(.debug_abbrev) }
61 | .debug_line 0 : { *(.debug_line) }
62 | .debug_frame 0 : { *(.debug_frame) }
63 | .debug_str 0 : { *(.debug_str) }
64 | .debug_loc 0 : { *(.debug_loc) }
65 | .debug_macinfo 0 : { *(.debug_macinfo) }
66 | .debug_weaknames 0 : { *(.debug_weaknames) }
67 | .debug_funcnames 0 : { *(.debug_funcnames) }
68 | .debug_typenames 0 : { *(.debug_typenames) }
69 | .debug_varnames 0 : { *(.debug_varnames) }
70 | .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
71 | .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) }
72 | /DISCARD/ : { *(.note.GNU-stack) *(.note.gnu*)}
73 | }
74 |
75 |
--------------------------------------------------------------------------------
/src-hello/startup.S:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 | .align 2
27 | .global _start
28 | _start:
29 | mrs a1,CPSR
30 | bic a1,a1,#0x1f
31 | orr a1,a1,#0x13 // supervisor mode
32 | orr a1,a1,#0xC0 // disable irq & fiq
33 | msr CPSR_cxsf,a1
34 | mov a2, #0
35 | ldr sp, = _stack
36 | ldr r12,= _init
37 | blx r12
38 | ldr r12,= main
39 | blx r12
40 | ldr r1, = _exit
41 | blx r1
42 | 2:
43 | b 2b
44 |
45 |
46 |
--------------------------------------------------------------------------------
/src-soc-sim/Makefile:
--------------------------------------------------------------------------------
1 | NAME :=soc-sim
2 | TARGET :=arm-none-eabi
3 | CROSS :=$(TARGET)-
4 | PREFIX ?=$(shell pwd)/../../prefix/$(CROSS:%-=%)#TEMPLATE
5 | SOC ?=soc-sim
6 | CPU :=arm
7 | INCLUDE:=-Iinclude -I$(SOC) -I$(PREFIX)/include
8 | COPTS ?=-march=armv7-a -mthumb
9 | AARCH :=$(shell echo $(COPTS) | sed -e 's/.*armv\([0-9]\).*/\1/g')
10 | AARCHX :=
11 | ifeq ($(shell echo $(COPTS) | sed -e 's/.*armv[0-9]-\([amr]\).*/\1/g'),m)
12 | AARCHX :=m
13 | endif
14 | MOPTS :=$(COPTS) \
15 | -DCFG_AARCH=$(AARCH) \
16 | -fno-builtin -fno-common \
17 | -ffunction-sections -fdata-sections -fshort-enums
18 | CONFIG ?=
19 | ASFLAGS:=$(MOPTS) $(CONFIG) -O2 -g -Wall -Werror -D __ASSEMBLY__
20 | CFLAGS :=$(MOPTS) $(CONFIG) -O2 -g -Wall -Werror
21 | LSCRIPT:=rom.ld
22 | LDFLAGS:=$(MOPTS) -g -nostartfiles -nodefaultlibs -L $(PREFIX)/lib -T$(LSCRIPT)
23 | MSCRIPT:=$(PREFIX)/share/mod.ld
24 | LIB :=lib$(NAME).a
25 |
26 | ALL :=lib
27 | CLEAN :=
28 | CPU :=arm
29 |
30 | VPATH :=.
31 | VOBJ :=$(patsubst %.S,%.o, \
32 | $(patsubst %.c,%.o, \
33 | $(patsubst %.cpp, %.o, \
34 | $(notdir $(foreach DIR,$(VPATH),\
35 | $(wildcard $(DIR)/*.S) \
36 | $(wildcard $(DIR)/*.c) \
37 | $(wildcard $(DIR)/*.cpp))))))
38 | default:all
39 |
40 | include $(PREFIX)/share/Makefile.rule
41 |
--------------------------------------------------------------------------------
/src-soc-sim/include/_soc.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 | #ifndef SOC130408
27 | #define SOC130408
28 |
29 | #include "uart.h"
30 |
31 | enum {
32 | BASE_DRAM = 0x00000000,
33 | BASE_MISC = 0xB0100000,
34 | BASE_UART0 = 0xB0200000,
35 | BASE_UART1 = 0xB0300000,
36 | BASE_CPU = 0xB0400000,
37 | BASE_DIST = 0xB0401000,
38 | BASE_TIME = 0xB0500000,
39 | BASE_TIME1 = 0xB0600000,
40 | BASE_ETH = 0xB0700000,
41 | BASE_RTC = 0xB0800000,
42 | };
43 |
44 | enum {
45 | IRQ_TIME = 32,
46 | IRQ_TIME1 = 33,
47 | IRQ_RTC = 35,
48 | IRQ_ETH = 37,
49 | IRQ_UART0 = 39,
50 | IRQ_UART1 = 40,
51 | };
52 |
53 | enum {
54 | UART_BAUD = 115200,
55 | UART_CLK = 1000000,
56 | };
57 |
58 | static inline unsigned tmr_ticks2ms(unsigned ticks)
59 | {
60 | return ticks * 10;
61 | }
62 |
63 | static inline unsigned tmr_ms2ticks(unsigned ms)
64 | {
65 | return ms / 10;
66 | }
67 |
68 | extern uart_t u0, u1;
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/src-soc-sim/include/uart.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 | #ifndef UART0721
27 | #define UART0721
28 |
29 | #include
30 |
31 | #define UART_THR(_b) ((_b)+0x0)
32 | #define UART_DLL(_b) ((_b)+0x0)
33 | #define UART_DLH(_b) ((_b)+0x4)
34 | #define UART_IER(_b) ((_b)+0x4)
35 | #define UART_FCR(_b) ((_b)+0x8)
36 | #define UART_LCR(_b) ((_b)+0xc)
37 | #define UART_LSR(_b) ((_b)+0x14)
38 |
39 | #define UART_LSR_THRE 0x0020
40 |
41 | typedef struct {
42 | unsigned base, irq;
43 | } uart_t;
44 |
45 | void uart_init(uart_t * o, unsigned base, unsigned irq);
46 |
47 | void uart_baud(uart_t * o, unsigned clk, unsigned baud);
48 |
49 | void uart_put(uart_t * o, char c);
50 |
51 | int uart_get(uart_t * o);
52 |
53 | static inline int uart_w(uart_t * o, const char *buf, int n)
54 | {
55 | while (n--) {
56 | char c = *buf++;
57 | uart_put(o, c);
58 | }
59 | return 0;
60 | }
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/src-soc-sim/soc-fs.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "_soc.h"
28 | #include
29 | #include
30 | #include
31 |
32 | int _close(int fd)
33 | {
34 | return -1;
35 | }
36 |
37 | int _stat(const char *filename, struct stat *st)
38 | {
39 | return -1;
40 | }
41 |
42 | int _fstat(int file, struct stat *st)
43 | {
44 | return -1;
45 | }
46 |
47 | int _getpid(void)
48 | {
49 | return 1;
50 | }
51 |
52 | int _gettimeofday(void *tp, void *tzp)
53 | {
54 | return -1;
55 | }
56 |
57 | int _isatty(int fd)
58 | {
59 | return (fd ^ STDOUT_FILENO) ^ (fd ^ STDERR_FILENO);
60 | }
61 |
62 | int _kill(int pid, int sig)
63 | {
64 | return 0;
65 | }
66 |
67 | off_t _lseek(int fd, off_t off, int whence)
68 | {
69 | return -1;
70 | }
71 |
72 | int _open(const char *buf, int flags, int mode)
73 | {
74 | return -1;
75 | }
76 |
77 | int _write(int fd, const char *buf, int nbytes)
78 | {
79 | switch (fd) {
80 | case 0:
81 | case 1:
82 | uart_w(&u0, buf, nbytes);
83 | break;
84 |
85 | }
86 | return 0;
87 | }
88 |
89 | int _read(int fd, char *buf, int nbytes)
90 | {
91 | return 0;
92 | }
93 |
94 | void *core_alloc(unsigned sz, int align_bits);
95 |
96 | char *_sbrk(int nbytes)
97 | {
98 | return core_alloc(nbytes, 0);
99 | }
100 |
101 | int _rename(const char *oldpath, const char *newpath)
102 | {
103 | return -1;
104 | }
105 |
106 | int _unlink(const char *pathname)
107 | {
108 | return -1;
109 | }
110 |
--------------------------------------------------------------------------------
/src-soc-sim/soc.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 | #if ! CFG_IRQ_VECTS
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include "uart.h"
37 | #include "_soc.h"
38 |
39 | uart_t u0, u1;
40 |
41 | static int tmr_off;
42 |
43 | void soc_idle(int next_expire)
44 | {
45 | cpu_idle();
46 | }
47 |
48 | void soc_init(void)
49 | {
50 | #if CFG_CACHE_VMSA
51 | cache_mmu_section(BASE_DRAM,
52 | BASE_DRAM, 0, 0, CACHE_PERM_RW_RW, 0x10000000);
53 | cache_mmu_section(BASE_MISC,
54 | BASE_MISC, 0, 0, CACHE_PERM_RW_RW, 0x800000);
55 |
56 | cache_mmu_on();
57 | #endif
58 | gic_init(BASE_DIST, BASE_CPU);
59 | // hyper_init(ns_ints);
60 | uart_init(&u0, BASE_UART0, -1);
61 | uart_baud(&u0, UART_CLK, UART_BAUD);
62 |
63 | uart_init(&u1, BASE_UART1, -1);
64 | uart_baud(&u1, UART_CLK, UART_BAUD);
65 | irq_cfg(IRQ_UART0, 1);
66 | irq_cfg(IRQ_UART1, 1);
67 | }
68 |
69 | void irq_cfg(unsigned irq, int is_level)
70 | {
71 | gic_set_type(irq, is_level);
72 | }
73 |
74 | unsigned irq_mask(unsigned irq)
75 | {
76 | return gic_irq_mask(irq);
77 | }
78 |
79 | void irq_unmask(unsigned irq)
80 | {
81 | gic_irq_unmask(irq);
82 | }
83 |
84 | irq_sta_t irq_ack(void)
85 | {
86 | unsigned v = gic_get_irq();
87 | v &= 0x1ff;
88 | return v == 0x1ff ? IRQ_NA : v;
89 | }
90 |
91 | void irq_eoi(unsigned irq)
92 | {
93 | gic_eoi(irq);
94 | }
95 |
96 | void irq_sgi(unsigned irq)
97 | {
98 | gic_sgi(irq);
99 | }
100 |
101 | void tmr_enable(int on)
102 | {
103 | writel(on ? 0x3 : 0, (void *)BASE_TIME + 0x8);
104 | writel(on ? 0x3 : 0, (void *)BASE_TIME1 + 0x8);
105 | tmr_off = !on;
106 | }
107 |
108 | int tmr_init_soc(unsigned *rtcs2tick, unsigned *hz)
109 | {
110 | irq_cfg(IRQ_RTC, 0);
111 | irq_cfg(IRQ_TIME, 0);
112 | irq_unmask(IRQ_RTC);
113 | writel(0x1, (void *)BASE_TIME + 0x0);
114 | writel(0x2, (void *)BASE_TIME + 0x4);
115 | writel(0x3, (void *)BASE_TIME + 0x8);
116 | *rtcs2tick = 2;
117 | *hz = 64;
118 | return IRQ_TIME;
119 | }
120 |
121 | unsigned soc_rtcs()
122 | {
123 | return readl(BASE_RTC + 0x4);
124 | }
125 |
126 | void tmr_tickless_soc(unsigned next_expire)
127 | {
128 | if (!tmr_off)
129 | writel(next_expire << 2, (void *)BASE_RTC + 0x0);
130 | }
131 |
132 | int _dbm_get()
133 | {
134 | return uart_get(&u1);
135 | }
136 |
137 | void dbm_put(char ch)
138 | {
139 | uart_put(&u1, ch);
140 | }
141 |
142 | unsigned dbm_irq(void)
143 | {
144 | return IRQ_UART1;
145 | }
146 |
147 | void udelay(int us)
148 | {
149 | volatile int i;
150 | int n = us * 120;
151 | for (i = 0; i < n; i++) ;
152 | }
153 | #endif
154 |
--------------------------------------------------------------------------------
/src-soc-sim/uart.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 | #include "uart.h"
27 |
28 | void uart_init(uart_t * o, unsigned base, unsigned irq)
29 | {
30 | o->base = base;
31 | o->irq = irq;
32 | }
33 |
34 | void uart_baud(uart_t * o, unsigned clk, unsigned baud)
35 | {
36 | unsigned div = (clk + 4 * baud) / (8 * baud);
37 | unsigned base = o->base;
38 | writeb(0xBF, (void *)UART_LCR(base));
39 | writeb(0x00, (void *)UART_FCR(base));
40 | writeb(0x03, (void *)UART_LCR(base));
41 | writeb(0x83, (void *)UART_LCR(base));
42 | writeb(div, (void *)UART_DLL(base));
43 | writeb(0x00, (void *)UART_DLH(base));
44 | writeb(0x03, (void *)UART_LCR(base));
45 | writeb(0x07, (void *)UART_FCR(base)); // FIFO
46 | writeb(readb(UART_IER(base)) | 0x01, (void *)UART_IER(base));
47 | }
48 |
49 | void uart_put(uart_t * o, char c)
50 | {
51 | unsigned base = o->base;
52 | while (1) {
53 | unsigned short lsr = readb(UART_LSR(base));
54 | if (lsr & UART_LSR_THRE) {
55 | writeb(c, (void *)UART_THR(base));
56 | break;
57 | }
58 | }
59 | }
60 |
61 | int uart_get(uart_t * o)
62 | {
63 | unsigned base = o->base;
64 | unsigned char lsr;
65 |
66 | lsr = readb(base + 0x14);
67 | if ((lsr & 0x1) == 0)
68 | return -1;
69 | return readb(base + 0x00);
70 | }
71 |
--------------------------------------------------------------------------------
/src/core.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "core.h"
28 | #include "soc.h"
29 | #include "tmr.h"
30 | #include "io.h"
31 | #include "task.h"
32 | #include "sem.h"
33 | #include "mut.h"
34 | #include "cfg.h"
35 | #include "tmr.h"
36 | #include "tmr_impl.h"
37 | #include "sch.h"
38 | #include "cpu/cache.h"
39 | #include "cpu/_cpu.h"
40 |
41 | ll_t core_gc_task;
42 |
43 | unsigned core_heap;
44 |
45 | static task_t core_task_idle;
46 |
47 | static ll_t idle_listeners;
48 |
49 | #if CFG_OSUTIL
50 |
51 | static unsigned idles[1<> 1) + core_ut.idles[iidle];
69 | core_ut.all = (core_ut.all >> 1) + (now - ut_sta);
70 | ut_sta = now;
71 | irq_restore(iflag);
72 | iidle = (iidle + 1) & ((1<ll);
93 | irq_restore(iflag);
94 | if (task_gc)
95 | task_gc(gct);
96 | }
97 | }
98 |
99 | static core_idle_t idle_gc = { LLE_INIT(idle_gc.ll), gcf, 0 };
100 |
101 | static void core_idle(void *priv)
102 | {
103 | lle_t *lle;
104 | sch_schedule(1);
105 | for (;;) {
106 | ll_for_each(&idle_listeners, lle) {
107 | core_idle_t *l = lle_get(lle, core_idle_t, ll);
108 | l->notify(l);
109 | }
110 | #if CFG_TICKLESS
111 | soc_idle(tmr_tickless());
112 | #else
113 | cpu_idle();
114 | #endif
115 | }
116 | }
117 |
118 | extern char _end[];
119 |
120 | void *core_alloc(unsigned sz, int align_bits)
121 | {
122 | if (core_heap == 0)
123 | core_heap = (unsigned)(&_end);
124 | core_heap = BI_RUP(core_heap, align_bits);
125 | core_heap += sz;
126 | return (void *)(core_heap - sz);
127 | }
128 |
129 | void core_init()
130 | {
131 | cache_init();
132 | cpu_init();
133 | soc_init();
134 | sch_init();
135 | task_init(&core_task_idle,
136 | "idle",
137 | core_idle,
138 | CFG_TPRI_NUM - 1,
139 | _alloc(CFG_IDLE_STACK), CFG_IDLE_STACK, 10, 0);
140 | tmr_init_sys();
141 | ll_init(&core_gc_task);
142 | ll_init(&idle_listeners);
143 | #if CFG_TASK_GC
144 | core_idle_listen(&idle_gc);
145 | #endif
146 | }
147 |
148 | void core_start()
149 | {
150 | lle_del(&core_task_idle.ll);
151 | _task_cur = &core_task_idle;
152 | _task_cur->sch = soc_rtcs();
153 | task_load(&core_task_idle);
154 | }
155 |
156 | void core_idle_listen(core_idle_t * o)
157 | {
158 | ll_addt(&idle_listeners, &o->ll);
159 | }
160 |
--------------------------------------------------------------------------------
/src/cpu-arm/Makefile:
--------------------------------------------------------------------------------
1 | armobj:=asm-off.o
2 |
3 | v5obj:= $(armobj) \
4 | task-cpu.o \
5 | cpu.o \
6 | gic.o \
7 | cache-vmsa.o \
8 | vector5.o \
9 | sem-cpu-c.o \
10 | mut-cpu-c.o
11 |
12 | v7obj:=$(armobj) \
13 | task-cpu.o \
14 | cpu.o \
15 | gic.o \
16 | cache-vmsa.o \
17 | vector7.o \
18 | sem-cpu.o \
19 | mut-cpu.o
20 |
21 | v7mobj:=$(armobj) \
22 | task-cpum.o \
23 | cpum.o \
24 | sem-cpu.o \
25 | mut-cpu.o \
26 | cache-pmsa.o \
27 | vector7m.o
28 |
29 | VOBJ+=$(v$(AARCH)$(AARCHX)obj)
30 |
31 | .PHONY:_cpu
32 | _cpu:include/asm-off.h
33 |
34 | .PHONY:include/asm-off.h
35 | include/asm-off.h:src/cpu-arm/asm-off.c
36 | $(GCC) $(CFLAGS) $(INCLUDE) -DASM_UTIL $(CONFIG) -o asm-off.s.text -S $<
37 | cat asm-off.s.text | grep define | sed -e 's/#//g' -e 's/[\t]*define/#define/g' > $@
38 |
39 |
--------------------------------------------------------------------------------
/src/cpu-arm/asm-off.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifdef ASM_UTIL
28 |
29 | #include "task.h"
30 | #include "sem.h"
31 | #include "mut.h"
32 | #include "cpu/reg.h"
33 |
34 | #define add(_n, _v) \
35 | asm volatile("define " #_n " %0" : : "i" (_v))
36 |
37 | #define off(_t, _m) \
38 | (unsigned)(&((_t*)((void*)0))->_m)
39 |
40 | int main(void)
41 | {
42 | add(mut_val, off(mut_t, val));
43 | add(mut_own, off(mut_t, own));
44 | add(mut_own_pri, off(mut_t, own_pri));
45 | add(sem_val, off(sem_t, val));
46 |
47 | add(task_pri, off(task_t, pri));
48 | add(task_context, off(task_t, context));
49 | add(task_stack, off(task_t, stack));
50 | add(task_stack_sz, off(task_t, stack_sz));
51 |
52 | add(reg_irq_sz, sizeof(reg_irq_t));
53 | add(reg_irq_pc, off(reg_irq_t, pc));
54 | add(reg_irq_cpsr, off(reg_irq_t, cpsr));
55 | #if CFG_IRQ_VECTS
56 | add(reg_irq_sz, sizeof(reg_irq_t));
57 | add(reg_irq_lr, off(reg_irq_t, lr));
58 | add(reg_sz, sizeof(reg_t));
59 | add(reg_pc, off(reg_t, pc));
60 | #else
61 | add(reg_sz, sizeof(reg_t));
62 | add(reg_r0, off(reg_t, r0));
63 | add(reg_r1, off(reg_t, r1));
64 | add(reg_r2, off(reg_t, r2));
65 | add(reg_r3, off(reg_t, r3));
66 | add(reg_r4, off(reg_t, r4));
67 | add(reg_r11, off(reg_t, r11));
68 | add(reg_r12, off(reg_t, r12));
69 | add(reg_lr, off(reg_t, lr));
70 | add(reg_pc, off(reg_t, pc));
71 | add(reg_cpsr, off(reg_t, cpsr));
72 | #endif
73 | #ifdef REG_FIQ_T_DEF
74 | add(reg_fiq_pc, off(reg_fiq_t, pc));
75 | add(reg_fiq_cpsr, off(reg_fiq_t, cpsr));
76 | #endif
77 | return 0;
78 | }
79 |
80 | #endif
81 |
--------------------------------------------------------------------------------
/src/cpu-arm/cache-pmsa.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | void cache_init()
28 | {
29 | }
30 |
--------------------------------------------------------------------------------
/src/cpu-arm/cache-vmsa.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "io.h"
28 | #include "core.h"
29 | #include "cpu-arm/cache-vmsa.h"
30 | #include "cpu-arm/asm.h"
31 | #include
32 |
33 | unsigned *cache_ttb;
34 |
35 | enum {
36 | MMU_L1_FAULT_ID = 0x0,
37 | MMU_L1_PAGE_ID = 0x1,
38 | MMU_L1_SEC_ID = 0x2,
39 | };
40 |
41 | struct MMU_L1_FAULT {
42 | int id:2;
43 | int sbz:30;
44 | };
45 |
46 | struct MMU_L1_PAGE {
47 | int id:2;
48 | int imp:2;
49 | int dom:4;
50 | int sbz:1;
51 | int base:23;
52 | };
53 |
54 | struct MMU_L1_SEC {
55 | int id:2;
56 | int b:1;
57 | int c:1;
58 | int imp:1;
59 | int dom:4;
60 | int sbz0:1;
61 | int ap:2;
62 | int sbz1:7;
63 | int ns:1;
64 | int base:12;
65 | };
66 |
67 | struct MMU_L1_RES {
68 | int id:2;
69 | int sbz:30;
70 | };
71 |
72 | union MMU_L1_DES {
73 | unsigned long word;
74 | struct MMU_L1_FAULT fault;
75 | struct MMU_L1_PAGE page;
76 | struct MMU_L1_SEC sec;
77 | struct MMU_L1_RES res;
78 | };
79 |
80 | void cache_init(void)
81 | {
82 | unsigned t;
83 |
84 | #define NO_ACCESS(dom_num) (0x0 << (dom_num)*2)
85 | #define CLIENT(dom_num) (0x1 << (dom_num)*2)
86 | #define MANAGER(dom_num) (0x3 << (dom_num)*2)
87 |
88 | // Set the Domain Access Control Register
89 | t = MANAGER(0) |
90 | NO_ACCESS(1) |
91 | NO_ACCESS(2) |
92 | NO_ACCESS(3) |
93 | NO_ACCESS(4) |
94 | NO_ACCESS(5) |
95 | NO_ACCESS(6) |
96 | NO_ACCESS(7) |
97 | NO_ACCESS(8) |
98 | NO_ACCESS(9) |
99 | NO_ACCESS(10) |
100 | NO_ACCESS(11) |
101 | NO_ACCESS(12) | NO_ACCESS(13) | NO_ACCESS(14) | NO_ACCESS(15);
102 | asm volatile (""
103 | asm_beg(r2) "mcr p15,0,%0,c3,c0,0" "\n\t" asm_end(r2)
104 | ::"r"(t)
105 | :"r2");
106 | cache_ttb = core_alloc(0x4000, 14);
107 | memset((void *)cache_ttb, 0, 0x4000);
108 | }
109 |
110 | static void mmu_section(unsigned ppn, unsigned vpn, unsigned c, unsigned b,
111 | unsigned perm)
112 | {
113 | register union MMU_L1_DES desc;
114 | desc.word = MMU_L1_SEC_ID & 0x3;
115 | desc.sec.imp = 1;
116 | desc.sec.dom = 0;
117 | desc.sec.c = (c);
118 | desc.sec.b = (b);
119 | desc.sec.ap = (perm);
120 | desc.sec.ns = 0;
121 | desc.sec.base = (ppn);
122 | writel(desc.word, (void *)(cache_ttb) + ((vpn) << 2));
123 | }
124 |
125 | void cache_mmu_section(unsigned pa, unsigned va,
126 | unsigned c, unsigned b, cache_perm_t perm, unsigned sz)
127 | {
128 | unsigned ppn = pa >> 20;
129 | unsigned vpn = va >> 20;
130 | unsigned np = (((sz) >> 20) + ((sz) & 0xfffff ? 1 : 0));
131 | int i;
132 |
133 | for (i = np; i > 0; i--) {
134 | mmu_section(ppn, vpn, c, b, perm);
135 | ppn++;
136 | vpn++;
137 | }
138 | }
139 |
140 | unsigned cache_mmu_on(void)
141 | {
142 | register unsigned ov, tmp;
143 |
144 | // load ttb
145 | asm volatile ("" asm_beg(r2) "mcr p15,0,%0,c2,c0,0 \n" asm_end(r2)
146 | ::"r"(cache_ttb)
147 | :"r2");
148 |
149 | // enable mmu
150 | asm volatile (""
151 | asm_beg(r2)
152 | "mrc p15,0,%0,c1,c0,0 \n"
153 | "orr %1,%0,#1 \n"
154 | "mcr p15,0,%1,c1,c0,0 \n" asm_end(r2)
155 | :"=r"(ov), "=r"(tmp)
156 | ::"r2");
157 | return ov;
158 | }
159 |
160 | void cache_i_inv(unsigned sta, unsigned sz)
161 | {
162 | asm volatile (""
163 | asm_beg(r2)
164 | "mov r1,#0\n"
165 | "mcr p15,0,r1,c7,c5,0\n"
166 | "mcr p15,0,r1,c8,c5,0\n"
167 | "nop\n"
168 | "nop\n" "nop\n" "nop\n" "nop\n" "nop\n" asm_end(r2)
169 | :::"r1", "r2");
170 | }
171 |
172 | void cache_d_flu(unsigned sta, unsigned sz)
173 | {
174 | /*
175 | asm volatile (""
176 | asm_beg(r2)
177 | "1:\n"
178 | "mrc p15, 0, r15, c7, c14, 3\n"
179 | "bne 1b\n"
180 | "mcr p15,0,r0,c7,c10,4\n"
181 | asm_end(r2)
182 | :
183 | :
184 | : "r0", "r2");
185 | */
186 |
187 | }
188 |
--------------------------------------------------------------------------------
/src/cpu-arm/cpu.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "core.h"
28 | #include "task.h"
29 | #include "cpu-arm/asm.h"
30 | #include "cpu-arm/_cpu.h"
31 | #include "cpu-arm/reg.h"
32 | #include
33 |
34 | void *cpu_cur_pc(unsigned line)
35 | {
36 | return __builtin_return_address(0);
37 | }
38 |
39 | void cpu_set_stack(unsigned mode, void *stack)
40 | {
41 | unsigned cpsr_old, cpsr_new;
42 | mode &= 0x1f;
43 | asm volatile (""
44 | asm_beg(%0)
45 | "mrs %0, CPSR \n"
46 | "bic %1, %0,#0x1f\n"
47 | "orr %1, %1,%2 \n"
48 | "msr CPSR_cxsf,%1\n"
49 | "mov sp, %3 \n" "msr CPSR, %0 \n" asm_end(%0)
50 | :"=&r"(cpsr_old), "=&r"(cpsr_new)
51 | :"r"(mode), "r"(stack));
52 | }
53 |
54 | void cpu_init(void)
55 | {
56 | unsigned tmp;
57 | // trapping in arm mode
58 | asm volatile (""
59 | asm_beg(r2)
60 | "mrc p15, 0, %0, c1, c0, 0\n"
61 | "bic %0, #0x40000000 \n"
62 | "mcr p15, 0, %0, c1, c0, 0\n" asm_end(r2)
63 | :"=r"(tmp)
64 | ::"r2");
65 |
66 | extern unsigned _vects[];
67 | // load vector base
68 | asm volatile ("" asm_beg(r2) "mcr p15, 0, %0, c12, c0, 0\n" asm_end(r2)
69 | ::"r"(((unsigned)(&_vects)) - 0x20)
70 | :"r2");
71 | cpu_set_stack(_IRQ, _alloc(CFG_STACK_IRQ) + CFG_STACK_IRQ);
72 | cpu_set_stack(_ABT, _alloc(CFG_STACK_ABT) + CFG_STACK_ABT);
73 | irqs = _alloc(CFG_IRQ_MAX * sizeof(irq_t));
74 | }
75 |
76 | static inline void *stack_top(task_t * t)
77 | {
78 | return (((char *)t->stack) + t->stack_sz);
79 | }
80 |
81 | reg_t *_cpu_task_init(task_t * t, void *priv, void *dest)
82 | {
83 | reg_t *r = stack_top(t) - sizeof(reg_t);
84 | memset(r, 0, sizeof(reg_t));
85 | r->r0 = (unsigned)priv;
86 | r->lr = (unsigned)dest;
87 | r->pc = (unsigned)t->ent;
88 | r->cpsr = 0x13 | ((r->pc & 0x1) << 5);
89 | return r;
90 | }
91 |
92 | char *cpu_reg_names[] = {
93 | "r0", "r1", "r2", "r3",
94 | "r4", "r5", "r6", "r7",
95 | "r8", "r9", "r10", "r11",
96 | "r12", "lr",
97 | #if CFG_ASM_RFE
98 | "pc", "cpsr"
99 | #else
100 | "cpsr", "pc"
101 | #endif
102 | };
103 |
--------------------------------------------------------------------------------
/src/cpu-arm/gic-cfg.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef GIC_CFG150502
28 | #define GIC_CFG150502
29 |
30 | #define GICP_ENN 0xF8
31 |
32 | #define GICP_ENS 0x78
33 |
34 | #if CFG_SECURE && CFG_SECURE_NSIRQPRE
35 | #define GICP_INIT GICP_ENN
36 | #elif CFG_SECURE && !CFG_SECURE_NSIRQPRE
37 | #define GICP_INIT GICP_ENS
38 | #else
39 | #define GICP_INIT GICP_ENN
40 | #endif
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/src/cpu-arm/mut-cpu-c.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "mut.h"
28 | #include "task.h"
29 | #include "irq.h"
30 | #include
31 |
32 | int mut_lock_wait(mut_t * u, wait_t w);
33 |
34 | /// \return 0 on success
35 | int mut_lock(mut_t * u, wait_t w)
36 | {
37 | unsigned iflag = irq_lock();
38 | if (!u->val) {
39 | u->val++;
40 | u->own = _task_cur;
41 | u->own_pri = _task_cur->pri;
42 | irq_restore(iflag);
43 | return 0;
44 | }
45 | irq_restore(iflag);
46 | return mut_lock_wait(u, w);
47 | }
48 |
49 | void mut_unlock_wake(mut_t * u);
50 |
51 | void mut_unlock(mut_t * u)
52 | {
53 | unsigned iflag = irq_lock();
54 | if (u->val == 1) {
55 | irq_restore(iflag);
56 | return mut_unlock_wake(u);
57 | }
58 | u->val--;
59 | irq_restore(iflag);
60 | }
61 |
--------------------------------------------------------------------------------
/src/cpu-arm/mut-cpu.S:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "asm-off.h"
28 | #include "cpu/asm.h"
29 | #include "cpu/_irq.h"
30 |
31 | .asm_syn
32 |
33 | .text
34 | .asm_fun mut_lock
35 | mut_lock:
36 | ldrex r2, [r0,#mut_val]
37 | cmp r2, #0
38 | bne mut_lock_wait
39 | add r2, r2, #1
40 | strex r3, r2, [r0]
41 | cmp r3, #0
42 | bne mut_lock
43 | ldr r2, = _task_cur
44 | ldr r2, [r2]
45 | str r2, [r0, #mut_own]
46 | ldrh r3, [r2, #task_pri]
47 | strh r3, [r0, #mut_own_pri]
48 | mov r0, #0
49 | 1:
50 | bx lr
51 |
52 | .asm_fun mut_unlock
53 | mut_unlock:
54 | ldrex r2, [r0, #mut_val]
55 | cmp r2, #1
56 | ble mut_unlock_wake
57 | add r2, r2, #-1
58 | strex r3, r2, [r0]
59 | cmp r3, #0
60 | bne mut_unlock
61 | bx lr
62 |
63 |
64 |
--------------------------------------------------------------------------------
/src/cpu-arm/sem-cpu-c.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "sem.h"
28 | #include "ll.h"
29 | #include "task.h"
30 | #include "irq.h"
31 | #include
32 |
33 | int sem_get_wait(sem_t * s, wait_t w, unsigned iflag);
34 |
35 | void sem_post_wake(sem_t * s);
36 |
37 | /// \return 0 on success
38 | int sem_get(sem_t * s, wait_t w)
39 | {
40 | unsigned iflag = irq_lock();
41 | if (s->val > 0) {
42 | s->val--;
43 | irq_restore(iflag);
44 | return 0;
45 | }
46 | return sem_get_wait(s, w, iflag);
47 | }
48 |
49 | int sem_post(sem_t * s)
50 | {
51 | unsigned iflag = irq_lock();
52 | s->val++;
53 | if (s->val > 0) {
54 | irq_restore(iflag);
55 | sem_post_wake(s);
56 | } else {
57 | irq_restore(iflag);
58 | }
59 | return 0;
60 | }
61 |
--------------------------------------------------------------------------------
/src/cpu-arm/sem-cpu.S:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "asm-off.h"
28 | #include "cpu/_irq.h"
29 |
30 | .asm_syn
31 | .text
32 | .asm_fun sem_get
33 | sem_get:
34 | ldrex r2, [r0, #sem_val]
35 | add r2, r2, #-1
36 | cmp r2, #0
37 | blt 1f
38 | strex r3, r2, [r0]
39 | cmp r3, #0
40 | bne sem_get
41 | mov r0, #0
42 | bx lr
43 | 1:
44 | .irq_lock r2, r3
45 | // FIXME: give up ldrex mux
46 | ldr r3, [r0, #sem_val]
47 | cmp r3, #0
48 | ble sem_get_wait
49 | .irq_restore r2
50 | b sem_get
51 |
52 | .asm_fun sem_post
53 | sem_post:
54 | ldrex r2, [r0, #sem_val]
55 | add r2, r2, r1
56 | strex r3, r2, [r0]
57 | cmp r3, #0
58 | bne sem_post
59 | cmp r2, #0
60 | bgt sem_post_wake
61 | mov r0, #0
62 | bx lr
63 |
64 |
--------------------------------------------------------------------------------
/src/cpu-arm/task-cpu.S:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "asm-off.h"
28 | #include "cpu/asm.h"
29 | #include "cpu/_irq.h"
30 |
31 | .asm_syn
32 | .text
33 | // @param r0 next_task->context
34 | // @param r1 &(cur_task->context)
35 | // @param r2 reg_irq_t* cur_irq
36 | .asm_fun _task_switch_irq
37 | _task_switch_irq:
38 | // pop the irq stack
39 | add sp, sp, #reg_irq_sz
40 | // get cur task sp
41 | ldr r12, [r2, #reg_irq_cpsr]
42 | mrs r3, cpsr
43 | #if CFG_ASM_BFI
44 | bfi r3, r12, #0, #5
45 | #else
46 | bic r3, r3, #0x1f
47 | and r12,r12, #0x1f
48 | orr r3, r3, r12
49 | #endif
50 | orr r3, r3, #0x80
51 | msr cpsr, r3
52 |
53 | add sp, sp, #-reg_sz
54 | str sp, [r1]
55 |
56 | ldr r3 , [r2, #reg_irq_pc]
57 | ldr r12, [r2, #reg_irq_cpsr]
58 |
59 | str lr, [sp, #reg_lr]
60 | str r3 , [sp, #reg_pc]
61 | str r12, [sp, #reg_cpsr]
62 |
63 | mov lr, r0
64 | ldmia r2, {r0-r3,r12}
65 | stmia sp, {r0-r12}
66 | mov r0, lr
67 |
68 | b _task_load
69 |
70 | // @param r0 next_task->context
71 | // @param r1 &(cur_task->context)
72 | .asm_fun _task_switch
73 | _task_switch:
74 | add sp, sp, #-reg_sz // alloc reg_t
75 | str sp, [r1]
76 | add r2, sp, # reg_r4 // skip r0 ~ r3
77 | stmia r2, {r4-r11}
78 |
79 | mrs r2, cpsr_all
80 | and r3, lr, #1
81 | orr r2, r2, r3, lsl #5
82 | str lr, [sp,# reg_pc] // pc
83 | str r2, [sp,# reg_cpsr]// cpsr
84 | _stack_check:
85 | #if CFG_STACK_CHK
86 | ldr r2, [r1, #(task_stack- task_context)]
87 | ldr r3, [r2]
88 | ldr r4, =0xABBA
89 | cmp r3, r4
90 | beq 1f
91 | mov r5, r0
92 | add r0, r1, #-task_context
93 | ldr r6, task_ov
94 | blx r6
95 | mov r0, r5
96 | 1:
97 | #endif
98 | // @param r0 next_task->context
99 | .asm_fun _task_load
100 | _task_load:
101 | mov sp, r0
102 | #if CFG_ASM_RFE
103 | ldmia sp!, {r0-r12, lr}
104 | rfeia sp!
105 | #else
106 | ldr r1, [sp, #reg_cpsr]
107 | msr spsr, r1
108 | ldmia sp!, {r0-r12, lr}
109 | add sp, sp, #4
110 | ldmia sp!, {pc}^
111 | #endif
112 |
113 | .global task_ov
114 | task_ov:
115 | .word _stackov
116 |
--------------------------------------------------------------------------------
/src/cpu-arm/task-cpum.S:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "asm-off.h"
28 | #include "cpu/asm.h"
29 | #include "cpu/_irq.h"
30 |
31 | .asm_syn
32 | .text
33 |
34 | .asm_fun _task_pendsv
35 | _task_pendsv:
36 | cpsid i
37 | ldr r3, =fctx_corrupted
38 | ldr r3, [r3]
39 | cmp r3, #0
40 | beq 1f
41 | movw r3, #0xED88 // CPACR
42 | movt r3, #0xE000
43 | ldr r2, [r3]
44 | bic.w r2, 0xf00000
45 | str r2, [r3]
46 | 1:
47 | ldr r3, = _task_pend
48 | ldr r0, [r3]
49 | cbnz r0, 2f
50 | cpsie i
51 | bx lr
52 | 2:
53 | mov r2, #0
54 | str r2, [r3]
55 | stmdb sp!,{r0, lr}
56 | bl _task_switch_status
57 | mov r1, r0
58 | ldmia sp!,{r0, lr}
59 |
60 | add r0, r0, #task_context
61 | ldr r0, [r0]
62 |
63 | // @param r0 next_task->context
64 | // @param r1 &(cur_task->context)
65 | .asm_fun _task_switch
66 | _task_switch:
67 | mrs r3, PSP
68 | add r3, #-(reg_sz-reg_irq_sz)
69 | mov r2, lr
70 | stmia r3, {r2, r4-r11}
71 | str r3, [r1]
72 | //bne 1f
73 | //ldr r3, =_task_cur
74 | //ldr r3, [r3]
75 | //ldr r2, =cpu_fctx
76 | //str r3, [r2]
77 | // @note FPCAR = stack_top
78 | //add r2, r1, #(task_stack_sz-task_context)
79 | //ldr r2, [r2]
80 | //add r3, r1, #(task_stack-task_context)
81 | //ldr r3, [r3]
82 | //add r3, r2
83 | //movw r2, #0xEF38 // FPCAR
84 | //movt r2, #0xE000
85 | //str r3, [r2]
86 | //1:
87 | _stack_check:
88 | #if CFG_STACK_CHK
89 | ldr r2, [r1, #(task_stack- task_context)]
90 | ldr r3, [r2]
91 | ldr r4, =0xABBA
92 | cmp r3, r4
93 | beq _task_load
94 | mov r5, r0
95 | add r0, r1, #-task_context
96 | ldr r6, task_ov
97 | blx r6
98 | mov r0, r5
99 | #endif
100 |
101 | // @param r0 next_task->context
102 | .asm_fun _task_load
103 | _task_load:
104 | movw r3, #0xED88 // CPACR
105 | movt r3, #0xE000
106 | ldr r2, [r3]
107 | bic.w r2, 0xf00000
108 | str r2, [r3]
109 | ldmia r0!, {r2, r4-r11}
110 | lsls r2, r2, #27
111 | ite mi
112 | orrmi.w lr, lr, #16
113 | bicpl.w lr, lr, #16
114 | msr PSP, r0
115 | cpsie i
116 | bx lr
117 |
118 | .global task_ov
119 | task_ov:
120 | .word _stackov
121 |
--------------------------------------------------------------------------------
/src/cpu-arm/vector7m.S:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "cfg.h"
28 | #include "asm-off.h"
29 | #include "cpu/asm.h"
30 | .asm_syn
31 |
32 | .text
33 | .asm_fun _hfault
34 | _hfault:
35 | tst lr, #4
36 | ite eq
37 | mrseq r0, MSP
38 | mrsne r0, PSP
39 | push {lr}
40 | bl cpu_tf
41 | pop {lr}
42 | cmp r0, #0
43 | it ne
44 | // return iff it's a lazy float trap
45 | bxne lr
46 |
47 | 1:
48 | b 1b
49 | .asm_fun __abt
50 | __abt:
51 | tst lr, #4
52 | ite eq
53 | mrseq r0, MSP
54 | mrsne r0, PSP
55 |
56 | push {lr}
57 | ldr lr, =core_abt
58 | ldr lr, [lr]
59 | blx lr
60 | pop {lr}
61 | bx lr
62 |
63 | .data
64 | .align 2
65 | .global core_abt
66 | core_abt:
67 | .word _abt
68 |
--------------------------------------------------------------------------------
/src/init.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include
28 |
29 | void _init()
30 | {
31 | extern char _data_load, _data_sta, _data_end;
32 | extern char _bss_sta, _bss_end;
33 |
34 | unsigned sz;
35 |
36 | if (_data_load != _data_sta) {
37 | sz = (unsigned)&_data_end - (unsigned)&_data_sta;
38 | memcpy(&_data_sta, &_data_load, sz);
39 | }
40 | sz = (unsigned)&_bss_end - (unsigned)&_bss_sta;
41 | memset(&_bss_sta, 0, sz);
42 | }
43 |
--------------------------------------------------------------------------------
/src/irq.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "irq.h"
28 | #include "cfg.h"
29 | #include "soc.h"
30 | #include "dbg.h"
31 | #include "tmr_impl.h"
32 | #include "cpu/reg.h"
33 | #include
34 |
35 | #if !CFG_IRQ_VECTS
36 | volatile unsigned irq_cnt, irq_depth;
37 |
38 | volatile unsigned fiq_cnt;
39 | #endif
40 |
41 | irq_t *irqs;
42 |
43 | void _irq_init(irq_t * irqs, unsigned irq, irq_t f)
44 | {
45 | irq_t *o = irqs + (int)irq;
46 | _assert((int)irq < CFG_IRQ_MAX);
47 | *o = f;
48 | if (((int)irq) >= 0)
49 | irq_unmask(irq);
50 | }
51 |
52 | void _irq_dest(irq_t * irqs, unsigned irq)
53 | {
54 | irq_t *o = irqs + irq;
55 | *o = 0;
56 | }
57 |
58 | void irq_init(unsigned irq, irq_t f)
59 | {
60 | _irq_init(irqs, irq, f);
61 | }
62 |
63 | void irq_dest(unsigned irq)
64 | {
65 | _irq_dest(irqs, irq);
66 | }
67 |
68 | void *irq_bind_data[CFG_IRQ_MAX];
69 |
70 | void irq_bind(unsigned irq, void *data)
71 | {
72 | irq_bind_data[irq] = data;
73 | }
74 |
75 | void *irq_data(void)
76 | {
77 | int n = irq_actn();
78 | if (n == IRQ_NA)
79 | return 0;
80 | return irq_bind_data[n];
81 | }
82 |
83 | #if !CFG_IRQ_VECTS
84 |
85 | static int irq_act_n;
86 |
87 | int irq_actn()
88 | {
89 | return irq_act_n;
90 | }
91 |
92 | int irq_dispatch(irq_sta_t irq, reg_irq_t * reg_irq, int depth)
93 | {
94 | unsigned r = 0;
95 | irq_t *o;
96 | if (irq == IRQ_NA)
97 | return 0;
98 | irq_act_n = irq;
99 | #if CFG_TICKLESS
100 | if (tmr_rtcs)
101 | tmr_tickless_end();
102 | #endif
103 | o = irqs + irq;
104 | if (*o)
105 | r = (*o) (irq, reg_irq, depth);
106 | if (r != IRQ_DONE)
107 | irq_eoi(irq);
108 | irq_act_n = IRQ_NA;
109 | #if CFG_DBM
110 | return irq == dbm_irq();
111 | #else
112 | return 0;
113 | #endif
114 | }
115 | #endif
116 |
--------------------------------------------------------------------------------
/src/mq.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "mq.h"
28 | #include "task.h"
29 | #include "dbg.h"
30 | #include "irq.h"
31 | #include
32 |
33 | mq_t *mq_init(mq_t * m, int no_words, unsigned *b, int bsz)
34 | {
35 | memset(m, 0, sizeof(*m));
36 | m->b = (void *)b;
37 | m->h = (void *)b;
38 | m->t = (void *)b;
39 | m->bsz = bsz;
40 | m->isz = sizeof(unsigned) * no_words;
41 | m->sz = bsz / m->isz;
42 | m->n = 0;
43 | ll_init(&m->waitp);
44 | ll_init(&m->waitg);
45 | _assert(m->isz * m->sz == bsz);
46 | return m;
47 | }
48 |
49 | int mq_put(mq_t * m, unsigned *msg, wait_t w)
50 | {
51 | unsigned *d;
52 | unsigned iflag;
53 |
54 | if (m->n >= m->sz && !w)
55 | return -1;
56 | iflag = irq_lock();
57 | if (m->n >= m->sz) {
58 | if (!task_suspend(&m->waitp, w)) {
59 | irq_restore(iflag);
60 | return -1;
61 | }
62 | }
63 |
64 | _assert(m->n < m->sz);
65 |
66 | d = (void *)m->t;
67 | switch (m->isz >> 2) {
68 | case 4:
69 | *d++ = *msg++;
70 | case 3:
71 | *d++ = *msg++;
72 | case 2:
73 | *d++ = *msg++;
74 | case 1:
75 | *d++ = *msg++;
76 | break;
77 | default:
78 | memcpy(d, msg, m->isz);
79 | }
80 |
81 | m->t += m->isz;
82 | if (m->t >= m->b + m->bsz)
83 | m->t = m->b;
84 | m->n++;
85 | _task_wakeq(&m->waitg, iflag);
86 | return 0;
87 | }
88 |
89 | static int mq_fetch(mq_t * m, unsigned *msg, wait_t w)
90 | {
91 | unsigned *s;
92 | if (!m->n && !w)
93 | return -1;
94 | if (!m->n) {
95 | if (task_suspend(&m->waitg, w)) {
96 | return -1;
97 | }
98 | }
99 | _assert(m->n > 0);
100 | s = (void *)m->h;
101 | switch (m->isz >> 2) {
102 | case 4:
103 | *msg++ = *s++;
104 | case 3:
105 | *msg++ = *s++;
106 | case 2:
107 | *msg++ = *s++;
108 | case 1:
109 | *msg++ = *s++;
110 | break;
111 | default:
112 | memcpy(msg, m->h, m->isz);
113 | }
114 | return 0;
115 | }
116 |
117 | int mq_peek(mq_t * m, unsigned *msg, wait_t w)
118 | {
119 | int r;
120 | unsigned iflag;
121 | iflag = irq_lock();
122 | r = mq_fetch(m, msg, w);
123 | irq_restore(iflag);
124 | return r;
125 | }
126 |
127 | int mq_get(mq_t * m, unsigned *msg, wait_t w)
128 | {
129 | unsigned iflag;
130 | iflag = irq_lock();
131 | if (mq_fetch(m, msg, w)) {
132 | irq_restore(iflag);
133 | return -1;
134 | }
135 | m->h += m->isz;
136 | if (m->h >= m->b + m->bsz)
137 | m->h = m->b;
138 | m->n--;
139 | _task_wakeq(&m->waitp, iflag);
140 | return 0;
141 | }
142 |
--------------------------------------------------------------------------------
/src/mut.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "mut.h"
28 | #include "task.h"
29 | #include "irq.h"
30 | #include
31 |
32 | mut_t *mut_init(mut_t * u)
33 | {
34 | memset(u, 0, sizeof(*u));
35 | ll_init(&u->wait);
36 | return u;
37 | }
38 |
39 | int mut_lock_wait(mut_t * u, wait_t w)
40 | {
41 | unsigned iflag;
42 |
43 | task_t *tc = _task_cur;
44 | task_t *own = u->own;
45 |
46 | if (u->own == tc) {
47 | u->val++;
48 | return 0;
49 | }
50 |
51 | iflag = irq_lock();
52 | if (!u->val)
53 | goto done;
54 |
55 | if (own->pri > tc->pri) {
56 | _task_pri(own, tc->pri);
57 | }
58 |
59 | if (task_suspend(&u->wait, w)) {
60 | irq_restore(iflag);
61 | return -1;
62 | } else {
63 | done:
64 | _assert(u->val == 0);
65 | u->val++;
66 | u->own = tc;
67 | u->own_pri = tc->pri;
68 | irq_restore(iflag);
69 | return 0;
70 | }
71 | }
72 |
73 | void mut_unlock_wake(mut_t * u)
74 | {
75 | task_t *tc = _task_cur;
76 | unsigned iflag;
77 | int own_pri;
78 |
79 | _assert(u->own == tc);
80 | own_pri = tc->pri;
81 |
82 | iflag = irq_lock();
83 | tc->pri = u->own_pri;
84 | u->val--;
85 | if (_task_wakeq(&u->wait, iflag) != 0 && own_pri != tc->pri)
86 | sch_schedule(own_pri);
87 | }
88 |
--------------------------------------------------------------------------------
/src/sch.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef SCH150904
28 | #define SCH150904
29 |
30 | void sch_schedule(unsigned hint);
31 |
32 | /// wake up thread, possible trigger an immediate context switch if t's
33 | /// priority is higher than current
34 | void sch_wake(task_t * t);
35 |
36 | void sch_add(task_t * t);
37 |
38 | void sch_del(task_t * t);
39 |
40 | void sch_tick(void);
41 |
42 | void sch_init(void);
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/src/sch_pq.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "cfg.h"
28 | #include "task.h"
29 | #include "io.h"
30 |
31 | static ll_t task_ready[CFG_TPRI_NUM];
32 |
33 | #if CFG_SCH_PQ == 1
34 |
35 | void sch_schedule(unsigned hint)
36 | {
37 | task_t *tn;
38 | unsigned i, iflag;
39 |
40 | _assert(_task_cur != 0);
41 | irq_dep_chk(irq_depth == 0);
42 |
43 | //L_restart:
44 | // irq_prev = irq_cnt;
45 | iflag = irq_lock();
46 | for (i = hint; i < CFG_TPRI_NUM; i++) {
47 |
48 | if (!ll_empty(&task_ready[i])) {
49 |
50 | tn = lle_get(ll_head(&task_ready[i]), task_t, ll);
51 | _assert(tn != _task_cur);
52 | // this might inprove RT but may has starvation problem when system busy
53 | // iflag = irq_lock();
54 | // if(irq_prev != irq_cnt){
55 | // irq_prev = irq_cnt;
56 | // irq_restore(iflag);
57 | // goto L_restart;
58 | // }
59 | if ((_task_cur->status != TASK_READY) ||
60 | (tn->pri < _task_cur->pri)) {
61 |
62 | _task_switch_sync(tn, _task_switch_status(tn));
63 | }
64 |
65 | irq_restore(iflag);
66 | return;
67 | }
68 | }
69 | irq_restore(iflag);
70 | _assert(0);
71 | }
72 |
73 | void sch_add(task_t * t)
74 | {
75 | ll_addt(&task_ready[t->pri], &t->ll);
76 | }
77 |
78 | void sch_del(task_t * t)
79 | {
80 | lle_del(&t->ll);
81 | }
82 |
83 | #elif CFG_SCH_PQ == 2
84 | #include
85 |
86 | unsigned map_l1[BI_RUP(CFG_TPRI_NUM, 10) >> 10];
87 |
88 | unsigned map_l2[BI_RUP(CFG_TPRI_NUM, 5) >> 5];
89 |
90 | void sch_schedule(unsigned hint)
91 | {
92 | task_t *tn;
93 | unsigned i, iflag;
94 |
95 | _assert(_task_cur != 0);
96 | irq_dep_chk(irq_depth == 0);
97 |
98 | iflag = irq_lock();
99 |
100 | for (i = 0; i < sizeof(map_l1) / sizeof(unsigned); i++) {
101 |
102 | unsigned m, n, q;
103 | m = __builtin_ffs(map_l1[i]);
104 | if (!m)
105 | continue;
106 | m--;
107 |
108 | n = __builtin_ffs(map_l2[m]);
109 | _assert(n != 0);
110 | n--;
111 |
112 | q = (m << 5) + n;
113 | _assert(!ll_empty(&task_ready[q]));
114 |
115 | tn = lle_get(ll_head(&task_ready[q]), task_t, ll);
116 | _assert(tn != _task_cur);
117 |
118 | if ((_task_cur->status != TASK_READY) ||
119 | (tn->pri < _task_cur->pri)) {
120 |
121 | _task_switch_sync(tn, _task_switch_status(tn));
122 | }
123 | irq_restore(iflag);
124 | return;
125 | }
126 | irq_restore(iflag);
127 | _assert(0);
128 | }
129 |
130 | void sch_add(task_t * t)
131 | {
132 | unsigned *l2, *l1;
133 |
134 | l2 = map_l2 + (t->pri >> 5);
135 | *l2 = BI_O_BIT(*l2, t->pri & 0x1f);
136 | l1 = map_l1 + (t->pri >> 10);
137 | *l1 = BI_O_BIT(*l1, ((t->pri >> 5) & 0x1f));
138 | ll_addt(&task_ready[t->pri], &t->ll);
139 | }
140 |
141 | void sch_del(task_t * t)
142 | {
143 | lle_del(&t->ll);
144 | if (ll_empty(&task_ready[t->pri])) {
145 |
146 | unsigned *l2, *l1;
147 |
148 | l2 = map_l2 + (t->pri >> 5);
149 | *l2 = BI_Z_BIT(*l2, t->pri & 0x1f);
150 |
151 | if (*l2 == 0) {
152 | l1 = map_l1 + (t->pri >> 10);
153 | *l1 = BI_Z_BIT(*l1, ((t->pri >> 5) & 0x1f));
154 | }
155 | }
156 | }
157 |
158 | #else
159 | #error "no scheduler config"
160 | #endif
161 |
162 | void sch_tick(void)
163 | {
164 | task_t *tn, *tc;
165 |
166 | tc = _task_cur;
167 |
168 | if (tc->slice_cur > 0)
169 | tc->slice_cur--;
170 | if (tc->slice_cur == 0 && !ll_empty(&task_ready[tc->pri])) {
171 |
172 | tn = lle_get(ll_head(&task_ready[tc->pri]), task_t, ll);
173 | _task_switch_pend(tn);
174 | }
175 | }
176 |
177 | void sch_wake(task_t * t)
178 | {
179 | t->status = TASK_READY;
180 | sch_add(t);
181 | if (t->pri < _task_cur->pri) {
182 | if (irq_act())
183 | _task_switch_pend(t);
184 | else
185 | _task_switch_sync(t, _task_switch_status(t));
186 | }
187 | }
188 |
189 | void sch_init()
190 | {
191 | int i;
192 | for (i = 1; i < CFG_TPRI_NUM; i++)
193 | ll_init(&task_ready[i]);
194 | }
195 |
--------------------------------------------------------------------------------
/src/sem.c:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #include "sem.h"
28 | #include "ll.h"
29 | #include "task.h"
30 | #include "irq.h"
31 | #include
32 |
33 | sem_t *sem_init(sem_t * s, int init_val)
34 | {
35 | memset(s, 0, sizeof(*s));
36 | ll_init(&s->wait);
37 | s->val = init_val;
38 | return s;
39 | }
40 |
41 | int sem_get_wait(sem_t * s, wait_t w, unsigned iflag)
42 | {
43 | if (task_suspend(&s->wait, w)) {
44 | irq_restore(iflag);
45 | return -1;
46 | } else {
47 | _assert(s->val > 0);
48 | s->val--;
49 | irq_restore(iflag);
50 | return 0;
51 | }
52 | }
53 |
54 | void sem_post_wake(sem_t * s)
55 | {
56 | task_wakeq(&s->wait);
57 | }
58 |
59 | int sem_post(sem_t * s)
60 | {
61 | return sem_post_n(s, 1);
62 | }
63 |
--------------------------------------------------------------------------------
/src/tmr_impl.h:
--------------------------------------------------------------------------------
1 | /*-****************************************************************************/
2 | /*- */
3 | /*- Copyright (c) of hyperCOS. */
4 | /*- */
5 | /*- This software is copyrighted by and is the sole property of socware.net. */
6 | /*- All rights, title, ownership, or other interests in the software remain */
7 | /*- the property of socware.net. The source code is FREE for short-term */
8 | /*- evaluation, educational or non-commercial research only. Any commercial */
9 | /*- application may only be used in accordance with the corresponding license*/
10 | /*- agreement. Any unauthorized use, duplication, transmission, distribution,*/
11 | /*- or disclosure of this software is expressly forbidden. */
12 | /*- */
13 | /*- Knowledge of the source code may NOT be used to develop a similar product*/
14 | /*- */
15 | /*- This Copyright notice may not be removed or modified without prior */
16 | /*- written consent of socware.net. */
17 | /*- */
18 | /*- socware.net reserves the right to modify this software */
19 | /*- without notice. */
20 | /*- */
21 | /*- To contact socware.net: */
22 | /*- */
23 | /*- socware.help@gmail.com */
24 | /*- */
25 | /*-****************************************************************************/
26 |
27 | #ifndef TMRIMPL0424
28 | #define TMRIMPL0424
29 |
30 | void tmr_init_sys(void);
31 |
32 | extern unsigned tmr_rtcs;
33 |
34 | int tmr_tickless();
35 |
36 | void tmr_tickless_end();
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------