Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #156 from misson20000/support-100
Browse files Browse the repository at this point in the history
add env_get_kernel_version() and 1.0.0 support
  • Loading branch information
misson20000 authored Jul 19, 2018
2 parents 5be2170 + c658dc1 commit 9019dd1
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 30 additions & 0 deletions include/libtransistor/environment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @file libtransistor/environment.h
* @brief Functions to query the current environment
*/

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include<libtransistor/types.h>

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
31 changes: 22 additions & 9 deletions lib/address_space.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include<libtransistor/address_space.h>
#include<libtransistor/environment.h>
#include<libtransistor/util.h>
#include<libtransistor/types.h>
#include<libtransistor/svc.h>
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions lib/environment.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include<libtransistor/environment.h>
#include<libtransistor/svc.h>

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;
}
7 changes: 6 additions & 1 deletion lib/usb_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include<libtransistor/internal_util.h>
#include<libtransistor/usb_serial.h>
#include<libtransistor/alloc_pages.h>
#include<libtransistor/environment.h>
#include<libtransistor/mutex.h>

#include<string.h>
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion mk/transistor.mk
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion mk/transistor_headers.mk
Original file line number Diff line number Diff line change
@@ -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)

Expand Down

0 comments on commit 9019dd1

Please sign in to comment.