KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
Architecture

Dreamcast Architecture-Specific Options and high-level API. More...

Modules

 Console Types
 Byte values returned by hardware_sys_mode()
 
 Exit Paths
 Potential exit paths from the kernel on arch_exit()
 
 Memory Capacity
 Console memory sizes.
 
 Region Codes
 Values returned by hardware_sys_mode();.
 

Files

file  arch.h
 Dreamcast architecture specific options.
 

Macros

#define _arch_mem_top   ((uint32) 0x8d000000)
 Top of memory available, depending on memory size.
 
#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   ((_arch_mem_top - page_phys_base) / PAGESIZE)
 Page count "variable".
 
#define page_phys_base   0x8c010000
 Base address of available physical pages.
 
#define HZ   100
 Scheduler interrupt frequency.
 
#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   115200
 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 HW_MEMSIZE   (_arch_mem_top - 0x8c000000)
 Determine how much memory is installed in current machine.
 
#define DBL_MEM   (_arch_mem_top - 0x8d000000)
 Use this macro to easily determine if system has 32MB of RAM.
 
#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) < _arch_mem_top)
 Returns true if the passed address is likely to be valid. Doesn't have to be exact, just a sort of general idea.
 
#define BYTE_ORDER   LITTLE_ENDIAN
 Define the byte-order of the platform in use.
 
#define arch_swap16(x)
 Swap the byte order of a 16-bit integer.
 
#define arch_swap32(x)
 Swap the byte order of a 32-bit integer.
 
#define arch_ntohs(x)   arch_swap16(x)
 Convert network-to-host short.
 
#define arch_ntohl(x)   arch_swap32(x)
 Convert network-to-host long.
 
#define arch_htons(x)   arch_swap16(x)
 Convert host-to-network short.
 
#define arch_htonl(x)   arch_swap32(x)
 Convert host-to-network long.
 

Functions

void arch_panic (const char *str) __noreturn
 Panic function.
 
void arch_main (void) __noreturn
 Kernel C-level entry point.
 
void arch_set_exit_path (int path)
 Set the exit path.
 
void arch_exit (void) __noreturn
 Generic kernel "exit" point.
 
void arch_return (int ret_code) __noreturn
 Kernel "return" point.
 
void arch_abort (void) __noreturn
 Kernel "abort" point.
 
void arch_reboot (void) __noreturn
 Kernel "reboot" call.
 
void arch_menu (void) __noreturn
 Kernel "exit to menu" call.
 
int mm_init (void)
 Initialize the memory management system.
 
void * mm_sbrk (unsigned long increment)
 Request more core memory from the system.
 
void arch_real_exit (int ret_code) __noreturn
 Jump back to the bootloader.
 
int hardware_sys_init (void)
 Initialize bare-bones hardware systems.
 
int hardware_periph_init (void)
 Initialize some peripheral systems.
 
void hardware_shutdown (void)
 Shut down hardware that was initted.
 
int hardware_sys_mode (int *region)
 Retrieve the system mode of the console in use.
 

Detailed Description

Dreamcast Architecture-Specific Options and high-level API.

Macro Definition Documentation

◆ _arch_mem_top

#define _arch_mem_top   ((uint32) 0x8d000000)

Top of memory available, depending on memory size.

◆ arch_fptr_next

#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.

◆ arch_fptr_ret_addr

#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.

◆ arch_get_fptr

#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:33

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.

◆ arch_get_ret_addr

#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.

◆ arch_htonl

#define arch_htonl (   x)    arch_swap32(x)

Convert host-to-network long.

This macro converts a value in the host's native byte order to network byte order (big endian). On a little endian system (like the Dreamcast), this should just call arch_swap32(). On a big endian system, this should be a no-op.

Parameters
xThe value to be converted. This should be a uint32, or equivalent.
Returns
The converted value.

◆ arch_htons

#define arch_htons (   x)    arch_swap16(x)

Convert host-to-network short.

This macro converts a value in the host's native byte order to network byte order (big endian). On a little endian system (like the Dreamcast), this should just call arch_swap16(). On a big endian system, this should be a no-op.

Parameters
xThe value to be converted. This should be a uint16, or equivalent.
Returns
The converted value.

◆ arch_ntohl

#define arch_ntohl (   x)    arch_swap32(x)

Convert network-to-host long.

This macro converts a network byte order (big endian) value to the host's native byte order. On a little endian system (like the Dreamcast), this should just call arch_swap32(). On a big endian system, this should be a no-op.

Parameters
xThe value to be converted. This should be a uint32, or equivalent.
Returns
The converted value.

◆ arch_ntohs

#define arch_ntohs (   x)    arch_swap16(x)

Convert network-to-host short.

This macro converts a network byte order (big endian) value to the host's native byte order. On a little endian system (like the Dreamcast), this should just call arch_swap16(). On a big endian system, this should be a no-op.

