libctru  v2.4.1
Data Structures | Macros | Functions
os.h File Reference

OS related stuff. More...

#include "svc.h"

Go to the source code of this file.

Data Structures

struct  osKernelConfig_s
 Kernel configuration page (read-only). More...
 
struct  osTimeRef_s
 Time reference information struct (filled in by PTM). More...
 
struct  osSharedConfig_s
 Shared system configuration page structure (read-only or read-write depending on exheader). More...
 
struct  TickCounter
 Tick counter. More...
 
struct  OS_VersionBin
 OS_VersionBin. Format of the system version: "<major>.<minor>.<build>-<nupver><region>". More...
 

Macros

#define SYSCLOCK_SOC   (16756991u)
 < The external clock rate for the SoC. More...
 
#define SYSCLOCK_SYS   (SYSCLOCK_SOC * 2)
 The base clock rate for the SDMMC controller (and some other peripherals).
 
#define SYSCLOCK_SDMMC   (SYSCLOCK_SYS * 2)
 The clock rate for the Arm9.
 
#define SYSCLOCK_ARM9   (SYSCLOCK_SYS * 4)
 The clock rate for the Arm11 in CTR mode and in svcGetSystemTick.
 
#define SYSCLOCK_ARM11   (SYSCLOCK_ARM9 * 2)
 The clock rate for the Arm11 in LGR1 mode.
 
#define SYSCLOCK_ARM11_LGR1   (SYSCLOCK_ARM11 * 2)
 The clock rate for the Arm11 in LGR2 mode.
 
#define SYSCLOCK_ARM11_LGR2   (SYSCLOCK_ARM11 * 3)
 The highest possible clock rate for the Arm11 on known New 3DS units.
 
#define SYSCLOCK_ARM11_NEW   SYSCLOCK_ARM11_LGR2
 
#define CPU_TICKS_PER_MSEC   (SYSCLOCK_ARM11 / 1000.0)
 
#define CPU_TICKS_PER_USEC   (SYSCLOCK_ARM11 / 1000000.0)
 
#define SYSTEM_VERSION(major, minor, revision)    (((major)<<24)|((minor)<<16)|((revision)<<8))
 Packs a system version from its components.
 
#define GET_VERSION_MAJOR(version)   ((version) >>24)
 Retrieves the major version from a packed system version.
 
#define GET_VERSION_MINOR(version)   (((version)>>16)&0xFF)
 Retrieves the minor version from a packed system version.
 
#define GET_VERSION_REVISION(version)   (((version)>> 8)&0xFF)
 Retrieves the revision version from a packed system version.
 
#define OS_HEAP_AREA_BEGIN   0x08000000
 Start of the heap area in the virtual address space.
 
#define OS_HEAP_AREA_END   0x0E000000
 End of the heap area in the virtual address space.
 
#define OS_MAP_AREA_BEGIN   0x10000000
 Start of the mappable area in the virtual address space.
 
#define OS_MAP_AREA_END   0x14000000
 End of the mappable area in the virtual address space.
 
#define OS_OLD_FCRAM_VADDR   0x14000000
 Old pre-8.x linear FCRAM mapping virtual address.
 
#define OS_OLD_FCRAM_PADDR   0x20000000
 Old pre-8.x linear FCRAM mapping physical address.
 
#define OS_OLD_FCRAM_SIZE   0x8000000
 Old pre-8.x linear FCRAM mapping size (128 MiB)
 
#define OS_QTMRAM_VADDR   0x1E800000
 New3DS QTM memory virtual address.
 
#define OS_QTMRAM_PADDR   0x1F000000
 New3DS QTM memory physical address.
 
#define OS_QTMRAM_SIZE   0x400000
 New3DS QTM memory size (4 MiB; last 128 KiB reserved by kernel)
 
#define OS_MMIO_VADDR   0x1EC00000
 Memory mapped IO range virtual address.
 
#define OS_MMIO_PADDR   0x10100000
 Memory mapped IO range physical address.
 
#define OS_MMIO_SIZE   0x400000
 Memory mapped IO range size (4 MiB)
 
#define OS_VRAM_VADDR   0x1F000000
 VRAM virtual address.
 
#define OS_VRAM_PADDR   0x18000000
 VRAM physical address.
 
#define OS_VRAM_SIZE   0x600000
 VRAM size (6 MiB)
 
#define OS_DSPRAM_VADDR   0x1FF00000
 DSP memory virtual address.
 
#define OS_DSPRAM_PADDR   0x1FF00000
 DSP memory physical address.
 
#define OS_DSPRAM_SIZE   0x80000
 DSP memory size (512 KiB)
 
