OpenCores
URL https://opencores.org/ocsvn/ion/ion/trunk

Subversion Repositories ion

[/] [ion/] [trunk/] [src/] [common/] [bootstrap.s] - Blame information for rev 232

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 173 ja_rd
################################################################################
2
# bootstrap.s -- Reset code and trap handlers.
3
#
4
# This is the boot code for all applications, includes reset code and basic trap
5
# handler with calls for all the trap causes.
6
#
7
# Initializes the caches and jumps to 'entry' in kernel mode and with interrupts
8
# disabled.
9
#
10
# This code is meant to be placed at the reset vector address (0xbfc00000).
11
#-------------------------------------------------------------------------------
12
# FIXME: exception handling is incomplete (nothing is done on exception).
13
################################################################################
14
 
15
    #---- Cache parameters -----------------------------------------------------
16
    .set ICACHE_NUM_LINES, 256              # no. of lines in the I-Cache
17
    .set DCACHE_NUM_LINES, 256              # no. of lines in the D-Cache
18
    .set DCACHE_LINE_SIZE, 4                # D-Cache line size in words
19
 
20
    #---------------------------------------------------------------------------
21
 
22
    .text
23
    .align  2
24
    .global reset
25
    .ent    reset
26
reset:
27
    .set    noreorder
28
 
29
    b       start_boot
30
    nop
31
 
32
    #--- Trap handler ----------------------------------------------------------
33
 
34
    # We have three trap sources: syscall, break and unimplemented opcode
35
    # Plus we have to account for a faulty cause code; that's 4 causes.
36
    # Besides, we have to look out for the branch delay flag (BD).
37
    .org    0x0180
38
interrupt_vector:
39
    mfc0    $k0,$13             # Get trap cause code
40
    srl     $k0,$k0,2
41
    andi    $k0,$k0,0x01f
42
    ori     $k1,$zero,0x8       # was it a syscall?
43
    beq     $k0,$k1,trap_syscall
44
    addi    $k1,$k1,0x1         # was it a break?
45
    beq     $k0,$k1,trap_break
46
    addi    $k1,$k1,0x1         # was it a bad opcode?
47
    bne     $k0,$k1,trap_invalid
48
    nop
49
 
50
    # Unimplemented instruction
51
trap_unimplemented:
52
    .ifdef  NO_EMU_MIPS32
53
    j       trap_return         # FIXME should flag the bad opcode?
54
    nop
55
    .else
56
    j       opcode_emu
57
    nop
58
    .endif
59
 
60
    # Break instruction
61
trap_break:
62
    j       trap_return         # FIXME no support for break opcode
63
    nop
64
 
65
    # Syscall instruction
66
trap_syscall:
67
    j       trap_return         # FIXME no support for syscall opcode
68
    nop
69
 
70
    # Invalid trap cause code, most likely hardware bug
71
trap_invalid:
72
    j       trap_return         # FIXME should do something about this
73
    nop
74
 
75
trap_return:
76
    mfc0    $k1,$14             # C0_EPC=14 (Exception PC)
77
    mfc0    $k0,$13             # Get bit 31 (BD) from C0 cause register
78
    srl     $k0,31
79
    andi    $k0,$k0,1
80
    bnez    $k0,trap_return_delay_slot
81
    addi    $k1,$k1,4           # skip trap instruction
82
    jr      $k1
83
    nop
84
trap_return_delay_slot:
85
    addi    $k1,$k1,4           # skip jump instruction too
86
    jr      $k1                 # (we just added 8 to epc)
87
    rfe
88
 
89
 
90
#-------------------------------------------------------------------------------
91
 
92
start_boot:
93
    mfc0    $a0,$12
94
    andi    $a0,$a0,0xfffe
95
    mtc0    $a0,$12             # disable interrupts, disable cache
96
 
97
    jal     setup_cache         # Initialize the caches
98
    nop
99
 
100
    # Hardware initialization done. Now we should jump to the main program.
101
    # Note that if this file was linked separately from the main program (for
102
    # example to be loaded in different memory areas) then the makefile will
103
    # have to provide a suitable value for symbol 'entry'.
104
    la      $a0,entry
105
    jr      $a0
106
    nop
107
    # We won't be coming back...
108
 
109
 
110
#---- Functions ----------------------------------------------------------------
111
 
112
# void setup_cache(void) -- invalidates all I-Cache lines (uses no RAM)
113
setup_cache:
114
    lui     $a1,0x0001      # Disable cache, enable I-cache line invalidation
115
    mfc0    $a0,$12
116
    andi    $a0,$a0,0xffff
117
    or      $a1,$a0,$a1
118
    mtc0    $a1,$12
119
 
120
    # In order to invalidate a I-Cache line we have to write its tag number to
121
    # any address while bits CP0[12].17:16=01. The write will be executed as a
122
    # regular write too, as a side effect, so we need to choose a harmless
123
    # target address.
124
 
125
    li      $a0,XRAM_BASE
126
    li      $a2,0
127
    li      $a1,ICACHE_NUM_LINES-1
128
 
129
inv_i_cache_loop:
130
    sw      $a2,0($a0)
131
    blt     $a2,$a1,inv_i_cache_loop
132
    addi    $a2,1
133
 
134
    # Now, the D-Cache is different. To invalidate a D-Cache line you just
135
    # read from it (by proper selection of a dummy target address)  while bits
136
    # CP0[12].17:16=01. The data read is undefined and should be discarded.
137
 
138
    li      $a0,0               # Use any base address that is mapped
139
    li      $a2,0
140
    li      $a1,DCACHE_NUM_LINES-1
141
 
142
inv_d_cache_loop:
143
    lw      $zero,0($a0)
144
    addi    $a0,DCACHE_LINE_SIZE*4
145
    blt     $a2,$a1,inv_d_cache_loop
146
    addi    $a2,1
147
 
148
    lui     $a1,0x0002          # Leave with cache enabled
149
    mfc0    $a0,$12
150
    andi    $a0,$a0,0xffff
151
    or      $a1,$a0,$a1
152
    jr      $ra
153
    mtc0    $a1,$12
154
 
155
    .set    reorder
156
    .end    reset

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.