OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [bootrom/] [bootrom.S] - Blame information for rev 413

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

Line No. Rev Author Line
1 361 julius
//////////////////////////////////////////////////////////////////////
2
///                                                               ////
3
/// bootrom                                                       ////
4
///                                                               ////
5
/// Assembly programs to be embedded inside system to aid boot    ////
6
///                                                               ////
7
/// Julius Baxter, julius@opencores.org                           ////
8
///                                                               ////
9
//////////////////////////////////////////////////////////////////////
10
////                                                              ////
11
//// Copyright (C) 2009, 2010 Authors and OPENCORES.ORG           ////
12
////                                                              ////
13
//// This source file may be used and distributed without         ////
14
//// restriction provided that this copyright statement is not    ////
15
//// removed from the file and that any derivative work contains  ////
16
//// the original copyright notice and the associated disclaimer. ////
17
////                                                              ////
18
//// This source file is free software; you can redistribute it   ////
19
//// and/or modify it under the terms of the GNU Lesser General   ////
20
//// Public License as published by the Free Software Foundation; ////
21
//// either version 2.1 of the License, or (at your option) any   ////
22
//// later version.                                               ////
23
////                                                              ////
24
//// This source is distributed in the hope that it will be       ////
25
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
26
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
27
//// PURPOSE.  See the GNU Lesser General Public License for more ////
28
//// details.                                                     ////
29
////                                                              ////
30
//// You should have received a copy of the GNU Lesser General    ////
31
//// Public License along with this source; if not, download it   ////
32
//// from http://www.opencores.org/lgpl.shtml                     ////
33
////                                                              ////
34
//////////////////////////////////////////////////////////////////////
35
 
36
// Defines for which bootrom app to use are in board.h - TODO: use the
37
// processed orspoc-defines.v file for this define. It makes more sense
38
// as this software ends up as gates.
39
 
40
#include "board.h"
41
 
42 403 julius
#ifdef BOOTROM_SPI_FLASH
43 361 julius
 
44
        /* Assembly program to go into the boot ROM */
45
        /* Currently just loads a program from SPI flash into RAM */
46
        /* Assuming address at RAM_LOAD_BASE gets clobbered, we need
47
           a byte writable address somewhere!*/
48
 
49
#define SPI_BASE SPI0_BASE
50
/* simple_spi driver */
51
#define SPI_SPCR 0x0
52
#define SPI_SPSR 0x1
53
#define SPI_SPDR 0x2
54
#define SPI_SPER 0x3
55
#define SPI_SPSS 0x4
56
 
57
#define SPI_SPCR_XFER_GO 0x51
58
#define SPI_SPSS_INIT 0x1
59
#define SPI_SPSR_RX_CHECK 0x01 /* Check bit 0 is cleared, fifo !empty*/
60
 
61
#define RAM_LOAD_BASE SDRAM_BASE
62
#define RESET_ADDR 0x100
63
 
64
boot_init:
65
        l.movhi r0, 0
66
        l.movhi r1, RAM_LOAD_BASE
67
        l.movhi r4, hi(SPI_BASE)
68
 
69
spi_init:
70
        l.ori r2, r0, SPI_SPCR_XFER_GO /* Setup SPCR with enable bit set */
71
        l.sb SPI_SPCR(r4), r2
72
        l.sb  SPI_SPSS(r4), r0         /* Clear SPI slave selects */
73
        l.ori r6, r0, SPI_SPSS_INIT
74
        l.sb  SPI_SPSS(r4), r6         /* Now put in appropriate slave select */
75
        l.jal spi_xfer
76
        l.ori r3, r0, 0x3              /* READ command opcode for SPI device */
77
        l.jal spi_xfer
78
        l.or r3, r0, r0
79
        l.jal spi_xfer
80
        l.or r3, r0, r0
81
        l.jal spi_xfer
82
        l.or r3, r0, r0
83
        l.movhi r6, 0
84
        l.movhi r7, 0xffff
85
 
86
copy:
87
        l.jal spi_xfer         /* Read a byte into r3 */
88
        l.add r8, r1, r6       /* Calculate store address */
89
        l.sb 0(r8), r3         /* Write byte to memory */
90
        l.addi r6, r6, 1       /* Increment counter */
91
        l.sfeqi r6, 0x4        /* Is this the first word */
92
        l.bf store_sizeword    /* put sizeword in the register */
93
        l.sfeq r6, r7          /* Check if we've finished loading the words */
94
        l.bnf copy             /* Continue copying if not last word */
95
        l.nop
96
 
97
goto_reset:
98
        l.ori r1, r1, RESET_ADDR
99
        l.jr r1
100
        l.sb  SPI_SPSS(r4), r0 /* Clear SPI slave selects */
101
 
102
store_sizeword:
103
        l.j copy
104
        l.lwz r7, 0(r1)         /* Size word is in first word of SDRAM */
105
 
106
spi_xfer:
107
        l.sb SPI_SPDR(r4), r3  /* Dummy write what's in r3 */
108
        l.ori r3, r0, SPI_SPSR_RX_CHECK /* r3 = , ensure loop just once */
109
spi_xfer_poll:
110
        l.andi r3, r3, SPI_SPSR_RX_CHECK /* AND read fifo bit empty */
111
        l.sfeqi r3, SPI_SPSR_RX_CHECK    /* is bit set? ... */
112
        l.bf spi_xfer_poll     /* ... if so, rxfifo empty, keep polling */
113
        l.lbz r3, SPI_SPSR(r4) /* Read SPSR */
114
        l.jr r9
115
        l.lbz r3, SPI_SPDR(r4) /* Get data byte */
116
 
117
 
118
#endif
119
 
120 403 julius
#ifdef BOOTROM_GOTO_RESET
121 361 julius
        /* Jump to reset vector in the SDRAM */
122
        l.movhi r0, 0
123
        l.movhi r4, SDRAM_BASE
124
        l.ori r4, r4, 0x100
125
        l.jr r4
126
        l.nop
127
 
128
#endif
129
 
130 403 julius
#ifdef BOOTROM_LOOP_AT_ZERO
131 361 julius
 
132
        /* Don't load app via SPI, instead just put an infinite loop into bottom
133
        of memory and jump there.
134
        */
135
        l.movhi r0, 0
136
        l.movhi r4, SDRAM_BASE
137
        l.sw 0x0(r4), r0
138
        l.movhi r5, hi(0x15000001) /* A l.nop 1 so sim exits if this enabled */
139
        l.ori r5, r5, lo(0x15000001)
140
        l.sw 0x4(r4), r5
141
        l.sw 0x8(r4), r5
142
        l.sw 0xc(r4), r5
143
        l.jr r4
144
        l.nop
145
 
146
 
147
 
148
#endif
149
 
150 403 julius
#ifdef BOOTROM_LOOP_IN_ROM
151 361 julius
 
152
        /* Don't load app via SPI, instead just put an infinite loop into bottom
153
        of memory and jump there.
154
        */
155
        l.movhi r0, 0
156
        l.nop 0x1
157
        l.j 0
158
        l.nop
159
        l.nop
160
 
161
 
162
 
163
#endif

powered by: WebSVN 2.1.0

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