#define OS_KERNELCFG_VADDR   0x1FF80000
 Kernel configuration page virtual address.
 
#define OS_SHAREDCFG_VADDR   0x1FF81000
 Shared system configuration page virtual address.
 
#define OS_FCRAM_VADDR   0x30000000
 Linear FCRAM mapping virtual address.
 
#define OS_FCRAM_PADDR   0x20000000
 Linear FCRAM mapping physical address.
 
#define OS_FCRAM_SIZE   0x10000000
 Linear FCRAM mapping size (256 MiB)
 
#define OS_KernelConfig   ((osKernelConfig_s const*)OS_KERNELCFG_VADDR)
 Pointer to the kernel configuration page (see osKernelConfig_s)
 
#define OS_SharedConfig   ((osSharedConfig_s*)OS_SHAREDCFG_VADDR)
 Pointer to the shared system configuration page (see osSharedConfig_s)
 

Functions

u32 osConvertVirtToPhys (const void *vaddr)
 Converts an address from virtual (process) memory to physical memory. More...
 
void * osConvertOldLINEARMemToNew (const void *vaddr)
 Converts 0x14* vmem to 0x30*. More...
 
const char * osStrError (Result error)
 Retrieves basic information about a service error. More...
 
static u32 osGetFirmVersion (void)
 Gets the system's FIRM version. More...
 
static u32 osGetKernelVersion (void)
 Gets the system's kernel version. More...
 
static u32 osGetSystemCoreVersion (void)
 Gets the system's "core version" (2 on NATIVE_FIRM, 3 on SAFE_FIRM, etc.)
 
static u32 osGetApplicationMemType (void)
 Gets the system's memory layout ID (0-5 on Old 3DS, 6-8 on New 3DS)
 
static u32 osGetMemRegionSize (MemRegion region)
 Gets the size of the specified memory region. More...
 
static u32 osGetMemRegionUsed (MemRegion region)
 Gets the number of used bytes within the specified memory region. More...
 
static u32 osGetMemRegionFree (MemRegion region)
 Gets the number of free bytes within the specified memory region. More...
 
osTimeRef_s osGetTimeRef (void)
 Reads the latest reference timepoint published by PTM. More...
 
u64 osGetTime (void)
 Gets the current time. More...
 
static void osTickCounterStart (TickCounter *cnt)
 Starts a tick counter. More...
 
static void osTickCounterUpdate (TickCounter *cnt)
 Updates the elapsed time in a tick counter. More...
 
double osTickCounterRead (const TickCounter *cnt)
 Reads the elapsed time in a tick counter. More...
 
static u8 osGetWifiStrength (void)
 Gets the current Wifi signal strength. More...
 
static float osGet3DSliderState (void)
 Gets the state of the 3D slider. More...
 
static bool osIsHeadsetConnected (void)
 Checks whether a headset is connected. More...
 
void osSetSpeedupEnable (bool enable)
 Configures the New 3DS speedup. More...
 
Result osGetSystemVersionData (OS_VersionBin *nver_versionbin, OS_VersionBin *cver_versionbin)
 Gets the NAND system-version stored in NVer/CVer. More...
 
Result osGetSystemVersionDataString (OS_VersionBin *nver_versionbin, OS_VersionBin *cver_versionbin, char *sysverstr, u32 sysverstr_maxsize)
 This is a wrapper for osGetSystemVersionData. More...
 

Detailed Description

OS related stuff.

Macro Definition Documentation

◆ SYSCLOCK_SOC

#define SYSCLOCK_SOC   (16756991u)

< The external clock rate for the SoC.

The base system clock rate (for I2C, NDMA, etc.).

Function Documentation

◆ osConvertOldLINEARMemToNew()

void* osConvertOldLINEARMemToNew ( const void *  vaddr)

Converts 0x14* vmem to 0x30*.

Parameters
vaddrInput virtual address.
Returns
The corresponding address in the 0x30* range, the input address if it's already within the new vmem, or 0 if it's outside of both ranges.

◆ osConvertVirtToPhys()

u32 osConvertVirtToPhys ( const void *  vaddr)

Converts an address from virtual (process) memory to physical memory.

Parameters
vaddrInput virtual address.
Returns
The corresponding physical address. It is sometimes required by services or when using the GPU command buffer.
Examples
mvd/source/main.c.

◆ osGet3DSliderState()

static float osGet3DSliderState ( void  )
inlinestatic

◆ osGetFirmVersion()

static u32 osGetFirmVersion ( void  )
inlinestatic

Gets the system's FIRM version.

Returns
The system's FIRM version.

