libdragon
Loading...
Searching...
No Matches
n64sys.h
Go to the documentation of this file.
1
6#ifndef __LIBDRAGON_N64SYS_H
7#define __LIBDRAGON_N64SYS_H
8
9#include <stdint.h>
10#include <stdbool.h>
11#include <stddef.h>
12#include <assert.h>
13#include "cop0.h"
14#include "cop1.h"
15
35extern int __boot_consoletype;
37
41#define RCP_FREQUENCY (__boot_consoletype ? 96000000 : 62500000)
42
46#define CPU_FREQUENCY (__boot_consoletype ? 144000000 : 93750000)
47
51#define KSEG0_START_ADDR ((void*)0x80000000)
52
61#define UncachedAddr(_addr) ((void *)(((unsigned long)(_addr))|0x20000000))
62
71#define UncachedShortAddr(_addr) ((short *)(((unsigned long)(_addr))|0x20000000))
72
81#define UncachedUShortAddr(_addr) ((unsigned short *)(((unsigned long)(_addr))|0x20000000))
82
91#define UncachedLongAddr(_addr) ((long *)(((unsigned long)(_addr))|0x20000000))
92
101#define UncachedULongAddr(_addr) ((unsigned long *)(((unsigned long)(_addr))|0x20000000))
102
111#define CachedAddr(_addr) ((void *)(((unsigned long)(_addr))&~0x20000000))
112
121#define PhysicalAddr(_addr) ({ \
122 const volatile void *_addrp = (_addr); \
123 (((unsigned long)(_addrp))&~0xE0000000); \
124})
125
127extern char __libdragon_text_start[];
128
130extern char __rom_end[];
131
133extern char __bss_end[];
134
138#define HEAP_START_ADDR ((void*)__bss_end)
139
147#define MEMORY_BARRIER() asm volatile ("" : : : "memory")
148
168#define TICKS_READ() C0_COUNT()
169
175#define TICKS_PER_SECOND (CPU_FREQUENCY/2)
176
183#define TICKS_DISTANCE(from, to) ((int32_t)((uint32_t)(to) - (uint32_t)(from)))
184
186#define TICKS_SINCE(t0) TICKS_DISTANCE(t0, TICKS_READ())
187
200#define TICKS_BEFORE(t1, t2) ({ TICKS_DISTANCE(t1, t2) > 0; })
201
205#define TICKS_FROM_MS(val) (((val) * (TICKS_PER_SECOND / 1000)))
206
210#define TICKS_FROM_US(val) (((val) * (8 * TICKS_PER_SECOND / 1000000) / 8))
211
215#define TICKS_TO_US(val) (((val) * 8 / (8 * TICKS_PER_SECOND / 1000000)))
216
220#define TICKS_TO_MS(val) (((val) / (TICKS_PER_SECOND / 1000)))
221
222
223#ifdef __cplusplus
224extern "C" {
225#endif
226
228inline bool sys_bbplayer(void) {
229 extern int __boot_consoletype;
230 return __boot_consoletype != 0;
231}
232
241uint64_t get_ticks(void);
242
251uint64_t get_ticks_us(void);
252
261uint64_t get_ticks_ms(void);
262
270void wait_ticks( unsigned long wait );
271
279void wait_ms( unsigned long wait_ms );
280
306#define data_cache_hit_invalidate(addr_, sz_) ({ \
307 void *addr = (addr_); unsigned long sz = (sz_); \
308 assert(((uint32_t)addr % 16) == 0 && (sz % 16) == 0); \
309 __data_cache_hit_invalidate(addr, sz); \
310})
311
312void __data_cache_hit_invalidate(volatile void * addr, unsigned long length);
313
324void data_cache_hit_writeback(volatile const void *, unsigned long);
325
337void data_cache_hit_writeback_invalidate(volatile void *, unsigned long);
338
347void data_cache_index_writeback_invalidate(volatile void *, unsigned long);
348
356
367void inst_cache_hit_writeback(volatile const void *, unsigned long);
368
379void inst_cache_hit_invalidate(volatile void *, unsigned long);
380
389void inst_cache_index_invalidate(volatile void *, unsigned long);
390
398
399
405int get_memory_size();
406
417bool is_memory_expanded();
418
437void *malloc_uncached(size_t size);
438
453void *malloc_uncached_aligned(int align, size_t size);
454
464void free_uncached(void *buf);
465
467typedef enum {
468 TV_PAL = 0,
470 TV_MPAL = 2
472
481
483typedef enum {
487
498
500/* Deprecated version of get_ticks */
501__attribute__((deprecated("use get_ticks instead")))
502static inline volatile unsigned long read_count(void) {
503 return get_ticks();
504}
505
506/* Deprecated functions to tell libdragon which CIC is installed.
507 This was only used to cope with differences in boot flags with
508 official IPL3s, but it's not required anymore with open source
509 IPL3. */
510__attribute__((deprecated("querying CIC type is not supported")))
511static inline int sys_get_boot_cic() { return 6102; }
512__attribute__((deprecated("cannot set CIC type at runtime, but this is not required anymore")))
513static inline void sys_set_boot_cic(int bc) {}
516#ifdef __cplusplus
517}
518#endif
519
522#endif
N64 COP0 Interface.
N64 COP1 Interface.
uint64_t get_ticks_us(void)
Read the number of microseconds since system startup.
Definition n64sys.c:157
void data_cache_index_writeback_invalidate(volatile void *, unsigned long)
Force a data cache index writeback invalidate over a memory region.
Definition n64sys.c:63
reset_type_t
Reset types.
Definition n64sys.h:483
bool is_memory_expanded()
Is expansion pak in use.
Definition n64sys.c:132
void wait_ms(unsigned long wait_ms)
Spin wait until the number of milliseconds have elapsed.
Definition n64sys.c:173
uint64_t get_ticks(void)
Read the number of ticks since system startup.
Definition n64sys.c:148
void inst_cache_invalidate_all(void)
Force an instruction cache invalidate over whole memory.
Definition n64sys.c:89
int get_memory_size()
Get amount of available memory.
Definition n64sys.c:127
reset_type_t sys_reset_type(void)
Get reset type.
Definition n64sys.c:143
tv_type_t get_tv_type()
Is system NTSC/PAL/MPAL.
Definition n64sys.c:138
char __rom_end[]
Symbol at the end of code, data, and sdata (set by the linker)
bool sys_bbplayer(void)
Return true if we are running on a iQue player.
Definition n64sys.h:228
void __data_cache_hit_invalidate(volatile void *addr, unsigned long length)
Underlying implementation of data_cache_hit_invalidate.
Definition n64sys.c:53
tv_type_t
Type of TV video output.
Definition n64sys.h:467
void inst_cache_hit_writeback(volatile const void *, unsigned long)
Force an instruction cache writeback over a memory region.
Definition n64sys.c:74
void data_cache_hit_writeback(volatile const void *, unsigned long)
Force a data cache writeback over a memory region.
Definition n64sys.c:47
void * malloc_uncached_aligned(int align, size_t size)
Allocate a buffer that will be accessed as uncached memory, specifying alignment.
Definition n64sys.c:100
void data_cache_writeback_invalidate_all(void)
Force a data cache writeback invalidate over whole memory.
Definition n64sys.c:68
void inst_cache_hit_invalidate(volatile void *, unsigned long)
Force an instruction cache invalidate over a memory region.
Definition n64sys.c:79
void data_cache_hit_writeback_invalidate(volatile void *, unsigned long)
Force a data cache writeback invalidate over a memory region.
Definition n64sys.c:58
char __bss_end[]
Symbol at the end of code, data, sdata, and bss (set by the linker)
void free_uncached(void *buf)
Free an uncached memory buffer.
Definition n64sys.c:122
void inst_cache_index_invalidate(volatile void *, unsigned long)
Force an instruction cache index invalidate over a memory region.
Definition n64sys.c:84
char __libdragon_text_start[]
Symbol at the start of code (start of ROM contents after header)
uint64_t get_ticks_ms(void)
Read the number of millisecounds since system startup.
Definition n64sys.c:162
void wait_ticks(unsigned long wait)
Spin wait until the number of ticks have elapsed.
Definition n64sys.c:167
void * malloc_uncached(size_t size)
Allocate a buffer that will be accessed as uncached memory.
Definition n64sys.c:95
@ RESET_COLD
Cold reset (power on)
Definition n64sys.h:484
@ RESET_WARM
Warm reset (reset button)
Definition n64sys.h:485
@ TV_MPAL
Video output is M-PAL.
Definition n64sys.h:470
@ TV_PAL
Video output is PAL.
Definition n64sys.h:468
@ TV_NTSC
Video output is NTSC.
Definition n64sys.h:469
int __boot_consoletype
Console type as detected by IPL3.
Definition n64sys.c:22
int wait(int *status)
Wait for a child process.
Definition system.c:1130