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 <stdlib.h>
16#include <assert.h>
17#include "cop0.h"
18#include "cop1.h"
19
39extern int __boot_memsize;
40extern int __boot_consoletype;
41extern int __boot_tvtype;
43
47#define RCP_FREQUENCY (__boot_consoletype ? 96000000 : 62500000)
48
52#define CPU_FREQUENCY (__boot_consoletype ? 144000000 : 93750000)
53
57#define KSEG0_START_ADDR ((void*)0x80000000)
58
75typedef uint32_t phys_addr_t;
76
84#define PhysicalAddr(_addr) ({ \
85 const volatile void *_addrp = (_addr); \
86 (((phys_addr_t)(_addrp))&~0xE0000000); \
87})
88
104#define VirtualCachedAddr(_addr) ((void *)(((unsigned long)(_addr))|0x80000000))
105
121#define VirtualUncachedAddr(_addr) ((void *)(((unsigned long)(_addr))|0xA0000000))
122
123
132#define UncachedAddr(_addr) ((void *)(((unsigned long)(_addr))|0x20000000))
133
142#define UncachedShortAddr(_addr) ((short *)(((unsigned long)(_addr))|0x20000000))
143
152#define UncachedUShortAddr(_addr) ((unsigned short *)(((unsigned long)(_addr))|0x20000000))
153
162#define UncachedLongAddr(_addr) ((long *)(((unsigned long)(_addr))|0x20000000))
163
172#define UncachedULongAddr(_addr) ((unsigned long *)(((unsigned long)(_addr))|0x20000000))
173
182#define CachedAddr(_addr) ((void *)(((unsigned long)(_addr))&~0x20000000))
183
185extern char __libdragon_text_start[];
186
188extern char __rom_end[];
189
191extern char __bss_end[];
192
196#define HEAP_START_ADDR ((void*)__bss_end)
197
205#define MEMORY_BARRIER() asm volatile ("" : : : "memory")
206
226#define TICKS_READ() C0_COUNT()
227
233#define TICKS_PER_SECOND (CPU_FREQUENCY/2)
234
241#define TICKS_DISTANCE(from, to) ((int32_t)((uint32_t)(to) - (uint32_t)(from)))
242
244#define TICKS_SINCE(t0) TICKS_DISTANCE(t0, TICKS_READ())
245
258#define TICKS_BEFORE(t1, t2) ({ TICKS_DISTANCE(t1, t2) > 0; })
259
263#define TICKS_FROM_MS(val) (((val) * (TICKS_PER_SECOND / 1000)))
264
268#define TICKS_FROM_US(val) (((val) * (8 * TICKS_PER_SECOND / 1000000) / 8))
269
273#define TICKS_TO_US(val) (((val) * 8 / (8 * TICKS_PER_SECOND / 1000000)))
274
278#define TICKS_TO_MS(val) (((val) / (TICKS_PER_SECOND / 1000)))
279
280
281#ifdef __cplusplus
282extern "C" {
283#endif
284
286inline bool sys_bbplayer(void) {
287 extern int __boot_consoletype;
288 return __boot_consoletype != 0;
289}
290
299uint64_t get_ticks(void);
300
309uint64_t get_ticks_us(void);
310
319uint64_t get_ticks_ms(void);
320
328void wait_ticks( unsigned long wait );
329
337void wait_ms( unsigned long wait_ms );
338
349__attribute__((noreturn))
350void die(void);
351
377void data_cache_hit_invalidate(volatile void* addr, unsigned long length);
378
389void data_cache_hit_writeback(volatile const void *, unsigned long);
390
402void data_cache_hit_writeback_invalidate(volatile void *, unsigned long);
403
412void data_cache_index_writeback_invalidate(volatile void *, unsigned long);
413
421
432void inst_cache_hit_writeback(volatile const void *, unsigned long);
433
444void inst_cache_hit_invalidate(volatile void *, unsigned long);
445
454void inst_cache_index_invalidate(volatile void *, unsigned long);
455
463
464
470int get_memory_size(void);
471
485bool is_memory_expanded(void);
486
501void assert_memory_expanded(void);
502
506typedef struct {
507 int total;
508 int used;
510
515
534void *malloc_uncached(size_t size);
535
550void *malloc_uncached_aligned(int align, size_t size);
551
561void free_uncached(void *buf);
562
564typedef enum {
565 TV_PAL = 0,
567 TV_MPAL = 2
569
578{
579 return (tv_type_t)__boot_tvtype;
580}
581
583typedef enum {
587
598
600/* Deprecated version of get_ticks */
601__attribute__((deprecated("use get_ticks instead")))
602static inline volatile unsigned long read_count(void) {
603 return get_ticks();
604}
605
606/* Deprecated functions to tell libdragon which CIC is installed.
607 This was only used to cope with differences in boot flags with
608 official IPL3s, but it's not required anymore with open source
609 IPL3. */
610__attribute__((deprecated("querying CIC type is not supported")))
611static inline int sys_get_boot_cic() { return 6102; }
612__attribute__((deprecated("cannot set CIC type at runtime, but this is not required anymore")))
613static inline void sys_set_boot_cic(int bc) {}
616#ifdef __cplusplus
617}
618#endif
619
622#endif
N64 COP0 Interface.
N64 COP1 Interface.
int used
Used heap size in bytes.
Definition n64sys.h:508
int total
Total heap size in bytes.
Definition n64sys.h:507
uint64_t get_ticks_us(void)
Read the number of microseconds since system startup.
Definition n64sys.c:202
void data_cache_index_writeback_invalidate(volatile void *, unsigned long)
Force a data cache index writeback invalidate over a memory region.
Definition n64sys.c:101
int get_memory_size(void)
Get amount of available memory.
Definition n64sys.c:163
reset_type_t
Reset types.
Definition n64sys.h:583
void sys_get_heap_stats(heap_stats_t *stats)
Return information about memory usage of the heap.
Definition n64sys.c:248
void wait_ms(unsigned long wait_ms)
Spin wait until the number of milliseconds have elapsed.
Definition n64sys.c:218
uint64_t get_ticks(void)
Read the number of ticks since system startup.
Definition n64sys.c:193
void inst_cache_invalidate_all(void)
Force an instruction cache invalidate over whole memory.
Definition n64sys.c:126
reset_type_t sys_reset_type(void)
Get reset type.
Definition n64sys.c:188
char __rom_end[]
Symbol at the end of code, data, and sdata (set by the linker)
void assert_memory_expanded(void)
Assert that the expansion pak is present.
Definition n64sys.c:177
bool sys_bbplayer(void)
Return true if we are running on a iQue player.
Definition n64sys.h:286
void data_cache_hit_invalidate(volatile void *addr, unsigned long length)
Force a data cache invalidate over a memory region.
Definition n64sys.c:90
void die(void)
Force a complete halt of all processors.
Definition n64sys.c:233
tv_type_t get_tv_type(void)
Is system NTSC/PAL/MPAL.
Definition n64sys.h:577
tv_type_t
Type of TV video output.
Definition n64sys.h:564
void inst_cache_hit_writeback(volatile const void *, unsigned long)
Force an instruction cache writeback over a memory region.
Definition n64sys.c:111
void data_cache_hit_writeback(volatile const void *, unsigned long)
Force a data cache writeback over a memory region.
Definition n64sys.c:85
void * malloc_uncached_aligned(int align, size_t size)
Allocate a buffer that will be accessed as uncached memory, specifying alignment.
Definition n64sys.c:136
void data_cache_writeback_invalidate_all(void)
Force a data cache writeback invalidate over whole memory.
Definition n64sys.c:106
uint32_t phys_addr_t
A physical address on the MIPS bus.
Definition n64sys.h:75
void inst_cache_hit_invalidate(volatile void *, unsigned long)
Force an instruction cache invalidate over a memory region.
Definition n64sys.c:116
void data_cache_hit_writeback_invalidate(volatile void *, unsigned long)
Force a data cache writeback invalidate over a memory region.
Definition n64sys.c:96
char __bss_end[]
Symbol at the end of code, data, sdata, and bss (set by the linker)
bool is_memory_expanded(void)
Is expansion pak in use.
Definition n64sys.c:172
void free_uncached(void *buf)
Free an uncached memory buffer.
Definition n64sys.c:158
void inst_cache_index_invalidate(volatile void *, unsigned long)
Force an instruction cache index invalidate over a memory region.
Definition n64sys.c:121
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:207
void wait_ticks(unsigned long wait)
Spin wait until the number of ticks have elapsed.
Definition n64sys.c:212
void * malloc_uncached(size_t size)
Allocate a buffer that will be accessed as uncached memory.
Definition n64sys.c:131
@ RESET_COLD
Cold reset (power on)
Definition n64sys.h:584
@ RESET_WARM
Warm reset (reset button)
Definition n64sys.h:585
@ TV_MPAL
Video output is M-PAL.
Definition n64sys.h:567
@ TV_PAL
Video output is PAL.
Definition n64sys.h:565
@ TV_NTSC
Video output is NTSC.
Definition n64sys.h:566
Heap statistics.
Definition n64sys.h:506
int __boot_consoletype
Console type as detected by IPL3.
Definition n64sys.c:24
int __boot_tvtype
TV type as detected by IPL3.
Definition n64sys.c:22
int __boot_memsize
Memory size as detected by IPL3.
Definition n64sys.c:21
int wait(int *status)
Wait for a child process.
Definition system.c:1167