├── .gitignore ├── Makefile ├── README.md ├── allmake.sh ├── bootloader ├── BCM2835.h ├── BCM2836.h ├── Makefile ├── README ├── bootloader07.c ├── ihex.c ├── loader ├── memmap ├── periph.c ├── start.s └── vectors.s ├── build_toolchain └── arm-none-eabi-gcc.sh ├── dasm ├── csrc │ └── dynasm │ │ ├── WHAT │ │ ├── build-arm.sh │ │ ├── build-linux32.sh │ │ ├── build-linux64.sh │ │ ├── build-mingw32.sh │ │ ├── build-mingw64.sh │ │ ├── build-osx32.sh │ │ ├── build-osx64.sh │ │ ├── build.sh │ │ ├── dasm_arm.c │ │ ├── dasm_arm.h │ │ ├── dasm_extern.h │ │ ├── dasm_mips.h │ │ ├── dasm_ppc.h │ │ ├── dasm_proto.h │ │ ├── dasm_x86.c │ │ └── dasm_x86.h ├── dasm.lua ├── dasm_arm.lua ├── dasm_mm.lua ├── dasm_x64.lua ├── dasm_x86.lua ├── dynasm.lua ├── dynasm.md ├── dynasm_demo.lua └── dynasm_demo_x86.dasl ├── dl_footer._h ├── dl_header._h ├── exception.c ├── fmap_dummy.c ├── ldl.c ├── ldl.h ├── linenoise ├── COPYING ├── Changes ├── Makefile ├── README.md ├── example.lua ├── fmacros.h ├── linenoise.c ├── linenoise.h └── linenoise_lua.c ├── ljuart.c ├── lua ├── asm.lua ├── atags.lua ├── boot.lua ├── cc.lua ├── dasm │ ├── dasm.lua │ ├── dasm_arm.lua │ ├── dasm_mm.lua │ ├── dasm_x64.lua │ ├── dasm_x86.lua │ ├── dis_arm.lua │ ├── dynasm.lua │ └── dynasm_demo.lua ├── dasm_test.lua ├── dkjson │ └── dkjson.lua ├── ffi-reflect │ ├── ffi-reflect-test.lua │ └── reflect.lua ├── fs.lua ├── glob │ └── globtopattern.lua ├── hwrng.lua ├── linenoise.lua ├── lpeg │ ├── lpeg_test.lua │ └── re.lua ├── mbox.lua ├── ml │ └── ml.lua ├── more_tests.lua ├── pl │ ├── Date.lua │ ├── List.lua │ ├── Map.lua │ ├── MultiMap.lua │ ├── OrderedMap.lua │ ├── Set.lua │ ├── app.lua │ ├── array2d.lua │ ├── class.lua │ ├── compat.lua │ ├── comprehension.lua │ ├── config.lua │ ├── data.lua │ ├── dir.lua │ ├── file.lua │ ├── func.lua │ ├── import_into.lua │ ├── init.lua │ ├── input.lua │ ├── lapp.lua │ ├── lexer.lua │ ├── luabalanced.lua │ ├── operator.lua │ ├── path.lua │ ├── permute.lua │ ├── pretty.lua │ ├── seq.lua │ ├── sip.lua │ ├── strict.lua │ ├── stringio.lua │ ├── stringx.lua │ ├── tablex.lua │ ├── template.lua │ ├── test.lua │ ├── text.lua │ ├── types.lua │ ├── url.lua │ ├── utils.lua │ └── xml.lua ├── repl.lua ├── rpboot.lua ├── rpimodels.lua ├── shell.lua ├── sys.lua ├── term │ ├── colors.lua │ ├── completion.lua │ ├── pretty_print.lua │ └── repl_utils.lua ├── test.lua ├── tweetnacl.lua └── zip_require.lua ├── mem.h ├── memmap ├── miniz └── miniz.c ├── mmu.c ├── rboot ├── README ├── atag.c ├── atag.h ├── block.c ├── block.h ├── block_cache.c ├── console.c ├── console.h ├── dirent.h ├── elf.c ├── elf.h ├── emmc.c ├── ext2.c ├── fat.c ├── fb.c ├── fb.h ├── font.c ├── fs.h ├── libfs.c ├── mbox.c ├── mbox.h ├── mbr.c ├── mmio.c ├── mmio.h ├── multiboot.h ├── nofs.c ├── output.c ├── output.h ├── timer.c ├── timer.h ├── uart.c ├── uart.h ├── util.h ├── vfs.c └── vfs.h ├── sqlite_stubs.c ├── syscalls.c ├── tcc ├── COPYING ├── Changelog ├── Makefile ├── README ├── TODO ├── VERSION ├── arm-gen.c ├── c67-gen.c ├── coff.h ├── config.h ├── config.mak ├── config.texi ├── configure ├── conftest-15222.h ├── conftest.c ├── elf.h ├── examples │ ├── ex1.c │ ├── ex2.c │ ├── ex3.c │ ├── ex4.c │ └── ex5.c ├── i386-asm.c ├── i386-asm.h ├── i386-gen.c ├── i386-tok.h ├── il-gen.c ├── il-opcodes.h ├── include │ ├── float.h │ ├── stdarg.h │ ├── stdbool.h │ ├── stddef.h │ ├── tcclib.h │ └── varargs.h ├── lib │ ├── Makefile │ ├── alloca86-bt.S │ ├── alloca86.S │ ├── alloca86_64.S │ ├── bcheck.c │ └── libtcc1.c ├── libtcc.c ├── libtcc.h ├── stab.def ├── stab.h ├── tcc-doc.html ├── tcc-doc.texi ├── tcc.c ├── tcc.h ├── tccasm.c ├── tcccoff.c ├── tccelf.c ├── tccgen.c ├── tccpe.c ├── tccpp.c ├── tccrun.c ├── tcctok.h ├── tests │ ├── Makefile │ ├── asmtest.S │ ├── boundtest.c │ ├── gcctestsuite.sh │ ├── libtcc_test.c │ ├── tcctest.c │ └── tests2 │ │ ├── 00_assignment.c │ │ ├── 00_assignment.expect │ │ ├── 01_comment.c │ │ ├── 01_comment.expect │ │ ├── 02_printf.c │ │ ├── 02_printf.expect │ │ ├── 03_struct.c │ │ ├── 03_struct.expect │ │ ├── 04_for.c │ │ ├── 04_for.expect │ │ ├── 05_array.c │ │ ├── 05_array.expect │ │ ├── 06_case.c │ │ ├── 06_case.expect │ │ ├── 07_function.c │ │ ├── 07_function.expect │ │ ├── 08_while.c │ │ ├── 08_while.expect │ │ ├── 09_do_while.c │ │ ├── 09_do_while.expect │ │ ├── 10_pointer.c │ │ ├── 10_pointer.expect │ │ ├── 11_precedence.c │ │ ├── 11_precedence.expect │ │ ├── 12_hashdefine.c │ │ ├── 12_hashdefine.expect │ │ ├── 13_integer_literals.c │ │ ├── 13_integer_literals.expect │ │ ├── 14_if.c │ │ ├── 14_if.expect │ │ ├── 15_recursion.c │ │ ├── 15_recursion.expect │ │ ├── 16_nesting.c │ │ ├── 16_nesting.expect │ │ ├── 17_enum.c │ │ ├── 17_enum.expect │ │ ├── 18_include.c │ │ ├── 18_include.expect │ │ ├── 18_include.h │ │ ├── 19_pointer_arithmetic.c │ │ ├── 19_pointer_arithmetic.expect │ │ ├── 20_pointer_comparison.c │ │ ├── 20_pointer_comparison.expect │ │ ├── 21_char_array.c │ │ ├── 21_char_array.expect │ │ ├── 22_floating_point.c │ │ ├── 22_floating_point.expect │ │ ├── 23_type_coercion.c │ │ ├── 23_type_coercion.expect │ │ ├── 24_math_library.c │ │ ├── 24_math_library.expect │ │ ├── 25_quicksort.c │ │ ├── 25_quicksort.expect │ │ ├── 26_character_constants.c │ │ ├── 26_character_constants.expect │ │ ├── 27_sizeof.c │ │ ├── 27_sizeof.expect │ │ ├── 28_strings.c │ │ ├── 28_strings.expect │ │ ├── 29_array_address.c │ │ ├── 29_array_address.expect │ │ ├── 30_hanoi.c │ │ ├── 30_hanoi.expect │ │ ├── 31_args.c │ │ ├── 31_args.expect │ │ ├── 32_led.c │ │ ├── 32_led.expect │ │ ├── 33_ternary_op.c │ │ ├── 33_ternary_op.expect │ │ ├── 34_array_assignment.c │ │ ├── 34_array_assignment.expect │ │ ├── 35_sizeof.c │ │ ├── 35_sizeof.expect │ │ ├── 36_array_initialisers.c │ │ ├── 36_array_initialisers.expect │ │ ├── 37_sprintf.c │ │ ├── 37_sprintf.expect │ │ ├── 38_multiple_array_index.c │ │ ├── 38_multiple_array_index.expect │ │ ├── 39_typedef.c │ │ ├── 39_typedef.expect │ │ ├── 40_stdio.c │ │ ├── 40_stdio.expect │ │ ├── 41_hashif.c │ │ ├── 41_hashif.expect │ │ ├── 42_function_pointer.c │ │ ├── 42_function_pointer.expect │ │ ├── 43_void_param.c │ │ ├── 43_void_param.expect │ │ ├── 44_scoped_declarations.c │ │ ├── 44_scoped_declarations.expect │ │ ├── 45_empty_for.c │ │ ├── 45_empty_for.expect │ │ ├── 46_grep.c │ │ ├── 47_switch_return.c │ │ ├── 47_switch_return.expect │ │ ├── 48_nested_break.c │ │ ├── 48_nested_break.expect │ │ ├── 49_bracket_evaluation.c │ │ ├── 49_bracket_evaluation.expect │ │ ├── 50_logical_second_arg.c │ │ ├── 50_logical_second_arg.expect │ │ ├── 51_static.c │ │ ├── 51_static.expect │ │ ├── 52_unnamed_enum.c │ │ ├── 52_unnamed_enum.expect │ │ ├── 54_goto.c │ │ ├── 54_goto.expect │ │ ├── 55_lshift_type.c │ │ ├── 55_lshift_type.expect │ │ ├── LICENSE │ │ └── Makefile ├── texi2pod.pl ├── win32 │ ├── build-tcc.bat │ ├── examples │ │ ├── dll.c │ │ ├── fib.c │ │ ├── hello_dll.c │ │ └── hello_win.c │ ├── include │ │ ├── _mingw.h │ │ ├── assert.h │ │ ├── conio.h │ │ ├── ctype.h │ │ ├── dir.h │ │ ├── direct.h │ │ ├── dirent.h │ │ ├── dos.h │ │ ├── errno.h │ │ ├── excpt.h │ │ ├── fcntl.h │ │ ├── fenv.h │ │ ├── inttypes.h │ │ ├── io.h │ │ ├── limits.h │ │ ├── locale.h │ │ ├── malloc.h │ │ ├── math.h │ │ ├── mem.h │ │ ├── memory.h │ │ ├── process.h │ │ ├── sec_api │ │ │ ├── conio_s.h │ │ │ ├── crtdbg_s.h │ │ │ ├── io_s.h │ │ │ ├── mbstring_s.h │ │ │ ├── search_s.h │ │ │ ├── stdio_s.h │ │ │ ├── stdlib_s.h │ │ │ ├── stralign_s.h │ │ │ ├── string_s.h │ │ │ ├── sys │ │ │ │ └── timeb_s.h │ │ │ ├── tchar_s.h │ │ │ ├── time_s.h │ │ │ └── wchar_s.h │ │ ├── setjmp.h │ │ ├── share.h │ │ ├── signal.h │ │ ├── stdint.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.h │ │ ├── sys │ │ │ ├── fcntl.h │ │ │ ├── file.h │ │ │ ├── locking.h │ │ │ ├── stat.h │ │ │ ├── time.h │ │ │ ├── timeb.h │ │ │ ├── types.h │ │ │ ├── unistd.h │ │ │ └── utime.h │ │ ├── tchar.h │ │ ├── time.h │ │ ├── vadefs.h │ │ ├── values.h │ │ ├── wchar.h │ │ ├── wctype.h │ │ └── winapi │ │ │ ├── basetsd.h │ │ │ ├── basetyps.h │ │ │ ├── guiddef.h │ │ │ ├── intrin.h │ │ │ ├── poppack.h │ │ │ ├── pshpack1.h │ │ │ ├── pshpack2.h │ │ │ ├── pshpack4.h │ │ │ ├── pshpack8.h │ │ │ ├── reason.h │ │ │ ├── specstrings.h │ │ │ ├── stralign.h │ │ │ ├── tvout.h │ │ │ ├── winbase.h │ │ │ ├── wincon.h │ │ │ ├── windef.h │ │ │ ├── windows.h │ │ │ ├── winerror.h │ │ │ ├── wingdi.h │ │ │ ├── winnetwk.h │ │ │ ├── winnls.h │ │ │ ├── winnt.h │ │ │ ├── winreg.h │ │ │ ├── winuser.h │ │ │ └── winver.h │ ├── lib │ │ ├── chkstk.S │ │ ├── crt1.c │ │ ├── dllcrt1.c │ │ ├── dllmain.c │ │ ├── gdi32.def │ │ ├── kernel32.def │ │ ├── msvcrt.def │ │ ├── user32.def │ │ └── wincrt1.c │ ├── tcc-win32.txt │ └── tools │ │ ├── tiny_impdef.c │ │ └── tiny_libmaker.c ├── x86_64-asm.h └── x86_64-gen.c ├── tcc_wrap.c ├── todo ├── valvers ├── rpi-base.h ├── rpi-mailbox-interface.c ├── rpi-mailbox-interface.h ├── rpi-mailbox.c └── rpi-mailbox.h └── vectors.s /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | *.su 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # luajitpi 2 | LuaJIT + TinyCC on RPi bare metal. 3 | 4 | 5 | **This has only been tested on an RPi B+. The changes to make this run on the RPi2 are probably easy (just the GPIO addresses) but I've not tested this!** 6 | 7 | ## Compiling 8 | I built the `arm-none-eabi toolchain` from source on Linux (lubuntu on x64) using a modified version of the script from https://gist.github.com/cjmeyer/4251208 9 | I used: 10 | 11 | * binutils 2.27 12 | * GCC 4.9.4 13 | * newlib 2.4.0 14 | * gdb 7.9 15 | 16 | The script I used is included in `build_toolchain/` as `arm-none-eabi.sh` 17 | 18 | The Debian `arm-none-eabi` package may also work, but I haven't tried it yet. 19 | 20 | ## LuaJIT 21 | [LuaJIT 2.0.4](http://luajit.org/download/LuaJIT-2.0.4.tar.gz) compiles easily if you: 22 | 23 | modify the Makefile to uncomment the line 24 | 25 | XCFLAGS += -DLUAJIT_USE_SYSMALLOC 26 | 27 | (which forces LuaJIT to use the newlib `malloc()`) 28 | and change the `BUILDMODE` from `mixed` to `static` 29 | 30 | BUILDMODE= static 31 | 32 | then compile with: 33 | make HOST_CC="gcc -m32" CROSS="arm-none-eabi-" 34 | 35 | To enable dynamic link loading, edit lj_arch.h and adjust the LJ_TARGET_DLOPEN to 36 | 37 | #define LJ_TARGET_DLOPEN 1 38 | 39 | add edit lj_clib.c and lib_package.c to include "ldl.h" instead of . 40 | 41 | 42 | Note that luajit itself won't build (because `libdl` is missing) but this isn't important as `libluajit.a` will be built succesfully. 43 | 44 | ## TinyCC 45 | I had to modify TCC slightly to make it compile without standard libraries or dynamic link support; see the modified version in `tcc/`. Note that TCC is distributed under an LGPL license. The modification just add some stubs to `tccrun.c`, and adjust the Makefile to remove `libdl` 46 | 47 | I used [version 0.9.26 of TinyCC](http://download.savannah.gnu.org/releases/tinycc/tcc-0.9.26.tar.bz2). 48 | 49 | ## UART access 50 | I based the UART access on dwelch67's [newlib example](https://github.com/dwelch67/raspberrypi/tree/master/newlib0), but the current version uses the code from rpi-boot. 51 | 52 | The bootloader in `bootloader/` is a slightly modified version of dwelch67's [`bootloader07`](https://github.com/dwelch67/raspberrypi/tree/master/bootloader07) (it prints dots and flashes the LED during loading, as the images are very large and it is nice to see some progress indication!). 53 | 54 | 55 | -------------------------------------------------------------------------------- /allmake.sh: -------------------------------------------------------------------------------- 1 | rm bootfiles.zip 2 | make 3 | make fmap.c 4 | make fmap.o 5 | make 6 | make fmap.c 7 | make fmap.o 8 | make 9 | 10 | -------------------------------------------------------------------------------- /bootloader/BCM2835.h: -------------------------------------------------------------------------------- 1 | 2 | #define PBASE 0x20000000 3 | 4 | //------------------------------------------------------------------------- 5 | // 6 | // Copyright (c) 2012 David Welch dwelch@dwelch.com 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | // 14 | //------------------------------------------------------------------------- 15 | -------------------------------------------------------------------------------- /bootloader/BCM2836.h: -------------------------------------------------------------------------------- 1 | 2 | #define PBASE 0x3F000000 3 | 4 | //------------------------------------------------------------------------- 5 | // 6 | // Copyright (c) 2012 David Welch dwelch@dwelch.com 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | // 14 | //------------------------------------------------------------------------- 15 | -------------------------------------------------------------------------------- /bootloader/README: -------------------------------------------------------------------------------- 1 | 2 | See the top level README file for more information on documentation 3 | and how to run these programs. 4 | 5 | This is a very simple bootloader. Instead of the sd dance (see 6 | top level README), this makes life a bit simpler and greatly reduces 7 | physical wear and tear on the sd card socket. Do the sd card dance one 8 | more time with this kernel.img. Get some sort of serial solution to 9 | connect a dumb termial program with the ability to download raw/ascii 10 | files. 11 | 12 | bootloader01 was .hex based, this one is also .hex based but a 13 | different way to parse it. bootloader02 through bootloader06 14 | expect binary files, a binary image of the memory starting at 15 | address 0x8000. I intend to release bootloader08 at the same time 16 | and it will be .bin based but have the go feature. 17 | 18 | This bootloader07 parses intel hex formatted files. Look that up at 19 | wikipedia, it is very simple and historically widely used for bare 20 | metal embedded work. (S record is another format like intel hex but 21 | of course motorola had to have their own. Intel hex and Motorola S- 22 | record). I felt like doing another state machine and honestly had 23 | forgotten I did one before in bootloader01. This bootloader does 24 | not make any of the others obsolete, it was just a fun exercise. 25 | 26 | The thing that annoyed me the most about my bootloader is that 27 | I use minicom and minicom spawns a separate program to do the file 28 | transfers, xmodem, ascii, kermit, etc, and there is a delay and 29 | a loss of data when the spawned program exits and minicom returns. 30 | The solution is that you hit the g key when you want the program 31 | to start so you are basically back in the terminal at that point. 32 | 33 | I normally do not deliver binaries. In this case I have included all 34 | of the build files so that you can at least get started without having 35 | to build the bootloader. Backup whatever kernel.img file you are using 36 | and replace with the kernel.img file in this repo (on your sd card) to 37 | use this program. If on a Raspberry Pi 2 then use kernel7.img instead 38 | of kernel.img. 39 | 40 | blinker.hex is for older RPi boards the A and B whose activity led 41 | is tied to GPIO16. The A+, B+, and RPi2 use GPIO47, also on these 42 | latter boards the power led is on GPIO35. Last I checked they wouldnt 43 | provide a schematic for these latter boards (so much for being "open") 44 | so we have to just go on faith... 45 | -------------------------------------------------------------------------------- /bootloader/loader: -------------------------------------------------------------------------------- 1 | 2 | MEMORY 3 | { 4 | ram : ORIGIN = 0x8000, LENGTH = 0x1000000 5 | } 6 | 7 | SECTIONS 8 | { 9 | .text : { *(.text*) } > ram 10 | .bss : { *(.bss*) } > ram 11 | } 12 | 13 | -------------------------------------------------------------------------------- /bootloader/memmap: -------------------------------------------------------------------------------- 1 | 2 | MEMORY 3 | { 4 | ram : ORIGIN = 0x8000, LENGTH = 0x1000 5 | } 6 | 7 | SECTIONS 8 | { 9 | .text : { *(.text*) } > ram 10 | .bss : { *(.bss*) } > ram 11 | } 12 | 13 | -------------------------------------------------------------------------------- /bootloader/start.s: -------------------------------------------------------------------------------- 1 | 2 | ;@------------------------------------------------------------------------- 3 | ;@------------------------------------------------------------------------- 4 | 5 | .globl _start 6 | _start: 7 | mov sp,#0x8000 8 | bl notmain 9 | hang: b hang 10 | 11 | .globl PUT32 12 | PUT32: 13 | str r1,[r0] 14 | bx lr 15 | 16 | .globl GET32 17 | GET32: 18 | ldr r0,[r0] 19 | bx lr 20 | 21 | .globl dummy 22 | dummy: 23 | bx lr 24 | 25 | ;@------------------------------------------------------------------------- 26 | ;@------------------------------------------------------------------------- 27 | 28 | 29 | ;@------------------------------------------------------------------------- 30 | ;@ 31 | ;@ Copyright (c) 2012 David Welch dwelch@dwelch.com 32 | ;@ 33 | ;@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 34 | ;@ 35 | ;@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 36 | ;@ 37 | ;@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 38 | ;@ 39 | ;@------------------------------------------------------------------------- 40 | -------------------------------------------------------------------------------- /bootloader/vectors.s: -------------------------------------------------------------------------------- 1 | 2 | ;@------------------------------------------------------------------------- 3 | ;@------------------------------------------------------------------------- 4 | 5 | .globl _start 6 | _start: 7 | b skip 8 | 9 | .space 0x200000-0x8004,0 10 | 11 | skip: 12 | mov sp,#0x08000000 13 | bl notmain 14 | hang: b hang 15 | 16 | .globl PUT32 17 | PUT32: 18 | str r1,[r0] 19 | bx lr 20 | 21 | .globl PUT16 22 | PUT16: 23 | strh r1,[r0] 24 | bx lr 25 | 26 | .globl PUT8 27 | PUT8: 28 | strb r1,[r0] 29 | bx lr 30 | 31 | .globl GET32 32 | GET32: 33 | ldr r0,[r0] 34 | bx lr 35 | 36 | .globl GETPC 37 | GETPC: 38 | mov r0,lr 39 | bx lr 40 | 41 | .globl BRANCHTO 42 | BRANCHTO: 43 | bx r0 44 | 45 | .globl dummy 46 | dummy: 47 | bx lr 48 | 49 | 50 | ;@------------------------------------------------------------------------- 51 | ;@------------------------------------------------------------------------- 52 | 53 | 54 | ;@------------------------------------------------------------------------- 55 | ;@ 56 | ;@ Copyright (c) 2012 David Welch dwelch@dwelch.com 57 | ;@ 58 | ;@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 59 | ;@ 60 | ;@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 61 | ;@ 62 | ;@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 63 | ;@ 64 | ;@------------------------------------------------------------------------- 65 | -------------------------------------------------------------------------------- /dasm/csrc/dynasm/WHAT: -------------------------------------------------------------------------------- 1 | DynASM 1.4.0 from https://github.com/LuaJIT/LuaJIT (MIT License) 2 | 3 | 4 | 5 | The encoder part written in C was not modified. 6 | The Lua part was modified to support Lua mode (see docs for details). 7 | -------------------------------------------------------------------------------- /dasm/csrc/dynasm/build-arm.sh: -------------------------------------------------------------------------------- 1 | X=arm-none-eabi- P=linux32 L="-s -static-libgcc" D=libdasm_arm.so A=libdasm_arm.a ./build.sh 2 | -------------------------------------------------------------------------------- /dasm/csrc/dynasm/build-linux32.sh: -------------------------------------------------------------------------------- 1 | P=linux32 L="-s -static-libgcc" D=libdasm_x86.so A=libdasm_x86.a ./build.sh 2 | -------------------------------------------------------------------------------- /dasm/csrc/dynasm/build-linux64.sh: -------------------------------------------------------------------------------- 1 | P=linux64 C=-fPIC L="-s -static-libgcc" D=libdasm_x86.so A=libdasm_x86.a ./build.sh 2 | -------------------------------------------------------------------------------- /dasm/csrc/dynasm/build-mingw32.sh: -------------------------------------------------------------------------------- 1 | P=mingw32 L="-s -static-libgcc" D=dasm_x86.dll A=dasm_x86.a ./build.sh 2 | -------------------------------------------------------------------------------- /dasm/csrc/dynasm/build-mingw64.sh: -------------------------------------------------------------------------------- 1 | P=mingw64 L="-s -static-libgcc" D=dasm_x86.dll A=dasm_x86.a ./build.sh 2 | -------------------------------------------------------------------------------- /dasm/csrc/dynasm/build-osx32.sh: -------------------------------------------------------------------------------- 1 | [ `uname` = Linux ] && export X=i386-apple-darwin11- 2 | P=osx32 C="-arch i386" L="-arch i386 -install_name @rpath/libdasm_x86.dylib" \ 3 | D=libdasm_x86.dylib A=libdasm_x86.a ./build.sh 4 | -------------------------------------------------------------------------------- /dasm/csrc/dynasm/build-osx64.sh: -------------------------------------------------------------------------------- 1 | [ `uname` = Linux ] && export X=x86_64-apple-darwin11- 2 | P=osx64 C="-arch x86_64" L="-arch x86_64 -install_name @rpath/libdasm_x86.dylib" \ 3 | D=libdasm_x86.dylib A=libdasm_x86.a ./build.sh 4 | -------------------------------------------------------------------------------- /dasm/csrc/dynasm/build.sh: -------------------------------------------------------------------------------- 1 | ${X}gcc -c -O2 $C dasm_arm.c -DDASM_CHECKS 2 | #${X}gcc *.o -shared $L -o ../../bin/$P/$D 3 | #${X}ar rcs ../../bin/$P/$A *.o 4 | -------------------------------------------------------------------------------- /dasm/csrc/dynasm/dasm_arm.c: -------------------------------------------------------------------------------- 1 | /* 2 | Encoding engine to use with dasm.lua. 3 | 4 | Compile with: 5 | 6 | gcc dasm_x86.c -O -fPIC -DDASM_CHECKS -shared -s -o libdasm_x86.so 7 | */ 8 | 9 | #include "dasm_extern.h" 10 | #include "dasm_proto.h" 11 | #include "dasm_arm.h" 12 | -------------------------------------------------------------------------------- /dasm/csrc/dynasm/dasm_extern.h: -------------------------------------------------------------------------------- 1 | // DASM_EXTERN_FUNC is a global function pointer to be set at runtime. 2 | // It will be used in place of the DASM_EXTERN() macro. 3 | typedef int (*DASM_EXTERN_TYPE) (void *ctx, unsigned char *addr, int idx, int type); 4 | DASM_EXTERN_TYPE DASM_EXTERN_FUNC; 5 | #define DASM_EXTERN(a,b,c,d) DASM_EXTERN_FUNC(a,b,c,d) 6 | -------------------------------------------------------------------------------- /dasm/csrc/dynasm/dasm_proto.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** DynASM encoding engine prototypes. 3 | ** Copyright (C) 2005-2015 Mike Pall. All rights reserved. 4 | ** Released under the MIT license. See dynasm.lua for full copyright notice. 5 | */ 6 | 7 | #ifndef _DASM_PROTO_H 8 | #define _DASM_PROTO_H 9 | 10 | #include 11 | #include 12 | 13 | #define DASM_IDENT "DynASM 1.3.0" 14 | #define DASM_VERSION 10300 /* 1.3.0 */ 15 | 16 | #ifndef Dst_DECL 17 | #define Dst_DECL dasm_State **Dst 18 | #endif 19 | 20 | #ifndef Dst_REF 21 | #define Dst_REF (*Dst) 22 | #endif 23 | 24 | #ifndef DASM_FDEF 25 | #define DASM_FDEF extern 26 | #endif 27 | 28 | #ifndef DASM_M_GROW 29 | #define DASM_M_GROW(ctx, t, p, sz, need) \ 30 | do { \ 31 | size_t _sz = (sz), _need = (need); \ 32 | if (_sz < _need) { \ 33 | if (_sz < 16) _sz = 16; \ 34 | while (_sz < _need) _sz += _sz; \ 35 | (p) = (t *)realloc((p), _sz); \ 36 | if ((p) == NULL) exit(1); \ 37 | (sz) = _sz; \ 38 | } \ 39 | } while(0) 40 | #endif 41 | 42 | #ifndef DASM_M_FREE 43 | #define DASM_M_FREE(ctx, p, sz) free(p) 44 | #endif 45 | 46 | /* Internal DynASM encoder state. */ 47 | typedef struct dasm_State dasm_State; 48 | 49 | 50 | /* Initialize and free DynASM state. */ 51 | DASM_FDEF void dasm_init(Dst_DECL, int maxsection); 52 | DASM_FDEF void dasm_free(Dst_DECL); 53 | 54 | /* Setup global array. Must be called before dasm_setup(). */ 55 | DASM_FDEF void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl); 56 | 57 | /* Grow PC label array. Can be called after dasm_setup(), too. */ 58 | DASM_FDEF void dasm_growpc(Dst_DECL, unsigned int maxpc); 59 | 60 | /* Setup encoder. */ 61 | DASM_FDEF void dasm_setup(Dst_DECL, const void *actionlist); 62 | 63 | /* Feed encoder with actions. Calls are generated by pre-processor. */ 64 | DASM_FDEF void dasm_put(Dst_DECL, int start, ...); 65 | 66 | /* Link sections and return the resulting size. */ 67 | DASM_FDEF int dasm_link(Dst_DECL, size_t *szp); 68 | 69 | /* Encode sections into buffer. */ 70 | DASM_FDEF int dasm_encode(Dst_DECL, void *buffer); 71 | 72 | /* Get PC label offset. */ 73 | DASM_FDEF int dasm_getpclabel(Dst_DECL, unsigned int pc); 74 | 75 | #ifdef DASM_CHECKS 76 | /* Optional sanity checker to call between isolated encoding steps. */ 77 | DASM_FDEF int dasm_checkstep(Dst_DECL, int secmatch); 78 | #else 79 | #define dasm_checkstep(a, b) 0 80 | #endif 81 | 82 | 83 | #endif /* _DASM_PROTO_H */ 84 | -------------------------------------------------------------------------------- /dasm/csrc/dynasm/dasm_x86.c: -------------------------------------------------------------------------------- 1 | /* 2 | Encoding engine to use with dasm.lua. 3 | 4 | Compile with: 5 | 6 | gcc dasm_x86.c -O -fPIC -DDASM_CHECKS -shared -s -o libdasm_x86.so 7 | */ 8 | 9 | #include "dasm_extern.h" 10 | #include "dasm_proto.h" 11 | #include "dasm_x86.h" 12 | -------------------------------------------------------------------------------- /dasm/dasm_x64.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- DynASM x64 module. 3 | -- 4 | -- Copyright (C) 2005-2015 Mike Pall. All rights reserved. 5 | -- See dynasm.lua for full copyright notice. 6 | ------------------------------------------------------------------------------ 7 | -- This module just sets 64 bit mode for the combined x86/x64 module. 8 | -- All the interesting stuff is there. 9 | ------------------------------------------------------------------------------ 10 | 11 | --unload dasm_x86 if it's already loaded. 12 | if not package then package = {loaded = {}} end --for compat. with minilua 13 | local dasm_x86 = package.loaded.dasm_x86 14 | package.loaded.dasm_x86 = nil 15 | 16 | x64 = true -- Using a global is an ugly, but effective solution. 17 | local dasm_x64 = require("dasm_x86") 18 | 19 | package.loaded.dasm_x86 = dasm_x86 --put it back 20 | 21 | return dasm_x64 22 | 23 | -------------------------------------------------------------------------------- /dl_footer._h: -------------------------------------------------------------------------------- 1 | {0x0, 0x0}, 2 | }; 3 | -------------------------------------------------------------------------------- /dl_header._h: -------------------------------------------------------------------------------- 1 | typedef struct ldl_sym 2 | { 3 | unsigned int addr; 4 | char *sym; 5 | } ldl_sym; 6 | 7 | const ldl_sym __attribute__ ((section ("symdata"))) _all_symbols [] = 8 | { 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /exception.c: -------------------------------------------------------------------------------- 1 | typedef struct vector_table 2 | { 3 | void (*reset)(void); 4 | void (*undefined_instruction)(void); 5 | void (*software_interrupt)(unsigned int); 6 | void (*prefetch_abort)(void); 7 | void (*data_access)(void); 8 | void (*unhandled_exception)(void); 9 | void (*interrupt)(void); 10 | void (*fast_interrupt)(void); 11 | 12 | } vector_table; 13 | 14 | /* We simply dispatch to wherever the table is pointing to */ 15 | /* This should be set in Lua */ 16 | 17 | /* Force GCC to preserve the callee-saved registers */ 18 | #define PRESERVE_REGS asm volatile ( "nop" : : : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r14"); 19 | 20 | vector_table arm_exc_table = {0}; 21 | 22 | void exc_reset(void) 23 | { 24 | arm_exc_table.reset(); 25 | } 26 | 27 | void __attribute__((interrupt("SWI"))) exc_software_interrupt(void) 28 | { 29 | volatile unsigned int intrp;; 30 | asm("LDR r0, [lr, #-4]"); 31 | asm("BIC r0, #0xFF000000"); 32 | asm("MOV %0, r0":"=r"(intrp):); 33 | arm_exc_table.software_interrupt(intrp); 34 | } 35 | 36 | void __attribute__((interrupt("ABORT"))) exc_prefetch_abort(void) 37 | { 38 | PRESERVE_REGS; 39 | arm_exc_table.prefetch_abort(); 40 | 41 | } 42 | 43 | void exc_data_access(void) 44 | { 45 | PRESERVE_REGS; 46 | arm_exc_table.data_access(); 47 | } 48 | 49 | void __attribute__((interrupt("UNDEF"))) exc_undefined_instruction(void) 50 | { 51 | PRESERVE_REGS; 52 | arm_exc_table.undefined_instruction(); 53 | } 54 | 55 | void exc_unhandled_exception(void) 56 | { 57 | PRESERVE_REGS; 58 | arm_exc_table.unhandled_exception(); 59 | } 60 | 61 | void __attribute__((interrupt("IRQ"))) exc_interrupt(void) 62 | { 63 | arm_exc_table.interrupt(); 64 | } 65 | 66 | void __attribute__((interrupt("FIQ"))) exc_fast_interrupt(void) 67 | { 68 | arm_exc_table.fast_interrupt(); 69 | } 70 | -------------------------------------------------------------------------------- /fmap_dummy.c: -------------------------------------------------------------------------------- 1 | typedef struct ldl_sym 2 | { 3 | unsigned int addr; 4 | char *sym; 5 | } ldl_sym; 6 | 7 | const ldl_sym _all_symbols [] = { 8 | {0x0, 0x0} 9 | }; 10 | 11 | 12 | -------------------------------------------------------------------------------- /ldl.c: -------------------------------------------------------------------------------- 1 | #include "ldl.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | /* Simple stubs for emulating dynamic library support. 11 | This enables the use of ffi.open() in LuaJIT. 12 | */ 13 | 14 | static char *last_error; 15 | static char error_bad_symbol[] = "Symbol not found in sym_table."; 16 | 17 | typedef struct ldl_sym 18 | { 19 | unsigned int addr; 20 | char *sym; 21 | } ldl_sym; 22 | 23 | extern const ldl_sym _all_symbols []; 24 | 25 | static char *dummy="none"; 26 | void *dlopen(const char *filename, int flag) 27 | { 28 | /* NB: flags are ignored */ 29 | last_error = NULL; 30 | /* can't return null */ 31 | return (void*)dummy; 32 | } 33 | 34 | const char *dlerror(void) 35 | { 36 | return last_error; 37 | } 38 | 39 | void *dlsym(void *handle, const char *symbol) 40 | { 41 | char *sym; 42 | unsigned int addr; 43 | int i=0; 44 | do 45 | { 46 | addr = _all_symbols[i].addr; 47 | sym = _all_symbols[i].sym; 48 | if(!strcmp(sym, symbol)) 49 | { 50 | return (void *)addr; 51 | } 52 | i++; 53 | } while(sym!=NULL); 54 | /* no match in the symbol table */ 55 | last_error = error_bad_symbol; 56 | return NULL; 57 | } 58 | 59 | void dlclose(void *handle) 60 | { 61 | } 62 | -------------------------------------------------------------------------------- /ldl.h: -------------------------------------------------------------------------------- 1 | #ifndef LDL_H 2 | #define LDL_H 3 | void *dlopen(const char *filename, int flag); 4 | const char *dlerror(void); 5 | void *dlsym(void *handle, const char *symbol); 6 | void dlclose(void *handle); 7 | #define RTLD_DEFAULT NULL 8 | #define RTLD_LAZY 0x001 9 | #define RTLD_NOW 0x002 10 | #define RTLD_GLOBAL 0x100 11 | #define RTLD_LOCAL 0x101 12 | #endif 13 | -------------------------------------------------------------------------------- /linenoise/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2015 Rob Hoelz 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /linenoise/Changes: -------------------------------------------------------------------------------- 1 | 0.8 2015 Apr 29 2 | - Fix memory leak (thanks, Dirk Feytons!) 3 | 4 | 0.7 2015 Feb 24 5 | - Bump linenoise version 6 | 7 | 0.4 2012 Dec 18 8 | - Offer more options when building. 9 | - Update bundled version of linenoise. 10 | 11 | 0.3 2012 Sep 19 12 | - Update rockspec and upload to luarocks. 13 | 14 | 0.2 ??? 15 | - Initial release. 16 | -------------------------------------------------------------------------------- /linenoise/Makefile: -------------------------------------------------------------------------------- 1 | linenoise_example: linenoise.h linenoise.c linenoise_lua.c 2 | 3 | linenoise_example: linenoise.c linenoise_lua.c 4 | arm-none-eabi-gcc -Wall -W -Os -g -c linenoise.c linenoise_lua.c -I ~/LuaJIT-2.0.4/src 5 | clean: 6 | rm -f *.o 7 | -------------------------------------------------------------------------------- /linenoise/example.lua: -------------------------------------------------------------------------------- 1 | local L = require 'linenoise' 2 | -- L.clearscreen() 3 | print '----- Testing lua-linenoise! ------' 4 | local prompt, history = '? ', 'history.txt' 5 | L.historyload(history) -- load existing history 6 | L.setcompletion(function(c,s) 7 | if s == 'h' then 8 | L.addcompletion(c,'help') 9 | L.addcompletion(c,'halt') 10 | end 11 | end) 12 | local line = L.linenoise(prompt) 13 | while line do 14 | if #line > 0 then 15 | print(line:upper()) 16 | L.historyadd(line) 17 | L.historysave(history) -- save every new line 18 | end 19 | line = L.linenoise(prompt) 20 | end 21 | 22 | -------------------------------------------------------------------------------- /linenoise/fmacros.h: -------------------------------------------------------------------------------- 1 | #ifndef _REDIS_FMACRO_H 2 | #define _REDIS_FMACRO_H 3 | 4 | #define _BSD_SOURCE 5 | 6 | #if defined(__linux__) || defined(__OpenBSD__) 7 | #define _XOPEN_SOURCE 700 8 | #else 9 | #define _XOPEN_SOURCE 10 | #endif 11 | 12 | #define _LARGEFILE_SOURCE 13 | #define _FILE_OFFSET_BITS 64 14 | 15 | #ifdef _WIN32 16 | #define off off_t 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /lua/asm.lua: -------------------------------------------------------------------------------- 1 | local dis = require("dis_arm") 2 | 3 | function disas(addr, len, out) 4 | -- default to printing 5 | if out==nil then 6 | out = io.write 7 | end 8 | local dmem = ffi.string(ffi.cast("void*",addr), len) 9 | dis.disass(dmem, addr, out) 10 | end 11 | 12 | 13 | 14 | function dump(offset, len) 15 | -- force 16 byte alignment 16 | local i = 0 17 | local off = bit.band(offset, bit.bnot(15)) 18 | while i=32 and m<127 then 28 | ascii = ascii .. string.char(m) 29 | end 30 | end 31 | 32 | print(string.format("%08X",i+offset).." |"..s.."|"..ascii) 33 | i = i + 16 34 | end 35 | end 36 | 37 | -------------------------------------------------------------------------------- /lua/cc.lua: -------------------------------------------------------------------------------- 1 | 2 | ffi.cdef([[ 3 | void *compile_tcc(const char *str); 4 | void delete_tcc(void *tcc); 5 | void *getsymbol_tcc(void *tcc, const char *str); 6 | ]]) 7 | 8 | function cc(fn, proto, c_code) 9 | local tcc_context = ffi.C.compile_tcc(c_code) 10 | func = ffi.C.getsymbol_tcc(compiled, fn) 11 | func = ffi.cast(proto, func) 12 | return func 13 | end 14 | -------------------------------------------------------------------------------- /lua/dasm/dasm_x64.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- DynASM x64 module. 3 | -- 4 | -- Copyright (C) 2005-2015 Mike Pall. All rights reserved. 5 | -- See dynasm.lua for full copyright notice. 6 | ------------------------------------------------------------------------------ 7 | -- This module just sets 64 bit mode for the combined x86/x64 module. 8 | -- All the interesting stuff is there. 9 | ------------------------------------------------------------------------------ 10 | 11 | --unload dasm_x86 if it's already loaded. 12 | if not package then package = {loaded = {}} end --for compat. with minilua 13 | local dasm_x86 = package.loaded.dasm_x86 14 | package.loaded.dasm_x86 = nil 15 | 16 | x64 = true -- Using a global is an ugly, but effective solution. 17 | local dasm_x64 = require("dasm_x86") 18 | 19 | package.loaded.dasm_x86 = dasm_x86 --put it back 20 | 21 | return dasm_x64 22 | 23 | -------------------------------------------------------------------------------- /lua/dasm_test.lua: -------------------------------------------------------------------------------- 1 | dynasm = require("dynasm") 2 | 3 | local gencode, actions = dynasm.loadstring([[ 4 | local ffi = require('ffi') 5 | local dasm = require('dasm') 6 | 7 | |.arch arm 8 | |.actionlist actions 9 | 10 | local function gencode(Dst) 11 | | mov r0, #0 12 | end 13 | 14 | return gencode, actions 15 | ]]) -------------------------------------------------------------------------------- /lua/fs.lua: -------------------------------------------------------------------------------- 1 | -- initialise the SD card access 2 | ffi.C.libfs_init() 3 | 4 | -- return a table of directory entries 5 | -- each entry has name, size and isdir attributes 6 | function ls_dir(dirpath) 7 | dir = ffi.C.mb_opendir(dirpath) 8 | dirent = ffi.C.mb_readdir(dir) 9 | dirs = {} 10 | while dirent~=ffi.NULL do 11 | table.insert(dirs, {name=ffi.string(dirent.name), size=dirent.byte_size, isdir=dirent.is_dir}) 12 | dirent = dirent.next 13 | end 14 | ffi.C.mb_closedir(dir) 15 | return dirs 16 | end 17 | 18 | function lpad(str, len, char) 19 | if char == nil then char = ' ' end 20 | return str .. string.rep(char, len - #str) 21 | end 22 | 23 | function ls(dirpath) 24 | dirs = ls_dir(dirpath) 25 | for k,v in ipairs(dirs) do 26 | if v.isdir==0 then 27 | dirtype = "" 28 | else 29 | dirtype = "" 30 | end 31 | print(lpad(v.name,20), " ", lpad(tostring(v.size),12), " ", lpad(dirtype,8)) 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lua/hwrng.lua: -------------------------------------------------------------------------------- 1 | --> 2 | local hw_rng_base = io_address(0x104000) 3 | local hw_rng_ctrl = hw_rng_base 4 | local hw_rng_ctrl_engage = 0x01 5 | local hw_rng_status = hw_rng_base+0x4 6 | local hw_rng_data = hw_rng_base+0x8 7 | 8 | local burn_in = 0x8000 9 | --< 10 | -- burn in 11 | put32(hw_rng_status, burn_in) 12 | put32(hw_rng_ctrl, hw_rng_ctrl_engage) 13 | 14 | 15 | local function raw_read_rng() 16 | repeat 17 | local wait = bit.rshift(get32(hw_rng_status),24) 18 | until wait~=0 19 | return get32(hw_rng_data) 20 | end 21 | 22 | 23 | 24 | return {raw=raw_read_rng} -------------------------------------------------------------------------------- /lua/linenoise.lua: -------------------------------------------------------------------------------- 1 | 2 | linenoise = [[ 3 | typedef struct linenoiseCompletions { 4 | size_t len; 5 | char **cvec; 6 | } linenoiseCompletions; 7 | 8 | typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *); 9 | typedef char*(linenoiseHintsCallback)(const char *, int *color, int *bold); 10 | typedef void(linenoiseFreeHintsCallback)(void *); 11 | void linenoiseSetCompletionCallback(linenoiseCompletionCallback *); 12 | void linenoiseSetHintsCallback(linenoiseHintsCallback *); 13 | void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *); 14 | void linenoiseAddCompletion(linenoiseCompletions *, const char *); 15 | 16 | char *linenoise(const char *prompt); 17 | void linenoiseFree(void *ptr); 18 | int linenoiseHistoryAdd(const char *line); 19 | int linenoiseHistorySetMaxLen(int len); 20 | int linenoiseHistorySave(const char *filename); 21 | int linenoiseHistoryLoad(const char *filename); 22 | void linenoiseClearScreen(void); 23 | void linenoiseSetMultiLine(int ml); 24 | void linenoisePrintKeyCodes(void); 25 | ]] 26 | 27 | ffi.cdef(linenoise) 28 | 29 | -------------------------------------------------------------------------------- /lua/more_tests.lua: -------------------------------------------------------------------------------- 1 | print("Memory access test, should dump first 256 bytes of ram") 2 | 3 | dump(0x8000, 0x100) 4 | 5 | 6 | deadbeef = [[ 7 | void set_deadbeef(unsigned int *n) 8 | { 9 | *n = 0xdeadbeef; 10 | } 11 | ]] 12 | 13 | 14 | print("Testing TCC from LuaJIT...") 15 | print(deadbeef) 16 | 17 | 18 | print("Compiling...") 19 | compiled = ffi.C.compile_tcc(deadbeef) 20 | func = ffi.C.getsymbol_tcc(compiled, "set_deadbeef") 21 | func = ffi.cast("void (*)(unsigned int*)", func) 22 | test = ffi.new("unsigned int [1]", 0) 23 | func(test) 24 | 25 | print("Output should be DEADBEEF") 26 | print(string.format("%08X", test[0])) 27 | 28 | -------------------------------------------------------------------------------- /lua/pl/MultiMap.lua: -------------------------------------------------------------------------------- 1 | --- MultiMap, a Map which has multiple values per key. 2 | -- 3 | -- Dependencies: `pl.utils`, `pl.class`, `pl.tablex`, `pl.List` 4 | -- @classmod pl.MultiMap 5 | 6 | local classes = require 'pl.class' 7 | local tablex = require 'pl.tablex' 8 | local utils = require 'pl.utils' 9 | local List = require 'pl.List' 10 | 11 | local index_by,tsort,concat = tablex.index_by,table.sort,table.concat 12 | local append,extend,slice = List.append,List.extend,List.slice 13 | local append = table.insert 14 | 15 | local class = require 'pl.class' 16 | local Map = require 'pl.Map' 17 | 18 | -- MultiMap is a standard MT 19 | local MultiMap = utils.stdmt.MultiMap 20 | 21 | class(Map,nil,MultiMap) 22 | MultiMap._name = 'MultiMap' 23 | 24 | function MultiMap:_init (t) 25 | if not t then return end 26 | self:update(t) 27 | end 28 | 29 | --- update a MultiMap using a table. 30 | -- @param t either a Multimap or a map-like table. 31 | -- @return the map 32 | function MultiMap:update (t) 33 | utils.assert_arg(1,t,'table') 34 | if Map:class_of(t) then 35 | for k,v in pairs(t) do 36 | self[k] = List() 37 | self[k]:append(v) 38 | end 39 | else 40 | for k,v in pairs(t) do 41 | self[k] = List(v) 42 | end 43 | end 44 | end 45 | 46 | --- add a new value to a key. Setting a nil value removes the key. 47 | -- @param key the key 48 | -- @param val the value 49 | -- @return the map 50 | function MultiMap:set (key,val) 51 | if val == nil then 52 | self[key] = nil 53 | else 54 | if not self[key] then 55 | self[key] = List() 56 | end 57 | self[key]:append(val) 58 | end 59 | end 60 | 61 | return MultiMap 62 | -------------------------------------------------------------------------------- /lua/pl/file.lua: -------------------------------------------------------------------------------- 1 | --- File manipulation functions: reading, writing, moving and copying. 2 | -- 3 | -- Dependencies: `pl.utils`, `pl.dir`, `pl.path` 4 | -- @module pl.file 5 | local os = os 6 | local utils = require 'pl.utils' 7 | local dir = require 'pl.dir' 8 | local path = require 'pl.path' 9 | 10 | --[[ 11 | module ('pl.file',utils._module) 12 | ]] 13 | local file = {} 14 | 15 | --- return the contents of a file as a string 16 | -- @function file.read 17 | -- @string filename The file path 18 | -- @return file contents 19 | file.read = utils.readfile 20 | 21 | --- write a string to a file 22 | -- @function file.write 23 | -- @string filename The file path 24 | -- @string str The string 25 | file.write = utils.writefile 26 | 27 | --- copy a file. 28 | -- @function file.copy 29 | -- @string src source file 30 | -- @string dest destination file 31 | -- @bool flag true if you want to force the copy (default) 32 | -- @return true if operation succeeded 33 | file.copy = dir.copyfile 34 | 35 | --- move a file. 36 | -- @function file.move 37 | -- @string src source file 38 | -- @string dest destination file 39 | -- @return true if operation succeeded, else false and the reason for the error. 40 | file.move = dir.movefile 41 | 42 | --- Return the time of last access as the number of seconds since the epoch. 43 | -- @function file.access_time 44 | -- @string path A file path 45 | file.access_time = path.getatime 46 | 47 | ---Return when the file was created. 48 | -- @function file.creation_time 49 | -- @string path A file path 50 | file.creation_time = path.getctime 51 | 52 | --- Return the time of last modification 53 | -- @function file.modified_time 54 | -- @string path A file path 55 | file.modified_time = path.getmtime 56 | 57 | --- Delete a file 58 | -- @function file.delete 59 | -- @string path A file path 60 | file.delete = os.remove 61 | 62 | return file 63 | -------------------------------------------------------------------------------- /lua/pl/init.lua: -------------------------------------------------------------------------------- 1 | -------------- 2 | -- Entry point for loading all PL libraries only on demand, into the global space. 3 | -- Requiring 'pl' means that whenever a module is implicitly accesssed 4 | -- (e.g. `utils.split`) 5 | -- then that module is dynamically loaded. The submodules are all brought into 6 | -- the global space. 7 | --Updated to use @{pl.import_into} 8 | -- @module pl 9 | require'pl.import_into'(_G) 10 | 11 | if rawget(_G,'PENLIGHT_STRICT') then require 'pl.strict' end 12 | -------------------------------------------------------------------------------- /lua/pl/permute.lua: -------------------------------------------------------------------------------- 1 | --- Permutation operations. 2 | -- 3 | -- Dependencies: `pl.utils`, `pl.tablex` 4 | -- @module pl.permute 5 | local tablex = require 'pl.tablex' 6 | local utils = require 'pl.utils' 7 | local copy = tablex.deepcopy 8 | local append = table.insert 9 | local coroutine = coroutine 10 | local resume = coroutine.resume 11 | local assert_arg = utils.assert_arg 12 | 13 | 14 | local permute = {} 15 | 16 | -- PiL, 9.3 17 | 18 | local permgen 19 | permgen = function (a, n, fn) 20 | if n == 0 then 21 | fn(a) 22 | else 23 | for i=1,n do 24 | -- put i-th element as the last one 25 | a[n], a[i] = a[i], a[n] 26 | 27 | -- generate all permutations of the other elements 28 | permgen(a, n - 1, fn) 29 | 30 | -- restore i-th element 31 | a[n], a[i] = a[i], a[n] 32 | 33 | end 34 | end 35 | end 36 | 37 | --- an iterator over all permutations of the elements of a list. 38 | -- Please note that the same list is returned each time, so do not keep references! 39 | -- @param a list-like table 40 | -- @return an iterator which provides the next permutation as a list 41 | function permute.iter (a) 42 | assert_arg(1,a,'table') 43 | local n = #a 44 | local co = coroutine.create(function () permgen(a, n, coroutine.yield) end) 45 | return function () -- iterator 46 | local code, res = resume(co) 47 | return res 48 | end 49 | end 50 | 51 | --- construct a table containing all the permutations of a list. 52 | -- @param a list-like table 53 | -- @return a table of tables 54 | -- @usage permute.table {1,2,3} --> {{2,3,1},{3,2,1},{3,1,2},{1,3,2},{2,1,3},{1,2,3}} 55 | function permute.table (a) 56 | assert_arg(1,a,'table') 57 | local res = {} 58 | local n = #a 59 | permgen(a,n,function(t) append(res,copy(t)) end) 60 | return res 61 | end 62 | 63 | return permute 64 | -------------------------------------------------------------------------------- /lua/pl/url.lua: -------------------------------------------------------------------------------- 1 | --- Python-style URL quoting library. 2 | -- 3 | -- @module pl.url 4 | 5 | local url = {} 6 | 7 | local function quote_char(c) 8 | return string.format("%%%02X", string.byte(c)) 9 | end 10 | 11 | --- Quote the url, replacing special characters using the '%xx' escape. 12 | -- @string s the string 13 | -- @bool quote_plus Also escape slashes and replace spaces by plus signs. 14 | function url.quote(s, quote_plus) 15 | if not s or not type(s) == "string" then 16 | return s 17 | end 18 | 19 | s = s:gsub("\n", "\r\n") 20 | s = s:gsub("([^A-Za-z0-9 %-_%./])", quote_char) 21 | if quote_plus then 22 | s = s:gsub(" ", "+") 23 | s = s:gsub("/", quote_char) 24 | else 25 | s = s:gsub(" ", "%%20") 26 | end 27 | 28 | return s 29 | end 30 | 31 | local function unquote_char(h) 32 | return string.char(tonumber(h, 16)) 33 | end 34 | 35 | --- Unquote the url, replacing '%xx' escapes and plus signs. 36 | -- @string s the string 37 | function url.unquote(s) 38 | if not s or not type(s) == "string" then 39 | return s 40 | end 41 | 42 | s = s:gsub("+", " ") 43 | s = s:gsub("%%(%x%x)", unquote_char) 44 | s = s:gsub("\r\n", "\n") 45 | 46 | return s 47 | end 48 | 49 | return url 50 | -------------------------------------------------------------------------------- /lua/repl.lua: -------------------------------------------------------------------------------- 1 | local pretty_print = require("pretty_print") 2 | 3 | local tpprint = function(f) 4 | local toprint = {} 5 | for k,v in ipairs(f) do 6 | if k>1 then table.insert(toprint, v) end 7 | end 8 | pretty_print.display(toprint) 9 | end 10 | 11 | function pprint(f) pretty_print.display({f}) end 12 | 13 | -- return a char* buffer with a given string 14 | function cstr(str) 15 | buf = ffi.new("char["..(string.len(str)+1).."]") 16 | ffi.copy(buf, str) 17 | return buf 18 | end 19 | 20 | -- autocompletion 21 | local completion = require("completion") 22 | 23 | local function ln_complete(expr, ln_completions) 24 | --add the completion 25 | completion.complete(ffi.string(expr), function (s) ffi.C.linenoiseAddCompletion(ln_completions, cstr(s)) end) 26 | end 27 | 28 | ffi.C.linenoiseSetCompletionCallback(ln_complete) 29 | 30 | -- get a multiline input 31 | function get_multiline() 32 | local lines_buffer = {} 33 | while true do 34 | line = ffi.string(ffi.C.linenoise("-")) 35 | if line=='--<' then 36 | return table.concat(lines_buffer) 37 | else 38 | table.insert(lines_buffer, line) 39 | table.insert(lines_buffer, "\n") 40 | end 41 | end 42 | end 43 | 44 | 45 | function repl() 46 | 47 | 48 | print("-----------------") 49 | print("Lua REPL") 50 | 51 | while true do 52 | line = ffi.string(ffi.C.linenoise(">>>")) 53 | 54 | if line=='-->' then 55 | line = get_multiline() 56 | end 57 | 58 | -- try wrapping with a return statement 59 | f, err = loadstring("return "..line) 60 | if not f then 61 | f, err = loadstring(line) 62 | end 63 | 64 | -- store the history 65 | ffi.C.linenoiseHistoryAdd(line) 66 | 67 | if f then 68 | -- call the function and store the result in _ 69 | xpargs = {xpcall(f, debug.traceback)} 70 | if xpargs[1]~=nil and table.getn(xpargs)>1 then 71 | _ = xpargs[2] 72 | tpprint(xpargs) 73 | end 74 | else 75 | console_error(err) 76 | end 77 | end 78 | end 79 | 80 | -------------------------------------------------------------------------------- /lua/rpimodels.lua: -------------------------------------------------------------------------------- 1 | -- get the actual model of Pi we are using 2 | local b1_1= {name="Model B rev 1.0", model="B1", revision=1, version=1, memory=256} 3 | local b1_2 = {name="Model B rev 1.0 + ECN0001", model="B1", revision=1, version=1, memory=256} 4 | local b1_v2 = {name="Model B rev 2.0", model="B1", revision=2, version=1, memory=256} 5 | local a = {name="Model A", model="A1", version=1, revision=1, memory=256} 6 | local b1_v2_1 = {name="Model B rev 2.0 [512Mb]", model="B1", version=1, revision=2, memory=512} 7 | local bplus = {name="Model B+", model="B+", version=1, revision=1, memory=512} 8 | local compute = {name="Compute Module", model="CM", version=1, revision=1, memory=512} 9 | local aplus = {name="Model A+", model="A+", version=1, revision=1, memory=256} 10 | local b2 = {name="Pi 2 Model B", model="B2", version=2, revision=1, memory=1024} 11 | local zero = {name="Pi Zero", model="P0", version=0, revision=1, memory=512} 12 | local b3 = {name="Pi 3 Model B", model="B3", version=3, revision=1, memory=1024} 13 | 14 | 15 | rpi_model_table = { 16 | [0x2] = b1_1, 17 | [0x3] = b1_2, 18 | [0x4] = b1_v2, 19 | [0x5] = b1_v2, 20 | [0x6] = b1_v2, 21 | [0x7] = a, 22 | [0x8] = a, 23 | [0x9] = a, 24 | [0xd] = b1_v2_1, 25 | [0xe] = b1_v2_1, 26 | [0xf] = b1_v2_1, 27 | [0x10] = bplus, 28 | [0x13] = bplus, 29 | [0x11] = compute, 30 | [0x12] = aplus, 31 | [0xa01041] = b2, 32 | [0xa21041] = b2, 33 | [0x900092] = zero, 34 | [0xa02082] = b3, 35 | [0xa22082] = b3, 36 | } 37 | 38 | -------------------------------------------------------------------------------- /lua/shell.lua: -------------------------------------------------------------------------------- 1 | -- cd 2 | -- ls 3 | -- cp 4 | -- mv 5 | -- rm 6 | -- grep 7 | -- more 8 | -- pwd 9 | -- rmdir 10 | -- mkdir 11 | -- set 12 | -- $ interpolation 13 | -- zip 14 | -- unzip 15 | -- upload 16 | -- dload 17 | -- cat 18 | 19 | local _pwd='/' 20 | 21 | function sh_pwd() 22 | return pwd 23 | end 24 | 25 | function sh_ls() 26 | ls(_pwd) 27 | end 28 | 29 | function sh_cat(file) 30 | local f_ = io.open(_pwd..file) 31 | local all = f_.read('*all') 32 | print(all) 33 | end 34 | 35 | function -------------------------------------------------------------------------------- /lua/sys.lua: -------------------------------------------------------------------------------- 1 | function io_address(addr) 2 | return memmap.gpio_base + addr 3 | end 4 | 5 | function split32(a) 6 | local a1 = bit.rshift(bit.band(a,0xff), 0) 7 | local a2 = bit.rshift(bit.band(a,0xff), 8) 8 | local a3 = bit.rshift(bit.band(a,0xff), 16) 9 | local a4 = bit.rshift(bit.band(a,0xff), 24) 10 | return a1,a2,a3,a4 11 | end 12 | 13 | ffi.cdef([[ 14 | void enable_mmu(void); 15 | ]]) 16 | 17 | mem = ffi.new("unsigned char *", ffi.cast("unsigned char *", 0x0)) 18 | mem32 = {} 19 | _mem32 = ffi.new("unsigned int *", ffi.cast("unsigned int *", 0x0)) 20 | local mt_mem32 = { 21 | __index = function(t,addr) return t[bit.rshift(addr,2)] end, 22 | __newindex = function(t,addr,val) t[bit.rshift(addr,2)]=val end 23 | } 24 | setmetatable(mem32, mt_mem32) 25 | 26 | -- simple get and put functions 27 | function get32(addr) 28 | return _mem32[bit.rshift(addr, 2)] 29 | end 30 | 31 | function put32(addr, val) 32 | _mem32[bit.rshift(addr, 2)] = val 33 | end 34 | 35 | 36 | function set_bit(v, b) 37 | return bit.bor(v, bit.lshift(1, b)) 38 | end 39 | 40 | function clear_bit(v, b) 41 | return bit.band(v, bit.bnot(bit.lshift(1, b))) 42 | end 43 | 44 | function get_bit(v, b) 45 | return bit.rshift(bit.band(v, bit.lshift(1,b)), b) 46 | end 47 | 48 | ffi.C.enable_mmu() 49 | 50 | 51 | ffi.cdef( 52 | [[typedef struct vector_table 53 | { 54 | void (*reset)(void); 55 | void (*undefined_instruction)(void); 56 | void (*software_interrupt)(void); 57 | void (*prefetch_abort)(void); 58 | void (*data_access)(void); 59 | void (*unhandled_exception)(void); 60 | void (*interrupt)(void); 61 | void (*fast_interrupt)(void); 62 | 63 | } vector_table; 64 | ]]) 65 | 66 | sys = {} 67 | sys.memmap = memmap 68 | sys.exc_table = ffi.cast("vector_table *", memmap.exc_table) 69 | sys.atags = {} -------------------------------------------------------------------------------- /lua/test.lua: -------------------------------------------------------------------------------- 1 | print("Testing Lua...") 2 | print("---") 3 | 4 | print("Opening the ffi interface...") 5 | ffi = require("ffi") 6 | ffi.load("default") 7 | print("Serial output test; should print ABC...") 8 | 9 | 10 | ffi.cdef([[ 11 | void uart_putc(unsigned int); 12 | unsigned int uart_getc(void); 13 | ]]) 14 | 15 | putc = ffi.C.uart_putc 16 | putc(65) 17 | putc(66) 18 | putc(67) 19 | putc(10) 20 | putc(13) 21 | 22 | 23 | function getline() 24 | c = nil 25 | str = {} 26 | while c~=10 do 27 | c = getc() 28 | table.insert(str, string.char(c)) 29 | putc(c) 30 | end 31 | return table.concat(str) 32 | end 33 | 34 | --print("Testing getline()...") 35 | --print("Got: ", getline()) 36 | 37 | 38 | -------------------------------------------------------------------------------- /lua/zip_require.lua: -------------------------------------------------------------------------------- 1 | local zip_list = bootzip:list() 2 | 3 | function zip_require(pac) 4 | -- package already loaded 5 | if package.loaded[pac]~=nil then 6 | return package.loaded[pac] 7 | end 8 | 9 | -- load the package from the zip file 10 | if package.preload[pac]==nil then 11 | for k,v in ipairs(zip_list) do 12 | local fname = v.filename 13 | -- replace . with / to make subpackage loading work right 14 | local fpac = string.gsub(pac, "%.", "/") 15 | if string.find(fname, "/"..fpac.."%.lua$") then 16 | package.loaded[pac] = run_bootzip(fname) 17 | -- remember even packages that don't return anything 18 | if package.loaded[pac]==nil then 19 | package.loaded[pac] = true 20 | end 21 | return package.loaded[pac] 22 | end 23 | end 24 | else 25 | -- in the preload table 26 | return package.preload[pac]() 27 | end 28 | print("Package "..pac.." not found") 29 | return nil 30 | end 31 | 32 | require = zip_require 33 | -------------------------------------------------------------------------------- /mem.h: -------------------------------------------------------------------------------- 1 | /* Memory map: 2 | 0x000000 reserverd 3 | 0x008000 kernel 4 | 0x208000 kernel max 5 | 0x210000 stack ptr 6 | 0x220000 heap starts 7 | */ 8 | 9 | #ifndef MEM_H 10 | #define MEM_H 11 | #include 12 | 13 | 14 | typedef unsigned char u8; 15 | typedef unsigned int u32; 16 | 17 | #define MEM_RESERVED 0x000000 18 | #define MEM_KERNEL_START 0x008000 19 | #define MEM_STACK_PTR 0x310000 20 | #define MEM_HEAP_START 0x320000 21 | #define MEM_GPIO_BASE 0x20000000 22 | #define MEM_MMU_TABLE_SIZE 0x8000 23 | 24 | /* Declare ARM assembly-language helper functions */ 25 | extern void PUT_32(u32 addr, u32 data); 26 | extern u32 GET_32(u32 addr); 27 | extern void NO_OP(); 28 | extern void SPIN(u32 count); 29 | extern void BRANCH_TO(u32 addr); 30 | 31 | extern void memory_barrier(void); 32 | extern void start_l1cache(void); 33 | extern void stop_l1cache(void); 34 | extern void start_mmu(void); 35 | 36 | #endif -------------------------------------------------------------------------------- /memmap: -------------------------------------------------------------------------------- 1 | 2 | MEMORY 3 | { 4 | ram : ORIGIN = 0x8000, LENGTH = 0x300000 5 | } 6 | 7 | SECTIONS 8 | { 9 | .text : { *(.text*) } > ram 10 | .bss : { *(.bss*) } > ram 11 | .data : { *(.data*) } > ram 12 | .rodata : { *(.rodata*) } > ram 13 | __exidx_start = .; 14 | .ARM.exidx : {*(.ARM.exidx* .gnu.linkonce.armexidx.*) } > ram 15 | __exidx_end = .; 16 | .symdata : { *(.symdata*) } > ram 17 | __kernel_end = .; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /mmu.c: -------------------------------------------------------------------------------- 1 | #include "mem.h" 2 | 3 | volatile __attribute__ ((aligned (0x4000))) unsigned mem_mmu_table[MEM_MMU_TABLE_SIZE]; 4 | 5 | /* Code from https://www.raspberrypi.org/forums/viewtopic.php?t=65922&p=491887 */ 6 | void enable_mmu (void) 7 | { 8 | 9 | 10 | unsigned base; 11 | for (base = 0; base < 512; base++) 12 | { 13 | // outer and inner write back, write allocate, shareable 14 | mem_mmu_table[base] = base << 20 | 0x1140E; 15 | } 16 | for (; base < 4096; base++) 17 | { 18 | // shared device, never execute 19 | mem_mmu_table[base] = base << 20 | 0x10416; 20 | } 21 | 22 | // restrict cache size to 16K (no page coloring) 23 | unsigned auxctrl; 24 | asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (auxctrl)); 25 | auxctrl |= 1 << 6; 26 | asm volatile ("mcr p15, 0, %0, c1, c0, 1" :: "r" (auxctrl)); 27 | 28 | // set domain 0 to client 29 | asm volatile ("mcr p15, 0, %0, c3, c0, 0" :: "r" (1)); 30 | 31 | // always use TTBR0 32 | asm volatile ("mcr p15, 0, %0, c2, c0, 2" :: "r" (0)); 33 | 34 | // set TTBR0 (page table walk inner cacheable, outer non-cacheable, shareable memory) 35 | asm volatile ("mcr p15, 0, %0, c2, c0, 0" :: "r" (3 | (unsigned) &mem_mmu_table)); 36 | 37 | // invalidate data cache and flush prefetch buffer 38 | asm volatile ("mcr p15, 0, %0, c7, c5, 4" :: "r" (0) : "memory"); 39 | asm volatile ("mcr p15, 0, %0, c7, c6, 0" :: "r" (0) : "memory"); 40 | 41 | // enable MMU, L1 cache and instruction cache, L2 cache, write buffer, 42 | // branch prediction and extended page table on 43 | unsigned mode; 44 | asm volatile ("mrc p15,0,%0,c1,c0,0" : "=r" (mode)); 45 | mode |= 0x0480180D; 46 | asm volatile ("mcr p15,0,%0,c1,c0,0" :: "r" (mode) : "memory"); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /rboot/atag.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #include 23 | #include "atag.h" 24 | 25 | #define tag_next(t) (struct atag *)((uint32_t *)(t) + (t)->hdr.size) 26 | 27 | void parse_atags(uint32_t atags, void (*cb)(struct atag *)) 28 | { 29 | if(atags == 0) 30 | return; 31 | 32 | struct atag *cur = (struct atag *)atags; 33 | struct atag *prev; 34 | do 35 | { 36 | prev = cur; 37 | 38 | cb(cur); 39 | cur = tag_next(cur); 40 | } while(prev->hdr.tag != ATAG_NONE); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /rboot/block.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #ifndef BLOCK_H 23 | #define BLOCK_H 24 | 25 | #include 26 | #include 27 | 28 | struct fs; 29 | 30 | struct block_device { 31 | char *driver_name; 32 | char *device_name; 33 | uint8_t *device_id; 34 | size_t dev_id_len; 35 | 36 | int supports_multiple_block_read; 37 | int supports_multiple_block_write; 38 | 39 | int (*read)(struct block_device *dev, uint8_t *buf, size_t buf_size, uint32_t block_num); 40 | int (*write)(struct block_device *dev, uint8_t *buf, size_t buf_size, uint32_t block_num); 41 | size_t block_size; 42 | size_t num_blocks; 43 | 44 | struct fs *fs; 45 | }; 46 | 47 | size_t block_read(struct block_device *dev, uint8_t *buf, size_t buf_size, uint32_t starting_block); 48 | size_t block_write(struct block_device *dev, uint8_t *buf, size_t buf_size, uint32_t starting_block); 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /rboot/console.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #ifndef CONSOLE_H 23 | #define CONSOLE_H 24 | 25 | void clear(); 26 | void draw_char(char c, int x, int y, uint32_t fore, uint32_t back); 27 | int console_putc(int c); 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /rboot/dirent.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #ifndef DIRENT_H 23 | #define DIRENT_H 24 | 25 | struct mb_dirent; 26 | struct mb_dir_info { 27 | struct mb_dirent *first; 28 | struct mb_dirent *next; 29 | }; 30 | 31 | #ifdef DIR 32 | #undef DIR 33 | #endif 34 | #define DIR struct mb_dir_info 35 | 36 | #include "vfs.h" 37 | #include 38 | #include "multiboot.h" 39 | 40 | #endif 41 | 42 | -------------------------------------------------------------------------------- /rboot/fb.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #ifndef FB_H 23 | #define FB_H 24 | 25 | #define FB_FAIL_GET_RESOLUTION -1 26 | #define FB_FAIL_INVALID_RESOLUTION -2 27 | #define FB_FAIL_SETUP_FB -3 28 | #define FB_FAIL_INVALID_TAGS -4 29 | #define FB_FAIL_INVALID_TAG_RESPONSE -5 30 | #define FB_FAIL_INVALID_TAG_DATA -6 31 | #define FB_FAIL_INVALID_PITCH_RESPONSE -7 32 | #define FB_FAIL_INVALID_PITCH_DATA -8 33 | 34 | uint8_t *fb_get_framebuffer(); 35 | int fb_init(); 36 | int fb_get_bpp(); 37 | int fb_get_byte_size(); 38 | int fb_get_width(); 39 | int fb_get_height(); 40 | int fb_get_pitch(); 41 | 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /rboot/fs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #ifndef FS_H 23 | #define FS_H 24 | 25 | #include "dirent.h" 26 | #include 27 | #include 28 | #include "block.h" 29 | 30 | #define FS_FLAG_SUPPORTS_EMPTY_FNAME 1 31 | 32 | struct fs { 33 | struct block_device *parent; 34 | const char *fs_name; 35 | uint32_t flags; 36 | size_t block_size; 37 | 38 | MB_FILE *(*fopen)(struct fs *, struct mb_dirent *, const char *mode); 39 | size_t (*fread)(struct fs *, void *ptr, size_t byte_size, MB_FILE *stream); 40 | size_t (*fwrite)(struct fs *, void *ptr, size_t byte_size, MB_FILE *stream); 41 | int (*fclose)(struct fs *, MB_FILE *fp); 42 | long (*fsize)(MB_FILE *fp); 43 | int (*fseek)(MB_FILE *stream, long offset, int whence); 44 | long (*ftell)(MB_FILE *fp); 45 | int (*fflush)(MB_FILE *fp); 46 | 47 | struct mb_dirent *(*read_directory)(struct fs *, char **name); 48 | }; 49 | 50 | int register_fs(struct block_device *dev, int part_id); 51 | int fs_interpret_mode(const char *mode); 52 | size_t fs_fread(uint32_t (*get_next_bdev_block_num)(uint32_t f_block_idx, MB_FILE *s, void *opaque, int add_blocks), 53 | struct fs *fs, void *ptr, size_t byte_size, 54 | MB_FILE *stream, void *opaque); 55 | size_t fs_fwrite(uint32_t (*get_next_bdev_block_num)(uint32_t f_block_idx, MB_FILE *s, void *opaque, int add_blocks), 56 | struct fs *fs, void *ptr, size_t byte_size, 57 | MB_FILE *stream, void *opaque); 58 | 59 | #endif 60 | 61 | -------------------------------------------------------------------------------- /rboot/mbox.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #include 23 | #include "mbox.h" 24 | #include "mmio.h" 25 | 26 | #define MBOX_FULL 0x80000000 27 | #define MBOX_EMPTY 0x40000000 28 | 29 | uint32_t mbox_read(uint8_t channel) 30 | { 31 | while(1) 32 | { 33 | while(mmio_read(MBOX_BASE + MBOX_STATUS) & MBOX_EMPTY); 34 | 35 | uint32_t data = mmio_read(MBOX_BASE + MBOX_READ); 36 | uint8_t read_channel = (uint8_t)(data & 0xf); 37 | if(read_channel == channel) 38 | return (data & 0xfffffff0); 39 | } 40 | } 41 | 42 | void mbox_write(uint8_t channel, uint32_t data) 43 | { 44 | while(mmio_read(MBOX_BASE + MBOX_STATUS) & MBOX_FULL); 45 | mmio_write(MBOX_BASE + MBOX_WRITE, (data & 0xfffffff0) | (uint32_t)(channel & 0xf)); 46 | } 47 | 48 | -------------------------------------------------------------------------------- /rboot/mbox.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #ifndef MBOX_H 23 | #define MBOX_H 24 | 25 | #include 26 | #include "../mem.h" 27 | 28 | #define MBOX_BASE (MEM_GPIO_BASE+0x000b880) 29 | 30 | #define MBOX_PEEK 0x10 31 | #define MBOX_READ 0x00 32 | #define MBOX_WRITE 0x20 33 | #define MBOX_STATUS 0x18 34 | #define MBOX_SENDER 0x14 35 | #define MBOX_CONFIG 0x1c 36 | 37 | #define MBOX_FB 1 38 | #define MBOX_PROP 8 39 | 40 | #define MBOX_SUCCESS 0x80000000 41 | 42 | uint32_t mbox_read(uint8_t channel); 43 | void mbox_write(uint8_t channel, uint32_t data); 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /rboot/mmio.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #include 23 | #include "mmio.h" 24 | 25 | extern void memory_barrier(); 26 | 27 | inline void mmio_write(uint32_t reg, uint32_t data) 28 | { 29 | memory_barrier(); 30 | *(volatile uint32_t *)(reg) = data; 31 | memory_barrier(); 32 | } 33 | 34 | inline uint32_t mmio_read(uint32_t reg) 35 | { 36 | memory_barrier(); 37 | return *(volatile uint32_t *)(reg); 38 | memory_barrier(); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /rboot/mmio.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #ifndef MMIO_H 23 | #define MMIO_H 24 | 25 | #include 26 | 27 | void mmio_write(uint32_t reg, uint32_t data); 28 | uint32_t mmio_read(uint32_t reg); 29 | 30 | #endif // !MMIO_H 31 | 32 | -------------------------------------------------------------------------------- /rboot/multiboot.h: -------------------------------------------------------------------------------- 1 | /* multiboot.h - Multiboot header file. */ 2 | /* Copyright (C) 1999,2003,2007,2008,2009 Free Software Foundation, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY 17 | * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 19 | * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | // Modified from http://www.gnu.org/software/grub/manual/multiboot/multiboot.html 23 | 24 | #ifndef MULTIBOOT_H 25 | #define MULTIBOOT_H 26 | 27 | 28 | 29 | #define MB_SEEK_SET 0x1000 30 | #define MB_SEEK_CUR 0x1001 31 | #define MB_SEEK_END 0x1002 32 | #define MB_SEEK_START SEEK_SET 33 | 34 | struct mb_dirent { 35 | struct mb_dirent *next; 36 | char *name; 37 | uint32_t byte_size; 38 | uint8_t is_dir; 39 | void *opaque; 40 | struct fs *fs; 41 | }; 42 | 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /rboot/output.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #ifndef OUTPUT_H 23 | #define OUTPUT_H 24 | 25 | #include 26 | 27 | typedef uint32_t rpi_boot_output_state; 28 | 29 | 30 | rpi_boot_output_state output_get_state(); 31 | void output_restore_state(rpi_boot_output_state state); 32 | void output_enable_fb(); 33 | void output_disable_fb(); 34 | void output_enable_uart(); 35 | void output_disable_uart(); 36 | void output_enable_log(); 37 | void output_disable_log(); 38 | void output_enable_custom(); 39 | void output_disable_custom(); 40 | void output_init(); 41 | int split_putc(int c); 42 | int register_custom_output_function(int (*putc_function)(int c)); 43 | 44 | 45 | #define RPIBOOT_OUTPUT_FB (1 << 0) 46 | #define RPIBOOT_OUTPUT_UART (1 << 1) 47 | #define RPIBOOT_OUTPUT_LOG (1 << 2) 48 | #define RPIBOOT_OUTPUT_CUSTOM (1 << 3) 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /rboot/timer.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #include "timer.h" 23 | #include "mmio.h" 24 | #include 25 | #include 26 | #include 27 | #include "../mem.h" 28 | 29 | #define TIMER_CLO (MEM_GPIO_BASE+0x0003004) 30 | 31 | int usleep(usecs_t usec) 32 | { 33 | struct timer_wait tw = register_timer(usec); 34 | while(!compare_timer(tw)); 35 | return 0; 36 | } 37 | 38 | struct timer_wait register_timer(usecs_t usec) 39 | { 40 | struct timer_wait tw; 41 | tw.rollover = 0; 42 | tw.trigger_value = 0; 43 | 44 | if(usec < 0) 45 | { 46 | errno = EINVAL; 47 | return tw; 48 | } 49 | uint32_t cur_timer = mmio_read(TIMER_CLO); 50 | uint32_t trig = cur_timer + (uint32_t)usec; 51 | 52 | tw.trigger_value = trig; 53 | if(trig > cur_timer) 54 | tw.rollover = 0; 55 | else 56 | tw.rollover = 1; 57 | return tw; 58 | } 59 | 60 | int compare_timer(struct timer_wait tw) 61 | { 62 | uint32_t cur_timer = mmio_read(TIMER_CLO); 63 | 64 | if(cur_timer < tw.trigger_value) 65 | { 66 | if(tw.rollover) 67 | tw.rollover = 0; 68 | } 69 | else if(!tw.rollover) 70 | return 1; 71 | 72 | return 0; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /rboot/timer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #ifndef TIMER_H 23 | #define TIMER_H 24 | 25 | #include 26 | #include 27 | 28 | typedef int usecs_t; 29 | 30 | struct timer_wait 31 | { 32 | uint32_t trigger_value; 33 | int rollover; 34 | }; 35 | 36 | int usleep(usecs_t usec); 37 | struct timer_wait register_timer(usecs_t usec); 38 | int compare_timer(struct timer_wait tw); 39 | 40 | #define TIMEOUT_WAIT(stop_if_true, usec) \ 41 | do { \ 42 | struct timer_wait tw = register_timer(usec); \ 43 | do \ 44 | { \ 45 | if(stop_if_true) \ 46 | break; \ 47 | } while(!compare_timer(tw)); \ 48 | } while(0); 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /rboot/uart.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 by John Cronin 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | * THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UART_H 23 | #define UART_H 24 | 25 | #include 26 | #include "timer.h" 27 | 28 | void uart_init(); 29 | int uart_putc(int byte); 30 | void uart_puts(const char *str); 31 | int uart_getc(); 32 | int uart_getc_timeout(usecs_t timeout); 33 | 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /sqlite_stubs.c: -------------------------------------------------------------------------------- 1 | int sqlite3_os_init(void) 2 | { 3 | // do nothing for now... 4 | return 0; 5 | } 6 | 7 | 8 | int sqlite3_os_end(void) 9 | { 10 | // do nothing for now... 11 | return 0; 12 | } -------------------------------------------------------------------------------- /tcc/Changelog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnhw/luajitpi/80d4a2de34309dd1b61ba0de2e227a111566ec81/tcc/Changelog -------------------------------------------------------------------------------- /tcc/VERSION: -------------------------------------------------------------------------------- 1 | 0.9.26 2 | -------------------------------------------------------------------------------- /tcc/arm-gen.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnhw/luajitpi/80d4a2de34309dd1b61ba0de2e227a111566ec81/tcc/arm-gen.c -------------------------------------------------------------------------------- /tcc/config.h: -------------------------------------------------------------------------------- 1 | /* Automatically generated by configure - do not modify */ 2 | #ifndef CONFIG_TCCDIR 3 | # define CONFIG_TCCDIR "/usr/local/lib/tcc" 4 | #endif 5 | #define CONFIG_TCC_STATIC 1 6 | #define GCC_MAJOR 7 | #define GCC_MINOR 8 | #define HOST_ARM 1 9 | #define TCC_ARM_VERSION 4 10 | #define TCC_VERSION "0.9.26" 11 | #define CONFIG_NOLDL 12 | 13 | -------------------------------------------------------------------------------- /tcc/config.mak: -------------------------------------------------------------------------------- 1 | # Automatically generated by configure - do not modify 2 | prefix=/usr/local 3 | bindir=$(DESTDIR)/usr/local/bin 4 | tccdir=$(DESTDIR)/usr/local/lib/tcc 5 | libdir=$(DESTDIR)/usr/local/lib 6 | ln_libdir=/usr/local/lib 7 | includedir=$(DESTDIR)/usr/local/include 8 | mandir=$(DESTDIR)/usr/local/share/man 9 | infodir=$(DESTDIR)/usr/local/share/info 10 | docdir=$(DESTDIR)/usr/local/share/doc/tcc 11 | CC=arm-none-eabi-gcc 12 | GCC_MAJOR= 13 | GCC_MINOR= 14 | HOST_CC=gcc 15 | AR=ar 16 | STRIP=strip -s -R .comment -R .note 17 | CFLAGS=-Wall -g -O2 18 | LDFLAGS= 19 | LIBSUF=.a 20 | EXESUF= 21 | ARCH=arm 22 | TARGETOS=Linux 23 | VERSION=0.9.26 24 | SRC_PATH=/home/arm/tcc-0.9.26 25 | top_srcdir=$(TOP) 26 | top_builddir=$(TOP) 27 | -------------------------------------------------------------------------------- /tcc/config.texi: -------------------------------------------------------------------------------- 1 | @set VERSION 0.9.26 2 | -------------------------------------------------------------------------------- /tcc/conftest-15222.h: -------------------------------------------------------------------------------- 1 | /* Automatically generated by configure - do not modify */ 2 | #ifndef CONFIG_TCCDIR 3 | # define CONFIG_TCCDIR "/usr/local/lib/tcc" 4 | #endif 5 | #define GCC_MAJOR 6 | #define GCC_MINOR 7 | -------------------------------------------------------------------------------- /tcc/conftest.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Define architecture */ 4 | #if defined(__i386__) 5 | # define TRIPLET_ARCH "i386" 6 | #elif defined(__x86_64__) 7 | # define TRIPLET_ARCH "x86_64" 8 | #elif defined(__arm__) 9 | # define TRIPLET_ARCH "arm" 10 | #else 11 | # define TRIPLET_ARCH "unknown" 12 | #endif 13 | 14 | /* Define OS */ 15 | #if defined (__linux__) 16 | # define TRIPLET_OS "linux" 17 | #elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__) 18 | # define TRIPLET_OS "kfreebsd" 19 | #elif !defined (__GNU__) 20 | # define TRIPLET_OS "unknown" 21 | #endif 22 | 23 | /* Define calling convention and ABI */ 24 | #if defined (__ARM_EABI__) 25 | # if defined (__ARM_PCS_VFP) 26 | # define TRIPLET_ABI "gnueabihf" 27 | # else 28 | # define TRIPLET_ABI "gnueabi" 29 | # endif 30 | #else 31 | # define TRIPLET_ABI "gnu" 32 | #endif 33 | 34 | #ifdef __GNU__ 35 | # define TRIPLET TRIPLET_ARCH "-" TRIPLET_ABI 36 | #else 37 | # define TRIPLET TRIPLET_ARCH "-" TRIPLET_OS "-" TRIPLET_ABI 38 | #endif 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | switch(argc == 2 ? argv[1][0] : 0) { 43 | case 'b': 44 | { 45 | volatile unsigned foo = 0x01234567; 46 | puts(*(unsigned char*)&foo == 0x67 ? "no" : "yes"); 47 | break; 48 | } 49 | #ifdef __GNUC__ 50 | case 'm': 51 | printf("%d\n", __GNUC_MINOR__); 52 | break; 53 | case 'v': 54 | printf("%d\n", __GNUC__); 55 | break; 56 | #else 57 | case 'm': 58 | case 'v': 59 | puts("0"); 60 | break; 61 | #endif 62 | case 't': 63 | puts(TRIPLET); 64 | break; 65 | case -1: 66 | /* to test -Wno-unused-result */ 67 | fread(NULL, 1, 1, NULL); 68 | break; 69 | } 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /tcc/examples/ex1.c: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/tcc -run 2 | #include 3 | 4 | int main() 5 | { 6 | printf("Hello World\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tcc/examples/ex2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define N 20 5 | 6 | int nb_num; 7 | int tab[N]; 8 | int stack_ptr; 9 | int stack_op[N]; 10 | int stack_res[60]; 11 | int result; 12 | 13 | int find(int n, int i1, int a, int b, int op) 14 | { 15 | int i, j; 16 | int c; 17 | 18 | if (stack_ptr >= 0) { 19 | stack_res[3*stack_ptr] = a; 20 | stack_op[stack_ptr] = op; 21 | stack_res[3*stack_ptr+1] = b; 22 | stack_res[3*stack_ptr+2] = n; 23 | if (n == result) 24 | return 1; 25 | tab[i1] = n; 26 | } 27 | 28 | for(i=0;i 2 | #include 3 | 4 | int fib(n) 5 | { 6 | if (n <= 2) 7 | return 1; 8 | else 9 | return fib(n-1) + fib(n-2); 10 | } 11 | 12 | int main(int argc, char **argv) 13 | { 14 | int n; 15 | if (argc < 2) { 16 | printf("usage: fib n\n" 17 | "Compute nth Fibonacci number\n"); 18 | return 1; 19 | } 20 | 21 | n = atoi(argv[1]); 22 | printf("fib(%d) = %d\n", n, fib(n, 2)); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tcc/examples/ex4.c: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11 2 | #include 3 | #include 4 | #include 5 | 6 | /* Yes, TCC can use X11 too ! */ 7 | 8 | int main(int argc, char **argv) 9 | { 10 | Display *display; 11 | Screen *screen; 12 | 13 | display = XOpenDisplay(""); 14 | if (!display) { 15 | fprintf(stderr, "Could not open X11 display\n"); 16 | exit(1); 17 | } 18 | printf("X11 display opened.\n"); 19 | screen = XScreenOfDisplay(display, 0); 20 | printf("width = %d\nheight = %d\ndepth = %d\n", 21 | screen->width, 22 | screen->height, 23 | screen->root_depth); 24 | XCloseDisplay(display); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /tcc/examples/ex5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("Hello World\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tcc/i386-asm.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnhw/luajitpi/80d4a2de34309dd1b61ba0de2e227a111566ec81/tcc/i386-asm.c -------------------------------------------------------------------------------- /tcc/include/float.h: -------------------------------------------------------------------------------- 1 | #ifndef _FLOAT_H_ 2 | #define _FLOAT_H_ 3 | 4 | #define FLT_RADIX 2 5 | 6 | /* IEEE float */ 7 | #define FLT_MANT_DIG 24 8 | #define FLT_DIG 6 9 | #define FLT_ROUNDS 1 10 | #define FLT_EPSILON 1.19209290e-07F 11 | #define FLT_MIN_EXP (-125) 12 | #define FLT_MIN 1.17549435e-38F 13 | #define FLT_MIN_10_EXP (-37) 14 | #define FLT_MAX_EXP 128 15 | #define FLT_MAX 3.40282347e+38F 16 | #define FLT_MAX_10_EXP 38 17 | 18 | /* IEEE double */ 19 | #define DBL_MANT_DIG 53 20 | #define DBL_DIG 15 21 | #define DBL_EPSILON 2.2204460492503131e-16 22 | #define DBL_MIN_EXP (-1021) 23 | #define DBL_MIN 2.2250738585072014e-308 24 | #define DBL_MIN_10_EXP (-307) 25 | #define DBL_MAX_EXP 1024 26 | #define DBL_MAX 1.7976931348623157e+308 27 | #define DBL_MAX_10_EXP 308 28 | 29 | /* horrible intel long double */ 30 | #ifdef __i386__ 31 | 32 | #define LDBL_MANT_DIG 64 33 | #define LDBL_DIG 18 34 | #define LDBL_EPSILON 1.08420217248550443401e-19L 35 | #define LDBL_MIN_EXP (-16381) 36 | #define LDBL_MIN 3.36210314311209350626e-4932L 37 | #define LDBL_MIN_10_EXP (-4931) 38 | #define LDBL_MAX_EXP 16384 39 | #define LDBL_MAX 1.18973149535723176502e+4932L 40 | #define LDBL_MAX_10_EXP 4932 41 | 42 | #else 43 | 44 | /* same as IEEE double */ 45 | #define LDBL_MANT_DIG 53 46 | #define LDBL_DIG 15 47 | #define LDBL_EPSILON 2.2204460492503131e-16 48 | #define LDBL_MIN_EXP (-1021) 49 | #define LDBL_MIN 2.2250738585072014e-308 50 | #define LDBL_MIN_10_EXP (-307) 51 | #define LDBL_MAX_EXP 1024 52 | #define LDBL_MAX 1.7976931348623157e+308 53 | #define LDBL_MAX_10_EXP 308 54 | 55 | #endif 56 | 57 | #endif /* _FLOAT_H_ */ 58 | -------------------------------------------------------------------------------- /tcc/include/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDARG_H 2 | #define _STDARG_H 3 | 4 | #ifdef __x86_64__ 5 | #ifndef _WIN64 6 | 7 | typedef void *va_list; 8 | 9 | va_list __va_start(void *fp); 10 | void *__va_arg(va_list ap, int arg_type, int size); 11 | va_list __va_copy(va_list src); 12 | void __va_end(va_list ap); 13 | 14 | #define va_start(ap, last) ((ap) = __va_start(__builtin_frame_address(0))) 15 | #define va_arg(ap, type) \ 16 | (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type)))) 17 | #define va_copy(dest, src) ((dest) = __va_copy(src)) 18 | #define va_end(ap) __va_end(ap) 19 | 20 | #else /* _WIN64 */ 21 | typedef char *va_list; 22 | #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+7)&~7) 23 | #define va_arg(ap,type) (ap += (sizeof(type)+7)&~7, *(type *)(ap - ((sizeof(type)+7)&~7))) 24 | #define va_copy(dest, src) (dest) = (src) 25 | #define va_end(ap) 26 | #endif 27 | 28 | #else /* __i386__ */ 29 | typedef char *va_list; 30 | /* only correct for i386 */ 31 | #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) 32 | #define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3))) 33 | #define va_copy(dest, src) (dest) = (src) 34 | #define va_end(ap) 35 | #endif 36 | 37 | /* fix a buggy dependency on GCC in libio.h */ 38 | typedef va_list __gnuc_va_list; 39 | #define _VA_LIST_DEFINED 40 | 41 | #endif /* _STDARG_H */ 42 | -------------------------------------------------------------------------------- /tcc/include/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDBOOL_H 2 | #define _STDBOOL_H 3 | 4 | /* ISOC99 boolean */ 5 | 6 | #define bool _Bool 7 | #define true 1 8 | #define false 0 9 | 10 | #endif /* _STDBOOL_H */ 11 | -------------------------------------------------------------------------------- /tcc/include/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDDEF_H 2 | #define _STDDEF_H 3 | 4 | typedef __SIZE_TYPE__ size_t; 5 | typedef __PTRDIFF_TYPE__ ssize_t; 6 | typedef __WCHAR_TYPE__ wchar_t; 7 | typedef __PTRDIFF_TYPE__ ptrdiff_t; 8 | typedef __PTRDIFF_TYPE__ intptr_t; 9 | typedef __SIZE_TYPE__ uintptr_t; 10 | 11 | #ifndef __int8_t_defined 12 | #define __int8_t_defined 13 | typedef signed char int8_t; 14 | typedef signed short int int16_t; 15 | typedef signed int int32_t; 16 | typedef signed long long int int64_t; 17 | typedef unsigned char uint8_t; 18 | typedef unsigned short int uint16_t; 19 | typedef unsigned int uint32_t; 20 | typedef unsigned long long int uint64_t; 21 | #endif 22 | 23 | #define NULL ((void*)0) 24 | #define offsetof(type, field) ((size_t)&((type *)0)->field) 25 | 26 | void *alloca(size_t size); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /tcc/include/varargs.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _VARARGS_H 7 | #define _VARARGS_H 8 | 9 | #error "TinyCC no longer implements ." 10 | #error "Revise your code to use ." 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /tcc/lib/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Tiny C Compiler Makefile for libtcc1.a 3 | # 4 | 5 | TOP = .. 6 | include $(TOP)/Makefile 7 | VPATH = $(top_srcdir)/lib $(top_srcdir)/win32/lib 8 | 9 | ifndef TARGET 10 | ifdef CONFIG_WIN64 11 | TARGET = x86_64-win32 12 | else 13 | ifdef CONFIG_WIN32 14 | TARGET = i386-win32 15 | else 16 | ifeq ($(ARCH),i386) 17 | TARGET = i386 18 | ifneq ($(TARGETOS),Darwin) 19 | XCC = $(CC) 20 | endif 21 | else 22 | ifeq ($(ARCH),x86-64) 23 | TARGET = x86_64 24 | ifneq ($(TARGETOS),Darwin) 25 | XCC = $(CC) 26 | endif 27 | endif 28 | endif 29 | endif 30 | endif 31 | BCHECK_O = bcheck.o 32 | endif 33 | 34 | DIR = $(TARGET) 35 | 36 | native : ../libtcc1.a 37 | cross : $(DIR)/libtcc1.a 38 | 39 | native : TCC = $(TOP)/tcc$(EXESUF) 40 | cross : TCC = $(TOP)/$(TARGET)-tcc$(EXESUF) 41 | 42 | I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BCHECK_O) 43 | X86_64_O = libtcc1.o alloca86_64.o 44 | WIN32_O = $(I386_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o 45 | WIN64_O = $(X86_64_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o 46 | 47 | ifeq "$(TARGET)" "i386-win32" 48 | OBJ = $(addprefix $(DIR)/,$(WIN32_O)) 49 | TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE 50 | XCC = $(TCC) -B$(top_srcdir)/win32 -I$(top_srcdir)/include 51 | XAR = $(DIR)/tiny_libmaker$(EXESUF) 52 | else 53 | ifeq "$(TARGET)" "x86_64-win32" 54 | OBJ = $(addprefix $(DIR)/,$(WIN64_O)) 55 | TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE 56 | XCC = $(TCC) -B$(top_srcdir)/win32 -I$(top_srcdir)/include 57 | XAR = $(DIR)/tiny_libmaker$(EXESUF) 58 | else 59 | ifeq "$(TARGET)" "i386" 60 | OBJ = $(addprefix $(DIR)/,$(I386_O)) 61 | TGT = -DTCC_TARGET_I386 62 | XCC ?= $(TCC) -B$(TOP) 63 | else 64 | ifeq "$(TARGET)" "x86_64" 65 | OBJ = $(addprefix $(DIR)/,$(X86_64_O)) 66 | TGT = -DTCC_TARGET_X86_64 67 | XCC ?= $(TCC) -B$(TOP) 68 | else 69 | $(error libtcc1.a not supported on target '$(TARGET)') 70 | endif 71 | endif 72 | endif 73 | endif 74 | 75 | XFLAGS = $(CPPFLAGS) $(CFLAGS) $(TGT) 76 | 77 | ifeq ($(TARGETOS),Darwin) 78 | XAR = $(DIR)/tiny_libmaker$(EXESUF) 79 | XFLAGS += -D_ANSI_SOURCE 80 | BCHECK_O = 81 | endif 82 | 83 | ifdef XAR 84 | AR = $(XAR) 85 | endif 86 | 87 | $(DIR)/libtcc1.a ../libtcc1.a : $(OBJ) $(XAR) 88 | $(AR) rcs $@ $(OBJ) 89 | $(DIR)/%.o : %.c 90 | $(XCC) -c $< -o $@ $(XFLAGS) 91 | $(DIR)/%.o : %.S 92 | $(XCC) -c $< -o $@ $(XFLAGS) 93 | $(DIR)/%$(EXESUF) : $(TOP)/win32/tools/%.c 94 | $(CC) -o $@ $< $(XFLAGS) $(LDFLAGS) 95 | 96 | $(OBJ) $(XAR) : $(DIR)/exists 97 | $(DIR)/exists : 98 | mkdir -p $(DIR) 99 | @echo $@ > $@ 100 | 101 | clean : 102 | rm -rfv i386-win32 x86_64-win32 i386 x86_64 103 | -------------------------------------------------------------------------------- /tcc/lib/alloca86-bt.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca86-bt.S */ 3 | 4 | .globl __bound_alloca 5 | 6 | __bound_alloca: 7 | pop %edx 8 | pop %eax 9 | mov %eax, %ecx 10 | add $3,%eax 11 | and $-4,%eax 12 | jz p6 13 | 14 | #ifdef TCC_TARGET_PE 15 | p4: 16 | cmp $4096,%eax 17 | jle p5 18 | sub $4096,%esp 19 | sub $4096,%eax 20 | test %eax,(%esp) 21 | jmp p4 22 | 23 | p5: 24 | #endif 25 | 26 | sub %eax,%esp 27 | mov %esp,%eax 28 | 29 | push %edx 30 | push %eax 31 | push %ecx 32 | push %eax 33 | call __bound_new_region 34 | add $8, %esp 35 | pop %eax 36 | pop %edx 37 | 38 | p6: 39 | push %edx 40 | push %edx 41 | ret 42 | 43 | /* mark stack as nonexecutable */ 44 | #if defined __ELF__ && defined __linux__ 45 | .section .note.GNU-stack,"",@progbits 46 | #endif 47 | /* ---------------------------------------------- */ 48 | -------------------------------------------------------------------------------- /tcc/lib/alloca86.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca86.S */ 3 | 4 | .globl alloca 5 | 6 | alloca: 7 | pop %edx 8 | pop %eax 9 | add $3,%eax 10 | and $-4,%eax 11 | jz p3 12 | 13 | #ifdef TCC_TARGET_PE 14 | p1: 15 | cmp $4096,%eax 16 | jle p2 17 | sub $4096,%esp 18 | sub $4096,%eax 19 | test %eax,(%esp) 20 | jmp p1 21 | p2: 22 | #endif 23 | 24 | sub %eax,%esp 25 | mov %esp,%eax 26 | p3: 27 | push %edx 28 | push %edx 29 | ret 30 | 31 | /* mark stack as nonexecutable */ 32 | #if defined __ELF__ && defined __linux__ 33 | .section .note.GNU-stack,"",@progbits 34 | #endif 35 | /* ---------------------------------------------- */ 36 | -------------------------------------------------------------------------------- /tcc/lib/alloca86_64.S: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------- */ 2 | /* alloca86_64.S */ 3 | 4 | .globl alloca 5 | 6 | alloca: 7 | pop %rdx 8 | #ifdef TCC_TARGET_PE 9 | mov %rcx,%rax 10 | #else 11 | mov %rdi,%rax 12 | #endif 13 | add $15,%rax 14 | and $-16,%rax 15 | jz p3 16 | 17 | #ifdef TCC_TARGET_PE 18 | p1: 19 | cmp $4096,%rax 20 | jle p2 21 | sub $4096,%rsp 22 | sub $4096,%rax 23 | test %rax,(%rsp) 24 | jmp p1 25 | p2: 26 | #endif 27 | 28 | sub %rax,%rsp 29 | mov %rsp,%rax 30 | #ifdef TCC_TARGET_PE 31 | add $32,%rax 32 | #endif 33 | 34 | p3: 35 | push %rdx 36 | ret 37 | 38 | /* mark stack as nonexecutable */ 39 | #if defined __ELF__ && defined __linux__ 40 | .section .note.GNU-stack,"",@progbits 41 | #endif 42 | /* ---------------------------------------------- */ 43 | -------------------------------------------------------------------------------- /tcc/stab.h: -------------------------------------------------------------------------------- 1 | #ifndef __GNU_STAB__ 2 | 3 | /* Indicate the GNU stab.h is in use. */ 4 | 5 | #define __GNU_STAB__ 6 | 7 | #define __define_stab(NAME, CODE, STRING) NAME=CODE, 8 | 9 | enum __stab_debug_code 10 | { 11 | #include "stab.def" 12 | LAST_UNUSED_STAB_CODE 13 | }; 14 | 15 | #undef __define_stab 16 | 17 | #endif /* __GNU_STAB_ */ 18 | -------------------------------------------------------------------------------- /tcc/tests/gcctestsuite.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | TESTSUITE_PATH=$HOME/gcc/gcc-3.2/gcc/testsuite/gcc.c-torture 4 | TCC="./tcc -B. -I. -DNO_TRAMPOLINES" 5 | rm -f tcc.sum tcc.log 6 | nb_failed="0" 7 | 8 | for src in $TESTSUITE_PATH/compile/*.c ; do 9 | echo $TCC -o /tmp/test.o -c $src 10 | $TCC -o /tmp/test.o -c $src >> tcc.log 2>&1 11 | if [ "$?" = "0" ] ; then 12 | result="PASS" 13 | else 14 | result="FAIL" 15 | nb_failed=$(( $nb_failed + 1 )) 16 | fi 17 | echo "$result: $src" >> tcc.sum 18 | done 19 | 20 | for src in $TESTSUITE_PATH/execute/*.c ; do 21 | echo $TCC $src 22 | $TCC $src >> tcc.log 2>&1 23 | if [ "$?" = "0" ] ; then 24 | result="PASS" 25 | else 26 | result="FAIL" 27 | nb_failed=$(( $nb_failed + 1 )) 28 | fi 29 | echo "$result: $src" >> tcc.sum 30 | done 31 | 32 | echo "$nb_failed test(s) failed." >> tcc.sum 33 | echo "$nb_failed test(s) failed." 34 | -------------------------------------------------------------------------------- /tcc/tests/libtcc_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Simple Test program for libtcc 3 | * 4 | * libtcc can be useful to use tcc as a "backend" for a code generator. 5 | */ 6 | #include 7 | #include 8 | #include 9 | 10 | #include "libtcc.h" 11 | 12 | /* this function is called by the generated code */ 13 | int add(int a, int b) 14 | { 15 | return a + b; 16 | } 17 | 18 | char my_program[] = 19 | "int fib(int n)\n" 20 | "{\n" 21 | " if (n <= 2)\n" 22 | " return 1;\n" 23 | " else\n" 24 | " return fib(n-1) + fib(n-2);\n" 25 | "}\n" 26 | "\n" 27 | "int foo(int n)\n" 28 | "{\n" 29 | " printf(\"Hello World!\\n\");\n" 30 | " printf(\"fib(%d) = %d\\n\", n, fib(n));\n" 31 | " printf(\"add(%d, %d) = %d\\n\", n, 2 * n, add(n, 2 * n));\n" 32 | " return 0;\n" 33 | "}\n"; 34 | 35 | int main(int argc, char **argv) 36 | { 37 | TCCState *s; 38 | int (*func)(int); 39 | 40 | s = tcc_new(); 41 | if (!s) { 42 | fprintf(stderr, "Could not create tcc state\n"); 43 | exit(1); 44 | } 45 | 46 | /* if tcclib.h and libtcc1.a are not installed, where can we find them */ 47 | if (argc == 2 && !memcmp(argv[1], "lib_path=",9)) 48 | tcc_set_lib_path(s, argv[1]+9); 49 | 50 | /* MUST BE CALLED before any compilation */ 51 | tcc_set_output_type(s, TCC_OUTPUT_MEMORY); 52 | 53 | if (tcc_compile_string(s, my_program) == -1) 54 | return 1; 55 | 56 | /* as a test, we add a symbol that the compiled program can use. 57 | You may also open a dll with tcc_add_dll() and use symbols from that */ 58 | tcc_add_symbol(s, "add", add); 59 | 60 | /* relocate the code */ 61 | if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0) 62 | return 1; 63 | 64 | /* get entry symbol */ 65 | func = tcc_get_symbol(s, "foo"); 66 | if (!func) 67 | return 1; 68 | 69 | /* run the code */ 70 | func(32); 71 | 72 | /* delete the state */ 73 | tcc_delete(s); 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /tcc/tests/tests2/00_assignment.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | a = 42; 7 | printf("%d\n", a); 8 | 9 | int b = 64; 10 | printf("%d\n", b); 11 | 12 | int c = 12, d = 34; 13 | printf("%d, %d\n", c, d); 14 | 15 | return 0; 16 | } 17 | 18 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 19 | -------------------------------------------------------------------------------- /tcc/tests/tests2/00_assignment.expect: -------------------------------------------------------------------------------- 1 | 42 2 | 64 3 | 12, 34 4 | -------------------------------------------------------------------------------- /tcc/tests/tests2/01_comment.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("Hello\n"); 6 | printf("Hello\n"); /* this is a comment */ printf("Hello\n"); 7 | printf("Hello\n"); 8 | // this is also a comment sayhello(); 9 | printf("Hello\n"); 10 | 11 | return 0; 12 | } 13 | 14 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 15 | -------------------------------------------------------------------------------- /tcc/tests/tests2/01_comment.expect: -------------------------------------------------------------------------------- 1 | Hello 2 | Hello 3 | Hello 4 | Hello 5 | Hello 6 | -------------------------------------------------------------------------------- /tcc/tests/tests2/02_printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("Hello world\n"); 6 | 7 | int Count; 8 | for (Count = -5; Count <= 5; Count++) 9 | printf("Count = %d\n", Count); 10 | 11 | printf("String 'hello', 'there' is '%s', '%s'\n", "hello", "there"); 12 | printf("Character 'A' is '%c'\n", 65); 13 | printf("Character 'a' is '%c'\n", 'a'); 14 | 15 | return 0; 16 | } 17 | 18 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 19 | -------------------------------------------------------------------------------- /tcc/tests/tests2/02_printf.expect: -------------------------------------------------------------------------------- 1 | Hello world 2 | Count = -5 3 | Count = -4 4 | Count = -3 5 | Count = -2 6 | Count = -1 7 | Count = 0 8 | Count = 1 9 | Count = 2 10 | Count = 3 11 | Count = 4 12 | Count = 5 13 | String 'hello', 'there' is 'hello', 'there' 14 | Character 'A' is 'A' 15 | Character 'a' is 'a' 16 | -------------------------------------------------------------------------------- /tcc/tests/tests2/03_struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct fred 4 | { 5 | int boris; 6 | int natasha; 7 | }; 8 | 9 | void main() 10 | { 11 | struct fred bloggs; 12 | 13 | bloggs.boris = 12; 14 | bloggs.natasha = 34; 15 | 16 | printf("%d\n", bloggs.boris); 17 | printf("%d\n", bloggs.natasha); 18 | 19 | struct fred jones[2]; 20 | jones[0].boris = 12; 21 | jones[0].natasha = 34; 22 | jones[1].boris = 56; 23 | jones[1].natasha = 78; 24 | 25 | printf("%d\n", jones[0].boris); 26 | printf("%d\n", jones[0].natasha); 27 | printf("%d\n", jones[1].boris); 28 | printf("%d\n", jones[1].natasha); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /tcc/tests/tests2/03_struct.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 12 4 | 34 5 | 56 6 | 78 7 | -------------------------------------------------------------------------------- /tcc/tests/tests2/04_for.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | for (Count = 1; Count <= 10; Count++) 8 | { 9 | printf("%d\n", Count); 10 | } 11 | 12 | return 0; 13 | } 14 | 15 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 16 | -------------------------------------------------------------------------------- /tcc/tests/tests2/04_for.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /tcc/tests/tests2/05_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | int Array[10]; 7 | 8 | for (Count = 1; Count <= 10; Count++) 9 | { 10 | Array[Count-1] = Count * Count; 11 | } 12 | 13 | for (Count = 0; Count < 10; Count++) 14 | { 15 | printf("%d\n", Array[Count]); 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 22 | -------------------------------------------------------------------------------- /tcc/tests/tests2/05_array.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 9 4 | 16 5 | 25 6 | 36 7 | 49 8 | 64 9 | 81 10 | 100 11 | -------------------------------------------------------------------------------- /tcc/tests/tests2/06_case.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | for (Count = 0; Count < 4; Count++) 8 | { 9 | printf("%d\n", Count); 10 | switch (Count) 11 | { 12 | case 1: 13 | printf("%d\n", 1); 14 | break; 15 | 16 | case 2: 17 | printf("%d\n", 2); 18 | break; 19 | 20 | default: 21 | printf("%d\n", 0); 22 | break; 23 | } 24 | } 25 | 26 | return 0; 27 | } 28 | 29 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 30 | -------------------------------------------------------------------------------- /tcc/tests/tests2/06_case.expect: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 1 4 | 1 5 | 2 6 | 2 7 | 3 8 | 0 9 | -------------------------------------------------------------------------------- /tcc/tests/tests2/07_function.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int myfunc(int x) 4 | { 5 | return x * x; 6 | } 7 | 8 | void vfunc(int a) 9 | { 10 | printf("a=%d\n", a); 11 | } 12 | 13 | void qfunc() 14 | { 15 | printf("qfunc()\n"); 16 | } 17 | 18 | int main() 19 | { 20 | printf("%d\n", myfunc(3)); 21 | printf("%d\n", myfunc(4)); 22 | 23 | vfunc(1234); 24 | 25 | qfunc(); 26 | 27 | return 0; 28 | } 29 | 30 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 31 | -------------------------------------------------------------------------------- /tcc/tests/tests2/07_function.expect: -------------------------------------------------------------------------------- 1 | 9 2 | 16 3 | a=1234 4 | qfunc() 5 | -------------------------------------------------------------------------------- /tcc/tests/tests2/08_while.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int p; 7 | int t; 8 | 9 | a = 1; 10 | p = 0; 11 | t = 0; 12 | 13 | while (a < 100) 14 | { 15 | printf("%d\n", a); 16 | t = a; 17 | a = t + p; 18 | p = t; 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 25 | -------------------------------------------------------------------------------- /tcc/tests/tests2/08_while.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 2 4 | 3 5 | 5 6 | 8 7 | 13 8 | 21 9 | 34 10 | 55 11 | 89 12 | -------------------------------------------------------------------------------- /tcc/tests/tests2/09_do_while.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int p; 7 | int t; 8 | 9 | a = 1; 10 | p = 0; 11 | t = 0; 12 | 13 | do 14 | { 15 | printf("%d\n", a); 16 | t = a; 17 | a = t + p; 18 | p = t; 19 | } while (a < 100); 20 | 21 | return 0; 22 | } 23 | 24 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 25 | -------------------------------------------------------------------------------- /tcc/tests/tests2/09_do_while.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 2 4 | 3 5 | 5 6 | 8 7 | 13 8 | 21 9 | 34 10 | 55 11 | 89 12 | -------------------------------------------------------------------------------- /tcc/tests/tests2/10_pointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct ziggy 4 | { 5 | int a; 6 | int b; 7 | int c; 8 | } bolshevic; 9 | 10 | int main() 11 | { 12 | int a; 13 | int *b; 14 | int c; 15 | 16 | a = 42; 17 | b = &a; 18 | printf("a = %d\n", *b); 19 | 20 | bolshevic.a = 12; 21 | bolshevic.b = 34; 22 | bolshevic.c = 56; 23 | 24 | printf("bolshevic.a = %d\n", bolshevic.a); 25 | printf("bolshevic.b = %d\n", bolshevic.b); 26 | printf("bolshevic.c = %d\n", bolshevic.c); 27 | 28 | struct ziggy *tsar = &bolshevic; 29 | 30 | printf("tsar->a = %d\n", tsar->a); 31 | printf("tsar->b = %d\n", tsar->b); 32 | printf("tsar->c = %d\n", tsar->c); 33 | 34 | b = &(bolshevic.b); 35 | printf("bolshevic.b = %d\n", *b); 36 | 37 | return 0; 38 | } 39 | 40 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 41 | -------------------------------------------------------------------------------- /tcc/tests/tests2/10_pointer.expect: -------------------------------------------------------------------------------- 1 | a = 42 2 | bolshevic.a = 12 3 | bolshevic.b = 34 4 | bolshevic.c = 56 5 | tsar->a = 12 6 | tsar->b = 34 7 | tsar->c = 56 8 | bolshevic.b = 34 9 | -------------------------------------------------------------------------------- /tcc/tests/tests2/11_precedence.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int b; 7 | int c; 8 | int d; 9 | int e; 10 | int f; 11 | int x; 12 | int y; 13 | 14 | a = 12; 15 | b = 34; 16 | c = 56; 17 | d = 78; 18 | e = 0; 19 | f = 1; 20 | 21 | printf("%d\n", c + d); 22 | printf("%d\n", (y = c + d)); 23 | printf("%d\n", e || e && f); 24 | printf("%d\n", e || f && f); 25 | printf("%d\n", e && e || f); 26 | printf("%d\n", e && f || f); 27 | printf("%d\n", a && f | f); 28 | printf("%d\n", a | b ^ c & d); 29 | printf("%d, %d\n", a == a, a == b); 30 | printf("%d, %d\n", a != a, a != b); 31 | printf("%d\n", a != b && c != d); 32 | printf("%d\n", a + b * c / f); 33 | printf("%d\n", a + b * c / f); 34 | printf("%d\n", (4 << 4)); 35 | printf("%d\n", (64 >> 4)); 36 | 37 | return 0; 38 | } 39 | 40 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 41 | -------------------------------------------------------------------------------- /tcc/tests/tests2/11_precedence.expect: -------------------------------------------------------------------------------- 1 | 134 2 | 134 3 | 0 4 | 1 5 | 1 6 | 1 7 | 1 8 | 46 9 | 1, 0 10 | 0, 1 11 | 1 12 | 1916 13 | 1916 14 | 64 15 | 4 16 | -------------------------------------------------------------------------------- /tcc/tests/tests2/12_hashdefine.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define FRED 12 4 | #define BLOGGS(x) (12*(x)) 5 | 6 | int main() 7 | { 8 | printf("%d\n", FRED); 9 | printf("%d, %d, %d\n", BLOGGS(1), BLOGGS(2), BLOGGS(3)); 10 | 11 | return 0; 12 | } 13 | 14 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 15 | -------------------------------------------------------------------------------- /tcc/tests/tests2/12_hashdefine.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 12, 24, 36 3 | -------------------------------------------------------------------------------- /tcc/tests/tests2/13_integer_literals.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a = 24680; 6 | int b = 01234567; 7 | int c = 0x2468ac; 8 | int d = 0x2468AC; 9 | int e = 0b010101010101; 10 | 11 | printf("%d\n", a); 12 | printf("%d\n", b); 13 | printf("%d\n", c); 14 | printf("%d\n", d); 15 | printf("%d\n", e); 16 | 17 | return 0; 18 | } 19 | 20 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 21 | -------------------------------------------------------------------------------- /tcc/tests/tests2/13_integer_literals.expect: -------------------------------------------------------------------------------- 1 | 24680 2 | 342391 3 | 2386092 4 | 2386092 5 | 1365 6 | -------------------------------------------------------------------------------- /tcc/tests/tests2/14_if.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a = 1; 6 | 7 | if (a) 8 | printf("a is true\n"); 9 | else 10 | printf("a is false\n"); 11 | 12 | int b = 0; 13 | if (b) 14 | printf("b is true\n"); 15 | else 16 | printf("b is false\n"); 17 | 18 | return 0; 19 | } 20 | 21 | // vim: set expandtab ts=4 sw=3 sts=3 tw=80 : 22 | -------------------------------------------------------------------------------- /tcc/tests/tests2/14_if.expect: -------------------------------------------------------------------------------- 1 | a is true 2 | b is false 3 | -------------------------------------------------------------------------------- /tcc/tests/tests2/15_recursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int factorial(int i) 4 | { 5 | if (i < 2) 6 | return i; 7 | else 8 | return i * factorial(i - 1); 9 | } 10 | 11 | int main() 12 | { 13 | int Count; 14 | 15 | for (Count = 1; Count <= 10; Count++) 16 | printf("%d\n", factorial(Count)); 17 | 18 | return 0; 19 | } 20 | 21 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 22 | -------------------------------------------------------------------------------- /tcc/tests/tests2/15_recursion.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 6 4 | 24 5 | 120 6 | 720 7 | 5040 8 | 40320 9 | 362880 10 | 3628800 11 | -------------------------------------------------------------------------------- /tcc/tests/tests2/16_nesting.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int x, y, z; 6 | 7 | for (x = 0; x < 2; x++) 8 | { 9 | for (y = 0; y < 3; y++) 10 | { 11 | for (z = 0; z < 3; z++) 12 | { 13 | printf("%d %d %d\n", x, y, z); 14 | } 15 | } 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 22 | -------------------------------------------------------------------------------- /tcc/tests/tests2/16_nesting.expect: -------------------------------------------------------------------------------- 1 | 0 0 0 2 | 0 0 1 3 | 0 0 2 4 | 0 1 0 5 | 0 1 1 6 | 0 1 2 7 | 0 2 0 8 | 0 2 1 9 | 0 2 2 10 | 1 0 0 11 | 1 0 1 12 | 1 0 2 13 | 1 1 0 14 | 1 1 1 15 | 1 1 2 16 | 1 2 0 17 | 1 2 1 18 | 1 2 2 19 | -------------------------------------------------------------------------------- /tcc/tests/tests2/17_enum.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum fred 4 | { 5 | a, 6 | b, 7 | c, 8 | d, 9 | e = 54, 10 | f = 73, 11 | g, 12 | h 13 | }; 14 | 15 | int main() 16 | { 17 | enum fred frod; 18 | 19 | printf("%d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h); 20 | /* printf("%d\n", frod); */ 21 | frod = 12; 22 | printf("%d\n", frod); 23 | frod = e; 24 | printf("%d\n", frod); 25 | 26 | return 0; 27 | } 28 | 29 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 30 | -------------------------------------------------------------------------------- /tcc/tests/tests2/17_enum.expect: -------------------------------------------------------------------------------- 1 | 0 1 2 3 54 73 74 75 2 | 12 3 | 54 4 | -------------------------------------------------------------------------------- /tcc/tests/tests2/18_include.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("including\n"); 6 | #include "18_include.h" 7 | printf("done\n"); 8 | 9 | return 0; 10 | } 11 | 12 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 13 | -------------------------------------------------------------------------------- /tcc/tests/tests2/18_include.expect: -------------------------------------------------------------------------------- 1 | including 2 | included 3 | done 4 | -------------------------------------------------------------------------------- /tcc/tests/tests2/18_include.h: -------------------------------------------------------------------------------- 1 | printf("included\n"); 2 | -------------------------------------------------------------------------------- /tcc/tests/tests2/19_pointer_arithmetic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int *b; 7 | int *c; 8 | 9 | a = 42; 10 | b = &a; 11 | c = NULL; 12 | 13 | printf("%d\n", *b); 14 | 15 | if (b == NULL) 16 | printf("b is NULL\n"); 17 | else 18 | printf("b is not NULL\n"); 19 | 20 | if (c == NULL) 21 | printf("c is NULL\n"); 22 | else 23 | printf("c is not NULL\n"); 24 | 25 | return 0; 26 | } 27 | 28 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 29 | -------------------------------------------------------------------------------- /tcc/tests/tests2/19_pointer_arithmetic.expect: -------------------------------------------------------------------------------- 1 | 42 2 | b is not NULL 3 | c is NULL 4 | -------------------------------------------------------------------------------- /tcc/tests/tests2/20_pointer_comparison.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | int b; 7 | int *d; 8 | int *e; 9 | d = &a; 10 | e = &b; 11 | a = 12; 12 | b = 34; 13 | printf("%d\n", *d); 14 | printf("%d\n", *e); 15 | printf("%d\n", d == e); 16 | printf("%d\n", d != e); 17 | d = e; 18 | printf("%d\n", d == e); 19 | printf("%d\n", d != e); 20 | 21 | return 0; 22 | } 23 | 24 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 25 | -------------------------------------------------------------------------------- /tcc/tests/tests2/20_pointer_comparison.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 0 4 | 1 5 | 1 6 | 0 7 | -------------------------------------------------------------------------------- /tcc/tests/tests2/21_char_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int x = 'a'; 6 | char y = x; 7 | 8 | char *a = "hello"; 9 | 10 | printf("%s\n", a); 11 | 12 | int c; 13 | c = *a; 14 | 15 | char *b; 16 | for (b = a; *b != 0; b++) 17 | printf("%c: %d\n", *b, *b); 18 | 19 | char destarray[10]; 20 | char *dest = &destarray[0]; 21 | char *src = a; 22 | 23 | while (*src != 0) 24 | *dest++ = *src++; 25 | 26 | *dest = 0; 27 | 28 | printf("copied string is %s\n", destarray); 29 | 30 | return 0; 31 | } 32 | 33 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 34 | -------------------------------------------------------------------------------- /tcc/tests/tests2/21_char_array.expect: -------------------------------------------------------------------------------- 1 | hello 2 | h: 104 3 | e: 101 4 | l: 108 5 | l: 108 6 | o: 111 7 | copied string is hello 8 | -------------------------------------------------------------------------------- /tcc/tests/tests2/22_floating_point.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | // variables 7 | float a = 12.34 + 56.78; 8 | printf("%f\n", a); 9 | 10 | // infix operators 11 | printf("%f\n", 12.34 + 56.78); 12 | printf("%f\n", 12.34 - 56.78); 13 | printf("%f\n", 12.34 * 56.78); 14 | printf("%f\n", 12.34 / 56.78); 15 | 16 | // comparison operators 17 | printf("%d %d %d %d %d %d\n", 12.34 < 56.78, 12.34 <= 56.78, 12.34 == 56.78, 12.34 >= 56.78, 12.34 > 56.78, 12.34 != 56.78); 18 | printf("%d %d %d %d %d %d\n", 12.34 < 12.34, 12.34 <= 12.34, 12.34 == 12.34, 12.34 >= 12.34, 12.34 > 12.34, 12.34 != 12.34); 19 | printf("%d %d %d %d %d %d\n", 56.78 < 12.34, 56.78 <= 12.34, 56.78 == 12.34, 56.78 >= 12.34, 56.78 > 12.34, 56.78 != 12.34); 20 | 21 | // assignment operators 22 | a = 12.34; 23 | a += 56.78; 24 | printf("%f\n", a); 25 | 26 | a = 12.34; 27 | a -= 56.78; 28 | printf("%f\n", a); 29 | 30 | a = 12.34; 31 | a *= 56.78; 32 | printf("%f\n", a); 33 | 34 | a = 12.34; 35 | a /= 56.78; 36 | printf("%f\n", a); 37 | 38 | // prefix operators 39 | printf("%f\n", +12.34); 40 | printf("%f\n", -12.34); 41 | 42 | // type coercion 43 | a = 2; 44 | printf("%f\n", a); 45 | printf("%f\n", sin(2)); 46 | 47 | return 0; 48 | } 49 | 50 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 51 | -------------------------------------------------------------------------------- /tcc/tests/tests2/22_floating_point.expect: -------------------------------------------------------------------------------- 1 | 69.120003 2 | 69.120000 3 | -44.440000 4 | 700.665200 5 | 0.217330 6 | 1 1 0 0 0 1 7 | 0 1 1 1 0 0 8 | 0 0 0 1 1 1 9 | 69.120003 10 | -44.439999 11 | 700.665222 12 | 0.217330 13 | 12.340000 14 | -12.340000 15 | 2.000000 16 | 0.909297 17 | -------------------------------------------------------------------------------- /tcc/tests/tests2/23_type_coercion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void charfunc(char a) 4 | { 5 | printf("char: %c\n", a); 6 | } 7 | 8 | void intfunc(int a) 9 | { 10 | printf("int: %d\n", a); 11 | } 12 | 13 | void floatfunc(float a) 14 | { 15 | printf("float: %f\n", a); 16 | } 17 | 18 | int main() 19 | { 20 | charfunc('a'); 21 | charfunc(98); 22 | charfunc(99.0); 23 | 24 | intfunc('a'); 25 | intfunc(98); 26 | intfunc(99.0); 27 | 28 | floatfunc('a'); 29 | floatfunc(98); 30 | floatfunc(99.0); 31 | 32 | /* printf("%c %d %f\n", 'a', 'b', 'c'); */ 33 | /* printf("%c %d %f\n", 97, 98, 99); */ 34 | /* printf("%c %d %f\n", 97.0, 98.0, 99.0); */ 35 | 36 | char b = 97; 37 | char c = 97.0; 38 | 39 | printf("%d %d\n", b, c); 40 | 41 | int d = 'a'; 42 | int e = 97.0; 43 | 44 | printf("%d %d\n", d, e); 45 | 46 | float f = 'a'; 47 | float g = 97; 48 | 49 | printf("%f %f\n", f, g); 50 | 51 | return 0; 52 | } 53 | 54 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 55 | -------------------------------------------------------------------------------- /tcc/tests/tests2/23_type_coercion.expect: -------------------------------------------------------------------------------- 1 | char: a 2 | char: b 3 | char: c 4 | int: 97 5 | int: 98 6 | int: 99 7 | float: 97.000000 8 | float: 98.000000 9 | float: 99.000000 10 | 97 97 11 | 97 97 12 | 97.000000 97.000000 13 | -------------------------------------------------------------------------------- /tcc/tests/tests2/24_math_library.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("%f\n", sin(0.12)); 7 | printf("%f\n", cos(0.12)); 8 | printf("%f\n", tan(0.12)); 9 | printf("%f\n", asin(0.12)); 10 | printf("%f\n", acos(0.12)); 11 | printf("%f\n", atan(0.12)); 12 | printf("%f\n", sinh(0.12)); 13 | printf("%f\n", cosh(0.12)); 14 | printf("%f\n", tanh(0.12)); 15 | printf("%f\n", exp(0.12)); 16 | printf("%f\n", fabs(-0.12)); 17 | printf("%f\n", log(0.12)); 18 | printf("%f\n", log10(0.12)); 19 | printf("%f\n", pow(0.12, 0.12)); 20 | printf("%f\n", sqrt(0.12)); 21 | printf("%f\n", round(12.34)); 22 | printf("%f\n", ceil(12.34)); 23 | printf("%f\n", floor(12.34)); 24 | 25 | return 0; 26 | } 27 | 28 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 29 | -------------------------------------------------------------------------------- /tcc/tests/tests2/24_math_library.expect: -------------------------------------------------------------------------------- 1 | 0.119712 2 | 0.992809 3 | 0.120579 4 | 0.120290 5 | 1.450506 6 | 0.119429 7 | 0.120288 8 | 1.007209 9 | 0.119427 10 | 1.127497 11 | 0.120000 12 | -2.120264 13 | -0.920819 14 | 0.775357 15 | 0.346410 16 | 12.000000 17 | 13.000000 18 | 12.000000 19 | -------------------------------------------------------------------------------- /tcc/tests/tests2/25_quicksort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int array[16]; 4 | 5 | //Swap integer values by array indexes 6 | void swap(int a, int b) 7 | { 8 | int tmp = array[a]; 9 | array[a] = array[b]; 10 | array[b] = tmp; 11 | } 12 | 13 | //Partition the array into two halves and return the 14 | //index about which the array is partitioned 15 | int partition(int left, int right) 16 | { 17 | int pivotIndex = left; 18 | int pivotValue = array[pivotIndex]; 19 | int index = left; 20 | int i; 21 | 22 | swap(pivotIndex, right); 23 | for(i = left; i < right; i++) 24 | { 25 | if(array[i] < pivotValue) 26 | { 27 | swap(i, index); 28 | index += 1; 29 | } 30 | } 31 | swap(right, index); 32 | 33 | return index; 34 | } 35 | 36 | //Quicksort the array 37 | void quicksort(int left, int right) 38 | { 39 | if(left >= right) 40 | return; 41 | 42 | int index = partition(left, right); 43 | quicksort(left, index - 1); 44 | quicksort(index + 1, right); 45 | } 46 | 47 | int main() 48 | { 49 | int i; 50 | 51 | array[0] = 62; 52 | array[1] = 83; 53 | array[2] = 4; 54 | array[3] = 89; 55 | array[4] = 36; 56 | array[5] = 21; 57 | array[6] = 74; 58 | array[7] = 37; 59 | array[8] = 65; 60 | array[9] = 33; 61 | array[10] = 96; 62 | array[11] = 38; 63 | array[12] = 53; 64 | array[13] = 16; 65 | array[14] = 74; 66 | array[15] = 55; 67 | 68 | for (i = 0; i < 16; i++) 69 | printf("%d ", array[i]); 70 | 71 | printf("\n"); 72 | 73 | quicksort(0, 15); 74 | 75 | for (i = 0; i < 16; i++) 76 | printf("%d ", array[i]); 77 | 78 | printf("\n"); 79 | 80 | return 0; 81 | } 82 | 83 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 84 | -------------------------------------------------------------------------------- /tcc/tests/tests2/25_quicksort.expect: -------------------------------------------------------------------------------- 1 | 62 83 4 89 36 21 74 37 65 33 96 38 53 16 74 55 2 | 4 16 21 33 36 37 38 53 55 62 65 74 74 83 89 96 3 | -------------------------------------------------------------------------------- /tcc/tests/tests2/26_character_constants.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("%d\n", '\1'); 6 | printf("%d\n", '\10'); 7 | printf("%d\n", '\100'); 8 | printf("%d\n", '\x01'); 9 | printf("%d\n", '\x0e'); 10 | printf("%d\n", '\x10'); 11 | printf("%d\n", '\x40'); 12 | printf("test \x40\n"); 13 | 14 | return 0; 15 | } 16 | 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 18 | -------------------------------------------------------------------------------- /tcc/tests/tests2/26_character_constants.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 8 3 | 64 4 | 1 5 | 14 6 | 16 7 | 64 8 | test @ 9 | -------------------------------------------------------------------------------- /tcc/tests/tests2/27_sizeof.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char a; 6 | int b; 7 | double c; 8 | 9 | printf("%d\n", sizeof(a)); 10 | printf("%d\n", sizeof(b)); 11 | printf("%d\n", sizeof(c)); 12 | 13 | return 0; 14 | } 15 | 16 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 17 | -------------------------------------------------------------------------------- /tcc/tests/tests2/27_sizeof.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 8 4 | -------------------------------------------------------------------------------- /tcc/tests/tests2/28_strings.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | char a[10]; 8 | 9 | strcpy(a, "hello"); 10 | printf("%s\n", a); 11 | 12 | strncpy(a, "gosh", 2); 13 | printf("%s\n", a); 14 | 15 | printf("%d\n", strcmp(a, "apple") > 0); 16 | printf("%d\n", strcmp(a, "goere") > 0); 17 | printf("%d\n", strcmp(a, "zebra") < 0); 18 | 19 | printf("%d\n", strlen(a)); 20 | 21 | strcat(a, "!"); 22 | printf("%s\n", a); 23 | 24 | printf("%d\n", strncmp(a, "apple", 2) > 0); 25 | printf("%d\n", strncmp(a, "goere", 2) == 0); 26 | printf("%d\n", strncmp(a, "goerg", 2) == 0); 27 | printf("%d\n", strncmp(a, "zebra", 2) < 0); 28 | 29 | printf("%s\n", index(a, 'o')); 30 | printf("%s\n", rindex(a, 'l')); 31 | printf("%d\n", rindex(a, 'x') == NULL); 32 | 33 | memset(&a[1], 'r', 4); 34 | printf("%s\n", a); 35 | 36 | memcpy(&a[2], a, 2); 37 | printf("%s\n", a); 38 | 39 | printf("%d\n", memcmp(a, "apple", 4) > 0); 40 | printf("%d\n", memcmp(a, "grgr", 4) == 0); 41 | printf("%d\n", memcmp(a, "zebra", 4) < 0); 42 | 43 | return 0; 44 | } 45 | 46 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 47 | -------------------------------------------------------------------------------- /tcc/tests/tests2/28_strings.expect: -------------------------------------------------------------------------------- 1 | hello 2 | gollo 3 | 1 4 | 1 5 | 1 6 | 5 7 | gollo! 8 | 1 9 | 1 10 | 1 11 | 1 12 | ollo! 13 | lo! 14 | 1 15 | grrrr! 16 | grgrr! 17 | 1 18 | 1 19 | 1 20 | -------------------------------------------------------------------------------- /tcc/tests/tests2/29_array_address.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char a[10]; 7 | strcpy(a, "abcdef"); 8 | printf("%s\n", &a[1]); 9 | 10 | return 0; 11 | } 12 | 13 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 14 | -------------------------------------------------------------------------------- /tcc/tests/tests2/29_array_address.expect: -------------------------------------------------------------------------------- 1 | bcdef 2 | -------------------------------------------------------------------------------- /tcc/tests/tests2/30_hanoi.expect: -------------------------------------------------------------------------------- 1 | Solution of Tower of Hanoi Problem with 4 Disks 2 | 3 | Starting state: 4 | A: 1 2 3 4 5 | B: 0 0 0 0 6 | C: 0 0 0 0 7 | ------------------------------------------ 8 | 9 | 10 | Subsequent states: 11 | 12 | A: 0 2 3 4 13 | B: 0 0 0 0 14 | C: 0 0 0 1 15 | ------------------------------------------ 16 | A: 0 0 3 4 17 | B: 0 0 0 2 18 | C: 0 0 0 1 19 | ------------------------------------------ 20 | A: 0 0 3 4 21 | B: 0 0 1 2 22 | C: 0 0 0 0 23 | ------------------------------------------ 24 | A: 0 0 0 4 25 | B: 0 0 1 2 26 | C: 0 0 0 3 27 | ------------------------------------------ 28 | A: 0 0 1 4 29 | B: 0 0 0 2 30 | C: 0 0 0 3 31 | ------------------------------------------ 32 | A: 0 0 1 4 33 | B: 0 0 0 0 34 | C: 0 0 2 3 35 | ------------------------------------------ 36 | A: 0 0 0 4 37 | B: 0 0 0 0 38 | C: 0 1 2 3 39 | ------------------------------------------ 40 | A: 0 0 0 0 41 | B: 0 0 0 4 42 | C: 0 1 2 3 43 | ------------------------------------------ 44 | A: 0 0 0 0 45 | B: 0 0 1 4 46 | C: 0 0 2 3 47 | ------------------------------------------ 48 | A: 0 0 0 2 49 | B: 0 0 1 4 50 | C: 0 0 0 3 51 | ------------------------------------------ 52 | A: 0 0 1 2 53 | B: 0 0 0 4 54 | C: 0 0 0 3 55 | ------------------------------------------ 56 | A: 0 0 1 2 57 | B: 0 0 3 4 58 | C: 0 0 0 0 59 | ------------------------------------------ 60 | A: 0 0 0 2 61 | B: 0 0 3 4 62 | C: 0 0 0 1 63 | ------------------------------------------ 64 | A: 0 0 0 0 65 | B: 0 2 3 4 66 | C: 0 0 0 1 67 | ------------------------------------------ 68 | A: 0 0 0 0 69 | B: 1 2 3 4 70 | C: 0 0 0 0 71 | ------------------------------------------ 72 | -------------------------------------------------------------------------------- /tcc/tests/tests2/31_args.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int Count; 6 | 7 | printf("hello world %d\n", argc); 8 | for (Count = 0; Count < argc; Count++) 9 | printf("arg %d: %s\n", Count, argv[Count]); 10 | 11 | return 0; 12 | } 13 | 14 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 15 | -------------------------------------------------------------------------------- /tcc/tests/tests2/31_args.expect: -------------------------------------------------------------------------------- 1 | hello world 6 2 | arg 0: 31_args.c 3 | arg 1: - 4 | arg 2: arg1 5 | arg 3: arg2 6 | arg 4: arg3 7 | arg 5: arg4 8 | -------------------------------------------------------------------------------- /tcc/tests/tests2/32_led.expect: -------------------------------------------------------------------------------- 1 | _ _ _ _ 2 | | _| _| |_| |_ |_ | 3 | | |_ _| | _| |_| | 4 | 5 | -------------------------------------------------------------------------------- /tcc/tests/tests2/33_ternary_op.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | for (Count = 0; Count < 10; Count++) 8 | { 9 | printf("%d\n", (Count < 5) ? (Count*Count) : (Count * 3)); 10 | } 11 | 12 | return 0; 13 | } 14 | 15 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 16 | -------------------------------------------------------------------------------- /tcc/tests/tests2/33_ternary_op.expect: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 4 4 | 9 5 | 16 6 | 15 7 | 18 8 | 21 9 | 24 10 | 27 11 | -------------------------------------------------------------------------------- /tcc/tests/tests2/34_array_assignment.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a[4]; 6 | 7 | a[0] = 12; 8 | a[1] = 23; 9 | a[2] = 34; 10 | a[3] = 45; 11 | 12 | printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]); 13 | 14 | int b[4]; 15 | 16 | b = a; 17 | 18 | printf("%d %d %d %d\n", b[0], b[1], b[2], b[3]); 19 | 20 | return 0; 21 | } 22 | 23 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 24 | -------------------------------------------------------------------------------- /tcc/tests/tests2/34_array_assignment.expect: -------------------------------------------------------------------------------- 1 | 12 23 34 45 2 | 12 23 34 45 3 | -------------------------------------------------------------------------------- /tcc/tests/tests2/35_sizeof.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char a; 6 | short b; 7 | 8 | printf("%d %d\n", sizeof(char), sizeof(a)); 9 | printf("%d %d\n", sizeof(short), sizeof(b)); 10 | 11 | return 0; 12 | } 13 | 14 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 15 | -------------------------------------------------------------------------------- /tcc/tests/tests2/35_sizeof.expect: -------------------------------------------------------------------------------- 1 | 1 1 2 | 2 2 3 | -------------------------------------------------------------------------------- /tcc/tests/tests2/36_array_initialisers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count; 6 | 7 | int Array[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753 }; 8 | 9 | for (Count = 0; Count < 10; Count++) 10 | printf("%d: %d\n", Count, Array[Count]); 11 | 12 | int Array2[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753, }; 13 | 14 | for (Count = 0; Count < 10; Count++) 15 | printf("%d: %d\n", Count, Array2[Count]); 16 | 17 | 18 | return 0; 19 | } 20 | 21 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 22 | -------------------------------------------------------------------------------- /tcc/tests/tests2/36_array_initialisers.expect: -------------------------------------------------------------------------------- 1 | 0: 12 2 | 1: 34 3 | 2: 56 4 | 3: 78 5 | 4: 90 6 | 5: 123 7 | 6: 456 8 | 7: 789 9 | 8: 8642 10 | 9: 9753 11 | 0: 12 12 | 1: 34 13 | 2: 56 14 | 3: 78 15 | 4: 90 16 | 5: 123 17 | 6: 456 18 | 7: 789 19 | 8: 8642 20 | 9: 9753 21 | -------------------------------------------------------------------------------- /tcc/tests/tests2/37_sprintf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char Buf[100]; 6 | int Count; 7 | 8 | for (Count = 1; Count <= 20; Count++) 9 | { 10 | sprintf(Buf, "->%02d<-\n", Count); 11 | printf("%s", Buf); 12 | } 13 | 14 | return 0; 15 | } 16 | 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 18 | -------------------------------------------------------------------------------- /tcc/tests/tests2/37_sprintf.expect: -------------------------------------------------------------------------------- 1 | ->01<- 2 | ->02<- 3 | ->03<- 4 | ->04<- 5 | ->05<- 6 | ->06<- 7 | ->07<- 8 | ->08<- 9 | ->09<- 10 | ->10<- 11 | ->11<- 12 | ->12<- 13 | ->13<- 14 | ->14<- 15 | ->15<- 16 | ->16<- 17 | ->17<- 18 | ->18<- 19 | ->19<- 20 | ->20<- 21 | -------------------------------------------------------------------------------- /tcc/tests/tests2/38_multiple_array_index.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a[4][4]; 6 | int b = 0; 7 | int x; 8 | int y; 9 | 10 | for (x = 0; x < 4; x++) 11 | { 12 | for (y = 0; y < 4; y++) 13 | { 14 | b++; 15 | a[x][y] = b; 16 | } 17 | } 18 | 19 | for (x = 0; x < 4; x++) 20 | { 21 | printf("x=%d: ", x); 22 | for (y = 0; y < 4; y++) 23 | { 24 | printf("%d ", a[x][y]); 25 | } 26 | printf("\n"); 27 | } 28 | 29 | return 0; 30 | } 31 | 32 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 33 | -------------------------------------------------------------------------------- /tcc/tests/tests2/38_multiple_array_index.expect: -------------------------------------------------------------------------------- 1 | x=0: 1 2 3 4 2 | x=1: 5 6 7 8 3 | x=2: 9 10 11 12 4 | x=3: 13 14 15 16 5 | -------------------------------------------------------------------------------- /tcc/tests/tests2/39_typedef.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef int MyInt; 4 | 5 | struct FunStruct 6 | { 7 | int i; 8 | int j; 9 | }; 10 | 11 | typedef struct FunStruct MyFunStruct; 12 | 13 | typedef MyFunStruct *MoreFunThanEver; 14 | 15 | int main() 16 | { 17 | MyInt a = 1; 18 | printf("%d\n", a); 19 | 20 | MyFunStruct b; 21 | b.i = 12; 22 | b.j = 34; 23 | printf("%d,%d\n", b.i, b.j); 24 | 25 | MoreFunThanEver c = &b; 26 | printf("%d,%d\n", c->i, c->j); 27 | 28 | return 0; 29 | } 30 | 31 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 32 | -------------------------------------------------------------------------------- /tcc/tests/tests2/39_typedef.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 12,34 3 | 12,34 4 | -------------------------------------------------------------------------------- /tcc/tests/tests2/40_stdio.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | FILE *f = fopen("fred.txt", "w"); 6 | fwrite("hello\nhello\n", 1, 12, f); 7 | fclose(f); 8 | 9 | char freddy[7]; 10 | f = fopen("fred.txt", "r"); 11 | if (fread(freddy, 1, 6, f) != 6) 12 | printf("couldn't read fred.txt\n"); 13 | 14 | freddy[6] = '\0'; 15 | fclose(f); 16 | 17 | printf("%s", freddy); 18 | 19 | int InChar; 20 | char ShowChar; 21 | f = fopen("fred.txt", "r"); 22 | while ( (InChar = fgetc(f)) != EOF) 23 | { 24 | ShowChar = InChar; 25 | if (ShowChar < ' ') 26 | ShowChar = '.'; 27 | 28 | printf("ch: %d '%c'\n", InChar, ShowChar); 29 | } 30 | fclose(f); 31 | 32 | f = fopen("fred.txt", "r"); 33 | while ( (InChar = getc(f)) != EOF) 34 | { 35 | ShowChar = InChar; 36 | if (ShowChar < ' ') 37 | ShowChar = '.'; 38 | 39 | printf("ch: %d '%c'\n", InChar, ShowChar); 40 | } 41 | fclose(f); 42 | 43 | f = fopen("fred.txt", "r"); 44 | while (fgets(freddy, sizeof(freddy), f) != NULL) 45 | printf("x: %s", freddy); 46 | 47 | fclose(f); 48 | 49 | return 0; 50 | } 51 | 52 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 53 | -------------------------------------------------------------------------------- /tcc/tests/tests2/40_stdio.expect: -------------------------------------------------------------------------------- 1 | hello 2 | ch: 104 'h' 3 | ch: 101 'e' 4 | ch: 108 'l' 5 | ch: 108 'l' 6 | ch: 111 'o' 7 | ch: 10 '.' 8 | ch: 104 'h' 9 | ch: 101 'e' 10 | ch: 108 'l' 11 | ch: 108 'l' 12 | ch: 111 'o' 13 | ch: 10 '.' 14 | ch: 104 'h' 15 | ch: 101 'e' 16 | ch: 108 'l' 17 | ch: 108 'l' 18 | ch: 111 'o' 19 | ch: 10 '.' 20 | ch: 104 'h' 21 | ch: 101 'e' 22 | ch: 108 'l' 23 | ch: 108 'l' 24 | ch: 111 'o' 25 | ch: 10 '.' 26 | x: hello 27 | x: hello 28 | -------------------------------------------------------------------------------- /tcc/tests/tests2/41_hashif.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("#include test\n"); 6 | 7 | #if 1 8 | #if 0 9 | printf("a\n"); 10 | #else 11 | printf("b\n"); 12 | #endif 13 | #else 14 | #if 0 15 | printf("c\n"); 16 | #else 17 | printf("d\n"); 18 | #endif 19 | #endif 20 | 21 | #if 0 22 | #if 1 23 | printf("e\n"); 24 | #else 25 | printf("f\n"); 26 | #endif 27 | #else 28 | #if 1 29 | printf("g\n"); 30 | #else 31 | printf("h\n"); 32 | #endif 33 | #endif 34 | 35 | #define DEF 36 | 37 | #ifdef DEF 38 | #ifdef DEF 39 | printf("i\n"); 40 | #else 41 | printf("j\n"); 42 | #endif 43 | #else 44 | #ifdef DEF 45 | printf("k\n"); 46 | #else 47 | printf("l\n"); 48 | #endif 49 | #endif 50 | 51 | #ifndef DEF 52 | #ifndef DEF 53 | printf("m\n"); 54 | #else 55 | printf("n\n"); 56 | #endif 57 | #else 58 | #ifndef DEF 59 | printf("o\n"); 60 | #else 61 | printf("p\n"); 62 | #endif 63 | #endif 64 | 65 | #define ONE 1 66 | #define ZERO 0 67 | 68 | #if ONE 69 | #if ZERO 70 | printf("q\n"); 71 | #else 72 | printf("r\n"); 73 | #endif 74 | #else 75 | #if ZERO 76 | printf("s\n"); 77 | #else 78 | printf("t\n"); 79 | #endif 80 | #endif 81 | 82 | return 0; 83 | } 84 | 85 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 86 | -------------------------------------------------------------------------------- /tcc/tests/tests2/41_hashif.expect: -------------------------------------------------------------------------------- 1 | #include test 2 | b 3 | g 4 | i 5 | p 6 | r 7 | -------------------------------------------------------------------------------- /tcc/tests/tests2/42_function_pointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fred(int p) 4 | { 5 | printf("yo %d\n", p); 6 | return 42; 7 | } 8 | 9 | int (*f)(int) = &fred; 10 | 11 | int main() 12 | { 13 | printf("%d\n", (*f)(24)); 14 | 15 | return 0; 16 | } 17 | 18 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 19 | -------------------------------------------------------------------------------- /tcc/tests/tests2/42_function_pointer.expect: -------------------------------------------------------------------------------- 1 | yo 24 2 | 42 3 | -------------------------------------------------------------------------------- /tcc/tests/tests2/43_void_param.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred(void) 4 | { 5 | printf("yo\n"); 6 | } 7 | 8 | int main() 9 | { 10 | fred(); 11 | 12 | return 0; 13 | } 14 | 15 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 16 | -------------------------------------------------------------------------------- /tcc/tests/tests2/43_void_param.expect: -------------------------------------------------------------------------------- 1 | yo 2 | -------------------------------------------------------------------------------- /tcc/tests/tests2/44_scoped_declarations.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | 7 | for (a = 0; a < 2; a++) 8 | { 9 | int b = a; 10 | } 11 | 12 | printf("it's all good\n"); 13 | 14 | return 0; 15 | } 16 | 17 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 18 | -------------------------------------------------------------------------------- /tcc/tests/tests2/44_scoped_declarations.expect: -------------------------------------------------------------------------------- 1 | it's all good 2 | -------------------------------------------------------------------------------- /tcc/tests/tests2/45_empty_for.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count = 0; 6 | 7 | for (;;) 8 | { 9 | Count++; 10 | printf("%d\n", Count); 11 | if (Count >= 10) 12 | break; 13 | } 14 | 15 | return 0; 16 | } 17 | 18 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 19 | -------------------------------------------------------------------------------- /tcc/tests/tests2/45_empty_for.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /tcc/tests/tests2/47_switch_return.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred(int x) 4 | { 5 | switch (x) 6 | { 7 | case 1: printf("1\n"); return; 8 | case 2: printf("2\n"); break; 9 | case 3: printf("3\n"); return; 10 | } 11 | 12 | printf("out\n"); 13 | } 14 | 15 | int main() 16 | { 17 | fred(1); 18 | fred(2); 19 | fred(3); 20 | 21 | return 0; 22 | } 23 | 24 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 25 | -------------------------------------------------------------------------------- /tcc/tests/tests2/47_switch_return.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | out 4 | 3 5 | -------------------------------------------------------------------------------- /tcc/tests/tests2/48_nested_break.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | char b; 7 | 8 | a = 0; 9 | while (a < 2) 10 | { 11 | printf("%d", a++); 12 | break; 13 | 14 | b = 'A'; 15 | while (b < 'C') 16 | { 17 | printf("%c", b++); 18 | } 19 | printf("e"); 20 | } 21 | printf("\n"); 22 | 23 | return 0; 24 | } 25 | 26 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 27 | -------------------------------------------------------------------------------- /tcc/tests/tests2/48_nested_break.expect: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /tcc/tests/tests2/49_bracket_evaluation.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct point 4 | { 5 | double x; 6 | double y; 7 | }; 8 | 9 | struct point point_array[100]; 10 | 11 | int main() 12 | { 13 | int my_point = 10; 14 | 15 | point_array[my_point].x = 12.34; 16 | point_array[my_point].y = 56.78; 17 | 18 | printf("%f, %f\n", point_array[my_point].x, point_array[my_point].y); 19 | 20 | return 0; 21 | } 22 | 23 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 24 | -------------------------------------------------------------------------------- /tcc/tests/tests2/49_bracket_evaluation.expect: -------------------------------------------------------------------------------- 1 | 12.340000, 56.780000 2 | -------------------------------------------------------------------------------- /tcc/tests/tests2/50_logical_second_arg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fred() 4 | { 5 | printf("fred\n"); 6 | return 0; 7 | } 8 | 9 | int joe() 10 | { 11 | printf("joe\n"); 12 | return 1; 13 | } 14 | 15 | int main() 16 | { 17 | printf("%d\n", fred() && joe()); 18 | printf("%d\n", fred() || joe()); 19 | printf("%d\n", joe() && fred()); 20 | printf("%d\n", joe() || fred()); 21 | printf("%d\n", fred() && (1 + joe())); 22 | printf("%d\n", fred() || (0 + joe())); 23 | printf("%d\n", joe() && (0 + fred())); 24 | printf("%d\n", joe() || (1 + fred())); 25 | 26 | return 0; 27 | } 28 | 29 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 30 | -------------------------------------------------------------------------------- /tcc/tests/tests2/50_logical_second_arg.expect: -------------------------------------------------------------------------------- 1 | fred 2 | 0 3 | fred 4 | joe 5 | 1 6 | joe 7 | fred 8 | 0 9 | joe 10 | 1 11 | fred 12 | 0 13 | fred 14 | joe 15 | 1 16 | joe 17 | fred 18 | 0 19 | joe 20 | 1 21 | -------------------------------------------------------------------------------- /tcc/tests/tests2/51_static.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int fred = 1234; 4 | static int joe; 5 | 6 | void henry() 7 | { 8 | static int fred = 4567; 9 | 10 | printf("%d\n", fred); 11 | fred++; 12 | } 13 | 14 | int main() 15 | { 16 | printf("%d\n", fred); 17 | henry(); 18 | henry(); 19 | henry(); 20 | henry(); 21 | printf("%d\n", fred); 22 | fred = 8901; 23 | joe = 2345; 24 | printf("%d\n", fred); 25 | printf("%d\n", joe); 26 | 27 | return 0; 28 | } 29 | 30 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 31 | -------------------------------------------------------------------------------- /tcc/tests/tests2/51_static.expect: -------------------------------------------------------------------------------- 1 | 1234 2 | 4567 3 | 4568 4 | 4569 5 | 4570 6 | 1234 7 | 8901 8 | 2345 9 | -------------------------------------------------------------------------------- /tcc/tests/tests2/52_unnamed_enum.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum fred { a, b, c }; 4 | 5 | int main() 6 | { 7 | printf("a=%d\n", a); 8 | printf("b=%d\n", b); 9 | printf("c=%d\n", c); 10 | 11 | enum fred d; 12 | 13 | typedef enum { e, f, g } h; 14 | typedef enum { i, j, k } m; 15 | 16 | printf("e=%d\n", e); 17 | printf("f=%d\n", f); 18 | printf("g=%d\n", g); 19 | 20 | printf("i=%d\n", i); 21 | printf("j=%d\n", j); 22 | printf("k=%d\n", k); 23 | 24 | return 0; 25 | } 26 | 27 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 28 | -------------------------------------------------------------------------------- /tcc/tests/tests2/52_unnamed_enum.expect: -------------------------------------------------------------------------------- 1 | a=0 2 | b=1 3 | c=2 4 | e=0 5 | f=1 6 | g=2 7 | i=0 8 | j=1 9 | k=2 10 | -------------------------------------------------------------------------------- /tcc/tests/tests2/54_goto.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred() 4 | { 5 | printf("In fred()\n"); 6 | goto done; 7 | printf("In middle\n"); 8 | done: 9 | printf("At end\n"); 10 | } 11 | 12 | void joe() 13 | { 14 | int b = 5678; 15 | 16 | printf("In joe()\n"); 17 | 18 | { 19 | int c = 1234; 20 | printf("c = %d\n", c); 21 | goto outer; 22 | printf("uh-oh\n"); 23 | } 24 | 25 | outer: 26 | 27 | printf("done\n"); 28 | } 29 | 30 | void henry() 31 | { 32 | int a; 33 | 34 | printf("In henry()\n"); 35 | goto inner; 36 | 37 | { 38 | int b; 39 | inner: 40 | b = 1234; 41 | printf("b = %d\n", b); 42 | } 43 | 44 | printf("done\n"); 45 | } 46 | 47 | int main() 48 | { 49 | fred(); 50 | joe(); 51 | henry(); 52 | 53 | return 0; 54 | } 55 | 56 | /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ 57 | -------------------------------------------------------------------------------- /tcc/tests/tests2/54_goto.expect: -------------------------------------------------------------------------------- 1 | In fred() 2 | At end 3 | In joe() 4 | c = 1234 5 | done 6 | In henry() 7 | b = 1234 8 | done 9 | -------------------------------------------------------------------------------- /tcc/tests/tests2/55_lshift_type.c: -------------------------------------------------------------------------------- 1 | /* $Id: lshift-type.c 53089 2012-07-06 11:18:26Z vinc17/ypig $ 2 | 3 | Tests on left-shift type, written by Vincent Lefevre . 4 | 5 | ISO C99 TC3 says: [6.5.7#3] "The integer promotions are performed on 6 | each of the operands. The type of the result is that of the promoted 7 | left operand." 8 | */ 9 | 10 | #include 11 | 12 | #define PTYPE(M) ((M) < 0 || -(M) < 0 ? -1 : 1) * (int) sizeof((M)+0) 13 | #define CHECK(X,T) check(#X, PTYPE(X), PTYPE((X) << (T) 1)) 14 | #define TEST1(X,T) do { CHECK(X,T); CHECK(X,unsigned T); } while (0) 15 | #define TEST2(X) \ 16 | do \ 17 | { \ 18 | TEST1((X),short); \ 19 | TEST1((X),int); \ 20 | TEST1((X),long); \ 21 | TEST1((X),long long); \ 22 | } \ 23 | while (0) 24 | #define TEST3(X,T) do { TEST2((T)(X)); TEST2((unsigned T)(X)); } while (0) 25 | #define TEST4(X) \ 26 | do \ 27 | { \ 28 | TEST3((X),short); \ 29 | TEST3((X),int); \ 30 | TEST3((X),long); \ 31 | TEST3((X),long long); \ 32 | } \ 33 | while (0) 34 | 35 | static int debug, nfailed = 0; 36 | 37 | static void check (const char *s, int arg1, int shift) 38 | { 39 | int failed = arg1 != shift; 40 | if (debug || failed) 41 | printf ("%s %d %d\n", s, arg1, shift); 42 | nfailed += failed; 43 | } 44 | 45 | int main (int argc, char **argv) 46 | { 47 | debug = argc > 1; 48 | TEST4(1); 49 | TEST4(-1); 50 | printf ("%d test(s) failed\n", nfailed); 51 | return nfailed != 0; 52 | } 53 | -------------------------------------------------------------------------------- /tcc/tests/tests2/55_lshift_type.expect: -------------------------------------------------------------------------------- 1 | 0 test(s) failed 2 | -------------------------------------------------------------------------------- /tcc/tests/tests2/LICENSE: -------------------------------------------------------------------------------- 1 | The tests in this directory are either directly copied from the picoc project or 2 | are subsequently modified and added to for the purpose of TinyCC project. All 3 | these modifications are licensed under the same terms as TinyCC as specified in 4 | the file COPYING. 5 | 6 | === picoc license === 7 | 8 | Copyright (c) 2009-2011, Zik Saleeba 9 | All rights reserved. 10 | 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions are 13 | met: 14 | 15 | * Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in 20 | the documentation and/or other materials provided with the 21 | distribution. 22 | 23 | * Neither the name of the Zik Saleeba nor the names of its 24 | contributors may be used to endorse or promote products derived 25 | from this software without specific prior written permission. 26 | 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | -------------------------------------------------------------------------------- /tcc/tests/tests2/Makefile: -------------------------------------------------------------------------------- 1 | TOP = ../.. 2 | include $(TOP)/Makefile 3 | VPATH = $(top_srcdir)/tests/tests2 4 | 5 | TCCFLAGS = -B$(TOP) 6 | ifdef CONFIG_WIN32 7 | TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -L$(TOP) 8 | endif 9 | 10 | ifeq ($(TARGETOS),Darwin) 11 | CFLAGS += -Wl,-flat_namespace,-undefined,warning 12 | TCCFLAGS += -D_ANSI_SOURCE 13 | export MACOSX_DEPLOYMENT_TARGET:=10.2 14 | endif 15 | 16 | TCC_RUN = $(TOP)/tcc $(TCCFLAGS) -run 17 | 18 | TESTS = \ 19 | 00_assignment.test \ 20 | 01_comment.test \ 21 | 02_printf.test \ 22 | 03_struct.test \ 23 | 04_for.test \ 24 | 05_array.test \ 25 | 06_case.test \ 26 | 07_function.test \ 27 | 08_while.test \ 28 | 09_do_while.test \ 29 | 10_pointer.test \ 30 | 11_precedence.test \ 31 | 12_hashdefine.test \ 32 | 13_integer_literals.test \ 33 | 14_if.test \ 34 | 15_recursion.test \ 35 | 16_nesting.test \ 36 | 17_enum.test \ 37 | 18_include.test \ 38 | 19_pointer_arithmetic.test \ 39 | 20_pointer_comparison.test \ 40 | 21_char_array.test \ 41 | 22_floating_point.test \ 42 | 23_type_coercion.test \ 43 | 24_math_library.test \ 44 | 25_quicksort.test \ 45 | 26_character_constants.test \ 46 | 27_sizeof.test \ 47 | 28_strings.test \ 48 | 29_array_address.test \ 49 | 31_args.test \ 50 | 32_led.test \ 51 | 33_ternary_op.test \ 52 | 35_sizeof.test \ 53 | 36_array_initialisers.test \ 54 | 37_sprintf.test \ 55 | 38_multiple_array_index.test \ 56 | 39_typedef.test \ 57 | 40_stdio.test \ 58 | 41_hashif.test \ 59 | 42_function_pointer.test \ 60 | 43_void_param.test \ 61 | 44_scoped_declarations.test \ 62 | 45_empty_for.test \ 63 | 47_switch_return.test \ 64 | 48_nested_break.test \ 65 | 49_bracket_evaluation.test \ 66 | 50_logical_second_arg.test \ 67 | 51_static.test \ 68 | 52_unnamed_enum.test \ 69 | 54_goto.test \ 70 | 55_lshift_type.test 71 | 72 | # 30_hanoi.test -- seg fault in the code, gcc as well 73 | # 34_array_assignment.test -- array assignment is not in C standard 74 | # 46_grep.test -- does not compile even with gcc 75 | 76 | # some tests do not pass on all platforms, remove them for now 77 | ifeq ($(TARGETOS),Darwin) 78 | TESTS := $(filter-out 40_stdio.test,$(TESTS)) 79 | endif 80 | ifdef CONFIG_WIN32 81 | TESTS := $(filter-out 24_math_library.test 28_strings.test,$(TESTS)) 82 | endif 83 | 84 | %.test: %.c %.expect 85 | @echo Test: $*... 86 | @if [ "x`echo $* | grep args`" != "x" ]; \ 87 | then $(TCC_RUN) $< - arg1 arg2 arg3 arg4 >$*.output; \ 88 | else $(TCC_RUN) $< >$*.output; \ 89 | fi 90 | @if diff -bu $(<:.c=.expect) $*.output ; \ 91 | then rm -f $*.output; \ 92 | else exit 1; \ 93 | fi 94 | 95 | all test: $(TESTS) 96 | 97 | clean: 98 | rm -vf fred.txt *.output 99 | -------------------------------------------------------------------------------- /tcc/win32/build-tcc.bat: -------------------------------------------------------------------------------- 1 | @rem ---------------------------------------------------- 2 | @rem batch file to build tcc using mingw gcc 3 | @rem ---------------------------------------------------- 4 | 5 | @set /p VERSION= < ..\VERSION 6 | echo>..\config.h #define TCC_VERSION "%VERSION%" 7 | 8 | @if _%PROCESSOR_ARCHITEW6432%_==_AMD64_ goto x86_64 9 | @if _%PROCESSOR_ARCHITECTURE%_==_AMD64_ goto x86_64 10 | 11 | @set target=-DTCC_TARGET_PE -DTCC_TARGET_I386 12 | @set CC=gcc -Os -s -fno-strict-aliasing 13 | @set P=32 14 | @goto tools 15 | 16 | :x86_64 17 | @set target=-DTCC_TARGET_PE -DTCC_TARGET_X86_64 18 | @rem mingw 64 has an ICE with -Os 19 | @set CC=x86_64-pc-mingw32-gcc -O0 -s -fno-strict-aliasing 20 | @set P=64 21 | @goto tools 22 | 23 | :tools 24 | %CC% %target% tools/tiny_impdef.c -o tiny_impdef.exe 25 | %CC% %target% tools/tiny_libmaker.c -o tiny_libmaker.exe 26 | 27 | :libtcc 28 | if not exist libtcc\nul mkdir libtcc 29 | copy ..\libtcc.h libtcc\libtcc.h 30 | %CC% %target% -shared -DLIBTCC_AS_DLL -DONE_SOURCE ../libtcc.c -o libtcc.dll -Wl,-out-implib,libtcc/libtcc.a 31 | tiny_impdef libtcc.dll -o libtcc/libtcc.def 32 | 33 | :tcc 34 | %CC% %target% ../tcc.c -o tcc.exe -ltcc -Llibtcc 35 | 36 | :copy_std_includes 37 | copy ..\include\*.h include 38 | 39 | :libtcc1.a 40 | .\tcc %target% -c ../lib/libtcc1.c 41 | .\tcc %target% -c lib/crt1.c 42 | .\tcc %target% -c lib/wincrt1.c 43 | .\tcc %target% -c lib/dllcrt1.c 44 | .\tcc %target% -c lib/dllmain.c 45 | .\tcc %target% -c lib/chkstk.S 46 | goto lib%P% 47 | 48 | :lib32 49 | .\tcc %target% -c ../lib/alloca86.S 50 | .\tcc %target% -c ../lib/alloca86-bt.S 51 | .\tcc %target% -c ../lib/bcheck.c 52 | tiny_libmaker lib/libtcc1.a libtcc1.o alloca86.o alloca86-bt.o crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o bcheck.o 53 | @goto the_end 54 | 55 | :lib64 56 | .\tcc %target% -c ../lib/alloca86_64.S 57 | tiny_libmaker lib/libtcc1.a libtcc1.o alloca86_64.o crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o 58 | 59 | :the_end 60 | del *.o 61 | -------------------------------------------------------------------------------- /tcc/win32/examples/dll.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | // 3 | // dll.c - Windows DLL example - dynamically linked part 4 | // 5 | 6 | #include 7 | #define DLL_EXPORT __declspec(dllexport) 8 | 9 | DLL_EXPORT void HelloWorld (void) 10 | { 11 | MessageBox (0, "Hello World!", "From DLL", MB_ICONINFORMATION); 12 | } 13 | -------------------------------------------------------------------------------- /tcc/win32/examples/fib.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fib(n) 4 | { 5 | if (n <= 2) 6 | return 1; 7 | else 8 | return fib(n-1) + fib(n-2); 9 | } 10 | 11 | int main(int argc, char **argv) 12 | { 13 | int n; 14 | if (argc < 2) { 15 | printf("usage: fib n\n" 16 | "Compute nth Fibonacci number\n"); 17 | return 1; 18 | } 19 | 20 | n = atoi(argv[1]); 21 | printf("fib(%d) = %d\n", n, fib(n)); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /tcc/win32/examples/hello_dll.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | // 3 | // HELLO_DLL.C - Windows DLL example - main application part 4 | // 5 | 6 | #include 7 | 8 | void HelloWorld (void); 9 | 10 | int WINAPI WinMain( 11 | HINSTANCE hInstance, 12 | HINSTANCE hPrevInstance, 13 | LPSTR lpCmdLine, 14 | int nCmdShow) 15 | { 16 | HelloWorld(); 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /tcc/win32/include/assert.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef __ASSERT_H_ 7 | #define __ASSERT_H_ 8 | 9 | #include <_mingw.h> 10 | #ifdef __cplusplus 11 | #include 12 | #endif 13 | 14 | #ifdef NDEBUG 15 | #ifndef assert 16 | #define assert(_Expression) ((void)0) 17 | #endif 18 | #else 19 | 20 | #ifndef _CRT_TERMINATE_DEFINED 21 | #define _CRT_TERMINATE_DEFINED 22 | void __cdecl __MINGW_NOTHROW exit(int _Code) __MINGW_ATTRIB_NORETURN; 23 | _CRTIMP void __cdecl __MINGW_NOTHROW _exit(int _Code) __MINGW_ATTRIB_NORETURN; 24 | #if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */ 25 | /* C99 function name */ 26 | void __cdecl _Exit(int) __MINGW_ATTRIB_NORETURN; 27 | __CRT_INLINE __MINGW_ATTRIB_NORETURN void __cdecl _Exit(int status) 28 | { _exit(status); } 29 | #endif 30 | 31 | #pragma push_macro("abort") 32 | #undef abort 33 | void __cdecl __declspec(noreturn) abort(void); 34 | #pragma pop_macro("abort") 35 | 36 | #endif 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | extern void __cdecl _wassert(const wchar_t *_Message,const wchar_t *_File,unsigned _Line); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #ifndef assert 49 | #define assert(_Expression) (void)((!!(_Expression)) || (_wassert(_CRT_WIDE(#_Expression),_CRT_WIDE(__FILE__),__LINE__),0)) 50 | #endif 51 | 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /tcc/win32/include/dir.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * dir.h 8 | * 9 | * This file OBSOLESCENT and only provided for backward compatibility. 10 | * Please use io.h instead. 11 | * 12 | * This file is part of the Mingw32 package. 13 | * 14 | * Contributors: 15 | * Created by Colin Peters 16 | * Mumit Khan 17 | * 18 | * THIS SOFTWARE IS NOT COPYRIGHTED 19 | * 20 | * This source code is offered for use in the public domain. You may 21 | * use, modify or distribute it freely. 22 | * 23 | * This code is distributed in the hope that it will be useful but 24 | * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY 25 | * DISCLAIMED. This includes but is not limited to warranties of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 27 | * 28 | */ 29 | 30 | #include 31 | 32 | -------------------------------------------------------------------------------- /tcc/win32/include/direct.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_DIRECT 7 | #define _INC_DIRECT 8 | 9 | #include <_mingw.h> 10 | #include 11 | 12 | #pragma pack(push,_CRT_PACKING) 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #ifndef _DISKFREE_T_DEFINED 19 | #define _DISKFREE_T_DEFINED 20 | struct _diskfree_t { 21 | unsigned total_clusters; 22 | unsigned avail_clusters; 23 | unsigned sectors_per_cluster; 24 | unsigned bytes_per_sector; 25 | }; 26 | #endif 27 | 28 | _CRTIMP char *__cdecl _getcwd(char *_DstBuf,int _SizeInBytes); 29 | _CRTIMP char *__cdecl _getdcwd(int _Drive,char *_DstBuf,int _SizeInBytes); 30 | char *__cdecl _getdcwd_nolock(int _Drive,char *_DstBuf,int _SizeInBytes); 31 | _CRTIMP int __cdecl _chdir(const char *_Path); 32 | _CRTIMP int __cdecl _mkdir(const char *_Path); 33 | _CRTIMP int __cdecl _rmdir(const char *_Path); 34 | _CRTIMP int __cdecl _chdrive(int _Drive); 35 | _CRTIMP int __cdecl _getdrive(void); 36 | _CRTIMP unsigned long __cdecl _getdrives(void); 37 | 38 | #ifndef _GETDISKFREE_DEFINED 39 | #define _GETDISKFREE_DEFINED 40 | _CRTIMP unsigned __cdecl _getdiskfree(unsigned _Drive,struct _diskfree_t *_DiskFree); 41 | #endif 42 | 43 | #ifndef _WDIRECT_DEFINED 44 | #define _WDIRECT_DEFINED 45 | _CRTIMP wchar_t *__cdecl _wgetcwd(wchar_t *_DstBuf,int _SizeInWords); 46 | _CRTIMP wchar_t *__cdecl _wgetdcwd(int _Drive,wchar_t *_DstBuf,int _SizeInWords); 47 | wchar_t *__cdecl _wgetdcwd_nolock(int _Drive,wchar_t *_DstBuf,int _SizeInWords); 48 | _CRTIMP int __cdecl _wchdir(const wchar_t *_Path); 49 | _CRTIMP int __cdecl _wmkdir(const wchar_t *_Path); 50 | _CRTIMP int __cdecl _wrmdir(const wchar_t *_Path); 51 | #endif 52 | 53 | #ifndef NO_OLDNAMES 54 | 55 | #define diskfree_t _diskfree_t 56 | 57 | char *__cdecl getcwd(char *_DstBuf,int _SizeInBytes); 58 | int __cdecl chdir(const char *_Path); 59 | int __cdecl mkdir(const char *_Path); 60 | int __cdecl rmdir(const char *_Path); 61 | #endif 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #pragma pack(pop) 68 | #endif 69 | -------------------------------------------------------------------------------- /tcc/win32/include/dos.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_DOS 7 | #define _INC_DOS 8 | 9 | #include <_mingw.h> 10 | #include 11 | 12 | #pragma pack(push,_CRT_PACKING) 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #ifndef _DISKFREE_T_DEFINED 19 | #define _DISKFREE_T_DEFINED 20 | 21 | struct _diskfree_t { 22 | unsigned total_clusters; 23 | unsigned avail_clusters; 24 | unsigned sectors_per_cluster; 25 | unsigned bytes_per_sector; 26 | }; 27 | #endif 28 | 29 | #define _A_NORMAL 0x00 30 | #define _A_RDONLY 0x01 31 | #define _A_HIDDEN 0x02 32 | #define _A_SYSTEM 0x04 33 | #define _A_SUBDIR 0x10 34 | #define _A_ARCH 0x20 35 | 36 | #ifndef _GETDISKFREE_DEFINED 37 | #define _GETDISKFREE_DEFINED 38 | _CRTIMP unsigned __cdecl _getdiskfree(unsigned _Drive,struct _diskfree_t *_DiskFree); 39 | #endif 40 | 41 | #if (defined(_X86_) && !defined(__x86_64)) 42 | void __cdecl _disable(void); 43 | void __cdecl _enable(void); 44 | #endif 45 | 46 | #ifndef NO_OLDNAMES 47 | #define diskfree_t _diskfree_t 48 | #endif 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #pragma pack(pop) 55 | #endif 56 | -------------------------------------------------------------------------------- /tcc/win32/include/errno.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_ERRNO 7 | #define _INC_ERRNO 8 | 9 | #include <_mingw.h> 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #ifndef _CRT_ERRNO_DEFINED 16 | #define _CRT_ERRNO_DEFINED 17 | _CRTIMP extern int *__cdecl _errno(void); 18 | #define errno (*_errno()) 19 | 20 | errno_t __cdecl _set_errno(int _Value); 21 | errno_t __cdecl _get_errno(int *_Value); 22 | #endif 23 | 24 | #define EPERM 1 25 | #define ENOENT 2 26 | #define ESRCH 3 27 | #define EINTR 4 28 | #define EIO 5 29 | #define ENXIO 6 30 | #define E2BIG 7 31 | #define ENOEXEC 8 32 | #define EBADF 9 33 | #define ECHILD 10 34 | #define EAGAIN 11 35 | #define ENOMEM 12 36 | #define EACCES 13 37 | #define EFAULT 14 38 | #define EBUSY 16 39 | #define EEXIST 17 40 | #define EXDEV 18 41 | #define ENODEV 19 42 | #define ENOTDIR 20 43 | #define EISDIR 21 44 | #define ENFILE 23 45 | #define EMFILE 24 46 | #define ENOTTY 25 47 | #define EFBIG 27 48 | #define ENOSPC 28 49 | #define ESPIPE 29 50 | #define EROFS 30 51 | #define EMLINK 31 52 | #define EPIPE 32 53 | #define EDOM 33 54 | #define EDEADLK 36 55 | #define ENAMETOOLONG 38 56 | #define ENOLCK 39 57 | #define ENOSYS 40 58 | #define ENOTEMPTY 41 59 | 60 | #ifndef RC_INVOKED 61 | #if !defined(_SECURECRT_ERRCODE_VALUES_DEFINED) 62 | #define _SECURECRT_ERRCODE_VALUES_DEFINED 63 | #define EINVAL 22 64 | #define ERANGE 34 65 | #define EILSEQ 42 66 | #define STRUNCATE 80 67 | #endif 68 | #endif 69 | 70 | #define EDEADLOCK EDEADLK 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | #endif 76 | -------------------------------------------------------------------------------- /tcc/win32/include/fcntl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #include <_mingw.h> 7 | 8 | #include 9 | 10 | #ifndef _INC_FCNTL 11 | #define _INC_FCNTL 12 | 13 | #define _O_RDONLY 0x0000 14 | #define _O_WRONLY 0x0001 15 | #define _O_RDWR 0x0002 16 | #define _O_APPEND 0x0008 17 | #define _O_CREAT 0x0100 18 | #define _O_TRUNC 0x0200 19 | #define _O_EXCL 0x0400 20 | #define _O_TEXT 0x4000 21 | #define _O_BINARY 0x8000 22 | #define _O_WTEXT 0x10000 23 | #define _O_U16TEXT 0x20000 24 | #define _O_U8TEXT 0x40000 25 | #define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR) 26 | 27 | #define _O_RAW _O_BINARY 28 | #define _O_NOINHERIT 0x0080 29 | #define _O_TEMPORARY 0x0040 30 | #define _O_SHORT_LIVED 0x1000 31 | 32 | #define _O_SEQUENTIAL 0x0020 33 | #define _O_RANDOM 0x0010 34 | 35 | #if !defined(NO_OLDNAMES) || defined(_POSIX) 36 | #define O_RDONLY _O_RDONLY 37 | #define O_WRONLY _O_WRONLY 38 | #define O_RDWR _O_RDWR 39 | #define O_APPEND _O_APPEND 40 | #define O_CREAT _O_CREAT 41 | #define O_TRUNC _O_TRUNC 42 | #define O_EXCL _O_EXCL 43 | #define O_TEXT _O_TEXT 44 | #define O_BINARY _O_BINARY 45 | #define O_RAW _O_BINARY 46 | #define O_TEMPORARY _O_TEMPORARY 47 | #define O_NOINHERIT _O_NOINHERIT 48 | #define O_SEQUENTIAL _O_SEQUENTIAL 49 | #define O_RANDOM _O_RANDOM 50 | #define O_ACCMODE _O_ACCMODE 51 | #endif 52 | #endif 53 | -------------------------------------------------------------------------------- /tcc/win32/include/locale.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_LOCALE 7 | #define _INC_LOCALE 8 | 9 | #include <_mingw.h> 10 | 11 | #pragma pack(push,_CRT_PACKING) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #ifndef NULL 18 | #ifdef __cplusplus 19 | #define NULL 0 20 | #else 21 | #define NULL ((void *)0) 22 | #endif 23 | #endif 24 | 25 | #define LC_ALL 0 26 | #define LC_COLLATE 1 27 | #define LC_CTYPE 2 28 | #define LC_MONETARY 3 29 | #define LC_NUMERIC 4 30 | #define LC_TIME 5 31 | 32 | #define LC_MIN LC_ALL 33 | #define LC_MAX LC_TIME 34 | 35 | #ifndef _LCONV_DEFINED 36 | #define _LCONV_DEFINED 37 | struct lconv { 38 | char *decimal_point; 39 | char *thousands_sep; 40 | char *grouping; 41 | char *int_curr_symbol; 42 | char *currency_symbol; 43 | char *mon_decimal_point; 44 | char *mon_thousands_sep; 45 | char *mon_grouping; 46 | char *positive_sign; 47 | char *negative_sign; 48 | char int_frac_digits; 49 | char frac_digits; 50 | char p_cs_precedes; 51 | char p_sep_by_space; 52 | char n_cs_precedes; 53 | char n_sep_by_space; 54 | char p_sign_posn; 55 | char n_sign_posn; 56 | }; 57 | #endif 58 | 59 | #ifndef _CONFIG_LOCALE_SWT 60 | #define _CONFIG_LOCALE_SWT 61 | 62 | #define _ENABLE_PER_THREAD_LOCALE 0x1 63 | #define _DISABLE_PER_THREAD_LOCALE 0x2 64 | #define _ENABLE_PER_THREAD_LOCALE_GLOBAL 0x10 65 | #define _DISABLE_PER_THREAD_LOCALE_GLOBAL 0x20 66 | #define _ENABLE_PER_THREAD_LOCALE_NEW 0x100 67 | #define _DISABLE_PER_THREAD_LOCALE_NEW 0x200 68 | 69 | #endif 70 | 71 | int __cdecl _configthreadlocale(int _Flag); 72 | char *__cdecl setlocale(int _Category,const char *_Locale); 73 | _CRTIMP struct lconv *__cdecl localeconv(void); 74 | _locale_t __cdecl _get_current_locale(void); 75 | _locale_t __cdecl _create_locale(int _Category,const char *_Locale); 76 | void __cdecl _free_locale(_locale_t _Locale); 77 | _locale_t __cdecl __get_current_locale(void); 78 | _locale_t __cdecl __create_locale(int _Category,const char *_Locale); 79 | void __cdecl __free_locale(_locale_t _Locale); 80 | 81 | #ifndef _WLOCALE_DEFINED 82 | #define _WLOCALE_DEFINED 83 | _CRTIMP wchar_t *__cdecl _wsetlocale(int _Category,const wchar_t *_Locale); 84 | #endif 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #pragma pack(pop) 91 | #endif 92 | -------------------------------------------------------------------------------- /tcc/win32/include/mem.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * This file is part of the Mingw32 package. 8 | * 9 | * mem.h maps to string.h 10 | */ 11 | #ifndef __STRICT_ANSI__ 12 | #include 13 | #endif 14 | -------------------------------------------------------------------------------- /tcc/win32/include/memory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_MEMORY 7 | #define _INC_MEMORY 8 | 9 | #include <_mingw.h> 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #ifndef _CONST_RETURN 16 | #define _CONST_RETURN 17 | #endif 18 | 19 | #define _WConst_return _CONST_RETURN 20 | 21 | #ifndef _CRT_MEMORY_DEFINED 22 | #define _CRT_MEMORY_DEFINED 23 | _CRTIMP void *__cdecl _memccpy(void *_Dst,const void *_Src,int _Val,size_t _MaxCount); 24 | _CONST_RETURN void *__cdecl memchr(const void *_Buf ,int _Val,size_t _MaxCount); 25 | _CRTIMP int __cdecl _memicmp(const void *_Buf1,const void *_Buf2,size_t _Size); 26 | _CRTIMP int __cdecl _memicmp_l(const void *_Buf1,const void *_Buf2,size_t _Size,_locale_t _Locale); 27 | int __cdecl memcmp(const void *_Buf1,const void *_Buf2,size_t _Size); 28 | void *__cdecl memcpy(void *_Dst,const void *_Src,size_t _Size); 29 | void *__cdecl memset(void *_Dst,int _Val,size_t _Size); 30 | 31 | #ifndef NO_OLDNAMES 32 | void *__cdecl memccpy(void *_Dst,const void *_Src,int _Val,size_t _Size); 33 | int __cdecl memicmp(const void *_Buf1,const void *_Buf2,size_t _Size); 34 | #endif 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | #endif 41 | -------------------------------------------------------------------------------- /tcc/win32/include/sec_api/conio_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #ifndef _INC_CONIO_S 8 | #define _INC_CONIO_S 9 | 10 | #include 11 | 12 | #if defined(MINGW_HAS_SECURE_API) 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | _CRTIMP errno_t __cdecl _cgets_s(char *_Buffer,size_t _Size,size_t *_SizeRead); 19 | _CRTIMP int __cdecl _cprintf_s(const char *_Format,...); 20 | _CRTIMP int __cdecl _cscanf_s(const char *_Format,...); 21 | _CRTIMP int __cdecl _cscanf_s_l(const char *_Format,_locale_t _Locale,...); 22 | _CRTIMP int __cdecl _vcprintf_s(const char *_Format,va_list _ArgList); 23 | _CRTIMP int __cdecl _cprintf_s_l(const char *_Format,_locale_t _Locale,...); 24 | _CRTIMP int __cdecl _vcprintf_s_l(const char *_Format,_locale_t _Locale,va_list _ArgList); 25 | 26 | #ifndef _WCONIO_DEFINED_S 27 | #define _WCONIO_DEFINED_S 28 | _CRTIMP errno_t __cdecl _cgetws_s(wchar_t *_Buffer,size_t _SizeInWords,size_t *_SizeRead); 29 | _CRTIMP int __cdecl _cwprintf_s(const wchar_t *_Format,...); 30 | _CRTIMP int __cdecl _cwscanf_s(const wchar_t *_Format,...); 31 | _CRTIMP int __cdecl _cwscanf_s_l(const wchar_t *_Format,_locale_t _Locale,...); 32 | _CRTIMP int __cdecl _vcwprintf_s(const wchar_t *_Format,va_list _ArgList); 33 | _CRTIMP int __cdecl _cwprintf_s_l(const wchar_t *_Format,_locale_t _Locale,...); 34 | _CRTIMP int __cdecl _vcwprintf_s_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | #endif 43 | -------------------------------------------------------------------------------- /tcc/win32/include/sec_api/crtdbg_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #ifndef _INC_CRTDBG_S 8 | #define _INC_CRTDBG_S 9 | 10 | #include 11 | 12 | #if defined(MINGW_HAS_SECURE_API) 13 | 14 | #define _dupenv_s_dbg(ps1,size,s2,t,f,l) _dupenv_s(ps1,size,s2) 15 | #define _wdupenv_s_dbg(ps1,size,s2,t,f,l) _wdupenv_s(ps1,size,s2) 16 | 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /tcc/win32/include/sec_api/io_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_IO_S 7 | #define _INC_IO_S 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | _CRTIMP errno_t __cdecl _access_s(const char *_Filename,int _AccessMode); 18 | _CRTIMP errno_t __cdecl _chsize_s(int _FileHandle,__int64 _Size); 19 | _CRTIMP errno_t __cdecl _mktemp_s(char *_TemplateName,size_t _Size); 20 | _CRTIMP errno_t __cdecl _umask_s(int _NewMode,int *_OldMode); 21 | 22 | #ifndef _WIO_S_DEFINED 23 | #define _WIO_S_DEFINED 24 | _CRTIMP errno_t __cdecl _waccess_s(const wchar_t *_Filename,int _AccessMode); 25 | _CRTIMP errno_t __cdecl _wmktemp_s(wchar_t *_TemplateName,size_t _SizeInWords); 26 | #endif 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | #endif 34 | -------------------------------------------------------------------------------- /tcc/win32/include/sec_api/search_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_SEARCH_S 7 | #define _INC_SEARCH_S 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | _CRTIMP void *__cdecl _lfind_s(const void *_Key,const void *_Base,unsigned int *_NumOfElements,size_t _SizeOfElements,int (__cdecl *_PtFuncCompare)(void *,const void *,const void *),void *_Context); 18 | _CRTIMP void *__cdecl _lsearch_s(const void *_Key,void *_Base,unsigned int *_NumOfElements,size_t _SizeOfElements,int (__cdecl *_PtFuncCompare)(void *,const void *,const void *),void *_Context); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /tcc/win32/include/sec_api/stralign_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef __STRALIGN_H_S_ 7 | #define __STRALIGN_H_S_ 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #if !defined(I_X86_) && defined(_WSTRING_S_DEFINED) 18 | #if defined(__cplusplus) && defined(_WConst_Return) 19 | static __inline PUWSTR ua_wcscpy_s(PUWSTR Destination,size_t DestinationSize,PCUWSTR Source) { 20 | if(WSTR_ALIGNED(Source) && WSTR_ALIGNED(Destination)) return (wcscpy_s((PWSTR)Destination,DestinationSize,(PCWSTR)Source)==0 ? Destination : NULL); 21 | return uaw_wcscpy((PCUWSTR)String,Character); 22 | } 23 | #endif 24 | #endif 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /tcc/win32/include/sec_api/string_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_STRING_S 7 | #define _INC_STRING_S 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | _CRTIMP errno_t __cdecl _strset_s(char *_Dst,size_t _DstSize,int _Value); 18 | _CRTIMP errno_t __cdecl _strerror_s(char *_Buf,size_t _SizeInBytes,const char *_ErrMsg); 19 | _CRTIMP errno_t __cdecl _strlwr_s(char *_Str,size_t _Size); 20 | _CRTIMP errno_t __cdecl _strlwr_s_l(char *_Str,size_t _Size,_locale_t _Locale); 21 | _CRTIMP errno_t __cdecl _strnset_s(char *_Str,size_t _Size,int _Val,size_t _MaxCount); 22 | _CRTIMP errno_t __cdecl _strupr_s(char *_Str,size_t _Size); 23 | _CRTIMP errno_t __cdecl _strupr_s_l(char *_Str,size_t _Size,_locale_t _Locale); 24 | #ifndef _WSTRING_S_DEFINED 25 | #define _WSTRING_S_DEFINED 26 | _CRTIMP wchar_t *__cdecl wcstok_s(wchar_t *_Str,const wchar_t *_Delim,wchar_t **_Context); 27 | _CRTIMP errno_t __cdecl _wcserror_s(wchar_t *_Buf,size_t _SizeInWords,int _ErrNum); 28 | _CRTIMP errno_t __cdecl __wcserror_s(wchar_t *_Buffer,size_t _SizeInWords,const wchar_t *_ErrMsg); 29 | _CRTIMP errno_t __cdecl _wcsnset_s(wchar_t *_Dst,size_t _DstSizeInWords,wchar_t _Val,size_t _MaxCount); 30 | _CRTIMP errno_t __cdecl _wcsset_s(wchar_t *_Str,size_t _SizeInWords,wchar_t _Val); 31 | _CRTIMP errno_t __cdecl _wcslwr_s(wchar_t *_Str,size_t _SizeInWords); 32 | _CRTIMP errno_t __cdecl _wcslwr_s_l(wchar_t *_Str,size_t _SizeInWords,_locale_t _Locale); 33 | _CRTIMP errno_t __cdecl _wcsupr_s(wchar_t *_Str,size_t _Size); 34 | _CRTIMP errno_t __cdecl _wcsupr_s_l(wchar_t *_Str,size_t _Size,_locale_t _Locale); 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | #endif 41 | #endif 42 | -------------------------------------------------------------------------------- /tcc/win32/include/sec_api/sys/timeb_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #ifndef _TIMEB_H_S 8 | #define _TIMEB_H_S 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #if defined(MINGW_HAS_SECURE_API) 17 | 18 | #ifdef _USE_32BIT_TIME_T 19 | #define _ftime_s _ftime32_s 20 | #else 21 | #define _ftime_s _ftime64_s 22 | #endif 23 | 24 | _CRTIMP errno_t __cdecl _ftime32_s(struct __timeb32 *_Time); 25 | #if _INTEGRAL_MAX_BITS >= 64 26 | _CRTIMP errno_t __cdecl _ftime64_s(struct __timeb64 *_Time); 27 | #endif 28 | #endif 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /tcc/win32/include/sec_api/time_s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _TIME_H__S 7 | #define _TIME_H__S 8 | 9 | #include 10 | 11 | #if defined(MINGW_HAS_SECURE_API) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | _CRTIMP errno_t __cdecl _ctime32_s(char *_Buf,size_t _SizeInBytes,const __time32_t *_Time); 18 | _CRTIMP errno_t __cdecl _gmtime32_s(struct tm *_Tm,const __time32_t *_Time); 19 | _CRTIMP errno_t __cdecl _localtime32_s(struct tm *_Tm,const __time32_t *_Time); 20 | _CRTIMP errno_t __cdecl _strdate_s(char *_Buf,size_t _SizeInBytes); 21 | _CRTIMP errno_t __cdecl _strtime_s(char *_Buf ,size_t _SizeInBytes); 22 | #if _INTEGRAL_MAX_BITS >= 64 23 | _CRTIMP errno_t __cdecl _ctime64_s(char *_Buf,size_t _SizeInBytes,const __time64_t *_Time); 24 | _CRTIMP errno_t __cdecl _gmtime64_s(struct tm *_Tm,const __time64_t *_Time); 25 | _CRTIMP errno_t __cdecl _localtime64_s(struct tm *_Tm,const __time64_t *_Time); 26 | #endif 27 | 28 | #ifndef _WTIME_S_DEFINED 29 | #define _WTIME_S_DEFINED 30 | _CRTIMP errno_t __cdecl _wasctime_s(wchar_t *_Buf,size_t _SizeInWords,const struct tm *_Tm); 31 | _CRTIMP errno_t __cdecl _wctime32_s(wchar_t *_Buf,size_t _SizeInWords,const __time32_t *_Time); 32 | _CRTIMP errno_t __cdecl _wstrdate_s(wchar_t *_Buf,size_t _SizeInWords); 33 | _CRTIMP errno_t __cdecl _wstrtime_s(wchar_t *_Buf,size_t _SizeInWords); 34 | #if _INTEGRAL_MAX_BITS >= 64 35 | _CRTIMP errno_t __cdecl _wctime64_s(wchar_t *_Buf,size_t _SizeInWords,const __time64_t *_Time); 36 | #endif 37 | 38 | #if !defined (RC_INVOKED) && !defined (_INC_WTIME_S_INL) 39 | #define _INC_WTIME_S_INL 40 | #ifdef _USE_32BIT_TIME_T 41 | __CRT_INLINE errno_t __cdecl _wctime_s(wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) { return _wctime32_s(_Buffer,_SizeInWords,_Time); } 42 | #else 43 | __CRT_INLINE errno_t __cdecl _wctime_s(wchar_t *_Buffer,size_t _SizeInWords,const time_t *_Time) { return _wctime64_s(_Buffer,_SizeInWords,_Time); } 44 | #endif 45 | #endif 46 | #endif 47 | 48 | #ifndef RC_INVOKED 49 | #ifdef _USE_32BIT_TIME_T 50 | __CRT_INLINE errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) { return _localtime32_s(_Tm,_Time); } 51 | #else 52 | __CRT_INLINE errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) { return _localtime64_s(_Tm,_Time); } 53 | #endif 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | #endif 62 | -------------------------------------------------------------------------------- /tcc/win32/include/share.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_SHARE 7 | #define _INC_SHARE 8 | 9 | #ifndef _WIN32 10 | #error Only Win32 target is supported! 11 | #endif 12 | 13 | #define _SH_COMPAT 0x00 14 | #define _SH_DENYRW 0x10 15 | #define _SH_DENYWR 0x20 16 | #define _SH_DENYRD 0x30 17 | #define _SH_DENYNO 0x40 18 | #define _SH_SECURE 0x80 19 | 20 | #ifndef NO_OLDNAMES 21 | #define SH_COMPAT _SH_COMPAT 22 | #define SH_DENYRW _SH_DENYRW 23 | #define SH_DENYWR _SH_DENYWR 24 | #define SH_DENYRD _SH_DENYRD 25 | #define SH_DENYNO _SH_DENYNO 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /tcc/win32/include/signal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_SIGNAL 7 | #define _INC_SIGNAL 8 | 9 | #include <_mingw.h> 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #ifndef _SIG_ATOMIC_T_DEFINED 16 | #define _SIG_ATOMIC_T_DEFINED 17 | typedef int sig_atomic_t; 18 | #endif 19 | 20 | #define NSIG 23 21 | 22 | #define SIGHUP 1 /* hangup */ 23 | #define SIGINT 2 24 | #define SIGQUIT 3 /* quit */ 25 | #define SIGILL 4 26 | #define SIGTRAP 5 /* trace trap (not reset when caught) */ 27 | #define SIGIOT 6 /* IOT instruction */ 28 | #define SIGABRT 6 /* used by abort, replace SIGIOT in the future */ 29 | #define SIGEMT 7 /* EMT instruction */ 30 | #define SIGFPE 8 31 | #define SIGKILL 9 /* kill (cannot be caught or ignored) */ 32 | #define SIGBUS 10 /* bus error */ 33 | #define SIGSEGV 11 34 | #define SIGSYS 12 /* bad argument to system call */ 35 | #define SIGPIPE 13 /* write on a pipe with no one to read it */ 36 | #ifdef __USE_MINGW_ALARM 37 | #define SIGALRM 14 /* alarm clock */ 38 | #endif 39 | #define SIGTERM 15 40 | #define SIGBREAK 21 41 | #define SIGABRT2 22 42 | 43 | #define SIGABRT_COMPAT 6 44 | 45 | typedef void (*__p_sig_fn_t)(int); 46 | 47 | #define SIG_DFL (__p_sig_fn_t)0 48 | #define SIG_IGN (__p_sig_fn_t)1 49 | #define SIG_GET (__p_sig_fn_t)2 50 | #define SIG_SGE (__p_sig_fn_t)3 51 | #define SIG_ACK (__p_sig_fn_t)4 52 | #define SIG_ERR (__p_sig_fn_t)-1 53 | 54 | extern void **__cdecl __pxcptinfoptrs(void); 55 | #define _pxcptinfoptrs (*__pxcptinfoptrs()) 56 | 57 | __p_sig_fn_t __cdecl signal(int _SigNum,__p_sig_fn_t _Func); 58 | int __cdecl raise(int _SigNum); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | #endif 64 | -------------------------------------------------------------------------------- /tcc/win32/include/sys/fcntl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * This file is part of the Mingw32 package. 8 | * 9 | * This fcntl.h maps to the root fcntl.h 10 | */ 11 | #ifndef __STRICT_ANSI__ 12 | #include 13 | #endif 14 | -------------------------------------------------------------------------------- /tcc/win32/include/sys/file.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * This file is part of the Mingw32 package. 8 | * 9 | * This file.h maps to the root fcntl.h 10 | * TODO? 11 | */ 12 | #ifndef __STRICT_ANSI__ 13 | #include 14 | #endif 15 | -------------------------------------------------------------------------------- /tcc/win32/include/sys/locking.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_LOCKING 7 | #define _INC_LOCKING 8 | 9 | #ifndef _WIN32 10 | #error Only Win32 target is supported! 11 | #endif 12 | 13 | /* All the headers include this file. */ 14 | #include <_mingw.h> 15 | 16 | #define _LK_UNLCK 0 17 | #define _LK_LOCK 1 18 | #define _LK_NBLCK 2 19 | #define _LK_RLCK 3 20 | #define _LK_NBRLCK 4 21 | 22 | #ifndef NO_OLDNAMES 23 | #define LK_UNLCK _LK_UNLCK 24 | #define LK_LOCK _LK_LOCK 25 | #define LK_NBLCK _LK_NBLCK 26 | #define LK_RLCK _LK_RLCK 27 | #define LK_NBRLCK _LK_NBRLCK 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /tcc/win32/include/sys/time.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #ifndef _SYS_TIME_H_ 8 | #define _SYS_TIME_H_ 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #ifndef __STRICT_ANSI__ 17 | #ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */ 18 | #define _TIMEVAL_DEFINED 19 | struct timeval { 20 | long tv_sec; 21 | long tv_usec; 22 | }; 23 | #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 24 | #define timercmp(tvp, uvp, cmp) \ 25 | (((tvp)->tv_sec != (uvp)->tv_sec) ? \ 26 | ((tvp)->tv_sec cmp (uvp)->tv_sec) : \ 27 | ((tvp)->tv_usec cmp (uvp)->tv_usec)) 28 | #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 29 | #endif /* _TIMEVAL_DEFINED */ 30 | 31 | #ifndef _TIMEZONE_DEFINED /* also in sys/time.h */ 32 | #define _TIMEZONE_DEFINED 33 | /* Provided for compatibility with code that assumes that 34 | the presence of gettimeofday function implies a definition 35 | of struct timezone. */ 36 | struct timezone 37 | { 38 | int tz_minuteswest; /* of Greenwich */ 39 | int tz_dsttime; /* type of dst correction to apply */ 40 | }; 41 | 42 | extern int __cdecl mingw_gettimeofday (struct timeval *p, struct timezone *z); 43 | 44 | #endif 45 | 46 | /* 47 | Implementation as per: 48 | The Open Group Base Specifications, Issue 6 49 | IEEE Std 1003.1, 2004 Edition 50 | 51 | The timezone pointer arg is ignored. Errors are ignored. 52 | */ 53 | #ifndef _GETTIMEOFDAY_DEFINED 54 | #define _GETTIMEOFDAY_DEFINED 55 | int __cdecl gettimeofday(struct timeval *__restrict__, 56 | void *__restrict__ /* tzp (unused) */); 57 | #endif 58 | 59 | #endif /* __STRICT_ANSI__ */ 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | /* Adding timespec definition. */ 66 | #include 67 | 68 | 69 | #endif /* _SYS_TIME_H_ */ 70 | -------------------------------------------------------------------------------- /tcc/win32/include/sys/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_TYPES 7 | #define _INC_TYPES 8 | 9 | #ifndef _WIN32 10 | #error Only Win32 target is supported! 11 | #endif 12 | 13 | #include <_mingw.h> 14 | 15 | #ifndef __TINYC__ //gr 16 | #ifdef _USE_32BIT_TIME_T 17 | #ifdef _WIN64 18 | #undef _USE_32BIT_TIME_T 19 | #endif 20 | #else 21 | #if _INTEGRAL_MAX_BITS < 64 22 | #define _USE_32BIT_TIME_T 23 | #endif 24 | #endif 25 | #endif 26 | 27 | #ifndef _TIME32_T_DEFINED 28 | #define _TIME32_T_DEFINED 29 | typedef long __time32_t; 30 | #endif 31 | 32 | #ifndef _TIME64_T_DEFINED 33 | #define _TIME64_T_DEFINED 34 | #if _INTEGRAL_MAX_BITS >= 64 35 | typedef __int64 __time64_t; 36 | #endif 37 | #endif 38 | 39 | #ifndef _TIME_T_DEFINED 40 | #define _TIME_T_DEFINED 41 | #ifdef _USE_32BIT_TIME_T 42 | typedef __time32_t time_t; 43 | #else 44 | typedef __time64_t time_t; 45 | #endif 46 | #endif 47 | 48 | #ifndef _INO_T_DEFINED 49 | #define _INO_T_DEFINED 50 | typedef unsigned short _ino_t; 51 | #ifndef NO_OLDNAMES 52 | typedef unsigned short ino_t; 53 | #endif 54 | #endif 55 | 56 | #ifndef _DEV_T_DEFINED 57 | #define _DEV_T_DEFINED 58 | typedef unsigned int _dev_t; 59 | #ifndef NO_OLDNAMES 60 | typedef unsigned int dev_t; 61 | #endif 62 | #endif 63 | 64 | #ifndef _PID_T_ 65 | #define _PID_T_ 66 | #ifndef _WIN64 67 | typedef int _pid_t; 68 | #else 69 | typedef __int64 _pid_t; 70 | #endif 71 | 72 | #ifndef NO_OLDNAMES 73 | typedef _pid_t pid_t; 74 | #endif 75 | #endif /* Not _PID_T_ */ 76 | 77 | #ifndef _MODE_T_ 78 | #define _MODE_T_ 79 | typedef unsigned short _mode_t; 80 | 81 | #ifndef NO_OLDNAMES 82 | typedef _mode_t mode_t; 83 | #endif 84 | #endif /* Not _MODE_T_ */ 85 | 86 | #ifndef _OFF_T_DEFINED 87 | #define _OFF_T_DEFINED 88 | #ifndef _OFF_T_ 89 | #define _OFF_T_ 90 | typedef long _off_t; 91 | #if !defined(NO_OLDNAMES) || defined(_POSIX) 92 | typedef long off_t; 93 | #endif 94 | #endif 95 | #endif 96 | 97 | #ifndef _OFF64_T_DEFINED 98 | #define _OFF64_T_DEFINED 99 | typedef long long _off64_t; 100 | #if !defined(NO_OLDNAMES) || defined(_POSIX) 101 | typedef long long off64_t; 102 | #endif 103 | #endif 104 | 105 | #ifndef _TIMESPEC_DEFINED 106 | #define _TIMESPEC_DEFINED 107 | struct timespec { 108 | time_t tv_sec; /* Seconds */ 109 | long tv_nsec; /* Nanoseconds */ 110 | }; 111 | 112 | struct itimerspec { 113 | struct timespec it_interval; /* Timer period */ 114 | struct timespec it_value; /* Timer expiration */ 115 | }; 116 | #endif 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /tcc/win32/include/sys/unistd.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | /* 7 | * This file is part of the Mingw32 package. 8 | * 9 | * unistd.h maps (roughly) to io.h 10 | */ 11 | #ifndef __STRICT_ANSI__ 12 | #include 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /tcc/win32/include/vadefs.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _INC_VADEFS 7 | #define _INC_VADEFS 8 | 9 | //!__TINYC__: GNUC specific stuff removed 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /tcc/win32/include/values.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TODO: Nothing here yet. Should provide UNIX compatibility constants 3 | * comparible to those in limits.h and float.h. 4 | */ 5 | -------------------------------------------------------------------------------- /tcc/win32/include/winapi/intrin.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef __INTRIN_H_ 7 | #define __INTRIN_H_ 8 | 9 | //!__TINYC__: intrinsic stuff removed 10 | 11 | #endif /* end __INTRIN_H_ */ 12 | -------------------------------------------------------------------------------- /tcc/win32/include/winapi/poppack.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(pop) 8 | #endif 9 | -------------------------------------------------------------------------------- /tcc/win32/include/winapi/pshpack1.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(push,1) 8 | #endif 9 | -------------------------------------------------------------------------------- /tcc/win32/include/winapi/pshpack2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(push,2) 8 | #endif 9 | -------------------------------------------------------------------------------- /tcc/win32/include/winapi/pshpack4.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(push,4) 8 | #endif 9 | -------------------------------------------------------------------------------- /tcc/win32/include/winapi/pshpack8.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #if !(defined(lint) || defined(RC_INVOKED)) 7 | #pragma pack(push,8) 8 | #endif 9 | -------------------------------------------------------------------------------- /tcc/win32/include/winapi/specstrings.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | 7 | #define __specstrings 8 | -------------------------------------------------------------------------------- /tcc/win32/include/winapi/tvout.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef __TVOUT__ 7 | #define __TVOUT__ 8 | 9 | #include 10 | 11 | typedef struct _VIDEOPARAMETERS { 12 | GUID Guid; 13 | ULONG dwOffset; 14 | ULONG dwCommand; 15 | ULONG dwFlags; 16 | ULONG dwMode; 17 | ULONG dwTVStandard; 18 | ULONG dwAvailableModes; 19 | ULONG dwAvailableTVStandard; 20 | ULONG dwFlickerFilter; 21 | ULONG dwOverScanX; 22 | ULONG dwOverScanY; 23 | ULONG dwMaxUnscaledX; 24 | ULONG dwMaxUnscaledY; 25 | ULONG dwPositionX; 26 | ULONG dwPositionY; 27 | ULONG dwBrightness; 28 | ULONG dwContrast; 29 | ULONG dwCPType; 30 | ULONG dwCPCommand; 31 | ULONG dwCPStandard; 32 | ULONG dwCPKey; 33 | ULONG bCP_APSTriggerBits; 34 | UCHAR bOEMCopyProtection[256]; 35 | } VIDEOPARAMETERS,*PVIDEOPARAMETERS,*LPVIDEOPARAMETERS; 36 | 37 | #define VP_COMMAND_GET 0x0001 38 | #define VP_COMMAND_SET 0x0002 39 | 40 | #define VP_FLAGS_TV_MODE 0x0001 41 | #define VP_FLAGS_TV_STANDARD 0x0002 42 | #define VP_FLAGS_FLICKER 0x0004 43 | #define VP_FLAGS_OVERSCAN 0x0008 44 | #define VP_FLAGS_MAX_UNSCALED 0x0010 45 | #define VP_FLAGS_POSITION 0x0020 46 | #define VP_FLAGS_BRIGHTNESS 0x0040 47 | #define VP_FLAGS_CONTRAST 0x0080 48 | #define VP_FLAGS_COPYPROTECT 0x0100 49 | 50 | #define VP_MODE_WIN_GRAPHICS 0x0001 51 | #define VP_MODE_TV_PLAYBACK 0x0002 52 | 53 | #define VP_TV_STANDARD_NTSC_M 0x0001 54 | #define VP_TV_STANDARD_NTSC_M_J 0x0002 55 | #define VP_TV_STANDARD_PAL_B 0x0004 56 | #define VP_TV_STANDARD_PAL_D 0x0008 57 | #define VP_TV_STANDARD_PAL_H 0x0010 58 | #define VP_TV_STANDARD_PAL_I 0x0020 59 | #define VP_TV_STANDARD_PAL_M 0x0040 60 | #define VP_TV_STANDARD_PAL_N 0x0080 61 | #define VP_TV_STANDARD_SECAM_B 0x0100 62 | #define VP_TV_STANDARD_SECAM_D 0x0200 63 | #define VP_TV_STANDARD_SECAM_G 0x0400 64 | #define VP_TV_STANDARD_SECAM_H 0x0800 65 | #define VP_TV_STANDARD_SECAM_K 0x1000 66 | #define VP_TV_STANDARD_SECAM_K1 0x2000 67 | #define VP_TV_STANDARD_SECAM_L 0x4000 68 | #define VP_TV_STANDARD_WIN_VGA 0x8000 69 | #define VP_TV_STANDARD_NTSC_433 0x00010000 70 | #define VP_TV_STANDARD_PAL_G 0x00020000 71 | #define VP_TV_STANDARD_PAL_60 0x00040000 72 | #define VP_TV_STANDARD_SECAM_L1 0x00080000 73 | 74 | #define VP_CP_TYPE_APS_TRIGGER 0x0001 75 | #define VP_CP_TYPE_MACROVISION 0x0002 76 | #define VP_CP_CMD_ACTIVATE 0x0001 77 | #define VP_CP_CMD_DEACTIVATE 0x0002 78 | #define VP_CP_CMD_CHANGE 0x0004 79 | #endif 80 | -------------------------------------------------------------------------------- /tcc/win32/include/winapi/windows.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the w64 mingw-runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER within this package. 5 | */ 6 | #ifndef _WINDOWS_ 7 | #define _WINDOWS_ 8 | 9 | #ifndef WINVER 10 | #define WINVER 0x0502 11 | #endif 12 | 13 | #include <_mingw.h> 14 | 15 | #ifndef _INC_WINDOWS 16 | #define _INC_WINDOWS 17 | 18 | #if defined(RC_INVOKED) && !defined(NOWINRES) 19 | 20 | #include 21 | #else 22 | 23 | #ifdef RC_INVOKED 24 | #define NOATOM 25 | #define NOGDI 26 | #define NOGDICAPMASKS 27 | #define NOMETAFILE 28 | #define NOMINMAX 29 | #define NOMSG 30 | #define NOOPENFILE 31 | #define NORASTEROPS 32 | #define NOSCROLL 33 | #define NOSOUND 34 | #define NOSYSMETRICS 35 | #define NOTEXTMETRIC 36 | #define NOWH 37 | #define NOCOMM 38 | #define NOKANJI 39 | #define NOCRYPT 40 | #define NOMCX 41 | #endif 42 | 43 | #if !defined(I_X86_) && !defined(_IA64_) && !defined(_AMD64_) && (defined(_X86_) && !defined(__x86_64)) 44 | #define I_X86_ 45 | #endif 46 | 47 | #if !defined(I_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(__x86_64) 48 | #define _AMD64_ 49 | #endif 50 | 51 | #if !defined(I_X86_) && !(defined(_X86_) && !defined(__x86_64)) && !defined(_AMD64_) && defined(__ia64__) 52 | #if !defined(_IA64_) 53 | #define _IA64_ 54 | #endif 55 | #endif 56 | 57 | #ifndef RC_INVOKED 58 | #include 59 | #include 60 | #endif 61 | 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | 72 | #ifndef WIN32_LEAN_AND_MEAN 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | #include 83 | #include 84 | #ifndef NOCRYPT 85 | #include 86 | #include 87 | #include 88 | #endif 89 | 90 | #ifndef NOUSER 91 | #ifndef NOGDI 92 | #include 93 | #ifdef INC_OLE1 94 | #include 95 | #else 96 | #include 97 | #endif 98 | #include 99 | #endif 100 | #endif 101 | #endif 102 | 103 | #include 104 | 105 | #ifdef INC_OLE2 106 | #include 107 | #endif 108 | 109 | #ifndef NOSERVICE 110 | #include 111 | #endif 112 | 113 | #ifndef NOMCX 114 | #include 115 | #endif 116 | 117 | #ifndef NOIME 118 | #include 119 | #endif 120 | 121 | #endif 122 | #endif 123 | #endif 124 | -------------------------------------------------------------------------------- /tcc/win32/lib/crt1.c: -------------------------------------------------------------------------------- 1 | // ============================================= 2 | // crt1.c 3 | 4 | #include 5 | 6 | #define __UNKNOWN_APP 0 7 | #define __CONSOLE_APP 1 8 | #define __GUI_APP 2 9 | void __set_app_type(int); 10 | void _controlfp(unsigned a, unsigned b); 11 | 12 | typedef struct 13 | { 14 | int newmode; 15 | } _startupinfo; 16 | 17 | void __getmainargs(int *pargc, char ***pargv, char ***penv, int globb, _startupinfo*); 18 | int main(int argc, char **argv, char **env); 19 | 20 | int _start(void) 21 | { 22 | __TRY__ 23 | int argc; char **argv; char **env; int ret; 24 | _startupinfo start_info = {0}; 25 | 26 | _controlfp(0x10000, 0x30000); 27 | __set_app_type(__CONSOLE_APP); 28 | __getmainargs(&argc, &argv, &env, 0, &start_info); 29 | 30 | ret = main(argc, argv, env); 31 | exit(ret); 32 | } 33 | 34 | // ============================================= 35 | -------------------------------------------------------------------------------- /tcc/win32/lib/dllcrt1.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #include 4 | 5 | BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved); 6 | 7 | BOOL WINAPI _dllstart(HANDLE hDll, DWORD dwReason, LPVOID lpReserved) 8 | { 9 | BOOL bRet; 10 | bRet = DllMain (hDll, dwReason, lpReserved); 11 | return bRet; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tcc/win32/lib/dllmain.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #include 4 | 5 | BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved) 6 | { 7 | return TRUE; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tcc/win32/lib/wincrt1.c: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------------- 2 | 3 | #include 4 | #include 5 | 6 | #define __UNKNOWN_APP 0 7 | #define __CONSOLE_APP 1 8 | #define __GUI_APP 2 9 | void __set_app_type(int); 10 | void _controlfp(unsigned a, unsigned b); 11 | 12 | int _winstart(void) 13 | { 14 | __TRY__ 15 | char *szCmd; 16 | STARTUPINFO startinfo; 17 | int fShow; 18 | int ret; 19 | 20 | __set_app_type(__GUI_APP); 21 | _controlfp(0x10000, 0x30000); 22 | 23 | szCmd = GetCommandLine(); 24 | if (szCmd) { 25 | while (' ' == *szCmd) 26 | szCmd++; 27 | if ('\"' == *szCmd) { 28 | while (*++szCmd) 29 | if ('\"' == *szCmd) { 30 | szCmd++; 31 | break; 32 | } 33 | } else { 34 | while (*szCmd && ' ' != *szCmd) 35 | szCmd++; 36 | } 37 | while (' ' == *szCmd) 38 | szCmd++; 39 | } 40 | 41 | GetStartupInfo(&startinfo); 42 | fShow = startinfo.wShowWindow; 43 | if (0 == (startinfo.dwFlags & STARTF_USESHOWWINDOW)) 44 | fShow = SW_SHOWDEFAULT; 45 | 46 | ret = WinMain(GetModuleHandle(NULL), NULL, szCmd, fShow); 47 | exit(ret); 48 | } 49 | 50 | int _runwinmain(int argc, char **argv) 51 | { 52 | char *szCmd, *p; 53 | 54 | p = GetCommandLine(); 55 | szCmd = NULL; 56 | if (argc > 1) 57 | szCmd = strstr(p, argv[1]); 58 | if (NULL == szCmd) 59 | szCmd = ""; 60 | else if (szCmd > p && szCmd[-1] == '\"') 61 | --szCmd; 62 | return WinMain(GetModuleHandle(NULL), NULL, szCmd, SW_SHOWDEFAULT); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /tcc_wrap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | void *compile_tcc(char *s) 8 | { 9 | TCCState *tcc = tcc_new(); 10 | 11 | if(!tcc) 12 | { 13 | printf("TCC state not created :(\n"); 14 | return NULL; 15 | } 16 | 17 | // disable standard libraries 18 | if(!tcc_set_options(tcc, "-nostdlib")) 19 | { 20 | printf("TCC set nostdlib failed :(\n"); 21 | return NULL; 22 | } 23 | 24 | tcc_set_output_type(tcc, TCC_OUTPUT_MEMORY); 25 | 26 | if(tcc_compile_string(tcc, s)==-1) 27 | { 28 | printf("TCC compile failed :(\n"); 29 | return NULL; 30 | } 31 | 32 | if(tcc_relocate(tcc, TCC_RELOCATE_AUTO)<0) 33 | { 34 | printf("TCC relocate failed :(\n"); 35 | return NULL; 36 | } 37 | 38 | return (void *) tcc; 39 | } 40 | 41 | void *getsymbol_tcc(void *tcc, char *symbol) 42 | { 43 | 44 | void *func = (void*)(tcc_get_symbol((TCCState *)tcc, symbol)); 45 | if(!func) 46 | { 47 | printf("TCC get symbol failed :(\n"); 48 | return NULL; 49 | } 50 | return func; 51 | } 52 | 53 | void delete_tcc(void *tcc) 54 | { 55 | tcc_delete((TCCState *)tcc); 56 | } 57 | -------------------------------------------------------------------------------- /todo: -------------------------------------------------------------------------------- 1 | -- implemented and linked 2 | luajit [primary language] + (LuaJIT 2.0.4, modified build script) https://github.com/LuaJIT/LuaJIT / MIT 3 | tcc [c compiler] (TCC + modified tccrun.c for baremetal) http://bellard.org/tcc/ / LGPL 4 | miniz [compression] (miniz.c) https://github.com/richgel999/miniz / public-domain/unlicense 5 | rpi-boot [framebuffer, sd card, fs] (rpiboot, modified to avoid name conflict) / https://github.com/jncronin/rpi-boot / BSD 6 | linenoise [nice terminal] (linenoise) / https://github.com/antirez/linenoise / BSD 7 | lpeg [text matching] (lpeg-1.0.0) / http://www.inf.puc-rio.br/~roberto/lpeg/ / MIT 8 | uart02 example (from dwelch67) / https://github.com/dwelch67/raspberrypi/tree/master/uart02 / MIT 9 | ffi-reflect [ffi-reflection] (ffi-reflect) https://github.com/corsix/ffi-reflect / MIT? 10 | penlight [lua utilities] (penlight) / https://github.com/stevedonovan/Penlight / MIT 11 | lua-repl (from lua-repl, modified sources) / https://github.com/hoelzro/lua-repl / MIT 12 | lua-linenoise (from lua-linenoise) https://github.com/hoelzro/lua-linenoise / MIT 13 | dkjson (dkjson) / http://dkolf.de/src/dkjson-lua.fsl/home / MIT 14 | dynasm [disassembler] (from LuaJIT 2.0.4) / MIT 15 | valvers arm c tutorial (mbox access) / http://www.valvers.com/open-software/raspberry-pi/step01-bare-metal-programming-in-cpt1/ 16 | 17 | -- compiled but unlinked 18 | nacl [crypto] (tweetnacl) / https://tweetnacl.cr.yp.to/ / Public domain 19 | sqlite [filesystem] / https://sqlite.org/ / Public domain 20 | lua-glob-pattern / https://github.com/davidm/lua-glob-pattern / MIT 21 | 22 | 23 | --todo 24 | fix randombytes 25 | lua-term 26 | add missing assembler/disassembler instructions 27 | make requiring .dasl files work 28 | basic multiline editor (list of lines) 29 | upload/download 30 | make i/o changeable from lua 31 | better module structure 32 | linker for modules? 33 | make vfs talk to the zip structure 34 | vectors at 0x0 35 | microlight? 36 | lsqlite3? 37 | add basic header files 38 | add usb driver csud ? 39 | 40 | -- not compiled/incuded 41 | 42 | bitstream [bitstream reading/writing] 43 | turtle [quaternions, matrices] 44 | stb_texedit [text editor] / public domain 45 | nuklear [ui] / public domain 46 | -------------------------------------------------------------------------------- /valvers/rpi-base.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013-2015, Brian Sidebotham 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 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_BASE_H 32 | #define RPI_BASE_H 33 | 34 | #include 35 | 36 | #ifdef RPI2 37 | #define PERIPHERAL_BASE 0x3F000000UL 38 | #else 39 | #define PERIPHERAL_BASE 0x20000000UL 40 | #endif 41 | 42 | typedef volatile uint32_t rpi_reg_rw_t; 43 | typedef volatile const uint32_t rpi_reg_ro_t; 44 | typedef volatile uint32_t rpi_reg_wo_t; 45 | 46 | typedef volatile uint64_t rpi_wreg_rw_t; 47 | typedef volatile const uint64_t rpi_wreg_ro_t; 48 | 49 | #endif 50 | --------------------------------------------------------------------------------