Search
lxdream.org :: lxdream/src/aica/armcore.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/aica/armcore.h
changeset 736:a02d1475ccfd
prev586:2a3ba82cf243
next814:f1a21df54e19
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
nkeynes@30
     1
/**
nkeynes@586
     2
 * $Id$
nkeynes@30
     3
 * 
nkeynes@30
     4
 * Interface definitions for the ARM CPU emulation core proper.
nkeynes@30
     5
 *
nkeynes@30
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@30
     7
 *
nkeynes@30
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@30
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@30
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@30
    11
 * (at your option) any later version.
nkeynes@30
    12
 *
nkeynes@30
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@30
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@30
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@30
    16
 * GNU General Public License for more details.
nkeynes@30
    17
 */
nkeynes@2
    18
nkeynes@736
    19
#ifndef lxdream_armcore_H
nkeynes@736
    20
#define lxdream_armcore_H 1
nkeynes@2
    21
nkeynes@586
    22
#include "lxdream.h"
nkeynes@586
    23
#include "mem.h"
nkeynes@2
    24
#include <stdint.h>
nkeynes@35
    25
#include <stdio.h>
nkeynes@35
    26
nkeynes@736
    27
#ifdef __cplusplus
nkeynes@736
    28
extern "C" {
nkeynes@736
    29
#endif
nkeynes@736
    30
nkeynes@73
    31
#define ARM_BASE_RATE 2 /* MHZ */
nkeynes@35
    32
extern uint32_t arm_cpu_freq;
nkeynes@35
    33
extern uint32_t arm_cpu_period;
nkeynes@2
    34
nkeynes@7
    35
#define ROTATE_RIGHT_LONG(operand,shift) ((((uint32_t)operand) >> shift) | ((operand<<(32-shift))) )
nkeynes@2
    36
nkeynes@2
    37
struct arm_registers {
nkeynes@11
    38
    uint32_t r[16]; /* Current register bank */
nkeynes@11
    39
    
nkeynes@11
    40
    uint32_t cpsr;
nkeynes@11
    41
    uint32_t spsr;
nkeynes@11
    42
    
nkeynes@35
    43
    /* Various banked versions of the registers. Note that these are used
nkeynes@35
    44
     * to save the registers for the named bank when leaving the mode, they're
nkeynes@35
    45
     * not actually used actively.
nkeynes@35
    46
     **/
nkeynes@11
    47
    uint32_t user_r[7]; /* User/System bank 8..14 */
nkeynes@35
    48
    uint32_t svc_r[3]; /* SVC bank 13..14, SPSR */
nkeynes@35
    49
    uint32_t abt_r[3]; /* ABT bank 13..14, SPSR */
nkeynes@35
    50
    uint32_t und_r[3]; /* UND bank 13..14, SPSR */
nkeynes@35
    51
    uint32_t irq_r[3]; /* IRQ bank 13..14, SPSR */
nkeynes@35
    52
    uint32_t fiq_r[8]; /* FIQ bank 8..14, SPSR */
nkeynes@11
    53
    
nkeynes@11
    54
    uint32_t c,n,z,v,t;
nkeynes@11
    55
    
nkeynes@11
    56
    /* "fake" registers */
nkeynes@51
    57
    uint32_t int_pending; /* Mask of CPSR_I and CPSR_F */
nkeynes@11
    58
    uint32_t shift_c;  /* used for temporary storage of shifter results */
nkeynes@11
    59
    uint32_t icount; /* Instruction counter */
nkeynes@86
    60
    gboolean running; /* Indicates that the ARM is operational, as opposed to
nkeynes@86
    61
		       * halted */
nkeynes@2
    62
};
nkeynes@2
    63
nkeynes@2
    64
#define CPSR_N 0x80000000 /* Negative flag */
nkeynes@2
    65
#define CPSR_Z 0x40000000 /* Zero flag */
nkeynes@2
    66
#define CPSR_C 0x20000000 /* Carry flag */
nkeynes@2
    67
#define CPSR_V 0x10000000 /* Overflow flag */
nkeynes@2
    68
#define CPSR_I 0x00000080 /* Interrupt disable bit */ 
nkeynes@2
    69
#define CPSR_F 0x00000040 /* Fast interrupt disable bit */
nkeynes@2
    70
#define CPSR_T 0x00000020 /* Thumb mode */
nkeynes@2
    71
#define CPSR_MODE 0x0000001F /* Current execution mode */
nkeynes@37
    72
#define CPSR_COMPACT_MASK 0x0FFFFFDF /* Mask excluding all separated flags */
nkeynes@2
    73
nkeynes@35
    74
#define MODE_USER 0x10 /* User mode */
nkeynes@35
    75
#define MODE_FIQ   0x11 /* Fast IRQ mode */
nkeynes@35
    76
#define MODE_IRQ  0x12 /* IRQ mode */
nkeynes@35
    77
#define MODE_SVC  0x13 /* Supervisor mode */
nkeynes@35
    78
#define MODE_ABT 0x17 /* Abort mode */
nkeynes@35
    79
#define MODE_UND 0x1B /* Undefined mode */
nkeynes@35
    80
#define MODE_SYS 0x1F /* System mode */
nkeynes@2
    81
nkeynes@37
    82
#define IS_PRIVILEGED_MODE() ((armr.cpsr & CPSR_MODE) != MODE_USER)
nkeynes@37
    83
#define IS_EXCEPTION_MODE() (IS_PRIVILEGED_MODE() && (armr.cpsr & CPSR_MODE) != MODE_SYS)
nkeynes@46
    84
#define IS_FIQ_MODE() ((armr.cpsr & CPSR_MODE) == MODE_FIQ)
nkeynes@37
    85
nkeynes@2
    86
extern struct arm_registers armr;
nkeynes@2
    87
nkeynes@5
    88
#define CARRY_FLAG (armr.cpsr&CPSR_C)
nkeynes@2
    89
nkeynes@35
    90
/* ARM core functions */
nkeynes@35
    91
void arm_reset( void );
nkeynes@35
    92
uint32_t arm_run_slice( uint32_t nanosecs );
nkeynes@35
    93
void arm_save_state( FILE *f );
nkeynes@35
    94
int arm_load_state( FILE *f );
nkeynes@35
    95
gboolean arm_execute_instruction( void );
nkeynes@586
    96
void arm_set_breakpoint( uint32_t pc, breakpoint_type_t type );
nkeynes@586
    97
gboolean arm_clear_breakpoint( uint32_t pc, breakpoint_type_t type );
nkeynes@43
    98
int arm_get_breakpoint( uint32_t pc );
nkeynes@35
    99
nkeynes@11
   100
/* ARM Memory */
nkeynes@37
   101
uint32_t arm_read_long( uint32_t addr );
nkeynes@37
   102
uint32_t arm_read_word( uint32_t addr );
nkeynes@37
   103
uint32_t arm_read_byte( uint32_t addr );
nkeynes@37
   104
uint32_t arm_read_long_user( uint32_t addr );
nkeynes@37
   105
uint32_t arm_read_byte_user( uint32_t addr );
nkeynes@11
   106
void arm_write_long( uint32_t addr, uint32_t val );
nkeynes@11
   107
void arm_write_word( uint32_t addr, uint32_t val );
nkeynes@11
   108
void arm_write_byte( uint32_t addr, uint32_t val );
nkeynes@37
   109
void arm_write_long_user( uint32_t addr, uint32_t val );
nkeynes@37
   110
void arm_write_byte_user( uint32_t addr, uint32_t val );
nkeynes@11
   111
int32_t arm_read_phys_word( uint32_t addr );
nkeynes@14
   112
int arm_has_page( uint32_t addr );
nkeynes@431
   113
void arm_mem_init(void);
nkeynes@736
   114
nkeynes@736
   115
#ifdef __cplusplus
nkeynes@736
   116
}
nkeynes@736
   117
#endif
nkeynes@736
   118
nkeynes@736
   119
#endif /* !lxdream_armcore_H */
.