KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Macros | Functions | Variables
arch.h File Reference

Dreamcast architecture specific options. More...

#include <kos/cdefs.h>
#include <dc/video.h>

Go to the source code of this file.

Macros

#define PAGESIZE   4096
 Page size (for MMU)
#define PAGESIZE_BITS   12
 Bits for page size.
#define PAGEMASK   (PAGESIZE - 1)
 Mask for page offset.
#define page_count   ((16*1024*1024 - 0x10000) / PAGESIZE)
 Page count "variable".
#define page_phys_base   0x8c010000
 Base address of available physical pages.
#define HZ   100
 Number of timer ticks per second.
#define THD_STACK_SIZE   32768
 Default thread stack size.
#define DEFAULT_VID_MODE   DM_640x480
 Default video mode.
#define DEFAULT_PIXEL_MODE   PM_RGB565
 Default pixel mode for video.
#define DEFAULT_SERIAL_BAUD   57600
 Default serial bitrate.
#define DEFAULT_SERIAL_FIFO   1
 Default serial FIFO behavior.
#define ELF_SYM_PREFIX   "_"
 Global symbol prefix in ELF files.
#define ELF_SYM_PREFIX_LEN   1
 Length of global symbol prefix in ELF files.
#define ARCH_EXIT_RETURN   1
 Return to loader.
#define ARCH_EXIT_MENU   2
 Return to system menu.
#define ARCH_EXIT_REBOOT   3
 Reboot the machine.
#define KOS_INIT_FLAGS(flags)   uint32 __kos_init_flags = (flags)
 Use this macro to determine the level of initialization you'd like in your program by default.
#define KOS_INIT_ROMDISK(rd)   void * __kos_romdisk = (rd)
 Define a romdisk for your program, if you'd like one.
#define KOS_INIT_ROMDISK_NONE   NULL
 State that you don't want a romdisk.
#define INIT_DEFAULT   (INIT_IRQ | INIT_THD_PREEMPT)
 Default init flags (IRQs on, preemption enabled).
#define INIT_NONE   0x0000
 Don't init optional things.
#define INIT_IRQ   0x0001
 Enable IRQs at startup.
#define INIT_THD_PREEMPT   0x0002
 Enable thread preemption.
#define INIT_NET   0x0004
 Enable built-in networking.
#define INIT_MALLOCSTATS   0x0008
 Enable malloc statistics.
#define INIT_QUIET   0x0010
 Disable dbgio.
#define INIT_OCRAM   0x10000
 Use half of the dcache as RAM.
#define INIT_NO_DCLOAD   0x20000
 Disable dcload.
#define arch_sleep()
 Dreamcast specific sleep mode "function".
#define arch_get_ret_addr()
 DC specific "function" to get the return address from the current function.
#define arch_get_fptr()
 DC specific "function" to get the frame pointer from the current function.
#define arch_fptr_ret_addr(fptr)   (*((uint32*)fptr))
 Pass in a frame pointer value to get the return address for the given frame.
#define arch_fptr_next(fptr)   (*((uint32*)(fptr+4)))
 Pass in a frame pointer value to get the previous frame pointer for the given frame.
#define arch_valid_address(ptr)   ((ptr_t)(ptr) >= 0x8c010000 && (ptr_t)(ptr) < 0x8d000000)
 Returns true if the passed address is likely to be valid. Doesn't have to be exact, just a sort of general idea.

Functions

void panic (const char *str) __noreturn
 Panic function.
int arch_main ()
 Kernel C-level entry point.
void arch_set_exit_path (int path)
 Set the exit path.
void arch_exit () __noreturn
 Generic kernel "exit" point.
void arch_return () __noreturn
 Kernel "return" point.
void arch_abort () __noreturn
 Kernel "abort" point.
void arch_reboot () __noreturn
 Kernel "reboot" call.
void arch_menu () __noreturn
 Kernel "exit to menu" call.
void arch_ctors ()
 Call to run all ctors.
void arch_dtors ()
 Call to run all dtors.
void __crtend_pullin ()
 Hook to ensure linking of crtend.c.
int mm_init ()
 Initialize the memory management system.
void * mm_sbrk (unsigned long increment)
 Request more core memory from the system.
void arch_real_exit () __noreturn
 Jump back to the bootloader.
int hardware_sys_init ()
 Initialize bare-bones hardware systems.
int hardware_periph_init ()
 Initialize some peripheral systems.
void hardware_shutdown ()
 Shut down hardware that was initted.

Variables

uint32 __kos_init_flags
 The init flags. Do not modify this directly!
void * __kos_romdisk
 Built-in romdisk. Do not modify this directly!

Detailed Description

Dreamcast architecture specific options.

This file has various architecture specific options defined in it. Also, any functions that start with arch_ are in here.

Author:
Dan Potter

Macro Definition Documentation

#define arch_fptr_next (   fptr)    (*((uint32*)(fptr+4)))

Pass in a frame pointer value to get the previous frame pointer for the given frame.

Parameters:
fptrThe frame pointer to look at.
Returns:
The previous frame pointer.
#define arch_fptr_ret_addr (   fptr)    (*((uint32*)fptr))

Pass in a frame pointer value to get the return address for the given frame.

