From 9be5f55bfd7d98d025acbb3d682e2cbd245a94c9 Mon Sep 17 00:00:00 2001 From: Jyun-Yan You Date: Tue, 29 Jan 2013 13:04:51 +0800 Subject: [PATCH 1/5] rt: MIPS32 support --- configure | 7 +- mk/libuv/mips/unix/linux/Makefile | 354 ++++++++++++++++++ .../linux/src/libuv/run-benchmarks.target.mk | 122 ++++++ .../unix/linux/src/libuv/run-tests.target.mk | 165 ++++++++ .../mips/unix/linux/src/libuv/uv.Makefile | 6 + .../mips/unix/linux/src/libuv/uv.target.mk | 191 ++++++++++ mk/rt.mk | 6 +- src/rt/arch/mips/_context.S | 81 ++++ src/rt/arch/mips/ccall.S | 12 + src/rt/arch/mips/context.cpp | 46 +++ src/rt/arch/mips/context.h | 51 +++ src/rt/arch/mips/gpr.cpp | 31 ++ src/rt/arch/mips/gpr.h | 33 ++ src/rt/arch/mips/record_sp.S | 44 +++ src/rt/arch/mips/regs.h | 18 + src/rt/rust_task.h | 3 + 16 files changed, 1166 insertions(+), 4 deletions(-) create mode 100644 mk/libuv/mips/unix/linux/Makefile create mode 100644 mk/libuv/mips/unix/linux/src/libuv/run-benchmarks.target.mk create mode 100644 mk/libuv/mips/unix/linux/src/libuv/run-tests.target.mk create mode 100644 mk/libuv/mips/unix/linux/src/libuv/uv.Makefile create mode 100644 mk/libuv/mips/unix/linux/src/libuv/uv.target.mk create mode 100644 src/rt/arch/mips/_context.S create mode 100644 src/rt/arch/mips/ccall.S create mode 100644 src/rt/arch/mips/context.cpp create mode 100644 src/rt/arch/mips/context.h create mode 100644 src/rt/arch/mips/gpr.cpp create mode 100644 src/rt/arch/mips/gpr.h create mode 100644 src/rt/arch/mips/record_sp.S create mode 100644 src/rt/arch/mips/regs.h diff --git a/configure b/configure index 4cbd4eb183279..773d84fb549b5 100755 --- a/configure +++ b/configure @@ -577,8 +577,9 @@ make_dir rt for t in $CFG_TARGET_TRIPLES do make_dir rt/$t - for i in \ - isaac linenoise sync test arch/i386 arch/x86_64 \ + for i in \ + isaac linenoise sync test \ + arch/i386 arch/x86_64 arch/arm arch/mips \ libuv libuv/src/ares libuv/src/eio libuv/src/ev do make_dir rt/$t/$i @@ -717,7 +718,7 @@ do then msg "configuring LLVM for $t" - LLVM_TARGETS="--enable-targets=x86,x86_64,arm" + LLVM_TARGETS="--enable-targets=x86,x86_64,arm,mips" LLVM_BUILD="--build=$t" LLVM_HOST="--host=$t" LLVM_TARGET="--target=$t" diff --git a/mk/libuv/mips/unix/linux/Makefile b/mk/libuv/mips/unix/linux/Makefile new file mode 100644 index 0000000000000..b17f5546016fc --- /dev/null +++ b/mk/libuv/mips/unix/linux/Makefile @@ -0,0 +1,354 @@ +# We borrow heavily from the kernel build setup, though we are simpler since +# we don't have Kconfig tweaking settings on us. + +# The implicit make rules have it looking for RCS files, among other things. +# We instead explicitly write all the rules we care about. +# It's even quicker (saves ~200ms) to pass -r on the command line. +MAKEFLAGS=-r + +# The source directory tree. +srcdir := ../../../../.. +abs_srcdir := $(abspath $(srcdir)) + +# The name of the builddir. +builddir_name ?= out + +# The V=1 flag on command line makes us verbosely print command lines. +ifdef V + quiet= +else + quiet=quiet_ +endif + +# Specify BUILDTYPE=Release on the command line for a release build. +BUILDTYPE ?= Debug + +# Directory all our build output goes into. +# Note that this must be two directories beneath src/ for unit tests to pass, +# as they reach into the src/ directory for data with relative paths. +builddir ?= $(builddir_name)/$(BUILDTYPE) +abs_builddir := $(abspath $(builddir)) +depsdir := $(builddir)/.deps + +# Object output directory. +obj := $(builddir)/obj +abs_obj := $(abspath $(obj)) + +# We build up a list of every single one of the targets so we can slurp in the +# generated dependency rule Makefiles in one pass. +all_deps := + + + +# C++ apps need to be linked with g++. +# +# Note: flock is used to seralize linking. Linking is a memory-intensive +# process so running parallel links can often lead to thrashing. To disable +# the serialization, override LINK via an envrionment variable as follows: +# +# export LINK=g++ +# +# This will allow make to invoke N linker processes as specified in -jN. +LINK ?= flock $(builddir)/linker.lock $(CXX) + +CC.target ?= $(CC) +CFLAGS.target ?= $(CFLAGS) +CXX.target ?= $(CXX) +CXXFLAGS.target ?= $(CXXFLAGS) +LINK.target ?= $(LINK) +LDFLAGS.target ?= $(LDFLAGS) +AR.target ?= $(AR) +ARFLAGS.target ?= crs + +# N.B.: the logic of which commands to run should match the computation done +# in gyp's make.py where ARFLAGS.host etc. is computed. +# TODO(evan): move all cross-compilation logic to gyp-time so we don't need +# to replicate this environment fallback in make as well. +CC.host ?= gcc +CFLAGS.host ?= +CXX.host ?= g++ +CXXFLAGS.host ?= +LINK.host ?= g++ +LDFLAGS.host ?= +AR.host ?= ar +ARFLAGS.host := crs + +# Define a dir function that can handle spaces. +# http://www.gnu.org/software/make/manual/make.html#Syntax-of-Functions +# "leading spaces cannot appear in the text of the first argument as written. +# These characters can be put into the argument value by variable substitution." +empty := +space := $(empty) $(empty) + +# http://stackoverflow.com/questions/1189781/using-make-dir-or-notdir-on-a-path-with-spaces +replace_spaces = $(subst $(space),?,$1) +unreplace_spaces = $(subst ?,$(space),$1) +dirx = $(call unreplace_spaces,$(dir $(call replace_spaces,$1))) + +# Flags to make gcc output dependency info. Note that you need to be +# careful here to use the flags that ccache and distcc can understand. +# We write to a dep file on the side first and then rename at the end +# so we can't end up with a broken dep file. +depfile = $(depsdir)/$(call replace_spaces,$@).d +DEPFLAGS = -MMD -MF $(depfile).raw + +# We have to fixup the deps output in a few ways. +# (1) the file output should mention the proper .o file. +# ccache or distcc lose the path to the target, so we convert a rule of +# the form: +# foobar.o: DEP1 DEP2 +# into +# path/to/foobar.o: DEP1 DEP2 +# (2) we want missing files not to cause us to fail to build. +# We want to rewrite +# foobar.o: DEP1 DEP2 \ +# DEP3 +# to +# DEP1: +# DEP2: +# DEP3: +# so if the files are missing, they're just considered phony rules. +# We have to do some pretty insane escaping to get those backslashes +# and dollar signs past make, the shell, and sed at the same time. +# Doesn't work with spaces, but that's fine: .d files have spaces in +# their names replaced with other characters. +define fixup_dep +# The depfile may not exist if the input file didn't have any #includes. +touch $(depfile).raw +# Fixup path as in (1). +sed -e "s|^$(notdir $@)|$@|" $(depfile).raw >> $(depfile) +# Add extra rules as in (2). +# We remove slashes and replace spaces with new lines; +# remove blank lines; +# delete the first line and append a colon to the remaining lines. +sed -e 's|\\||' -e 'y| |\n|' $(depfile).raw |\ + grep -v '^$$' |\ + sed -e 1d -e 's|$$|:|' \ + >> $(depfile) +rm $(depfile).raw +endef + +# Command definitions: +# - cmd_foo is the actual command to run; +# - quiet_cmd_foo is the brief-output summary of the command. + +quiet_cmd_cc = CC($(TOOLSET)) $@ +cmd_cc = $(CC.$(TOOLSET)) $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c -o $@ $< + +quiet_cmd_cxx = CXX($(TOOLSET)) $@ +cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $< + +quiet_cmd_touch = TOUCH $@ +cmd_touch = touch $@ + +quiet_cmd_copy = COPY $@ +# send stderr to /dev/null to ignore messages when linking directories. +cmd_copy = ln -f "$<" "$@" 2>/dev/null || (rm -rf "$@" && cp -af "$<" "$@") + +quiet_cmd_alink = AR($(TOOLSET)) $@ +cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) $(ARFLAGS.$(TOOLSET)) $@ $(filter %.o,$^) + +# Due to circular dependencies between libraries :(, we wrap the +# special "figure out circular dependencies" flags around the entire +# input list during linking. +quiet_cmd_link = LINK($(TOOLSET)) $@ +cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS) + +# We support two kinds of shared objects (.so): +# 1) shared_library, which is just bundling together many dependent libraries +# into a link line. +# 2) loadable_module, which is generating a module intended for dlopen(). +# +# They differ only slightly: +# In the former case, we want to package all dependent code into the .so. +# In the latter case, we want to package just the API exposed by the +# outermost module. +# This means shared_library uses --whole-archive, while loadable_module doesn't. +# (Note that --whole-archive is incompatible with the --start-group used in +# normal linking.) + +# Other shared-object link notes: +# - Set SONAME to the library filename so our binaries don't reference +# the local, absolute paths used on the link command-line. +quiet_cmd_solink = SOLINK($(TOOLSET)) $@ +cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS) + +quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@ +cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS) + + +# Define an escape_quotes function to escape single quotes. +# This allows us to handle quotes properly as long as we always use +# use single quotes and escape_quotes. +escape_quotes = $(subst ','\'',$(1)) +# This comment is here just to include a ' to unconfuse syntax highlighting. +# Define an escape_vars function to escape '$' variable syntax. +# This allows us to read/write command lines with shell variables (e.g. +# $LD_LIBRARY_PATH), without triggering make substitution. +escape_vars = $(subst $$,$$$$,$(1)) +# Helper that expands to a shell command to echo a string exactly as it is in +# make. This uses printf instead of echo because printf's behaviour with respect +# to escape sequences is more portable than echo's across different shells +# (e.g., dash, bash). +exact_echo = printf '%s\n' '$(call escape_quotes,$(1))' + +# Helper to compare the command we're about to run against the command +# we logged the last time we ran the command. Produces an empty +# string (false) when the commands match. +# Tricky point: Make has no string-equality test function. +# The kernel uses the following, but it seems like it would have false +# positives, where one string reordered its arguments. +# arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ +# $(filter-out $(cmd_$@), $(cmd_$(1)))) +# We instead substitute each for the empty string into the other, and +# say they're equal if both substitutions produce the empty string. +# .d files contain ? instead of spaces, take that into account. +command_changed = $(or $(subst $(cmd_$(1)),,$(cmd_$(call replace_spaces,$@))),\ + $(subst $(cmd_$(call replace_spaces,$@)),,$(cmd_$(1)))) + +# Helper that is non-empty when a prerequisite changes. +# Normally make does this implicitly, but we force rules to always run +# so we can check their command lines. +# $? -- new prerequisites +# $| -- order-only dependencies +prereq_changed = $(filter-out FORCE_DO_CMD,$(filter-out $|,$?)) + +# Helper that executes all postbuilds, and deletes the output file when done +# if any of the postbuilds failed. +define do_postbuilds + @E=0;\ + for p in $(POSTBUILDS); do\ + eval $$p;\ + F=$$?;\ + if [ $$F -ne 0 ]; then\ + E=$$F;\ + fi;\ + done;\ + if [ $$E -ne 0 ]; then\ + rm -rf "$@";\ + exit $$E;\ + fi +endef + +# do_cmd: run a command via the above cmd_foo names, if necessary. +# Should always run for a given target to handle command-line changes. +# Second argument, if non-zero, makes it do asm/C/C++ dependency munging. +# Third argument, if non-zero, makes it do POSTBUILDS processing. +# Note: We intentionally do NOT call dirx for depfile, since it contains ? for +# spaces already and dirx strips the ? characters. +define do_cmd +$(if $(or $(command_changed),$(prereq_changed)), + @$(call exact_echo, $($(quiet)cmd_$(1))) + @mkdir -p "$(call dirx,$@)" "$(dir $(depfile))" + $(if $(findstring flock,$(word 1,$(cmd_$1))), + @$(cmd_$(1)) + @echo " $(quiet_cmd_$(1)): Finished", + @$(cmd_$(1)) + ) + @$(call exact_echo,$(call escape_vars,cmd_$(call replace_spaces,$@) := $(cmd_$(1)))) > $(depfile) + @$(if $(2),$(fixup_dep)) + $(if $(and $(3), $(POSTBUILDS)), + $(call do_postbuilds) + ) +) +endef + +# Declare the "all" target first so it is the default, +# even though we don't have the deps yet. +.PHONY: all +all: + +# Use FORCE_DO_CMD to force a target to run. Should be coupled with +# do_cmd. +.PHONY: FORCE_DO_CMD +FORCE_DO_CMD: + +TOOLSET := target +# Suffix rules, putting all outputs into $(obj). +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cpp FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cxx FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.S FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.s FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# Try building from generated source, too. +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cpp FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cxx FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.S FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.s FORCE_DO_CMD + @$(call do_cmd,cc,1) + +$(obj).$(TOOLSET)/%.o: $(obj)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.cc FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.cpp FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.cxx FORCE_DO_CMD + @$(call do_cmd,cxx,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.S FORCE_DO_CMD + @$(call do_cmd,cc,1) +$(obj).$(TOOLSET)/%.o: $(obj)/%.s FORCE_DO_CMD + @$(call do_cmd,cc,1) + + +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,src/libuv/run-benchmarks.target.mk)))),) + include src/libuv/run-benchmarks.target.mk +endif +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,src/libuv/run-tests.target.mk)))),) + include src/libuv/run-tests.target.mk +endif +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\ + $(findstring $(join ^,$(prefix)),\ + $(join ^,src/libuv/uv.target.mk)))),) + include src/libuv/uv.target.mk +endif + +#quiet_cmd_regen_makefile = ACTION Regenerating $@ +#cmd_regen_makefile = ./src/libuv/build/gyp/gyp -fmake --ignore-environment "--toplevel-dir=." -Isrc/libuv/common.gypi "--depth=." "--generator-output=mk/libuv/mips/unix/linux" "-Ddefault_configuration=Default" "-Dcomponent=static_library" "-Dlibrary=static_library" "-Dtarget_arch=mips" "-DOS=linux" src/libuv/uv.gyp +#Makefile: $(srcdir)/src/libuv/uv.gyp $(srcdir)/src/libuv/common.gypi +# $(call do_cmd,regen_makefile) + +# "all" is a concatenation of the "all" targets from all the included +# sub-makefiles. This is just here to clarify. +all: + +# Add in dependency-tracking rules. $(all_deps) is the list of every single +# target in our tree. Only consider the ones with .d (dependency) info: +d_files := $(wildcard $(foreach f,$(all_deps),$(depsdir)/$(f).d)) +ifneq ($(d_files),) + # Rather than include each individual .d file, concatenate them into a + # single file which make is able to load faster. We split this into + # commands that take 1000 files at a time to avoid overflowing the + # command line. + $(shell cat $(wordlist 1,1000,$(d_files)) > $(depsdir)/all.deps) + + ifneq ($(word 1001,$(d_files)),) + $(error Found unprocessed dependency files (gyp didn't generate enough rules!)) + endif + + # make looks for ways to re-generate included makefiles, but in our case, we + # don't have a direct way. Explicitly telling make that it has nothing to do + # for them makes it go faster. + $(depsdir)/all.deps: ; + + include $(depsdir)/all.deps +endif diff --git a/mk/libuv/mips/unix/linux/src/libuv/run-benchmarks.target.mk b/mk/libuv/mips/unix/linux/src/libuv/run-benchmarks.target.mk new file mode 100644 index 0000000000000..25b01014e79d4 --- /dev/null +++ b/mk/libuv/mips/unix/linux/src/libuv/run-benchmarks.target.mk @@ -0,0 +1,122 @@ +# This file is generated by gyp; do not edit. + +TOOLSET := target +TARGET := run-benchmarks +DEFS_Debug := '-D_LARGEFILE_SOURCE' \ + '-D_FILE_OFFSET_BITS=64' \ + '-D_GNU_SOURCE' \ + '-DEIO_STACKSIZE=262144' \ + '-DDEBUG' \ + '-D_DEBUG' \ + '-DEV_VERIFY=2' + +# Flags passed to all source files. +CFLAGS_Debug := -pthread \ + -Wall \ + -ansi \ + -pthread \ + -fvisibility=hidden \ + -g \ + -O0 + +# Flags passed to only C files. +CFLAGS_C_Debug := + +# Flags passed to only C++ files. +CFLAGS_CC_Debug := -fno-rtti \ + -fno-exceptions + +INCS_Debug := -I$(srcdir)/src/libuv/include + +DEFS_Release := '-D_LARGEFILE_SOURCE' \ + '-D_FILE_OFFSET_BITS=64' \ + '-D_GNU_SOURCE' \ + '-DEIO_STACKSIZE=262144' \ + '-DNDEBUG' + +# Flags passed to all source files. +CFLAGS_Release := -pthread \ + -Wall \ + -ansi \ + -pthread \ + -fvisibility=hidden \ + -O3 \ + -fomit-frame-pointer \ + -fdata-sections \ + -ffunction-sections + +# Flags passed to only C files. +CFLAGS_C_Release := + +# Flags passed to only C++ files. +CFLAGS_CC_Release := -fno-rtti \ + -fno-exceptions + +INCS_Release := -I$(srcdir)/src/libuv/include + +OBJS := $(obj).target/$(TARGET)/src/libuv/test/benchmark-ares.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-getaddrinfo.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-ping-pongs.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-pound.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-pump.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-sizes.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-spawn.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-thread.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-tcp-write-batch.o \ + $(obj).target/$(TARGET)/src/libuv/test/benchmark-udp-packet-storm.o \ + $(obj).target/$(TARGET)/src/libuv/test/dns-server.o \ + $(obj).target/$(TARGET)/src/libuv/test/echo-server.o \ + $(obj).target/$(TARGET)/src/libuv/test/blackhole-server.o \ + $(obj).target/$(TARGET)/src/libuv/test/run-benchmarks.o \ + $(obj).target/$(TARGET)/src/libuv/test/runner.o \ + $(obj).target/$(TARGET)/src/libuv/test/runner-unix.o + +# Add to the list of files we specially track dependencies for. +all_deps += $(OBJS) + +# Make sure our dependencies are built before any of us. +$(OBJS): | $(obj).target/src/libuv/libuv.a + +# CFLAGS et al overrides must be target-local. +# See "Target-specific Variable Values" in the GNU Make manual. +$(OBJS): TOOLSET := $(TOOLSET) +$(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) +$(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) + +# Suffix rules, putting all outputs into $(obj). + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# Try building from generated source, too. + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# End of this set of suffix rules +### Rules for final target. +LDFLAGS_Debug := -pthread + +LDFLAGS_Release := -pthread + +LIBS := -lrt + +$(builddir)/run-benchmarks: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE)) +$(builddir)/run-benchmarks: LIBS := $(LIBS) +$(builddir)/run-benchmarks: LD_INPUTS := $(OBJS) $(obj).target/src/libuv/libuv.a +$(builddir)/run-benchmarks: TOOLSET := $(TOOLSET) +$(builddir)/run-benchmarks: $(OBJS) $(obj).target/src/libuv/libuv.a FORCE_DO_CMD + $(call do_cmd,link) + +all_deps += $(builddir)/run-benchmarks +# Add target alias +.PHONY: run-benchmarks +run-benchmarks: $(builddir)/run-benchmarks + +# Add executable to "all" target. +.PHONY: all +all: $(builddir)/run-benchmarks + diff --git a/mk/libuv/mips/unix/linux/src/libuv/run-tests.target.mk b/mk/libuv/mips/unix/linux/src/libuv/run-tests.target.mk new file mode 100644 index 0000000000000..a2fe0d2065e23 --- /dev/null +++ b/mk/libuv/mips/unix/linux/src/libuv/run-tests.target.mk @@ -0,0 +1,165 @@ +# This file is generated by gyp; do not edit. + +TOOLSET := target +TARGET := run-tests +DEFS_Debug := '-D_LARGEFILE_SOURCE' \ + '-D_FILE_OFFSET_BITS=64' \ + '-D_GNU_SOURCE' \ + '-DEIO_STACKSIZE=262144' \ + '-DDEBUG' \ + '-D_DEBUG' \ + '-DEV_VERIFY=2' + +# Flags passed to all source files. +CFLAGS_Debug := -pthread \ + -Wall \ + -ansi \ + -pthread \ + -fvisibility=hidden \ + -g \ + -O0 + +# Flags passed to only C files. +CFLAGS_C_Debug := + +# Flags passed to only C++ files. +CFLAGS_CC_Debug := -fno-rtti \ + -fno-exceptions + +INCS_Debug := -I$(srcdir)/src/libuv/include + +DEFS_Release := '-D_LARGEFILE_SOURCE' \ + '-D_FILE_OFFSET_BITS=64' \ + '-D_GNU_SOURCE' \ + '-DEIO_STACKSIZE=262144' \ + '-DNDEBUG' + +# Flags passed to all source files. +CFLAGS_Release := -pthread \ + -Wall \ + -ansi \ + -pthread \ + -fvisibility=hidden \ + -O3 \ + -fomit-frame-pointer \ + -fdata-sections \ + -ffunction-sections + +# Flags passed to only C files. +CFLAGS_C_Release := + +# Flags passed to only C++ files. +CFLAGS_CC_Release := -fno-rtti \ + -fno-exceptions + +INCS_Release := -I$(srcdir)/src/libuv/include + +OBJS := $(obj).target/$(TARGET)/src/libuv/test/blackhole-server.o \ + $(obj).target/$(TARGET)/src/libuv/test/echo-server.o \ + $(obj).target/$(TARGET)/src/libuv/test/run-tests.o \ + $(obj).target/$(TARGET)/src/libuv/test/runner.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-get-loadavg.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-util.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-async.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-callback-stack.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-connection-fail.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-cwd-and-chdir.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-delayed-accept.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-eio-overflow.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-fail-always.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-fs.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-fs-event.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-get-currentexe.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-get-memory.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-getaddrinfo.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-gethostbyname.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-getsockname.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-hrtime.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-idle.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-ipc.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-ipc-threads.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-loop-handles.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-multiple-listen.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-pass-always.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-ping-pong.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-pipe-bind-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-pipe-connect-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-platform-output.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-process-title.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-ref.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-shutdown-eof.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-spawn.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-stdio-over-pipes.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-bind-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-bind6-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-close.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-flags.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-connect-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-connect6-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-write-error.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-write-to-half-open-connection.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tcp-writealot.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-threadpool.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-mutexes.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-thread.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-timer-again.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-timer.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-tty.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-udp-dgram-too-big.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-udp-ipv6.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-udp-options.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-udp-send-and-recv.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-udp-multicast-join.o \ + $(obj).target/$(TARGET)/src/libuv/test/test-counters-init.o \ + $(obj).target/$(TARGET)/src/libuv/test/runner-unix.o + +# Add to the list of files we specially track dependencies for. +all_deps += $(OBJS) + +# Make sure our dependencies are built before any of us. +$(OBJS): | $(obj).target/src/libuv/libuv.a + +# CFLAGS et al overrides must be target-local. +# See "Target-specific Variable Values" in the GNU Make manual. +$(OBJS): TOOLSET := $(TOOLSET) +$(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) +$(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) + +# Suffix rules, putting all outputs into $(obj). + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# Try building from generated source, too. + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# End of this set of suffix rules +### Rules for final target. +LDFLAGS_Debug := -pthread + +LDFLAGS_Release := -pthread + +LIBS := -lrt + +$(builddir)/run-tests: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE)) +$(builddir)/run-tests: LIBS := $(LIBS) +$(builddir)/run-tests: LD_INPUTS := $(OBJS) $(obj).target/src/libuv/libuv.a +$(builddir)/run-tests: TOOLSET := $(TOOLSET) +$(builddir)/run-tests: $(OBJS) $(obj).target/src/libuv/libuv.a FORCE_DO_CMD + $(call do_cmd,link) + +all_deps += $(builddir)/run-tests +# Add target alias +.PHONY: run-tests +run-tests: $(builddir)/run-tests + +# Add executable to "all" target. +.PHONY: all +all: $(builddir)/run-tests + diff --git a/mk/libuv/mips/unix/linux/src/libuv/uv.Makefile b/mk/libuv/mips/unix/linux/src/libuv/uv.Makefile new file mode 100644 index 0000000000000..38379e2500137 --- /dev/null +++ b/mk/libuv/mips/unix/linux/src/libuv/uv.Makefile @@ -0,0 +1,6 @@ +# This file is generated by gyp; do not edit. + +export builddir_name ?= mk/libuv/mips/unix/linux/./src/libuv/out +.PHONY: all +all: + $(MAKE) -C ../.. uv run-benchmarks run-tests diff --git a/mk/libuv/mips/unix/linux/src/libuv/uv.target.mk b/mk/libuv/mips/unix/linux/src/libuv/uv.target.mk new file mode 100644 index 0000000000000..9404769e23822 --- /dev/null +++ b/mk/libuv/mips/unix/linux/src/libuv/uv.target.mk @@ -0,0 +1,191 @@ +# This file is generated by gyp; do not edit. + +TOOLSET := target +TARGET := uv +DEFS_Debug := '-D_LARGEFILE_SOURCE' \ + '-D_FILE_OFFSET_BITS=64' \ + '-D_GNU_SOURCE' \ + '-DEIO_STACKSIZE=262144' \ + '-DHAVE_CONFIG_H' \ + '-DEV_CONFIG_H="config_linux.h"' \ + '-DEIO_CONFIG_H="config_linux.h"' \ + '-DDEBUG' \ + '-D_DEBUG' \ + '-DEV_VERIFY=2' + +# Flags passed to all source files. +CFLAGS_Debug := -pthread \ + -Wall \ + -ansi \ + -pthread \ + -fvisibility=hidden \ + -g \ + --std=gnu89 \ + -pedantic \ + -Wall \ + -Wextra \ + -Wno-unused-parameter \ + -g \ + -O0 \ + -fPIC + +# Flags passed to only C files. +CFLAGS_C_Debug := + +# Flags passed to only C++ files. +CFLAGS_CC_Debug := -fno-rtti \ + -fno-exceptions + +INCS_Debug := -I$(srcdir)/src/libuv/include \ + -I$(srcdir)/src/libuv/include/uv-private \ + -I$(srcdir)/src/libuv/src \ + -I$(srcdir)/src/libuv/src/unix/ev \ + -I$(srcdir)/src/libuv/src/ares/config_linux + +DEFS_Release := '-D_LARGEFILE_SOURCE' \ + '-D_FILE_OFFSET_BITS=64' \ + '-D_GNU_SOURCE' \ + '-DEIO_STACKSIZE=262144' \ + '-DHAVE_CONFIG_H' \ + '-DEV_CONFIG_H="config_linux.h"' \ + '-DEIO_CONFIG_H="config_linux.h"' \ + '-DNDEBUG' + +# Flags passed to all source files. +CFLAGS_Release := -pthread \ + -Wall \ + -ansi \ + -pthread \ + -fvisibility=hidden \ + -g \ + --std=gnu89 \ + -pedantic \ + -Wall \ + -Wextra \ + -Wno-unused-parameter \ + -O3 \ + -fomit-frame-pointer \ + -fdata-sections \ + -ffunction-sections \ + -fPIC + +# Flags passed to only C files. +CFLAGS_C_Release := + +# Flags passed to only C++ files. +CFLAGS_CC_Release := -fno-rtti \ + -fno-exceptions + +INCS_Release := -I$(srcdir)/src/libuv/include \ + -I$(srcdir)/src/libuv/include/uv-private \ + -I$(srcdir)/src/libuv/src \ + -I$(srcdir)/src/libuv/src/unix/ev \ + -I$(srcdir)/src/libuv/src/ares/config_linux + +OBJS := $(obj).target/$(TARGET)/src/libuv/src/uv-common.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_cancel.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares__close_sockets.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_data.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_destroy.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_expand_name.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_expand_string.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_fds.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_free_hostent.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_free_string.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_gethostbyaddr.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_gethostbyname.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares__get_hostent.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_getnameinfo.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_getopt.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_getsock.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_init.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_library_init.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_llist.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_mkquery.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_nowarn.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_options.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_aaaa_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_a_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_mx_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_ns_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_ptr_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_srv_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_parse_txt_reply.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_process.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_query.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares__read_line.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_search.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_send.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_strcasecmp.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_strdup.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_strerror.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_timeout.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares__timeval.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_version.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/ares_writev.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/bitncmp.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/inet_net_pton.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/inet_ntop.o \ + $(obj).target/$(TARGET)/src/libuv/src/ares/windows_port.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/core.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/uv-eio.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/fs.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/udp.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/tcp.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/pipe.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/tty.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/stream.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/cares.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/dl.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/error.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/thread.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/process.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/eio/eio.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/ev/ev.o \ + $(obj).target/$(TARGET)/src/libuv/src/unix/linux.o + +# Add to the list of files we specially track dependencies for. +all_deps += $(OBJS) + +# CFLAGS et al overrides must be target-local. +# See "Target-specific Variable Values" in the GNU Make manual. +$(OBJS): TOOLSET := $(TOOLSET) +$(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE)) +$(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE)) + +# Suffix rules, putting all outputs into $(obj). + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# Try building from generated source, too. + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.c FORCE_DO_CMD + @$(call do_cmd,cc,1) + +# End of this set of suffix rules +### Rules for final target. +LDFLAGS_Debug := -pthread + +LDFLAGS_Release := -pthread + +LIBS := -lm + +$(obj).target/src/libuv/libuv.a: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE)) +$(obj).target/src/libuv/libuv.a: LIBS := $(LIBS) +$(obj).target/src/libuv/libuv.a: TOOLSET := $(TOOLSET) +$(obj).target/src/libuv/libuv.a: $(OBJS) FORCE_DO_CMD + $(call do_cmd,alink) + +all_deps += $(obj).target/src/libuv/libuv.a +# Add target alias +.PHONY: uv +uv: $(obj).target/src/libuv/libuv.a + +# Add target alias to "all" target. +.PHONY: all +all: uv + diff --git a/mk/rt.mk b/mk/rt.mk index efabfc397498b..7078fd2fd9486 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -84,8 +84,12 @@ RUNTIME_S_$(1) := rt/arch/$$(HOST_$(1))/_context.S \ ifeq ($$(HOST_$(1)), i386) LIBUV_ARCH_$(1) := ia32 -else +else ifeq ($$(HOST_$(1)), x86_64) LIBUV_ARCH_$(1) := x86_64 +else ifeq ($$(HOST_$(1)), arm) + LIBUV_ARCH_$(1) := arm +else ifeq ($$(HOST_$(1)), mips) + LIBUV_ARCH_$(1) := mips endif ifeq ($$(CFG_WINDOWSY), 1) diff --git a/src/rt/arch/mips/_context.S b/src/rt/arch/mips/_context.S new file mode 100644 index 0000000000000..a903557ba6cb1 --- /dev/null +++ b/src/rt/arch/mips/_context.S @@ -0,0 +1,81 @@ +.text +.globl swap_registers +.align 2 +.set nomips16 +.ent swap_registers +swap_registers: + .set noreorder + .set nomacro + .set noat + sw $1, 1 * 4($4) + sw $2, 2 * 4($4) + sw $3, 3 * 4($4) + sw $4, 4 * 4($4) + sw $5, 5 * 4($4) + sw $6, 6 * 4($4) + sw $7, 7 * 4($4) + + sw $8, 8 * 4($4) + sw $9, 9 * 4($4) + sw $10, 10 * 4($4) + sw $11, 11 * 4($4) + sw $12, 12 * 4($4) + sw $13, 13 * 4($4) + sw $14, 14 * 4($4) + sw $15, 15 * 4($4) + + sw $16, 16 * 4($4) + sw $17, 17 * 4($4) + sw $18, 18 * 4($4) + sw $19, 19 * 4($4) + sw $20, 20 * 4($4) + sw $21, 21 * 4($4) + sw $22, 22 * 4($4) + sw $23, 23 * 4($4) + + sw $24, 24 * 4($4) + sw $25, 25 * 4($4) + sw $26, 26 * 4($4) + sw $27, 27 * 4($4) + sw $28, 28 * 4($4) + sw $29, 29 * 4($4) + sw $30, 30 * 4($4) + sw $31, 31 * 4($4) + + lw $1, 1 * 4($5) + lw $2, 2 * 4($5) + lw $3, 3 * 4($5) + lw $4, 4 * 4($5) + lw $5, 5 * 4($5) + lw $6, 6 * 4($5) + lw $7, 7 * 4($5) + + lw $8, 8 * 4($5) + lw $9, 9 * 4($5) + lw $10, 10 * 4($5) + lw $11, 11 * 4($5) + lw $12, 12 * 4($5) + lw $13, 13 * 4($5) + lw $14, 14 * 4($5) + lw $15, 15 * 4($5) + + lw $16, 16 * 4($5) + lw $17, 17 * 4($5) + lw $18, 18 * 4($5) + lw $19, 19 * 4($5) + lw $20, 20 * 4($5) + lw $21, 21 * 4($5) + lw $22, 22 * 4($5) + lw $23, 23 * 4($5) + + lw $24, 24 * 4($5) + lw $25, 25 * 4($5) + lw $26, 26 * 4($5) + lw $27, 27 * 4($5) + lw $28, 28 * 4($5) + lw $29, 29 * 4($5) + lw $30, 30 * 4($5) + lw $31, 31 * 4($5) + + jr $31 +.end swap_registers diff --git a/src/rt/arch/mips/ccall.S b/src/rt/arch/mips/ccall.S new file mode 100644 index 0000000000000..184c4cd7e45fe --- /dev/null +++ b/src/rt/arch/mips/ccall.S @@ -0,0 +1,12 @@ +.text + +.globl __morestack +.hidden __morestack +.align 2 +.set nomips16 +.ent __morestack +__morestack: + .set noreorder + .set nomacro + +.end __morestack diff --git a/src/rt/arch/mips/context.cpp b/src/rt/arch/mips/context.cpp new file mode 100644 index 0000000000000..d8c3c38daa6df --- /dev/null +++ b/src/rt/arch/mips/context.cpp @@ -0,0 +1,46 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#include "context.h" +#include "../../rust_globals.h" + +extern "C" void CDECL swap_registers(registers_t *oregs, + registers_t *regs) +asm ("swap_registers"); + +context::context() +{ + assert((void*)®s == (void*)this); + memset(®s, 0, sizeof(regs)); +} + +void context::swap(context &out) +{ + swap_registers(&out.regs, ®s); +} + +void context::call(void *f, void *arg, void *stack) +{ + // Get the current context, which we will then modify to call the + // given function. + swap(*this); + + // set up the stack + uint32_t *sp = (uint32_t *)stack; + //sp = align_down(sp); + // The final return address. 0 indicates the bottom of the stack + *--sp = 0; + + regs.data[4] = (uint32_t)arg; + regs.data[29] = (uint32_t)sp; + regs.data[31] = (uint32_t)f; + + // Last base pointer on the stack should be 0 +} diff --git a/src/rt/arch/mips/context.h b/src/rt/arch/mips/context.h new file mode 100644 index 0000000000000..5e2364437ec2c --- /dev/null +++ b/src/rt/arch/mips/context.h @@ -0,0 +1,51 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#ifndef CONTEXT_H +#define CONTEXT_H + +#include +#include +#include +//#include + +#include "vg/memcheck.h" + +template +T align_down(T sp) +{ + // There is no platform we care about that needs more than a + // 16-byte alignment. + return (T)((uint32_t)sp & ~(16 - 1)); +} + +// The struct in which we store the saved data. This is mostly the +// volatile registers and instruction pointer, but it also includes +// RCX/RDI which are used to pass arguments. The indices for each +// register are found in "regs.h". Note that the alignment must be +// 16 bytes so that SSE instructions can be used. +#include "regs.h" +struct registers_t { + uint32_t data[RUSTRT_MAX]; +} __attribute__((aligned(16))); + +class context { +public: + registers_t regs; + + context(); + + context *next; + + void swap(context &out); + void call(void *f, void *arg, void *sp); +}; + +#endif diff --git a/src/rt/arch/mips/gpr.cpp b/src/rt/arch/mips/gpr.cpp new file mode 100644 index 0000000000000..da2f515999fda --- /dev/null +++ b/src/rt/arch/mips/gpr.cpp @@ -0,0 +1,31 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#include "gpr.h" + +#define LOAD(n) do { \ + uintptr_t tmp; \ + asm(".set noat; move %0, $" #n : "=r" (tmp) :); \ + this->r##n = tmp; \ +} while (0) + +void rust_gpr::load() { + LOAD(1); LOAD(2); LOAD(3); + LOAD(4); LOAD(5); LOAD(6); LOAD(7); + + LOAD(8); LOAD(9); LOAD(10); LOAD(11); + LOAD(12); LOAD(13); LOAD(14); LOAD(15); + + LOAD(16); LOAD(17); LOAD(18); LOAD(19); + LOAD(20); LOAD(21); LOAD(22); LOAD(23); + + LOAD(24); LOAD(25); LOAD(26); LOAD(27); + LOAD(28); LOAD(29); LOAD(30); LOAD(31); +} diff --git a/src/rt/arch/mips/gpr.h b/src/rt/arch/mips/gpr.h new file mode 100644 index 0000000000000..a174146e6928d --- /dev/null +++ b/src/rt/arch/mips/gpr.h @@ -0,0 +1,33 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#ifndef GPR_H +#define GPR_H + +#include "rust_gpr_base.h" + +class rust_gpr : public rust_gpr_base { +public: + uintptr_t r0, r1, r2, r3, r4, r5, r6, r7; + uintptr_t r8, r9, r10, r11, r12, r13, r14, r15; + uintptr_t r16, r17, r18, r19, r20, r21, r22, r23; + uintptr_t r24, r25, r26, r27, r28, r29, r30, r31; + + inline uintptr_t get_fp() { return r30; } + inline uintptr_t get_ip() { return r0; } + + inline void set_fp(uintptr_t new_fp) { r30 = new_fp; } + inline void set_ip(uintptr_t new_ip) { r0 = new_ip; } + + void load(); +}; + +#endif + diff --git a/src/rt/arch/mips/record_sp.S b/src/rt/arch/mips/record_sp.S new file mode 100644 index 0000000000000..6821b175c9ee5 --- /dev/null +++ b/src/rt/arch/mips/record_sp.S @@ -0,0 +1,44 @@ +.text + +.globl record_sp_limit +.align 2 +.set nomips16 +.ent record_sp_limit +record_sp_limit: + .set noreorder + .set nomacro + .set push + .set mips32r2 + rdhwr $3, $29 + .set pop + addiu $3, $3, -0x7008 + sw $4, 4($3) + jr $31 +.end record_sp_limit + +.globl get_sp_limit +.align 2 +.set nomips16 +.ent get_sp_limit +get_sp_limit: + .set noreorder + .set nomacro + .set push + .set mips32r2 + rdhwr $3, $29 + .set pop + addiu $3, $3, -0x7008 + lw $2, 4($3) + jr $31 +.end get_sp_limit + +.globl get_sp +.align 2 +.set nomips16 +.ent get_sp +get_sp: + .set noreorder + .set nomacro + move $2, $29 + jr $31 +.end get_sp diff --git a/src/rt/arch/mips/regs.h b/src/rt/arch/mips/regs.h new file mode 100644 index 0000000000000..2f38e1507ad0e --- /dev/null +++ b/src/rt/arch/mips/regs.h @@ -0,0 +1,18 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#define RUSTRT_MAX 32 + +// ARG0 is the register in which the first argument goes. +// Naturally this depends on your operating system. +#define RUSTRT_ARG0_S r4 +#define RUSTRT_ARG1_S r5 +#define RUSTRT_ARG2_S r6 +#define RUSTRT_ARG3_S r7 diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h index 20c9a48f1ddef..2c185d40cc3ed 100644 --- a/src/rt/rust_task.h +++ b/src/rt/rust_task.h @@ -140,6 +140,9 @@ #ifdef __x86_64__ #define RED_ZONE_SIZE RZ_LINUX_64 #endif +#ifdef __mips__ +#define RED_ZONE_SIZE RZ_LINUX_32 +#endif #endif #ifdef __APPLE__ #ifdef __i386__ From a8da1cfc7ce2d70cdaab435bfb71a2b1e1d0c604 Mon Sep 17 00:00:00 2001 From: Jyun-Yan You Date: Tue, 29 Jan 2013 22:28:08 +0800 Subject: [PATCH 2/5] rustc: MIPS32 support --- Makefile.in | 2 +- src/libcore/cleanup.rs | 7 +++ src/libcore/libc.rs | 1 + src/libcore/os.rs | 6 ++ src/libcore/path.rs | 1 + src/libcore/sys.rs | 2 + src/libcore/uint-template/uint.rs | 1 + src/librustc/back/mips.rs | 85 +++++++++++++++++++++++++++++ src/librustc/driver/driver.rs | 13 +++-- src/librustc/driver/session.rs | 2 +- src/librustc/middle/trans/base.rs | 8 ++- src/librustc/middle/trans/common.rs | 6 +- src/librustc/rustc.rc | 1 + src/libstd/bigint.rs | 6 ++ src/libstd/net_tcp.rs | 1 + src/libstd/uv_ll.rs | 14 ++++- src/rustllvm/RustWrapper.cpp | 12 ++++ src/rustllvm/rustllvm.def.in | 7 +++ 18 files changed, 164 insertions(+), 11 deletions(-) create mode 100644 src/librustc/back/mips.rs diff --git a/Makefile.in b/Makefile.in index e476ac1dba2d1..b27b9cf720db9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -241,7 +241,7 @@ DRIVER_CRATE := $(S)src/driver/driver.rs ###################################################################### # FIXME: x86-ism -LLVM_COMPONENTS=x86 arm ipo bitreader bitwriter linker asmparser jit mcjit \ +LLVM_COMPONENTS=x86 arm mips ipo bitreader bitwriter linker asmparser jit mcjit \ interpreter define DEF_LLVM_VARS diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs index 8428484f6300a..45078c5541b29 100644 --- a/src/libcore/cleanup.rs +++ b/src/libcore/cleanup.rs @@ -45,8 +45,14 @@ struct Registers { data: [u32 * 16] } +#[cfg(target_arch="mips")] +struct Registers { + data: [u32 * 32] +} + #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] +#[cfg(target_arch="mips")] struct Context { regs: Registers, next: *Context, @@ -73,6 +79,7 @@ struct BoxedRegion { #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] +#[cfg(target_arch="mips")] struct Task { // Public fields refcount: intptr_t, // 0 diff --git a/src/libcore/libc.rs b/src/libcore/libc.rs index a1107d49c0ec1..c7355a1853ba0 100644 --- a/src/libcore/libc.rs +++ b/src/libcore/libc.rs @@ -206,6 +206,7 @@ pub mod types { #[cfg(target_arch = "x86")] #[cfg(target_arch = "arm")] + #[cfg(target_arch = "mips")] pub mod arch { pub mod c95 { pub type c_char = i8; diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 1f1135ae87132..1086c67794e95 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -974,6 +974,9 @@ pub mod consts { #[cfg(target_arch = "arm")] use os::consts::arm::*; + #[cfg(target_arch = "mips")] + use os::consts::mips::*; + pub mod x86 { pub const ARCH: &str = "x86"; } @@ -983,6 +986,9 @@ pub mod consts { pub mod arm { pub const ARCH: &str = "arm"; } + pub mod mips { + pub const ARCH: &str = "mips"; + } } #[cfg(test)] diff --git a/src/libcore/path.rs b/src/libcore/path.rs index 7f5f334ac1f9a..83bf61df13997 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -93,6 +93,7 @@ pub pure fn Path(s: &str) -> Path { mod stat { #[cfg(target_arch = "x86")] #[cfg(target_arch = "arm")] + #[cfg(target_arch = "mips")] pub mod arch { use libc; diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index 914eccd3d86c0..a926b56afd9f5 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -170,6 +170,7 @@ pub mod tests { #[test] #[cfg(target_arch = "x86")] #[cfg(target_arch = "arm")] + #[cfg(target_arch = "mips")] pub fn size_of_32() { assert size_of::() == 4u; assert size_of::<*uint>() == 4u; @@ -200,6 +201,7 @@ pub mod tests { #[test] #[cfg(target_arch = "x86")] #[cfg(target_arch = "arm")] + #[cfg(target_arch = "mips")] pub fn align_of_32() { assert pref_align_of::() == 4u; assert pref_align_of::<*uint>() == 4u; diff --git a/src/libcore/uint-template/uint.rs b/src/libcore/uint-template/uint.rs index f54290f8394ab..d6b15941ee5de 100644 --- a/src/libcore/uint-template/uint.rs +++ b/src/libcore/uint-template/uint.rs @@ -25,6 +25,7 @@ mod inst { #[cfg(target_arch = "x86")] #[cfg(target_arch = "arm")] + #[cfg(target_arch = "mips")] pub const bits: uint = 32; #[cfg(target_arch = "x86_64")] diff --git a/src/librustc/back/mips.rs b/src/librustc/back/mips.rs new file mode 100644 index 0000000000000..20efb4f6fa55f --- /dev/null +++ b/src/librustc/back/mips.rs @@ -0,0 +1,85 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use back::target_strs; +use driver::session; +use session::sess_os_to_meta_os; +use metadata::loader::meta_section_name; + +fn get_target_strs(target_os: session::os) -> target_strs::t { + return { + module_asm: ~"", + + meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)), + + data_layout: match target_os { + session::os_macos => { + ~"e-p:32:32:32" + + ~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" + + ~"-f32:32:32-f64:64:64" + + ~"-v64:64:64-v128:64:128" + + ~"-a0:0:64-n32" + } + + session::os_win32 => { + ~"e-p:32:32:32" + + ~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" + + ~"-f32:32:32-f64:64:64" + + ~"-v64:64:64-v128:64:128" + + ~"-a0:0:64-n32" + } + + session::os_linux => { + ~"e-p:32:32:32" + + ~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" + + ~"-f32:32:32-f64:64:64" + + ~"-v64:64:64-v128:64:128" + + ~"-a0:0:64-n32" + } + + session::os_android => { + ~"e-p:32:32:32" + + ~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" + + ~"-f32:32:32-f64:64:64" + + ~"-v64:64:64-v128:64:128" + + ~"-a0:0:64-n32" + } + + session::os_freebsd => { + ~"e-p:32:32:32" + + ~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" + + ~"-f32:32:32-f64:64:64" + + ~"-v64:64:64-v128:64:128" + + ~"-a0:0:64-n32" + } + }, + + target_triple: match target_os { + session::os_macos => ~"mips-apple-darwin", + session::os_win32 => ~"mips-pc-mingw32", + session::os_linux => ~"mips-unknown-linux-gnu", + session::os_android => ~"mips-unknown-android-gnu", + session::os_freebsd => ~"mips-unknown-freebsd" + }, + + cc_args: ~[] + }; +} + + +// +// Local Variables: +// mode: rust +// fill-column: 78; +// indent-tabs-mode: nil +// c-basic-offset: 4 +// buffer-file-coding-system: utf-8-unix +// End: +// diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 12281e0b9803f..af31f783dac39 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -11,7 +11,7 @@ use core::prelude::*; use back::link; -use back::{arm, x86, x86_64}; +use back::{arm, x86, x86_64, mips}; use front; use lib::llvm::llvm; use metadata::{creader, cstore, filesearch}; @@ -91,7 +91,8 @@ pub fn default_configuration(sess: Session, +argv0: ~str, input: input) -> let (arch,wordsz) = match sess.targ_cfg.arch { session::arch_x86 => (~"x86",~"32"), session::arch_x86_64 => (~"x86_64",~"64"), - session::arch_arm => (~"arm",~"32") + session::arch_arm => (~"arm",~"32"), + session::arch_mips => (~"mips",~"32") }; return ~[ // Target bindings. @@ -452,6 +453,8 @@ pub fn get_arch(triple: ~str) -> Option { } else if str::contains(triple, ~"arm") || str::contains(triple, ~"xscale") { Some(session::arch_arm) + } else if str::contains(triple, ~"mips") { + Some(session::arch_mips) } else { None } } @@ -470,12 +473,14 @@ pub fn build_target_config(sopts: @session::options, let (int_type, uint_type, float_type) = match arch { session::arch_x86 => (ast::ty_i32, ast::ty_u32, ast::ty_f64), session::arch_x86_64 => (ast::ty_i64, ast::ty_u64, ast::ty_f64), - session::arch_arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64) + session::arch_arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64), + session::arch_mips => (ast::ty_i32, ast::ty_u32, ast::ty_f64) }; let target_strs = match arch { session::arch_x86 => x86::get_target_strs(os), session::arch_x86_64 => x86_64::get_target_strs(os), - session::arch_arm => arm::get_target_strs(os) + session::arch_arm => arm::get_target_strs(os), + session::arch_mips => mips::get_target_strs(os) }; let target_cfg: @session::config = @{os: os, arch: arch, target_strs: target_strs, int_type: int_type, diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 3b32952ba3175..8ec04abfffaba 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -38,7 +38,7 @@ pub impl os : cmp::Eq { pure fn ne(&self, other: &os) -> bool { !(*self).eq(other) } } -pub enum arch { arch_x86, arch_x86_64, arch_arm, } +pub enum arch { arch_x86, arch_x86_64, arch_arm, arch_mips, } pub impl arch : cmp::Eq { pure fn eq(&self, other: &arch) -> bool { diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 7961350a69ec5..3607118eb7298 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1431,7 +1431,9 @@ fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef, let _icx = cx.insn_ctxt("call_memcpy"); let ccx = cx.ccx(); let key = match ccx.sess.targ_cfg.arch { - session::arch_x86 | session::arch_arm => ~"llvm.memcpy.p0i8.p0i8.i32", + session::arch_x86 + | session::arch_arm + | session::arch_mips => ~"llvm.memcpy.p0i8.p0i8.i32", session::arch_x86_64 => ~"llvm.memcpy.p0i8.p0i8.i64" }; let memcpy = ccx.intrinsics.get(key); @@ -1473,7 +1475,9 @@ fn memzero(cx: block, llptr: ValueRef, llty: TypeRef) { let intrinsic_key; match ccx.sess.targ_cfg.arch { - session::arch_x86 | session::arch_arm => { + session::arch_x86 + | session::arch_arm + | session::arch_mips => { intrinsic_key = ~"llvm.memset.p0i8.i32"; } session::arch_x86_64 => { diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 3babfbd8285fd..94397f553240c 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -785,7 +785,8 @@ fn T_int(targ_cfg: @session::config) -> TypeRef { return match targ_cfg.arch { session::arch_x86 => T_i32(), session::arch_x86_64 => T_i64(), - session::arch_arm => T_i32() + session::arch_arm => T_i32(), + session::arch_mips => T_i32() }; } @@ -822,7 +823,8 @@ fn T_float(targ_cfg: @session::config) -> TypeRef { return match targ_cfg.arch { session::arch_x86 => T_f64(), session::arch_x86_64 => T_f64(), - session::arch_arm => T_f64() + session::arch_arm => T_f64(), + session::arch_mips => T_f64() }; } diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc index c61a84c9082b8..d7a59f2cbb80c 100644 --- a/src/librustc/rustc.rc +++ b/src/librustc/rustc.rc @@ -148,6 +148,7 @@ pub mod back { pub mod abi; pub mod upcall; pub mod arm; + pub mod mips; pub mod x86; pub mod x86_64; pub mod rpath; diff --git a/src/libstd/bigint.rs b/src/libstd/bigint.rs index 4283a7e402bce..51c4a00a6b1f1 100644 --- a/src/libstd/bigint.rs +++ b/src/libstd/bigint.rs @@ -27,6 +27,7 @@ A BigDigit is half the size of machine word size. */ #[cfg(target_arch = "x86")] #[cfg(target_arch = "arm")] +#[cfg(target_arch = "mips")] pub type BigDigit = u16; /** @@ -42,6 +43,7 @@ pub mod BigDigit { #[cfg(target_arch = "x86")] #[cfg(target_arch = "arm")] + #[cfg(target_arch = "mips")] pub const bits: uint = 16; #[cfg(target_arch = "x86_64")] @@ -529,6 +531,7 @@ priv pure fn get_radix_base(radix: uint) -> (uint, uint) { #[cfg(target_arch = "arm")] #[cfg(target_arch = "x86")] +#[cfg(target_arch = "mips")] priv pure fn get_radix_base(radix: uint) -> (uint, uint) { assert 1 < radix && radix <= 16; match radix { @@ -945,6 +948,7 @@ mod biguint_tests { #[cfg(target_arch = "arm")] #[cfg(target_arch = "x86")] + #[cfg(target_arch = "mips")] fn test_shl_bits() { check(~[0x3210, 0x7654, 0xba98, 0xfedc, 0x3210, 0x7654, 0xba98, 0xfedc], 4, @@ -961,6 +965,7 @@ mod biguint_tests { #[test] #[ignore(cfg(target_arch = "x86"))] #[ignore(cfg(target_arch = "arm"))] + #[ignore(cfg(target_arch = "mips"))] fn test_shr() { fn check(v: ~[BigDigit], shift: uint, ans: ~[BigDigit]) { assert BigUint::new(v) >> shift == BigUint::new(ans); @@ -988,6 +993,7 @@ mod biguint_tests { #[cfg(target_arch = "arm")] #[cfg(target_arch = "x86")] + #[cfg(target_arch = "mips")] fn test_shr_bits() { check(~[0x2100, 0x6543, 0xa987, 0xedcb, 0x210f, 0x6543, 0xa987, 0xedcb, 0xf], 4, diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index d9e4bfc540ccb..31941a87310c4 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -1500,6 +1500,7 @@ pub mod test { } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] + #[cfg(target_arch="mips")] pub mod impl32 { use net::tcp::test::*; diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index 8bef6eb6c9186..3f96042e20397 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -111,6 +111,7 @@ pub struct uv_tcp_t_32bit_unix_riders { } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] +#[cfg(target_arch="mips")] pub struct uv_tcp_t_32bit_unix_riders { a29: *u8, a30: *u8, a31: *u8, a32: *u8, a33: *u8, a34: *u8, @@ -168,6 +169,7 @@ pub struct uv_write_t_32bit_unix_riders { } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] +#[cfg(target_arch="mips")] pub struct uv_write_t_32bit_unix_riders { a13: *u8, a14: *u8, } @@ -196,6 +198,7 @@ pub struct uv_async_t_32bit_unix_riders { } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] +#[cfg(target_arch="mips")] pub struct uv_async_t_32bit_unix_riders { a10: *u8, a11: *u8, a12: *u8, a13: *u8, } @@ -225,6 +228,7 @@ pub struct uv_timer_t_32bit_unix_riders { } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] +#[cfg(target_arch="mips")] pub struct uv_timer_t_32bit_unix_riders { a10: *u8, a11: *u8, a12: *u8, a13: *u8, a14: *u8, a15: *u8, a16: *u8, @@ -255,6 +259,7 @@ pub struct sockaddr_in6 { } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] +#[cfg(target_arch="mips")] pub struct sockaddr_in6 { a0: *u8, a1: *u8, a2: *u8, a3: *u8, @@ -273,7 +278,8 @@ pub mod addr_in_impl { a2: *u8, a3: *u8, } #[cfg(target_arch="x86")] -#[cfg(target_arch="arm")] + #[cfg(target_arch="arm")] + #[cfg(target_arch="mips")] pub struct addr_in { a0: *u8, a1: *u8, a2: *u8, a3: *u8, @@ -301,6 +307,7 @@ pub mod addrinfo_impl { } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] + #[cfg(target_arch="mips")] pub struct addrinfo { a00: *u8, a01: *u8, a02: *u8, a03: *u8, a04: *u8, a05: *u8, a06: *u8, a07: *u8, @@ -388,6 +395,7 @@ pub mod uv_ll_struct_stubgen { } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] + #[cfg(target_arch="mips")] pub fn gen_stub_arch() -> uv_tcp_t { uv_tcp_t { fields: uv_handle_fields { @@ -481,6 +489,7 @@ pub mod uv_ll_struct_stubgen { } #[cfg(target_arch = "x86")] #[cfg(target_arch="arm")] + #[cfg(target_arch="mips")] pub fn gen_stub_arch() -> uv_async_t { uv_async_t { fields: uv_handle_fields { @@ -540,6 +549,7 @@ pub mod uv_ll_struct_stubgen { } #[cfg(target_arch = "x86")] #[cfg(target_arch="arm")] + #[cfg(target_arch="mips")] pub fn gen_stub_arch() -> uv_timer_t { uv_timer_t { fields: uv_handle_fields { @@ -600,6 +610,7 @@ pub mod uv_ll_struct_stubgen { } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] + #[cfg(target_arch="mips")] pub fn gen_stub_arch() -> uv_write_t { uv_write_t { fields: uv_handle_fields { @@ -1681,6 +1692,7 @@ pub mod test { } #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] + #[cfg(target_arch="mips")] pub mod impl32 { use uv_ll::test::*; #[test] diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 3c38f3c6215d4..3af936d34612b 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -97,6 +97,12 @@ void LLVMInitializeARMTarget(); void LLVMInitializeARMTargetMC(); void LLVMInitializeARMAsmPrinter(); void LLVMInitializeARMAsmParser(); + +void LLVMInitializeMipsTargetInfo(); +void LLVMInitializeMipsTarget(); +void LLVMInitializeMipsTargetMC(); +void LLVMInitializeMipsAsmPrinter(); +void LLVMInitializeMipsAsmParser(); // Only initialize the platforms supported by Rust here, // because using --llvm-root will have multiple platforms // that rustllvm doesn't actually link to and it's pointless to put target info @@ -114,6 +120,12 @@ void LLVMRustInitializeTargets() { LLVMInitializeARMTargetMC(); LLVMInitializeARMAsmPrinter(); LLVMInitializeARMAsmParser(); + + LLVMInitializeMipsTargetInfo(); + LLVMInitializeMipsTarget(); + LLVMInitializeMipsTargetMC(); + LLVMInitializeMipsAsmPrinter(); + LLVMInitializeMipsAsmParser(); } // Custom memory manager for MCJITting. It needs special features diff --git a/src/rustllvm/rustllvm.def.in b/src/rustllvm/rustllvm.def.in index d3cbc490ada45..f1acf9d0dc80f 100644 --- a/src/rustllvm/rustllvm.def.in +++ b/src/rustllvm/rustllvm.def.in @@ -384,18 +384,25 @@ LLVMInitializeScalarOpts LLVMInitializeTarget LLVMInitializeTransformUtils LLVMInitializeARMAsmLexer +LLVMInitializeMipsAsmLexer LLVMInitializeX86AsmLexer LLVMInitializeARMAsmParser +LLVMInitializeMipsAsmParser LLVMInitializeX86AsmParser LLVMInitializeARMAsmPrinter +LLVMInitializeMipsAsmPrinter LLVMInitializeX86AsmPrinter LLVMInitializeARMDisassembler +LLVMInitializeMipsDisassembler LLVMInitializeX86Disassembler LLVMInitializeARMTarget +LLVMInitializeMipsTarget LLVMInitializeX86Target LLVMInitializeARMTargetMC +LLVMInitializeMipsTargetMC LLVMInitializeX86TargetMC LLVMInitializeARMTargetInfo +LLVMInitializeMipsTargetInfo LLVMInitializeX86TargetInfo LLVMInsertBasicBlock LLVMInsertBasicBlockInContext From 4a8a0abcc50fafd56d409d44214a44441e8f395c Mon Sep 17 00:00:00 2001 From: Jyun-Yan You Date: Wed, 30 Jan 2013 01:31:50 +0800 Subject: [PATCH 3/5] rustc: implement MIPS O32 ABI --- src/librustc/middle/trans/cabi_mips.rs | 220 +++++++++++++++++++++++++ src/librustc/middle/trans/foreign.rs | 5 +- src/librustc/rustc.rc | 2 + 3 files changed, 225 insertions(+), 2 deletions(-) create mode 100644 src/librustc/middle/trans/cabi_mips.rs diff --git a/src/librustc/middle/trans/cabi_mips.rs b/src/librustc/middle/trans/cabi_mips.rs new file mode 100644 index 0000000000000..ee2336cd3a50c --- /dev/null +++ b/src/librustc/middle/trans/cabi_mips.rs @@ -0,0 +1,220 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use lib::llvm::{llvm, TypeRef, ValueRef, Integer, Pointer, Float, Double}; +use lib::llvm::{Struct, Array, Attribute}; +use lib::llvm::{StructRetAttribute, ByValAttribute}; +use middle::trans::common::*; +use middle::trans::cabi::*; + +export mips_abi_info; + +fn align_up_to(off: uint, a: uint) -> uint { + return (off + a - 1u) / a * a; +} + +fn align(off: uint, ty: TypeRef) -> uint { + let a = ty_align(ty); + return align_up_to(off, a); +} + +fn struct_tys(ty: TypeRef) -> ~[TypeRef] { + unsafe { + let n = llvm::LLVMCountStructElementTypes(ty); + if (n == 0) { + return ~[]; + } + let mut elts = vec::from_elem(n as uint, ptr::null()); + llvm::LLVMGetStructElementTypes(ty, + ptr::to_mut_unsafe_ptr(&mut elts[0])); + return elts; + } +} + +fn ty_align(ty: TypeRef) -> uint { + unsafe { + return match llvm::LLVMGetTypeKind(ty) { + Integer => { + ((llvm::LLVMGetIntTypeWidth(ty) as uint) + 7) / 8 + } + Pointer => 4, + Float => 4, + Double => 8, + Struct => { + do vec::foldl(1, struct_tys(ty)) |a, t| { + uint::max(a, ty_align(*t)) + } + } + Array => { + let elt = llvm::LLVMGetElementType(ty); + ty_align(elt) + } + _ => fail ~"ty_size: unhandled type" + }; + } +} + +fn ty_size(ty: TypeRef) -> uint { + unsafe { + return match llvm::LLVMGetTypeKind(ty) { + Integer => { + ((llvm::LLVMGetIntTypeWidth(ty) as uint) + 7) / 8 + } + Pointer => 4, + Float => 4, + Double => 8, + Struct => { + let size = do vec::foldl(0, struct_tys(ty)) |s, t| { + align(s, *t) + ty_size(*t) + }; + align(size, ty) + } + Array => { + let len = llvm::LLVMGetArrayLength(ty) as uint; + let elt = llvm::LLVMGetElementType(ty); + let eltsz = ty_size(elt); + len * eltsz + } + _ => fail ~"ty_size: unhandled type" + }; + } +} + +fn classify_ret_ty(ty: TypeRef) -> (LLVMType, Option) { + return if is_reg_ty(ty) { + (LLVMType { cast: false, ty: ty }, None) + } else { + (LLVMType { cast: false, ty: T_ptr(ty) }, Some(StructRetAttribute)) + }; +} + +fn classify_arg_ty(ty: TypeRef, + offset: &mut uint) -> (LLVMType, Option) { + let orig_offset = *offset; + let size = ty_size(ty) * 8; + let mut align = ty_align(ty); + + align = uint::min(uint::max(align, 4), 8); + *offset = align_up_to(*offset, align); + *offset += align_up_to(size, align * 8) / 8; + + let padding = padding_ty(align, orig_offset); + return if !is_reg_ty(ty) { + (LLVMType { + cast: true, + ty: struct_ty(ty, padding, true) + }, None) + } else if padding.is_some() { + (LLVMType { + cast: true, + ty: struct_ty(ty, padding, false) + }, None) + } else { + (LLVMType { cast: false, ty: ty }, None) + }; +} + +fn is_reg_ty(ty: TypeRef) -> bool { + unsafe { + return match llvm::LLVMGetTypeKind(ty) { + Integer + | Pointer + | Float + | Double => true, + _ => false + }; + } +} + +fn padding_ty(align: uint, offset: uint) -> Option { + if ((align - 1 ) & offset) > 0 { + return Some(T_i32()); + } + + return None; +} + +fn coerce_to_int(size: uint) -> ~[TypeRef] { + let int_ty = T_i32(); + let mut args = ~[]; + + let mut n = size / 32; + while n > 0 { + args.push(int_ty); + n -= 1; + } + + let r = size % 32; + if r > 0 { + unsafe { + args.push(llvm::LLVMIntType(r as c_uint)) + } + } + + return args; +} + +fn struct_ty(ty: TypeRef, + padding: Option, + coerce: bool) -> TypeRef { + let size = ty_size(ty) * 8; + let mut fields = padding.map_default(~[], |p| ~[*p]); + + if coerce { + fields = vec::append(fields, coerce_to_int(size)); + } else { + fields.push(ty); + } + + return T_struct(fields); +} + +enum MIPS_ABIInfo { MIPS_ABIInfo } + +impl MIPS_ABIInfo: ABIInfo { + fn compute_info(&self, + atys: &[TypeRef], + rty: TypeRef, + ret_def: bool) -> FnType { + let mut (ret_ty, ret_attr) = if ret_def { + classify_ret_ty(rty) + } else { + (LLVMType { cast: false, ty: T_void() }, None) + }; + + let sret = ret_attr.is_some(); + let mut arg_tys = ~[]; + let mut attrs = ~[]; + let mut offset = if sret { 4 } else { 0 }; + + for atys.each() |aty| { + let (ty, attr) = classify_arg_ty(*aty, &mut offset); + arg_tys.push(ty); + attrs.push(attr); + }; + + if sret { + arg_tys = vec::append(~[ret_ty], arg_tys); + attrs = vec::append(~[ret_attr], attrs); + ret_ty = LLVMType { cast: false, ty: T_void() }; + } + + return FnType { + arg_tys: arg_tys, + ret_ty: ret_ty, + attrs: attrs, + sret: sret + }; + } +} + +fn mips_abi_info() -> ABIInfo { + return MIPS_ABIInfo as ABIInfo; +} diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 1ebd497a61d5b..625f735a29638 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -11,8 +11,7 @@ use core::prelude::*; use back::{link, abi}; -use driver::session::arch_x86_64; -use driver::session::arch_arm; +use driver::session::{arch_x86_64, arch_mips}; use lib::llvm::{SequentiallyConsistent, Acquire, Release, Xchg}; use lib::llvm::{Struct, Array, ModuleRef, CallConv, Attribute}; use lib::llvm::{StructRetAttribute, ByValAttribute}; @@ -21,6 +20,7 @@ use lib; use middle::trans::base::*; use middle::trans::cabi; use middle::trans::cabi_x86_64::*; +use middle::trans::cabi_mips::*; use middle::trans::build::*; use middle::trans::callee::*; use middle::trans::common::*; @@ -46,6 +46,7 @@ export link_name, trans_foreign_mod, register_foreign_fn, trans_foreign_fn, fn abi_info(arch: session::arch) -> cabi::ABIInfo { return match arch { arch_x86_64 => x86_64_abi_info(), + arch_mips => mips_abi_info(), _ => cabi::llvm_abi_info() } } diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc index d7a59f2cbb80c..d057dde4a1504 100644 --- a/src/librustc/rustc.rc +++ b/src/librustc/rustc.rc @@ -82,6 +82,8 @@ pub mod middle { #[legacy_exports] pub mod cabi_x86_64; #[legacy_exports] + pub mod cabi_mips; + #[legacy_exports] pub mod foreign; #[legacy_exports] pub mod reflect; From ed6610f1d4997db38caf8cf67c126cbbebe8edfa Mon Sep 17 00:00:00 2001 From: Jyun-Yan You Date: Wed, 30 Jan 2013 23:42:48 +0800 Subject: [PATCH 4/5] rt: fix some bugs for MIPS target --- src/rt/arch/mips/_context.S | 1 + src/rt/arch/mips/ccall.S | 17 +++++++++++++++++ src/rt/arch/mips/gpr.h | 4 ++-- src/rt/arch/mips/record_sp.S | 3 +++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/rt/arch/mips/_context.S b/src/rt/arch/mips/_context.S index a903557ba6cb1..614cf68681708 100644 --- a/src/rt/arch/mips/_context.S +++ b/src/rt/arch/mips/_context.S @@ -78,4 +78,5 @@ swap_registers: lw $31, 31 * 4($5) jr $31 + nop .end swap_registers diff --git a/src/rt/arch/mips/ccall.S b/src/rt/arch/mips/ccall.S index 184c4cd7e45fe..522714a8807b4 100644 --- a/src/rt/arch/mips/ccall.S +++ b/src/rt/arch/mips/ccall.S @@ -8,5 +8,22 @@ __morestack: .set noreorder .set nomacro + move $7, $29 + move $29, $6 + sw $7, 0($29) + sw $31, -4($29) + + addiu $29, $29, -24 + move $25, $5 + jalr $25 + nop + addiu $29, $29, 24 + + lw $31, -4($29) + lw $7, 0($29) + + move $29, $7 + jr $31 + nop .end __morestack diff --git a/src/rt/arch/mips/gpr.h b/src/rt/arch/mips/gpr.h index a174146e6928d..4ff0729633a64 100644 --- a/src/rt/arch/mips/gpr.h +++ b/src/rt/arch/mips/gpr.h @@ -21,10 +21,10 @@ class rust_gpr : public rust_gpr_base { uintptr_t r24, r25, r26, r27, r28, r29, r30, r31; inline uintptr_t get_fp() { return r30; } - inline uintptr_t get_ip() { return r0; } + inline uintptr_t get_ip() { return r31; } inline void set_fp(uintptr_t new_fp) { r30 = new_fp; } - inline void set_ip(uintptr_t new_ip) { r0 = new_ip; } + inline void set_ip(uintptr_t new_ip) { r31 = new_ip; } void load(); }; diff --git a/src/rt/arch/mips/record_sp.S b/src/rt/arch/mips/record_sp.S index 6821b175c9ee5..6b782fc4629ec 100644 --- a/src/rt/arch/mips/record_sp.S +++ b/src/rt/arch/mips/record_sp.S @@ -14,6 +14,7 @@ record_sp_limit: addiu $3, $3, -0x7008 sw $4, 4($3) jr $31 + nop .end record_sp_limit .globl get_sp_limit @@ -30,6 +31,7 @@ get_sp_limit: addiu $3, $3, -0x7008 lw $2, 4($3) jr $31 + nop .end get_sp_limit .globl get_sp @@ -41,4 +43,5 @@ get_sp: .set nomacro move $2, $29 jr $31 + nop .end get_sp From 534488a6fbb54f5c3cd3a609b549e02538e29882 Mon Sep 17 00:00:00 2001 From: Jyun-Yan You Date: Thu, 31 Jan 2013 00:10:20 +0800 Subject: [PATCH 5/5] rustc: add missing pub for back::mips::get_target_strs --- src/librustc/back/mips.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/back/mips.rs b/src/librustc/back/mips.rs index 20efb4f6fa55f..b9890120c3fe3 100644 --- a/src/librustc/back/mips.rs +++ b/src/librustc/back/mips.rs @@ -13,7 +13,7 @@ use driver::session; use session::sess_os_to_meta_os; use metadata::loader::meta_section_name; -fn get_target_strs(target_os: session::os) -> target_strs::t { +pub fn get_target_strs(target_os: session::os) -> target_strs::t { return { module_asm: ~"",