├── COPYING ├── MAINTAINER ├── TODO ├── ctags.sh ├── doxygen.conf ├── env ├── arm7 │ ├── Makefile │ ├── at91sam7x256.h │ ├── at91sam7x256.x │ ├── crt.S │ ├── env.c │ ├── env.h │ ├── gdbrc │ ├── lib_at91sam7x256.h │ ├── lpc2xxx.h │ ├── openocd.gpnvm │ ├── openocd.olimex.debug.gen │ ├── openocd.olimex.flash.gen │ ├── openocd.olimex.flash.go.gen │ ├── sys_call.c │ ├── sys_call.h │ └── types.h ├── avr5 │ ├── Makefile │ ├── env.c │ ├── env.h │ ├── gdbrc │ ├── mangle.spec │ └── types.h ├── env.h ├── gba │ ├── Makefile │ ├── arm7.c │ ├── arm7.h │ ├── bios.S │ ├── crt.S │ ├── env.c │ ├── env.h │ ├── gba.h │ ├── gba.x │ ├── gba_timer.h │ ├── gdbrc │ ├── make_bios.sh │ ├── sys_call.c │ ├── sys_call.h │ └── types.h ├── m16c │ ├── Makefile │ ├── crt.S │ ├── env.c │ ├── env.h │ ├── interrupts.h │ ├── iom16c62.h │ ├── m16c.x │ └── types.h ├── m16c_srp │ ├── Makefile │ ├── crt.S │ ├── env.c │ ├── env.h │ ├── interrupts.h │ ├── iom16c62.h │ ├── m16c.x │ └── types.h ├── mips │ ├── Makefile │ ├── env.c │ ├── env.h │ ├── env_asm.S │ ├── mangle.spec │ ├── mips-r3k-syncsim.x │ └── types.h ├── msp430 │ ├── Makefile │ ├── env.c │ ├── env.h │ ├── gdbrc │ ├── mangle.spec │ └── types.h ├── msp430_srp │ ├── Makefile │ ├── env.c │ ├── env.h │ ├── gdbrc │ ├── mangle.spec │ └── types.h ├── pic18 │ ├── 18f4620.lkr │ ├── 18f4620_e.lkr │ ├── env.c │ ├── env.h │ ├── mangle.spec │ └── types.h ├── posix │ ├── Makefile │ ├── ack.c │ ├── ack.h │ ├── env.c │ ├── env.h │ └── types.h ├── posix_srp │ ├── Makefile │ ├── env.c │ ├── env.h │ └── types.h ├── skel │ ├── Makefile │ ├── env.c │ ├── env.h │ └── types.h └── types.h ├── examples ├── Makefile ├── doxygen │ └── tt_action.c ├── hello_world │ ├── Makefile │ └── src │ │ ├── Makefile │ │ └── main.c ├── hello_world_srp │ ├── Makefile │ └── src │ │ ├── Makefile │ │ ├── app_objects.h │ │ └── main.c └── srp │ ├── Makefile │ └── src │ ├── Makefile │ ├── app_objects.h │ └── main.c ├── mangle.sh └── tT ├── Makefile ├── kernel.c ├── kernel.h ├── kernel_srp.c ├── kernel_srp.h ├── objects_srp.c ├── objects_srp.h └── tT.h /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 2 | Simon Aittamaa. 3 | 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the Luleå University of Technology nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 21 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /MAINTAINER: -------------------------------------------------------------------------------- 1 | Current maintainer (Fri Jan 25 09:00:51 CET 2008): 2 | Simon Aittamaa 3 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | 2 | NOTE: 3 | The items are not in any order just in the order I cam up with them ;) 4 | 5 | env/*: 6 | 7 | * Look into the timer code on all environments, there are some edge 8 | cases that will make the code behave strangely :/ 9 | 10 | * Figure out why the MSP430 environment breaks when taking overflow 11 | into account in the timer_get() function, until then we will take 12 | the long way around and just generate those extra interrupts. 13 | 14 | * Draw out guidelines for pre-emptive interrupts. This will allow the 15 | kernel to leave protected mode while doing some things, such as 16 | setting up variables and copying memory. 17 | 18 | env/arm7: 19 | 20 | * Figure out how to do this sligthly more portable? Or should we just live 21 | with separate runtimes for the different models... Proabably the only 22 | "sane" solution :/ 23 | 24 | * Fix the AIC code so that nested interrupts are supported... 25 | -------------------------------------------------------------------------------- /ctags.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ctags --recurse --language-force=c --fields=fkmsS * 3 | -------------------------------------------------------------------------------- /env/arm7/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef ENV_ROOT 10 | $(error Variable ENV_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Sanity check since and SRP environment is quite different. 15 | ################################################################################ 16 | ifdef SRP 17 | $(error Environment does not support SRP.) 18 | endif 19 | 20 | ################################################################################ 21 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 22 | ################################################################################ 23 | 24 | CC := arm-elf-gcc 25 | ASFLAGS := -mthumb-interwork 26 | CFLAGS := -DENV_ARM7=1 -O2 -gstabs+ -Wall -mthumb-interwork\ 27 | -I$(ENV_ROOT) -mcpu=arm7tdmi $(CFLAGS) 28 | LDFLAGS := -Wl,-T$(ENV_ROOT)/$(ENV)/at91sam7x256.x $(LDFLAGS)\ 29 | -mthumb-interwork -nostartfiles -mcpu=arm7tdmi 30 | 31 | ################################################################################ 32 | # Setup the rules for building the required object files from the source. 33 | ################################################################################ 34 | 35 | $(BUILD_ROOT)/crt.o: $(ENV_ROOT)/$(ENV)/crt.S 36 | $(CC) $(ASFLAGS) $< -c -o $@ 37 | 38 | $(BUILD_ROOT)/env.o: $(ENV_ROOT)/$(ENV)/env.c 39 | $(CC) $(CFLAGS) $< -c -o $@ 40 | 41 | $(BUILD_ROOT)/sys_call.o: $(ENV_ROOT)/$(ENV)/sys_call.c 42 | $(CC) $(CFLAGS) $< -c -o $@ 43 | 44 | ################################################################################ 45 | # Setup the required objects for the enviroment sources. 46 | ################################################################################ 47 | 48 | ENV_OBJECTS := $(BUILD_ROOT)/crt.o\ 49 | $(BUILD_ROOT)/env.o\ 50 | $(BUILD_ROOT)/sys_call.o 51 | 52 | ################################################################################ 53 | # 54 | # ARM7 Specific targets, nothing portable to see here... 55 | # 56 | ################################################################################ 57 | 58 | OPENOCD_BINARY = $(BUILD_ROOT)/openocd_binary.bin 59 | OPENOCD_DEBUG = $(BUILD_ROOT)/openocd.olimex.debug 60 | OPENOCD_FLASH = $(BUILD_ROOT)/openocd.olimex.flash 61 | OPENOCD_FLASH_GO = $(BUILD_ROOT)/openocd.olimex.flash.go 62 | 63 | $(OPENOCD_DEBUG): $(BUILD_ROOT) 64 | $(ENV_ROOT)/$(ENV)/openocd.olimex.debug.gen > $@ 65 | 66 | $(OPENOCD_FLASH): $(BUILD_ROOT) 67 | $(ENV_ROOT)/$(ENV)/openocd.olimex.flash.gen "${OPENOCD_FLASH_GO}" > $@ 68 | 69 | $(OPENOCD_FLASH_GO): $(BUILD_ROOT) 70 | $(ENV_ROOT)/$(ENV)/openocd.olimex.flash.go.gen "${OPENOCD_BINARY}" > $@ 71 | 72 | $(OPENOCD_BINARY): $(APP_BINARY) 73 | arm-elf-objcopy -O binary --strip-all $(APP_BINARY) $@ 74 | 75 | flash: $(OPENOCD_FLASH) $(OPENOCD_FLASH_GO) $(OPENOCD_BINARY) 76 | sudo openocd --file $(OPENOCD_FLASH) 77 | 78 | debug: 79 | arm-elf-gdb -x $(ENV_ROOT)/$(ENV)/gdbrc $(APP_BINARY) 80 | 81 | debug_launch: $(OPENOCD_DEBUG) 82 | sudo openocd --file $(OPENOCD_DEBUG) > /dev/null 83 | -------------------------------------------------------------------------------- /env/arm7/at91sam7x256.x: -------------------------------------------------------------------------------- 1 | /* Set the entry point, warning if we mess up. */ 2 | ENTRY(__vec_reset); 3 | 4 | /* Setup the memory layout. */ 5 | MEMORY 6 | { 7 | flash : ORIGIN = 0x100000, LENGTH = 256K 8 | ram : ORIGIN = 0x200000, LENGTH = 64K 9 | } 10 | 11 | /* Provide some information about where some areas start and end. */ 12 | __flash_start = 0x100000; 13 | __flash_end = 0x13ffff; 14 | __ram_start = 0x200000; 15 | __ram_end = 0x20fffc; 16 | 17 | /* The sections of the object file. */ 18 | SECTIONS 19 | { 20 | /* Start at flash. */ 21 | . = 0; 22 | 23 | /* Data section, copied by our crt from flash to ram. 24 | * 25 | * NOTE: 26 | * The .data section must come BEFORE the .text section. This is just 27 | * because we wish for the .vectors to be located at offset 0 in the flash 28 | * where the initializer data is stored. 29 | */ 30 | .data : 31 | { 32 | /* This is where the data starts. */ 33 | *(.vectors); 34 | *(.data); 35 | *(.forced_ram); /* This is the forced ram section. */ 36 | . = ALIGN(4); 37 | } > ram AT > flash 38 | 39 | /* We need this to copy the data. */ 40 | __data_start = LOADADDR(.data); 41 | __data_end = LOADADDR(.data) + SIZEOF(.data); 42 | 43 | /* 44 | * BSS section, intialized to zero. This doesn't strictly have to be 45 | * before the .text section but let's keep the RAM stuff together. 46 | */ 47 | .bss : 48 | { 49 | __bss_start = .; 50 | *(.bss); 51 | . = ALIGN(4); 52 | *(COMMON); 53 | . = ALIGN(4); 54 | __bss_end = .; 55 | } > ram 56 | 57 | /* Provide and _end variable, usefull for malloc & co. */ 58 | _end = ADDR(.bss) + SIZEOF(.bss); 59 | 60 | /* Text section. */ 61 | .text : 62 | { 63 | *(.text); 64 | *(.rodata); 65 | *(.rodata*); 66 | *(.glue_7); 67 | *(.glue_7t); 68 | . = ALIGN(4); 69 | } > flash 70 | } 71 | -------------------------------------------------------------------------------- /env/arm7/gdbrc: -------------------------------------------------------------------------------- 1 | #file arm7/app.elf 2 | set watchdog 0 3 | target remote localhost:2000 4 | monitor arm7_9 force_hw_bkpts enable 5 | 6 | define show_us0 7 | printf "US_CSR: %08x\n", ((AT91S_USART*)0xfffC0000).US_CSR 8 | printf "US_MR: %08x\n", ((AT91S_USART*)0xfffC0000).US_MR 9 | printf "US_IMR: %08x\n", ((AT91S_USART*)0xfffC0000).US_IMR 10 | printf "US_BRGR: %08x\n", ((AT91S_USART*)0xfffC0000).US_BRGR 11 | end 12 | 13 | define show_us1 14 | printf "US_CSR: %08x\n", ((AT91S_USART*)0xfffC4000).US_CSR 15 | printf "US_MR: %08x\n", ((AT91S_USART*)0xfffC4000).US_MR 16 | printf "US_IMR: %08x\n", ((AT91S_USART*)0xfffC4000).US_IMR 17 | printf "US_BRGR: %08x\n", ((AT91S_USART*)0xfffC4000).US_BRGR 18 | end 19 | 20 | define show_pmc 21 | printf "PMC_SR: %08x\n", ((AT91S_PMC*)0xfffffC00).PMC_SR 22 | printf "PMC_SCSR: %08x\n", ((AT91S_PMC*)0xfffffC00).PMC_SCSR 23 | printf "PMC_PCSR: %08x\n", ((AT91S_PMC*)0xfffffC00).PMC_PCSR 24 | printf "PMC_MCKR: %08x\n", ((AT91S_PMC*)0xfffffC00).PMC_MCKR 25 | printf "PMC_MCfR: %08x\n", ((AT91S_PMC*)0xfffffC00).PMC_MCFR 26 | printf "PMC_PLLR: %08x\n", ((AT91S_PMC*)0xfffffC00).PMC_PLLR 27 | printf "PMC_MCKR: %08x\n", ((AT91S_PMC*)0xfffffC00).PMC_MCKR 28 | end 29 | 30 | define show_pioa 31 | printf "PIO_PSR: %08x\n", ((AT91S_PIO*)0xfffff400).PIO_PSR 32 | printf "PIO_OSR: %08x\n", ((AT91S_PIO*)0xfffff400).PIO_OSR 33 | printf "PIO_ISR: %08x\n", ((AT91S_PIO*)0xfffff400).PIO_ISR 34 | printf "PIO_ODSR: %08x\n", ((AT91S_PIO*)0xfffff400).PIO_ODSR 35 | printf "PIO_ISR: %08x\n", ((AT91S_PIO*)0xfffff400).PIO_ISR 36 | printf "PIO_MDSR: %08x\n", ((AT91S_PIO*)0xfffff400).PIO_MDSR 37 | printf "PIO_PPUSR: %08x\n", ((AT91S_PIO*)0xfffff400).PIO_PPUSR 38 | printf "PIO_ABSR: %08x\n", ((AT91S_PIO*)0xfffff400).PIO_ABSR 39 | printf "PIO_OWSR: %08x\n", ((AT91S_PIO*)0xfffff400).PIO_OWSR 40 | end 41 | 42 | define show_piob 43 | printf "PIO_PSR: %08x\n", ((AT91S_PIO*)0xfffff600).PIO_PSR 44 | printf "PIO_OSR: %08x\n", ((AT91S_PIO*)0xfffff600).PIO_OSR 45 | printf "PIO_ISR: %08x\n", ((AT91S_PIO*)0xfffff600).PIO_ISR 46 | printf "PIO_ODSR: %08x\n", ((AT91S_PIO*)0xfffff600).PIO_ODSR 47 | printf "PIO_PDSR: %08x\n", ((AT91S_PIO*)0xfffff600).PIO_PDSR 48 | printf "PIO_ISR: %08x\n", ((AT91S_PIO*)0xfffff600).PIO_ISR 49 | printf "PIO_MDSR: %08x\n", ((AT91S_PIO*)0xfffff600).PIO_MDSR 50 | printf "PIO_PPUSR: %08x\n", ((AT91S_PIO*)0xfffff600).PIO_PPUSR 51 | printf "PIO_ABSR: %08x\n", ((AT91S_PIO*)0xfffff600).PIO_ABSR 52 | printf "PIO_OWSR: %08x\n", ((AT91S_PIO*)0xfffff600).PIO_OWSR 53 | end 54 | 55 | define show_tc0 56 | printf "TCO_CMR: %08x\n", ((AT91S_TC*)0xfffa0000).TC_CMR 57 | printf "TCO_CV: %08x\n", ((AT91S_TC*)0xfffa0000).TC_CV 58 | printf "TCO_RA: %08x\n", ((AT91S_TC*)0xfffa0000).TC_RA 59 | printf "TCO_RB: %08x\n", ((AT91S_TC*)0xfffa0000).TC_RB 60 | printf "TCO_RC: %08x\n", ((AT91S_TC*)0xfffa0000).TC_RC 61 | printf "TCO_SR: %08x\n", ((AT91S_TC*)0xfffa0000).TC_SR 62 | printf "TC0_IMR: %08x\n", ((AT91S_TC*)0xfffa0000).TC_IMR 63 | end 64 | 65 | define show_tc1 66 | printf "TC1_CMR: %08x\n", ((AT91S_TC*)0xfffa0040).TC_CMR 67 | printf "TC1_CV: %08x\n", ((AT91S_TC*)0xfffa0040).TC_CV 68 | printf "TC1_RA: %08x\n", ((AT91S_TC*)0xfffa0040).TC_RA 69 | printf "TC1_RB: %08x\n", ((AT91S_TC*)0xfffa0040).TC_RB 70 | printf "TC1_RC: %08x\n", ((AT91S_TC*)0xfffa0040).TC_RC 71 | printf "TC1_SR: %08x\n", ((AT91S_TC*)0xfffa0040).TC_SR 72 | printf "TC1_IMR: %08x\n", ((AT91S_TC*)0xfffa0040).TC_IMR 73 | end 74 | 75 | define show_tc2 76 | printf "TC2_CMR: %08x\n", ((AT91S_TC*)0xfffa0080).TC_CMR 77 | printf "TC2_CV: %08x\n", ((AT91S_TC*)0xfffa0080).TC_CV 78 | printf "TC2_RA: %08x\n", ((AT91S_TC*)0xfffa0080).TC_RA 79 | printf "TC2_RB: %08x\n", ((AT91S_TC*)0xfffa0080).TC_RB 80 | printf "TC2_RC: %08x\n", ((AT91S_TC*)0xfffa0080).TC_RC 81 | printf "TC2_SR: %08x\n", ((AT91S_TC*)0xfffa0080).TC_SR 82 | printf "TC2_IMR: %08x\n", ((AT91S_TC*)0xfffa0080).TC_IMR 83 | end 84 | 85 | define show_tcb 86 | printf "TCB_BMR: %08x\n", ((AT91S_TCB*)0xfffa0000).TCB_BMR 87 | show_tc0 88 | show_tc1 89 | show_tc2 90 | end 91 | -------------------------------------------------------------------------------- /env/arm7/lib_at91sam7x256.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simait/TinyTimber/52e5ac37327be47427acd5d385974a3831a10c32/env/arm7/lib_at91sam7x256.h -------------------------------------------------------------------------------- /env/arm7/openocd.gpnvm: -------------------------------------------------------------------------------- 1 | wait_halt 2 | mdw 0xffffff68 3 | mww 0xffffff64 0x5a00020b 4 | mdw 0xffffff68 5 | -------------------------------------------------------------------------------- /env/arm7/openocd.olimex.debug.gen: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cat < 29 | #target arm7tdmi 30 | target arm7tdmi little run_and_halt 0 arm7tdmi 31 | run_and_halt_time 0 1 32 | 33 | # flash-options AT91 34 | working_area 0 0x00200000 0x4000 nobackup 35 | flash bank at91sam7 0 0 0 0 0 36 | HERE 37 | -------------------------------------------------------------------------------- /env/arm7/openocd.olimex.flash.gen: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if test $# -ne 1 4 | then 5 | echo "No reset target script specified, unable to generate OpenOCD script." 6 | exit 1 7 | fi 8 | 9 | cat < 35 | #target arm7tdmi 36 | target arm7tdmi little run_and_init 0 arm7tdmi 37 | run_and_halt_time 0 30 38 | 39 | # setup the reset script 40 | target_script 0 reset "$1" 41 | 42 | # flash-options AT91 43 | working_area 0 0x00200000 0x4000 nobackup 44 | flash bank at91sam7 0 0 0 0 0 45 | HERE 46 | -------------------------------------------------------------------------------- /env/arm7/openocd.olimex.flash.go.gen: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if test $# -ne 1 4 | then 5 | echo "No binary file was specified, unable to generate OpenOCD script." 6 | exit 1 7 | fi 8 | 9 | cat < 32 | #include 33 | 34 | /* ************************************************************************** */ 35 | 36 | typedef void (*arm7_sys_call_t)(void); 37 | 38 | /* ************************************************************************** */ 39 | 40 | /** 41 | * \cond 42 | * 43 | * Just forward all system call implementations so that we can use them in 44 | * the table, no need for parameter correctness as we just want the address. 45 | */ 46 | 47 | /** 48 | * \endcond 49 | */ 50 | 51 | /** 52 | * \brief 53 | * System call table, used to determine which system call should 54 | * be issued. 55 | */ 56 | arm7_sys_call_t arm7_sys_call_table[] = 57 | { 58 | (arm7_sys_call_t)_arm7_context_dispatch 59 | }; 60 | 61 | /* ************************************************************************** */ 62 | 63 | /** 64 | * \cond 65 | * 66 | * System call binding, used to get the mapping of syscall id to function. 67 | */ 68 | 69 | /** 70 | * \endcond 71 | */ 72 | 73 | /* ************************************************************************** */ 74 | 75 | /** 76 | * \brief ARM7 system call entry point. 77 | * 78 | * A system call should be treated as a simple C function call. We just 79 | * need some magic to make the syscall id translate into a C function. 80 | * 81 | * \todo Perform a sanity check that the system call id is valid. 82 | */ 83 | ENV_EXT_FORCE_RAM __attribute__((naked)) void arm7_sys_call(void) 84 | { 85 | /* 86 | * Adjudt the link register so that we can treat this as a regular 87 | * interrupt ie. use save/restore context macros. 88 | */ 89 | asm volatile("add lr, lr, #4\n"); 90 | 91 | /* 92 | * Save context, we must do this since we don't know if the system 93 | * call will possibly switch the context... 94 | */ 95 | ARM7_CONTEXT_SAVE(); 96 | 97 | asm volatile 98 | ( 99 | /* 100 | * r0-r3 may or may not hold parameters, let's assume they do 101 | * and use r4 and r5 as temporary. Please note that _all_ user 102 | * mode registers are saved but registers r0-r3 are used for 103 | * parameter passing thus we wish to keep them intact so that 104 | * we do not have to take anything special into conisderation 105 | * when dealing with the system calls. 106 | */ 107 | "ldr r4, [lr, #-8]\n" 108 | "and r4, r4, #0xffffff\n" 109 | "ldr r5, =arm7_sys_call_table\n" 110 | "ldr r4, [r5, r4, lsl #2]\n" 111 | "mov lr, pc\n" 112 | "mov pc, r4\n" 113 | ); 114 | 115 | /* Restore the context, might be same context or new context. */ 116 | ARM7_CONTEXT_RESTORE(); 117 | } 118 | -------------------------------------------------------------------------------- /env/arm7/sys_call.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ENV_ARM7_ARM7_SYS_CALL_H_ 32 | #define ENV_ARM7_ARM7_SYS_CALL_H_ 33 | 34 | /* ************************************************************************** */ 35 | 36 | #define ARM7_SYS_CALL_BIND(function, id) \ 37 | __attribute__((naked)) function\ 38 | {\ 39 | asm volatile(\ 40 | "swi %0\n"\ 41 | "mov pc, lr\n"\ 42 | :: "I" (id)\ 43 | );\ 44 | } 45 | 46 | /* ************************************************************************** */ 47 | 48 | /** 49 | * \brief ARM7 system call enum 50 | */ 51 | enum 52 | { 53 | /** 54 | * \brief Dispatch system call id. 55 | */ 56 | ARM7_SYS_CALL_DISPATCH = 0, 57 | 58 | /** 59 | * \brief The last system call id + 1, needed for sanity. 60 | */ 61 | ARM7_SYS_CALL_MAX 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /env/arm7/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /** 32 | * \brief Skeleton environment types. 33 | * 34 | * Just used for compile testing and perhaps as a template for a new 35 | * environment. Should compile but does not run. 36 | */ 37 | #ifndef ENV_ARM7_TYPES_H_ 38 | #define ENV_ARM7_TYPES_H_ 39 | 40 | /** 41 | * \brief ARM7 context typedef. 42 | */ 43 | typedef struct arm7_context_t 44 | { 45 | /** 46 | * \brief The stack pointer. 47 | */ 48 | unsigned int *sp; 49 | 50 | /** 51 | * \brief The context cookie pointer. 52 | */ 53 | unsigned int *cookie; 54 | } arm7_context_t; 55 | 56 | /** 57 | * \brief Environment context typedef. 58 | * 59 | * Should evalutate to the type that is used to store the context of a 60 | * thread. 61 | */ 62 | typedef arm7_context_t env_context_t; 63 | 64 | /** 65 | * \brief Environment result typdef. 66 | * 67 | * Should evaluate to the result of a synchronus function call. 68 | */ 69 | typedef int env_result_t; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /env/avr5/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef ENV_ROOT 10 | $(error Variable ENV_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Sanity check since and SRP environment is quite different. 15 | ################################################################################ 16 | ifdef SRP 17 | $(error Environment does not support SRP.) 18 | endif 19 | 20 | ################################################################################ 21 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 22 | ################################################################################ 23 | 24 | CC := avr-gcc 25 | CFLAGS := -DENV_AVR5=1 -mmcu=at90can128 -O2 -Wall -I$(ENV_ROOT) $(CFLAGS) 26 | 27 | ################################################################################ 28 | # Setup the rules for building the required object files from the source. 29 | ################################################################################ 30 | 31 | $(BUILD_ROOT)/env.o: $(ENV_ROOT)/$(ENV)/env.c 32 | $(CC) $(CFLAGS) $< -c -o $@ 33 | 34 | ################################################################################ 35 | # Setup the required objects for the enviroment sources. 36 | ################################################################################ 37 | 38 | ENV_OBJECTS := $(BUILD_ROOT)/env.o 39 | -------------------------------------------------------------------------------- /env/avr5/gdbrc: -------------------------------------------------------------------------------- 1 | file main.elf 2 | set watchdog 0 3 | target remote :2000 4 | -------------------------------------------------------------------------------- /env/avr5/mangle.spec: -------------------------------------------------------------------------------- 1 | TT_C=env/avr5/env.c _KERNEL_ 2 | TT_H=env/avr5/types.h env/types.h _TT_ _KERNEL_ env/avr5/env.h _ENV_ 3 | -------------------------------------------------------------------------------- /env/avr5/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ENV_AVR_TYPES_H_ 32 | #define ENV_AVR_TYPES_H_ 33 | 34 | /** 35 | * \brief The AVR context typedef. 36 | */ 37 | typedef struct avr5_context_t 38 | { 39 | /** 40 | * \brief The stackpointer. 41 | */ 42 | char *sp; 43 | 44 | /** 45 | * \brief The magic cookie pointer. 46 | */ 47 | unsigned short *cookie; 48 | } avr5_context_t; 49 | 50 | /* ************************************************************************** */ 51 | 52 | /** 53 | * \brief Export of avr context as env_context_t. 54 | */ 55 | typedef avr5_context_t env_context_t; 56 | 57 | /* ************************************************************************** */ 58 | 59 | /** 60 | * \brief The AVR result typedef. 61 | */ 62 | typedef unsigned long env_result_t; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /env/env.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ENV_H_ 32 | #define ENV_H_ 33 | 34 | #if ! defined TT_MANGLED 35 | # if defined ENV_POSIX 36 | # include "posix/env.h" 37 | # elif defined ENV_POSIX_SRP 38 | # include "posix_srp/env.h" 39 | # elif defined ENV_MSP430 40 | # include "msp430/env.h" 41 | # elif defined ENV_MSP430_SRP 42 | # include "msp430_srp/env.h" 43 | # elif defined ENV_AVR5 44 | # include "avr5/env.h" 45 | # elif defined ENV_PIC18 46 | # include "pic18/env.h" 47 | # elif defined ENV_ARM7 48 | # include "arm7/env.h" 49 | # elif defined ENV_GBA 50 | # include "gba/env.h" 51 | # elif defined ENV_MIPS 52 | # include "mips/env.h" 53 | # elif defined ENV_M16C 54 | # include "m16c/env.h" 55 | # elif defined ENV_M16C_SRP 56 | # include "m16c_srp/env.h" 57 | # elif defined ENV_SKEL 58 | # include "skel/env.h" 59 | # else 60 | # error Unknown environment. 61 | # endif 62 | #endif 63 | 64 | /* ************************************************************************** */ 65 | /* ********************************** DEFAULT ******************************* */ 66 | /* ************************************************************************** */ 67 | 68 | /** 69 | * \brief Environment inline macro. 70 | * 71 | * If the environment did not supply a definition for this then default to 72 | * nothing. Not all environments allow for the inline keyword(it's C99 not C89). 73 | */ 74 | #ifndef ENV_INLINE 75 | # define ENV_INLINE 76 | #endif 77 | 78 | /** 79 | * \brief Environment priority reset macro. 80 | * 81 | * Not always required by the environment so should evaluate to a void 82 | * expression if not defined. 83 | */ 84 | #ifndef ENV_INTERRUPT_PRIORITY_RESET 85 | # define ENV_INTERRUPT_PRIORITY_RESET() ((void)0) 86 | #endif 87 | 88 | /** 89 | * \brief Environment fast code macro. 90 | * 91 | * If the environment does not supply a defenition for this the default is 92 | * nothing. This really only makes sense on the arm7 where we want to force 93 | * the linking of the functions into SRAM since it's the only thing that is 94 | * read in 1 cycle. 95 | */ 96 | #ifndef ENV_CODE_FAST 97 | # define ENV_CODE_FAST 98 | #endif 99 | 100 | /** 101 | * \brief Environment debug macro. 102 | * 103 | * The debug macro is NOT neccesary but can be helpfull. 104 | */ 105 | 106 | #ifndef ENV_DEBUG 107 | # define ENV_DEBUG(msg) ((void)0) 108 | #endif 109 | 110 | /* ************************************************************************** */ 111 | /* *********************************** SANITY ******************************* */ 112 | /* ************************************************************************** */ 113 | 114 | #ifndef ENV_INIT 115 | # error Environment did not define ENV_INIT(). 116 | #endif 117 | 118 | #ifndef ENV_PROTECT 119 | # error Environment did not define ENV_PROTECT(). 120 | #endif 121 | 122 | #ifndef ENV_ISPROTECTED 123 | # error Environment did not define ENV_PROTECTED(). 124 | #endif 125 | 126 | #ifndef ENV_PANIC 127 | # error Environment did not define ENV_PANIC(). 128 | #endif 129 | 130 | #ifndef ENV_IDLE 131 | # error Environment did not define ENV_IDLE() 132 | #endif 133 | 134 | #ifndef ENV_TIMER_START 135 | # error Environment did not define ENV_TIMER_START(). 136 | #endif 137 | 138 | #ifndef ENV_TIMER_SET 139 | # error Environment did not define ENV_TIMER_SET(). 140 | #endif 141 | 142 | #ifndef ENV_TIMER_GET 143 | # error Environment did not define ENV_TIMER_GET(). 144 | #endif 145 | 146 | #ifndef ENV_TIMESTAMP 147 | # error Environment did not define ENV_TIMESTAMP(). 148 | #endif 149 | 150 | #ifndef ENV_USEC 151 | # error Environment did not define ENV_USEC(). 152 | #endif 153 | 154 | #ifndef ENV_MSEC 155 | # error Environment did not define ENV_MSEC(). 156 | #endif 157 | 158 | #ifndef ENV_SEC 159 | # error Environment did not define ENV_SEC(). 160 | #endif 161 | 162 | #ifndef ENV_STARTUP 163 | # error Environment did not define ENV_STARTUP(). 164 | #endif 165 | 166 | /* ************************************************************************** */ 167 | /* ***************************** SANITY (NON-SRP) *************************** */ 168 | /* ************************************************************************** */ 169 | 170 | #if defined ENV_SRP 171 | 172 | # ifdef ENV_NUM_THREADS 173 | # warning Environment defined ENV_NUM_THREADS?!? 174 | # endif 175 | 176 | # ifdef ENV_CONTEXT_INIT 177 | # warning Environment defined ENV_CONTEXT_INIT?!? 178 | # endif 179 | 180 | # ifdef ENV_CONTEXT_DISPATCH 181 | # warning Environment defined ENV_CONTEXT_DISPATCH?!? 182 | # endif 183 | 184 | #else 185 | 186 | # ifndef ENV_NUM_THREADS 187 | # error Environment did not define ENV_NUM_THREADS. 188 | # endif 189 | 190 | # ifndef ENV_CONTEXT_INIT 191 | # error Environment did not define ENV_CONTEXT_INIT(). 192 | # endif 193 | 194 | # ifndef ENV_CONTEXT_DISPATCH 195 | # error Environment did not define ENV_CONTEXT_DISPATCH(). 196 | # endif 197 | 198 | #endif 199 | 200 | #endif 201 | -------------------------------------------------------------------------------- /env/gba/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef ENV_ROOT 10 | $(error Variable ENV_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Sanity check since and SRP environment is quite different. 15 | ################################################################################ 16 | ifdef SRP 17 | $(error Environment does not support SRP.) 18 | endif 19 | 20 | ################################################################################ 21 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 22 | ################################################################################ 23 | 24 | CC := arm-elf-gcc 25 | AS := arm-elf-as 26 | ASFLAGS := -mthumb-interwork -mcpu=arm7tdmi 27 | CFLAGS := -DENV_GBA=1 -O2 -gstabs+ -Wall -mthumb-interwork -fPIC\ 28 | -I$(ENV_ROOT) -mcpu=arm7tdmi $(CFLAGS) 29 | LDFLAGS := -Wl,-T$(ENV_ROOT)/$(ENV)/gba.x $(LDFLAGS)\ 30 | -mthumb-interwork -nostartfiles -mcpu=arm7tdmi 31 | 32 | ################################################################################ 33 | # Setup the rules for building the required object files from the source. 34 | ################################################################################ 35 | 36 | $(BUILD_ROOT)/crt.o: $(ENV_ROOT)/$(ENV)/crt.S 37 | $(AS) $(ASFLAGS) -k -mfloat-abi=soft $< -o $@ 38 | 39 | $(BUILD_ROOT)/bios.o: $(ENV_ROOT)/$(ENV)/bios.S 40 | $(CC) $(ASFLAGS) $< -c -o $@ 41 | 42 | $(BUILD_ROOT)/env.o: $(ENV_ROOT)/$(ENV)/env.c 43 | $(CC) $(CFLAGS) $< -c -o $@ 44 | 45 | $(BUILD_ROOT)/arm7.o: $(ENV_ROOT)/$(ENV)/arm7.c 46 | $(CC) $(CFLAGS) $< -c -o $@ 47 | 48 | $(BUILD_ROOT)/sys_call.o: $(ENV_ROOT)/$(ENV)/sys_call.c 49 | $(CC) $(CFLAGS) $< -c -o $@ 50 | 51 | ################################################################################ 52 | # Setup the required objects for the enviroment sources. 53 | ################################################################################ 54 | 55 | ENV_OBJECTS := $(BUILD_ROOT)/crt.o\ 56 | $(BUILD_ROOT)/bios.o\ 57 | $(BUILD_ROOT)/env.o\ 58 | $(BUILD_ROOT)/arm7.o\ 59 | $(BUILD_ROOT)/sys_call.o 60 | 61 | ################################################################################ 62 | # Setup some special targets fort GBA environment. 63 | ################################################################################ 64 | 65 | GBA_BIOS := $(BUILD_ROOT)/bios.bin 66 | GBA_BINARY := $(BUILD_ROOT)/app.bin 67 | 68 | $(GBA_BIOS): $(APP_BINARY) 69 | $(ENV_ROOT)/$(ENV)/make_bios.sh $(APP_BINARY) $(GBA_BIOS) 70 | 71 | $(GBA_BINARY): $(APP_BINARY) 72 | arm-elf-objcopy -j .text -O binary $(APP_BINARY) $(GBA_BINARY) 73 | 74 | bios: $(GBA_BIOS) 75 | 76 | binary: $(GBA_BINARY) 77 | 78 | run: $(APP_BINARY) $(GBA_BIOS) 79 | VisualBoyAdvance --throttle=100 --bios=$(GBA_BIOS) $(APP_BINARY) 80 | 81 | debug: $(APP_BINARY) $(GBA_BIOS) 82 | VisualBoyAdvance --throttle=100 --bios=$(GBA_BIOS) --gdb=tcp $(APP_BINARY) > /dev/null & 83 | arm-elf-gdb -x $(ENV_ROOT)/$(ENV)/gdbrc $(APP_BINARY) 84 | -------------------------------------------------------------------------------- /env/gba/arm7.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | #include 38 | 39 | /* ************************************************************************** */ 40 | 41 | /** \cond */ 42 | 43 | /* 44 | * The stack for the idle thread and all the other threads. 45 | */ 46 | unsigned char __attribute__((aligned(4))) arm7_stack[ARM7_STACKSIZE]; 47 | 48 | /* ************************************************************************** */ 49 | 50 | /* 51 | * This is an export so that crt.s knows where to place the user/system mode 52 | * stack. 53 | */ 54 | const unsigned int * const arm7_stack_start = 55 | (const unsigned int * const)&arm7_stack[ARM7_STACKSIZE]; 56 | 57 | /* ************************************************************************** */ 58 | 59 | const unsigned int arm7_context_cookie = ARM7_CONTEXT_COOKIE; 60 | 61 | /* ************************************************************************** */ 62 | 63 | /* 64 | * Used in the ENV_CONTEXT_(SAVE|RESTORE) macros. Must not be static or 65 | * the inline asm will not see it :/ 66 | * Makes life easier(tm). 67 | */ 68 | void arm7_context_panic(void) 69 | { 70 | ARM7_BREAK(); 71 | } 72 | 73 | /** \endcond */ 74 | 75 | /* ************************************************************************** */ 76 | 77 | /** 78 | * \brief ARM7 context init function. 79 | * 80 | * \param context The context that should be initialized. 81 | * \param stacksize The size of the stack that should be used. 82 | * \param function The function that should be called. 83 | */ 84 | void arm7_context_init(arm7_context_t *context, size_t stacksize, tt_thread_function_t function) 85 | { 86 | int i; 87 | static unsigned int arm7_stack_offset = ARM7_STACKSIZE-ENV_STACKSIZE_IDLE; 88 | 89 | /* Check for alignment. */ 90 | if (stacksize & 0x3) { 91 | ARM7_BREAK(); 92 | } 93 | 94 | /* Make sure we have enough stack and assign some to the context. */ 95 | if (arm7_stack_offset < stacksize) { 96 | ARM7_BREAK(); 97 | } 98 | 99 | context->sp = (unsigned int *)&arm7_stack[arm7_stack_offset]; 100 | context->cookie = (unsigned int*)&arm7_stack[arm7_stack_offset-stacksize]; 101 | *context->cookie = ARM7_CONTEXT_COOKIE; 102 | 103 | i = (int)context->sp; 104 | 105 | /* Push the return address onto the stack. */ 106 | *(--context->sp) = (unsigned int)function; 107 | 108 | /* Push a bogus link register onto the stack. */ 109 | *(--context->sp) = (unsigned int)0x00000000; 110 | 111 | /* Push the stack pointer onto the stack. */ 112 | *(--context->sp) = (unsigned int)i; 113 | 114 | /* Push some fake registers onto the stack. */ 115 | for (i=13;i>0;i--) 116 | { 117 | *(--context->sp) = i-1; 118 | } 119 | 120 | /* Push the SPSR onto the stack. */ 121 | *(--context->sp) = 0xdf; /* System mode, all interrupts disabled. */ 122 | 123 | /* Save the offset for the next stack. */ 124 | arm7_stack_offset -= stacksize; 125 | } 126 | 127 | /* ************************************************************************** */ 128 | 129 | /** 130 | * \brief ARM7 Context dispatch system call implementation. 131 | */ 132 | void _arm7_context_dispatch(arm7_context_t *new) 133 | { 134 | tt_current = new; 135 | } 136 | 137 | /* ************************************************************************** */ 138 | 139 | /** 140 | * \brief ARM7 Context dispatch system call binding. 141 | */ 142 | ARM7_SYS_CALL_BIND( 143 | void arm7_context_dispatch(env_context_t *thread), 144 | ARM7_SYS_CALL_DISPATCH 145 | ); 146 | 147 | /* ************************************************************************** */ 148 | 149 | /** 150 | * \brief ARM7 protect function. 151 | * 152 | * Used only when protect is called from thumb mode. 153 | * 154 | * \param state non-zero to enter protected mode, zero to leave protected mode. 155 | */ 156 | void _arm7_protect(int state) 157 | { 158 | arm7_protect(state); 159 | } 160 | 161 | /* ************************************************************************** */ 162 | 163 | /** 164 | * \brief ARM7 isprotected function. 165 | * 166 | * Used only when protect is called from thumb mode. 167 | * 168 | * \return non-zero if protected, nonzero otherwise. 169 | */ 170 | int _arm7_isprotected(void) 171 | { 172 | return arm7_isprotected(); 173 | } 174 | 175 | __attribute__((naked)) void _arm7_irq(void) 176 | { 177 | ARM7_CONTEXT_SAVE(); 178 | 179 | /* 180 | * Interrupt handling code goes here, such as figuring out what 181 | * happened (no vectored interrupt conteoller for the GBA). 182 | */ 183 | gba_interrupt(); 184 | 185 | ARM7_CONTEXT_RESTORE(); 186 | } 187 | 188 | __attribute__((naked)) void _arm7_fiq(void) 189 | { 190 | /* This interrupt is not available on the GBA. */ 191 | ARM7_BREAK(); 192 | } 193 | -------------------------------------------------------------------------------- /env/gba/bios.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | .arm 32 | .text 33 | .align 34 | 35 | .extern __flash_start 36 | 37 | .section .bios 38 | __bios_vec_reset: ldr pc, =__flash_start 39 | __bios_vec_undef: ldr pc, =__flash_start+4 40 | __bios_vec_swi: ldr pc, =__flash_start+8 41 | __bios_vec_code_abort: ldr pc, =__flash_start+12 42 | __bios_vec_data_abort: ldr pc, =__flash_start+16 43 | __bios_vec_reserved: nop 44 | __bios_vec_irq: ldr pc, =__flash_start+24 45 | __bios_vec_fiq: ldr pc, =__flash_start+28 46 | -------------------------------------------------------------------------------- /env/gba/env.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ENV_ARM7_ENV_H_ 32 | #define ENV_ARM7_ENV_H_ 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | 41 | /* ************************************************************************** */ 42 | 43 | void gba_init(void); 44 | void gba_idle(void); 45 | void gba_timer_start(void); 46 | void gba_timer_set(env_time_t); 47 | env_time_t gba_timer_get(void); 48 | env_time_t gba_timestamp(void); 49 | void gba_print(const char *); 50 | void gba_panic(const char *); 51 | void gba_schedule(void); 52 | void _gba_schedule(void); 53 | void gba_timer_set(env_time_t); 54 | void gba_interrupt(void); 55 | 56 | /* ************************************************************************** */ 57 | 58 | /** 59 | * \brief Environment initialization. 60 | * 61 | * Should take care of initializing the environment setting up any hardware 62 | * required by the environment such as serial ports, timers etc. 63 | */ 64 | #define ENV_INIT() \ 65 | gba_init() 66 | 67 | /* ************************************************************************** */ 68 | 69 | /** 70 | * \brief Environemnt debug macro. 71 | * 72 | * May print the string pointer to by msg but it is not required. 73 | */ 74 | #define ENV_DEBUG(msg) \ 75 | gba_print(msg) 76 | 77 | /* ************************************************************************** */ 78 | 79 | /** 80 | * \brief Environment panic macro. 81 | * 82 | * Must indicate that a critical error has occured and halt or reset the 83 | * execution. 84 | */ 85 | #define ENV_PANIC(msg) \ 86 | gba_panic(msg) 87 | 88 | /* ************************************************************************** */ 89 | 90 | /** 91 | * \brief Environment idle macro. 92 | * 93 | * Should place the environment in an "idle" state. Can be busy waiting or 94 | * some power-saving mode. The environment must initialize the context pointerd 95 | * to by tt_current so that the kernel can dispatch another thread. 96 | */ 97 | #define ENV_IDLE() \ 98 | gba_idle() 99 | 100 | /* ************************************************************************** */ 101 | 102 | /** 103 | * \brief Environment timer start macro. 104 | * 105 | * Should start the environment timer service. 106 | */ 107 | #define ENV_TIMER_START() \ 108 | gba_timer_start() 109 | 110 | /* ************************************************************************** */ 111 | 112 | /** 113 | * \brief Environment timer set macro. 114 | * 115 | * Should set the time when tt_expired(time) should be called. 116 | */ 117 | #define ENV_TIMER_SET(time) \ 118 | gba_timer_set(time) 119 | 120 | /* ************************************************************************** */ 121 | 122 | /** 123 | * \brief Environment timer get macro. 124 | * 125 | * Should evaluate to the current time. 126 | */ 127 | #define ENV_TIMER_GET() \ 128 | gba_timer_get() 129 | 130 | /* ************************************************************************** */ 131 | 132 | /** 133 | * \brief Environment timestamp macro. 134 | * 135 | * Should evaluate to the time when the most recent interrupt was triggered. 136 | */ 137 | #define ENV_MARK() \ 138 | gba_timer_mark() 139 | 140 | /* ************************************************************************** */ 141 | 142 | /** 143 | * \brief Environment timestamp macro. 144 | * 145 | * Should evaluate to the time when the most recent interrupt was triggered. 146 | */ 147 | #define ENV_TIMESTAMP() \ 148 | gba_timestamp() 149 | 150 | /* ************************************************************************** */ 151 | 152 | /** 153 | * \brief Environment inline macro. 154 | * 155 | * Used to tag functions mainly in the tT kernel for inlining. 156 | */ 157 | #define ENV_INLINE \ 158 | inline 159 | 160 | /* ************************************************************************** */ 161 | 162 | /** 163 | * \brief Environment timer HZ macro. 164 | * 165 | * The timer maximum resolution. 166 | */ 167 | #define ENV_TIMER_HZ ((GBA_CPU_FREQ+255)/256) 168 | 169 | /* ************************************************************************** */ 170 | 171 | /** 172 | * \brief Environment usec macro. 173 | * 174 | * The given number of usecs should be converted to time-base of 175 | * the environment. 176 | */ 177 | #define ENV_USEC(n) ((n*ENV_TIMER_HZ)/100000) 178 | 179 | /* ************************************************************************** */ 180 | 181 | /** 182 | * \brief Environment msec macro. 183 | * 184 | * The given number of msecs should be converted to time-base of 185 | * the environment. 186 | */ 187 | #define ENV_MSEC(n) ((n*ENV_TIMER_HZ)/1000) 188 | 189 | /* ************************************************************************** */ 190 | 191 | /** 192 | * \brief Environment sec macro. 193 | * 194 | * The given number of secs should be converted to time-base of 195 | * the environment. 196 | */ 197 | #define ENV_SEC(n) (n*ENV_TIMER_HZ) 198 | 199 | /* ************************************************************************** */ 200 | 201 | /** 202 | * \brief ARM7 environment extension to force something into the ram. 203 | * 204 | * Usually used for interrupt functions and any code that must be in ARM 205 | * mode and run at full speed. 206 | */ 207 | #define ENV_EXT_FORCE_RAM __attribute__((section(".forced_ram"))) 208 | 209 | /* ************************************************************************** */ 210 | 211 | /** 212 | * \brief ARM7 environment fast call. 213 | * 214 | * Just force it into the ram with ENV_EXT_FORCE_RAM. 215 | */ 216 | #define ENV_CODE_FAST 217 | 218 | #endif 219 | -------------------------------------------------------------------------------- /env/gba/gba.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef GBA_H_ 32 | #define GBA_H_ 33 | 34 | #define GBA_INTERNAL_ 35 | 36 | #define GBA_CPU_FREQ 16780000 37 | 38 | typedef volatile unsigned char gba_reg8_t; 39 | typedef volatile unsigned short gba_reg16_t; 40 | typedef volatile unsigned int gba_reg32_t; 41 | 42 | #define GBA_IE (*((gba_reg16_t *)0x4000200)) 43 | #define GBA_IF (*((gba_reg16_t *)0x4000202)) 44 | #define GBA_IME (*((gba_reg16_t *)0x4000208)) 45 | 46 | #include "gba_timer.h" 47 | 48 | #undef GBA_INTERNAL_ 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /env/gba/gba.x: -------------------------------------------------------------------------------- 1 | /* Set the entry point, warning if we mess up. */ 2 | ENTRY(__vec_reset); 3 | 4 | /* Setup the memory layout. */ 5 | MEMORY 6 | { 7 | sflash : ORIGIN = 0x00000000, LENGTH = 16K 8 | eram : ORIGIN = 0x02000000, LENGTH = 256K 9 | iram : ORIGIN = 0x03000000, LENGTH = 32K 10 | 11 | /* 12 | * There are actually 3 different types of roms located at 3 distinct 13 | * addresses and the only difference is the wait state or access time 14 | * for the rom. In this example we'll just use the first/fastest address 15 | * range for our simulated rom. 16 | */ 17 | flash : ORIGIN = 0x08000000, LENGTH = 32M 18 | } 19 | 20 | /* Provide some information about where some areas start and end. */ 21 | __sflash_start = 0x00000000; 22 | __sflash_end = 0x00004000; 23 | __eram_start = 0x02000000; 24 | __eram_end = 0x02040000; 25 | __iram_start = 0x03000000; 26 | __iram_end = 0x03008000; 27 | __flash_start = 0x08000000; 28 | __flash_end = 0x0a000000; 29 | 30 | /* Provide the start and end of the ram, could be anywhere really. */ 31 | __ram_start = __iram_start; 32 | __ram_end = __iram_end; 33 | 34 | /* The sections of the object file. */ 35 | SECTIONS 36 | { 37 | .bios : 38 | { 39 | . = __sflash_start; 40 | *(.bios); 41 | . = __sflash_end; 42 | } > sflash =0 43 | 44 | /* Data section, copied by our crt from flash to ram. 45 | * 46 | * NOTE: 47 | * The .data section must come BEFORE the .text section. This is just 48 | * because we wish for the .vectors to be located at offset 0 in the flash 49 | * where the initializer data is stored. 50 | */ 51 | 52 | . = __flash_start; 53 | 54 | /* Text section. */ 55 | .text : 56 | { 57 | *(.vectors); 58 | *(.text); 59 | *(.rodata); 60 | *(.rodata*); 61 | *(.got*); 62 | *(.data.rel*); 63 | *(.glue_7); 64 | *(.glue_7t); 65 | . = ALIGN(4); 66 | } > flash =0 67 | 68 | .data : 69 | { 70 | /* This is where the data starts. */ 71 | *(.data); 72 | } > iram AT > flash =0 73 | 74 | /* We need this to copy the data. */ 75 | __data_start = LOADADDR(.data); 76 | __data_end = LOADADDR(.data) + SIZEOF(.data); 77 | 78 | /* 79 | * BSS section, intialized to zero. This doesn't strictly have to be 80 | * before the .text section but let's keep the RAM stuff together. 81 | */ 82 | .bss : 83 | { 84 | __bss_start = .; 85 | *(.bss); 86 | . = ALIGN(4); 87 | *(COMMON); 88 | . = ALIGN(4); 89 | __bss_end = .; 90 | } > iram 91 | 92 | /* Provide _end variable, usefull for malloc & co. */ 93 | _end = ADDR(.bss) + SIZEOF(.bss); 94 | } 95 | -------------------------------------------------------------------------------- /env/gba/gba_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef GBA_TIMER_H_ 32 | #define GBA_TIMER_H_ 33 | 34 | #ifndef GBA_INTERNAL_ 35 | # error Do not include gba_timer.h directly, use gba.h. 36 | #endif 37 | 38 | typedef struct gba_timer_t 39 | { 40 | union 41 | { 42 | gba_reg32_t both; 43 | struct 44 | { 45 | gba_reg16_t cnt; 46 | gba_reg16_t ctrl; 47 | }; 48 | }; 49 | } gba_timer_t; 50 | 51 | #define GBA_TMR0 ((gba_timer_t*)0x4000100) 52 | #define GBA_TMR1 ((gba_timer_t*)0x4000104) 53 | #define GBA_TMR2 ((gba_timer_t*)0x4000108) 54 | #define GBA_TMR3 ((gba_timer_t*)0x400010c) 55 | 56 | /* The difference prescalevalues for the timer. */ 57 | #define GBA_TMR_S1 (0<<0) 58 | #define GBA_TMR_S32 (1<<0) 59 | #define GBA_TMR_S256 (2<<0) 60 | #define GBA_TMR_S1024 (3<<0) 61 | 62 | /* Count up mode, ie. when tmrX-1 overflow update tmrX. */ 63 | #define GBA_TMR_CU (1<<2) 64 | 65 | /* Interrupt / Count enable flags. */ 66 | #define GBA_TMR_IEN (1<<6) 67 | #define GBA_TMR_ENABLE (1<<7) 68 | 69 | /* Interrupt flags in GBA_IE/GBA_IF. */ 70 | #define GBA_INT_TMR0 (1<<3) 71 | #define GBA_INT_TMR1 (1<<4) 72 | #define GBA_INT_TMR2 (1<<5) 73 | #define GBA_INT_TMR3 (1<<6) 74 | 75 | /* The number of ticks of the counter. */ 76 | #define GBA_TMR_COUNT 0x10000 77 | #define GBA_TMR_BITS 0x0ffff 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /env/gba/gdbrc: -------------------------------------------------------------------------------- 1 | set watchdog 0 2 | target remote localhost:55555 3 | 4 | define tmr0 5 | printf "cnt: %04x, ctrl: %04x\n", *((unsigned short*)0x4000100), *((unsigned short*)0x4000102) 6 | end 7 | 8 | define tmr1 9 | printf "cnt: %04x, ctrl: %04x\n", *((unsigned short*)0x4000104), *((unsigned short*)0x4000106) 10 | end 11 | 12 | define tmr2 13 | printf "cnt: %04x, ctrl: %04x\n", *((unsigned short*)0x4000108), *((unsigned short*)0x400010a) 14 | end 15 | 16 | define tmr3 17 | printf "cnt: %04x, ctrl: %04x\n", *((unsigned short*)0x400010c), *((unsigned short*)0x400010e) 18 | end 19 | 20 | define ie 21 | printf "ie: %04x\n", *((unsigned short*)0x4000200) 22 | end 23 | 24 | define if 25 | printf "if: %04x\n", *((unsigned short*)0x4000202) 26 | end 27 | 28 | define ime 29 | printf "ime: %04x\n", *((unsigned short*)0x4000208) 30 | end 31 | 32 | define timer 33 | printf "gba_timer_active: %08x\n", gba_timer_active 34 | printf "gba_timer_base: %08x\n", gba_timer_base 35 | printf "gba_timer_next: %08x\n", gba_timer_next 36 | end 37 | -------------------------------------------------------------------------------- /env/gba/make_bios.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if test $# -lt 2 3 | then 4 | echo "Usage make_bios.sh " 5 | exit 1 6 | fi 7 | 8 | arm-elf-objcopy --only-section .bios -O binary $1 $2 9 | -------------------------------------------------------------------------------- /env/gba/sys_call.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | /* ************************************************************************** */ 35 | 36 | typedef void (*arm7_sys_call_t)(void); 37 | 38 | /* ************************************************************************** */ 39 | 40 | /** 41 | * \cond 42 | * 43 | * Just forward all system call implementations so that we can use them in 44 | * the table, no need for parameter correctness as we just want the address. 45 | */ 46 | 47 | /** 48 | * \endcond 49 | */ 50 | 51 | /** 52 | * \brief 53 | * System call table, used to determine which system call should 54 | * be issued. 55 | */ 56 | arm7_sys_call_t arm7_sys_call_table[] = 57 | { 58 | (arm7_sys_call_t)_arm7_context_dispatch 59 | }; 60 | 61 | /* ************************************************************************** */ 62 | 63 | /** 64 | * \cond 65 | * 66 | * System call binding, used to get the mapping of syscall id to function. 67 | */ 68 | 69 | /** 70 | * \endcond 71 | */ 72 | 73 | /* ************************************************************************** */ 74 | 75 | /** 76 | * \brief ARM7 system call entry point. 77 | * 78 | * A system call should be treated as a simple C function call. We just 79 | * need some magic to make the syscall id translate into a C function. 80 | * 81 | * \todo Perform a sanity check that the system call id is valid. 82 | */ 83 | __attribute__((naked)) void arm7_sys_call(void) 84 | { 85 | /* 86 | * Adjudt the link register so that we can treat this as a regular 87 | * interrupt ie. use save/restore context macros. 88 | */ 89 | asm volatile("add lr, lr, #4\n"); 90 | 91 | /* 92 | * Save context, we must do this since we don't know if the system 93 | * call will possibly switch the context... 94 | */ 95 | ARM7_CONTEXT_SAVE(); 96 | 97 | asm volatile 98 | ( 99 | /* 100 | * r0-r3 may or may not hold parameters, let's assume they do 101 | * and use r4 and r5 as temporary. Please note that _all_ user 102 | * mode registers are saved but registers r0-r3 are used for 103 | * parameter passing thus we wish to keep them intact so that 104 | * we do not have to take anything special into conisderation 105 | * when dealing with the system calls. 106 | */ 107 | "ldr r4, [lr, #-8]\n" 108 | "and r4, r4, #0xffffff\n" 109 | "ldr r5, =arm7_sys_call_table\n" 110 | "ldr r4, [r5, r4, lsl #2]\n" 111 | "mov lr, pc\n" 112 | "mov pc, r4\n" 113 | ); 114 | 115 | /* Restore the context, might be same context or new context. */ 116 | ARM7_CONTEXT_RESTORE(); 117 | } 118 | -------------------------------------------------------------------------------- /env/gba/sys_call.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ENV_ARM7_ARM7_SYS_CALL_H_ 32 | #define ENV_ARM7_ARM7_SYS_CALL_H_ 33 | 34 | /* ************************************************************************** */ 35 | 36 | #define ARM7_SYS_CALL_BIND(function, id) \ 37 | __attribute__((naked)) function\ 38 | {\ 39 | asm volatile(\ 40 | "swi %0\n"\ 41 | "mov pc, lr\n"\ 42 | :: "I" (id)\ 43 | );\ 44 | } 45 | 46 | /* ************************************************************************** */ 47 | 48 | /** 49 | * \brief ARM7 system call enum 50 | */ 51 | enum 52 | { 53 | /** 54 | * \brief Dispatch system call id. 55 | */ 56 | ARM7_SYS_CALL_DISPATCH = 0, 57 | 58 | /** 59 | * \brief The last system call id + 1, needed for sanity. 60 | */ 61 | ARM7_SYS_CALL_MAX 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /env/gba/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /** 32 | * \brief Skeleton environment types. 33 | * 34 | * Just used for compile testing and perhaps as a template for a new 35 | * environment. Should compile but does not run. 36 | */ 37 | #ifndef ENV_ARM7_TYPES_H_ 38 | #define ENV_ARM7_TYPES_H_ 39 | 40 | /** 41 | * \brief ARM7 context typedef. 42 | */ 43 | typedef struct arm7_context_t 44 | { 45 | /** 46 | * \brief The stack pointer. 47 | */ 48 | unsigned int *sp; 49 | 50 | /** 51 | * \brief The context cookie pointer. 52 | */ 53 | unsigned int *cookie; 54 | } arm7_context_t; 55 | 56 | /** 57 | * \brief Environment context typedef. 58 | * 59 | * Should evalutate to the type that is used to store the context of a 60 | * thread. 61 | */ 62 | typedef arm7_context_t env_context_t; 63 | 64 | /** 65 | * \brief Environment result typdef. 66 | * 67 | * Should evaluate to the result of a synchronus function call. 68 | */ 69 | typedef int env_result_t; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /env/m16c/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef ENV_ROOT 10 | $(error Variable ENV_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Sanity check since and SRP environment is quite different. 15 | ################################################################################ 16 | ifdef SRP 17 | $(error Environment does not support SRP.) 18 | endif 19 | 20 | ################################################################################ 21 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 22 | ################################################################################ 23 | 24 | CC := m32c-elf-gcc 25 | CFLAGS := -DENV_M16C=1 -mcpu=m16c -O2 -Wall -I$(ENV_ROOT) $(CFLAGS) 26 | LDFLAGS := -Wl,-T$(ENV_ROOT)/$(ENV)/m16c.x -nostartfiles -mcpu=m16c 27 | 28 | ################################################################################ 29 | # Setup the rules for building the required object files from the source. 30 | ################################################################################ 31 | 32 | $(BUILD_ROOT)/crt.o: $(ENV_ROOT)/$(ENV)/crt.S 33 | $(CC) $< -c -o $@ 34 | 35 | $(BUILD_ROOT)/env.o: $(ENV_ROOT)/$(ENV)/env.c 36 | $(CC) $(CFLAGS) $< -c -o $@ 37 | 38 | ################################################################################ 39 | # Setup the required objects for the enviroment sources. 40 | ################################################################################ 41 | 42 | ENV_OBJECTS := $(BUILD_ROOT)/crt.o\ 43 | $(BUILD_ROOT)/env.o 44 | -------------------------------------------------------------------------------- /env/m16c/crt.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | .set PM0, 0x04 32 | .set PRCR, 0x0a 33 | 34 | .set ISTACK_SIZE, 0x100 35 | 36 | .text 37 | .global _start 38 | .global __vector_default 39 | 40 | .extern _main 41 | 42 | _start: 43 | /* Setup processor mode, single chip mode. */ 44 | mov.b #0x02, PRCR 45 | mov.b #0x00, PM0 46 | mov.b #0x00, PRCR 47 | 48 | /* Setup the FLG register to some sane defaults. */ 49 | ldc #0, flg 50 | 51 | /* Setup the interrupt stack. */ 52 | mov.w #__ram_end, r0 53 | ldc r0, isp 54 | sub.w #ISTACK_SIZE, r0 55 | 56 | /* Setup user stack. */ 57 | fset u 58 | ldc r0, sp 59 | 60 | /* Setup interrupt vector. */ 61 | ldc #%hi16(_vectors_variable), intbh 62 | ldc #%lo16(_vectors_variable), intbl 63 | 64 | /* Copy .data. */ 65 | mov.b #%hi8(__data_start), r1h 66 | mov.w #%lo16(__data_start), a0 67 | mov.w #__ram_start, a1 68 | mov.w #__data_size, r3 69 | smovf.b 70 | 71 | /* Zero out .bss. */ 72 | mov.b #0x00, R0L 73 | mov.w #__bss_size, r3 74 | mov.w #__bss_start, a1 75 | sstr.b 76 | 77 | /* Enter main(). */ 78 | jsr.a _main 79 | 80 | /* In case we return, should realy generate a reset :/ */ 81 | jmp.b 0 82 | 83 | /* We should probably not get here. */ 84 | __vector_default: 85 | jmp.a __vector_default 86 | 87 | /* Fixed hardware vector table. */ 88 | .section .vectors_fixed, "a",@progbits 89 | 90 | .size _vectors_fixed, 36 91 | .type _vectors_fixed, @object 92 | 93 | _vectors_fixed: 94 | 95 | .long 0 /* Undefined Instruction. */ 96 | .long 0 /* Overflow INTO Instruction. */ 97 | .long 0 /* BRK Instruction.*/ 98 | .long 0 /* Address Match Interupt. */ 99 | .long 0 /* Single Step Interrupt. */ 100 | .long 0 /* Watchdog, Oscillation, Voltage Interrupt. */ 101 | .long 0 /* DBC. */ 102 | .long 0 /* NMI. */ 103 | .long _start /* Reset. */ 104 | 105 | /* Variable vector table. */ 106 | .section .vectors_variable 107 | 108 | .size _vectors_variable, 256 109 | .type _vectors_variable, @object 110 | 111 | _vectors_variable: 112 | 113 | .long __vector_0 114 | .long __vector_1 115 | .long __vector_2 116 | .long __vector_3 117 | .long __vector_4 118 | .long __vector_5 119 | .long __vector_6 120 | .long __vector_7 121 | .long __vector_8 122 | .long __vector_9 123 | .long __vector_10 124 | .long __vector_11 125 | .long __vector_12 126 | .long __vector_13 127 | .long __vector_14 128 | .long __vector_15 129 | .long __vector_16 130 | .long __vector_17 131 | .long __vector_18 132 | .long __vector_19 133 | .long __vector_20 134 | .long __vector_21 135 | .long __vector_22 136 | .long __vector_23 137 | .long __vector_24 138 | .long __vector_25 139 | .long __vector_26 140 | .long __vector_27 141 | .long __vector_28 142 | .long __vector_29 143 | .long __vector_30 144 | .long __vector_31 145 | .long __vector_32 146 | .long __vector_33 147 | .long __vector_34 148 | .long __vector_35 149 | .long __vector_36 150 | .long __vector_37 151 | .long __vector_38 152 | .long __vector_39 153 | .long __vector_40 154 | .long __vector_41 155 | .long __vector_42 156 | .long __vector_43 157 | .long __vector_44 158 | .long __vector_45 159 | .long __vector_46 160 | .long __vector_47 161 | .long __vector_48 162 | .long __vector_49 163 | .long __vector_50 164 | .long __vector_51 165 | .long __vector_52 166 | .long __vector_53 167 | .long __vector_54 168 | .long __vector_55 169 | .long __vector_56 170 | .long __vector_57 171 | .long __vector_58 172 | .long __vector_59 173 | .long __vector_60 174 | .long __vector_61 175 | .long __vector_62 176 | .long __vector_63 177 | -------------------------------------------------------------------------------- /env/m16c/interrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /** 32 | * \brief M16C interrupt id defines. 33 | */ 34 | 35 | #ifndef M16C_INTERRUPTS_H_ 36 | #define M16C_INTERRUPTS_H_ 37 | 38 | /* Software interrupts - boud to peripherail hardware. */ 39 | 40 | #define M16C_BRK 0 41 | #define M16C_INT3 4 42 | #define M16C_TMRB5 5 43 | #define M16C_TMRB4 6 44 | #define M16C_UART1_BCD 6 45 | #define M16C_TMRB3 7 46 | #define M16C_UART0_BCD 7 47 | #define M16C_INT5 8 48 | #define M16C_SI_O4 8 49 | #define M16C_INT4 9 50 | #define M16C_SI_O3 9 51 | #define M16C_UART2_BCD 10 52 | #define M16C_DMA0 11 53 | #define M16C_DMA1 12 54 | #define M16C_KEY 13 55 | #define M16C_AD 14 56 | #define M16C_UART2_NACK 15 57 | #define M16C_UART2_ACK 16 58 | #define M16C_UART0_NACK 17 59 | #define M16C_UART0_ACK 18 60 | #define M16C_UART1_NACK 19 61 | #define M16C_UART1_ACK 20 62 | #define M16C_TMRA0 21 63 | #define M16C_TMRA1 22 64 | #define M16C_TMRA2 23 65 | #define M16C_TMRA3 24 66 | #define M16C_TMRA4 25 67 | #define M16C_TMRB0 26 68 | #define M16C_TMRB1 27 69 | #define M16C_TMRB2 28 70 | #define M16C_INT0 29 71 | #define M16C_INT1 30 72 | #define M16C_INT2 31 73 | 74 | /* Software interrupts - not boud to peripheral hardware. */ 75 | 76 | #define M16C_SINT0 32 77 | #define M16C_SINT1 33 78 | #define M16C_SINT2 34 79 | #define M16C_SINT3 35 80 | #define M16C_SINT4 36 81 | #define M16C_SINT5 37 82 | #define M16C_SINT6 38 83 | #define M16C_SINT7 39 84 | #define M16C_SINT8 40 85 | #define M16C_SINT9 41 86 | #define M16C_SINT10 42 87 | #define M16C_SINT11 43 88 | #define M16C_SINT12 44 89 | #define M16C_SINT13 45 90 | #define M16C_SINT14 46 91 | #define M16C_SINT15 47 92 | #define M16C_SINT16 48 93 | #define M16C_SINT17 49 94 | #define M16C_SINT18 50 95 | #define M16C_SINT19 51 96 | #define M16C_SINT20 52 97 | #define M16C_SINT21 53 98 | #define M16C_SINT22 54 99 | #define M16C_SINT23 55 100 | #define M16C_SINT24 56 101 | #define M16C_SINT25 57 102 | #define M16C_SINT26 58 103 | #define M16C_SINT27 59 104 | #define M16C_SINT28 60 105 | #define M16C_SINT29 61 106 | #define M16C_SINT30 62 107 | #define M16C_SINT31 63 108 | 109 | /* Regular C-Style interrupt management. */ 110 | 111 | #define _M16C_INTERRUPT(id) \ 112 | __attribute__((interrupt)) void _vector_##id(void) 113 | 114 | #define M16C_INTERRUPT(id) \ 115 | _M16C_INTERRUPT(id) 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /env/m16c/m16c.x: -------------------------------------------------------------------------------- 1 | ENTRY(_start) 2 | 3 | MEMORY { 4 | ram (rw) : o = 0x0000400, l = 31k 5 | flash (rx) : o = 0x00c0000, l = 256k 6 | } 7 | 8 | /* Provide any vector symbols not defined. */ 9 | PROVIDE(__vector_0 = __vector_default); 10 | PROVIDE(__vector_1 = __vector_default); 11 | PROVIDE(__vector_2 = __vector_default); 12 | PROVIDE(__vector_3 = __vector_default); 13 | PROVIDE(__vector_4 = __vector_default); 14 | PROVIDE(__vector_5 = __vector_default); 15 | PROVIDE(__vector_6 = __vector_default); 16 | PROVIDE(__vector_7 = __vector_default); 17 | PROVIDE(__vector_8 = __vector_default); 18 | PROVIDE(__vector_9 = __vector_default); 19 | PROVIDE(__vector_10 = __vector_default); 20 | PROVIDE(__vector_11 = __vector_default); 21 | PROVIDE(__vector_12 = __vector_default); 22 | PROVIDE(__vector_13 = __vector_default); 23 | PROVIDE(__vector_14 = __vector_default); 24 | PROVIDE(__vector_15 = __vector_default); 25 | PROVIDE(__vector_16 = __vector_default); 26 | PROVIDE(__vector_17 = __vector_default); 27 | PROVIDE(__vector_18 = __vector_default); 28 | PROVIDE(__vector_19 = __vector_default); 29 | PROVIDE(__vector_20 = __vector_default); 30 | PROVIDE(__vector_21 = __vector_default); 31 | PROVIDE(__vector_22 = __vector_default); 32 | PROVIDE(__vector_23 = __vector_default); 33 | PROVIDE(__vector_24 = __vector_default); 34 | PROVIDE(__vector_25 = __vector_default); 35 | PROVIDE(__vector_26 = __vector_default); 36 | PROVIDE(__vector_27 = __vector_default); 37 | PROVIDE(__vector_28 = __vector_default); 38 | PROVIDE(__vector_29 = __vector_default); 39 | PROVIDE(__vector_30 = __vector_default); 40 | PROVIDE(__vector_31 = __vector_default); 41 | PROVIDE(__vector_32 = __vector_default); 42 | PROVIDE(__vector_33 = __vector_default); 43 | PROVIDE(__vector_34 = __vector_default); 44 | PROVIDE(__vector_35 = __vector_default); 45 | PROVIDE(__vector_36 = __vector_default); 46 | PROVIDE(__vector_37 = __vector_default); 47 | PROVIDE(__vector_38 = __vector_default); 48 | PROVIDE(__vector_39 = __vector_default); 49 | PROVIDE(__vector_40 = __vector_default); 50 | PROVIDE(__vector_41 = __vector_default); 51 | PROVIDE(__vector_42 = __vector_default); 52 | PROVIDE(__vector_43 = __vector_default); 53 | PROVIDE(__vector_44 = __vector_default); 54 | PROVIDE(__vector_45 = __vector_default); 55 | PROVIDE(__vector_46 = __vector_default); 56 | PROVIDE(__vector_47 = __vector_default); 57 | PROVIDE(__vector_48 = __vector_default); 58 | PROVIDE(__vector_49 = __vector_default); 59 | PROVIDE(__vector_50 = __vector_default); 60 | PROVIDE(__vector_51 = __vector_default); 61 | PROVIDE(__vector_52 = __vector_default); 62 | PROVIDE(__vector_53 = __vector_default); 63 | PROVIDE(__vector_54 = __vector_default); 64 | PROVIDE(__vector_55 = __vector_default); 65 | PROVIDE(__vector_56 = __vector_default); 66 | PROVIDE(__vector_57 = __vector_default); 67 | PROVIDE(__vector_58 = __vector_default); 68 | PROVIDE(__vector_59 = __vector_default); 69 | PROVIDE(__vector_60 = __vector_default); 70 | PROVIDE(__vector_61 = __vector_default); 71 | PROVIDE(__vector_62 = __vector_default); 72 | PROVIDE(__vector_63 = __vector_default); 73 | 74 | SECTIONS { 75 | /* 76 | * Ram starts at 0x400 but for some reason it does not allow med to 77 | * start placing data at 0x400 since it's not inte the ram... Life 78 | * is great. 79 | */ 80 | __ram_start = 0x500; 81 | __ram_end = 0x400 + 31k - 1; 82 | 83 | .data __ram_start : { 84 | *(.data); 85 | *(.rodata); /* Do NOT place in '.text'. */ 86 | *(.rodata.*); /* Do NOT place in '.text'. */ 87 | *(.plt); /* Do NOT place in '.text'. */ 88 | } > ram AT > flash 89 | 90 | __data_start = LOADADDR(.data); 91 | __data_size = SIZEOF(.data); 92 | 93 | .bss : { 94 | *(.bss); 95 | *(COMMON); 96 | } > ram 97 | 98 | __bss_start = ADDR(.bss); 99 | __bss_size = SIZEOF(.bss); 100 | 101 | .text 0xe0000 : { 102 | *(.text); 103 | *(.vectors_variable); 104 | } > flash 105 | 106 | PROVIDE(_end = __bss_start + __bss_size); 107 | 108 | /* Vector offset is fixed. */ 109 | .vectors 0x000FFFDC : { 110 | *(.vectors_fixed); 111 | } > flash 112 | } 113 | -------------------------------------------------------------------------------- /env/m16c/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /** 32 | * \brief Skeleton environment types. 33 | * 34 | * Just used for compile testing and perhaps as a template for a new 35 | * environment. Should compile but does not run. 36 | */ 37 | #ifndef ENV_M16C_TYPES_H_ 38 | #define ENV_M16C_TYPES_H_ 39 | 40 | /** 41 | * \brief M16C Environment context. 42 | * 43 | * Structure representing a context. 44 | */ 45 | typedef struct m16c_context_t { 46 | unsigned char *sp; 47 | unsigned short *cookie; 48 | } m16c_context_t; 49 | 50 | /* ************************************************************************** */ 51 | 52 | /** 53 | * \brief M16C Environment context typedef. 54 | * 55 | * Should evalutate to the type that is used to store the context of a 56 | * thread. 57 | */ 58 | typedef m16c_context_t env_context_t; 59 | 60 | /* ************************************************************************** */ 61 | 62 | /** 63 | * \brief M16C Environment result typdef. 64 | * 65 | * Should evaluate to the result of a synchronus function call. 66 | */ 67 | typedef int env_result_t; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /env/m16c_srp/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef ENV_ROOT 10 | $(error Variable ENV_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Sanity check since and SRP environment is quite different. 15 | ################################################################################ 16 | ifndef SRP 17 | $(error SRP not defined for SRP environment) 18 | endif 19 | 20 | ################################################################################ 21 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 22 | ################################################################################ 23 | 24 | CC := m32c-elf-gcc 25 | CFLAGS := -DENV_M16C_SRP=1 -mcpu=m16c -O2 -Wall -I$(ENV_ROOT) $(CFLAGS) 26 | LDFLAGS := -Wl,-T$(ENV_ROOT)/$(ENV)/m16c.x -nostartfiles -mcpu=m16c 27 | 28 | ################################################################################ 29 | # Setup the rules for building the required object files from the source. 30 | ################################################################################ 31 | 32 | $(BUILD_ROOT)/crt.o: $(ENV_ROOT)/$(ENV)/crt.S 33 | $(CC) $< -c -o $@ 34 | 35 | $(BUILD_ROOT)/env.o: $(ENV_ROOT)/$(ENV)/env.c 36 | $(CC) $(CFLAGS) $< -c -o $@ 37 | 38 | ################################################################################ 39 | # Setup the required objects for the enviroment sources. 40 | ################################################################################ 41 | 42 | ENV_OBJECTS := $(BUILD_ROOT)/crt.o\ 43 | $(BUILD_ROOT)/env.o 44 | -------------------------------------------------------------------------------- /env/m16c_srp/crt.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | .set PM0, 0x04 32 | .set PRCR, 0x0a 33 | 34 | .set ISTACK_SIZE, 0x100 35 | 36 | .text 37 | .global _start 38 | .global __vector_default 39 | 40 | .extern _main 41 | .extern _vector_panic 42 | 43 | _start: 44 | /* Setup processor mode, single chip mode. */ 45 | mov.b #0x02, PRCR 46 | mov.b #0x00, PM0 47 | mov.b #0x00, PRCR 48 | 49 | /* Setup the FLG register to some sane defaults. */ 50 | ldc #0, flg 51 | 52 | /* Setup the interrupt stack. */ 53 | mov.w #__ram_end, r0 54 | ldc r0, isp 55 | sub.w #ISTACK_SIZE, r0 56 | 57 | /* Setup user stack. */ 58 | fset u 59 | ldc r0, sp 60 | 61 | /* Setup interrupt vector. */ 62 | ldc #%hi16(_vectors_variable), intbh 63 | ldc #%lo16(_vectors_variable), intbl 64 | 65 | /* Copy .data. */ 66 | mov.b #%hi8(__data_start), r1h 67 | mov.w #%lo16(__data_start), a0 68 | mov.w #__ram_start, a1 69 | mov.w #__data_size, r3 70 | smovf.b 71 | 72 | /* Zero out .bss. */ 73 | mov.b #0x00, R0L 74 | mov.w #__bss_size, r3 75 | mov.w #__bss_start, a1 76 | sstr.b 77 | 78 | /* Enter main(). */ 79 | jsr.a _main 80 | 81 | /* In case we return, should realy generate a reset :/ */ 82 | jmp.b 0 83 | 84 | /* We should probably not get here. */ 85 | __vector_default: 86 | jmp.a _vector_panic 87 | jmp.a __vector_default 88 | 89 | /* Fixed hardware vector table. */ 90 | .section .vectors_fixed, "a",@progbits 91 | 92 | .size _vectors_fixed, 36 93 | .type _vectors_fixed, @object 94 | 95 | _vectors_fixed: 96 | 97 | .long 0 /* Undefined Instruction. */ 98 | .long 0 /* Overflow INTO Instruction. */ 99 | .long 0 /* BRK Instruction.*/ 100 | .long 0 /* Address Match Interupt. */ 101 | .long 0 /* Single Step Interrupt. */ 102 | .long 0 /* Watchdog, Oscillation, Voltage Interrupt. */ 103 | .long 0 /* DBC. */ 104 | .long 0 /* NMI. */ 105 | .long _start /* Reset. */ 106 | 107 | /* Variable vector table. */ 108 | .section .vectors_variable 109 | 110 | .size _vectors_variable, 256 111 | .type _vectors_variable, @object 112 | 113 | _vectors_variable: 114 | 115 | .long __vector_0 116 | .long __vector_1 117 | .long __vector_2 118 | .long __vector_3 119 | .long __vector_4 120 | .long __vector_5 121 | .long __vector_6 122 | .long __vector_7 123 | .long __vector_8 124 | .long __vector_9 125 | .long __vector_10 126 | .long __vector_11 127 | .long __vector_12 128 | .long __vector_13 129 | .long __vector_14 130 | .long __vector_15 131 | .long __vector_16 132 | .long __vector_17 133 | .long __vector_18 134 | .long __vector_19 135 | .long __vector_20 136 | .long __vector_21 137 | .long __vector_22 138 | .long __vector_23 139 | .long __vector_24 140 | .long __vector_25 141 | .long __vector_26 142 | .long __vector_27 143 | .long __vector_28 144 | .long __vector_29 145 | .long __vector_30 146 | .long __vector_31 147 | .long __vector_32 148 | .long __vector_33 149 | .long __vector_34 150 | .long __vector_35 151 | .long __vector_36 152 | .long __vector_37 153 | .long __vector_38 154 | .long __vector_39 155 | .long __vector_40 156 | .long __vector_41 157 | .long __vector_42 158 | .long __vector_43 159 | .long __vector_44 160 | .long __vector_45 161 | .long __vector_46 162 | .long __vector_47 163 | .long __vector_48 164 | .long __vector_49 165 | .long __vector_50 166 | .long __vector_51 167 | .long __vector_52 168 | .long __vector_53 169 | .long __vector_54 170 | .long __vector_55 171 | .long __vector_56 172 | .long __vector_57 173 | .long __vector_58 174 | .long __vector_59 175 | .long __vector_60 176 | .long __vector_61 177 | .long __vector_62 178 | .long __vector_63 179 | -------------------------------------------------------------------------------- /env/m16c_srp/interrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /** 32 | * \brief M16C interrupt id defines. 33 | */ 34 | 35 | #ifndef M16C_INTERRUPTS_H_ 36 | #define M16C_INTERRUPTS_H_ 37 | 38 | /* Software interrupts - boud to peripherail hardware. */ 39 | 40 | #define M16C_BRK 0 41 | #define M16C_INT3 4 42 | #define M16C_TMRB5 5 43 | #define M16C_TMRB4 6 44 | #define M16C_UART1_BCD 6 45 | #define M16C_TMRB3 7 46 | #define M16C_UART0_BCD 7 47 | #define M16C_INT5 8 48 | #define M16C_SI_O4 8 49 | #define M16C_INT4 9 50 | #define M16C_SI_O3 9 51 | #define M16C_UART2_BCD 10 52 | #define M16C_DMA0 11 53 | #define M16C_DMA1 12 54 | #define M16C_KEY 13 55 | #define M16C_AD 14 56 | #define M16C_UART2_NACK 15 57 | #define M16C_UART2_ACK 16 58 | #define M16C_UART0_NACK 17 59 | #define M16C_UART0_ACK 18 60 | #define M16C_UART1_NACK 19 61 | #define M16C_UART1_ACK 20 62 | #define M16C_TMRA0 21 63 | #define M16C_TMRA1 22 64 | #define M16C_TMRA2 23 65 | #define M16C_TMRA3 24 66 | #define M16C_TMRA4 25 67 | #define M16C_TMRB0 26 68 | #define M16C_TMRB1 27 69 | #define M16C_TMRB2 28 70 | #define M16C_INT0 29 71 | #define M16C_INT1 30 72 | #define M16C_INT2 31 73 | 74 | /* Software interrupts - not boud to peripheral hardware. */ 75 | 76 | #define M16C_SINT0 32 77 | #define M16C_SINT1 33 78 | #define M16C_SINT2 34 79 | #define M16C_SINT3 35 80 | #define M16C_SINT4 36 81 | #define M16C_SINT5 37 82 | #define M16C_SINT6 38 83 | #define M16C_SINT7 39 84 | #define M16C_SINT8 40 85 | #define M16C_SINT9 41 86 | #define M16C_SINT10 42 87 | #define M16C_SINT11 43 88 | #define M16C_SINT12 44 89 | #define M16C_SINT13 45 90 | #define M16C_SINT14 46 91 | #define M16C_SINT15 47 92 | #define M16C_SINT16 48 93 | #define M16C_SINT17 49 94 | #define M16C_SINT18 50 95 | #define M16C_SINT19 51 96 | #define M16C_SINT20 52 97 | #define M16C_SINT21 53 98 | #define M16C_SINT22 54 99 | #define M16C_SINT23 55 100 | #define M16C_SINT24 56 101 | #define M16C_SINT25 57 102 | #define M16C_SINT26 58 103 | #define M16C_SINT27 59 104 | #define M16C_SINT28 60 105 | #define M16C_SINT29 61 106 | #define M16C_SINT30 62 107 | #define M16C_SINT31 63 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /env/m16c_srp/m16c.x: -------------------------------------------------------------------------------- 1 | ENTRY(_start) 2 | 3 | MEMORY { 4 | ram (rw) : o = 0x0000400, l = 31k 5 | flash (rx) : o = 0x00c0000, l = 256k 6 | } 7 | 8 | /* Provide any vector symbols not defined. */ 9 | PROVIDE(__vector_0 = __vector_default); 10 | PROVIDE(__vector_1 = __vector_default); 11 | PROVIDE(__vector_2 = __vector_default); 12 | PROVIDE(__vector_3 = __vector_default); 13 | PROVIDE(__vector_4 = __vector_default); 14 | PROVIDE(__vector_5 = __vector_default); 15 | PROVIDE(__vector_6 = __vector_default); 16 | PROVIDE(__vector_7 = __vector_default); 17 | PROVIDE(__vector_8 = __vector_default); 18 | PROVIDE(__vector_9 = __vector_default); 19 | PROVIDE(__vector_10 = __vector_default); 20 | PROVIDE(__vector_11 = __vector_default); 21 | PROVIDE(__vector_12 = __vector_default); 22 | PROVIDE(__vector_13 = __vector_default); 23 | PROVIDE(__vector_14 = __vector_default); 24 | PROVIDE(__vector_15 = __vector_default); 25 | PROVIDE(__vector_16 = __vector_default); 26 | PROVIDE(__vector_17 = __vector_default); 27 | PROVIDE(__vector_18 = __vector_default); 28 | PROVIDE(__vector_19 = __vector_default); 29 | PROVIDE(__vector_20 = __vector_default); 30 | PROVIDE(__vector_21 = __vector_default); 31 | PROVIDE(__vector_22 = __vector_default); 32 | PROVIDE(__vector_23 = __vector_default); 33 | PROVIDE(__vector_24 = __vector_default); 34 | PROVIDE(__vector_25 = __vector_default); 35 | PROVIDE(__vector_26 = __vector_default); 36 | PROVIDE(__vector_27 = __vector_default); 37 | PROVIDE(__vector_28 = __vector_default); 38 | PROVIDE(__vector_29 = __vector_default); 39 | PROVIDE(__vector_30 = __vector_default); 40 | PROVIDE(__vector_31 = __vector_default); 41 | PROVIDE(__vector_32 = __vector_default); 42 | PROVIDE(__vector_33 = __vector_default); 43 | PROVIDE(__vector_34 = __vector_default); 44 | PROVIDE(__vector_35 = __vector_default); 45 | PROVIDE(__vector_36 = __vector_default); 46 | PROVIDE(__vector_37 = __vector_default); 47 | PROVIDE(__vector_38 = __vector_default); 48 | PROVIDE(__vector_39 = __vector_default); 49 | PROVIDE(__vector_40 = __vector_default); 50 | PROVIDE(__vector_41 = __vector_default); 51 | PROVIDE(__vector_42 = __vector_default); 52 | PROVIDE(__vector_43 = __vector_default); 53 | PROVIDE(__vector_44 = __vector_default); 54 | PROVIDE(__vector_45 = __vector_default); 55 | PROVIDE(__vector_46 = __vector_default); 56 | PROVIDE(__vector_47 = __vector_default); 57 | PROVIDE(__vector_48 = __vector_default); 58 | PROVIDE(__vector_49 = __vector_default); 59 | PROVIDE(__vector_50 = __vector_default); 60 | PROVIDE(__vector_51 = __vector_default); 61 | PROVIDE(__vector_52 = __vector_default); 62 | PROVIDE(__vector_53 = __vector_default); 63 | PROVIDE(__vector_54 = __vector_default); 64 | PROVIDE(__vector_55 = __vector_default); 65 | PROVIDE(__vector_56 = __vector_default); 66 | PROVIDE(__vector_57 = __vector_default); 67 | PROVIDE(__vector_58 = __vector_default); 68 | PROVIDE(__vector_59 = __vector_default); 69 | PROVIDE(__vector_60 = __vector_default); 70 | PROVIDE(__vector_61 = __vector_default); 71 | PROVIDE(__vector_62 = __vector_default); 72 | PROVIDE(__vector_63 = __vector_default); 73 | 74 | SECTIONS { 75 | /* 76 | * Ram starts at 0x400 but for some reason it does not allow med to 77 | * start placing data at 0x400 since it's not inte the ram... Life 78 | * is great. 79 | */ 80 | __ram_start = 0x500; 81 | __ram_end = 0x400 + 31k - 1; 82 | 83 | .data __ram_start : { 84 | *(.data); 85 | *(.rodata); /* Do NOT place in '.text'. */ 86 | *(.rodata.*); /* Do NOT place in '.text'. */ 87 | *(.plt); /* Do NOT place in '.text'. */ 88 | } > ram AT > flash 89 | 90 | __data_start = LOADADDR(.data); 91 | __data_size = SIZEOF(.data); 92 | 93 | .bss : { 94 | *(.bss); 95 | *(COMMON); 96 | } > ram 97 | 98 | __bss_start = ADDR(.bss); 99 | __bss_size = SIZEOF(.bss); 100 | 101 | .text 0xe0000 : { 102 | *(.text); 103 | *(.vectors_variable); 104 | } > flash 105 | 106 | PROVIDE(_end = __bss_start + __bss_size); 107 | 108 | /* Vector offset is fixed. */ 109 | .vectors 0x000FFFDC : { 110 | *(.vectors_fixed); 111 | } > flash 112 | } 113 | -------------------------------------------------------------------------------- /env/m16c_srp/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /** 32 | * \brief Skeleton environment types. 33 | * 34 | * Just used for compile testing and perhaps as a template for a new 35 | * environment. Should compile but does not run. 36 | */ 37 | #ifndef ENV_M16C_SRP_TYPES_H_ 38 | #define ENV_M16C_SRP_TYPES_H_ 39 | 40 | /** 41 | * \brief M16C Environment context. 42 | * 43 | * Structure representing a context. 44 | */ 45 | typedef struct m16c_srp_context_t { 46 | unsigned char *sp; 47 | unsigned short *cookie; 48 | } m16c_srp_context_t; 49 | 50 | /* ************************************************************************** */ 51 | 52 | /** 53 | * \brief M16C Environment context typedef. 54 | * 55 | * Should evalutate to the type that is used to store the context of a 56 | * thread. 57 | */ 58 | typedef m16c_srp_context_t env_context_t; 59 | 60 | /* ************************************************************************** */ 61 | 62 | /** 63 | * \brief M16C Environment result typdef. 64 | * 65 | * Should evaluate to the result of a synchronus function call. 66 | */ 67 | typedef int env_result_t; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /env/mips/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef ENV_ROOT 10 | $(error Variable ENV_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Sanity check since and SRP environment is quite different. 15 | ################################################################################ 16 | ifdef SRP 17 | $(error Environment does not support SRP.) 18 | endif 19 | 20 | ################################################################################ 21 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 22 | ################################################################################ 23 | 24 | CC := mipsel-linux-gcc 25 | CFLAGS := -DENV_MIPS=1 -mmcu=r3k -O2 -Wall -nostartfiles -nostdlib\ 26 | -I$(ENV_ROOT) $(CFLAGS) 27 | LDFLAGS := -Wl,-T$(ENV_ROOT)/$(ENV)/mips_r3k.x $(LDFLAGS) 28 | 29 | ################################################################################ 30 | # Setup the rules for building the required object files from the source. 31 | ################################################################################ 32 | 33 | $(BUILD_ROOT)/env.o: $(ENV_ROOT)/$(ENV)/env_asm.S 34 | $(CC) $< -c -o $@ 35 | 36 | $(BUILD_ROOT)/env.o: $(ENV_ROOT)/$(ENV)/env.c 37 | $(CC) $(CFLAGS) $< -c -o $@ 38 | 39 | ################################################################################ 40 | # Setup the required objects for the enviroment sources. 41 | ################################################################################ 42 | 43 | ENV_OBJECTS := $(BUILD_ROOT)/env_asm.o\ 44 | $(BUILD_ROOT)/env.o 45 | 46 | -------------------------------------------------------------------------------- /env/mips/env_asm.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | .global __start 32 | .global mips_context_dispatch 33 | 34 | .extern mips_panic 35 | .extern mips_stack_start 36 | .extern mips_interupt_table 37 | .extern TMR_CTL 38 | 39 | .equ MIPS_CONTEXT_COOKIE,0x55aa55aa 40 | 41 | .set noreorder 42 | 43 | .section .kdata: 44 | .align 1 45 | 46 | interrupt_panic: 47 | .asciz "Invalid interrupt, not timer compare and no other sources.\n" 48 | 49 | interrupt_handler_panic: 50 | .asciz "Invalid interrupt (NULL).\n" 51 | 52 | context_cookie_panic: 53 | .asciz "Context cookie corrupter.\n" 54 | 55 | .section .start,"ax",@progbits 56 | .align 4 57 | __start: 58 | la $29, mips_stack_start 59 | lw $29, 0($29) 60 | j main 61 | nop 62 | 63 | # NOTE: We should never get here. 64 | j mips_panic 65 | nop 66 | 67 | .section .ktext,"ax",@progbits 68 | .align 4 69 | 70 | # void mips_interrupt(void); 71 | mips_interrupt: 72 | 73 | subu $29, 72 74 | .set noat 75 | sw $1, 0($sp) 76 | .set at 77 | sw $2, 4($sp) 78 | sw $3, 8($sp) 79 | sw $4, 12($sp) 80 | sw $5, 16($sp) 81 | sw $6, 20($sp) 82 | sw $7, 24($sp) 83 | sw $8, 28($sp) 84 | sw $9, 32($sp) 85 | sw $10, 36($sp) 86 | sw $11, 40($sp) 87 | sw $12, 44($sp) 88 | sw $13, 48($sp) 89 | sw $14, 52($sp) 90 | sw $15, 56($sp) 91 | sw $24, 60($sp) 92 | sw $25, 64($sp) 93 | sw $31, 68($sp) 94 | 95 | 96 | .Linterrupt_next: 97 | 98 | # Lower id means higher priority. 99 | la $26, mips_interrupt_table 100 | 101 | mfc0 $27, $13 102 | nop 103 | srl $27, $27, 10 104 | andi $27, $27, 0x3f 105 | 106 | beq $0, $27, .Linterrupt_done 107 | nop 108 | 109 | subu $26, $26, 4 110 | 111 | .Linterrupt_find: 112 | 113 | andi $8, $27, 1 114 | srl $27, $27, 1 115 | beq $0, $8, .Linterrupt_find 116 | addu $26, $26, 4 117 | 118 | lw $8, 0($26) 119 | nop 120 | beq $0, $8, .Linterrupt_invalid_handler 121 | nop 122 | 123 | jalr $8 124 | nop 125 | b .Linterrupt_next 126 | nop 127 | 128 | .Linterrupt_invalid_handler: 129 | 130 | la $4, interrupt_handler_panic 131 | la $5, mips_panic 132 | jr $5 133 | nop 134 | 135 | .Linterrupt_done: 136 | 137 | .set noat 138 | lw $1, 0($sp) 139 | .set at 140 | lw $2, 4($sp) 141 | lw $3, 8($sp) 142 | lw $4, 12($sp) 143 | lw $5, 16($sp) 144 | lw $6, 20($sp) 145 | lw $7, 24($sp) 146 | lw $8, 28($sp) 147 | lw $9, 32($sp) 148 | lw $10, 36($sp) 149 | lw $11, 40($sp) 150 | lw $12, 44($sp) 151 | lw $13, 48($sp) 152 | lw $14, 52($sp) 153 | lw $15, 56($sp) 154 | lw $24, 60($sp) 155 | lw $25, 64($sp) 156 | lw $31, 68($sp) 157 | addu $29, 72 158 | 159 | mfc0 $26, $14 160 | nop 161 | jr $26 162 | rfe 163 | 164 | .section .text,"ax",@progbits 165 | .align 4 166 | 167 | # void mips_context_dispatch(mips_context_t *); 168 | mips_context_dispatch: 169 | 170 | # Save callee-saved registers. 171 | subu $29, $29, 48 172 | sw $16, 0($29) 173 | sw $17, 4($29) 174 | sw $18, 8($29) 175 | sw $19, 12($29) 176 | sw $20, 16($29) 177 | sw $21, 20($29) 178 | sw $22, 24($29) 179 | sw $23, 28($29) 180 | sw $28, 32($29) 181 | sw $30, 36($29) 182 | sw $31, 40($29) 183 | 184 | # Change current to new context. 185 | la $2, tt_current 186 | lw $3, 0($2) 187 | sw $4, 0($2) 188 | sw $29, 0($3) 189 | lw $5, 4($3) 190 | nop 191 | lw $5, 0($5) 192 | li $6, MIPS_CONTEXT_COOKIE 193 | bne $5, $6, .Lcontext_cookie_error 194 | lw $5, 4($4) 195 | nop 196 | lw $5, 0($5) 197 | nop 198 | bne $5, $6, .Lcontext_cookie_error 199 | nop 200 | b .Lcontext_cookie_ok 201 | nop 202 | 203 | .Lcontext_cookie_error: 204 | la $4, context_cookie_panic 205 | la $5, mips_panic 206 | jr $5 207 | nop 208 | 209 | .Lcontext_cookie_ok: 210 | lw $29, 0($4) 211 | nop 212 | 213 | # Restore callee-saved registers. 214 | lw $16, 0($29) 215 | lw $17, 4($29) 216 | lw $18, 8($29) 217 | lw $19, 12($29) 218 | lw $20, 16($29) 219 | lw $21, 20($29) 220 | lw $22, 24($29) 221 | lw $23, 28($29) 222 | lw $28, 32($29) 223 | lw $31, 40($29) 224 | lw $30, 36($29) 225 | jr $31 226 | addu $29, $29, 48 227 | 228 | -------------------------------------------------------------------------------- /env/mips/mangle.spec: -------------------------------------------------------------------------------- 1 | TT_C=env/mips/env.c _KERNEL_ 2 | TT_H=env/mips/types.h _TT_ _KERNEL_ env/mips/env.h _ENV_ 3 | -------------------------------------------------------------------------------- /env/mips/mips-r3k-syncsim.x: -------------------------------------------------------------------------------- 1 | /*GNU ld version 2.9-mipssde-031003 (with BFD 2.9-mipssde-031003) 2 | Supported emulations: 3 | elf32algmip 4 | elf32ebmip 5 | elf32elmip 6 | mipsbig 7 | mipslit 8 | elf32bsmip 9 | elf32lsmip 10 | using internal linker script: 11 | ==================================================*/ 12 | OUTPUT_FORMAT("elf32-bigmips", "elf32-bigmips", 13 | "elf32-littlemips") 14 | OUTPUT_ARCH(mips) 15 | ENTRY(__start) 16 | SEARCH_DIR(/usr/local/sde5/sde/lib); 17 | /* Do we need any of these for elf? 18 | __DYNAMIC = 0; */ 19 | 20 | SECTIONS 21 | { 22 | . = 0x00000000; 23 | .text : { *(.start); *(.text) } 24 | . = 0x00002000; 25 | .data : { *(.data); *(.sdata); *(.scommon); } 26 | .bss : { *(.bss); *(.sbss); } 27 | . = 0x80000080; 28 | .ktext : { *(.ktext) } 29 | . = 0x80002000; 30 | .kdata : { *(.kdata) } 31 | 32 | /* IO Memory mapped registers. */ 33 | IO_CTL = 0xffff0000; 34 | IO_IN = 0xffff0004; 35 | IO_OUT = 0xffff0008; 36 | 37 | /* Timer Memory mapped registers. */ 38 | TMR_CTL = 0xffff0010; 39 | TMR_CNT = 0xffff0014; 40 | TMR_CMP = 0xffff0018; 41 | } 42 | -------------------------------------------------------------------------------- /env/mips/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ENV_MIPS_TYPES_H_ 32 | #define ENV_MIPS_TYPES_H_ 33 | 34 | #include 35 | #include 36 | 37 | /* ************************************************************************** */ 38 | 39 | /** 40 | * \brief The mips context structure typedef. 41 | */ 42 | typedef struct mips_context_t 43 | { 44 | /** 45 | * \brief The stackpointer. 46 | */ 47 | unsigned int *sp; 48 | 49 | /** 50 | * \brief The magic cookie pointer. 51 | */ 52 | unsigned int *cookie; 53 | } mips_context_t; 54 | 55 | /* ************************************************************************** */ 56 | 57 | /** 58 | * \brief Export the mips context as env_context_t. 59 | */ 60 | typedef mips_context_t env_context_t; 61 | 62 | /* ************************************************************************** */ 63 | 64 | /** 65 | * \brief Export what a result is to the kernel. 66 | */ 67 | typedef uintptr_t env_result_t; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /env/msp430/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef ENV_ROOT 10 | $(error Variable ENV_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Sanity check since and SRP environment is quite different. 15 | ################################################################################ 16 | ifdef SRP 17 | $(error Environment does not support SRP.) 18 | endif 19 | 20 | ################################################################################ 21 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 22 | ################################################################################ 23 | 24 | CC := msp430-gcc 25 | CFLAGS := -DENV_MSP430=1 -mmcu=msp430x1611 -O2 -Wall\ 26 | -I$(ENV_ROOT) $(CFLAGS) 27 | #-mendup-at=main -mno-stack-init\ 28 | LDFLAGS := -mmcu=msp430x1611 29 | 30 | ################################################################################ 31 | # Setup the rules for building the required object files from the source. 32 | ################################################################################ 33 | 34 | $(BUILD_ROOT)/env.o: $(ENV_ROOT)/$(ENV)/env.c 35 | $(CC) $(CFLAGS) $< -c -o $@ 36 | 37 | ################################################################################ 38 | # Setup the required objects for the enviroment sources. 39 | ################################################################################ 40 | 41 | ENV_OBJECTS := $(BUILD_ROOT)/env.o 42 | -------------------------------------------------------------------------------- /env/msp430/gdbrc: -------------------------------------------------------------------------------- 1 | file date08.elf 2 | set watchdog 0 3 | target remote :2000 4 | -------------------------------------------------------------------------------- /env/msp430/mangle.spec: -------------------------------------------------------------------------------- 1 | TT_C=env/msp430/env.c _KERNEL_ 2 | TT_H=env/msp430/types.h _TT_ _KERNEL_ env/msp430/env.h _ENV_ 3 | -------------------------------------------------------------------------------- /env/msp430/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ENV_MSP430_TYPES_H_ 32 | #define ENV_MSP430_TYPES_H_ 33 | 34 | #include 35 | #include 36 | 37 | /** 38 | * \brief The msp430 context structure typedef. 39 | */ 40 | typedef struct msp430_context_t 41 | { 42 | /** 43 | * \brief The stackpointer. 44 | */ 45 | unsigned short *sp; 46 | 47 | /** 48 | * \brief The magic cookie pointer. 49 | */ 50 | unsigned short *cookie; 51 | } msp430_context_t; 52 | 53 | /* ************************************************************************** */ 54 | 55 | /** 56 | * \brief Export the msp430 context as env_context_t. 57 | */ 58 | typedef msp430_context_t env_context_t; 59 | 60 | /* ************************************************************************** */ 61 | 62 | /** 63 | * \brief Export what a result is to the kernel. 64 | */ 65 | typedef uintptr_t env_result_t; 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /env/msp430_srp/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef ENV_ROOT 10 | $(error Variable ENV_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Sanity check since and SRP environment is quite different. 15 | ################################################################################ 16 | ifndef SRP 17 | $(error SRP not defined for SRP environment) 18 | endif 19 | 20 | ################################################################################ 21 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 22 | ################################################################################ 23 | 24 | CC := msp430-gcc 25 | CFLAGS := -DENV_MSP430_SRP=1 -mmcu=msp430x1611 -O2 -Wall -mendup-at=main\ 26 | -I$(ENV_ROOT) $(CFLAGS) 27 | LDFLAGS := -mmcu=msp430x1611 28 | 29 | ################################################################################ 30 | # Setup the rules for building the required object files from the source. 31 | ################################################################################ 32 | 33 | $(BUILD_ROOT)/env.o: $(ENV_ROOT)/$(ENV)/env.c 34 | $(CC) $(CFLAGS) $< -c -o $@ 35 | 36 | ################################################################################ 37 | # Setup the required objects for the enviroment sources. 38 | ################################################################################ 39 | 40 | ENV_OBJECTS := $(BUILD_ROOT)/env.o 41 | -------------------------------------------------------------------------------- /env/msp430_srp/gdbrc: -------------------------------------------------------------------------------- 1 | file date08.elf 2 | set watchdog 0 3 | target remote :2000 4 | -------------------------------------------------------------------------------- /env/msp430_srp/mangle.spec: -------------------------------------------------------------------------------- 1 | TT_C=env/msp430_srp/env.c _KERNEL_ 2 | TT_H=env/msp430_srp/types.h _TT_ _KERNEL_ env/msp430/env.h _ENV_ 3 | -------------------------------------------------------------------------------- /env/msp430_srp/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ENV_MSP430_SRP_TYPES_H_ 32 | #define ENV_MSP430_SRP_TYPES_H_ 33 | 34 | #include 35 | #include 36 | 37 | /** 38 | * \brief Export what a result is to the kernel. 39 | */ 40 | typedef uintptr_t env_result_t; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /env/pic18/18f4620.lkr: -------------------------------------------------------------------------------- 1 | // $Id: 18f4620.lkr,v 1.3 2004/04/26 18:09:00 curtiss Exp $ 2 | // File: 18f4620.lkr 3 | // Sample linker script for the PIC18F4620 processor 4 | 5 | LIBPATH . 6 | 7 | FILES c018i.o 8 | FILES clib.lib 9 | FILES p18f4620.lib 10 | 11 | CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED 12 | CODEPAGE NAME=page START=0x2A END=0xFFFF 13 | CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED 14 | CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED 15 | CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED 16 | CODEPAGE NAME=eedata START=0xF00000 END=0xF003FF PROTECTED 17 | 18 | ACCESSBANK NAME=accessram START=0x0 END=0x7F 19 | DATABANK NAME=gpr0 START=0x80 END=0xFF 20 | DATABANK NAME=gpr1 START=0x100 END=0x1FF 21 | DATABANK NAME=gpr2 START=0x200 END=0x2FF 22 | DATABANK NAME=gpr3 START=0x300 END=0x3FF 23 | DATABANK NAME=gpr4 START=0x400 END=0x4FF 24 | DATABANK NAME=gpr5 START=0x500 END=0x5FF 25 | DATABANK NAME=gpr6 START=0x600 END=0x6FF 26 | DATABANK NAME=gpr7 START=0x700 END=0x7FF 27 | DATABANK NAME=gpr8 START=0x800 END=0x8FF 28 | DATABANK NAME=gpr9 START=0x900 END=0x9FF 29 | 30 | // 511 bytes for message pool, should be enough for most of your needs. 31 | DATABANK NAME=message_bank START=0xa00 END=0xbfe 32 | 33 | // The rest of the bank is the init stack(We only need one byte for this). 34 | DATABANK NAME=init_stack_bank START=0xbff END=0xbff 35 | 36 | // 768(0x300) bytes for the software stacks. 37 | DATABANK NAME=stack_bank START=0xc00 END=0xeff 38 | 39 | //DATABANK NAME=gpr10 START=0xA00 END=0xAFF 40 | //DATABANK NAME=gpr11 START=0xB00 END=0xBFF 41 | //DATABANK NAME=gpr12 START=0xC00 END=0xCFF 42 | //DATABANK NAME=gpr13 START=0xD00 END=0xDFF 43 | //DATABANK NAME=gpr14 START=0xE00 END=0xEFF 44 | 45 | DATABANK NAME=gpr15 START=0xF00 END=0xF7F 46 | 47 | ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED 48 | 49 | SECTION NAME=CONFIG ROM=config 50 | 51 | SECTION NAME=stack_pool RAM=stack_bank 52 | SECTION NAME=message_pool RAM=message_bank 53 | 54 | STACK SIZE=0x1 RAM=init_stack_bank 55 | -------------------------------------------------------------------------------- /env/pic18/18f4620_e.lkr: -------------------------------------------------------------------------------- 1 | // $Id: 18f4620_e.lkr,v 1.3 2004/04/26 18:07:40 curtiss Exp $ 2 | // File: 18f4620_e.lkr 3 | // Sample linker script for the PIC18F4620 processor 4 | 5 | LIBPATH . 6 | 7 | FILES c018i_e.o 8 | FILES clib_e.lib 9 | FILES p18f4620_e.lib 10 | 11 | CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED 12 | CODEPAGE NAME=page START=0x2A END=0xFFFF 13 | CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED 14 | CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED 15 | CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED 16 | CODEPAGE NAME=eedata START=0xF00000 END=0xF003FF PROTECTED 17 | 18 | DATABANK NAME=gpre START=0x0 END=0x5F 19 | ACCESSBANK NAME=accessram START=0x60 END=0x7F 20 | DATABANK NAME=gpr0 START=0x80 END=0xFF 21 | DATABANK NAME=gpr1 START=0x100 END=0x1FF 22 | DATABANK NAME=gpr2 START=0x200 END=0x2FF 23 | DATABANK NAME=gpr3 START=0x300 END=0x3FF 24 | DATABANK NAME=gpr4 START=0x400 END=0x4FF 25 | DATABANK NAME=gpr5 START=0x500 END=0x5FF 26 | DATABANK NAME=gpr6 START=0x600 END=0x6FF 27 | DATABANK NAME=gpr7 START=0x700 END=0x7FF 28 | DATABANK NAME=gpr8 START=0x800 END=0x8FF 29 | DATABANK NAME=gpr9 START=0x900 END=0x9FF 30 | 31 | // 511 bytes for message pool, should be enough for most of your needs. 32 | DATABANK NAME=message_bank START=0xa00 END=0xbfe 33 | 34 | // The rest of the bank is the init stack(We only need one byte for this). 35 | DATABANK NAME=init_stack_bank START=0xbff END=0xbff 36 | 37 | // 768(0x300) bytes for the software stacks. 38 | DATABANK NAME=stack_bank START=0xc00 END=0xeff 39 | 40 | //DATABANK NAME=gpr10 START=0xA00 END=0xAFF 41 | //DATABANK NAME=gpr11 START=0xB00 END=0xBFF 42 | //DATABANK NAME=gpr12 START=0xC00 END=0xCFF 43 | //DATABANK NAME=gpr13 START=0xD00 END=0xDFF 44 | //DATABANK NAME=gpr14 START=0xE00 END=0xEFF 45 | 46 | DATABANK NAME=gpr15 START=0xF00 END=0xF7F 47 | 48 | ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED 49 | 50 | SECTION NAME=CONFIG ROM=config 51 | 52 | SECTION NAME=stack_pool RAM=stack_bank 53 | SECTION NAME=message_pool RAM=message_bank 54 | 55 | STACK SIZE=0x1 RAM=init_stack_bank 56 | -------------------------------------------------------------------------------- /env/pic18/mangle.spec: -------------------------------------------------------------------------------- 1 | TT_C=env/pic18/env.c _KERNEL_ 2 | TT_H=env/pic18/types.h _TT_ _KERNEL_ env/pic18/env.h _ENV_ 3 | -------------------------------------------------------------------------------- /env/pic18/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ENV_PIC18_TYPES_H_ 32 | #define ENV_PIC18_TYPES_H_ 33 | 34 | #ifndef __18CXX 35 | # error Unknown or unsupported compiler. 36 | #endif 37 | 38 | #include 39 | 40 | /** 41 | * \brief The PIC18 context. 42 | */ 43 | typedef struct pic18_context_t 44 | { 45 | /** 46 | * \brief Saved stack-pointer, holds all information about thread. 47 | */ 48 | unsigned char *sp; 49 | 50 | /** 51 | * \brief The magic cookie for this context, used to check for overflow. 52 | */ 53 | unsigned short *cookie; 54 | } pic18_context_t; 55 | 56 | /* ************************************************************************** */ 57 | 58 | /** 59 | * \brief Export the pic18 context as environment context. 60 | */ 61 | typedef pic18_context_t env_context_t; 62 | 63 | /* ************************************************************************** */ 64 | 65 | /** 66 | * \brief Environment result. 67 | */ 68 | typedef unsigned long env_result_t; 69 | 70 | /* ************************************************************************** */ 71 | 72 | /** 73 | * \brief Environment extension for interrupts. 74 | */ 75 | typedef void (*env_ext_interrupt_t)(void); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /env/posix/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef ENV_ROOT 10 | $(error Variable ENV_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Sanity check since and SRP environment is quite different. 15 | ################################################################################ 16 | ifdef SRP 17 | $(error Environment does not support SRP.) 18 | endif 19 | 20 | ################################################################################ 21 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 22 | ################################################################################ 23 | 24 | CC := gcc 25 | CFLAGS := -DENV_POSIX=1 -Wall -O2 -I$(ENV_ROOT) $(CFLAGS) 26 | LDFLAGS := -lpthread -lrt $(LDFLAGS) 27 | 28 | ################################################################################ 29 | # Setup the rules for building the required object files from the source. 30 | ################################################################################ 31 | 32 | $(BUILD_ROOT)/env.o: $(ENV_ROOT)/$(ENV)/env.c 33 | $(CC) $(CFLAGS) $< -c -o $@ 34 | 35 | $(BUILD_ROOT)/ack.o: $(ENV_ROOT)/$(ENV)/ack.c 36 | $(CC) $(CFLAGS) $< -c -o $@ 37 | 38 | ################################################################################ 39 | # Setup the required objects for the enviroment sources. 40 | ################################################################################ 41 | 42 | ENV_OBJECTS := $(BUILD_ROOT)/env.o\ 43 | $(BUILD_ROOT)/ack.o 44 | -------------------------------------------------------------------------------- /env/posix/ack.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | /** 39 | * \brief The ack structure. 40 | */ 41 | struct ack_t 42 | { 43 | /** 44 | * \brief ack lock. 45 | */ 46 | pthread_mutex_t lock; 47 | 48 | /** 49 | * \brief ack signal. 50 | */ 51 | pthread_cond_t signal; 52 | 53 | /** 54 | * \brief ack variable. 55 | */ 56 | sig_atomic_t acked; 57 | }; 58 | 59 | 60 | /** 61 | * \brief Create a new ack. 62 | * 63 | * \return The new ack, will not fail but call posix_panic(). 64 | */ 65 | ack_t *ack_new(void) 66 | { 67 | ack_t *ack; 68 | 69 | /* Allocate a new ack. */ 70 | ack = calloc(1, sizeof(ack_t)); 71 | if (!ack) 72 | posix_panic("Unable to allocate new ack.\n"); 73 | 74 | /* Create the lock. */ 75 | if (pthread_mutex_init(&ack->lock, NULL)) 76 | posix_panic("Unable to initialize ack lock.\n"); 77 | 78 | /* Create the signal condition. */ 79 | if (pthread_cond_init(&ack->signal, NULL)) 80 | posix_panic("Unable to initialize ack cond.\n"); 81 | 82 | /* Success. */ 83 | return ack; 84 | } 85 | 86 | /** 87 | * \brief Destroy an ack. 88 | * 89 | * \param ack The ack to destroy. 90 | */ 91 | void ack_delete(ack_t *ack) 92 | { 93 | assert(ack); 94 | 95 | /* Free the mallocs. */ 96 | free(ack); 97 | } 98 | 99 | /** 100 | * \brief Ack an ack. 101 | * 102 | * \param ack the ack to acknoledge. 103 | */ 104 | void ack_set(ack_t *ack) 105 | { 106 | /* Aquire the lock. */ 107 | if (pthread_mutex_lock(&ack->lock)) 108 | posix_panic("Unable to aquire ack lock.\n"); 109 | 110 | /* Set the acked to non-zero ie. acked. */ 111 | ack->acked++; 112 | 113 | /* Signal the change. */ 114 | if (pthread_cond_broadcast(&ack->signal)) 115 | posix_panic("Unable to signal acked state.\n"); 116 | 117 | /* Release the lock. */ 118 | if (pthread_mutex_unlock(&ack->lock)) 119 | posix_panic("Unable to release ack lock.\n"); 120 | } 121 | 122 | /** 123 | * \brief Reset an ack. 124 | * 125 | * \param ack The acknowledge struct to reset. 126 | */ 127 | void ack_clear(ack_t *ack) 128 | { 129 | assert(ack); 130 | 131 | /* Aquire the lock. */ 132 | if (pthread_mutex_lock(&ack->lock)) 133 | posix_panic("Unable to aquire ack lock.\n"); 134 | 135 | /* Set the acked to 0 ie. not acked. */ 136 | ack->acked = 0; 137 | 138 | /* Release the lock. */ 139 | if (pthread_mutex_unlock(&ack->lock)) 140 | posix_panic("Unable to release ack lock.\n"); 141 | } 142 | 143 | /** 144 | * \brief Wait for ack condition. 145 | * 146 | * \note 147 | * When we return we will have at least the number of acks 148 | * requested. 149 | * 150 | * \param ack The acknowledge struct to wait for. 151 | * \param last The number of acks to receive before returning. 152 | */ 153 | void ack_wait(ack_t *ack, int num) 154 | { 155 | assert(ack); 156 | 157 | /* Aquire the lock. */ 158 | if (pthread_mutex_lock(&ack->lock)) 159 | posix_panic("Unable to aquire ack lock.\n"); 160 | 161 | /* Wait until we get an acknoledgment. */ 162 | while (ack->acked < num) 163 | { 164 | /* Wait. */ 165 | if (pthread_cond_wait(&ack->signal, &ack->lock)) 166 | posix_panic("Unable to wait for ack.\n"); 167 | } 168 | 169 | /* Someone acknoledged us. */ 170 | if (pthread_mutex_unlock(&ack->lock)) 171 | posix_panic("Unable to release ack lock.\n"); 172 | } 173 | 174 | /** 175 | * \brief Check if ack is set. 176 | * 177 | * \param ack The acknowledge state to check. 178 | * \return zero if no ack was set, non-zero if ack was set. 179 | */ 180 | int ack_acked(ack_t *ack) 181 | { 182 | int acked; 183 | 184 | /* Aquire the lock. */ 185 | if (pthread_mutex_lock(&ack->lock)) 186 | posix_panic("Unable to aquire lock.\n"); 187 | 188 | /* Grab an ack if there was one. */ 189 | acked = ack->acked; 190 | 191 | /* Release the lock. */ 192 | if (pthread_mutex_unlock(&ack->lock)) 193 | posix_panic("Unable to release lock.\n"); 194 | 195 | return acked; 196 | } 197 | -------------------------------------------------------------------------------- /env/posix/ack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ACK_H_ 32 | #define ACK_H_ 33 | 34 | #include 35 | #include 36 | 37 | typedef struct ack_t ack_t; 38 | 39 | void ack_delete(ack_t *ack); 40 | ack_t *ack_new(void); 41 | void ack_set(ack_t *ack); 42 | void ack_clear(ack_t *ack); 43 | void ack_wait(ack_t *ack, int); 44 | int ack_acked(ack_t *ack); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /env/posix/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ENV_POSIX_TYPES_H_ 32 | #define ENV_POSIX_TYPES_H_ 33 | 34 | /* Standard C headers. */ 35 | #include 36 | #include 37 | #include 38 | 39 | /* POSIX/UNIX headers. */ 40 | #include 41 | 42 | /* ************************************************************************** */ 43 | 44 | /** 45 | * \brief The internal context of a posix thread. 46 | */ 47 | typedef struct posix_context_t 48 | { 49 | /** 50 | * \brief The actual thread. 51 | */ 52 | pthread_t thread; 53 | 54 | /** 55 | * \brief The context lock. 56 | */ 57 | pthread_mutex_t lock; 58 | 59 | /** 60 | * \brief The signal condition variable. 61 | */ 62 | pthread_cond_t signal; 63 | 64 | /** 65 | * \brief The state of the thread. 66 | */ 67 | sig_atomic_t run; 68 | 69 | /** 70 | * \brief Pointer to the thread function to be run. 71 | */ 72 | void (*function)(void); 73 | } posix_context_t; 74 | 75 | /* ************************************************************************** */ 76 | 77 | /** 78 | * \brief Typedef so that tinyTimber knows what to use as context. 79 | */ 80 | typedef struct posix_context_t env_context_t; 81 | 82 | /* ************************************************************************** */ 83 | 84 | /** 85 | * \brief Typedef so that tinyTimber knows what a result is. 86 | */ 87 | typedef uintptr_t env_result_t; 88 | 89 | /* ************************************************************************** */ 90 | 91 | /** 92 | * \brief POSIX interrupt handler. 93 | */ 94 | typedef void (*posix_ext_interrupt_handler_t)(int); 95 | 96 | /* ************************************************************************** */ 97 | 98 | /** 99 | * \brief POSIX Uses special env_time_t type. 100 | * 101 | * struct timespec is used for time instead of the standard unsigned long. 102 | */ 103 | #define ENV_TIME_T 1 104 | 105 | /* ************************************************************************** */ 106 | 107 | /** 108 | * \brief POSIX env_time_t specific type, not standard. 109 | */ 110 | typedef struct timespec env_time_t; 111 | 112 | /* ************************************************************************** */ 113 | 114 | /** 115 | * \brief POSIX time less than macro. 116 | */ 117 | #define ENV_TIME_LT(v0, v1) \ 118 | (\ 119 | ((v0).tv_sec < (v1).tv_sec) ||\ 120 | (((v0).tv_sec == (v1).tv_sec) && ((v0).tv_nsec < (v1).tv_nsec))\ 121 | ) 122 | 123 | /* ************************************************************************** */ 124 | 125 | /** 126 | * \brief POSX time less than or equal to macro. 127 | */ 128 | #define ENV_TIME_LE(v0, v1) \ 129 | (\ 130 | ((v0).tv_sec <= (v1).tv_sec) &&\ 131 | ((v0).tv_nsec <= (v1).tv_nsec)\ 132 | ) 133 | 134 | /* ************************************************************************** */ 135 | 136 | /** 137 | * \brief POSIX time add macro. 138 | */ 139 | #define ENV_TIME_ADD(v0, v1) \ 140 | posix_time_add(&v0, &v1) 141 | 142 | /* ************************************************************************** */ 143 | 144 | /** 145 | * \brief POSIX time inherit value. 146 | */ 147 | extern env_time_t posix_time_inherit; 148 | 149 | /* ************************************************************************** */ 150 | 151 | /** 152 | * \brief POSIX time inherit macro. 153 | * 154 | * Used to indicate that the time should be inherited. 155 | */ 156 | #define ENV_TIME_INHERIT \ 157 | posix_time_inherit 158 | 159 | /* ************************************************************************** */ 160 | 161 | /** 162 | * \brief POSIX time inherited macro. 163 | * 164 | * Used to check if the time was inherited or not. 165 | */ 166 | #define ENV_TIME_INHERITED(v0) \ 167 | (((v0).tv_sec == 0) && (((v0).tv_nsec) == 0)) 168 | 169 | /* ************************************************************************** */ 170 | 171 | /** 172 | * \brief POSIX env_time_t addition function. 173 | * 174 | * Non-standard addition of the time types, should be inlined and/or eliminated 175 | * whenever you compile your code since it's static inline. Not always true but 176 | * at least sort of true for GCC (-O1+). 177 | * 178 | * \param v0 Frist value. 179 | * \param v1 Second value. 180 | * \return v0 + v1 with some special checks for overflow. 181 | */ 182 | static inline env_time_t posix_time_add( 183 | env_time_t *v0, 184 | env_time_t *v1 185 | ) 186 | { 187 | env_time_t tmp; 188 | if ((v0->tv_nsec + v1->tv_nsec) > 1000000000UL) { 189 | tmp.tv_sec = v0->tv_sec + v1->tv_sec + 1; 190 | tmp.tv_nsec = v0->tv_nsec + v1->tv_nsec - 1000000000UL; 191 | } else { 192 | tmp.tv_sec = v0->tv_sec + v1->tv_sec; 193 | tmp.tv_nsec = v0->tv_nsec + v1->tv_nsec; 194 | } 195 | return tmp; 196 | } 197 | 198 | #endif 199 | -------------------------------------------------------------------------------- /env/posix_srp/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef ENV_ROOT 10 | $(error Variable ENV_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Sanity check since and SRP environment is quite different. 15 | ################################################################################ 16 | ifndef SRP 17 | $(error SRP not defined for SRP environment) 18 | endif 19 | 20 | ################################################################################ 21 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 22 | ################################################################################ 23 | 24 | CC := gcc 25 | CFLAGS := -DENV_POSIX_SRP=1 -Wall -O2 -I$(ENV_ROOT) $(CFLAGS) 26 | LDFLAGS := -lpthread -lrt $(LDFLAGS) 27 | 28 | ################################################################################ 29 | # Setup the rules for building the required object files from the source. 30 | ################################################################################ 31 | 32 | $(BUILD_ROOT)/env.o: $(ENV_ROOT)/$(ENV)/env.c 33 | $(CC) $(CFLAGS) $< -c -o $@ 34 | 35 | ################################################################################ 36 | # Setup the required objects for the enviroment sources. 37 | ################################################################################ 38 | 39 | ENV_OBJECTS := $(BUILD_ROOT)/env.o 40 | 41 | -------------------------------------------------------------------------------- /env/posix_srp/env.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | /* ************************************************************************** */ 43 | 44 | /** \cond */ 45 | 46 | static sigset_t sigmask_protect; 47 | static sigset_t sigmask_unprotect; 48 | static pthread_t root; 49 | 50 | /* 51 | * Sort of private internal but used in the header file. 52 | */ 53 | int posix_srp_protected; 54 | env_time_t posix_srp_timer_timestamp; 55 | timer_t posix_srp_timer; 56 | env_time_t posix_time_inherit = {0}; 57 | 58 | /* ************************************************************************** */ 59 | 60 | static void interrupt_handler(int sig) 61 | { 62 | switch (sig) { 63 | case SIGALRM: 64 | tt_expired(posix_srp_timer_get()); 65 | tt_schedule(); 66 | break; 67 | 68 | default: 69 | posix_srp_panic("Unknown singal caught.\n"); 70 | break; 71 | } 72 | } 73 | 74 | /** \endcond */ 75 | 76 | /* ************************************************************************** */ 77 | 78 | void posix_srp_init(void) 79 | { 80 | struct sigevent timer_event; 81 | struct sigaction signal_action; 82 | 83 | sigfillset(&sigmask_protect); 84 | sigdelset(&sigmask_protect, SIGINT); 85 | 86 | sigfillset(&sigmask_unprotect); 87 | sigdelset(&sigmask_unprotect, SIGINT); 88 | sigdelset(&sigmask_unprotect, SIGALRM); 89 | sigdelset(&sigmask_unprotect, SIGUSR1); 90 | 91 | posix_srp_protected = 1; 92 | pthread_sigmask(SIG_SETMASK, &sigmask_protect, NULL); 93 | 94 | memset(&signal_action, 0, sizeof(signal_action)); 95 | signal_action.sa_handler = interrupt_handler; 96 | sigemptyset(&signal_action.sa_mask); 97 | sigaction(SIGALRM, &signal_action, NULL); 98 | sigaction(SIGUSR1, &signal_action, NULL); 99 | 100 | memset(&timer_event, 0, sizeof(timer_event)); 101 | timer_event.sigev_notify = SIGEV_SIGNAL; 102 | timer_event.sigev_signo = SIGALRM; 103 | 104 | timer_create(CLOCK_REALTIME, &timer_event, &posix_srp_timer); 105 | 106 | clock_gettime(CLOCK_REALTIME, &posix_srp_timer_timestamp); 107 | 108 | root = pthread_self(); 109 | } 110 | 111 | /* ************************************************************************** */ 112 | 113 | void posix_srp_print(const char * const msg) 114 | { 115 | fprintf(stderr, "%s", msg); 116 | } 117 | 118 | /* ************************************************************************** */ 119 | 120 | void posix_srp_panic(const char * const msg) 121 | { 122 | fprintf(stderr, "%s", msg); 123 | abort(); 124 | } 125 | 126 | /* ************************************************************************** */ 127 | 128 | void posix_srp_protect(int state) 129 | { 130 | if (state) { 131 | pthread_sigmask(SIG_SETMASK, &sigmask_protect, NULL); 132 | posix_srp_protected = 1; 133 | } else { 134 | posix_srp_protected = 0; 135 | pthread_sigmask(SIG_SETMASK, &sigmask_unprotect, NULL); 136 | } 137 | } 138 | 139 | /* ************************************************************************** */ 140 | 141 | void posix_srp_idle(void) 142 | { 143 | posix_srp_protect(0); 144 | for (;;) { 145 | pause(); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /env/posix_srp/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ENV_POSIX_TYPES_H_ 32 | #define ENV_POSIX_TYPES_H_ 33 | 34 | /* Standard C headers. */ 35 | #include 36 | #include 37 | #include 38 | 39 | /* ************************************************************************** */ 40 | 41 | /** 42 | * \brief Typedef so that TinyTimber knows what a result is. 43 | */ 44 | typedef uintptr_t env_result_t; 45 | 46 | /* ************************************************************************** */ 47 | 48 | /** 49 | * \brief POSIX interrupt handler. 50 | */ 51 | typedef void (*posix_ext_interrupt_handler_t)(int); 52 | 53 | /* ************************************************************************** */ 54 | 55 | /** 56 | * \brief POSIX SRP Uses special env_time_t type. 57 | * 58 | * struct timespec is used for time instead of the standard unsigned long. 59 | */ 60 | #define ENV_TIME_T 1 61 | 62 | /* ************************************************************************** */ 63 | 64 | /** 65 | * \brief POSIX env_time_t specific type, not standard. 66 | */ 67 | typedef struct timespec env_time_t; 68 | 69 | /* ************************************************************************** */ 70 | 71 | /** 72 | * \brief Environments time less than macro. 73 | */ 74 | #define ENV_TIME_LT(v0, v1) \ 75 | (\ 76 | ((v0).tv_sec < (v1).tv_sec) ||\ 77 | (((v0).tv_sec == (v1).tv_sec) && ((v0).tv_nsec < (v1).tv_nsec))\ 78 | ) 79 | 80 | /* ************************************************************************** */ 81 | 82 | /** 83 | * \brief Environments time less than or equal to macro. 84 | */ 85 | #define ENV_TIME_LE(v0, v1) \ 86 | (\ 87 | ((v0).tv_sec <= (v1).tv_sec) &&\ 88 | ((v0).tv_nsec <= (v1).tv_nsec)\ 89 | ) 90 | 91 | /* ************************************************************************** */ 92 | 93 | /** 94 | * \brief Environments time add macro. 95 | */ 96 | #define ENV_TIME_ADD(v0, v1) \ 97 | posix_srp_time_add(&v0, &v1) 98 | 99 | /* ************************************************************************** */ 100 | 101 | /** 102 | * \brief POSIX time inherit value. 103 | */ 104 | extern env_time_t posix_time_inherit; 105 | 106 | /* ************************************************************************** */ 107 | 108 | /** 109 | * \brief POSIX time inherit macro. 110 | * 111 | * Used to indicate that the time should be inherited. 112 | */ 113 | #define ENV_TIME_INHERIT \ 114 | posix_time_inherit 115 | 116 | /* ************************************************************************** */ 117 | 118 | /** 119 | * \brief POSIX time inherited macro. 120 | * 121 | * Used to check if the time was inherited or not. 122 | */ 123 | #define ENV_TIME_INHERITED(v0) \ 124 | (((v0).tv_sec == 0) && (((v0).tv_nsec) == 0)) 125 | 126 | /* ************************************************************************** */ 127 | 128 | /** 129 | * \brief POSIX env_time_t addition function. 130 | * 131 | * Non-standard addition of the time types, should be inlined and/or eliminated 132 | * whenever you compile your code since it's static inline. Not always true but 133 | * at least sort of true for GCC (-O1+). 134 | * 135 | * \param v0 Frist value. 136 | * \param v1 Second value. 137 | * \return v0 + v1 with some special checks for overflow. 138 | */ 139 | static inline env_time_t posix_srp_time_add( 140 | env_time_t *v0, 141 | env_time_t *v1 142 | ) 143 | { 144 | env_time_t tmp; 145 | if ((v0->tv_nsec + v1->tv_nsec) > 1000000000UL) { 146 | tmp.tv_sec = v0->tv_sec + v1->tv_sec + 1; 147 | tmp.tv_nsec = v0->tv_nsec + v1->tv_nsec - 1000000000UL; 148 | } else { 149 | tmp.tv_sec = v0->tv_sec + v1->tv_sec; 150 | tmp.tv_nsec = v0->tv_nsec + v1->tv_nsec; 151 | } 152 | return tmp; 153 | } 154 | 155 | 156 | #endif 157 | -------------------------------------------------------------------------------- /env/skel/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef ENV_ROOT 10 | $(error Variable ENV_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Sanity check since and SRP environment is quite different. 15 | ################################################################################ 16 | ifdef SRP 17 | $(error Environment does not support SRP.) 18 | endif 19 | 20 | ################################################################################ 21 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 22 | ################################################################################ 23 | 24 | CC := gcc 25 | CFLAGS := -DENV_SKEL=1 -Wall -O2 -I$(ENV_ROOT) $(CFLAGS) 26 | 27 | ################################################################################ 28 | # Setup the rules for building the required object files from the source. 29 | ################################################################################ 30 | 31 | $(BUILD_ROOT)/env.o: $(ENV_ROOT)/$(ENV)/env.c 32 | $(CC) $(CFLAGS) $< -c -o $@ 33 | 34 | ################################################################################ 35 | # Setup the required objects for the enviroment sources. 36 | ################################################################################ 37 | 38 | ENV_OBJECTS := $(BUILD_ROOT)/env.o 39 | -------------------------------------------------------------------------------- /env/skel/env.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | -------------------------------------------------------------------------------- /env/skel/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /** 32 | * \brief Skeleton environment types. 33 | * 34 | * Just used for compile testing and perhaps as a template for a new 35 | * environment. Should compile but does not run. 36 | */ 37 | #ifndef ENV_SKEL_TYPES_H_ 38 | #define ENV_SKEL_TYPES_H_ 39 | 40 | /** 41 | * \brief Environment context typedef. 42 | * 43 | * Should evalutate to the type that is used to store the context of a 44 | * thread. 45 | */ 46 | typedef struct env_context_t {int dummy;} env_context_t; 47 | 48 | /** 49 | * \brief Environment result typdef. 50 | * 51 | * Should evaluate to the result of a synchronus function call. 52 | */ 53 | typedef int env_result_t; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /env/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ENV_TYPES_H_ 32 | #define ENV_TYPES_H_ 33 | 34 | #if ! defined TT_MANGLED 35 | # if defined ENV_POSIX 36 | # include "posix/types.h" 37 | # elif defined ENV_POSIX_SRP 38 | # include "posix_srp/types.h" 39 | # elif defined ENV_MSP430 40 | # include "msp430/types.h" 41 | # elif defined ENV_MSP430_SRP 42 | # include "msp430_srp/types.h" 43 | # elif defined ENV_AVR5 44 | # include "avr5/types.h" 45 | # elif defined ENV_PIC18 46 | # include "pic18/types.h" 47 | # elif defined ENV_ARM7 48 | # include "arm7/types.h" 49 | # elif defined ENV_GBA 50 | # include "gba/types.h" 51 | # elif defined ENV_MIPS 52 | # include "mips/types.h" 53 | # elif defined ENV_M16C 54 | # include "m16c/types.h" 55 | # elif defined ENV_M16C_SRP 56 | # include "m16c_srp/types.h" 57 | # elif defined ENV_SKEL 58 | # include "skel/types.h" 59 | # else 60 | # error Unknown environment. 61 | # endif 62 | #endif 63 | 64 | #if defined TT_SRP 65 | # if ! defined ENV_RESOURCE_T 66 | /* 67 | * Resource definition was not supplied by the environment 68 | * so we supply the default definition as an unsigned long. 69 | */ 70 | # include 71 | typedef unsigned long env_resource_t; 72 | 73 | # define ENV_RESOURCE_MAX \ 74 | (sizeof(env_resource_t)*CHAR_BIT) 75 | # define ENV_RESOURCE(id) \ 76 | (1< 124 | typedef unsigned long env_time_t; 125 | 126 | # define ENV_TIME_LT(v0, v1) \ 127 | (((env_time_t)(v1) - (env_time_t)(v0) - (env_time_t)1) < (env_time_t)LONG_MAX) 128 | 129 | # define ENV_TIME_EQ(v0, v1) \ 130 | ((v0) == (v1)) 131 | 132 | # define ENV_TIME_LE(v0, v1) \ 133 | (((env_time_t)(v1) - (env_time_t)(v0)) < (env_time_t)LONG_MAX) 134 | 135 | 136 | # define ENV_TIME_GE(v0, v1) \ 137 | (!ENV_TIME_LT(v0, v1) || ENV_TIME_EQ(v0, v1)) 138 | 139 | # define ENV_TIME_ADD(v0, v1) \ 140 | ((v0) + (v1)) 141 | 142 | # define ENV_TIME_INHERIT \ 143 | (0) 144 | 145 | # define ENV_TIME_INHERITED(v0) \ 146 | ((v0) == 0ul) 147 | #else 148 | /* 149 | * If the nevironment supplies a special time type we'lll try to 150 | * check it for errors. 151 | */ 152 | # ifndef ENV_TIME_LT 153 | # error Environment did not define ENV_TIME_LT() 154 | # endif 155 | 156 | # ifndef ENV_TIME_LE 157 | # error Environment did not define ENV_TIME_LE() 158 | # endif 159 | 160 | # ifndef ENV_TIME_ADD 161 | # error Environment did not define ENV_TIME_ADD() 162 | # endif 163 | 164 | # ifndef ENV_TIME_INHERIT 165 | # error Environment did not define ENV_TIME_INHERIT 166 | # endif 167 | 168 | # ifndef ENV_TIME_INHERITED 169 | # error Environment did not define ENV_TIME_INHERITED() 170 | # endif 171 | 172 | #endif 173 | 174 | #endif 175 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # ENV is a required variable since it's used to generate a lot of 3 | # the other variables such as BUILD_ROOT etc. 4 | ################################################################################ 5 | 6 | #ENV=arm7 7 | #ENV=avr5 8 | #ENV=m16c 9 | #ENV=mips 10 | #ENV=msp430 11 | #ENV=pic18 12 | #ENV=posix 13 | #ENV=posix_srp 14 | #ENV=skel 15 | 16 | ifndef ENV 17 | $(error Variable ENV was not defined.) 18 | endif 19 | 20 | ################################################################################ 21 | # Almost as important as the ENV variable is the SRP variable. SRP 22 | # controls if the SRP or regular version of the kernel should be used. Since 23 | # this is NOT an SRP example let's leave it undefined. 24 | ################################################################################ 25 | 26 | #SRP=yes 27 | 28 | ################################################################################ 29 | # The BUILD_ROOT Variable is required as all the objects will be created in 30 | # the $(BUILD_ROOT)/ directory. 31 | ################################################################################ 32 | 33 | BUILD_ROOT=./$(ENV) 34 | 35 | ################################################################################ 36 | # TT_ROOT specifies where the TinyTimber headers and source is located. 37 | ################################################################################ 38 | 39 | TT_ROOT=../../tT/ 40 | 41 | ################################################################################ 42 | # ENV_ROOT specifies the Environment root, where all the different environents 43 | # are located. 44 | ################################################################################ 45 | 46 | ENV_ROOT=../../env/ 47 | 48 | ################################################################################ 49 | # APP_ROOT specifies the Application root, where the source of the application 50 | # is located. 51 | ################################################################################ 52 | 53 | APP_ROOT=./src/ 54 | 55 | ################################################################################ 56 | # Create the all target before we include any other target rules in Environment/ 57 | # Kernel Makefiles. 58 | ################################################################################ 59 | 60 | .PHONY: all build_root build rebuild clean 61 | all: build_root build 62 | 63 | ################################################################################ 64 | # Now we will include the Makefile for the environment that we wish to build. 65 | ################################################################################ 66 | 67 | include $(ENV_ROOT)/$(ENV)/Makefile 68 | 69 | ################################################################################ 70 | # Now we will include the Makefile for the TinyTimber kernel that we wish 71 | # to build (Regular or SRP). Make sure that the enviroment supports the 72 | # kernel we wish to build. 73 | ################################################################################ 74 | 75 | include $(TT_ROOT)/Makefile 76 | 77 | ################################################################################ 78 | # And last but not the least include the application Makefile. 79 | ################################################################################ 80 | 81 | include $(APP_ROOT)/Makefile 82 | 83 | ################################################################################ 84 | # Define the targets required by all. 85 | ################################################################################ 86 | 87 | $(BUILD_ROOT): build_root 88 | 89 | build_root: 90 | @test -d $(BUILD_ROOT) || mkdir -p $(BUILD_ROOT) 91 | 92 | build: $(ENV_OBJECTS) $(TT_OBJECTS) $(APP_OBJECTS) $(APP_BINARY) 93 | 94 | $(APP_BINARY): $(ENV_OBJECTS) $(TT_OBJECTS) $(APP_OBJECTS) 95 | $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ 96 | 97 | ################################################################################ 98 | # Rebuild rule that should force a rebuild of all the files. 99 | ################################################################################ 100 | rebuild: clean build_root build 101 | 102 | ################################################################################ 103 | # Last but not the least let's make a clean rule. 104 | ################################################################################ 105 | 106 | clean: 107 | rm -rf $(BUILD_ROOT) 108 | 109 | ################################################################################ 110 | # Since we can't really supply the means of flashing the device in a somewhat 111 | # portable manner we'll make the target specific for each ARCH. 112 | ################################################################################ 113 | 114 | # msp430 specific targets 115 | ifeq ($(ENV_ARCH), msp430) 116 | flash: $(APP_ELF) 117 | msp430-jtag --no-close --elf -e $(APP_ELF) 118 | endif 119 | 120 | # avr5 specific targets. 121 | ifeq ($(ENV_ARCH), avr5) 122 | ifdef APP_HEX 123 | $(APP_HEX): $(APP_ELF) 124 | avr-objcopy -R .eeprom -O ihex $(APP_ELF) $(APP_HEX) 125 | 126 | flash: $(APP_HEX) 127 | avrdude -c jtag2 -P usb -p c128 -U flash:w:$< 128 | 129 | debug: 130 | avarice --mkII --detach --jtag usb :2000 131 | avr-gdb -x $(ENV_ROOT)/$(ENV_ARCH)/gdbrc 132 | endif 133 | endif 134 | 135 | ifeq ($(ENV_ARCH), m16c) 136 | ifdef APP_MOT 137 | # Create the mot file. 138 | $(APP_MOT): $(APP_ELF) 139 | m32c-elf-objcopy -O srec $(APP_ELF) $(APP_MOT) 140 | 141 | # Flash the mot file to the device. 142 | flash: $(APP_MOT) 143 | ~/src/sf/sf.py --device /dev/ttyUSB0 --device-id 0:0:0:0:0:0:0 --baud-rate 57600 --input-file $(APP_MOT) --id-validate --flash-erase-all --flash-write 144 | endif 145 | endif 146 | -------------------------------------------------------------------------------- /examples/doxygen/tt_action.c: -------------------------------------------------------------------------------- 1 | /* Example structure for multiple arguments. */ 2 | typedef struct test_args_t 3 | { 4 | int a0; 5 | unsigned short a1; 6 | struct 7 | { 8 | char b0; 9 | char b1; 10 | } bytes; 11 | } test_args_t; 12 | 13 | /* Example function. */ 14 | env_result_t test(tt_object_t *self, test_args_t *args) 15 | { 16 | /* Do something with the arguments, might be more usefull than this. */ 17 | return args->a0<bytes.b0 + args->a1*args->bytes.b1; 18 | } 19 | 20 | /* Example invocation of test function after 1 second. */ 21 | tt_object_t object = tt_object(); 22 | test_args_t args = {0, 1, {2, 3}}; 23 | TT_AFTER(ENV_TIME_SEC(1), &object, test, &args); 24 | -------------------------------------------------------------------------------- /examples/hello_world/Makefile: -------------------------------------------------------------------------------- 1 | ../Makefile -------------------------------------------------------------------------------- /examples/hello_world/src/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef APP_ROOT 10 | $(error Variable APP_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 15 | ################################################################################ 16 | 17 | CFLAGS := -I$(APP_ROOT) $(CFLAGS) 18 | 19 | ################################################################################ 20 | # Setup the rules for building the required object files from the source. 21 | ################################################################################ 22 | 23 | $(BUILD_ROOT)/main.o: $(APP_ROOT)/main.c 24 | $(CC) $(CFLAGS) $< -c -o $@ 25 | 26 | ################################################################################ 27 | # Setup the required objects for the application sources. 28 | ################################################################################ 29 | 30 | APP_OBJECTS := $(BUILD_ROOT)/main.o 31 | 32 | ################################################################################ 33 | # Last but not the least we define the binary output of the application. 34 | ################################################################################ 35 | 36 | APP_BINARY := $(BUILD_ROOT)/app.elf 37 | -------------------------------------------------------------------------------- /examples/hello_world/src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | typedef struct hello_t 37 | { 38 | tt_object_t obj; 39 | } hello_t; 40 | 41 | static hello_t hello; 42 | 43 | static env_result_t hello_world(tt_object_t *self, void *arg) 44 | { 45 | TT_WITHIN(ENV_SEC(1), ENV_MSEC(500), self, hello_world, TT_ARGS_NONE); 46 | ENV_DEBUG("Hello World!\n"); 47 | return 0; 48 | } 49 | 50 | void init(void) 51 | { 52 | TT_WITHIN(ENV_SEC(0), ENV_MSEC(500),&hello, hello_world, TT_ARGS_NONE); 53 | } 54 | 55 | ENV_STARTUP(init); 56 | -------------------------------------------------------------------------------- /examples/hello_world_srp/Makefile: -------------------------------------------------------------------------------- 1 | ../Makefile -------------------------------------------------------------------------------- /examples/hello_world_srp/src/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef APP_ROOT 10 | $(error Variable APP_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 15 | ################################################################################ 16 | 17 | CFLAGS := -I$(APP_ROOT) $(CFLAGS) -g -O2 18 | 19 | ################################################################################ 20 | # Setup the rules for building the required object files from the source. 21 | ################################################################################ 22 | 23 | $(BUILD_ROOT)/main.o: $(APP_ROOT)/main.c 24 | $(CC) $(CFLAGS) $< -c -o $@ 25 | 26 | ################################################################################ 27 | # Setup the required objects for the application sources. 28 | ################################################################################ 29 | 30 | APP_OBJECTS := $(BUILD_ROOT)/main.o 31 | 32 | ################################################################################ 33 | # Last but not the least we define the binary output of the application. 34 | ################################################################################ 35 | 36 | APP_BINARY := $(BUILD_ROOT)/app.elf 37 | -------------------------------------------------------------------------------- /examples/hello_world_srp/src/app_objects.h: -------------------------------------------------------------------------------- 1 | #ifndef APP_OBJECT_H_ 2 | #define APP_OBJECT_H_ 3 | 4 | /** 5 | * \brief TinyTimber object id enum. 6 | * 7 | * Please add any object name/id you wish to this enum. Do _NOT_ specify an 8 | * id, it will be assigned automatically. 9 | */ 10 | enum app_objects_t 11 | { 12 | HELLO, 13 | APP_OBJECT_ID_MAX /* MUST NOT BE REMOVED! */ 14 | }; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /examples/hello_world_srp/src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "app_objects.h" 5 | 6 | typedef struct hello_t 7 | { 8 | tt_object_t obj; 9 | } hello_t; 10 | #define hello(oid, req) {tt_object(oid, req)} 11 | 12 | hello_t hello = hello(HELLO, 0); 13 | 14 | tt_object_t *app_objects[APP_OBJECT_ID_MAX] = { 15 | (tt_object_t*)&hello 16 | }; 17 | 18 | static env_result_t hello_world(hello_t *, void *); 19 | 20 | static env_result_t hello_world(hello_t *self, void *args) 21 | { 22 | ENV_DEBUG("Hello World!\r\n"); 23 | TT_WITHIN(ENV_SEC(1), ENV_MSEC(500), self, hello_world, TT_ARGS_NONE); 24 | return 0; 25 | } 26 | static void init(void) 27 | { 28 | TT_WITHIN(ENV_SEC(0), ENV_MSEC(500), &hello, hello_world, TT_ARGS_NONE); 29 | } 30 | 31 | ENV_STARTUP(init); 32 | -------------------------------------------------------------------------------- /examples/srp/Makefile: -------------------------------------------------------------------------------- 1 | ../Makefile -------------------------------------------------------------------------------- /examples/srp/src/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef APP_ROOT 10 | $(error Variable APP_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 15 | ################################################################################ 16 | 17 | CFLAGS := -I$(APP_ROOT) $(CFLAGS) -g -O2 -DTT_NUM_MESSAGES=20 18 | 19 | ################################################################################ 20 | # Setup the rules for building the required object files from the source. 21 | ################################################################################ 22 | 23 | $(BUILD_ROOT)/main.o: $(APP_ROOT)/main.c 24 | $(CC) $(CFLAGS) $< -c -o $@ 25 | 26 | ################################################################################ 27 | # Setup the required objects for the application sources. 28 | ################################################################################ 29 | 30 | APP_OBJECTS := $(BUILD_ROOT)/main.o 31 | 32 | ################################################################################ 33 | # Last but not the least we define the binary output of the application. 34 | ################################################################################ 35 | 36 | APP_BINARY := $(BUILD_ROOT)/app.elf 37 | -------------------------------------------------------------------------------- /examples/srp/src/app_objects.h: -------------------------------------------------------------------------------- 1 | #ifndef APP_OBJECT_H_ 2 | #define APP_OBJECT_H_ 3 | 4 | /** 5 | * \brief TinyTimber object id enum. 6 | * 7 | * Please add any object name/id you wish to this enum. Do _NOT_ specify an 8 | * id, it will be assigned automatically. 9 | */ 10 | enum app_objects_t 11 | { 12 | OBJECT_A, 13 | OBJECT_B, 14 | OBJECT_C, 15 | OBJECT_D, 16 | RELEASE, 17 | ANNOUNCE, 18 | APP_OBJECT_ID_MAX /* MUST NOT BE REMOVED! */ 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /examples/srp/src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "app_objects.h" 5 | 6 | typedef struct wait_t 7 | { 8 | tt_object_t obj; 9 | volatile char flag; 10 | } wait_t; 11 | #define wait(oid, req) {tt_object(oid, req), 1} 12 | 13 | typedef struct release_t 14 | { 15 | tt_object_t obj; 16 | } release_t; 17 | #define release(oid, req) {tt_object(oid, req)} 18 | 19 | typedef struct announce_t 20 | { 21 | tt_object_t obj; 22 | } announce_t; 23 | #define announce(oid, req) {tt_object(oid, req)} 24 | 25 | wait_t object_a = wait(OBJECT_A, 0); 26 | wait_t object_b = wait(OBJECT_B, ENV_RESOURCE(OBJECT_A)); 27 | wait_t object_c = wait(OBJECT_C, ENV_RESOURCE(OBJECT_B)); 28 | wait_t object_d = wait(OBJECT_D, 0); 29 | 30 | release_t release = release(RELEASE, 0); 31 | 32 | announce_t announce = announce(ANNOUNCE, 0); 33 | 34 | tt_object_t *app_objects[APP_OBJECT_ID_MAX] = { 35 | (tt_object_t*)&object_a, 36 | (tt_object_t*)&object_b, 37 | (tt_object_t*)&object_c, 38 | (tt_object_t*)&object_d, 39 | (tt_object_t*)&release, 40 | (tt_object_t*)&announce 41 | }; 42 | 43 | static env_result_t wait_a(wait_t *, void*); 44 | static env_result_t wait_b(wait_t *, void*); 45 | static env_result_t wait_c(wait_t *, void*); 46 | static env_result_t wait_d(wait_t *, void*); 47 | static env_result_t queue_a(announce_t *, void *); 48 | static env_result_t queue_b(announce_t *, void *); 49 | static env_result_t queue_c(announce_t *, void *); 50 | static env_result_t queue_d(announce_t *, void *); 51 | static env_result_t release_a(release_t *, char **); 52 | static env_result_t release_b(release_t *, char **); 53 | static env_result_t release_c(release_t *, char **); 54 | static env_result_t release_d(release_t *, char **); 55 | 56 | static env_result_t wait_a(wait_t *self, void *args) 57 | { 58 | ENV_DEBUG("\twait_a: start\r\n"); 59 | while (self->flag) {} 60 | ENV_DEBUG("\twait_a: done\r\n"); 61 | return 0; 62 | } 63 | 64 | static env_result_t wait_b(wait_t *self, void *args) 65 | { 66 | ENV_DEBUG("\t\twait_b: start\r\n"); 67 | while (self->flag) {} 68 | ENV_DEBUG("\t\twait_b: done\r\n"); 69 | return 0; 70 | } 71 | 72 | static env_result_t wait_c(wait_t *self, void *args) 73 | { 74 | ENV_DEBUG("\t\t\twait_c: start\r\n"); 75 | while (self->flag) {} 76 | ENV_DEBUG("\t\t\twait_c: done\r\n"); 77 | return 0; 78 | } 79 | 80 | static env_result_t wait_d(wait_t *self, void *args) 81 | { 82 | ENV_DEBUG("\t\t\t\twait_d: start\r\n"); 83 | while (self->flag) {} 84 | ENV_DEBUG("\t\t\t\twait_d: done\r\n"); 85 | return 0; 86 | } 87 | 88 | static env_result_t release_a(release_t *self, char **args) 89 | { 90 | object_a.flag = 0; 91 | return 0; 92 | } 93 | 94 | static env_result_t release_b(release_t *self, char **args) 95 | { 96 | object_b.flag = 0; 97 | return 0; 98 | } 99 | 100 | static env_result_t release_c(release_t *self, char **args) 101 | { 102 | object_c.flag = 0; 103 | return 0; 104 | } 105 | 106 | static env_result_t release_d(release_t *self, char **args) 107 | { 108 | object_d.flag = 0; 109 | return 0; 110 | } 111 | 112 | static env_result_t queue_a(announce_t *self, void *args) 113 | { 114 | ENV_DEBUG("\r\n"); 115 | return 0; 116 | } 117 | 118 | static env_result_t queue_b(announce_t *self, void *args) 119 | { 120 | ENV_DEBUG("\r\n"); 121 | return 0; 122 | } 123 | 124 | static env_result_t queue_c(announce_t *self, void *args) 125 | { 126 | ENV_DEBUG("\r\n"); 127 | return 0; 128 | } 129 | 130 | static env_result_t queue_d(announce_t *self, void *args) 131 | { 132 | ENV_DEBUG("\r\n"); 133 | return 0; 134 | } 135 | 136 | static void init(void) 137 | { 138 | TT_WITHIN(ENV_SEC(1), ENV_SEC(50), &object_a, wait_a, TT_ARGS_NONE); 139 | TT_WITHIN(ENV_SEC(1), ENV_SEC(49), &announce, queue_a, TT_ARGS_NONE); 140 | TT_WITHIN(ENV_SEC(5), ENV_SEC(0), &release, release_a, TT_ARGS_NONE); 141 | 142 | TT_WITHIN(ENV_SEC(2), ENV_SEC(40), &object_b, wait_b, TT_ARGS_NONE); 143 | TT_WITHIN(ENV_SEC(2), ENV_SEC(39), &announce, queue_b, TT_ARGS_NONE); 144 | TT_WITHIN(ENV_SEC(6), ENV_SEC(0), &release, release_b, TT_ARGS_NONE); 145 | 146 | TT_WITHIN(ENV_SEC(3), ENV_SEC(30), &object_c, wait_c, TT_ARGS_NONE); 147 | TT_WITHIN(ENV_SEC(3), ENV_SEC(29), &announce, queue_c, TT_ARGS_NONE); 148 | TT_WITHIN(ENV_SEC(6), ENV_SEC(0), &release, release_c, TT_ARGS_NONE); 149 | 150 | TT_WITHIN(ENV_SEC(4), ENV_SEC(20), &object_d, wait_d, TT_ARGS_NONE); 151 | TT_WITHIN(ENV_SEC(4), ENV_SEC(19), &announce, queue_d, TT_ARGS_NONE); 152 | TT_WITHIN(ENV_SEC(8), ENV_SEC(0), &release, release_d, TT_ARGS_NONE); 153 | } 154 | 155 | ENV_STARTUP(init); 156 | -------------------------------------------------------------------------------- /mangle.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | usage() 4 | { 5 | echo "mangle.sh " 6 | exit 1 7 | } 8 | 9 | if test $# -ne 1 10 | then 11 | echo "Wrong number of parameters." > /dev/stderr 12 | usage 13 | fi 14 | 15 | MANGLE_SPEC=env/$1/mangle.spec 16 | if test ! -f $MANGLE_SPEC 17 | then 18 | echo "Environment ${1} does not support mangling." 19 | exit 1 20 | fi 21 | 22 | TT_C=`cat $MANGLE_SPEC|awk -F= '/TT_C/{print $2}'` 23 | TT_H=`cat $MANGLE_SPEC|awk -F= '/TT_H/{print $2}'` 24 | 25 | TT_C="`echo ${TT_C}|sed -e 's/_KERNEL_/tT\/kernel.c/g'`" 26 | TT_H="`echo ${TT_H}|sed -e 's/_KERNEL_/tT\/kernel.h/g'`" 27 | TT_H="`echo ${TT_H}|sed -e 's/_TT_/tT\/tT.h/g'`" 28 | TT_H="`echo ${TT_H}|sed -e 's/_ENV_/env\/env.h/g'`" 29 | 30 | MANGLED_DIR=mangled/$1 31 | MANGLED_C=mangled/$1/tT.c 32 | MANGLED_H=mangled/$1/tT.h 33 | 34 | SHA1=`git-show-ref --heads --hash` 35 | ORIGIN="/* MANGLED ORIGIN: ${SHA1} */\n" 36 | 37 | MANGLED_C_HEADER="#include " 38 | MANGLED_C_FOOTER="" 39 | 40 | MANGLED_H_HEADER="#ifndef TT_MANGLED\n#define TT_MANGLED" 41 | MANGLED_H_FOOTER="#endif\n" 42 | 43 | mkdir -p $MANGLED_DIR 44 | 45 | rm -f $MANGLED_C 46 | echo -e "${ORIGIN}" >> $MANGLED_C 47 | echo -e "${MANGLED_C_HEADER}" >> $MANGLED_C 48 | for i in $TT_C 49 | do 50 | echo -e "\n/* MANGLE FILE: ${i} */\n" >> $MANGLED_C 51 | cat $i >> $MANGLED_C 52 | done 53 | echo -e "${MANGLED_C_FOOTER}" >> $MANGLED_C 54 | 55 | rm -f $MANGLED_H 56 | echo -e "${ORIGIN}" >> $MANGLED_H 57 | echo -e "${MANGLED_H_HEADER}" >> $MANGLED_H 58 | for i in $TT_H 59 | do 60 | echo -e "\n/* MANGLE FILE: ${i} */\n" >> $MANGLED_H 61 | cat $i >> $MANGLED_H 62 | done 63 | echo -e "${MANGLED_H_FOOTER}" >> $MANGLED_H 64 | -------------------------------------------------------------------------------- /tT/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Check the required variables, such as BUILD_ROOT, TT_ROOT, and ENV_ROOT. 3 | ################################################################################ 4 | 5 | ifndef BUILD_ROOT 6 | $(error Variable BUILD_ROOT was not defined.) 7 | endif 8 | 9 | ifndef TT_ROOT 10 | $(error Variable TT_ROOT was not defined.) 11 | endif 12 | 13 | ################################################################################ 14 | # Setup any build related flags, such as CC, AS, LDFLAGS, CFLAGS etc. 15 | ################################################################################ 16 | 17 | ifdef SRP 18 | CFLAGS := -DTT_SRP=1 -I$(TT_ROOT) $(CFLAGS) 19 | else 20 | CFLAGS := -I$(TT_ROOT) $(CFLAGS) 21 | endif 22 | 23 | ################################################################################ 24 | # Setup the rules for building the required object files from the source. 25 | ################################################################################ 26 | 27 | 28 | ifdef SRP 29 | $(BUILD_ROOT)/kernel_srp.o: $(TT_ROOT)/kernel_srp.c 30 | $(CC) $(CFLAGS) $< -c -o $@ 31 | $(BUILD_ROOT)/objects_srp.o: $(TT_ROOT)/objects_srp.c 32 | $(CC) $(CFLAGS) $< -c -o $@ 33 | else 34 | $(BUILD_ROOT)/kernel.o: $(TT_ROOT)/kernel.c 35 | $(CC) $(CFLAGS) $< -c -o $@ 36 | endif 37 | 38 | ################################################################################ 39 | # Setup the required objects for the kernel sources. 40 | ################################################################################ 41 | 42 | ifdef SRP 43 | TT_OBJECTS := $(BUILD_ROOT)/kernel_srp.o\ 44 | $(BUILD_ROOT)/objects_srp.o 45 | else 46 | TT_OBJECTS := $(BUILD_ROOT)/kernel.o 47 | endif 48 | -------------------------------------------------------------------------------- /tT/kernel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef KERNEL_H_ 32 | #define KERNEL_H_ 33 | 34 | /* 35 | * Following files should not be included in case the file is mangled. 36 | */ 37 | #if ! defined TT_MANGLED 38 | # include 39 | # include 40 | #endif 41 | 42 | /* 43 | * Just so that the user is aware that he gone did something stupid. 44 | */ 45 | #if defined ENV_SRP 46 | # error Compiling regular TinyTimber against SRP environment. 47 | #endif 48 | 49 | /* ************************************************************************** */ 50 | 51 | /** 52 | * \brief tinyTimber thread function typedef. 53 | */ 54 | typedef void (*tt_thread_function_t)(void); 55 | 56 | /* ************************************************************************** */ 57 | 58 | #if ! defined TT_TIMBER 59 | 60 | /** 61 | * \brief tinyTimber message typedef. 62 | */ 63 | typedef struct tt_message_t tt_message_t; 64 | 65 | /** 66 | * \brief Macro to start a message. 67 | */ 68 | #define TT_MESSAGE_RUN(msg) \ 69 | do {\ 70 | tt_request((msg)->to, (msg)->method, &(msg)->arg);\ 71 | } while (0) 72 | #else 73 | /** 74 | * \brief tinyTimber message typedef. 75 | */ 76 | typedef struct Msg tt_message_t; 77 | 78 | /** 79 | * \brief Macro to start a message. 80 | */ 81 | #define TT_MESSAGE_RUN(msg) \ 82 | do {\ 83 | if ((msg)->Code != NULL) {\ 84 | (msg)->Code();\ 85 | }\ 86 | } while (0) 87 | 88 | #endif /* defined TT_TIMBER */ 89 | 90 | /* ************************************************************************** */ 91 | 92 | /** 93 | * \brief tinyTimber thread structure. 94 | */ 95 | struct tt_thread_t 96 | { 97 | /** 98 | * \brief The context of the environment. 99 | * 100 | * \note 101 | * We use the same thing as with tt_object_t, keep this as the 102 | * first thing in the struct giving it the same address allowing 103 | * the environment to forget about what a tt_thread_t is. 104 | */ 105 | env_context_t context; 106 | 107 | /** 108 | * \brief The message this thread is running. 109 | */ 110 | tt_message_t *msg; 111 | 112 | /** 113 | * \brief The object this thread is waiting for. 114 | */ 115 | tt_object_t *waits_for; 116 | 117 | /** 118 | * \brief The next thread in the list. 119 | */ 120 | struct tt_thread_t *next; 121 | }; 122 | 123 | /* ************************************************************************** */ 124 | 125 | /** 126 | * \brief The current running thread according to tinyTimber. 127 | */ 128 | extern tt_thread_t *tt_current; 129 | 130 | 131 | /* ************************************************************************** */ 132 | 133 | void tt_interrupt(void); 134 | void tt_expired(env_time_t); 135 | 136 | /* ************************************************************************** */ 137 | 138 | #ifndef TT_NUM_MESSAGES 139 | /** 140 | * \brief The number of messages that the kernel facillitates. 141 | */ 142 | # define TT_NUM_MESSAGES 10 143 | #endif 144 | 145 | /* ************************************************************************** */ 146 | 147 | #ifndef TT_ARGS_SIZE 148 | /** 149 | * \brief The size of the variable argument buffer. 150 | */ 151 | # define TT_ARGS_SIZE 8 152 | #endif 153 | 154 | /* ************************************************************************** */ 155 | 156 | #ifdef TT_KERNEL_SANITY 157 | /** \cond */ 158 | # define _STR(str) #str 159 | # define STR(str) _STR(str) 160 | /** \endcond */ 161 | 162 | /** 163 | * \brief The kernel sanity macro. 164 | * 165 | * Should only be used for debugging purposes. Used whenever 166 | * TT_KERNEL_SANITY is defined. Will fail whenever the expression 167 | * supplied is not evaluated as true. 168 | */ 169 | # define TT_SANITY(expr) \ 170 | if (!(expr))\ 171 | ENV_PANIC(\ 172 | __FILE__ ":" STR(__LINE__) " ("\ 173 | #expr ") failed sanity check.\n"\ 174 | ) 175 | #else 176 | # define TT_SANITY(expr) 177 | #endif 178 | 179 | #endif 180 | -------------------------------------------------------------------------------- /tT/kernel_srp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /** 32 | * \file 33 | * \brief The TinyTimber Kernel environment interface (SRP). 34 | * 35 | * If possible avoid exporting this interface to the user via the environment. 36 | */ 37 | 38 | #ifndef KERNEL_H_ 39 | #define KERNEL_H_ 40 | 41 | /* 42 | * Following files should not be included in case the file is mangled. 43 | */ 44 | #if ! defined TT_MANGLED 45 | # include 46 | # include 47 | #endif 48 | 49 | /* 50 | * Just so that the user is aware that he gone did something stupid. 51 | */ 52 | #if ! defined ENV_SRP 53 | # error Compiling SRP TinyTimber against regular environment. 54 | #endif 55 | 56 | /* ************************************************************************** */ 57 | 58 | /** 59 | * \brief TinyTimber message typedef. 60 | */ 61 | typedef struct tt_message_t tt_message_t; 62 | 63 | /* ************************************************************************** */ 64 | 65 | void tt_expired(env_time_t); 66 | 67 | /* ************************************************************************** */ 68 | 69 | #ifndef TT_NUM_MESSAGES 70 | /** 71 | * \brief The number of messages that the kernel facillitates. 72 | */ 73 | # define TT_NUM_MESSAGES 10 74 | #endif 75 | 76 | /* ************************************************************************** */ 77 | 78 | #ifndef TT_ARGS_SIZE 79 | /** 80 | * \brief The size of the variable argument buffer. 81 | */ 82 | # define TT_ARGS_SIZE 8 83 | #endif 84 | 85 | /* ************************************************************************** */ 86 | 87 | #ifdef TT_KERNEL_SANITY 88 | /** \cond */ 89 | # define _STR(str) #str 90 | # define STR(str) _STR(str) 91 | /** \endcond */ 92 | 93 | /** 94 | * \brief The kernel sanity macro. 95 | * 96 | * Should only be used for debugging purposes. Used whenever 97 | * TT_KERNEL_SANITY is defined. Will fail whenever the expression 98 | * supplied is not evaluated as true. 99 | */ 100 | # define TT_SANITY(expr) \ 101 | if (!(expr))\ 102 | ENV_PANIC(\ 103 | __FILE__ ":" STR(__LINE__) " ("\ 104 | #expr ") failed sanity check.\n"\ 105 | ) 106 | #else 107 | # define TT_SANITY(expr) 108 | #endif 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /tT/objects_srp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | #include 37 | 38 | static void object_calc_req(tt_object_t *object) { 39 | int i; 40 | tt_object_t **tmp = app_objects; 41 | env_resource_t mask = 1; 42 | 43 | for (i=0;i object->resource.req) { 45 | break; 46 | } 47 | 48 | if (mask & object->resource.req) { 49 | if (!(*tmp)->resource.req & (*tmp)->resource.id) { 50 | /* Requirements for this object not yet calculated. */ 51 | object_calc_req(*tmp); 52 | } 53 | 54 | /* Merge resource requirements. */ 55 | object->resource.req |= (*tmp)->resource.req; 56 | } 57 | } 58 | 59 | /* 60 | * Set the object resource id in the requirements field to indicate 61 | * that recursive calculation has already been done. 62 | */ 63 | object->resource.req |= object->resource.id; 64 | } 65 | 66 | /** 67 | * \brief TinyTimber SRP object requirement calculation. 68 | * 69 | * Performs a recursive object requirement calculation. Easier for the 70 | * programmer 71 | */ 72 | void tt_objects_init(void) 73 | { 74 | int i; 75 | tt_object_t **tmp = app_objects; 76 | 77 | if (APP_OBJECT_ID_MAX >= ENV_RESOURCE_MAX) { 78 | ENV_PANIC("tt_object_init(): Maximum number of objects exceeded.\n"); 79 | } 80 | 81 | /* 82 | * For each object we will traverse the list of requirements and 83 | * add them to the list recursively. 84 | */ 85 | for (i=0;iresource.id) { 87 | ENV_PANIC("tt_objects_init(): ID missmatch, check app_objects.\n"); 88 | } 89 | 90 | if ((*tmp)->resource.req & (*tmp)->resource.id) { 91 | /* Requirements already calculated. */ 92 | continue; 93 | } 94 | 95 | object_calc_req(*tmp); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /tT/objects_srp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, Per Lindgren, Johan Eriksson, Johan Nordlander, 3 | * Simon Aittamaa. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of the Luleå University of Technology nor the 15 | * names of its contributors may be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef TT_OBJECTS_H_ 32 | #define TT_OBJECTS_H_ 33 | 34 | #include 35 | 36 | /** 37 | * \brief Application Objects. 38 | * 39 | * Should contain a list of pointers to the objects of the application. 40 | * 41 | * \note List _MUST_ Object location in list and ID must be correct. 42 | */ 43 | extern tt_object_t *app_objects[]; 44 | 45 | void tt_objects_init(void); 46 | 47 | #endif 48 | --------------------------------------------------------------------------------