commit 5a8df9f128f30532fd1a5a2dd393c461b585ff16 Author: Michael Scire Date: Sat Apr 21 20:31:06 2018 -0600 Stratosphere: extract common code to libstratosphere. diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..75ebfc78 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +debug +release +lib +*.bz2 diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..ff0e010e --- /dev/null +++ b/Makefile @@ -0,0 +1,150 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") +endif + +TOPDIR ?= $(CURDIR) +include $(DEVKITPRO)/libnx/switch_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# SOURCES is a list of directories containing source code +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +#--------------------------------------------------------------------------------- +TARGET := $(notdir $(CURDIR)) +SOURCES := source +DATA := data +INCLUDES := include + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE + +CFLAGS := -g -Wall -O2 -ffunction-sections \ + $(ARCH) $(DEFINES) + +CFLAGS += $(INCLUDE) -D__SWITCH__ + +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17 + +ASFLAGS := -g $(ARCH) +LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) + +LIBS := -lnx + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(LIBNX) + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) +export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) +export OFILES := $(OFILES_BIN) $(OFILES_SRC) +export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I. \ + -iquote $(CURDIR)/include/switch/ + +.PHONY: clean all + +#--------------------------------------------------------------------------------- +all: lib/$(TARGET).a lib/$(TARGET)d.a + +lib: + @[ -d $@ ] || mkdir -p $@ + +release: + @[ -d $@ ] || mkdir -p $@ + +debug: + @[ -d $@ ] || mkdir -p $@ + +lib/$(TARGET).a : lib release $(SOURCES) $(INCLUDES) + @$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \ + BUILD_CFLAGS="-DNDEBUG=1 -O2" \ + DEPSDIR=$(CURDIR)/release \ + --no-print-directory -C release \ + -f $(CURDIR)/Makefile + +lib/$(TARGET)d.a : lib debug $(SOURCES) $(INCLUDES) + @$(MAKE) BUILD=debug OUTPUT=$(CURDIR)/$@ \ + BUILD_CFLAGS="-DDEBUG=1 -Og" \ + DEPSDIR=$(CURDIR)/debug \ + --no-print-directory -C debug \ + -f $(CURDIR)/Makefile + +dist-bin: all + @tar --exclude=*~ -cjf $(TARGET).tar.bz2 include lib + +dist-src: + @tar --exclude=*~ -cjf $(TARGET)-src.tar.bz2 include source Makefile + +dist: dist-src dist-bin + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr release debug lib *.bz2 + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT) : $(OFILES) + +$(OFILES_SRC) : $(HFILES) + +#--------------------------------------------------------------------------------- +%_bin.h %.bin.o : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- + diff --git a/include/stratosphere.hpp b/include/stratosphere.hpp new file mode 100644 index 00000000..b4555d87 --- /dev/null +++ b/include/stratosphere.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include "stratosphere/ipc_templating.hpp" +#include "stratosphere/iwaitable.hpp" +#include "stratosphere/iserviceobject.hpp" +#include "stratosphere/servicesession.hpp" +#include "stratosphere/serviceserver.hpp" +#include "stratosphere/waitablemanager.hpp" \ No newline at end of file diff --git a/include/stratosphere/ipc_templating.hpp b/include/stratosphere/ipc_templating.hpp new file mode 100644 index 00000000..12868209 --- /dev/null +++ b/include/stratosphere/ipc_templating.hpp @@ -0,0 +1,411 @@ +#pragma once +#include +#include +#include +#include +#include +#include + +/* Represents an A descriptor. */ +template +struct InBuffer { + T *buffer; + size_t num_elements; + BufferType type; + + InBuffer(void *b, size_t n) : buffer((T *)b), num_elements(n/sizeof(T)) { } +}; + +/* Represents a B descriptor. */ +template +struct OutBuffer { + T *buffer; + size_t num_elements; + + OutBuffer(void *b, size_t n) : buffer((T *)b), num_elements(n/sizeof(T)) { } +}; + +/* Represents an X descriptor. */ +template +struct InPointer { + T *pointer; + size_t num_elements; + + InPointer(void *p, size_t n) : pointer((T *)p), num_elements(n/sizeof(T)) { } +}; + +/* Represents a C descriptor. */ +struct OutPointerWithServerSizeBase {}; + +template +struct OutPointerWithServerSize : OutPointerWithServerSizeBase { + T *pointer; + static const size_t num_elements = n; + + OutPointerWithServerSize(void *p) : pointer((T *)p) { } +}; + +/* Represents a C descriptor with size in raw data. */ +template +struct OutPointerWithClientSize { + T *pointer; + size_t num_elements; + + OutPointerWithClientSize(void *p, size_t n) : pointer((T *)p), num_elements(n/sizeof(T)) { } +}; + +/* Represents an input PID. */ +struct PidDescriptor { + u64 pid; + + PidDescriptor(u64 p) : pid(p) { } +}; + +/* Represents a moved handle. */ +struct MovedHandle { + Handle handle; + + MovedHandle(Handle h) : handle(h) { } +}; + +/* Represents a copied handle. */ +struct CopiedHandle { + Handle handle; + + CopiedHandle(Handle h) : handle(h) { } +}; + +/* Utilities. */ +template class Template> +struct is_specialization_of { + static const bool value = false; +}; + +template