Parameters
xThe value to be converted. This should be a uint16, or equivalent.
Returns
The converted value.

◆ arch_sleep

#define arch_sleep ( )
Value:
do { \
__asm__ __volatile__("sleep"); \
} while(0)

Dreamcast specific sleep mode "function".

◆ arch_swap16

#define arch_swap16 (   x)
Value:
({ \
uint16 __x = (x); \
__asm__ __volatile__("swap.b %0, %0" : "=r" (__x) : "0" (__x)); \
__x; \
})
unsigned short uint16
16-bit unsigned integer
Definition types.h:34

Swap the byte order of a 16-bit integer.

This macro swaps the byte order of a 16-bit integer in an architecture- defined manner.

Parameters
xThe value to be byte-swapped. This should be a uint16, or equivalent.
Returns
The swapped value.

◆ arch_swap32

#define arch_swap32 (   x)
Value:
({ \
uint32 __x = (x); \
__asm__ __volatile__("swap.b %0, %0\n\t" \
"swap.w %0, %0\n\t" \
"swap.b %0, %0\n\t" : "=r"(__x) : "0" (__x)); \
__x; \
})

Swap the byte order of a 32-bit integer.

This macro swaps the byte order of a 32-bit integer in an architecture- defined manner.

Parameters
xThe value to be byte-swapped. This should be a uint32, or equivalent.
Returns
The swapped value.

◆ arch_valid_address

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

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.

◆ BYTE_ORDER

#define BYTE_ORDER   LITTLE_ENDIAN

Define the byte-order of the platform in use.

◆ DBL_MEM

#define DBL_MEM   (_arch_mem_top - 0x8d000000)

Use this macro to easily determine if system has 32MB of RAM.

Returns
Non-zero if console has 32MB of RAM, zero otherwise

◆ DEFAULT_PIXEL_MODE

#define DEFAULT_PIXEL_MODE   PM_RGB565

Default pixel mode for video.

◆ DEFAULT_SERIAL_BAUD

#define DEFAULT_SERIAL_BAUD   115200

Default serial bitrate.

◆ DEFAULT_SERIAL_FIFO

#define DEFAULT_SERIAL_FIFO   1

Default serial FIFO behavior.

◆ DEFAULT_VID_MODE

#define DEFAULT_VID_MODE   DM_640x480

Default video mode.

◆ ELF_SYM_PREFIX

#define ELF_SYM_PREFIX   "_"

Global symbol prefix in ELF files.

◆ ELF_SYM_PREFIX_LEN

#define ELF_SYM_PREFIX_LEN   1

Length of global symbol prefix in ELF files.

◆ HW_MEMSIZE

#define HW_MEMSIZE   (_arch_mem_top - 0x8c000000)

Determine how much memory is installed in current machine.

Returns
The total size of system memory in bytes.

◆ HZ

#define HZ   100

Scheduler interrupt frequency.

Timer interrupt frequency for the KOS thread scheduler.

Note
This value is what KOS uses initially upon startup, but it can be reconfigured at run-time.
See also
thd_get_hz(), thd_set_hz()

◆ page_count

#define page_count   ((_arch_mem_top - page_phys_base) / PAGESIZE)

Page count "variable".

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

◆ page_phys_base

#define page_phys_base   0x8c010000

Base address of available physical pages.

◆ PAGEMASK

#define PAGEMASK   (PAGESIZE - 1)

Mask for page offset.

◆ PAGESIZE

#define PAGESIZE   4096

Page size (for MMU)

◆ PAGESIZE_BITS

#define PAGESIZE_BITS   12

Bits for page size.

◆ THD_STACK_SIZE

#define THD_STACK_SIZE   32768

Default thread stack size.

Function Documentation

◆ arch_abort()

void arch_abort ( void  )

Kernel "abort" point.

Note
This function will never return!

◆ arch_exit()

void arch_exit ( void  )

Generic kernel "exit" point.

Note
This function will never return!

◆ arch_main()

void arch_main ( void  )

Kernel C-level entry point.

Note
This function will never return!

◆ arch_menu()

void arch_menu ( void  )

Kernel "exit to menu" call.

Note
This function will never return!

◆ arch_panic()

void arch_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!

◆ arch_real_exit()

void arch_real_exit ( int  ret_code)

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!

◆ arch_reboot()

void arch_reboot ( void  )

Kernel "reboot" call.

Note
This function will never return!

◆ arch_return()

void arch_return ( int  ret_code)

Kernel "return" point.

Note
This function will never return!

◆ arch_set_exit_path()

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
Exit Paths

◆ hardware_periph_init()

int hardware_periph_init ( void  )

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).

◆ hardware_shutdown()

void hardware_shutdown ( void  )

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.

◆ hardware_sys_init()

int hardware_sys_init ( void  )

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).

◆ hardware_sys_mode()

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).

◆ mm_init()

int mm_init ( void  )

Initialize the memory management system.

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

◆ mm_sbrk()

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.