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) More...
 
#define PAGESIZE_BITS   12
 Bits for page size. More...
 
#define PAGEMASK   (PAGESIZE - 1)
 Mask for page offset. More...
 
#define page_count   ((16*1024*1024 - 0x10000) / PAGESIZE)
 Page count "variable". More...
 
#define page_phys_base   0x8c010000
 Base address of available physical pages. More...
 
#define HZ   100
 Number of timer ticks per second. More...
 
#define THD_STACK_SIZE   32768
 Default thread stack size. More...
 
#define DEFAULT_VID_MODE   DM_640x480
 Default video mode. More...
 
#define DEFAULT_PIXEL_MODE   PM_RGB565
 Default pixel mode for video. More...
 
#define DEFAULT_SERIAL_BAUD   57600
 Default serial bitrate. More...
 
#define DEFAULT_SERIAL_FIFO   1
 Default serial FIFO behavior. More...
 
#define ELF_SYM_PREFIX   "_"
 Global symbol prefix in ELF files. More...
 
#define ELF_SYM_PREFIX_LEN   1
 Length of global symbol prefix in ELF files. More...
 
#define ARCH_EXIT_RETURN   1
 Return to loader. More...
 
#define ARCH_EXIT_MENU   2
 Return to system menu. More...
 
#define ARCH_EXIT_REBOOT   3
 Reboot the machine. More...
 
#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. More...
 
#define KOS_INIT_ROMDISK(rd)   void * __kos_romdisk = (rd)
 Define a romdisk for your program, if you'd like one. More...
 
#define KOS_INIT_ROMDISK_NONE   NULL
 State that you don't want a romdisk. More...
 
#define INIT_DEFAULT   (INIT_IRQ | INIT_THD_PREEMPT)
 Default init flags (IRQs on, preemption enabled). More...
 
#define INIT_NONE   0x0000
 Don't init optional things. More...
 
#define INIT_IRQ   0x0001
 Enable IRQs at startup. More...
 
#define INIT_THD_PREEMPT   0x0002
 Enable thread preemption. More...
 
#define INIT_NET   0x0004
 Enable built-in networking. More...
 
#define INIT_MALLOCSTATS   0x0008
 Enable malloc statistics. More...
 
#define INIT_QUIET   0x0010
 Disable dbgio. More...
 
#define INIT_OCRAM   0x10000
 Use half of the dcache as RAM. More...
 
#define INIT_NO_DCLOAD   0x20000
 Disable dcload. More...
 
#define HW_TYPE_RETAIL   0x0
 A retail Dreamcast. More...
 
#define HW_TYPE_SET5   0x9
 A Set5.xx devkit. More...
 
#define HW_REGION_UNKNOWN   0x0
 Unknown region. More...
 
#define HW_REGION_ASIA   0x1
 Japan/Asia (NTSC) More...
 
#define HW_REGION_US   0x4
 North America. More...
 
#define HW_REGION_EUROPE   0xC
 Europe (PAL) More...
 
#define arch_sleep()
 Dreamcast specific sleep mode "function". More...
 
#define arch_get_ret_addr()
 DC specific "function" to get the return address from the current function. More...
 
#define arch_get_fptr()
 DC specific "function" to get the frame pointer from the current function. More...
 
#define arch_fptr_ret_addr(fptr)   (*((uint32*)fptr))
 Pass in a frame pointer value to get the return address for the given frame. More...
 
#define arch_fptr_next(fptr)   (*((uint32*)(fptr+4)))
 Pass in a frame pointer value to get the previous frame pointer for the given frame. More...
 
#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. More...
 

Functions

void panic (const char *str) __noreturn
 Panic function. More...
 
int arch_main ()
 Kernel C-level entry point. More...
 
void arch_set_exit_path (int path)
 Set the exit path. More...
 
void arch_exit () __noreturn
 Generic kernel "exit" point. More...
 
void arch_return () __noreturn
 Kernel "return" point. More...
 
void arch_abort () __noreturn
 Kernel "abort" point. More...
 
void arch_reboot () __noreturn
 Kernel "reboot" call. More...
 
void arch_menu () __noreturn
 Kernel "exit to menu" call. More...
 
void arch_ctors ()
 Call to run all ctors. More...
 
void arch_dtors ()
 Call to run all dtors. More...
 
void __crtend_pullin ()
 Hook to ensure linking of crtend.c. More...
 
int mm_init ()
 Initialize the memory management system. More...
 
void * mm_sbrk (unsigned long increment)
 Request more core memory from the system. More...
 
void arch_real_exit () __noreturn
 Jump back to the bootloader. More...
 
int hardware_sys_init ()
 Initialize bare-bones hardware systems. More...
 
int hardware_periph_init ()
 Initialize some peripheral systems. More...
 
void hardware_shutdown ()
 Shut down hardware that was initted. More...
 
int hardware_sys_mode (int *region)
 Retrieve the system mode of the console in use. More...
 
const char * kos_get_banner (void)
 Retrieve the banner printed at program initialization. More...
 
const char * kos_get_license (void)
 Retrieve the license information for the compiled copy of KOS. More...
 
const char * kos_get_authors (void)
 Retrieve a list of authors and the dates of their contributions. More...
 

Variables

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

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; })
unsigned long uint32
32-bit unsigned integer
Definition: types.h:28

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; })
unsigned long uint32
32-bit unsigned integer
Definition: types.h:28

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 hardware_sys_mode ( int *  region)

Retrieve the system mode of the console in use.

This function retrieves the system mode register of the console that is in use. This register details the actual system type in use (and in some system types the region of the device).

Parameters
regionOn return, the region code (one of the Region codes) of the device if the console type allows reading it through the system mode register – otherwise, you must retrieve the region from the flashrom.
Returns
The console type (one of the Console types).
const char* kos_get_authors ( void  )

Retrieve a list of authors and the dates of their contributions.

This function retrieves the copyright information for the version of KOS in use. This function can be used to add such information to the credits of programs using KOS to give the appropriate credit to those that have worked on KOS.

Remember, you do need to give credit where credit is due, and this is an easy way to do so. ;-)

Return values
Apointer to the authors' copyright information.
const char* kos_get_banner ( void  )

Retrieve the banner printed at program initialization.

This function retrieves the banner string that is printed at initialization time by the kernel. This contains the version of KOS in use and basic information about the environment in which it was compiled.

Return values
Apointer to the banner string.
const char* kos_get_license ( void  )

Retrieve the license information for the compiled copy of KOS.

This function retrieves a string containing the license terms that the version of KOS in use is distributed under. This can be used to easily add information to your program to be displayed at runtime.

Return values
Apointer to the license terms.
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!