GithubHelp home page GithubHelp logo

doytsujin / llvm-videocore4 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from christinaa/llvm-videocore4

0.0 1.0 0.0 42.6 MB

LLVM for VideoCore4 (Raspberry Pi VPU)

License: Other

Shell 0.15% C++ 53.29% Python 0.56% Perl 0.04% C 0.40% Emacs Lisp 0.02% Objective-C 0.54% OCaml 0.37% Assembly 9.02% SourcePawn 0.01% Makefile 0.32% CMake 0.27% LLVM 34.86% M4 0.14% Vim Script 0.02%

llvm-videocore4's Introduction

LLVM for VideoCore4

This is mostly based on the work done by David Given (cowlark). It works, and can compile and produce reasonable code. I did this so I could have a decent compiler to develop my Raspberry Pi firmware on.

The actual VideoCore4 target is in lib/Target/VideoCore4/. To build this, you'll need to use CMake.

What works

  • Pretty much everything that isn't listed under the 'Issues' section. Some corner cases may still lead to LLC errors such as using certain builtins. However, I have not done any comprehensive testing since I mostly targeted a feature set required for implementing a firmware for the VPU.

Issues

  • Variable length arrays do not work (because of FP not being implemented). This may also break some C++ features.
  • MC code emisssion is not supported, TableGen hacks need to be fixed before that is possible.
  • Use any floating point arithmetic at your own risk, I have not tested it, it is unlikely to work.
  • BB reordering is not implemented so you'll have to live with redundant branches being generated.
  • TableGen code is not ideal, I tried to improve it and get rid of some of the hacks used in the original one but there's still a long way to go.
  • Some directives emmited by LLC confuse VASM so at the moment I just sed them out in the Makefile (I've included an example).
  • Stack based return values (ie. struct returns) are unsupported.
  • No push/pop optimizations for prologues/epilogues, they're currently emitted as series of load/store instructions.

Using it

For now, you should just build LLC and use a stock Clang that can target XCore and emit LL files. As the VideoCore4 target does not currently support MC code emission, you will have to rely on an external assembler/linker, namely VASM and VLINK.

VASM requires a small patch in order to work but since the license does not allow redistribution of modifications, I cannot include it, but to summarise in the VideoCore cpu.c file, in translate the handler for for 48 bit arithmetic instructions needs to have the first conditional commented out (the one that checks if the instruction number is less than 32).

Once you applied this patch and built VASM and VLINK, you can use it as shown in the Makefile excerpt here:

CC = clang
CXX = clang++
AS = ../vasm/vasmvidcore_std
LINK = ../vlink/vlink
CFLAGS = -S -O3 -D__VIDEOCORE4__ -no-integrated-as -fno-vectorize -fno-slp-vectorize -emit-llvm -target xcore-none-none-none -nostdlib
ASFLAGS = -Fvobj -quiet
LLC =  ../llvm-vc4/build/bin/llc -O3 --mtriple vc4

$(TARGET_BUILD_DIR)/%.o: %.c $(HEADERS)
	$(CREATE_SUBDIR)
	@echo $(WARN_COLOR)CC $(NO_COLOR)  $@
	@$(CC) $(CFLAGS) $< -o [email protected]

	@echo $(WARN_COLOR)LLC$(NO_COLOR)  [email protected]
	@$(LLC) [email protected] -o [email protected]

	@sed -i '/^\t.section/d' [email protected]
	@sed -i '/^\t.bss/d' [email protected]
	@sed -i '/^\t.align	16/c\\t.align 2' [email protected]
	@echo $(WARN_COLOR)AS $(NO_COLOR)  $@
	@$(AS) $(ASFLAGS) [email protected] -o $@

$(TARGET_BOOTCODE): create_build_directory $(OBJ)
	@echo $(WARN_COLOR)LD $(NO_COLOR)  $@
	$(SET_BINUTILS_ENV)
	@$(LINK) $(OBJ) -b rawbin1 -o $(PRODUCT_DIRECTORY)/$@

The first object passed to the linker will be the first one in the binary, so it should have something along the lines of (if you're planning on generating bootcode.bin):

.text
empty_space:
	.space 0x200
# -snip-
.globl _start
.align 1
_start:
	# load the interrupt and normal stack pointers. these
	# are chosen to be near the top of the available cache memory
	mov r28, 0x1D000 
	mov sp, 0x1C000

	# -snip-
	
	# jump to C code
	mov r0, r5
	lea r1, _start(pc)

	ei
	bl _main

llvm-videocore4's People

Contributors

christinaa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.