├── .gitignore ├── .merlin ├── .ocp-indent ├── CHANGES.md ├── Makefile ├── Makefile.config ├── README.md ├── TODO.md ├── doc ├── greet.jpg └── style.css ├── libc-newlib ├── README.md ├── include │ └── dirent.h └── src │ ├── dirent.c │ └── newlib_syscalls.c ├── libc-ocaml ├── LICENSE.md ├── README.md ├── TODO.md ├── include │ ├── dirent.h │ ├── errno.h │ ├── fcntl.h │ ├── setjmp.h │ ├── signal.h │ ├── stdio.h │ ├── stdlib.h │ ├── string.h │ ├── sys │ │ ├── stat.h │ │ └── ucontext.h │ ├── time.h │ └── unistd.h └── src │ ├── dirent.c │ ├── errno.c │ ├── fcntl.c │ ├── malloc.c │ ├── newlib-fix.c │ ├── setjmp.c │ ├── signal.c │ ├── snprintf.c │ ├── stat.c │ ├── stdio.c │ ├── stdlib.c │ ├── string.c │ ├── strtod.c │ ├── time.c │ └── unistd.c ├── packages └── ocaml-armv7-none-eabihf.4.02.3 │ ├── files │ ├── armv7-none-eabihf.conf.in │ ├── bare-include │ │ ├── dirent.h │ │ └── sys │ │ │ └── ucontext.h │ └── config │ │ ├── .ignore │ │ ├── Makefile.in │ │ ├── m.h │ │ └── s.h │ └── opam ├── repo ├── rpi-boot-ocaml.ld ├── src-boot ├── boot.S ├── sbrk.c └── startup.c └── src ├── fb.ml ├── fb.mli ├── logo.ml ├── main.ml ├── rpi.ml ├── rpi.mli └── rpi_mem.c /.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | tmp 3 | *~ 4 | \#*# -------------------------------------------------------------------------------- /.merlin: -------------------------------------------------------------------------------- 1 | S src 2 | B _build/** -------------------------------------------------------------------------------- /.ocp-indent: -------------------------------------------------------------------------------- 1 | strict_with=always,match_clause=4,strict_else=never,strict_comments=true -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dbuenzli/rpi-boot-ocaml/e48324af6f23cf80e7a410f470601c2495a2a7b2/CHANGES.md -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include Makefile.config 2 | 3 | BDIR := _build 4 | 5 | # OCaml Kernel 6 | SRC := src 7 | KERNEL_MLIS := $(wildcard $(SRC)/*.mli) 8 | KERNEL_CMXS := $(patsubst $(SRC)/%.ml,$(BDIR)/%.cmx,$(addprefix $(SRC)/,$(ML))) 9 | KERNEL_STUBS += $(patsubst $(SRC)/%.c,$(BDIR)/%.o,$(wildcard $(SRC)/*.c)) 10 | KERNEL := $(BDIR)/kernel.o 11 | 12 | # librpi-boot-ocaml 13 | SRC_BOOT := src-boot 14 | BOOT_OBJS := $(patsubst $(SRC_BOOT)/%.S,$(BDIR)/%.o,$(wildcard $(SRC_BOOT)/*.S)) 15 | BOOT_OBJS += $(patsubst $(SRC_BOOT)/%.c,$(BDIR)/%.o,$(wildcard $(SRC_BOOT)/*.c)) 16 | BOOT_A += $(BDIR)/librpi-boot-ocaml.a 17 | 18 | ifeq ($(LIBC_USE_NEWLIB),true) 19 | LIBC_DIR := libc-newlib/src 20 | LIBC_CLIBS := -lc 21 | else 22 | LIBC_DIR := libc-ocaml/src 23 | LIBC_CLIBS := 24 | endif 25 | 26 | LIBC_SRCS := $(wildcard $(LIBC_DIR)/*.c) 27 | LIBC_OBJS := $(patsubst $(LIBC_DIR)/%.c,$(BDIR)/%.o,$(LIBC_SRCS)) 28 | LIBC_A := $(BDIR)/libc-ocaml.a 29 | 30 | # Build tools 31 | OCAMLOPT := ocamlfind -toolchain armv7_none_eabihf ocamlopt 32 | CROSS ?= arm-none-eabi- 33 | CC := $(CROSS)gcc 34 | AR := $(CROSS)ar 35 | LD := $(CROSS)ld 36 | OBJCOPY := $(CROSS)objcopy 37 | OBJDUMP := $(CROSS)objdump 38 | 39 | # C and assembly compiler options 40 | DEBUG := 41 | DEPEND_FLAGS := -MD -MP 42 | ARCH_FLAGS := -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard 43 | 44 | ASFLAGS := $(ARCH_FLAGS) -ffreestanding 45 | 46 | CINCS := -I src-boot 47 | CFLAGS := $(CINCS) $(DEPEND_FLAGS) $(DEBUG) $(ARCH_FLAGS) 48 | CFLAGS += -ffreestanding -std=c99 -O2 -Wall 49 | 50 | LINKER := rpi-boot-ocaml.ld 51 | LASMRUN_PATH := $(shell $(OCAMLOPT) -where) 52 | LDFLAGS := -T$(LINKER) 53 | LDFLAGS += -L $(LASMRUN_PATH) # For -lasmrun 54 | LDFLAGS += -L $(LC_PATH) # For -lc -lm for now 55 | LDFLAGS += -L $(LGCC_PATH) # For -lgcc 56 | CLIBS= -lbigarray -lasmrun -lgcc -lm 57 | 58 | # Build rules 59 | 60 | mk_bdir := $(shell mkdir -p $(BDIR)) 61 | 62 | .PHONY: doc 63 | doc: $(KERNEL_CMXS) $(KERNEL_MLIS) 64 | mkdir -p $(BDIR)/doc 65 | ocamldoc -colorize-code -charset utf-8 -I $(BDIR) -html \ 66 | -d $(BDIR)/doc $(KERNEL_MLIS) 67 | cp doc/style.css $(BDIR)/doc/ 68 | 69 | clean: 70 | $(RM) -r $(BDIR) 71 | 72 | rpi-boot-ocaml: $(BDIR)/rpi-boot-ocaml.img $(BDIR)/rpi-boot-ocaml.dasm 73 | 74 | $(LIBC_A): $(LIBC_OBJS) 75 | $(AR) rc -o $@ $^ 76 | 77 | $(BOOT_A): $(BOOT_OBJS) 78 | $(AR) rc -o $@ $^ 79 | 80 | $(KERNEL): $(KERNEL_CMXS) 81 | $(OCAMLOPT) -output-obj -o $@ bigarray.cmxa $^ 82 | 83 | $(BDIR)/rpi-boot-ocaml.elf: $(BOOT_A) $(KERNEL_STUBS) $(KERNEL) $(LINKER) \ 84 | $(LIBC_A) 85 | $(LD) -o $@ -Map $(BDIR)/rpi-boot-ocaml.map \ 86 | $(LDFLAGS) $(KERNEL_STUBS) $(KERNEL) $(CLIBS) $(LIBC_CLIBS) \ 87 | $(LIBC_A) $(BOOT_A) 88 | 89 | $(BDIR)/rpi-boot-ocaml.img: $(BDIR)/rpi-boot-ocaml.elf 90 | $(OBJCOPY) $(BDIR)/rpi-boot-ocaml.elf -O binary $@ 91 | 92 | $(BDIR)/rpi-boot-ocaml.dasm : $(BDIR)/rpi-boot-ocaml.elf 93 | $(OBJDUMP) -d $< > $@ 94 | 95 | $(BDIR)/%.o: $(LIBC_DIR)/%.c 96 | $(CC) $(CFLAGS) -I $(LIBC_DIR)/../include -c -o $@ $< 97 | 98 | $(BDIR)/%.o: $(SRC_BOOT)/%.c 99 | $(CC) $(CFLAGS) -c -o $@ $< 100 | 101 | $(BDIR)/%.o: $(SRC_BOOT)/%.S 102 | $(CC) $(ASFLAGS) -c -o $@ $< 103 | 104 | $(BDIR)/%.o: $(SRC)/%.c 105 | $(OCAMLOPT) -ccopt -std=c99 -ccopt -I$(SRC) -o $@ $< 106 | mv $(shell basename $@) $(BDIR)/ 107 | 108 | $(BDIR)/%.o $(BDIR)/%.cmx: $(SRC)/%.ml 109 | $(eval MLI := $(wildcard $(patsubst $(SRC)/%.ml,$(SRC)/%.mli,$<))) 110 | @echo $(MLI) 111 | if [ "$(MLI)" ]; then\ 112 | $(OCAMLOPT) -I $(BDIR) -c \ 113 | -o $(patsubst $(SRC)/%.ml,$(BDIR)/%.cmi,$<) $(MLI); \ 114 | fi 115 | $(OCAMLOPT) -I $(BDIR) -c -o $@ $< 116 | 117 | .PRECIOUS: %.cmx 118 | 119 | include $(wildcard $(BDIR)/*.d) 120 | -------------------------------------------------------------------------------- /Makefile.config: -------------------------------------------------------------------------------- 1 | # -*-Makefile-*- 2 | 3 | # OCaml sources for the kernel, add whathever you hack on in `src` to 4 | # here, in the right compilation order. 5 | ML := rpi.ml fb.ml logo.ml main.ml 6 | 7 | # The build OS 8 | BUILD_OS := $(shell uname -s) 9 | 10 | # libc, either newlib's ligc and libc-newlib's syscall stubs or libc-ocaml 11 | LIBC_USE_NEWLIB = false 12 | 13 | # Where is libgcc.a, libm.a and libc.a (if LIBC_USE_NEWLIB is true) 14 | ifeq ($(BUILD_OS),Darwin) 15 | LGCC_PATH = /usr/local/lib/gcc/arm-none-eabi/4.9.3/armv7-ar/thumb/fpu 16 | LC_PATH = /usr/local/Cellar/arm-none-eabi-gcc/4.9-2015-q2-update/arm-none-eabi/lib/armv7-ar/thumb/fpu 17 | else 18 | LGCC_PATH = /usr/lib/arm-none-eabi/4.8.2/armv7-ar/thumb/fpu 19 | LC_PATH = /usr/lib/arm-none-eabi/lib/armv7-ar/thumb/fpu 20 | endif 21 | 22 | # Default target 23 | 24 | all: rpi-boot-ocaml 25 | 26 | # Serial connection convenience target `make connect` 27 | 28 | SERIAL_DEV := /dev/tty.usbserial 29 | connect: 30 | sudo cu -l $(SERIAL_DEV) -s 115200 31 | 32 | # Deploy convenience target `make deploy` 33 | 34 | DEPLOY_VOLUME := /Volumes/boot 35 | 36 | ifeq ($(BUILD_OS),Darwin) 37 | 38 | deploy: rpi-boot-ocaml 39 | # This avoids having to replug the micro SD adapter 40 | -diskutil unmount $(DEPLOY_VOLUME) 41 | sudo kextunload -b com.apple.driver.AppleSDXC 42 | sudo kextload -b com.apple.driver.AppleSDXC 43 | sleep 1 44 | cp $(BDIR)/rpi-boot-ocaml.img $(DEPLOY_VOLUME)/rpi-boot-ocaml.img 45 | diskutil unmount $(DEPLOY_VOLUME) 46 | 47 | else 48 | 49 | deploy: rpi-boot-ocaml 50 | echo "Deploy recipe for $(BUILD_OS) welcome." 51 | 52 | endif 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | rpi-boot-ocaml - Raspberry Pi boot support for the OCaml system 2 | ------------------------------------------------------------------------------ 3 | Release %%VERSION%% 4 | 5 | rpi-boot-ocaml is a minimal static library and linker script for 6 | booting a Raspberry Pi directly into the OCaml system. The rest is 7 | yours. 8 | 9 | For now only the Raspberry [Pi 2 Model B][1] is supported. 10 | 11 | rpi-boot-ocaml is distributed under the BSD3 license. 12 | 13 | [1]: https://www.raspberrypi.org/products/raspberry-pi-2-model-b/ 14 | 15 | ## Prerequisites 16 | 17 | We first need an OCaml cross compiler for ARMv7. Add the following 18 | repository to `opam`: 19 | ``` 20 | opam repo add rpi-boot-ocaml http://erratique.ch/repos/rpi-boot-ocaml.git 21 | opam update 22 | ``` 23 | Install an OCaml compiler with a version that matches the cross-compiler 24 | (currently 4.02.3). On a 64-bit build system you need a 32-bit OCaml compiler. 25 | ``` 26 | opam switch 4.02.3 # If you are on a 32-bit platform 27 | opam switch 4.02.3+32bit # If you are on a 64-bit platform 28 | eval `opam config env` 29 | ``` 30 | You need ARM's gcc [cross-compiler][2] in your path. On Linux and 31 | MacOSX with homebrew it can be installed with: 32 | ``` 33 | opam depext ocaml-armv7-none-eabihf 34 | ``` 35 | The OCaml cross compiler can now be installed via: 36 | ``` 37 | opam install ocaml-armv7-none-eabihf 38 | ``` 39 | The cross compiler is installed in `$(opam config var 40 | prefix)/armv7-none-eabihf`. It can be invoked by using the 41 | `-toolchain` argument of `ocamlfind`: 42 | ``` 43 | ocamlfind -toolchain armv7_none_eabihf ocamlopt -config 44 | ``` 45 | Note that the compiler is configured not to link against `libc` and 46 | `libm` so that you can substitute them with whatever you wish. 47 | 48 | [2]: (https://launchpad.net/gcc-arm-embedded) 49 | 50 | ## Now run an OCaml system kernel 51 | 52 | Clone this repository: 53 | ``` 54 | git clone http://erratique.ch/repos/rpi-boot-ocaml.git 55 | cd rpi-boot-ocaml 56 | ``` 57 | A simple base example kernel is in the [`src`](src) directory. Adjust the 58 | variables in [Makefile.config](Makefile.config). And: 59 | ``` 60 | make 61 | ``` 62 | This will generate the kernel image `_build/rpi-boot-ocaml.img` that 63 | can be loaded by the Raspberry Pi. 64 | 65 | To run it, the easiest is to have an SD card loaded with one of the 66 | officially supported operating system images, follow 67 | [these instructions][3]. Simply copy `_build/rpi-boot-ocaml.img` at 68 | the root of the SD card and add the following line to the `config.txt` 69 | file present at that location: 70 | ``` 71 | kernel=rpi-boot-ocaml.img 72 | ``` 73 | 74 | Unmount the SD card, plug it in the Raspberry Pi. To witness the OCaml 75 | system boot you can connect a display and/or a [serial cable][4] to 76 | the Pi. Power the system. The display should show something like 77 | this: 78 | 79 | ![rpi-boot-ocaml greetings](doc/greet.jpg) 80 | 81 | The serial connection should output something along the lines of: 82 | ``` 83 | Welcome to rpi-boot-ocaml 🐫 84 | Boot time: 1324ms 85 | Framebuffer: 800x480 bpp:32 addr:0x3DA83000 86 | ``` 87 | Note that the outrageous boot time is not due to the use of OCaml 88 | whose runtime and linked modules initialisation only adds ~4ms to an 89 | equivalent boot sequence into a plain C kernel. 90 | 91 | [3]: https://www.raspberrypi.org/documentation/installation/installing-images/README.md 92 | [4]: http://elinux.org/RPi_Serial_Connection 93 | 94 | ## Boot and halt procedure 95 | 96 | We describe what happens once we get a chance to execute our code. If 97 | you want to know about the slow GPU dance that comes before see for 98 | example this (sligthly outdated) [stackoverflow answer][5]. 99 | 100 | The kernel starts with [`boot.S`](src-boot/boot.S) which: 101 | 102 | 1. Enables the L1 cache and branch prediction. 103 | 2. Enables the Neon MPE. 104 | 3. Zeroes the C [bss section](https://en.wikipedia.org/wiki/.bss). 105 | 4. Setups the C call stack and jumps into the `_startup` C function of 106 | [`startup.c`](src-boot/startup.c) which simply calls 107 | `caml_startup` and never returns. 108 | 109 | If the program ends up in the C `exit` or `abort` function the `halt` 110 | function of [`startup.c`](src-boot/startup.c) gets called with the 111 | status code (255 for `abort`). If the status code is non-zero the ACT 112 | led of the Pi will flash at high-frequency; this will happen for 113 | example in case of an uncaught OCaml exception or an out of memory 114 | condition. If `halt` is called with a status of `0` we just call the 115 | `wfe` ARM instruction in a loop; this will happen on `exit 0` or if 116 | `caml_startup` returns normally. 117 | 118 | [5]: http://raspberrypi.stackexchange.com/a/10595 119 | 120 | ## Kernel development and image build procedure 121 | 122 | To build a kernel simply create an OCaml program and link it into an 123 | object cfile using `ocamlopt`'s [`-output-obj`][6] option. 124 | 125 | This object file must then be linked using the 126 | [`rpi-boot-ocaml.ld`](rpi-boot-ocaml.ld) linker script with the 127 | following libraries: 128 | 129 | * `lib-ocaml-boot.a`, has the boot code from [`src-boot`](src-boot) 130 | * `libbigarray.a`, OCaml's bigarray support. 131 | * `libasmrun.a`, OCaml's runtime library. 132 | * `libgcc.a`, gcc library needed for some of the generated code. 133 | * `libc.a`, a `libc` of your choice. 134 | * `libm.a`, a `libm` of your choice. 135 | 136 | This results in an an ELF executable that must be stripped to a raw 137 | binary ARM executable using `objcopy`. 138 | 139 | If you hack directly on this repo you should be able to simply add 140 | `.c` and `.ml` files to [`src`](src), mention the `.ml` files in 141 | [`Makefile.config`](Makefile.config) and things should compile into 142 | the `_build/rpi-boot-ocaml.img` kernel image. Generated documentation 143 | for the helper `Rpi` module can be found 144 | [here](http://erratique.ch/software/rpi-boot-ocaml/doc/Rpi.html). 145 | 146 | In case of problems you can have a look at the generated assembly code 147 | `_build/rpi-boot-ocaml.dasm` and the map file 148 | `_build/rpi-boot-ocaml.map`. 149 | 150 | [6]: http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec454 151 | 152 | ## Status and future plans 153 | 154 | Note that all this is only a starting point and there are quite a few 155 | issues to solve and a few problems you may run into. See the 156 | [`TODO.md`](TODO.md) file and the issue tracker. 157 | 158 | Once we get proper cross-compilation support in `opam` the plan is to 159 | eventually package and split away `libc-ocaml` and make this a package 160 | only for the `src-boot` static library and the linker script (and 161 | maybe the helper base [`Rpi`](`src/rpi.mli`) module). The rest in 162 | `src` should be developed and distributed independently as libraries. 163 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | * Use openlibm for libm. 2 | 3 | * libc-ocaml `snprintf`, it seems that some formats are broken, test that fix 4 | it or replace it. 5 | 6 | * Interrupt vector setup and handling strategy. The vectors should 7 | simply set some global variables. With effects we can then easily 8 | have code that suspends until the interrupt occurs by making an 9 | effect. The main run loop simply checks the interrupt global 10 | variables to see if there's something new and invokes the 11 | continuations waiting on them. If there's nothing to do the main 12 | loop can sleep with `WFI` until the next os timer deadline. 13 | 14 | * Stack size ? What's the correct way of setting this up ? See link script. 15 | Can we honour/specify the OCAMLRUNPARAM variable name. 16 | 17 | * Heap size ? See `sbrk.c`. We should repect the ARM/VideoCore split 18 | which we can get using the mailbox (tag 0x00010005). Formally it may 19 | be too late if we are in a hypothetical case were ocaml init allocs 20 | a lot before we get to the initalisation of the rpi module Rpi where 21 | we set the split as a toplevel phrase, we can simply assume that Rpi 22 | must be linked early if not the first and set a minimal 23 | 24 | * Determine why that `*(.bss*)` is needed in the build script *for newlib*'s 25 | libc. Without that sbrk our gets called with negative inputs at the start 26 | which leads to `ENOMEM`. 27 | 28 | * Try to compile the ocaml compiler with `-nostdinc`, and against 29 | libc-ocaml, this will avoid the need for `newlib-fix.c` in 30 | libc-ocaml which is there because the newlib header pollutes the 31 | object files of `libasmrun`. This would also allow to remove 32 | `bare-includes` from the cross compiler OCaml package. 33 | 34 | * Distribute `libc-ocaml` separately. 35 | 36 | * Provide a way to allocate bigarrays aligned on 16 bytes boundaries 37 | (needed for VC communication). Currently a hack is being used. 38 | 39 | * Device tree support, need to add a trailer to the kernel image otherwise 40 | we get atags. 41 | 42 | * Sort out the memory addressing and MMU stuff. 43 | 44 | * `git grep FIXME`. 45 | 46 | * The build system is fucked up w.r.t. to ocaml dependencies. Too tired 47 | with build systems to fix that. 48 | -------------------------------------------------------------------------------- /doc/greet.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dbuenzli/rpi-boot-ocaml/e48324af6f23cf80e7a410f470601c2495a2a7b2/doc/greet.jpg -------------------------------------------------------------------------------- /doc/style.css: -------------------------------------------------------------------------------- 1 | /* A style for ocamldoc. Daniel C. Buenzli */ 2 | 3 | /* Reset a few things. */ 4 | html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre, 5 | a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp, 6 | small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset, 7 | form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td 8 | { margin: 0; padding: 0; border: 0 none; outline: 0; font-size: 100%; 9 | font-weight: inherit; font-style:inherit; font-family:inherit; 10 | line-height: inherit; vertical-align: baseline; text-align:inherit; 11 | color:inherit; background: transparent; } 12 | 13 | table { border-collapse: collapse; border-spacing: 0; } 14 | 15 | /* Basic page layout */ 16 | 17 | body { font: normal 10pt/1.375em helvetica, arial, sans-serif; text-align:left; 18 | margin: 1.375em 10%; min-width: 40ex; max-width: 72ex; 19 | color: black; background: transparent /* url(line-height-22.gif) */; } 20 | 21 | b { font-weight: bold } 22 | em { font-style: italic } 23 | 24 | tt, code, pre { font-family: WorkAroundWebKitAndMozilla, monospace; 25 | font-size: 1em; } 26 | pre code { font-size : inherit; } 27 | .codepre { margin-bottom:1.375em /* after code example we introduce space. */ } 28 | 29 | .superscript,.subscript 30 | { font-size : 0.813em; line-height:0; margin-left:0.4ex;} 31 | .superscript { vertical-align: super; } 32 | .subscript { vertical-align: sub; } 33 | 34 | /* ocamldoc markup workaround hacks */ 35 | 36 | 37 | 38 | hr, hr + br, div + br, center + br, span + br, ul + br, ol + br, pre + br 39 | { display: none } /* annoying */ 40 | 41 | div.info + br { display:block} 42 | 43 | .codepre br + br { display: none } 44 | h1 + pre { margin-bottom:1.375em} /* Toplevel module description */ 45 | 46 | /* Sections and document divisions */ 47 | 48 | /* .navbar { margin-bottom: -1.375em } */ 49 | h1 { font-weight: bold; font-size: 1.5em; /* margin-top:1.833em; */ 50 | margin-top:0.917em; padding-top:0.875em; 51 | border-top-style:solid; border-width:1px; border-color:#AAA; } 52 | h2 { font-weight: bold; font-size: 1.313em; margin-top: 1.048em } 53 | h3 { font-weight: bold; font-size: 1.125em; margin-top: 1.222em } 54 | h3 { font-weight: bold; font-size: 1em; margin-top: 1.375em} 55 | h4 { font-style: italic; } 56 | 57 | /* Used by OCaml's own library documentation. */ 58 | h6 { font-weight: bold; font-size: 1.125em; margin-top: 1.222em } 59 | .h7 { font-weight: bold; font-size: 1em; margin-top: 1.375em } 60 | 61 | p { margin-top: 1.375em } 62 | pre { margin-top: 1.375em } 63 | .info { margin: 0.458em 0em -0.458em 2em;}/* Description of types values etc. */ 64 | td .info { margin:0; padding:0; margin-left: 2em;} /* Description in indexes */ 65 | 66 | ul, ol { margin-top:0.688em; padding-bottom:0.687em; 67 | list-style-position:outside} 68 | ul + p, ol + p { margin-top: 0em } 69 | ul { list-style-type: square } 70 | 71 | 72 | /* h2 + ul, h3 + ul, p + ul { } */ 73 | ul > li { margin-left: 1.375em; } 74 | ol > li { margin-left: 1.7em; } 75 | /* Links */ 76 | 77 | a, a:link, a:visited, a:active, a:hover { color : #00B; text-decoration: none } 78 | a:hover { text-decoration : underline } 79 | *:target {background-color: #FFFF99;} /* anchor highlight */ 80 | 81 | /* Code */ 82 | 83 | .keyword { font-weight: bold; } 84 | .comment { color : red } 85 | .constructor { color : green } 86 | .string { color : brown } 87 | .warning { color : red ; font-weight : bold } 88 | 89 | /* Functors */ 90 | 91 | .paramstable { border-style : hidden ; padding-bottom:1.375em} 92 | .paramstable code { margin-left: 1ex; margin-right: 1ex } 93 | .sig_block {margin-left: 1em} 94 | 95 | /* Images */ 96 | 97 | img { margin-top: 1.375em } 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /libc-newlib/README.md: -------------------------------------------------------------------------------- 1 | Implements newlib's syscalls so that one can link against newlib's 2 | libc. 3 | -------------------------------------------------------------------------------- /libc-newlib/include/dirent.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | /** dirent.h stubs */ 8 | 9 | #ifndef DIRENT_H 10 | #define DIRENT_H 11 | 12 | #include 13 | 14 | struct dirent { ino_t d_ino; char d_name[]; }; 15 | typedef int DIR; 16 | 17 | DIR *opendir(const char *); 18 | struct dirent *readdir(DIR *); 19 | int closedir(DIR *); 20 | 21 | #endif 22 | 23 | /*--------------------------------------------------------------------------- 24 | Copyright (c) 2015 Daniel C. Bünzli. 25 | All rights reserved. 26 | 27 | Redistribution and use in source and binary forms, with or without 28 | modification, are permitted provided that the following conditions 29 | are met: 30 | 31 | 1. Redistributions of source code must retain the above copyright 32 | notice, this list of conditions and the following disclaimer. 33 | 34 | 2. Redistributions in binary form must reproduce the above 35 | copyright notice, this list of conditions and the following 36 | disclaimer in the documentation and/or other materials provided 37 | with the distribution. 38 | 39 | 3. Neither the name of Daniel C. Bünzli nor the names of 40 | contributors may be used to endorse or promote products derived 41 | from this software without specific prior written permission. 42 | 43 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 44 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 45 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 46 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 47 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 48 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 49 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 50 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 51 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 52 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 53 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54 | --------------------------------------------------------------------------*/ 55 | -------------------------------------------------------------------------------- /libc-newlib/src/dirent.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include // for NULL 8 | #include 9 | #include 10 | 11 | DIR *opendir (const char *name) { errno = ENOSYS; return NULL; } 12 | int closedir (DIR *d) { errno = ENOSYS; return -1; } 13 | struct dirent *readdir (DIR *d) { errno = ENOSYS; return NULL; } 14 | 15 | /*--------------------------------------------------------------------------- 16 | Copyright (c) 2015 Daniel C. Bünzli. 17 | All rights reserved. 18 | 19 | Redistribution and use in source and binary forms, with or without 20 | modification, are permitted provided that the following conditions 21 | are met: 22 | 23 | 1. Redistributions of source code must retain the above copyright 24 | notice, this list of conditions and the following disclaimer. 25 | 26 | 2. Redistributions in binary form must reproduce the above 27 | copyright notice, this list of conditions and the following 28 | disclaimer in the documentation and/or other materials provided 29 | with the distribution. 30 | 31 | 3. Neither the name of Daniel C. Bünzli nor the names of 32 | contributors may be used to endorse or promote products derived 33 | from this software without specific prior written permission. 34 | 35 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | --------------------------------------------------------------------------*/ 47 | -------------------------------------------------------------------------------- /libc-newlib/src/newlib_syscalls.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | extern void halt (int status); 15 | 16 | void *_sbrk (int incr) { return sbrk (incr); } 17 | void _exit (int status) { halt (status); while (1); } 18 | 19 | int _close (int file) { errno = ENOSYS; return -1;} 20 | int chdir (const char *path) { errno = ENOSYS; return -1; } 21 | int _fstat (int file, struct stat *st) { errno = ENOSYS; return -1;} 22 | void _fini (void) { } 23 | pid_t _getpid(void) { return 1; } 24 | pid_t getppid(void) { return 0; } 25 | int _gettimeofday (struct timeval *tv, struct timezone *tz) 26 | { errno = ENOSYS; return -1; } 27 | 28 | char *getcwd (char *buf, size_t size) { errno = ENOSYS; return NULL; } 29 | int _isatty (int file) { errno = ENOSYS; return -1; } 30 | int _kill (int pid, int sig) { errno = ENOSYS; return -1;} 31 | int _link (const char *o, const char *n) { errno = ENOSYS; return -1; } 32 | int _lseek (int file, int ptr, int dir) { errno = ENOSYS; return 0;} 33 | int _open (const char *name, int flags, int mode) { errno = ENOSYS; return -1;} 34 | int _read (int fd, void *buf, size_t count) { errno = ENOSYS; return -1;} 35 | int _stat (const char *pathname, struct stat *st) { errno = ENOSYS; return -1;} 36 | int _unlink (const char *pathname) { errno = ENOSYS; return -1; } 37 | int _write (int file, char *ptr, int len) { errno = ENOSYS; return -1; } 38 | clock_t _times (struct tms *buf) { errno = ENOSYS; return -1;} 39 | 40 | /*--------------------------------------------------------------------------- 41 | Copyright (c) 2015 Daniel C. Bünzli. 42 | All rights reserved. 43 | 44 | Redistribution and use in source and binary forms, with or without 45 | modification, are permitted provided that the following conditions 46 | are met: 47 | 48 | 1. Redistributions of source code must retain the above copyright 49 | notice, this list of conditions and the following disclaimer. 50 | 51 | 2. Redistributions in binary form must reproduce the above 52 | copyright notice, this list of conditions and the following 53 | disclaimer in the documentation and/or other materials provided 54 | with the distribution. 55 | 56 | 3. Neither the name of Daniel C. Bünzli nor the names of 57 | contributors may be used to endorse or promote products derived 58 | from this software without specific prior written permission. 59 | 60 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 61 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 62 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 63 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 64 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 65 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 66 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 67 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 68 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 69 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 70 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 71 | --------------------------------------------------------------------------*/ 72 | -------------------------------------------------------------------------------- /libc-ocaml/LICENSE.md: -------------------------------------------------------------------------------- 1 | The file [`src/malloc.c`](src/malloc.c) is authored by Doug Lea under a 2 | public domain [CC0 license](http://creativecommons.org/publicdomain/zero/1.0/). 3 | 4 | The file [`src/strtod.c`](src/strod.c) is authored by David M. Gay and 5 | distributed under the following license: 6 | ``` 7 | The author of this software is David M. Gay. 8 | 9 | Copyright (c) 1991, 2000, 2001 by Lucent Technologies. 10 | 11 | Permission to use, copy, modify, and distribute this software for any 12 | purpose without fee is hereby granted, provided that this entire notice 13 | is included in all copies of any software which is or includes a copy 14 | or modification of this software and in all copies of the supporting 15 | documentation for such software. 16 | 17 | THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 18 | WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY 19 | REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 20 | OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 21 | ``` 22 | 23 | The file [`src/snprintf.c`](src/snprintf.c) is authored Patrick Powell and 24 | Holger Weiss and is distributed under the following license: 25 | ``` 26 | Copyright (c) 1995 Patrick Powell. 27 | 28 | This code is based on code written by Patrick Powell . 29 | It may be used for any purpose as long as this notice remains intact on all 30 | source code distributions. 31 | 32 | Copyright (c) 2008 Holger Weiss. 33 | 34 | This version of the code is maintained by Holger Weiss . 35 | My changes to the code may freely be used, modified and/or redistributed for 36 | any purpose. 37 | ``` 38 | 39 | The rest is authored by Daniel C. Bünzli under a BSD3 license. 40 | -------------------------------------------------------------------------------- /libc-ocaml/README.md: -------------------------------------------------------------------------------- 1 | libc-ocaml - Minimal C library to support the OCaml system 2 | ------------------------------------------------------------------------------ 3 | Release %%VERSION%% 4 | 5 | libc-ocaml is a minimal C standard library for bare metal OCaml 6 | projects. It provides the minimal set of functions needed to compile 7 | and link OCaml's runtime libraries. 8 | 9 | libc-ocaml is mainly distributed under the BSD3 license, a few bits 10 | are copyrighted under slightly different but at least as liberal 11 | terms. See [LICENSE.md](LICENSE.md) for details. 12 | 13 | ## Porting 14 | 15 | In order for `malloc(3)` to work your system needs to define a `sbrk` function 16 | with the following signature: 17 | ``` 18 | void *sbrk (int incr); 19 | ``` 20 | A call to this function must increment the program's heap space by 21 | `incr` bytes and return the address of the previous heap limit. If 22 | there no memory left it should return `(void *)-1` and set `errno` to 23 | `ENOMEM`. 24 | 25 | You also need to define a `halt` function with the following signature: 26 | ``` 27 | void halt (int status) 28 | ``` 29 | This will be called on POSIX `exit` or `abort`. 30 | 31 | ## Implementation notes 32 | 33 | The only functions that are implemented seriously are memory 34 | allocation, string handling and string formatting functions. Most of 35 | the other function, especially all the file system related ones, 36 | simply error with `ENOSYS`. 37 | 38 | ## Stolen code 39 | 40 | See [LICENSE.md](LICENSE.md) for the copyright details. 41 | 42 | * `free`, `malloc`, `calloc` and `realloc` use Doug Lea's [malloc][1] 43 | implementation, see [`malloc.c`](src/malloc.c). Note that `abort` 44 | and `sbrk` are not required by the OCaml system, but are by this 45 | code. 46 | 47 | * `strtod` is implemented by David M. Gay's [dtoa.c][2] source, 48 | see [strod.c](src/strtod.c). 49 | 50 | * `snprintf` and `vsnprintf` are implemented using Holger Weiss's 51 | [sprintf][3] implementation, see [snprintf.c](src/snprintf.c). 52 | 53 | [1]: http://g.oswego.edu/dl/html/malloc.html 54 | [2]: http://www.netlib.org/fp/dtoa.c 55 | [3]: http://www.jhweiss.de/software/snprintf.html 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /libc-ocaml/TODO.md: -------------------------------------------------------------------------------- 1 | * Sort out the `setjmp` stuff. 2 | * Replace/redo or debug the snprintf implementation, it seems 3 | to be broken on certain formats. 4 | -------------------------------------------------------------------------------- /libc-ocaml/include/dirent.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #ifndef DIRENT_H 8 | #define DIRENT_H 9 | 10 | #include 11 | 12 | struct dirent { ino_t d_ino; char d_name[]; }; 13 | typedef int DIR; 14 | 15 | DIR *opendir(const char *); 16 | struct dirent *readdir(DIR *); 17 | int closedir(DIR *); 18 | 19 | #endif 20 | 21 | /*--------------------------------------------------------------------------- 22 | Copyright (c) 2015 Daniel C. Bünzli. 23 | All rights reserved. 24 | 25 | Redistribution and use in source and binary forms, with or without 26 | modification, are permitted provided that the following conditions 27 | are met: 28 | 29 | 1. Redistributions of source code must retain the above copyright 30 | notice, this list of conditions and the following disclaimer. 31 | 32 | 2. Redistributions in binary form must reproduce the above 33 | copyright notice, this list of conditions and the following 34 | disclaimer in the documentation and/or other materials provided 35 | with the distribution. 36 | 37 | 3. Neither the name of Daniel C. Bünzli nor the names of 38 | contributors may be used to endorse or promote products derived 39 | from this software without specific prior written permission. 40 | 41 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 42 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 43 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 44 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 45 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 46 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 47 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 48 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 49 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 50 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 51 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 52 | --------------------------------------------------------------------------*/ 53 | -------------------------------------------------------------------------------- /libc-ocaml/include/errno.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #ifndef ERRNO_H 8 | #define ERRNO_H 9 | 10 | enum { 11 | /* These ones are used by our libc. */ 12 | ENOSYS, EINVAL, ENOMEM, EOVERFLOW, ERANGE, 13 | /* These are the ones found in OCaml's code */ 14 | EINTR, EAGAIN, EWOULDBLOCK, ENOENT }; 15 | 16 | int errno; 17 | #endif 18 | 19 | /*--------------------------------------------------------------------------- 20 | Copyright (c) 2015 Daniel C. Bünzli. 21 | All rights reserved. 22 | 23 | Redistribution and use in source and binary forms, with or without 24 | modification, are permitted provided that the following conditions 25 | are met: 26 | 27 | 1. Redistributions of source code must retain the above copyright 28 | notice, this list of conditions and the following disclaimer. 29 | 30 | 2. Redistributions in binary form must reproduce the above 31 | copyright notice, this list of conditions and the following 32 | disclaimer in the documentation and/or other materials provided 33 | with the distribution. 34 | 35 | 3. Neither the name of Daniel C. Bünzli nor the names of 36 | contributors may be used to endorse or promote products derived 37 | from this software without specific prior written permission. 38 | 39 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 40 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 41 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 42 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 43 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 45 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 46 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 47 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 48 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 49 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 50 | --------------------------------------------------------------------------*/ 51 | -------------------------------------------------------------------------------- /libc-ocaml/include/fcntl.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #ifndef FCNTL_H 8 | #define FCNTL_H 9 | 10 | int open (const char *path, int oflag, ...); 11 | int fcntl (int fd, int cmd, ...); 12 | 13 | #endif 14 | 15 | /*--------------------------------------------------------------------------- 16 | Copyright (c) 2015 Daniel C. Bünzli. 17 | All rights reserved. 18 | 19 | Redistribution and use in source and binary forms, with or without 20 | modification, are permitted provided that the following conditions 21 | are met: 22 | 23 | 1. Redistributions of source code must retain the above copyright 24 | notice, this list of conditions and the following disclaimer. 25 | 26 | 2. Redistributions in binary form must reproduce the above 27 | copyright notice, this list of conditions and the following 28 | disclaimer in the documentation and/or other materials provided 29 | with the distribution. 30 | 31 | 3. Neither the name of Daniel C. Bünzli nor the names of 32 | contributors may be used to endorse or promote products derived 33 | from this software without specific prior written permission. 34 | 35 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | --------------------------------------------------------------------------*/ 47 | -------------------------------------------------------------------------------- /libc-ocaml/include/setjmp.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #ifndef SETJUMP_H 8 | #define SETJUMP_H 9 | 10 | typedef int jmp_buf; 11 | 12 | int setjmp (jmp_buf env); 13 | 14 | #endif 15 | 16 | /*--------------------------------------------------------------------------- 17 | Copyright (c) 2015 Daniel C. Bünzli. 18 | All rights reserved. 19 | 20 | Redistribution and use in source and binary forms, with or without 21 | modification, are permitted provided that the following conditions 22 | are met: 23 | 24 | 1. Redistributions of source code must retain the above copyright 25 | notice, this list of conditions and the following disclaimer. 26 | 27 | 2. Redistributions in binary form must reproduce the above 28 | copyright notice, this list of conditions and the following 29 | disclaimer in the documentation and/or other materials provided 30 | with the distribution. 31 | 32 | 3. Neither the name of Daniel C. Bünzli nor the names of 33 | contributors may be used to endorse or promote products derived 34 | from this software without specific prior written permission. 35 | 36 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 37 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 38 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 39 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 40 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 43 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 44 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 45 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 46 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 47 | --------------------------------------------------------------------------*/ 48 | -------------------------------------------------------------------------------- /libc-ocaml/include/signal.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #ifndef SIGNAL_H 8 | #define SIGNAL_H 9 | 10 | void (*signal(int sig, void (*func)(int)))(int); 11 | 12 | #endif 13 | 14 | /*--------------------------------------------------------------------------- 15 | Copyright (c) 2015 Daniel C. Bünzli. 16 | All rights reserved. 17 | 18 | Redistribution and use in source and binary forms, with or without 19 | modification, are permitted provided that the following conditions 20 | are met: 21 | 22 | 1. Redistributions of source code must retain the above copyright 23 | notice, this list of conditions and the following disclaimer. 24 | 25 | 2. Redistributions in binary form must reproduce the above 26 | copyright notice, this list of conditions and the following 27 | disclaimer in the documentation and/or other materials provided 28 | with the distribution. 29 | 30 | 3. Neither the name of Daniel C. Bünzli nor the names of 31 | contributors may be used to endorse or promote products derived 32 | from this software without specific prior written permission. 33 | 34 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 35 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 36 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 37 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 38 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 39 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 40 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 41 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 43 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 44 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | --------------------------------------------------------------------------*/ 46 | -------------------------------------------------------------------------------- /libc-ocaml/include/stdio.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #ifndef STDIO_H 8 | #define STDIO_H 9 | 10 | #include 11 | 12 | enum { EOF = -1 }; 13 | 14 | typedef int FILE; 15 | 16 | int rename (const char *o, const char *n); 17 | 18 | int fprintf (FILE *restrict s, const char *restrict fmt, ...); 19 | int fputc (int c, FILE *s); 20 | int fputs (const char *restrict str, FILE *restrict s); 21 | size_t fwrite(const void *restrict p, size_t size, size_t n, FILE *restrict s); 22 | int fflush (FILE *s); 23 | 24 | int sscanf (const char *restrict s, const char *restrict format, ...); 25 | 26 | #endif 27 | 28 | /*--------------------------------------------------------------------------- 29 | Copyright (c) 2015 Daniel C. Bünzli. 30 | All rights reserved. 31 | 32 | Redistribution and use in source and binary forms, with or without 33 | modification, are permitted provided that the following conditions 34 | are met: 35 | 36 | 1. Redistributions of source code must retain the above copyright 37 | notice, this list of conditions and the following disclaimer. 38 | 39 | 2. Redistributions in binary form must reproduce the above 40 | copyright notice, this list of conditions and the following 41 | disclaimer in the documentation and/or other materials provided 42 | with the distribution. 43 | 44 | 3. Neither the name of Daniel C. Bünzli nor the names of 45 | contributors may be used to endorse or promote products derived 46 | from this software without specific prior written permission. 47 | 48 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 49 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 50 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 51 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 52 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 53 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 54 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 55 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 56 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 57 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 58 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 59 | --------------------------------------------------------------------------*/ 60 | -------------------------------------------------------------------------------- /libc-ocaml/include/stdlib.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #ifndef STDLIB_H 8 | #define STDLIB_H 9 | 10 | #include 11 | #include 12 | 13 | void abort (void); 14 | void exit (int status); 15 | 16 | int system (const char *command); 17 | 18 | char *getenv (const char *name); 19 | 20 | void free (void *ptr); 21 | void *malloc (size_t size); 22 | void *calloc (size_t nelem, size_t elsize); 23 | void *realloc (void *ptr, size_t size); 24 | 25 | double strtod(const char *restrict nptr, char **restrict endptr); 26 | 27 | int snprintf(char *restrict s, size_t n, const char *restrict format, ...); 28 | int vsnprintf(char *restrict s, size_t n, const char *restrict format, 29 | va_list ap); 30 | #endif 31 | 32 | /*--------------------------------------------------------------------------- 33 | Copyright (c) 2015 Daniel C. Bünzli. 34 | All rights reserved. 35 | 36 | Redistribution and use in source and binary forms, with or without 37 | modification, are permitted provided that the following conditions 38 | are met: 39 | 40 | 1. Redistributions of source code must retain the above copyright 41 | notice, this list of conditions and the following disclaimer. 42 | 43 | 2. Redistributions in binary form must reproduce the above 44 | copyright notice, this list of conditions and the following 45 | disclaimer in the documentation and/or other materials provided 46 | with the distribution. 47 | 48 | 3. Neither the name of Daniel C. Bünzli nor the names of 49 | contributors may be used to endorse or promote products derived 50 | from this software without specific prior written permission. 51 | 52 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 53 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 54 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 55 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 56 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 57 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 58 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 59 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 60 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 61 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 62 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 63 | --------------------------------------------------------------------------*/ 64 | -------------------------------------------------------------------------------- /libc-ocaml/include/string.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #ifndef STRING_H 8 | #define STRING_H 9 | 10 | #include 11 | 12 | int strcmp (const char *s1, const char *s2); 13 | size_t strlen (const char *s); 14 | char *strerror (int errnum); 15 | 16 | int memcmp (const void *s1, const void *s2, size_t n); 17 | void *memcpy (void *restrict dst, const void *restrict src, size_t n); 18 | void *memmove (void *dst, const void *src, size_t n); 19 | void *memset (void *s, int c, size_t n); 20 | 21 | #endif 22 | 23 | /*--------------------------------------------------------------------------- 24 | Copyright (c) 2015 Daniel C. Bünzli. 25 | All rights reserved. 26 | 27 | Redistribution and use in source and binary forms, with or without 28 | modification, are permitted provided that the following conditions 29 | are met: 30 | 31 | 1. Redistributions of source code must retain the above copyright 32 | notice, this list of conditions and the following disclaimer. 33 | 34 | 2. Redistributions in binary form must reproduce the above 35 | copyright notice, this list of conditions and the following 36 | disclaimer in the documentation and/or other materials provided 37 | with the distribution. 38 | 39 | 3. Neither the name of Daniel C. Bünzli nor the names of 40 | contributors may be used to endorse or promote products derived 41 | from this software without specific prior written permission. 42 | 43 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 44 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 45 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 46 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 47 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 48 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 49 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 50 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 51 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 52 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 53 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54 | --------------------------------------------------------------------------*/ 55 | -------------------------------------------------------------------------------- /libc-ocaml/include/sys/stat.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #ifndef STAT_H 8 | #define STAT_H 9 | 10 | #include 11 | 12 | struct stat { 13 | dev_t st_dev; 14 | ino_t st_ino; 15 | mode_t st_mode; 16 | nlink_t st_nlink; 17 | uid_t st_uid; 18 | gid_t st_gid; 19 | dev_t st_rdev; 20 | off_t st_size; 21 | /* 22 | blksize_t st_blksize; 23 | blkcnt_t st_blocks; 24 | */ 25 | time_t st_atime; 26 | time_t st_mtime; 27 | time_t st_ctime; }; 28 | 29 | int stat (const char *restrict path, struct stat *restrict buf); 30 | 31 | #endif 32 | 33 | /*--------------------------------------------------------------------------- 34 | Copyright (c) 2015 Daniel C. Bünzli. 35 | All rights reserved. 36 | 37 | Redistribution and use in source and binary forms, with or without 38 | modification, are permitted provided that the following conditions 39 | are met: 40 | 41 | 1. Redistributions of source code must retain the above copyright 42 | notice, this list of conditions and the following disclaimer. 43 | 44 | 2. Redistributions in binary form must reproduce the above 45 | copyright notice, this list of conditions and the following 46 | disclaimer in the documentation and/or other materials provided 47 | with the distribution. 48 | 49 | 3. Neither the name of Daniel C. Bünzli nor the names of 50 | contributors may be used to endorse or promote products derived 51 | from this software without specific prior written permission. 52 | 53 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 54 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 55 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 56 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 57 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 58 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 59 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 60 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 61 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 62 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 63 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 64 | --------------------------------------------------------------------------*/ 65 | -------------------------------------------------------------------------------- /libc-ocaml/include/sys/ucontext.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | /** ucontext.h stubs */ 8 | 9 | #ifndef UCONTEXT_H 10 | #define UCONTEXT_H 11 | 12 | union sigval { 13 | int sival_int; /* Integer signal value */ 14 | void *sival_ptr; /* Pointer signal value */ 15 | }; 16 | 17 | typedef struct { 18 | int si_signo; /* Signal number */ 19 | int si_code; /* Cause of the signal */ 20 | union sigval si_value; /* Signal value */ 21 | } siginfo_t; 22 | 23 | typedef struct __ucontext ucontext_t; 24 | 25 | #endif 26 | 27 | /*--------------------------------------------------------------------------- 28 | Copyright (c) 2015 Daniel C. Bünzli. 29 | All rights reserved. 30 | 31 | Redistribution and use in source and binary forms, with or without 32 | modification, are permitted provided that the following conditions 33 | are met: 34 | 35 | 1. Redistributions of source code must retain the above copyright 36 | notice, this list of conditions and the following disclaimer. 37 | 38 | 2. Redistributions in binary form must reproduce the above 39 | copyright notice, this list of conditions and the following 40 | disclaimer in the documentation and/or other materials provided 41 | with the distribution. 42 | 43 | 3. Neither the name of Daniel C. Bünzli nor the names of 44 | contributors may be used to endorse or promote products derived 45 | from this software without specific prior written permission. 46 | 47 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 48 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 49 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 50 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 51 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 52 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 53 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 54 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 55 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 56 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 57 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 | --------------------------------------------------------------------------*/ 59 | -------------------------------------------------------------------------------- /libc-ocaml/include/time.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #ifndef TIME_H 8 | #define TIME_H 9 | 10 | #include 11 | 12 | clock_t clock (void); 13 | time_t time (time_t *tloc); 14 | 15 | #endif 16 | 17 | /*--------------------------------------------------------------------------- 18 | Copyright (c) 2015 Daniel C. Bünzli. 19 | All rights reserved. 20 | 21 | Redistribution and use in source and binary forms, with or without 22 | modification, are permitted provided that the following conditions 23 | are met: 24 | 25 | 1. Redistributions of source code must retain the above copyright 26 | notice, this list of conditions and the following disclaimer. 27 | 28 | 2. Redistributions in binary form must reproduce the above 29 | copyright notice, this list of conditions and the following 30 | disclaimer in the documentation and/or other materials provided 31 | with the distribution. 32 | 33 | 3. Neither the name of Daniel C. Bünzli nor the names of 34 | contributors may be used to endorse or promote products derived 35 | from this software without specific prior written permission. 36 | 37 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 38 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 39 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 40 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 41 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 44 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 45 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 46 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 47 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 48 | --------------------------------------------------------------------------*/ 49 | -------------------------------------------------------------------------------- /libc-ocaml/include/unistd.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #ifndef UNISTD_H 8 | #define UNISTD_H 9 | 10 | #include 11 | 12 | int chdir(const char *p); 13 | int unlink (const char *p); 14 | char *getcwd(char *buf, size_t size); 15 | 16 | int close (int fd); 17 | ssize_t read (int fd, void *b, size_t n); 18 | ssize_t write (int fd, const void *b, size_t n); 19 | off_t lseek (int fd, off_t offset, int whence); 20 | 21 | pid_t getpid (void); 22 | pid_t getppid (void); 23 | 24 | #endif 25 | 26 | /*--------------------------------------------------------------------------- 27 | Copyright (c) 2015 Daniel C. Bünzli. 28 | All rights reserved. 29 | 30 | Redistribution and use in source and binary forms, with or without 31 | modification, are permitted provided that the following conditions 32 | are met: 33 | 34 | 1. Redistributions of source code must retain the above copyright 35 | notice, this list of conditions and the following disclaimer. 36 | 37 | 2. Redistributions in binary form must reproduce the above 38 | copyright notice, this list of conditions and the following 39 | disclaimer in the documentation and/or other materials provided 40 | with the distribution. 41 | 42 | 3. Neither the name of Daniel C. Bünzli nor the names of 43 | contributors may be used to endorse or promote products derived 44 | from this software without specific prior written permission. 45 | 46 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 47 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 48 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 49 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 50 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 51 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 52 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 53 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 54 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 55 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | --------------------------------------------------------------------------*/ 58 | -------------------------------------------------------------------------------- /libc-ocaml/src/dirent.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include // for NULL 8 | #include 9 | #include 10 | 11 | DIR *opendir (const char *name) { errno = ENOSYS; return NULL; } 12 | int closedir (DIR *d) { errno = ENOSYS; return -1; } 13 | struct dirent *readdir (DIR *d) { errno = ENOSYS; return NULL; } 14 | 15 | /*--------------------------------------------------------------------------- 16 | Copyright (c) 2015 Daniel C. Bünzli. 17 | All rights reserved. 18 | 19 | Redistribution and use in source and binary forms, with or without 20 | modification, are permitted provided that the following conditions 21 | are met: 22 | 23 | 1. Redistributions of source code must retain the above copyright 24 | notice, this list of conditions and the following disclaimer. 25 | 26 | 2. Redistributions in binary form must reproduce the above 27 | copyright notice, this list of conditions and the following 28 | disclaimer in the documentation and/or other materials provided 29 | with the distribution. 30 | 31 | 3. Neither the name of Daniel C. Bünzli nor the names of 32 | contributors may be used to endorse or promote products derived 33 | from this software without specific prior written permission. 34 | 35 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | --------------------------------------------------------------------------*/ 47 | -------------------------------------------------------------------------------- /libc-ocaml/src/errno.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | 9 | int errno; 10 | 11 | /*--------------------------------------------------------------------------- 12 | Copyright (c) 2015 Daniel C. Bünzli. 13 | All rights reserved. 14 | 15 | Redistribution and use in source and binary forms, with or without 16 | modification, are permitted provided that the following conditions 17 | are met: 18 | 19 | 1. Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 22 | 2. Redistributions in binary form must reproduce the above 23 | copyright notice, this list of conditions and the following 24 | disclaimer in the documentation and/or other materials provided 25 | with the distribution. 26 | 27 | 3. Neither the name of Daniel C. Bünzli nor the names of 28 | contributors may be used to endorse or promote products derived 29 | from this software without specific prior written permission. 30 | 31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 37 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 | --------------------------------------------------------------------------*/ 43 | -------------------------------------------------------------------------------- /libc-ocaml/src/fcntl.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | 10 | int open (const char *path, int oflag, ...) { errno = ENOSYS; return -1; } 11 | int fcntl (int fd, int cmd, ...) { errno = ENOSYS; return -1; } 12 | 13 | /*--------------------------------------------------------------------------- 14 | Copyright (c) 2015 Daniel C. Bünzli. 15 | All rights reserved. 16 | 17 | Redistribution and use in source and binary forms, with or without 18 | modification, are permitted provided that the following conditions 19 | are met: 20 | 21 | 1. Redistributions of source code must retain the above copyright 22 | notice, this list of conditions and the following disclaimer. 23 | 24 | 2. Redistributions in binary form must reproduce the above 25 | copyright notice, this list of conditions and the following 26 | disclaimer in the documentation and/or other materials provided 27 | with the distribution. 28 | 29 | 3. Neither the name of Daniel C. Bünzli nor the names of 30 | contributors may be used to endorse or promote products derived 31 | from this software without specific prior written permission. 32 | 33 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 34 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 35 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 36 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 37 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 38 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 39 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 40 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 41 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 42 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | --------------------------------------------------------------------------*/ 45 | -------------------------------------------------------------------------------- /libc-ocaml/src/newlib-fix.c: -------------------------------------------------------------------------------- 1 | /* FIXME remove, we only have that at the moment because in the current 2 | packaging setting OCaml libasmrun's library is compiled against 3 | newlib's headers. */ 4 | 5 | #include 6 | 7 | void *_impure_ptr; 8 | char *__ctype_ptr__; 9 | int *__errno (void) { return &errno; } 10 | -------------------------------------------------------------------------------- /libc-ocaml/src/setjmp.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | 9 | int setjmp (jmp_buf env) 10 | { 11 | /* We don't do anything. FIXME is this only used for signal handling ? */ 12 | return 0; 13 | } 14 | 15 | /*--------------------------------------------------------------------------- 16 | Copyright (c) 2015 Daniel C. Bünzli. 17 | All rights reserved. 18 | 19 | Redistribution and use in source and binary forms, with or without 20 | modification, are permitted provided that the following conditions 21 | are met: 22 | 23 | 1. Redistributions of source code must retain the above copyright 24 | notice, this list of conditions and the following disclaimer. 25 | 26 | 2. Redistributions in binary form must reproduce the above 27 | copyright notice, this list of conditions and the following 28 | disclaimer in the documentation and/or other materials provided 29 | with the distribution. 30 | 31 | 3. Neither the name of Daniel C. Bünzli nor the names of 32 | contributors may be used to endorse or promote products derived 33 | from this software without specific prior written permission. 34 | 35 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | --------------------------------------------------------------------------*/ 47 | -------------------------------------------------------------------------------- /libc-ocaml/src/signal.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | 10 | void (*signal(int sig, void (*func)(int)))(int) 11 | { 12 | /* Don't do anything. We don't do signals. */ 13 | return 0; 14 | } 15 | 16 | /*--------------------------------------------------------------------------- 17 | Copyright (c) 2015 Daniel C. Bünzli. 18 | All rights reserved. 19 | 20 | Redistribution and use in source and binary forms, with or without 21 | modification, are permitted provided that the following conditions 22 | are met: 23 | 24 | 1. Redistributions of source code must retain the above copyright 25 | notice, this list of conditions and the following disclaimer. 26 | 27 | 2. Redistributions in binary form must reproduce the above 28 | copyright notice, this list of conditions and the following 29 | disclaimer in the documentation and/or other materials provided 30 | with the distribution. 31 | 32 | 3. Neither the name of Daniel C. Bünzli nor the names of 33 | contributors may be used to endorse or promote products derived 34 | from this software without specific prior written permission. 35 | 36 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 37 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 38 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 39 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 40 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 43 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 44 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 45 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 46 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 47 | --------------------------------------------------------------------------*/ 48 | -------------------------------------------------------------------------------- /libc-ocaml/src/stat.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | 10 | int stat (const char *restrict path, struct stat *restrict buf) 11 | { 12 | errno = ENOSYS; return -1; 13 | } 14 | 15 | /*--------------------------------------------------------------------------- 16 | Copyright (c) 2015 Daniel C. Bünzli. 17 | All rights reserved. 18 | 19 | Redistribution and use in source and binary forms, with or without 20 | modification, are permitted provided that the following conditions 21 | are met: 22 | 23 | 1. Redistributions of source code must retain the above copyright 24 | notice, this list of conditions and the following disclaimer. 25 | 26 | 2. Redistributions in binary form must reproduce the above 27 | copyright notice, this list of conditions and the following 28 | disclaimer in the documentation and/or other materials provided 29 | with the distribution. 30 | 31 | 3. Neither the name of Daniel C. Bünzli nor the names of 32 | contributors may be used to endorse or promote products derived 33 | from this software without specific prior written permission. 34 | 35 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | --------------------------------------------------------------------------*/ 47 | -------------------------------------------------------------------------------- /libc-ocaml/src/stdio.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | 10 | int rename (const char *o, const char *n) { errno = ENOSYS; return -1; } 11 | 12 | int fprintf (FILE *restrict s, const char *restrict fmt, ...) 13 | { 14 | errno = ENOSYS; return -1; 15 | } 16 | 17 | int fputc (int c, FILE *s) { errno = ENOSYS; return EOF; } 18 | 19 | int fputs (const char *restrict str, FILE *restrict s) 20 | { 21 | errno = ENOSYS; return EOF; 22 | } 23 | 24 | size_t fwrite(const void *restrict p, size_t size, size_t n, FILE *restrict s) 25 | { 26 | errno = ENOSYS; return 0; 27 | } 28 | 29 | int fflush (FILE *stream) { errno = ENOSYS; return EOF; } 30 | 31 | int sscanf(const char *restrict s, const char *restrict format, ... ) 32 | { 33 | /* N.B. sscanf is only used to parse the environment variable 34 | OCAMLRUNPARAM. Our getenv returns NULL anyway so not implementing. */ 35 | errno = ENOSYS; return EOF; 36 | } 37 | 38 | 39 | /*--------------------------------------------------------------------------- 40 | Copyright (c) 2015 Daniel C. Bünzli. 41 | All rights reserved. 42 | 43 | Redistribution and use in source and binary forms, with or without 44 | modification, are permitted provided that the following conditions 45 | are met: 46 | 47 | 1. Redistributions of source code must retain the above copyright 48 | notice, this list of conditions and the following disclaimer. 49 | 50 | 2. Redistributions in binary form must reproduce the above 51 | copyright notice, this list of conditions and the following 52 | disclaimer in the documentation and/or other materials provided 53 | with the distribution. 54 | 55 | 3. Neither the name of Daniel C. Bünzli nor the names of 56 | contributors may be used to endorse or promote products derived 57 | from this software without specific prior written permission. 58 | 59 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 60 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 61 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 62 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 63 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 64 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 65 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 66 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 67 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 68 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 69 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 70 | --------------------------------------------------------------------------*/ 71 | -------------------------------------------------------------------------------- /libc-ocaml/src/stdlib.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include // for NULL 9 | #include 10 | 11 | extern void halt (int status); 12 | 13 | void abort (void) { exit (255); while (1) ; } 14 | void exit (int status) { halt (status); while (1) ; } 15 | 16 | char *getenv (const char *name) { return NULL; } 17 | 18 | int system (const char *command) 19 | { 20 | if (command == NULL) { return 0; } 21 | else { errno = ENOSYS; return -1; } 22 | } 23 | 24 | /*--------------------------------------------------------------------------- 25 | Copyright (c) 2015 Daniel C. Bünzli. 26 | All rights reserved. 27 | 28 | Redistribution and use in source and binary forms, with or without 29 | modification, are permitted provided that the following conditions 30 | are met: 31 | 32 | 1. Redistributions of source code must retain the above copyright 33 | notice, this list of conditions and the following disclaimer. 34 | 35 | 2. Redistributions in binary form must reproduce the above 36 | copyright notice, this list of conditions and the following 37 | disclaimer in the documentation and/or other materials provided 38 | with the distribution. 39 | 40 | 3. Neither the name of Daniel C. Bünzli nor the names of 41 | contributors may be used to endorse or promote products derived 42 | from this software without specific prior written permission. 43 | 44 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 45 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 46 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 47 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 48 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 49 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 50 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 51 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 52 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 53 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 54 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 55 | --------------------------------------------------------------------------*/ 56 | -------------------------------------------------------------------------------- /libc-ocaml/src/string.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | 10 | int strcmp (const char *s1, const char *s2) 11 | { 12 | while (*s1 != '\x00' && *s1 == *s2) { s1++; s2++; } 13 | return ((unsigned char)*s1) - ((unsigned char)*s2); 14 | } 15 | 16 | size_t strlen (const char *s) 17 | { 18 | const char *start = s; 19 | while (*s) { s++; } 20 | return s - start; 21 | } 22 | 23 | char *strerror (int errnum) 24 | { 25 | // We define strings only for errors that we actually return. 26 | switch (errnum) { 27 | case ENOSYS: return "Function not implemented"; 28 | case ENOMEM: return "Not enough space"; 29 | case EINVAL: return "Invalid argument"; 30 | default: return "Unknown error"; 31 | } 32 | } 33 | 34 | int memcmp (const void *ss1, const void *ss2, size_t n) 35 | { 36 | const char *s1 = ss1; 37 | const char *s2 = ss2; 38 | 39 | while (n) 40 | { 41 | if (*s1 != *s2) { return (*s1 - *s2); } 42 | s1++; s2++; n--; 43 | } 44 | return 0; 45 | } 46 | 47 | void *memcpy (void *restrict ddst, const void *restrict ssrc, size_t n) 48 | { 49 | char *dst = ddst; 50 | const char *src = ssrc; 51 | 52 | while (n) { *dst = *src; dst++; src++; n--; } 53 | return ddst; 54 | } 55 | 56 | void *memmove(void *ddst, const void *ssrc, size_t n) 57 | { 58 | char *dst = ddst; 59 | const char *src = ssrc; 60 | 61 | if (src < dst && dst < src + n) 62 | { 63 | // Backward copy 64 | dst += n; 65 | src += n; 66 | while (n) { dst--; src--; n--; *dst = *src; } 67 | } else { 68 | while (n) { *dst = *src; dst++; src++; n--; } 69 | } 70 | return ddst; 71 | } 72 | 73 | void *memset(void *ss, int cc, size_t n) 74 | { 75 | char *s = ss; 76 | unsigned char c = (unsigned char)cc; 77 | while (n) { *s = c; s++; n--; } 78 | return ss; 79 | } 80 | 81 | /*--------------------------------------------------------------------------- 82 | Copyright (c) 2015 Daniel C. Bünzli. 83 | All rights reserved. 84 | 85 | Redistribution and use in source and binary forms, with or without 86 | modification, are permitted provided that the following conditions 87 | are met: 88 | 89 | 1. Redistributions of source code must retain the above copyright 90 | notice, this list of conditions and the following disclaimer. 91 | 92 | 2. Redistributions in binary form must reproduce the above 93 | copyright notice, this list of conditions and the following 94 | disclaimer in the documentation and/or other materials provided 95 | with the distribution. 96 | 97 | 3. Neither the name of Daniel C. Bünzli nor the names of 98 | contributors may be used to endorse or promote products derived 99 | from this software without specific prior written permission. 100 | 101 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 102 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 103 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 104 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 105 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 106 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 107 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 108 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 109 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 110 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 111 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 112 | --------------------------------------------------------------------------*/ 113 | -------------------------------------------------------------------------------- /libc-ocaml/src/time.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | 10 | clock_t clock (void) { errno = ENOSYS; return 0; } 11 | time_t time (time_t *tloc) { errno = ENOSYS; return (time_t)-1; } 12 | 13 | /*--------------------------------------------------------------------------- 14 | Copyright (c) 2015 Daniel C. Bünzli. 15 | All rights reserved. 16 | 17 | Redistribution and use in source and binary forms, with or without 18 | modification, are permitted provided that the following conditions 19 | are met: 20 | 21 | 1. Redistributions of source code must retain the above copyright 22 | notice, this list of conditions and the following disclaimer. 23 | 24 | 2. Redistributions in binary form must reproduce the above 25 | copyright notice, this list of conditions and the following 26 | disclaimer in the documentation and/or other materials provided 27 | with the distribution. 28 | 29 | 3. Neither the name of Daniel C. Bünzli nor the names of 30 | contributors may be used to endorse or promote products derived 31 | from this software without specific prior written permission. 32 | 33 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 34 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 35 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 36 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 37 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 38 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 39 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 40 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 41 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 42 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | --------------------------------------------------------------------------*/ 45 | -------------------------------------------------------------------------------- /libc-ocaml/src/unistd.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | 10 | int chdir(const char *p) { errno = ENOSYS; return -1; } 11 | int unlink (const char *p) { errno = ENOSYS; return -1; } 12 | char *getcwd(char *buf, size_t size) { errno = ENOSYS; return NULL; } 13 | 14 | int close (int fd) { errno = ENOSYS; return -1; } 15 | ssize_t read(int fd, void *b, size_t n) { errno = ENOSYS; return -1; } 16 | ssize_t write (int fd, const void *b, size_t n) { errno = ENOSYS; return -1; } 17 | off_t lseek (int fd, off_t offset, int whence) { errno = ENOSYS; return -1; } 18 | 19 | pid_t getpid(void) { return 1; } 20 | pid_t getppid(void) { return 0; } 21 | 22 | /*--------------------------------------------------------------------------- 23 | Copyright (c) 2015 Daniel C. Bünzli. 24 | All rights reserved. 25 | 26 | Redistribution and use in source and binary forms, with or without 27 | modification, are permitted provided that the following conditions 28 | are met: 29 | 30 | 1. Redistributions of source code must retain the above copyright 31 | notice, this list of conditions and the following disclaimer. 32 | 33 | 2. Redistributions in binary form must reproduce the above 34 | copyright notice, this list of conditions and the following 35 | disclaimer in the documentation and/or other materials provided 36 | with the distribution. 37 | 38 | 3. Neither the name of Daniel C. Bünzli nor the names of 39 | contributors may be used to endorse or promote products derived 40 | from this software without specific prior written permission. 41 | 42 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 43 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 44 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 45 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 46 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 47 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 48 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 49 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 50 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 51 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 52 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 53 | --------------------------------------------------------------------------*/ 54 | -------------------------------------------------------------------------------- /packages/ocaml-armv7-none-eabihf.4.02.3/files/armv7-none-eabihf.conf.in: -------------------------------------------------------------------------------- 1 | path(armv7_none_eabihf) = "%{prefix}%/armv7-none-eabihf/lib" 2 | destdir(armv7_none_eabihf) = "%{prefix}%/armv7-none-eabihf/lib" 3 | stdlib(armv7_none_eabihf) = "%{prefix}%/armv7-none-eabihf/lib/ocaml" 4 | ocamlc(armv7_none_eabihf) = "%{prefix}%/armv7-none-eabihf/bin/ocamlc" 5 | ocamlopt(armv7_none_eabihf) = "%{prefix}%/armv7-none-eabihf/bin/ocamlopt" 6 | ocamlcp(armv7_none_eabihf) = "%{prefix}%/armv7-none-eabihf/bin/ocamlcp" 7 | ocamlmklib(armv7_none_eabihf) = "%{prefix}%/armv7-none-eabihf/bin/ocamlmklib" 8 | ocamlmktop(armv7_none_eabihf) = "%{prefix}%/armv7-none-eabihf/bin/ocamlmktop" 9 | ocamldep(armv7_none_eabihf) = "%{prefix}%/armv7-none-eabihf/bin/ocamldep" 10 | -------------------------------------------------------------------------------- /packages/ocaml-armv7-none-eabihf.4.02.3/files/bare-include/dirent.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | /** dirent.h stubs */ 8 | 9 | #ifndef DIRENT_H 10 | #define DIRENT_H 11 | 12 | #include 13 | 14 | struct dirent { ino_t d_ino; char d_name[]; }; 15 | typedef int DIR; 16 | 17 | DIR *opendir(const char *); 18 | struct dirent *readdir(DIR *); 19 | int closedir(DIR *); 20 | 21 | #endif 22 | 23 | /*--------------------------------------------------------------------------- 24 | Copyright (c) 2015 Daniel C. Bünzli. 25 | All rights reserved. 26 | 27 | Redistribution and use in source and binary forms, with or without 28 | modification, are permitted provided that the following conditions 29 | are met: 30 | 31 | 1. Redistributions of source code must retain the above copyright 32 | notice, this list of conditions and the following disclaimer. 33 | 34 | 2. Redistributions in binary form must reproduce the above 35 | copyright notice, this list of conditions and the following 36 | disclaimer in the documentation and/or other materials provided 37 | with the distribution. 38 | 39 | 3. Neither the name of Daniel C. Bünzli nor the names of 40 | contributors may be used to endorse or promote products derived 41 | from this software without specific prior written permission. 42 | 43 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 44 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 45 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 46 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 47 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 48 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 49 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 50 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 51 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 52 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 53 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54 | --------------------------------------------------------------------------*/ 55 | -------------------------------------------------------------------------------- /packages/ocaml-armv7-none-eabihf.4.02.3/files/bare-include/sys/ucontext.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | /** ucontext.h stubs */ 8 | 9 | #ifndef UCONTEXT_H 10 | #define UCONTEXT_H 11 | 12 | union sigval { 13 | int sival_int; /* Integer signal value */ 14 | void *sival_ptr; /* Pointer signal value */ 15 | }; 16 | 17 | typedef struct { 18 | int si_signo; /* Signal number */ 19 | int si_code; /* Cause of the signal */ 20 | union sigval si_value; /* Signal value */ 21 | } siginfo_t; 22 | 23 | typedef struct __ucontext ucontext_t; 24 | 25 | #endif 26 | 27 | /*--------------------------------------------------------------------------- 28 | Copyright (c) 2015 Daniel C. Bünzli. 29 | All rights reserved. 30 | 31 | Redistribution and use in source and binary forms, with or without 32 | modification, are permitted provided that the following conditions 33 | are met: 34 | 35 | 1. Redistributions of source code must retain the above copyright 36 | notice, this list of conditions and the following disclaimer. 37 | 38 | 2. Redistributions in binary form must reproduce the above 39 | copyright notice, this list of conditions and the following 40 | disclaimer in the documentation and/or other materials provided 41 | with the distribution. 42 | 43 | 3. Neither the name of Daniel C. Bünzli nor the names of 44 | contributors may be used to endorse or promote products derived 45 | from this software without specific prior written permission. 46 | 47 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 48 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 49 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 50 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 51 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 52 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 53 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 54 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 55 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 56 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 57 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 | --------------------------------------------------------------------------*/ 59 | -------------------------------------------------------------------------------- /packages/ocaml-armv7-none-eabihf.4.02.3/files/config/.ignore: -------------------------------------------------------------------------------- 1 | m.h 2 | s.h 3 | Makefile 4 | -------------------------------------------------------------------------------- /packages/ocaml-armv7-none-eabihf.4.02.3/files/config/Makefile.in: -------------------------------------------------------------------------------- 1 | PREFIX=%{prefix}%/armv7-none-eabihf 2 | BINDIR=$(PREFIX)/bin 3 | LIBDIR=$(PREFIX)/lib/ocaml 4 | STUBLIBDIR=$(LIBDIR)/stublibs 5 | MANDIR=$(PREFIX)/man 6 | MANEXT=1 7 | CAMLRUN=%{bin}%/ocamlrun # build-os binaries 8 | CAMLYACC=%{bin}%/ocamlyacc # build-os binaries 9 | RANLIB=arm-none-eabi-ranlib 10 | RANLIBCMD=arm-none-eabi-ranlib 11 | ARCMD=arm-none-eabi-ar 12 | SHARPBANGSCRIPTS=true 13 | UNIX_OR_WIN32=unix 14 | UNIXLIB=unix 15 | GRAPHLIB=graph 16 | BNG_ARCH=generic 17 | BNG_ASM_LEVEL=0 18 | PTHREAD_LINK= 19 | PTHREAD_CAML_LINK= 20 | X11_INCLUDES=not found 21 | X11_LINK=not found 22 | LIBBFD_LINK= 23 | 24 | # FIXME eventually we should use -nostdinc, have a proper 25 | # libc-ocaml-bare package and fetch headers from there. 26 | BARE_SYS_CCOPTS= -nostartfiles -nodefaultlibs -nostdlib \ 27 | -march=armv7-a -mtune=cortex-a7 \ 28 | -mfpu=neon-vfpv4 -mfloat-abi=hard 29 | 30 | BYTECC=arm-none-eabi-gcc $(BARE_SYS_CCOPTS) 31 | BYTECCCOMPOPTS=-I ../bare-include -O -fno-defer-pop -Wall -D_FILE_OFFSET_BITS=64 32 | BYTECCLINKOPTS= 33 | BYTECCLIBS= 34 | BYTECCRPATH= 35 | EXE= 36 | SUPPORTS_SHARED_LIBRARIES=false 37 | SHAREDCCCOMPOPTS=-O 38 | MKSHAREDLIBRPATH= 39 | NATDYNLINKOPTS= 40 | SYSLIB=-l$(1) 41 | #ml let syslib x = "-l"^x;; 42 | 43 | ### How to build a static library 44 | MKLIB=arm-none-eabi-ar rc $(1) $(2); arm-none-eabi-ranlib $(1) 45 | #ml let mklib out files opts = Printf.sprintf "arm-none-eabi-ar rc %s %s %s; arm-none-eabi-ranlib %s" out opts files out;; 46 | ARCH=arm 47 | MODEL=armv7l 48 | SYSTEM=linux_eabihf 49 | NATIVECC=$(BYTECC) 50 | NATIVECCCOMPOPTS=-I ../bare-include -O -Wall -D_FILE_OFFSET_BITS=64 51 | NATIVECCPROFOPTS=-I ../bare-include -O -Wall -D_FILE_OFFSET_BITS=64 52 | NATIVECCLINKOPTS= 53 | NATIVECCRPATH= 54 | NATIVECCLIBS= 55 | ASM=arm-none-eabi-as 56 | ASPP=$(BYTECC) -c 57 | ASPPPROFFLAGS=-DPROFILING 58 | PROFILING=prof 59 | DYNLINKOPTS= -ldl 60 | OTHERLIBRARIES=str num bigarray 61 | CC_PROFILE=-pg 62 | SYSTHREAD_SUPPORT=false 63 | PARTIALLD=arm-none-eabi-ld -r 64 | PACKLD=$(PARTIALLD) $(NATIVECCLINKOPTS) -o 65 | DLLCCCOMPOPTS= 66 | IFLEXDIR= 67 | O=o 68 | A=a 69 | SO=so 70 | EXT_OBJ=.o 71 | EXT_ASM=.s 72 | EXT_LIB=.a 73 | EXT_DLL=.so 74 | EXTRALIBS= 75 | CCOMPTYPE=cc 76 | TOOLCHAIN=cc 77 | NATDYNLINK=false 78 | CMXS=cmxa 79 | MKEXE=$(BYTECC) 80 | MKEXEDEBUGFLAG=-g 81 | MKDLL= 82 | MKMAINDLL= 83 | RUNTIMED=runtimed 84 | SHARED=noshared 85 | #WITH_DEBUGGER=ocamldebugger 86 | #WITH_OCAMLDOC=ocamldoc 87 | #WITH_OCAMLBUILD=ocamlbuild 88 | ASM_CFI_SUPPORTED=true 89 | WITH_FRAME_POINTERS=false 90 | TARGET=armv7l-unknown-linux-gnueabihf 91 | 92 | # Additional rules 93 | # 94 | # The build procedure below is identical to the one of OCaml except in 95 | # a few cases (but because of deps specifications we end up rewriting more 96 | # than needed). Hacking the build system directly would better but 97 | # conditional build artefacts seem to be quite heavy to implement. 98 | # 99 | # What we want to do is 100 | # 101 | # make world 102 | # make opt 103 | # make install 104 | # 105 | # However there are cases when C executable are produced with the gcc cross 106 | # compiling toolchain and thus ask for a concrete libc for the host-os 107 | # which we don't want to provide for now. Fundamentally this is simply: 108 | # 109 | # * byterun/Makefile all: should not build ocamlyacc and ocamlrun 110 | # * Makefile coreall: do not rebuild ocamlyacc or ocamllex 111 | # * othertools/Makefile all: should not build objinfo because it compiles an 112 | # objinfo_helper C program. 113 | 114 | bare-coldstart: 115 | cd byterun; $(MAKE) ld.conf libcamlrun.a libcamlrund.a 116 | cd stdlib; $(MAKE) COMPILER=../boot/ocamlc all 117 | cd stdlib; cp $(LIBFILES) ../boot 118 | ln -sf ../byterun/libcamlrun.a boot/libcamlrun.a 119 | ln -sf ../byterun/caml stdlib/caml 120 | 121 | # remove compilation of ocamlyacc and ocamlrun 122 | bare-runtime: 123 | cd byterun; $(MAKE) libcamlrun.a libcamlrund.a 124 | ln -sf ../byterun/libcamlrun.a stdlib/libcamlrun.a 125 | 126 | # Target ocamltools: remove compilation of objinfo as it needs 127 | # ocamlobjinfo_helper which compiles to a C native code executable 128 | # and thus wants a libc 129 | bare-coreall: 130 | $(MAKE) ocamlc 131 | cd tools; $(MAKE) ocamldep ocamlprof ocamlcp ocamloptp ocamlmktop \ 132 | ocamlmklib dumpobj read_cmt 133 | $(MAKE) library 134 | 135 | bare-all: 136 | $(MAKE) bare-runtime 137 | $(MAKE) bare-coreall 138 | $(MAKE) ocaml 139 | cd otherlibs/unix && make unix.cmi # for bigarray 140 | for i in $(OTHERLIBRARIES); do \ 141 | (cd otherlibs/$$i; $(MAKE) all) || exit $$?; \ 142 | done 143 | 144 | bare-world: 145 | $(MAKE) bare-coldstart 146 | $(MAKE) bare-all 147 | 148 | bare: 149 | $(MAKE) bare-world 150 | $(MAKE) opt 151 | 152 | # Fake existence of what we didn't compile so that install 153 | # doesn't fail and use the build-os ocamllex. 154 | bare-install: 155 | touch byterun/ocamlrund 156 | touch lex/ocamllex 157 | touch tools/objinfo 158 | touch tools/objinfo_helper 159 | $(MAKE) install 160 | rm $(INSTALL_BINDIR)/ocamlobjinfo$(EXE) # Fake 161 | cp $(CAMLYACC) $(INSTALL_BINDIR)/ocamlyacc$(EXE) # Use build-os 162 | cp %{bin}%/ocamllex \ 163 | $(INSTALL_BINDIR)/ocamllex$(EXE) # Use build-os 164 | cp otherlibs/unix/unix.cmi $(INSTALL_LIBDIR)/ # for bigarray 165 | -------------------------------------------------------------------------------- /packages/ocaml-armv7-none-eabihf.4.02.3/files/config/m.h: -------------------------------------------------------------------------------- 1 | #undef ARCH_SIXTYFOUR 2 | #define SIZEOF_INT 4 3 | #define SIZEOF_LONG 4 4 | #define SIZEOF_PTR 4 5 | #define SIZEOF_SHORT 2 6 | #define SIZEOF_LONGLONG 8 7 | #undef ARCH_BIG_ENDIAN 8 | #define ARCH_ALIGN_DOUBLE 9 | #define ARCH_ALIGN_INT64 10 | #undef NONSTANDARD_DIV_MOD 11 | #define ASM_CFI_SUPPORTED 12 | -------------------------------------------------------------------------------- /packages/ocaml-armv7-none-eabihf.4.02.3/files/config/s.h: -------------------------------------------------------------------------------- 1 | 2 | #define OCAML_OS_TYPE "Unix" 3 | #define OCAML_STDLIB_DIR "." 4 | //#define POSIX_SIGNALS 5 | #define HAS_C99_FLOAT_OPS 6 | //#define HAS_GETRUSAGE 7 | //#define HAS_TIMES 8 | //#define HAS_SOCKETS 9 | //#define HAS_SOCKLEN_T 10 | //#define HAS_INET_ATON 11 | //#define HAS_IPV6 12 | #define HAS_UNISTD 13 | //#define HAS_OFF_T 14 | #define HAS_DIRENT 15 | //#define HAS_REWINDDIR 16 | //#define HAS_LOCKF 17 | //#define HAS_MKFIFO 18 | #define HAS_GETCWD 19 | //#define HAS_GETWD 20 | //#define HAS_GETPRIORITY 21 | //#define HAS_UTIME 22 | //#define HAS_UTIMES 23 | //#define HAS_DUP2 24 | //#define HAS_FCHMOD 25 | //#define HAS_TRUNCATE 26 | //#define HAS_SYS_SELECT_H 27 | //#define HAS_SELECT 28 | //#define HAS_SYMLINK 29 | //#define HAS_WAITPID 30 | //#define HAS_WAIT4 31 | //#define HAS_GETGROUPS 32 | //#define HAS_SETGROUPS 33 | //#define HAS_INITGROUPS 34 | //#define HAS_TERMIOS 35 | //#define HAS_ASYNC_IO 36 | //#define HAS_SETITIMER 37 | //#define HAS_GETHOSTNAME 38 | //#define HAS_UNAME 39 | //#define HAS_GETTIMEOFDAY 40 | //#define HAS_MKTIME 41 | //#define HAS_SETSID 42 | //#define HAS_PUTENV 43 | //#define HAS_LOCALE 44 | //#define HAS_MMAP 45 | //#define HAS_PWRITE 46 | //#define HAS_NANOSECOND_STAT 1 47 | //#define HAS_GETHOSTBYNAME_R 6 48 | //#define HAS_GETHOSTBYADDR_R 8 49 | //#define HAS_MKSTEMP 50 | //#define HAS_NICE 51 | -------------------------------------------------------------------------------- /packages/ocaml-armv7-none-eabihf.4.02.3/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "daniel.buenzl i@erratique.ch" 3 | authors: "The OCaml development team" 4 | homepage: "http://ocaml.org" 5 | bug-reports: "https://github.com/ocaml/opam-repository/issues" 6 | dev-repo: "git+https://github.com/ocaml/ocaml.git" 7 | license: "LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception" 8 | substs: ["armv7-none-eabihf.conf" "config/Makefile"] 9 | 10 | build: [[ make "bare" ]] 11 | 12 | install: [ 13 | [ make "bare-install" ] 14 | 15 | # Copy base OCaml system META files 16 | [ "cp" "-r" "%{prefix}%/lib/bigarray" "%{prefix}%/armv7-none-eabihf/lib" ] 17 | [ "cp" "-r" "%{prefix}%/lib/bytes" "%{prefix}%/armv7-none-eabihf/lib" ] 18 | [ "cp" "-r" "%{prefix}%/lib/compiler-libs" "%{prefix}%/armv7-none-eabihf/lib" ] 19 | [ "cp" "-r" "%{prefix}%/lib/compiler-libs" "%{prefix}%/armv7-none-eabihf/lib" ] 20 | [ "cp" "-r" "%{prefix}%/lib/findlib" "%{prefix}%/armv7-none-eabihf/lib" ] 21 | [ "cp" "-r" "%{prefix}%/lib/num" "%{prefix}%/armv7-none-eabihf/lib" ] 22 | [ "cp" "-r" "%{prefix}%/lib/num-top" "%{prefix}%/armv7-none-eabihf/lib" ] 23 | [ "cp" "-r" "%{prefix}%/lib/stdlib" "%{prefix}%/armv7-none-eabihf/lib" ] 24 | [ "cp" "-r" "%{prefix}%/lib/str" "%{prefix}%/armv7-none-eabihf/lib" ] 25 | [ # For unix.cmi needed by bigarrays the unix library itself is not available. 26 | "cp" "-r" "%{prefix}%/lib/unix" "%{prefix}%/armv7-none-eabihf/lib" ] 27 | [ # We don't heave threads but otherwise ocamlfind complains 28 | "cp" "-r" "%{prefix}%/lib/threads" "%{prefix}%/armv7-none-eabihf/lib" ] 29 | 30 | [ "mkdir" "-p" "%{prefix}%/lib/findlib.conf.d" ] 31 | [ "cp" "armv7-none-eabihf.conf" "%{prefix}%/lib/findlib.conf.d/" ] 32 | ] 33 | 34 | remove: [ 35 | [ "rm" "-f" "%{prefix}%/armv7-none-eabihf/bin/ocaml" ] 36 | [ "rm" "-f" "%{prefix}%/armv7-none-eabihf/bin/ocamlc" ] 37 | [ "rm" "-f" "%{prefix}%/armv7-none-eabihf/bin/ocamlcp" ] 38 | [ "rm" "-f" "%{prefix}%/armv7-none-eabihf/bin/ocamldep" ] 39 | [ "rm" "-f" "%{prefix}%/armv7-none-eabihf/bin/ocamllex" ] 40 | [ "rm" "-f" "%{prefix}%/armv7-none-eabihf/bin/ocamlmklib" ] 41 | [ "rm" "-f" "%{prefix}%/armv7-none-eabihf/bin/ocamlmktop" ] 42 | [ "rm" "-f" "%{prefix}%/armv7-none-eabihf/bin/ocamlopt" ] 43 | [ "rm" "-f" "%{prefix}%/armv7-none-eabihf/bin/ocamloptp" ] 44 | [ "rm" "-f" "%{prefix}%/armv7-none-eabihf/bin/ocamlprof" ] 45 | [ "rm" "-f" "%{prefix}%/armv7-none-eabihf/bin/ocamlrun" ] 46 | [ "rm" "-f" "%{prefix}%/armv7-none-eabihf/bin/ocamlrund" ] 47 | [ "rm" "-f" "%{prefix}%/armv7-none-eabihf/bin/ocamlyacc" ] 48 | [ "rm" "-rf" "%{prefix}%/armv7-none-eabihf/lib/ocaml" ] 49 | [ "rm" "-f" "%{prefix}%/lib/findlib.conf.d/armv7-none-eabihf.conf" ] 50 | ] 51 | 52 | depends: [ "ocaml" {= "4.02.3"} "ocaml-variants" {= "4.02.3+32bit"} "ocamlfind" {>= "1.5.4"} ] 53 | 54 | depexts: [ 55 | ["gcc-arm-none-eabi"] {os-distribution = "debian"} 56 | ["gcc-arm-none-eabi"] {os-distribution = "ubuntu"} 57 | ["armmbed/formulae/arm-none-eabi-gcc"] 58 | {os = "macos" & os-distribution = "homebrew"} 59 | ] 60 | 61 | available: arch = "x86_32" 62 | synopsis: "OCaml cross-compiler for bare 32-bit armv7 with hard float" 63 | description: "You will need to provide your own libc." 64 | flags: light-uninstall 65 | extra-files: [ 66 | ["armv7-none-eabihf.conf.in" "md5=6047e37c327dfba75e6e477d320a397e"] 67 | ["bare-include/dirent.h" "md5=b74610472bb2dfecb2ef8bb32f348b7c"] 68 | ["bare-include/sys/ucontext.h" "md5=3d9ae92600c9d0835043a380a927ae63"] 69 | ["config/s.h" "md5=948414d3fc50fedd5dc3efa08e56c39b"] 70 | ["config/m.h" "md5=85c754520e42cc7daefa470c66e057cc"] 71 | ["config/Makefile.in" "md5=ad4a3552357d7db3829c2d83e1230c4c"] 72 | ["config/.ignore" "md5=32c2851983acb5ab6bc1a2fe42357e8c"] 73 | ] 74 | url { 75 | src: "http://caml.inria.fr/pub/distrib/ocaml-4.02/ocaml-4.02.3.tar.gz" 76 | checksum: "md5=ef1a324608c97031cbd92a442d685ab7" 77 | } 78 | -------------------------------------------------------------------------------- /repo: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | -------------------------------------------------------------------------------- /rpi-boot-ocaml.ld: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2014 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | START_ADDR = 0x8000; /* RPi Bootloader expects to start here */ 8 | PAGE_SIZE = 4096; 9 | 10 | ENTRY (_start) 11 | SECTIONS { 12 | . = START_ADDR; 13 | _kernel_start = .; 14 | .text : { KEEP (*(.boot)) *(.text) } 15 | . = ALIGN (PAGE_SIZE); 16 | 17 | .rodata : { *(.rodata) } 18 | . = ALIGN (PAGE_SIZE); 19 | 20 | .data : { *(.data) } 21 | . = ALIGN (PAGE_SIZE); 22 | 23 | _bss_start = .; 24 | .bss : { *(.bss) *(.bss*) /* FIXME the latter for newlib only why ? */ } 25 | _bss_end = .; 26 | . = ALIGN (PAGE_SIZE); 27 | 28 | _stack_start = .; 29 | . = _stack_start + 1024 * 1024; /* FIXME what's a good value here ? */ 30 | _stack_end = .; 31 | . = ALIGN (PAGE_SIZE); 32 | 33 | _kernel_end = .; 34 | } 35 | 36 | /*--------------------------------------------------------------------------- 37 | Copyright (c) 2014 Daniel C. Bünzli. 38 | All rights reserved. 39 | 40 | Redistribution and use in source and binary forms, with or without 41 | modification, are permitted provided that the following conditions 42 | are met: 43 | 44 | 1. Redistributions of source code must retain the above copyright 45 | notice, this list of conditions and the following disclaimer. 46 | 47 | 2. Redistributions in binary form must reproduce the above 48 | copyright notice, this list of conditions and the following 49 | disclaimer in the documentation and/or other materials provided 50 | with the distribution. 51 | 52 | 3. Neither the name of Daniel C. Bünzli nor the names of 53 | contributors may be used to endorse or promote products derived 54 | from this software without specific prior written permission. 55 | 56 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 57 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 58 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 59 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 60 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 61 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 62 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 63 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 64 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 65 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 66 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 67 | --------------------------------------------------------------------------*/ 68 | -------------------------------------------------------------------------------- /src-boot/boot.S: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | .section .boot 8 | .globl _start 9 | 10 | // In the following we preserve the r0, r1, r2 registers as they have 11 | // info from the GPU bootloader. 12 | 13 | _start: 14 | 15 | // Enable L1 data and instruction cache and branch prediction 16 | enable_l1_cache: 17 | mrc p15, 0, r3, c1, c0, 0 18 | orr r3, #0x00000004 19 | orr r3, #0x00001800 20 | mcr p15, 0, r3, c1, c0, 0 21 | 22 | // Enable Neon MPE (see ARM's Neon programmer's guide §2.1.7) 23 | enable_neon: 24 | mrc p15, 0, r3, c1, c0, 2 25 | orr r3, #0x00F00000 26 | mcr p15, 0, r3, c1, c0, 2 27 | isb 28 | mov r3, #0x40000000 29 | vmsr fpexc, r3 30 | 31 | // Clear bss segment 32 | bss_clear: 33 | ldr r3, =_bss_start 34 | ldr r4, =_bss_end 35 | mov r5, #0 36 | mov r6, #0 37 | mov r7, #0 38 | mov r8, #0 39 | b bss_test_end 40 | 41 | bss_clear_addr: 42 | stmia r3!, {r5-r8} 43 | 44 | bss_test_end: 45 | cmp r3, r4 46 | blo bss_clear_addr 47 | 48 | // Setup C stack, execute the C _startup function and never come again 49 | exec_startup: 50 | ldr sp, =_stack_end 51 | ldr r3, =_startup 52 | blx r3 53 | 54 | /*--------------------------------------------------------------------------- 55 | Copyright (c) 2015 Daniel C. Bünzli. 56 | All rights reserved. 57 | 58 | Redistribution and use in source and binary forms, with or without 59 | modification, are permitted provided that the following conditions 60 | are met: 61 | 62 | 1. Redistributions of source code must retain the above copyright 63 | notice, this list of conditions and the following disclaimer. 64 | 65 | 2. Redistributions in binary form must reproduce the above 66 | copyright notice, this list of conditions and the following 67 | disclaimer in the documentation and/or other materials provided 68 | with the distribution. 69 | 70 | 3. Neither the name of Daniel C. Bünzli nor the names of 71 | contributors may be used to endorse or promote products derived 72 | from this software without specific prior written permission. 73 | 74 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 75 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 76 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 77 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 78 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 79 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 80 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 81 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 82 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 83 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 84 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 85 | --------------------------------------------------------------------------*/ 86 | -------------------------------------------------------------------------------- /src-boot/sbrk.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | 10 | // FIXME heap_max size should set to the ARM/GPU memory split which we 11 | // can get throught the mailbox. Currently we'll happily overwite gpu 12 | // memory since heap_max is at rpi_mmio_base. As it is a bit painful 13 | // to interact with the mailbox before we get into OCaml we should 14 | // simply setup a reasonable amout for heap_max for the OCaml init 15 | // and then set it to the ARM/GPU split in the Rpi module. 16 | 17 | extern unsigned int _kernel_end; // Defined by the linker script 18 | extern uint32_t rpi_mmio_base; // See startup.c 19 | 20 | // Returns a pointer to the *start* of new allocated space 21 | void *sbrk (int incr) 22 | { 23 | static char *heap_end = (char *)(&_kernel_end); 24 | char *heap_max = (char *)(rpi_mmio_base - 1); 25 | 26 | char *ptr; 27 | 28 | if (heap_end + incr <= heap_max) 29 | { 30 | ptr = heap_end; 31 | heap_end += incr; 32 | return (void *)ptr; 33 | } else { 34 | errno = ENOMEM; 35 | return (void *)(-1); 36 | } 37 | } 38 | 39 | /*--------------------------------------------------------------------------- 40 | Copyright (c) 2015 Daniel C. Bünzli. 41 | All rights reserved. 42 | 43 | Redistribution and use in source and binary forms, with or without 44 | modification, are permitted provided that the following conditions 45 | are met: 46 | 47 | 1. Redistributions of source code must retain the above copyright 48 | notice, this list of conditions and the following disclaimer. 49 | 50 | 2. Redistributions in binary form must reproduce the above 51 | copyright notice, this list of conditions and the following 52 | disclaimer in the documentation and/or other materials provided 53 | with the distribution. 54 | 55 | 3. Neither the name of Daniel C. Bünzli nor the names of 56 | contributors may be used to endorse or promote products derived 57 | from this software without specific prior written permission. 58 | 59 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 60 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 61 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 62 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 63 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 64 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 65 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 66 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 67 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 68 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 69 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 70 | --------------------------------------------------------------------------*/ 71 | -------------------------------------------------------------------------------- /src-boot/startup.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | #include 9 | 10 | extern void caml_startup (char **argv); 11 | 12 | // Defined by the initial boot registers, we just save them. 13 | volatile uint32_t rpi_boot_dev; // boot device code (usually 0) 14 | volatile uint32_t rpi_arm_machine; // ARM machine type 15 | volatile uint32_t rpi_hw; // atags or device tree address 16 | 17 | // Memory mapped IO base for Rpi2, FIXME this should not be hardcoded. 18 | volatile uint32_t rpi_mmio_base = 0x3F000000; 19 | 20 | void halt (int status) 21 | { 22 | if (status == 0) { while (1) { __asm ("wfe"); } } else 23 | { 24 | while (1) 25 | { 26 | // Flash ACT led 27 | *(volatile uint32_t *)(rpi_mmio_base + 0x00200020) = (1 << 15); 28 | for (volatile int i = 0; i < 60000; i++) ; 29 | *(volatile uint32_t *)(rpi_mmio_base + 0x0020002C) = (1 << 15); 30 | for (volatile int i = 0; i < 60000; i++) ; 31 | } 32 | } 33 | } 34 | 35 | void _startup (uint32_t boot_dev, uint32_t arm_machine, uint32_t hw) 36 | { 37 | rpi_boot_dev = boot_dev; 38 | rpi_arm_machine = arm_machine; 39 | rpi_hw = hw; 40 | 41 | static char *argv[2] = { "rpi-boot-ocaml", NULL }; 42 | caml_startup (argv); // If uncaught exn, this calls exit(2) 43 | halt (0); 44 | } 45 | 46 | /*--------------------------------------------------------------------------- 47 | Copyright (c) 2015 Daniel C. Bünzli. 48 | All rights reserved. 49 | 50 | Redistribution and use in source and binary forms, with or without 51 | modification, are permitted provided that the following conditions 52 | are met: 53 | 54 | 1. Redistributions of source code must retain the above copyright 55 | notice, this list of conditions and the following disclaimer. 56 | 57 | 2. Redistributions in binary form must reproduce the above 58 | copyright notice, this list of conditions and the following 59 | disclaimer in the documentation and/or other materials provided 60 | with the distribution. 61 | 62 | 3. Neither the name of Daniel C. Bünzli nor the names of 63 | contributors may be used to endorse or promote products derived 64 | from this software without specific prior written permission. 65 | 66 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 67 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 68 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 69 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 70 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 71 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 72 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 73 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 74 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 75 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 76 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 77 | --------------------------------------------------------------------------*/ 78 | -------------------------------------------------------------------------------- /src/fb.ml: -------------------------------------------------------------------------------- 1 | (*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | ---------------------------------------------------------------------------*) 6 | 7 | open Rpi 8 | 9 | let strf = Format.asprintf 10 | 11 | let tag_allocate_buffer = 0x40001l 12 | let tag_release_buffer = 0x48001l 13 | let tag_blank_screen = 0x40002l 14 | 15 | let tag_phys_wh = 0x40003l 16 | let tag_virt_wh = 0x40004l 17 | let tag_depth = 0x40005l 18 | let tag_pixel_order = 0x40006l 19 | let tag_alpha_mode = 0x40007l 20 | let tag_pitch = 0x40008l 21 | let tag_virt_offset = 0x40009l 22 | let tag_overscan = 0x4000al 23 | let tag_palette = 0x4000bl 24 | 25 | type op = Get | Test | Set 26 | 27 | let tag_op op t = match op with 28 | | Get -> t 29 | | Test -> Int32.logor t 0x04000l 30 | | Set -> Int32.logor t 0x08000l 31 | 32 | let get_size () = 33 | let phys_wh = Mbox.Prop.(req tag_phys_wh ~resp:int_pair) in 34 | match Mbox.Prop.(send [r phys_wh]) with 35 | | `Error _ as e -> e 36 | | `Ok resp -> 37 | match Mbox.Prop.find resp phys_wh with 38 | | `Error _ as e -> e 39 | | `Ok None -> `Error (`Msg "framebuffer size undefined") 40 | | `Ok (Some s) -> `Ok s 41 | 42 | let set_phys_wh w h = 43 | Mbox.Prop.(req (tag_op Set tag_phys_wh) ~args:[w;h] ~resp:int_pair) 44 | 45 | let set_virt_wh w h = 46 | Mbox.Prop.(req (tag_op Set tag_virt_wh) ~args:[w;h] ~resp:int_pair) 47 | 48 | let set_bpp bpp = 49 | Mbox.Prop.(req (tag_op Set tag_depth) ~args:[bpp] ~resp:int) 50 | 51 | let get_pitch = 52 | Mbox.Prop.(req tag_pitch ~resp:int32) 53 | 54 | let alloc_buffer = 55 | Mbox.Prop.(req tag_allocate_buffer ~args:[1l] ~resp:int32_pair) 56 | 57 | let request_fb w h bpp = 58 | let w, h, bpp = Int32.(of_int w, of_int h, of_int bpp) in 59 | let pwh = set_phys_wh w h in 60 | let vwh = set_virt_wh w h in 61 | let bpp = set_bpp bpp in 62 | let buf = alloc_buffer in 63 | let pitch = get_pitch in 64 | let reqs = Mbox.Prop.[r pwh; r vwh; r bpp; r buf; r pitch] in 65 | match Mbox.Prop.(send reqs) with 66 | | `Error _ as e -> e 67 | | `Ok resp -> 68 | match Mbox.Prop.find resp pitch with 69 | | `Error (`Msg m) -> failwith m 70 | | `Ok None -> failwith "framebuffer pitch undefined" 71 | | `Ok (Some pitch) -> 72 | match Mbox.Prop.find resp buf with 73 | | `Error (`Msg m) -> failwith m 74 | | `Ok None -> failwith "framebuffer buffer undefined" 75 | | `Ok (Some (a, l)) -> 76 | `Ok (Mem.of_int32 a, Int32.to_int l, Int32.to_int pitch) 77 | 78 | type t = 79 | { w : int; h : int; stride : int; 80 | bpp : int; buffer : Mem.Map.bytes; } 81 | 82 | let bus_address_to_arm_physical addr = Nativeint.sub addr 0xC0000000n 83 | 84 | let init ~bpp = match get_size () with 85 | | `Error _ as e -> e 86 | | `Ok (w, h) -> 87 | match request_fb w h bpp with 88 | | `Error _ as e -> e 89 | | `Ok (addr, len, stride) -> 90 | let addr = bus_address_to_arm_physical addr in 91 | let buffer = Mem.Map.bytes addr ~len in 92 | `Ok { w; h; stride; bpp; buffer } 93 | 94 | let w fb = fb.w 95 | let h fb = fb.h 96 | let stride fb = fb.stride 97 | let bpp fb = fb.bpp 98 | let buffer fb = fb.buffer 99 | let addr fb = Mem.Map.base fb.buffer 100 | 101 | (*--------------------------------------------------------------------------- 102 | Copyright (c) 2015 Daniel C. Bünzli. 103 | All rights reserved. 104 | 105 | Redistribution and use in source and binary forms, with or without 106 | modification, are permitted provided that the following conditions 107 | are met: 108 | 109 | 1. Redistributions of source code must retain the above copyright 110 | notice, this list of conditions and the following disclaimer. 111 | 112 | 2. Redistributions in binary form must reproduce the above 113 | copyright notice, this list of conditions and the following 114 | disclaimer in the documentation and/or other materials provided 115 | with the distribution. 116 | 117 | 3. Neither the name of Daniel C. Bünzli nor the names of 118 | contributors may be used to endorse or promote products derived 119 | from this software without specific prior written permission. 120 | 121 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 122 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 123 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 124 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 125 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 126 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 127 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 128 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 129 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 130 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 131 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 132 | ---------------------------------------------------------------------------*) 133 | -------------------------------------------------------------------------------- /src/fb.mli: -------------------------------------------------------------------------------- 1 | (*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | ---------------------------------------------------------------------------*) 6 | 7 | (** Framebuffer access example. *) 8 | 9 | open Rpi 10 | 11 | type t 12 | val init : bpp:int -> t result 13 | val w : t -> int 14 | val h : t -> int 15 | val bpp : t -> int 16 | val stride : t -> int 17 | val buffer : t -> Mem.Map.bytes 18 | val addr : t -> Mem.addr 19 | 20 | (*--------------------------------------------------------------------------- 21 | Copyright (c) 2015 Daniel C. Bünzli. 22 | All rights reserved. 23 | 24 | Redistribution and use in source and binary forms, with or without 25 | modification, are permitted provided that the following conditions 26 | are met: 27 | 28 | 1. Redistributions of source code must retain the above copyright 29 | notice, this list of conditions and the following disclaimer. 30 | 31 | 2. Redistributions in binary form must reproduce the above 32 | copyright notice, this list of conditions and the following 33 | disclaimer in the documentation and/or other materials provided 34 | with the distribution. 35 | 36 | 3. Neither the name of Daniel C. Bünzli nor the names of 37 | contributors may be used to endorse or promote products derived 38 | from this software without specific prior written permission. 39 | 40 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 41 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 42 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 43 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 44 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 46 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 47 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 48 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 49 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 50 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 51 | ---------------------------------------------------------------------------*) 52 | -------------------------------------------------------------------------------- /src/main.ml: -------------------------------------------------------------------------------- 1 | (*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | ---------------------------------------------------------------------------*) 6 | 7 | open Rpi 8 | 9 | let activity_led = Gpio.P47 10 | 11 | let draw_image fb (w, h, s) = 12 | let start_x, start_y = (Fb.w fb - w) / 2, (Fb.h fb - h) / 2 in 13 | let x_stride, y_stride = 4, Fb.stride fb in 14 | let buf = Fb.buffer fb in 15 | for y = 0 to h - 1 do 16 | let k = (start_y + y) * y_stride in 17 | let i = y * (w * 3) in 18 | for x = 0 to w - 1 do 19 | let k = k + (start_x + x) * x_stride in 20 | let i = i + x * 3 in 21 | let b = Char.code (String.unsafe_get s (i )) in 22 | let g = Char.code (String.unsafe_get s (i + 1)) in 23 | let r = Char.code (String.unsafe_get s (i + 2)) in 24 | Bigarray.Array1.unsafe_set buf (k ) b; 25 | Bigarray.Array1.unsafe_set buf (k + 1) g; 26 | Bigarray.Array1.unsafe_set buf (k + 2) r; 27 | done 28 | done 29 | 30 | let draw_blink fb blink = 31 | let x, y = Fb.w fb / 2 + 67, Fb.h fb / 2 - 30 in 32 | let p = y * (Fb.stride fb) + x * 4 in 33 | let v = if blink then 0xFF else 0x00 in 34 | let buf = Fb.buffer fb in 35 | buf.{p} <- v; buf.{p + 1} <- v; buf.{p + 2} <- v; 36 | () 37 | 38 | let rec infinite_blink fb blink = 39 | Gpio.set activity_led blink; 40 | Serial.write "."; 41 | (match fb with None -> () | Some fb -> draw_blink fb blink); 42 | Mtime.sleep_us 1_000_000L; 43 | infinite_blink fb (not blink) 44 | 45 | let greet elapsed_us = 46 | let elapsed_ms = Int64.to_int elapsed_us / 1000 in 47 | Serial.write "\r\nWelcome to rpi-boot-ocaml \xF0\x9F\x90\xAB\r\n"; 48 | Serial.writef "Boot time: %dms\r\n" elapsed_ms; 49 | match Fb.init ~bpp:32 with 50 | | `Error (`Msg m) -> Serial.writef "Framebuffer: none: %s\r\n" m; None 51 | | `Ok fb -> 52 | let w, h, bpp, addr = Fb.(w fb, h fb, bpp fb, addr fb) in 53 | Serial.writef "Framebuffer: %dx%d bpp:%d addr:0x%nX\r\n" w h bpp addr; 54 | draw_image fb Logo.img; 55 | Some fb 56 | 57 | let main () = 58 | let boot_time = Mtime.elapsed_us () in 59 | let fb = greet boot_time in 60 | Gpio.set_func activity_led Gpio.F_OUT; 61 | infinite_blink fb true 62 | 63 | let () = try main () with e -> Serial.write (Printexc.get_backtrace ()) 64 | 65 | (*--------------------------------------------------------------------------- 66 | Copyright (c) 2015 Daniel C. Bünzli. 67 | All rights reserved. 68 | 69 | Redistribution and use in source and binary forms, with or without 70 | modification, are permitted provided that the following conditions 71 | are met: 72 | 73 | 1. Redistributions of source code must retain the above copyright 74 | notice, this list of conditions and the following disclaimer. 75 | 76 | 2. Redistributions in binary form must reproduce the above 77 | copyright notice, this list of conditions and the following 78 | disclaimer in the documentation and/or other materials provided 79 | with the distribution. 80 | 81 | 3. Neither the name of Daniel C. Bünzli nor the names of 82 | contributors may be used to endorse or promote products derived 83 | from this software without specific prior written permission. 84 | 85 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 86 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 87 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 88 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 89 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 90 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 91 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 92 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 93 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 94 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 95 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 96 | ---------------------------------------------------------------------------*) 97 | -------------------------------------------------------------------------------- /src/rpi.ml: -------------------------------------------------------------------------------- 1 | (*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | ---------------------------------------------------------------------------*) 6 | 7 | let strf = Format.asprintf 8 | 9 | type 'a result = [ `Ok of 'a | `Error of [`Msg of string ] ] 10 | 11 | module Mem = struct 12 | 13 | (* Addresses and memory barriers *) 14 | 15 | type addr = nativeint 16 | 17 | external wait : int -> unit = "ocamlrpi_barrier_wait" "noalloc" 18 | external dsb : unit -> unit = "ocamlrpi_barrier_dsb" "noalloc" 19 | external dmb : unit -> unit = "ocamlrpi_barrier_dmb" "noalloc" 20 | external isb : unit -> unit = "ocamlrpi_barrier_isb" "noalloc" 21 | 22 | let ( + ) = Nativeint.add 23 | let ( - ) = Nativeint.sub 24 | let offset a off = Nativeint.(add a (of_int off)) 25 | let of_int32 = Nativeint.of_int32 26 | let pp_addr ppf a = Format.fprintf ppf "0x%nX" a 27 | 28 | (* Reads *) 29 | 30 | external get : addr -> int = "ocamlrpi_mem_get_byte" "noalloc" 31 | external get_int : addr -> int = "ocamlrpi_mem_get_int" "noalloc" 32 | external get_int32 : addr -> int32 = "ocamlrpi_mem_get_int32" 33 | external get_int64 : addr -> int64 = "ocamlrpi_mem_get_int64" 34 | 35 | (* Writes *) 36 | 37 | external set : addr -> int -> unit = 38 | "ocamlrpi_mem_set_byte" "noalloc" 39 | 40 | external set_int : addr -> int -> unit = 41 | "ocamlrpi_mem_set_int" "noalloc" 42 | 43 | external set_int32 : addr -> int32 -> unit = 44 | "ocamlrpi_mem_set_int32" "noalloc" 45 | 46 | external set_int64 : addr -> int64 -> unit = 47 | "ocamlrpi_mem_set_int64" "noalloc" 48 | 49 | (* Masked writes *) 50 | 51 | external set_bits : addr -> bits:int -> int -> unit = 52 | "ocamlrpi_mem_set_byte_bits" "noalloc" 53 | 54 | external set_int_bits : addr -> bits:int -> int -> unit = 55 | "ocamlrpi_mem_set_int_bits" "noalloc" 56 | 57 | external set_int32_bits : addr -> bits:int32 -> int32 -> unit = 58 | "ocamlrpi_mem_set_int32_bits" "noalloc" 59 | 60 | external set_int64_bits : addr -> bits:int64 -> int64 -> unit = 61 | "ocamlrpi_mem_set_int64_bits" "noalloc" 62 | 63 | external set_int32_pow : addr -> int -> unit = 64 | "ocamlrpi_mem_set_int32_pow" "noalloc" 65 | 66 | (* Mapping *) 67 | 68 | module Map = struct 69 | 70 | type ('a, 'b) t = ('a, 'b, Bigarray.c_layout) Bigarray.Array1.t 71 | type bytes = (int, Bigarray.int8_unsigned_elt) t 72 | type int32s = (int32, Bigarray.int32_elt) t 73 | type int64s = (int64, Bigarray.int64_elt) t 74 | 75 | let length = Bigarray.Array1.dim 76 | 77 | external byte_length : ('a, 'b) t -> int = 78 | "ocamlrpi_mem_map_byte_length" 79 | 80 | external base : ('a, 'b) t -> addr = 81 | "ocamlrpi_mem_map_base" 82 | 83 | external bytes : addr -> len:int -> bytes = 84 | "ocamlrpi_mem_map_bytes" 85 | 86 | external int32s : addr -> len:int -> int32s = 87 | "ocamlrpi_mem_map_int32" 88 | 89 | external int64s : addr -> len:int -> int64s = 90 | "ocamlrpi_mem_map_int64" 91 | end 92 | end 93 | 94 | module Mmio = struct 95 | external get_base : unit -> nativeint = "ocamlrpi_mmio_base" 96 | let base = get_base () 97 | end 98 | 99 | module Gpio = struct 100 | 101 | (* GPIO addresses *) 102 | 103 | let gp_base = Mem.(Mmio.base + 0x00200000n) 104 | let gp_sel0 = Mem.(gp_base + 0x00n) 105 | let gp_set0 = Mem.(gp_base + 0x1Cn) 106 | let gp_set1 = Mem.(gp_base + 0x20n) 107 | let gp_clr0 = Mem.(gp_base + 0x28n) 108 | let gp_clr1 = Mem.(gp_base + 0x2Cn) 109 | let gp_pud = Mem.(gp_base + 0x94n) 110 | let gp_pudclk0 = Mem.(gp_base + 0x98n) 111 | let gp_pudclk1 = Mem.(gp_base + 0x98n) 112 | 113 | (* Pins *) 114 | 115 | type pin = 116 | | P00 | P01 | P02 | P03 | P04 | P05 | P06 | P07 | P08 | P09 117 | | P10 | P11 | P12 | P13 | P14 | P15 | P16 | P17 | P18 | P19 118 | | P20 | P21 | P22 | P23 | P24 | P25 | P26 | P27 | P28 | P29 119 | | P30 | P31 | P32 | P33 | P34 | P35 | P36 | P37 | P38 | P39 120 | | P40 | P41 | P42 | P43 | P44 | P45 | P46 | P47 | P48 | P49 121 | | P50 | P51 | P52 | P53 122 | 123 | let pin_to_int : pin -> int = fun p -> Obj.magic (Obj.repr p) 124 | 125 | (* Setup *) 126 | 127 | type func = F_IN | F_OUT | F_ALT5 | F_ALT4 | F_ALT0 | F_ALT1 | F_ALT2 | F_ALT3 128 | 129 | let func_to_int : func -> int = fun f -> Obj.magic (Obj.repr f) 130 | 131 | let set_func p f = 132 | let p = pin_to_int p in 133 | let f = func_to_int f in 134 | let r = Mem.offset gp_sel0 (4 * (p / 10)) in 135 | let bit_start = (p mod 10) * 3 in 136 | Mem.set_int_bits r ~bits:(0b111 lsl bit_start) (f lsl bit_start); 137 | () 138 | 139 | type pull_state = PULL_OFF | PULL_DOWN | PULL_UP 140 | 141 | let pull_state_to_int : pull_state -> int = fun s -> Obj.magic (Obj.repr s) 142 | 143 | let set_pull_state p s = 144 | let p = pin_to_int p in 145 | let s = pull_state_to_int s in 146 | let clk, n = if p > 31 then gp_pudclk1, p land 31 else gp_pudclk0, p in 147 | Mem.set_int gp_pud s; 148 | Mem.wait 150; 149 | Mem.set_int32_pow clk n; 150 | Mem.wait 150; 151 | Mem.set_int gp_pud 0; 152 | Mem.set_int clk 0; 153 | () 154 | 155 | (* Read and write *) 156 | 157 | let get p = failwith "TODO" 158 | let set p b = 159 | let p = pin_to_int p in 160 | let r, n = 161 | if p > 31 162 | then (if b then gp_set1 else gp_clr1), (p land 31) 163 | else (if b then gp_set0 else gp_clr0), p 164 | in 165 | Mem.set_int32_pow r n; 166 | () 167 | end 168 | 169 | (* We define serial as soon as possible so that it's available for 170 | debugging in this module. *) 171 | 172 | module Serial = struct 173 | 174 | (* UART0 registers *) 175 | 176 | let uart_base = Mem.(Mmio.base + 0x00201000n) 177 | let uart_dr = Mem.(uart_base + 0x00n) 178 | let uart_fr = Mem.(uart_base + 0x18n) 179 | let uart_ibrd = Mem.(uart_base + 0x24n) 180 | let uart_fbrd = Mem.(uart_base + 0x28n) 181 | let uart_lcrh = Mem.(uart_base + 0x2cn) 182 | let uart_cr = Mem.(uart_base + 0x30n) 183 | let uart_imsc = Mem.(uart_base + 0x38n) 184 | let uart_icr = Mem.(uart_base + 0x44n) 185 | 186 | (* Initialisation *) 187 | 188 | let inited = ref false 189 | 190 | let init () = 191 | if !inited then () else 192 | begin 193 | (* Disable UART *) 194 | Mem.set_int uart_cr 0; 195 | (* Disable pull up/down resistors on RC and TX pins *) 196 | Gpio.(set_pull_state P14 PULL_OFF); 197 | Gpio.(set_pull_state P15 PULL_OFF); 198 | (* Clear interrupts *) 199 | Mem.set_int uart_icr 0x7FF; 200 | (* Set baud rate to 115200 *) 201 | Mem.set_int uart_ibrd 1; 202 | Mem.set_int uart_fbrd 40; 203 | (* FIFO, 8 bit, no parity *) 204 | Mem.set_int uart_lcrh ((1 lsl 4) lor (0b11 lsl 5)); 205 | (* Mask interrupts *) 206 | Mem.set_int32 uart_imsc 0xFFFFl; 207 | (* Enable UART with reception and transmission *) 208 | Mem.set_int uart_cr ((1 lsl 0) lor (1 lsl 8) lor (1 lsl 9)); 209 | inited := true 210 | end 211 | 212 | (* Reads *) 213 | 214 | let read_byte () = 215 | while (Mem.get_int uart_fr land (1 lsl 4) <> 0) do () done; 216 | Mem.get_int uart_dr land 0xFF 217 | 218 | let try_read_byte () = match Mem.get_int uart_fr land (1 lsl 4) with 219 | | 0 -> None 220 | | n -> Some (Mem.get_int uart_dr land 0xFF) 221 | 222 | (* Writes *) 223 | 224 | let write_byte byte = 225 | while (Mem.get_int uart_fr land (1 lsl 5) <> 0) do () done; 226 | Mem.set_int uart_dr byte 227 | 228 | let write s = 229 | let max = String.length s - 1 in 230 | for i = 0 to max do write_byte (Char.code (String.unsafe_get s i)) done 231 | 232 | let b = Buffer.create 256 233 | let ppf = Format.formatter_of_buffer b 234 | let writef fmt = 235 | let k ppf = 236 | Format.pp_print_flush ppf (); 237 | let c = Buffer.contents b in 238 | (Buffer.clear b; write c) 239 | in 240 | Format.kfprintf k ppf fmt 241 | end 242 | 243 | module Mbox = struct 244 | 245 | type channel = 246 | | Power_management | Framebuffer | Virtual_UART | VCHIQ | LEDs 247 | | Buttons | Touchscreen | Unused | Tags_ARM_to_VC | Tags_VC_to_ARM 248 | 249 | let channel_to_int32 : channel -> int32 = 250 | fun m -> Int32.of_int (Obj.magic (Obj.repr m) : int) 251 | 252 | let mbox_base = Mem.(Mmio.base + 0xB880n) 253 | let mbox_read = Mem.(mbox_base + 0x00n) 254 | let mbox_peek = Mem.(mbox_base + 0x10n) 255 | let mbox_sender = Mem.(mbox_base + 0x14n) 256 | let mbox_status = Mem.(mbox_base + 0x18n) 257 | let mbox_config = Mem.(mbox_base + 0x1Cn) 258 | let mbox_write = Mem.(mbox_base + 0x20n) 259 | 260 | let empty = 0x40000000l 261 | let full = 0x80000000l 262 | 263 | let msg channel v = Int32.(logor v channel) 264 | let msg_channel r = Int32.logand r 0xFl 265 | let msg_value r = Nativeint.of_int32 (Int32.(logand r 0xFFFF_FFF0l)) 266 | 267 | let block_on s = 268 | while Int32.logand (Mem.get_int32 mbox_status) s <> 0l do () done 269 | 270 | let read c = 271 | let c = channel_to_int32 c in 272 | let rec loop () = 273 | block_on empty; 274 | Mem.dmb (); 275 | let m = Mem.get_int32 mbox_read in 276 | Mem.dmb (); 277 | if Int32.compare (msg_channel m) c = 0 then msg_value m else 278 | loop () 279 | in 280 | loop () 281 | 282 | let write c v = 283 | let c = channel_to_int32 c in 284 | let v = Nativeint.to_int32 v in 285 | let rec loop () = 286 | block_on full; 287 | Mem.set_int32 mbox_write (msg c v); 288 | in 289 | loop () 290 | 291 | (* Property interface *) 292 | 293 | module Prop = struct 294 | 295 | (* Property values *) 296 | 297 | type 'a t = 298 | | Unit : unit t 299 | | Bytes : int * (Mem.Map.bytes -> 'a result) -> 'a t 300 | | Int32 : int * (Mem.Map.int32s -> 'a result) -> 'a t 301 | | Int64 : int * (Mem.Map.int64s -> 'a result) -> 'a t 302 | 303 | let prop_byte_length = fun (type a) (p : a t) -> match p with 304 | | Unit -> 0 305 | | Bytes (count, _) -> count 306 | | Int32 (count, _) -> 4 * count 307 | | Int64 (count, _) -> 8 * count 308 | 309 | let err_short len exp = 310 | `Error (`Msg (strf "response value too short exp:%d got:%d" exp len)) 311 | 312 | let id x = x 313 | 314 | let get1 conv m = 315 | let len = Mem.Map.length m in 316 | if len < 1 then err_short len 1 else `Ok (conv m.{0}) 317 | 318 | let get2 conv m = 319 | let len = Mem.Map.length m in 320 | if len < 2 then err_short len 2 else 321 | `Ok (conv m.{0}, conv m.{1}) 322 | 323 | let unit = Unit 324 | let int = Int32 (1, get1 Int32.to_int) 325 | let int32 = Int32 (1, get1 id) 326 | let int64 = Int64 (1, get1 id) 327 | let int_pair = Int32 (2, get2 Int32.to_int) 328 | let int32_pair = Int32 (2, get2 id) 329 | let int64_pair = Int64 (2, get2 id) 330 | 331 | let string ~max = 332 | let parse m = 333 | let len = Mem.Map.length m in 334 | let b = Bytes.create len in 335 | let max = len - 1 in 336 | for i = 0 to max do Bytes.unsafe_set b i (Char.unsafe_chr m.{i}) done; 337 | `Ok (Bytes.unsafe_to_string b) 338 | in 339 | Bytes (max, parse) 340 | 341 | (* Requests *) 342 | 343 | type args = int32 list 344 | type ereq = { tag : int32; args : args; buf_blen : int; } 345 | type 'a req = ereq * 'a t 346 | 347 | let req ?(args = []) tag ~resp:prop = 348 | let buf_blen = max (4 * List.length args) (prop_byte_length prop) in 349 | let buf_blen = 350 | let rem = buf_blen mod 4 in 351 | if rem = 0 then buf_blen else buf_blen + (4 - rem) 352 | in 353 | { tag; args; buf_blen }, prop 354 | 355 | let req_byte_length r = 356 | 4 (* tag *) + 4 (* val len *) + 4 (* indicator *) + r.buf_blen 357 | 358 | let r (ereq, _) = ereq 359 | 360 | (* Responses *) 361 | 362 | type resp = { msg : Mem.Map.int32s; 363 | (* Tag, (start of value in msg, byte length) *) 364 | tag_index : (Int32.t * (int * int)) list; } 365 | 366 | let msg_addr = 0x1000n 367 | (* The location is free but FIXME. This should be allocated via 368 | malloc on a 16 byte boundary. A function should be added for 369 | that in Mem. It must be possible to do that by simply 370 | allocating a bigarray with Bigarray.Array1.create with + 16 371 | bytes an extracting a sub map out of it. 372 | 373 | FIXME Besides should this address be sent as a VC CPU Bus 374 | address ? Unclear. *) 375 | 376 | let request_msg reqs = 377 | let add_req_blen acc r = acc + req_byte_length r in 378 | let reqs_blen = List.fold_left add_req_blen 0 reqs in 379 | let msg_blen = 4 (* size *) + 4 (* code *) + reqs_blen + 4 (* end *) in 380 | let m = Mem.Map.int32s msg_addr ~len:(msg_blen / 4) in 381 | let rec add_reqs i = function 382 | | [] -> m.{i} <- 0l (* end tag *) 383 | | r :: reqs -> 384 | let next = i + 2 + r.buf_blen / 4 + 1 in 385 | m.{i } <- r.tag; 386 | m.{i + 1} <- Int32.of_int r.buf_blen; 387 | m.{i + 2} <- Int32.of_int @@ 4 * List.length r.args; 388 | ignore (List.fold_left (fun i a -> m.{i} <- a; i + 1) (i + 3) r.args); 389 | add_reqs next reqs 390 | in 391 | m.{0} <- Int32.of_int msg_blen; 392 | m.{1} <- 0l; (* Request *) 393 | add_reqs 2 reqs; 394 | m 395 | 396 | let err_unterminated = `Msg "unterminated response" 397 | let err_truncated_resp t = `Msg (strf "truncated response (tag:%lX)" t) 398 | let err_unknown_code c = `Msg (strf "unknown reponse code: %lX" c) 399 | let err_parse = `Msg (strf "GPU: error parsing request") 400 | let err_addr a a' = 401 | `Msg (strf "different return address %a %a" Mem.pp_addr a Mem.pp_addr a') 402 | 403 | let tag_index m = 404 | let max = Mem.Map.length m - 1 in 405 | let rec loop acc i = 406 | if i > max then `Error err_unterminated else 407 | let tag = m.{i} in 408 | if tag = 0l then `Ok acc else 409 | if i + 2 > max then `Error (err_truncated_resp tag) else 410 | let buf_blen = m.{i + 1} (* n.b. this is multiple of 4. *) in 411 | let next = i + 2 + (Int32.to_int buf_blen / 4) + 1 in 412 | let indic = m.{i + 2} in 413 | let acc = 414 | if (Int32.logand 0x8000_0000l indic = 0l) then acc else 415 | (tag, (i + 3, Int32.(to_int (logand 0x7FFF_FFFFl indic)))) :: acc 416 | in 417 | loop acc next 418 | in 419 | loop [] 2 420 | 421 | let send reqs = 422 | let msg = request_msg reqs in 423 | let addr = Mem.Map.base msg in 424 | write Tags_ARM_to_VC addr; 425 | let addr' = read Tags_ARM_to_VC in 426 | if addr <> addr' then `Error (err_addr addr addr') else 427 | match msg.{1} with 428 | | 0x80000000l -> 429 | begin match tag_index msg with 430 | | `Ok tag_index -> `Ok {msg; tag_index} 431 | | `Error _ as e -> e 432 | end 433 | | 0x80000001l -> `Error err_parse 434 | | c -> `Error (err_unknown_code c) 435 | 436 | let find (type a) resp (ereq, (prop : a t)) : a option result = 437 | try 438 | let some = function `Ok v -> `Ok (Some v) | `Error _ as e -> e in 439 | let pos, len = List.assoc ereq.tag resp.tag_index in 440 | match prop with 441 | | Unit -> `Ok (Some ()) 442 | | Bytes (_, parse) -> 443 | let addr = Mem.(offset (Map.base resp.msg) @@ 4 * pos) in 444 | some @@ parse (Mem.Map.bytes addr len) 445 | | Int32 (_, parse) -> 446 | some @@ parse (Bigarray.Array1.sub resp.msg pos (len / 4)) 447 | | Int64 (_, parse) -> 448 | let addr = Mem.(offset (Map.base resp.msg) @@ 4 * pos) in 449 | some @@ parse (Mem.Map.int64s addr (len / 8)) 450 | with Not_found -> `Ok None 451 | 452 | end 453 | end 454 | 455 | module Mtime = struct 456 | 457 | (* Time spans *) 458 | 459 | type span_us = int64 460 | 461 | (* Passing time *) 462 | 463 | let timer_base = Mem.(Mmio.base + 0x00003000n) 464 | let timer_clo = Mem.(timer_base + 0x04n) 465 | 466 | let elapsed_us () = Mem.get_int64 timer_clo 467 | let sleep_us d = 468 | (* That's a bit wasteful and unprecise because of allocs, FIXME 469 | wfi + timer IRQ *) 470 | let rec loop start = 471 | let e = Int64.sub (elapsed_us ()) start in 472 | if Int64.compare e d < 0 then loop start else () 473 | in 474 | loop (elapsed_us ()) 475 | 476 | (* Counters *) 477 | 478 | type counter = span_us 479 | let counter = elapsed_us 480 | let counter_value_us c = Int64.sub (elapsed_us ()) c 481 | 482 | (* Time scale conversions *) 483 | 484 | let s_to_us = 1_000_000L 485 | let ms_to_us = 1_000L 486 | end 487 | 488 | (*--------------------------------------------------------------------------- 489 | Copyright (c) 2015 Daniel C. Bünzli. 490 | All rights reserved. 491 | 492 | Redistribution and use in source and binary forms, with or without 493 | modification, are permitted provided that the following conditions 494 | are met: 495 | 496 | 1. Redistributions of source code must retain the above copyright 497 | notice, this list of conditions and the following disclaimer. 498 | 499 | 2. Redistributions in binary form must reproduce the above 500 | copyright notice, this list of conditions and the following 501 | disclaimer in the documentation and/or other materials provided 502 | with the distribution. 503 | 504 | 3. Neither the name of Daniel C. Bünzli nor the names of 505 | contributors may be used to endorse or promote products derived 506 | from this software without specific prior written permission. 507 | 508 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 509 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 510 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 511 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 512 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 513 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 514 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 515 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 516 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 517 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 518 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 519 | ---------------------------------------------------------------------------*) 520 | -------------------------------------------------------------------------------- /src/rpi.mli: -------------------------------------------------------------------------------- 1 | (*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | ---------------------------------------------------------------------------*) 6 | 7 | (** Rasbperry PI hardware access. 8 | 9 | Access to {{!Mem}memory}, {{!Gpio}GPIO pins}, {{!Mbox}mailboxes}, 10 | {{!Mtime}monotonic time}, and {{!Serial}a serial connection}. 11 | 12 | {b References} 13 | {ul 14 | {- {{:https://www.raspberrypi.org/documentation/hardware/} 15 | The Raspberry Pi Hardware documentation}.} 16 | {- {{:https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf}BCM2835 ARM Peripheral specification} (PDF). Also 17 | applies to RPiv2, except the MMIO base ARM physical address is 18 | different.}} *) 19 | 20 | (** {1:low Low-level interfaces} *) 21 | 22 | type 'a result = [ `Ok of 'a | `Error of [`Msg of string ]] 23 | (** The type for results. FIXME use [rresult]. *) 24 | 25 | (** Memory. 26 | 27 | {b Note.} All multi-bytes memory accesses are done in little endian 28 | order. *) 29 | module Mem : sig 30 | 31 | (** {1:addr Addresses} *) 32 | 33 | type addr = nativeint 34 | (** The type for byte addresses. *) 35 | 36 | val ( + ) : addr -> addr -> addr 37 | (** [a + off] adds [off] to [a]. *) 38 | 39 | val ( - ) : addr -> addr -> addr 40 | (** [a - off] subracts [off] to [a]. *) 41 | 42 | val offset : addr -> int -> addr 43 | (** [offset addr n] is [add + Nativeint.of_int n]. *) 44 | 45 | val of_int32 : int32 -> addr 46 | (** [of_int32 i] is the address corresponding to [i]. *) 47 | 48 | val pp_addr : Format.formatter -> addr -> unit 49 | (** [pp_addr ppf a] prints and unspecified reprsentation of [a] 50 | on [ppf]. *) 51 | 52 | (** {1:barriers Memory barriers} *) 53 | 54 | val wait : int -> unit 55 | (** [wait n] waits at least [n] CPU cycles. *) 56 | 57 | val dsb : unit -> unit 58 | (** [dsb ()] performs a data synchronization barrier. Returns when 59 | all instructions before the call are complete. *) 60 | 61 | val dmb : unit -> unit 62 | (** [dmb ()] performs a data memory barrier. Ensures that all explicit 63 | memory access before the call complete before any new explicit 64 | access made after the call. *) 65 | 66 | val isb : unit -> unit 67 | (** [isb ()] performs an instruction synchronization barrier. Flushes 68 | the pipeline in the processor so that all instruction following the 69 | call are fetched from cache or memory. *) 70 | 71 | (** {1:reads Reads} *) 72 | 73 | val get : addr -> int 74 | (** [get a] gets the byte at address [a]. *) 75 | 76 | val get_int : addr -> int 77 | (** [get_int a] gets the 4 bytes starting at address [a]. 78 | 79 | {b Warning.} Truncates the value of the 32nd bit. *) 80 | 81 | val get_int32 : addr -> int32 82 | (** [get_int32 a] gets the 4 bytes starting at address [a]. *) 83 | 84 | val get_int64 : addr -> int64 85 | (** [get_int64 a] gets the 8 bytes starting at address [a]. *) 86 | 87 | (** {1:writes Writes} *) 88 | 89 | val set : addr -> int -> unit 90 | (** [set a v] sets the byte at address [a] to [v]. *) 91 | 92 | val set_int : addr -> int -> unit 93 | (** [set a v] sets the 4 bytes starting at address [a] to [v]. *) 94 | 95 | val set_int32 : addr -> int32 -> unit 96 | (** [set a v] sets the 4 bytes starting at address [a] to [v]. *) 97 | 98 | val set_int64 : addr -> int64 -> unit 99 | (** [set a v] sets the 8 bytes starting at address [a] to [v]. *) 100 | 101 | (** {1:mask Masked writes} *) 102 | 103 | val set_bits : addr -> bits:int -> int -> unit 104 | (** [set_bits] is like {!set} but only affects the bits set 105 | in [bits]. *) 106 | 107 | val set_int_bits : addr -> bits:int -> int -> unit 108 | (** [masked_set_int] is like {!set_int} but only affects the bits set 109 | in [bits]. *) 110 | 111 | val set_int32_bits : addr -> bits:int32 -> int32 -> unit 112 | (** [set_int32_bits] is like {!set_int32} but only affects the bits 113 | set in [bits]. *) 114 | 115 | val set_int64_bits : addr -> bits:int64 -> int64 -> unit 116 | (** [set_int64_bits] is like {!set_int64} but only affects the bits 117 | set in [bits]. *) 118 | 119 | (** {1:map Mapping} *) 120 | 121 | (** Memory maps *) 122 | module Map : sig 123 | 124 | (** {1 Maps} *) 125 | 126 | type ('a, 'b) t = ('a, 'b, Bigarray.c_layout) Bigarray.Array1.t 127 | (** The type for memory maps. *) 128 | 129 | type bytes = (int, Bigarray.int8_unsigned_elt) t 130 | (** The type for byte memory maps. *) 131 | 132 | type int32s = (int32, Bigarray.int32_elt) t 133 | (** The type for int32 memory maps. *) 134 | 135 | type int64s = (int64, Bigarray.int64_elt) t 136 | (** The type for int64 memory maps. *) 137 | 138 | val length : ('a ,'b) t -> int 139 | (** [length m] is [m]'s scalar length. *) 140 | 141 | val byte_length : ('a, 'b) t -> int 142 | (** [byte_length m] is [m]'s byte length. *) 143 | 144 | val base : ('a, 'b) t -> addr 145 | (** [base m] is [m]'s base address. *) 146 | 147 | val bytes : addr -> len:int -> bytes 148 | (** [bytes a len] maps [len] bytes starting at [a]. *) 149 | 150 | val int32s : addr -> len:int -> int32s 151 | (** [int32s a len] maps [len] int32 values starting at [a]. *) 152 | 153 | val int64s : addr -> len:int -> int64s 154 | (** [map_int64 a len] maps [len] int64 values starting at [a]. *) 155 | end 156 | end 157 | 158 | (** Memory mapped IO. *) 159 | module Mmio : sig 160 | 161 | (** {1:base Base address} *) 162 | 163 | val base : Mem.addr 164 | (** The base ARM physical address at which memory mapped IO is available. 165 | On a RPiv2 this is [0x3F000000]. On previous models (unsupported 166 | for now) it was [0x20000000]. *) 167 | end 168 | 169 | (** GPIO pins. 170 | 171 | {b References} 172 | {ul 173 | {- {{:https://www.raspberrypi.org/documentation/hardware/raspberrypi/gpio/README.md}GPIO Raspberry Pi documentation}.} 174 | {- Section 6 of the {{:https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf}BCM2835 ARM Peripheral specification} (PDF).}} *) 175 | module Gpio : sig 176 | 177 | (** {1:pins Pins} *) 178 | 179 | (** The type for GPIO pins. *) 180 | type pin = 181 | | P00 | P01 | P02 | P03 | P04 | P05 | P06 | P07 | P08 | P09 182 | | P10 | P11 | P12 | P13 | P14 | P15 | P16 | P17 | P18 | P19 183 | | P20 | P21 | P22 | P23 | P24 | P25 | P26 | P27 | P28 | P29 184 | | P30 | P31 | P32 | P33 | P34 | P35 | P36 | P37 | P38 | P39 185 | | P40 | P41 | P42 | P43 | P44 | P45 | P46 | P47 | P48 | P49 186 | | P50 | P51 | P52 | P53 187 | 188 | (** {1:setup Pin setup} *) 189 | 190 | (** The type for pin functions. *) 191 | type func = 192 | | F_IN | F_OUT | F_ALT5 | F_ALT4 | F_ALT0 | F_ALT1 | F_ALT2 | F_ALT3 193 | 194 | val set_func : pin -> func -> unit 195 | (** [set p func] sets the function of pin [p] to [func]. *) 196 | 197 | (** The type for pin pull state. *) 198 | type pull_state = PULL_OFF | PULL_DOWN | PULL_UP 199 | 200 | val set_pull_state : pin -> pull_state -> unit 201 | (** [set p state] sets the pull state of pin [p] to [state]. *) 202 | 203 | (** {1:rw Read and write} *) 204 | 205 | val get : pin -> bool 206 | (** [get p] is the current value of pin [p]. *) 207 | 208 | val set : pin -> bool -> unit 209 | (** [set p v] sets the value of pin [p] to [v]. *) 210 | end 211 | 212 | (** Mailboxes. 213 | 214 | Mailbox allow to connect with the RPi's GPU which is in charge 215 | of a lot the bookkeeping. 216 | 217 | This is not very well documented, a bit of documentation can be found {{:https://github.com/raspberrypi/firmware/wiki/Mailboxes}here}. 218 | Using the {{!propi}property} interface should be enough. *) 219 | module Mbox : sig 220 | 221 | (** {1:propi Property interface} *) 222 | 223 | (** Property interface 224 | 225 | Convenience interface for the 226 | {{:https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface}mailbox property interface} (channel [Tags_ARM_to_VC]). *) 227 | module Prop : sig 228 | 229 | (** {1 Property values} *) 230 | 231 | (** The type for response property values. The expected maximal 232 | length of the response and a property parser. The map given to 233 | the property parser can be shorter than the specified 234 | length. *) 235 | type 'a t = 236 | | Unit : unit t 237 | | Bytes : int * (Mem.Map.bytes -> 'a result) -> 'a t 238 | | Int32 : int * (Mem.Map.int32s -> 'a result) -> 'a t 239 | | Int64 : int * (Mem.Map.int64s -> 'a result) -> 'a t 240 | 241 | val unit : unit t 242 | (** [unit] is an empty property. *) 243 | 244 | val string : max:int -> string t 245 | (** [string] is a string of maximum length [max]. *) 246 | 247 | val int : int t 248 | (** [int] is an integer property (parsed from an int32). *) 249 | 250 | val int32 : int32 t 251 | (** [int32] is an int32 property. *) 252 | 253 | val int64 : int64 t 254 | (** [int64] is an int64 property. *) 255 | 256 | val int_pair : (int * int) t 257 | (** [int] is an integer pair property (parsed from two int32s). *) 258 | 259 | val int32_pair : (int32 * int32) t 260 | (** [int32_pair] is an int32 pair property. *) 261 | 262 | val int64_pair : (int64 * int64) t 263 | (** [int32_pair] is an int64 pair property. *) 264 | 265 | (** {1:req Requests} *) 266 | 267 | type args = int32 list 268 | (** The type for property requests arguments. FIXME this 269 | should maybe be generalized but at the moment all published 270 | requests arguments are uint32. *) 271 | 272 | type 'a req 273 | (** The type for requests of properties of type 'a. *) 274 | 275 | type ereq 276 | (** The type for existential requests. *) 277 | 278 | val req : ?args:args -> int32 -> resp:'a t -> 'a req 279 | (** [req t args resp] is a property for tag [t] with request arguments 280 | [args] (defaults to []) and response property parsed with [resp]. *) 281 | 282 | val r : 'a req -> ereq 283 | (** [r req] is an existential request for [r]. *) 284 | 285 | (** {1:resp Responses} *) 286 | 287 | type resp 288 | (** The type for responses. *) 289 | 290 | val send : ereq list -> resp result 291 | (** [send reqs] sends the list of requests [reqs] in the given order. *) 292 | 293 | val find : resp -> 'a req -> 'a option result 294 | (** [find resp req] finds the property value of [req] in response [resp]. 295 | [None] is returned if the property can't be found. *) 296 | end 297 | 298 | (** {1:channels Channels} *) 299 | 300 | (** The type for mailbox channels *) 301 | type channel = 302 | | Power_management | Framebuffer | Virtual_UART | VCHIQ | LEDs 303 | | Buttons | Touchscreen | Unused | Tags_ARM_to_VC | Tags_VC_to_ARM 304 | 305 | (** {1:addr Communicating addresses} 306 | 307 | {b Warning} The lowest 4-bits of sent addresses can't be read 308 | by the GPU as they are used to transmit the channel. 309 | used. As such addresses must be aligned on 16 bytes. *) 310 | 311 | val read : channel -> Mem.addr 312 | (** [read c] reads the address of channel [c]. *) 313 | 314 | val write : channel -> Mem.addr -> unit 315 | (** [write c a] writes the [v] to the channel [c]. *) 316 | end 317 | 318 | (** {1 Higher-level interfaces} *) 319 | 320 | (** Monotonic time. 321 | 322 | [Mtime] gives access to the 64-bit free running system timer 323 | counter. Note that this time is independent from the CPU speed. 324 | 325 | {b References} 326 | {ul 327 | {- Section 12 of the {{:https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf}BCM2835 ARM Peripheral specification} (PDF).}} *) 328 | module Mtime : sig 329 | 330 | (** {1:spans Time spans} *) 331 | 332 | type span_us = int64 333 | (** The type for time spans in {e unsigned} microseconds. *) 334 | 335 | (** {1:passing Passing time} *) 336 | 337 | val elapsed_us : unit -> span_us 338 | (** [elapsed ()] is the number of microseconds elasped since boot 339 | time. *) 340 | 341 | val sleep_us : span_us -> unit 342 | (** [sleep_us d] blocks and sleeps for [d] microseconds. *) 343 | 344 | (** {1:counters Counters} *) 345 | 346 | type counter 347 | (** The type for counters. *) 348 | 349 | val counter : unit -> counter 350 | (** [counter ()] is a counter counting from call time on. *) 351 | 352 | val counter_value_us : counter -> span_us 353 | (** [counter_value_us c] is the current counter value in microseconds. *) 354 | 355 | (** {1:conv Time conversion} *) 356 | 357 | val s_to_us : int64 358 | (** [s_to_us] is the number of microseconds in one second. *) 359 | 360 | val ms_to_us : int64 361 | (** [ms_to_us] is the number of microseconds in one millisecond. *) 362 | end 363 | 364 | (** Serial connection. 365 | 366 | [Serial] gives access to a 367 | {{:http://elinux.org/RPi_Serial_Connection} serial connection} 368 | using the Pi's UART0 peripheral. 369 | 370 | {b References} 371 | {ul 372 | {- Section 13 of the {{:https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf}BCM2835 ARM Peripheral specification} (PDF).}} *) 373 | module Serial : sig 374 | 375 | (** {1:init Initialization} *) 376 | 377 | val init : unit -> unit 378 | (** [init ()] initializes the serial connection. *) 379 | 380 | (** {1:read Read} *) 381 | 382 | val read_byte : unit -> int 383 | (** [read_byte ()] blocks until a byte becomes available on the 384 | serial connection. *) 385 | 386 | val try_read_byte : unit -> int option 387 | (** [try_read_byte ()] is [Some b] a byte could be read from the 388 | serial connection and [None] otherwise. *) 389 | 390 | (** {1:write Write} *) 391 | 392 | val write_byte : int -> unit 393 | (** [write_byte b] writes the byte [b] on the serial connection. *) 394 | 395 | val write : string -> unit 396 | (** [write s] writes [s] on the serial connection. *) 397 | 398 | val writef : ('a, Format.formatter, unit) format -> 'a 399 | (** [writef fmt ...] write a string formatted according to [fmt] 400 | on the serial connection. *) 401 | end 402 | 403 | (*--------------------------------------------------------------------------- 404 | Copyright (c) 2015 Daniel C. Bünzli. 405 | All rights reserved. 406 | 407 | Redistribution and use in source and binary forms, with or without 408 | modification, are permitted provided that the following conditions 409 | are met: 410 | 411 | 1. Redistributions of source code must retain the above copyright 412 | notice, this list of conditions and the following disclaimer. 413 | 414 | 2. Redistributions in binary form must reproduce the above 415 | copyright notice, this list of conditions and the following 416 | disclaimer in the documentation and/or other materials provided 417 | with the distribution. 418 | 419 | 3. Neither the name of Daniel C. Bünzli nor the names of 420 | contributors may be used to endorse or promote products derived 421 | from this software without specific prior written permission. 422 | 423 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 424 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 425 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 426 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 427 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 428 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 429 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 430 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 431 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 432 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 433 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 434 | ---------------------------------------------------------------------------*) 435 | -------------------------------------------------------------------------------- /src/rpi_mem.c: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------- 2 | Copyright (c) 2015 Daniel C. Bünzli. All rights reserved. 3 | Distributed under the BSD3 license, see license at the end of the file. 4 | %%NAME%% release %%VERSION%% 5 | --------------------------------------------------------------------------*/ 6 | 7 | #include 8 | 9 | /* Memory barriers */ 10 | 11 | static inline void barrier_dsb (void) { __asm ("dsb"); } 12 | static inline void barrier_dmb (void) { __asm ("dmb"); } 13 | static inline void barrier_isb (void) { __asm ("isb"); } 14 | static inline void barrier_wait (uint32_t d) 15 | { 16 | for (volatile uint32_t i = 0; i < d; i++) ; 17 | } 18 | 19 | /* Memory reads */ 20 | 21 | static inline uint8_t mem_get_u8 (uint32_t r) 22 | { 23 | return *(volatile uint8_t *)r; 24 | } 25 | 26 | static inline uint32_t mem_get_u32 (uint32_t r) 27 | { 28 | return *(volatile uint32_t *)r; 29 | } 30 | 31 | static inline uint64_t mem_get_u64 (uint32_t r) 32 | { 33 | return *(volatile uint64_t *)r; 34 | } 35 | 36 | /* Memory writes */ 37 | 38 | static inline void mem_set_u8 (uint32_t r, uint8_t v) 39 | { 40 | *(volatile uint8_t *)r = v; 41 | } 42 | 43 | static inline void mem_set_u32 (uint32_t r, uint32_t v) 44 | { 45 | *(volatile uint32_t *)r = v; 46 | } 47 | 48 | static inline void mem_set_u64 (uint32_t r, uint64_t v) 49 | { 50 | *(volatile uint64_t *)r = v; 51 | } 52 | 53 | /* Memory masked writes */ 54 | 55 | static inline void mem_set_u8_bits (uint32_t r, uint8_t bits, uint8_t v) 56 | { 57 | uint8_t current = mem_get_u8 (r); 58 | v = (current & ~bits) | (v & bits); 59 | mem_set_u8 (r, v); 60 | } 61 | 62 | static inline void mem_set_u32_bits (uint32_t r, uint32_t bits, uint32_t v) 63 | { 64 | uint32_t current = mem_get_u32 (r); 65 | v = (current & ~bits) | (v & bits); 66 | mem_set_u32 (r, v); 67 | } 68 | 69 | static inline void mem_set_u64_bits (uint32_t r, uint64_t bits, uint64_t v) 70 | { 71 | uint64_t current = mem_get_u64 (r); 72 | v = (current & ~bits) | (v & bits); 73 | mem_set_u64 (r, v); 74 | } 75 | 76 | /* OCaml stubs */ 77 | 78 | #include 79 | #include 80 | #include 81 | 82 | /* Memory mapped IO */ 83 | 84 | value ocamlrpi_mmio_base (value unit) 85 | { 86 | extern uint32_t rpi_mmio_base; // See startup.c 87 | return caml_copy_nativeint (rpi_mmio_base); 88 | } 89 | 90 | /* Memory barriers */ 91 | 92 | value ocamlrpi_barrier_dsb (value unit) { barrier_dsb (); return Val_unit; } 93 | value ocamlrpi_barrier_dmb (value unit) { barrier_dmb (); return Val_unit; } 94 | value ocamlrpi_barrier_isb (value unit) { barrier_isb (); return Val_unit; } 95 | value ocamlrpi_barrier_wait (value d) 96 | { 97 | barrier_wait (Int_val (d)); 98 | return Val_unit; 99 | } 100 | 101 | /* Reads */ 102 | 103 | value ocamlrpi_mem_get_byte (value addr) 104 | { 105 | return Val_int (mem_get_u8 (Nativeint_val (addr))); 106 | } 107 | 108 | value ocamlrpi_mem_get_int (value addr) 109 | { 110 | return Val_int (mem_get_u32 (Nativeint_val (addr))); 111 | } 112 | 113 | value ocamlrpi_mem_get_int32 (value addr) 114 | { 115 | return caml_copy_int32 (mem_get_u32 (Nativeint_val (addr))); 116 | } 117 | 118 | value ocamlrpi_mem_get_int64 (value addr) 119 | { 120 | return caml_copy_int64 (mem_get_u64 (Nativeint_val (addr))); 121 | } 122 | 123 | /* Writes */ 124 | 125 | value ocamlrpi_mem_set_byte (value addr, value v) 126 | { 127 | mem_set_u8 (Nativeint_val (addr), Int_val (v)); 128 | return Val_unit; 129 | } 130 | 131 | value ocamlrpi_mem_set_int (value addr, value v) 132 | { 133 | mem_set_u32 (Nativeint_val (addr), Int_val (v)); 134 | return Val_unit; 135 | } 136 | 137 | value ocamlrpi_mem_set_int32 (value addr, value v) 138 | { 139 | mem_set_u32 (Nativeint_val (addr), Int32_val (v)); 140 | return Val_unit; 141 | } 142 | 143 | value ocamlrpi_mem_set_int64 (value addr, value v) 144 | { 145 | mem_set_u64 (Nativeint_val (addr), Int64_val (v)); 146 | return Val_unit; 147 | } 148 | 149 | value ocamlrpi_mem_set_int32_pow (value addr, value pow) 150 | { 151 | mem_set_u32 (Nativeint_val (addr), 1 << Int_val (pow)); 152 | return Val_unit; 153 | } 154 | 155 | /* Masked writes */ 156 | 157 | value ocamlrpi_mem_set_byte_bits (value addr, value bits, value v) 158 | { 159 | mem_set_u8_bits (Nativeint_val (addr), Int_val (bits), Int_val (v)); 160 | return Val_unit; 161 | } 162 | 163 | value ocamlrpi_mem_set_int_bits (value addr, value bits, value v) 164 | { 165 | mem_set_u32_bits (Nativeint_val (addr), Int_val (bits), Int_val (v)); 166 | return Val_unit; 167 | } 168 | 169 | value ocamlrpi_mem_set_int32_bits (value addr, value bits, value v) 170 | { 171 | mem_set_u32_bits (Nativeint_val (addr), Int32_val (bits), Int32_val (v)); 172 | return Val_unit; 173 | } 174 | 175 | value ocamlrpi_mem_set_int64_bits (value addr, value bits, value v) 176 | { 177 | mem_set_u32_bits (Nativeint_val (addr), Int64_val (bits), Int64_val (v)); 178 | return Val_unit; 179 | } 180 | 181 | /* Mapping */ 182 | 183 | value ocamlrpi_mem_map_byte_length (value ba) 184 | { 185 | return Val_int (caml_ba_byte_size (Caml_ba_array_val (ba))); 186 | } 187 | 188 | 189 | value ocamlrpi_mem_map_base (value ba) 190 | { 191 | return caml_copy_nativeint ((uint32_t)(Caml_ba_data_val (ba))); 192 | } 193 | 194 | value ocamlrpi_mem_map_bytes (value addr, value len) 195 | { 196 | return caml_ba_alloc_dims (CAML_BA_UINT8 | CAML_BA_C_LAYOUT, 1, 197 | (void *)(Nativeint_val (addr)), Int_val (len)); 198 | } 199 | 200 | value ocamlrpi_mem_map_int32 (value addr, value len) 201 | { 202 | return caml_ba_alloc_dims (CAML_BA_INT32 | CAML_BA_C_LAYOUT, 1, 203 | (void *)(Nativeint_val (addr)), Int_val (len)); 204 | } 205 | 206 | value ocamlrpi_mem_map_int64 (value addr, value len) 207 | { 208 | return caml_ba_alloc_dims (CAML_BA_INT64 | CAML_BA_C_LAYOUT, 1, 209 | (void *)(Nativeint_val (addr)), Int_val (len)); 210 | } 211 | 212 | /*--------------------------------------------------------------------------- 213 | Copyright (c) 2015 Daniel C. Bünzli. 214 | All rights reserved. 215 | 216 | Redistribution and use in source and binary forms, with or without 217 | modification, are permitted provided that the following conditions 218 | are met: 219 | 220 | 1. Redistributions of source code must retain the above copyright 221 | notice, this list of conditions and the following disclaimer. 222 | 223 | 2. Redistributions in binary form must reproduce the above 224 | copyright notice, this list of conditions and the following 225 | disclaimer in the documentation and/or other materials provided 226 | with the distribution. 227 | 228 | 3. Neither the name of Daniel C. Bünzli nor the names of 229 | contributors may be used to endorse or promote products derived 230 | from this software without specific prior written permission. 231 | 232 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 233 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 234 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 235 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 236 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 237 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 238 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 239 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 240 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 241 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 242 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 243 | --------------------------------------------------------------------------*/ 244 | --------------------------------------------------------------------------------