Parameters:
fptrThe frame pointer to look at.
Returns:
The return address of the pointer.
#define arch_get_fptr ( )
Value:
({ \
uint32 fp; \
__asm__ __volatile__("mov r14,%0\n" \
: "=&z" (fp) \
: /* no inputs */ \
: "memory" ); \
fp; })

DC specific "function" to get the frame pointer from the current function.

Returns:
The frame pointer from the current function.
Note:
This only works if you don't disable frame pointers.
#define arch_get_ret_addr ( )
Value:
({ \
uint32 pr; \
__asm__ __volatile__("sts pr,%0\n" \
: "=&z" (pr) \
: /* no inputs */ \
: "memory" ); \
pr; })

DC specific "function" to get the return address from the current function.

Returns:
The return address of the current function.
#define arch_sleep ( )
Value:
do { \
__asm__ __volatile__("sleep"); \
} while(0)

Dreamcast specific sleep mode "function".

#define arch_valid_address (   ptr)    ((ptr_t)(ptr) >= 0x8c010000 && (ptr_t)(ptr) < 0x8d000000)

Returns true if the passed address is likely to be valid. Doesn't have to be exact, just a sort of general idea.

Returns:
Whether the address is valid or not for normal memory access.
#define DEFAULT_PIXEL_MODE   PM_RGB565

Default pixel mode for video.

#define DEFAULT_SERIAL_BAUD   57600

Default serial bitrate.

#define DEFAULT_SERIAL_FIFO   1

Default serial FIFO behavior.

#define DEFAULT_VID_MODE   DM_640x480

Default video mode.

#define ELF_SYM_PREFIX   "_"

Global symbol prefix in ELF files.

#define ELF_SYM_PREFIX_LEN   1

Length of global symbol prefix in ELF files.

#define HZ   100

Number of timer ticks per second.

#define KOS_INIT_FLAGS (   flags)    uint32 __kos_init_flags = (flags)

Use this macro to determine the level of initialization you'd like in your program by default.

The defaults line will be fine for most things.

Parameters:
flagsParts of KOS to init.
#define KOS_INIT_ROMDISK (   rd)    void * __kos_romdisk = (rd)

Define a romdisk for your program, if you'd like one.

Parameters:
rdPointer to the romdisk image in your code.
#define KOS_INIT_ROMDISK_NONE   NULL

State that you don't want a romdisk.

#define page_count   ((16*1024*1024 - 0x10000) / PAGESIZE)

Page count "variable".

The number of pages is static, so we can optimize this quite a bit.

#define page_phys_base   0x8c010000

Base address of available physical pages.

#define PAGEMASK   (PAGESIZE - 1)

Mask for page offset.

#define PAGESIZE   4096

Page size (for MMU)

#define PAGESIZE_BITS   12

Bits for page size.

#define THD_STACK_SIZE   32768

Default thread stack size.


Function Documentation

void __crtend_pullin ( )

Hook to ensure linking of crtend.c.

void arch_abort ( )

Kernel "abort" point.

Note:
This function will never return!
void arch_ctors ( )

Call to run all ctors.

void arch_dtors ( )

Call to run all dtors.

void arch_exit ( )

Generic kernel "exit" point.

Note:
This function will never return!
int arch_main ( )

Kernel C-level entry point.

Returns:
The program's return value.
void arch_menu ( )

Kernel "exit to menu" call.

Note:
This function will never return!
void arch_real_exit ( )

Jump back to the bootloader.

You generally shouldn't use this function, but rather use arch_exit() or exit() instead.

Note:
This function will never return!
void arch_reboot ( )

Kernel "reboot" call.

Note:
This function will never return!
void arch_return ( )

Kernel "return" point.

Note:
This function will never return!
void arch_set_exit_path ( int  path)

Set the exit path.

The default, if you don't call this, is ARCH_EXIT_RETURN.

Parameters:
pathWhat arch_exit() should do.
See also:
Potential exit paths from the kernel on
int hardware_periph_init ( )

Initialize some peripheral systems.

This will be done automatically for you on start by the default arch_main(), so you shouldn't have to deal with this yourself.

Return values:
0On success (no error conditions defined).
void hardware_shutdown ( )

Shut down hardware that was initted.

This function will shut down anything initted with hardware_sys_init() and hardware_periph_init(). This will be done for you automatically by the various exit points, so you shouldn't have to do this yourself.

int hardware_sys_init ( )

Initialize bare-bones hardware systems.

This will be done automatically for you on start by the default arch_main(), so you shouldn't have to deal with this yourself.

Return values:
0On success (no error conditions defined).
int mm_init ( )

Initialize the memory management system.

Return values:
0On success (no error conditions defined).
void* mm_sbrk ( unsigned long  increment)

Request more core memory from the system.

Parameters:
incrementThe number of bytes requested.
Returns:
A pointer to the memory.
Note:
This function will panic if no memory is available.
void panic ( const char *  str)

Panic function.

This function will cause a kernel panic, printing the specified message.

Parameters:
strThe error message to print.
Note:
This function will never return!

Variable Documentation

uint32 __kos_init_flags

The init flags. Do not modify this directly!

void* __kos_romdisk

Built-in romdisk. Do not modify this directly!