From b81ceeca21eb970194647755ee61622f5bb95938 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 21 Apr 2018 20:31:06 -0600 Subject: [PATCH] Stratosphere: extract common code to libstratosphere. --- stratosphere/libstratosphere/.gitignore | 4 + stratosphere/libstratosphere/Makefile | 150 ++++++++++++++++++ .../libstratosphere/include/stratosphere.hpp | 8 + .../include/stratosphere}/ipc_templating.hpp | 2 - .../include/stratosphere}/iserviceobject.hpp | 0 .../include/stratosphere}/iwaitable.hpp | 0 .../include/stratosphere}/serviceserver.hpp | 4 - .../include/stratosphere}/servicesession.hpp | 6 +- .../include/stratosphere}/waitablemanager.hpp | 0 .../source/waitablemanager.cpp | 2 +- stratosphere/loader/Makefile | 6 +- .../loader/source/ldr_debug_monitor.hpp | 2 +- stratosphere/loader/source/ldr_main.cpp | 3 +- .../loader/source/ldr_process_manager.hpp | 2 +- stratosphere/loader/source/ldr_shell.hpp | 3 +- 15 files changed, 171 insertions(+), 21 deletions(-) create mode 100644 stratosphere/libstratosphere/.gitignore create mode 100644 stratosphere/libstratosphere/Makefile create mode 100644 stratosphere/libstratosphere/include/stratosphere.hpp rename stratosphere/{loader/source => libstratosphere/include/stratosphere}/ipc_templating.hpp (99%) rename stratosphere/{loader/source => libstratosphere/include/stratosphere}/iserviceobject.hpp (100%) rename stratosphere/{loader/source => libstratosphere/include/stratosphere}/iwaitable.hpp (100%) rename stratosphere/{loader/source => libstratosphere/include/stratosphere}/serviceserver.hpp (93%) rename stratosphere/{loader/source => libstratosphere/include/stratosphere}/servicesession.hpp (98%) rename stratosphere/{loader/source => libstratosphere/include/stratosphere}/waitablemanager.hpp (100%) rename stratosphere/{loader => libstratosphere}/source/waitablemanager.cpp (98%) diff --git a/stratosphere/libstratosphere/.gitignore b/stratosphere/libstratosphere/.gitignore new file mode 100644 index 000000000..75ebfc783 --- /dev/null +++ b/stratosphere/libstratosphere/.gitignore @@ -0,0 +1,4 @@ +debug +release +lib +*.bz2 diff --git a/stratosphere/libstratosphere/Makefile b/stratosphere/libstratosphere/Makefile new file mode 100644 index 000000000..ff0e010e7 --- /dev/null +++ b/stratosphere/libstratosphere/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/stratosphere/libstratosphere/include/stratosphere.hpp b/stratosphere/libstratosphere/include/stratosphere.hpp new file mode 100644 index 000000000..b4555d87e --- /dev/null +++ b/stratosphere/libstratosphere/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/stratosphere/loader/source/ipc_templating.hpp b/stratosphere/libstratosphere/include/stratosphere/ipc_templating.hpp similarity index 99% rename from stratosphere/loader/source/ipc_templating.hpp rename to stratosphere/libstratosphere/include/stratosphere/ipc_templating.hpp index eb9504851..128682095 100644 --- a/stratosphere/loader/source/ipc_templating.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/ipc_templating.hpp @@ -1,12 +1,10 @@ #pragma once #include -#include #include #include #include #include #include -#include /* Represents an A descriptor. */ template diff --git a/stratosphere/loader/source/iserviceobject.hpp b/stratosphere/libstratosphere/include/stratosphere/iserviceobject.hpp similarity index 100% rename from stratosphere/loader/source/iserviceobject.hpp rename to stratosphere/libstratosphere/include/stratosphere/iserviceobject.hpp diff --git a/stratosphere/loader/source/iwaitable.hpp b/stratosphere/libstratosphere/include/stratosphere/iwaitable.hpp similarity index 100% rename from stratosphere/loader/source/iwaitable.hpp rename to stratosphere/libstratosphere/include/stratosphere/iwaitable.hpp diff --git a/stratosphere/loader/source/serviceserver.hpp b/stratosphere/libstratosphere/include/stratosphere/serviceserver.hpp similarity index 93% rename from stratosphere/loader/source/serviceserver.hpp rename to stratosphere/libstratosphere/include/stratosphere/serviceserver.hpp index f1896fea0..7de6431d0 100644 --- a/stratosphere/loader/source/serviceserver.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/serviceserver.hpp @@ -92,11 +92,7 @@ class ServiceServer : public IWaitable { Handle session_h; svcAcceptSession(&session_h, this->port_handle); - fprintf(stderr, "Accept %08X -> %08X\n", this->port_handle, session_h); - fprintf(stderr, "Sessions: %08X/%08X\n", this->num_sessions, this->max_sessions); - if (this->num_sessions >= this->max_sessions) { - fprintf(stderr, "Closing because of max sessions...\n"); svcCloseHandle(session_h); return 0x10601; } diff --git a/stratosphere/loader/source/servicesession.hpp b/stratosphere/libstratosphere/include/stratosphere/servicesession.hpp similarity index 98% rename from stratosphere/loader/source/servicesession.hpp rename to stratosphere/libstratosphere/include/stratosphere/servicesession.hpp index 2a20d91c8..e7430de2e 100644 --- a/stratosphere/loader/source/servicesession.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/servicesession.hpp @@ -1,7 +1,6 @@ #pragma once #include #include -#include #include "ipc_templating.hpp" #include "iserviceobject.hpp" @@ -89,10 +88,7 @@ class ServiceSession : public IWaitable { IpcParsedCommand r; IpcCommand c; - - - fprintf(stderr, "Doing ServiceSession parse...\n"); - + ipcInitialize(&c); retval = ipcParse(&r); diff --git a/stratosphere/loader/source/waitablemanager.hpp b/stratosphere/libstratosphere/include/stratosphere/waitablemanager.hpp similarity index 100% rename from stratosphere/loader/source/waitablemanager.hpp rename to stratosphere/libstratosphere/include/stratosphere/waitablemanager.hpp diff --git a/stratosphere/loader/source/waitablemanager.cpp b/stratosphere/libstratosphere/source/waitablemanager.cpp similarity index 98% rename from stratosphere/loader/source/waitablemanager.cpp rename to stratosphere/libstratosphere/source/waitablemanager.cpp index 733740b36..5eee835c5 100644 --- a/stratosphere/loader/source/waitablemanager.cpp +++ b/stratosphere/libstratosphere/source/waitablemanager.cpp @@ -3,7 +3,7 @@ #include #include -#include "waitablemanager.hpp" +#include unsigned int WaitableManager::get_num_signalable() { diff --git a/stratosphere/loader/Makefile b/stratosphere/loader/Makefile index a6304873f..74ee33781 100644 --- a/stratosphere/loader/Makefile +++ b/stratosphere/loader/Makefile @@ -48,18 +48,18 @@ CFLAGS := -g -Wall -O2 -ffunction-sections \ CFLAGS += $(INCLUDE) -D__SWITCH__ -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++1z +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 +LIBS := -lstratosphere -lnx #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing # include and lib #--------------------------------------------------------------------------------- -LIBDIRS := $(PORTLIBS) $(LIBNX) +LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../libstratosphere #--------------------------------------------------------------------------------- diff --git a/stratosphere/loader/source/ldr_debug_monitor.hpp b/stratosphere/loader/source/ldr_debug_monitor.hpp index 6242244f5..20f8fef64 100644 --- a/stratosphere/loader/source/ldr_debug_monitor.hpp +++ b/stratosphere/loader/source/ldr_debug_monitor.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include "iserviceobject.hpp" +#include #include "ldr_registration.hpp" enum DebugMonitorServiceCmd { diff --git a/stratosphere/loader/source/ldr_main.cpp b/stratosphere/loader/source/ldr_main.cpp index 23334f2ec..b82521435 100644 --- a/stratosphere/loader/source/ldr_main.cpp +++ b/stratosphere/loader/source/ldr_main.cpp @@ -4,9 +4,8 @@ #include #include +#include -#include "waitablemanager.hpp" -#include "serviceserver.hpp" #include "ldr_process_manager.hpp" #include "ldr_debug_monitor.hpp" #include "ldr_shell.hpp" diff --git a/stratosphere/loader/source/ldr_process_manager.hpp b/stratosphere/loader/source/ldr_process_manager.hpp index e908f6674..3da91dcf3 100644 --- a/stratosphere/loader/source/ldr_process_manager.hpp +++ b/stratosphere/loader/source/ldr_process_manager.hpp @@ -1,7 +1,7 @@ #pragma once #include +#include -#include "iserviceobject.hpp" #include "ldr_registration.hpp" #include "ldr_process_creation.hpp" diff --git a/stratosphere/loader/source/ldr_shell.hpp b/stratosphere/loader/source/ldr_shell.hpp index 2a8965b21..ab6e8749e 100644 --- a/stratosphere/loader/source/ldr_shell.hpp +++ b/stratosphere/loader/source/ldr_shell.hpp @@ -1,7 +1,6 @@ #pragma once #include - -#include "iserviceobject.hpp" +#include enum ShellServiceCmd { Shell_Cmd_AddTitleToLaunchQueue = 0,