libdragon
Loading...
Searching...
No Matches
n64sys.h
Go to the documentation of this file.
1
9#ifndef __LIBDRAGON_N64SYS_H
10#define __LIBDRAGON_N64SYS_H
11
12#include <stdint.h>
13#include <stdbool.h>
14#include <stddef.h>
15#include <assert.h>
16#include "cop0.h"
17#include "cop1.h"
18
38extern int __boot_consoletype;
40
44#define RCP_FREQUENCY (__boot_consoletype ? 96000000 : 62500000)
45
49#define CPU_FREQUENCY (__boot_consoletype ? 144000000 : 93750000)
50
54#define KSEG0_START_ADDR ((void*)0x80000000)
55
64#define UncachedAddr(_addr) ((void *)(((unsigned long)(_addr))|0x20000000))
65
74#define UncachedShortAddr(_addr) ((short *)(((unsigned long)(_addr))|0x20000000))
75
84#define UncachedUShortAddr(_addr) ((unsigned short *)(((unsigned long)(_addr))|0x20000000))
85
94#define UncachedLongAddr(_addr) ((long *)(((unsigned long)(_addr))|0x20000000))
95
104#define UncachedULongAddr(_addr) ((unsigned long *)(((unsigned long)(_addr))|0x20000000))
105
114#define CachedAddr(_addr) ((void *)(((unsigned long)(_addr))&~0x20000000))
115
124#define PhysicalAddr(_addr) ({ \
125 const volatile void *_addrp = (_addr); \
126 (((unsigned long)(_addrp))&~0xE0000000); \
127})
128
130extern char __libdragon_text_start[];
131
133extern char __rom_end[];
134
136extern char __bss_end[];
137
141#define HEAP_START_ADDR ((void*)__bss_end)
142
150#define MEMORY_BARRIER() asm volatile ("" : : : "memory")
151
171#define TICKS_READ() C0_COUNT()
172
178#define TICKS_PER_SECOND (CPU_FREQUENCY/2)
179
186#define TICKS_DISTANCE(from, to) ((int32_t)((uint32_t)(to) - (uint32_t)(from)))
187
189#define TICKS_SINCE(t0) TICKS_DISTANCE(t0, TICKS_READ())
190
203#define TICKS_BEFORE(t1, t2) ({ TICKS_DISTANCE(t1, t2) > 0; })
204
208#define TICKS_FROM_MS(val) (((val) * (TICKS_PER_SECOND / 1000)))
209
213#define TICKS_FROM_US(val) (((val) * (8 * TICKS_PER_SECOND / 1000000) / 8))
214
218#define TICKS_TO_US(val) (((val) * 8 / (8 * TICKS_PER_SECOND / 1000000)))
219
223#define TICKS_TO_MS(val) (((val) / (TICKS_PER_SECOND / 1000)))
224
225
226#ifdef __cplusplus
227extern "C" {
228#endif
229
231inline bool sys_bbplayer(void) {
232 extern int __boot_consoletype;
233 return __boot_consoletype != 0;
234}
235
244uint64_t get_ticks(void);
245
254uint64_t get_ticks_us(void);
255
264uint64_t get_ticks_ms(void);
265
273void wait_ticks( unsigned long wait );
274
282void wait_ms( unsigned long wait_ms );
283
309#define data_cache_hit_invalidate(addr_, sz_) ({ \
310 void *addr = (addr_); unsigned long sz = (sz_); \
311 assert(((uint32_t)addr % 16) == 0 && (sz % 16) == 0); \
312 __data_cache_hit_invalidate(addr, sz); \
313})
314
315void __data_cache_hit_invalidate(volatile void * addr, unsigned long length);
316
327void data_cache_hit_writeback(volatile const void *, unsigned long);
328
340void data_cache_hit_writeback_invalidate(volatile void *, unsigned long);
341
350void data_cache_index_writeback_invalidate(volatile void *, unsigned long);
351
359
370void inst_cache_hit_writeback(volatile const void *, unsigned long);
371
382void inst_cache_hit_invalidate(volatile void *, unsigned long);
383
392void inst_cache_index_invalidate(volatile void *, unsigned long);
393
401
402
408int get_memory_size();
409
420bool is_memory_expanded();
421
440void *malloc_uncached(size_t size);
441
456void *malloc_uncached_aligned(int align, size_t size);
457
467void free_uncached(void *buf);
468
470typedef enum {
471 TV_PAL = 0,
473 TV_MPAL = 2
475
484
486typedef enum {
490
501
503/* Deprecated version of get_ticks */
504__attribute__((deprecated("use get_ticks instead")))
505static inline volatile unsigned long read_count(void) {
506 return get_ticks();
507}
508
509/* Deprecated functions to tell libdragon which CIC is installed.
510 This was only used to cope with differences in boot flags with
511 official IPL3s, but it's not required anymore with open source
512 IPL3. */
513__attribute__((deprecated("querying CIC type is not supported")))
514static inline int sys_get_boot_cic() { return 6102; }
515__attribute__((deprecated("cannot set CIC type at runtime, but this is not required anymore")))
516static inline void sys_set_boot_cic(int bc) {}
519#ifdef __cplusplus
520}
521#endif
522
525#endif
N64 COP0 Interface.
N64 COP1 Interface.
uint64_t get_ticks_us(void)
Read the number of microseconds since system startup.
Definition n64sys.c:159
void data_cache_index_writeback_invalidate(volatile void *, unsigned long)
Force a data cache index writeback invalidate over a memory region.
Definition n64sys.c:65
reset_type_t
Reset types.
Definition n64sys.h:486
bool is_memory_expanded()
Is expansion pak in use.
Definition n64sys.c:134
void wait_ms(unsigned long wait_ms)
Spin wait until the number of milliseconds have elapsed.
Definition n64sys.c:175
uint64_t get_ticks(void)
Read the number of ticks since system startup.
Definition n64sys.c:150
void inst_cache_invalidate_all(void)
Force an instruction cache invalidate over whole memory.
Definition n64sys.c:91
int get_memory_size()
Get amount of available memory.
Definition n64sys.c:129
reset_type_t sys_reset_type(void)
Get reset type.
Definition n64sys.c:145
tv_type_t get_tv_type()
Is system NTSC/PAL/MPAL.
Definition n64sys.c:140
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:231
void __data_cache_hit_invalidate(volatile void *addr, unsigned long length)
Underlying implementation of data_cache_hit_invalidate.
Definition n64sys.c:55
tv_type_t
Type of TV video output.
Definition n64sys.h:470
void inst_cache_hit_writeback(volatile const void *, unsigned long)
Force an instruction cache writeback over a memory region.
Definition n64sys.c:76
void data_cache_hit_writeback(volatile const void *, unsigned long)
Force a data cache writeback over a memory region.
Definition n64sys.c:49
void * malloc_uncached_aligned(int align, size_t size)
Allocate a buffer that will be accessed as uncached memory, specifying alignment.
Definition n64sys.c:102
void data_cache_writeback_invalidate_all(void)
Force a data cache writeback invalidate over whole memory.
Definition n64sys.c:70
void inst_cache_hit_invalidate(volatile void *, unsigned long)
Force an instruction cache invalidate over a memory region.
Definition n64sys.c:81
void data_cache_hit_writeback_invalidate(volatile void *, unsigned long)
Force a data cache writeback invalidate over a memory region.
Definition n64sys.c:60
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:124
void inst_cache_index_invalidate(volatile void *, unsigned long)
Force an instruction cache index invalidate over a memory region.
Definition n64sys.c:86
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:164
void wait_ticks(unsigned long wait)
Spin wait until the number of ticks have elapsed.
Definition n64sys.c:169
void * malloc_uncached(size_t size)
Allocate a buffer that will be accessed as uncached memory.
Definition n64sys.c:97
@ RESET_COLD
Cold reset (power on)
Definition n64sys.h:487
@ RESET_WARM
Warm reset (reset button)
Definition n64sys.h:488
@ TV_MPAL
Video output is M-PAL.
Definition n64sys.h:473
@ TV_PAL
Video output is PAL.
Definition n64sys.h:471
@ TV_NTSC
Video output is NTSC.
Definition n64sys.h:472
int __boot_consoletype
Console type as detected by IPL3.
Definition n64sys.c:24
int wait(int *status)
Wait for a child process.
Definition system.c:1131