diff --git a/.travis.yml b/.travis.yml index 9f7d1f2a..9a875886 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ sudo: false env: global: - DEPS_DIR=${TRAVIS_BUILD_DIR}/deps - - MEPHISTO_VERSION=v1.2.0 + - MEPHISTO_VERSION=v1.2.1 - LIBTRANSISTOR_BASE_VERSION=v2.0.0-rc7 cache: directories: diff --git a/include/libtransistor/environment.h b/include/libtransistor/environment.h new file mode 100644 index 00000000..98fb3347 --- /dev/null +++ b/include/libtransistor/environment.h @@ -0,0 +1,30 @@ +/** + * @file libtransistor/environment.h + * @brief Functions to query the current environment + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef enum { + KERNEL_VERSION_INVALID, + KERNEL_VERSION_100, + KERNEL_VERSION_200, + KERNEL_VERSION_300, + KERNEL_VERSION_400, + KERNEL_VERSION_500, +} kernel_version_t; + +/** + * @brief Returns the current kernel version, for feature-detection purposes + */ +kernel_version_t env_get_kernel_version(); + +#ifdef __cplusplus +} +#endif diff --git a/lib/address_space.c b/lib/address_space.c index 92089351..ac798706 100644 --- a/lib/address_space.c +++ b/lib/address_space.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -70,15 +71,27 @@ result_t as_init() { return r; } - if((r = as_set_region_from_info(as_grab_region(), 14, 15, RESERVED_BY_KERNEL)) != RESULT_OK) { // NewMapRegion - trn_mutex_unlock(&as_lock); - return r; - } - - // TODO: if we want to support 1.0.0, this will need a workaround - if((r = as_set_region_from_info(&address_space, 12, 13, INVALID)) != RESULT_OK) { // AddressSpace - trn_mutex_unlock(&as_lock); - return r; + if(env_get_kernel_version() >= KERNEL_VERSION_200) { + if((r = as_set_region_from_info(as_grab_region(), 14, 15, RESERVED_BY_KERNEL)) != RESULT_OK) { // NewMapRegion + trn_mutex_unlock(&as_lock); + return r; + } + + if((r = as_set_region_from_info(&address_space, 12, 13, INVALID)) != RESULT_OK) { // AddressSpace + trn_mutex_unlock(&as_lock); + return r; + } + } else { + r = svcUnmapMemory((void*) 0xffffffffffffe000, (void *) ((2^36) - 0x2000), 0x1000); + if(r == 0xdc01) { // invalid destination address + // source 36-bit address was valid + address_space.base = 0x8000000; + address_space.size = (2^36) - address_space.base; + } else { + // let's just assume 32-bit + address_space.base = 0x200000; + address_space.size = (2^32) - address_space.base; + } } trn_mutex_unlock(&as_lock); diff --git a/lib/environment.c b/lib/environment.c new file mode 100644 index 00000000..8e083e2b --- /dev/null +++ b/lib/environment.c @@ -0,0 +1,15 @@ +#include +#include + +kernel_version_t env_get_kernel_version() { + static kernel_version_t version = KERNEL_VERSION_INVALID; + if(version == KERNEL_VERSION_INVALID) { + version = KERNEL_VERSION_500; + uint64_t info; + if(svcGetInfo(&info, 20, 0xffff8001, 0) == 0xf001) { version = KERNEL_VERSION_500 - 1; } + if(svcGetInfo(&info, 19, 0xffff8001, 0) == 0xf001) { version = KERNEL_VERSION_400 - 1; } + if(svcGetInfo(&info, 16, 0xffff8001, 0) == 0xf001) { version = KERNEL_VERSION_300 - 1; } + if(svcGetInfo(&info, 12, 0xffff8001, 0) == 0xf001) { version = KERNEL_VERSION_200 - 1; } + } + return version; +} diff --git a/lib/usb_serial.c b/lib/usb_serial.c index 6fd57115..d96a5162 100644 --- a/lib/usb_serial.c +++ b/lib/usb_serial.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -124,7 +125,11 @@ result_t usb_serial_init() { revent_h usb_state_event = 0xFFFFFFFF; LIB_ASSERT_OK(fail_usb, usb_ds_get_state_change_event(&usb_state_event)); - LIB_ASSERT_OK(fail_usb, usb_ds_set_vid_pid_bcd(&descriptor_data)); + if(env_get_kernel_version() >= KERNEL_VERSION_200) { + // added in 2.0.0 + LIB_ASSERT_OK(fail_usb, usb_ds_set_vid_pid_bcd(&descriptor_data)); + } + LIB_ASSERT_OK(fail_usb, usb_ds_get_interface(&interface_descriptor, "usb", &interface)); LIB_ASSERT_OK(fail_usb_interface, usb_ds_interface_get_endpoint(&interface, &endpoint_in_descriptor, &endpoint_in)); LIB_ASSERT_OK(fail_usb_endpoint_in, usb_ds_interface_get_endpoint(&interface, &endpoint_out_descriptor, &endpoint_out)); diff --git a/mk/transistor.mk b/mk/transistor.mk index d42adbd8..1038c7cc 100644 --- a/mk/transistor.mk +++ b/mk/transistor.mk @@ -1,6 +1,6 @@ # LIBTRANSISTOR -libtransistor_OBJECT_NAMES := crt0_common.o svc.o ipc.o tls.o util.o ipc/sm.o ipc/bsd.o ipc/fs.o ipc/fs/ifilesystem.o ipc/fs/ifile.o ipc/fs/idirectory.o ipc/nv.o ipc/hid.o ipc/ro.o ipc/nifm.o hid.o ipc/vi.o display/binder.o display/parcel.o display/surface.o gpu/gpu.o ipc/am.o display/graphic_buffer_queue.o display/display.o gfx/blit.o ipc/time.o syscalls/syscalls.o syscalls/fd.o syscalls/sched.o syscalls/socket.o lz4.o squashfs/cache.o squashfs/decompress.o squashfs/dir.o squashfs/file.o squashfs/fs.o squashfs/hash.o squashfs/nonstd-pread.o squashfs/nonstd-stat.o squashfs/stack.o squashfs/swap.o squashfs/table.o squashfs/traverse.o squashfs/util.o squashfs/xattr.o fs/blobfd.o fs/squashfs.o fs/mountfs.o fs/fspfs.o fs/fs.o ipc/audio.o ipc/bpc.o ipcserver.o strtold.o ipc/pm.o alloc_pages.o address_space.o loader_config.o ipc/usb.o ipc/usb/ds/interface.o ipc/usb/ds/endpoint.o usb_serial.o mutex.o tls_support.o thread.o ld/ld.o ld/elf.o ld/relocate.o ld/resolve.o ld/discover.o ld/loader/nro_via_ldr_ro.o ld/loader/nro_via_svc.o sha256.o ipc/fatal.o cpp/types.o cpp/ipc/hid.o cpp/svc.o cpp/ipcserver.o cpp/ipc/sm.o ipc/twili.o waiter.o cpp/waiter.o cpp/ipc/usb_ds.o cpp/ipcclient.o ld/dlfcn.o syscalls/phal.o ld/loader/elf.o +libtransistor_OBJECT_NAMES := crt0_common.o svc.o ipc.o tls.o util.o ipc/sm.o ipc/bsd.o ipc/fs.o ipc/fs/ifilesystem.o ipc/fs/ifile.o ipc/fs/idirectory.o ipc/nv.o ipc/hid.o ipc/ro.o ipc/nifm.o hid.o ipc/vi.o display/binder.o display/parcel.o display/surface.o gpu/gpu.o ipc/am.o display/graphic_buffer_queue.o display/display.o gfx/blit.o ipc/time.o syscalls/syscalls.o syscalls/fd.o syscalls/sched.o syscalls/socket.o lz4.o squashfs/cache.o squashfs/decompress.o squashfs/dir.o squashfs/file.o squashfs/fs.o squashfs/hash.o squashfs/nonstd-pread.o squashfs/nonstd-stat.o squashfs/stack.o squashfs/swap.o squashfs/table.o squashfs/traverse.o squashfs/util.o squashfs/xattr.o fs/blobfd.o fs/squashfs.o fs/mountfs.o fs/fspfs.o fs/fs.o ipc/audio.o ipc/bpc.o ipcserver.o strtold.o ipc/pm.o alloc_pages.o address_space.o loader_config.o ipc/usb.o ipc/usb/ds/interface.o ipc/usb/ds/endpoint.o usb_serial.o mutex.o tls_support.o thread.o ld/ld.o ld/elf.o ld/relocate.o ld/resolve.o ld/discover.o ld/loader/nro_via_ldr_ro.o ld/loader/nro_via_svc.o sha256.o ipc/fatal.o cpp/types.o cpp/ipc/hid.o cpp/svc.o cpp/ipcserver.o cpp/ipc/sm.o ipc/twili.o waiter.o cpp/waiter.o cpp/ipc/usb_ds.o cpp/ipcclient.o ld/dlfcn.o syscalls/phal.o ld/loader/elf.o environment.o libtransistor_OBJECT_FILES := $(addprefix $(BUILD_DIR)/transistor/,$(libtransistor_OBJECT_NAMES)) libtransistor_WARNINGS := -Wall -Wextra -Werror-implicit-function-declaration -Wno-unused-parameter -Wno-unused-command-line-argument -Werror-thread-safety diff --git a/mk/transistor_headers.mk b/mk/transistor_headers.mk index e777d431..751f6441 100644 --- a/mk/transistor_headers.mk +++ b/mk/transistor_headers.mk @@ -1,6 +1,6 @@ # LIBTRANSISTOR HEADERS -libtransistor_HEADER_NAMES := alloc_pages.h audio.h display/graphic_buffer.h display/display.h display/surface.h display/parcel.h display/rect.h display/binder.h display/fence.h display/graphic_buffer_queue.h err/modules.h err.h fd.h fs/squashfs.h fs/fd.h fs/fs.h fs/inode.h fs/blobfd.h fs/mountfs.h fs/fspfs.h gfx/blit.h gfx/gfx.h gpu/gpu.h gpu/nv_ioc.h hid.h internal_util.h ipc/vi.h ipc/am.h ipc/nifm.h ipc/time.h ipc/nv.h ipc/ro.h ipc/fs/idirectory.h ipc/fs/ifilesystem.h ipc/fs/ifile.h ipc/fs/err.h ipc/bpc.h ipc/bsd.h ipc/fs.h ipc/audio.h ipc/sm.h ipc/pm.h ipc/hid.h ipc.h ipcserver.h loader_config.h nx.h stb_sprintf.h svc.h tls.h types.h util.h address_space.h ipc_helpers.h ipc/usb.h ipc/usb/ds/interface.h ipc/usb/ds/endpoint.h usb_serial.h mutex.h thread.h ld/ld.h ld/elf.h ld/module.h ld/internal.h ld/loaders.h collections/list.h ipc/fatal.h cpp/types.hpp cpp/ipc/hid.hpp cpp/svc.hpp cpp/ipcserver.hpp cpp/ipc.hpp cpp/ipc/sm.hpp ipc/twili.h waiter.h cpp/waiter.hpp cpp/ipc/usb_ds.hpp cpp/ipc/usb.hpp runtime_config.h cpp/ipcclient.hpp +libtransistor_HEADER_NAMES := alloc_pages.h audio.h display/graphic_buffer.h display/display.h display/surface.h display/parcel.h display/rect.h display/binder.h display/fence.h display/graphic_buffer_queue.h err/modules.h err.h fd.h fs/squashfs.h fs/fd.h fs/fs.h fs/inode.h fs/blobfd.h fs/mountfs.h fs/fspfs.h gfx/blit.h gfx/gfx.h gpu/gpu.h gpu/nv_ioc.h hid.h internal_util.h ipc/vi.h ipc/am.h ipc/nifm.h ipc/time.h ipc/nv.h ipc/ro.h ipc/fs/idirectory.h ipc/fs/ifilesystem.h ipc/fs/ifile.h ipc/fs/err.h ipc/bpc.h ipc/bsd.h ipc/fs.h ipc/audio.h ipc/sm.h ipc/pm.h ipc/hid.h ipc.h ipcserver.h loader_config.h nx.h stb_sprintf.h svc.h tls.h types.h util.h address_space.h ipc_helpers.h ipc/usb.h ipc/usb/ds/interface.h ipc/usb/ds/endpoint.h usb_serial.h mutex.h thread.h ld/ld.h ld/elf.h ld/module.h ld/internal.h ld/loaders.h collections/list.h ipc/fatal.h cpp/types.hpp cpp/ipc/hid.hpp cpp/svc.hpp cpp/ipcserver.hpp cpp/ipc.hpp cpp/ipc/sm.hpp ipc/twili.h waiter.h cpp/waiter.hpp cpp/ipc/usb_ds.hpp cpp/ipc/usb.hpp runtime_config.h cpp/ipcclient.hpp environment.h DIST_TRANSISTOR_HEADERS := $(addprefix $(LIBTRANSISTOR_HOME)/include/libtransistor/,$(libtransistor_HEADER_NAMES)) $(DIST_NEITHER_HEADERS)