This can be used to compare system versions easily with SYSTEM_VERSION.

◆ osGetKernelVersion()

static u32 osGetKernelVersion ( void  )
inlinestatic

Gets the system's kernel version.

Returns
The system's kernel version.

This can be used to compare system versions easily with SYSTEM_VERSION.

if(osGetKernelVersion() > SYSTEM_VERSION(2,46,0)) printf("You are running 9.0 or higher\n");
static u32 osGetKernelVersion(void)
Gets the system's kernel version.
Definition: os.h:197
#define SYSTEM_VERSION(major, minor, revision)
Packs a system version from its components.
Definition: os.h:29

◆ osGetMemRegionFree()

static u32 osGetMemRegionFree ( MemRegion  region)
inlinestatic

Gets the number of free bytes within the specified memory region.

Parameters
regionMemory region to check.
Returns
The number of free bytes of memory.

◆ osGetMemRegionSize()

static u32 osGetMemRegionSize ( MemRegion  region)
inlinestatic

Gets the size of the specified memory region.

Parameters
regionMemory region to check.
Returns
The size of the memory region, in bytes.

◆ osGetMemRegionUsed()

static u32 osGetMemRegionUsed ( MemRegion  region)
inlinestatic

Gets the number of used bytes within the specified memory region.

Parameters
regionMemory region to check.
Returns
The number of used bytes of memory.

◆ osGetSystemVersionData()

Result osGetSystemVersionData ( OS_VersionBin nver_versionbin,
OS_VersionBin cver_versionbin 
)

Gets the NAND system-version stored in NVer/CVer.

Parameters
nver_versionbinOutput OS_VersionBin structure for the data read from NVer.
cver_versionbinOutput OS_VersionBin structure for the data read from CVer.
Returns
The result-code. This value can be positive if opening "romfs:/version.bin" fails with stdio, since errno would be returned in that case. In some cases the error can be special negative values as well.

◆ osGetSystemVersionDataString()

Result osGetSystemVersionDataString ( OS_VersionBin nver_versionbin,
OS_VersionBin cver_versionbin,
char *  sysverstr,
u32  sysverstr_maxsize 
)

This is a wrapper for osGetSystemVersionData.

Parameters
nver_versionbinOptional output OS_VersionBin structure for the data read from NVer, can be NULL.
cver_versionbinOptional output OS_VersionBin structure for the data read from CVer, can be NULL.
sysverstrOutput string where the printed system-version will be written, in the same format displayed by the System Settings title.
sysverstr_maxsizeMax size of the above string buffer, including NULL-terminator.
Returns
See osGetSystemVersionData.

◆ osGetTime()

u64 osGetTime ( void  )

Gets the current time.

Returns
The number of milliseconds since 1st Jan 1900 00:00.

◆ osGetTimeRef()

osTimeRef_s osGetTimeRef ( void  )

Reads the latest reference timepoint published by PTM.

Returns
Structure (see osTimeRef_s).

◆ osGetWifiStrength()

static u8 osGetWifiStrength ( void  )
inlinestatic

Gets the current Wifi signal strength.

Returns
The current Wifi signal strength.

Valid values are 0-3:

  • 0 means the signal strength is terrible or the 3DS is disconnected from all networks.
  • 1 means the signal strength is bad.
  • 2 means the signal strength is decent.
  • 3 means the signal strength is good.

Values outside the range of 0-3 should never be returned.

These values correspond with the number of wifi bars displayed by Home Menu.

◆ osIsHeadsetConnected()

static bool osIsHeadsetConnected ( void  )
inlinestatic

Checks whether a headset is connected.

Returns
true or false.

◆ osSetSpeedupEnable()

void osSetSpeedupEnable ( bool  enable)

Configures the New 3DS speedup.

Parameters
enableSpecifies whether to enable or disable the speedup.

◆ osStrError()

const char* osStrError ( Result  error)

Retrieves basic information about a service error.

Parameters
errorError to retrieve information about.
Returns
A string containing a summary of an error.

This can be used to get some details about an error returned by a service call.

◆ osTickCounterRead()

double osTickCounterRead ( const TickCounter cnt)

Reads the elapsed time in a tick counter.

Parameters
cntThe tick counter.
Returns
The number of milliseconds elapsed.

◆ osTickCounterStart()

static void osTickCounterStart ( TickCounter cnt)
inlinestatic

Starts a tick counter.

Parameters
cntThe tick counter.

◆ osTickCounterUpdate()

static void osTickCounterUpdate ( TickCounter cnt)
inlinestatic

Updates the elapsed time in a tick counter.

Parameters
cntThe tick counter.