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

Subversion Repositories hive

[/] [hive/] [trunk/] [v04.05/] [boot_code/] [boot_code_v_io.h] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 ericw
/*
2
--------------------------------------------------------------------------------
3
 
4
Module : boot_code.h
5
 
6
--------------------------------------------------------------------------------
7
 
8
Function:
9
- Boot code for a processor core.
10
 
11
Instantiates:
12
- Nothing.
13
 
14
Notes:
15
- For testing (@ core.v):
16
  CLR_BASE              = 'h0;
17
  CLR_SPAN              = 2;  // gives 4 instructions
18
  INTR_BASE             = 'h20;  // 'd32
19
  INTR_SPAN             = 2;  // gives 4 instructions
20
 
21
 
22
--------------------------------------------------------------------------------
23
*/
24
 
25
        /*
26
        --------------------
27
        -- external stuff --
28
        --------------------
29
        */
30
        `include "op_encode.h"
31
        `include "reg_set_addr.h"
32
        `include "boot_code_defs.h"
33
 
34
        /*
35
        ----------------------------------------
36
        -- initialize: fill with default data --
37
        ----------------------------------------
38
        */
39
        integer i;
40
 
41
        initial begin
42
 
43
/*      // fill with nop (some compilers need this)
44
        for ( i = 0; i < CAPACITY; i = i+1 ) begin
45
                ram[i] = { `nop, `__, `__ };
46
        end
47
*/
48
 
49
        /*
50
        ---------------
51
        -- boot code --
52
        ---------------
53
        */
54
 
55
 
56
        // Thread 0 : test I/O functions
57
        // All other threads : loop forever
58
 
59
        ///////////////
60
        // clr space //
61
        ///////////////
62
 
63
        // thread 0
64
        i='h0;   ram[i] = { `lit_u,            `__, `s2 };  // s2='h0100
65
        i=i+1;   ram[i] =                      16'h0100  ;  //
66
        i=i+1;   ram[i] = { `gto,              `P2, `__ };  // goto, pop s2 (addr)
67
        // thread 1
68
        i='h4;   ram[i] = { `lit_u,            `__, `s2 };  // s2='h0200
69
        i=i+1;   ram[i] =                      16'h0200  ;  //
70
        i=i+1;   ram[i] = { `gto,              `P2, `__ };  // goto, pop s2 (addr)
71
        // and the rest
72
        i='h08;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
73
        i='h0c;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
74
        i='h10;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
75
        i='h14;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
76
        i='h18;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
77
        i='h1c;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
78
 
79
 
80
        ////////////////
81
        // intr space //
82
        ////////////////
83
 
84
        ///////////////////////
85
        // code & data space //
86
        ///////////////////////
87
 
88
 
89
        // test I/O functions, result in s0
90
        // Correct functioning is s0 = 'd8 ('h8).
91
        //
92
        // s0 : final test result
93
        // s1 : test value
94
        // s2 : test value
95
        // s3 : running test result, subroutine return address
96
        //
97
        // setup running test result:
98
        i='h100; ram[i] = { `dat_is,          6'd0, `s3 };  // s3=0
99
        // PGC
100
        i=i+1;   ram[i] = { `pgc,              `__, `s1 };  // s1=PC
101
        i=i+1;   ram[i] = { `lit_u,            `__, `s0 };  // s0='h0102
102
        i=i+1;   ram[i] =                      16'h0102  ;  //
103
        i=i+1;   ram[i] = { `jmp_ie,     4'd1, `P1, `P0 };  // (s0==s1) ? skip, pop both
104
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3--
105
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
106
        // setup test value:
107
        i=i+1;   ram[i] = { `lit_u,            `__, `s1 };  // s1='h36c9,a53c
108
        i=i+1;   ram[i] =                      16'ha53c  ;  //
109
        i=i+1;   ram[i] = { `lit_h,            `__, `P1 };  //
110
        i=i+1;   ram[i] =                      16'h36c9  ;  // 
111
        // MEM_IWH & MEM_IRH
112
        i=i+1;   ram[i] = { `lit_u,            `__, `s2 };  // s2='h0a00
113
        i=i+1;   ram[i] =                      16'h0a00  ;  //
114
        i=i+1;   ram[i] = { `mem_iw,     4'd0, `s2, `s1 };  // (s2+offset)=s1
115
        i=i+1;   ram[i] = { `mem_iwh,    4'd1, `s2, `s1 };  //
116
        i=i+1;   ram[i] = { `mem_irs,    4'd0, `s2, `s0 };  // s0=(s2+offset)
117
        i=i+1;   ram[i] = { `mem_irh,    4'd1, `P2, `P0 };  //
118
        i=i+1;   ram[i] = { `jmp_ie,     4'd1, `s1, `P0 };  // (s0==s1) ? skip, pop s0
119
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3--
120
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
121
        // MEM_IRS (signed)
122
        i=i+1;   ram[i] = { `lit_u,            `__, `s2 };  // s2='h0a00
123
        i=i+1;   ram[i] =                      16'h0a10  ;  //
124
        i=i+1;   ram[i] = { `mem_iw,     4'd0, `s2, `s1 };  // (s2+offset)=s1
125
        i=i+1;   ram[i] = { `mem_irs,    4'd0, `P2, `s0 };  // s0=(s2+offset), pop s2
126
        i=i+1;   ram[i] = { `shl_is,         6'd16, `s1 };  // s1<<=16
127
        i=i+1;   ram[i] = { `shl_is,        -6'd16, `P1 };  // s1>>=16
128
        i=i+1;   ram[i] = { `jmp_ie,     4'd1, `P1, `P0 };  // (s0==s1) ? skip, pop both
129
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3--
130
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
131
        // MEM_IRS (unsigned)
132
        i=i+1;   ram[i] = { `lit_u,            `__, `s2 };  // s2='h0a00
133
        i=i+1;   ram[i] =                      16'h0a20  ;  //
134
        i=i+1;   ram[i] = { `mem_iwh,    4'd0, `s2, `s1 };  // (s2+offset)=s1
135
        i=i+1;   ram[i] = { `mem_irs,    4'd0, `P2, `s0 };  // s0=(s2+offset), pop s2
136
        i=i+1;   ram[i] = { `psu_i,        -6'd16, `s1 };  // s1>>=16
137
        i=i+1;   ram[i] = { `jmp_ie,     4'd1, `P1, `P0 };  // (s0==s1) ? skip, pop both
138
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3--
139
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
140
        // REG_RS, REG_RH, REG_W & REG_WH (check manually for I/O loopback)
141
        i=i+1;   ram[i] = { `dat_is,        `IO_LO, `s2 };  // s2=reg addr
142
        i=i+1;   ram[i] = { `reg_rs,           `s2, `s1 };  // s1=(s2)
143
        i=i+1;   ram[i] = { `reg_w,            `P2, `P1 };  // (s2)=s1, pop both
144
        i=i+1;   ram[i] = { `dat_is,        `IO_HI, `s2 };  // s2=reg addr
145
        i=i+1;   ram[i] = { `reg_rh,           `s2, `s1 };  // s1=(s2)
146
        i=i+1;   ram[i] = { `reg_wh,           `P2, `P1 };  // (s2)=s1, pop s2
147
        // LIT_S
148
        i=i+1;   ram[i] = { `lit_s,            `__, `s0 };  // s0='ha53c
149
        i=i+1;   ram[i] =                      16'ha53c  ;  //
150
        i=i+1;   ram[i] = { `shl_is,         6'd16, `s1 };  // s1<<=16
151
        i=i+1;   ram[i] = { `shl_is,        -6'd16, `P1 };  // s1>>=16, pop s1
152
        i=i+1;   ram[i] = { `jmp_ie,     4'd1, `P1, `P0 };  // (s0==s1) ? skip, pop both
153
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3--
154
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
155
        // LIT_U
156
        i=i+1;   ram[i] = { `lit_u,            `__, `s0 };  // s0='ha53c
157
        i=i+1;   ram[i] =                      16'ha53c  ;  //
158
        i=i+1;   ram[i] = { `shl_is,         6'd16, `s1 };  // s1<<=16
159
        i=i+1;   ram[i] = { `psu_i,         -6'd16, `P1 };  // s1>>=16, pop s1
160
        i=i+1;   ram[i] = { `jmp_ie,     4'd1, `P1, `P0 };  // (s0==s1) ? skip, pop both
161
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3--
162
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
163
        // check for no opcode errors
164
        i=i+1;   ram[i] = { `lit_u,            `__, `s7 };  // s7='h0900
165
        i=i+1;   ram[i] =                      16'h0900  ;  //
166
        i=i+1;   ram[i] = { `gsb,              `P7, `s7 };  // gsb, pop s7 (addr)
167
        i=i+1;   ram[i] = { `jmp_iz,          6'd1, `P4 };  // (s4==0) ? skip, pop s4
168
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3--
169
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
170
        // check for no stack errors
171
        i=i+1;   ram[i] = { `lit_u,            `__, `s7 };  // s7='h0910
172
        i=i+1;   ram[i] =                      16'h0910  ;  //
173
        i=i+1;   ram[i] = { `gsb,              `P7, `s7 };  // gsb, pop s2 (addr)
174
        i=i+1;   ram[i] = { `jmp_iz,          6'd1, `P4 };  // (s4==0) ? skip, pop s4
175
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3--
176
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
177
        // copy result to s0
178
        i=i+1;   ram[i] = { `cpy,              `P3, `s0 };  // s0=s3, pop s3
179
        // loop forever
180
        i=i+1;   ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
181
        // end sub
182
 
183
 
184
        // test UART
185
        //
186
        // s0 : TX value
187
        // s1 :
188
        // s2 : reg addr
189
        // s3 :
190
        // s4 : TX ready
191
        //
192
        //
193
        i='h200; ram[i] = { `lit_u,            `__, `s0 };  // s0='h00a5
194
        i=i+1;   ram[i] =                      16'h00a5  ;  //
195
        i=i+1;   ram[i] = { `dat_is,      `UART_TX, `s2 };  // s2=reg addr
196
        i=i+1;   ram[i] = { `reg_rs,           `s2, `s4 };  // s4=(s2)
197
        i=i+1;   ram[i] = { `jmp_iz,          6'd1, `P4 };  // (s4==0) ? skip, pop s4
198
        i=i+1;   ram[i] = { `reg_w,            `s2, `s0 };  // (s2)=s0
199
        // loop forever
200
        i=i+1;   ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
201
        // end sub
202
 
203
 
204
        /////////////////
205
        // subroutines //
206
        /////////////////
207
 
208
 
209
        // sub : read & clear opcode errors for this thread => s4, return to (s7)
210
        // avoid the use of s1!
211
        i='h900; ram[i] = { `dat_is,      `THRD_ID, `s6 };  // s6=reg addr
212
        i=i+1;   ram[i] = { `reg_rs,           `P6, `s5 };  // s5=(s6), pop s6
213
        i=i+1;   ram[i] = { `pow,              `P5, `s4 };  // s4=1<<s5, pop s5
214
        i=i+1;   ram[i] = { `dat_is,        `OP_ER, `s6 };  // s6=reg addr
215
        i=i+1;   ram[i] = { `reg_rs,           `s6, `s5 };  // s5=(s6)
216
        i=i+1;   ram[i] = { `and,              `P5, `P4 };  // s4&=s5, pop s5
217
        i=i+1;   ram[i] = { `reg_w,            `P6, `s4 };  // (s6)=s4, pop s6
218
        i=i+1;   ram[i] = { `gto,              `P7, `__ };  // return to (s7), pop s7
219
 
220
 
221
        // sub : read & clear stack errors for this thread => s4, return to (s7)
222
        // avoid the use of s1!
223
        i='h910; ram[i] = { `dat_is,      `THRD_ID, `s6 };  // s6=reg addr
224
        i=i+1;   ram[i] = { `reg_rs,           `P6, `s5 };  // s5=(s6), pop s6
225
        i=i+1;   ram[i] = { `pow,              `P5, `s4 };  // s4=1<<s5, pop s5
226
        i=i+1;   ram[i] = { `cpy,              `s4, `s5 };  // s5=s4
227
        i=i+1;   ram[i] = { `shl_is,          6'd8, `P5 };  // s5<<=8
228
        i=i+1;   ram[i] = { `orr,              `P5, `P4 };  // s4|=s5, pop s5
229
        i=i+1;   ram[i] = { `dat_is,       `STK_ER, `s6 };  // s6=reg addr
230
        i=i+1;   ram[i] = { `reg_rs,           `s6, `s5 };  // s5=(s6)
231
        i=i+1;   ram[i] = { `and,              `P5, `P4 };  // s4&=s5, pop s5
232
        i=i+1;   ram[i] = { `reg_w,            `P6, `s4 };  // (s6)=s4, pop s6
233
        i=i+1;   ram[i] = { `gto,              `P7, `__ };  // return to (s7), pop s7
234
 
235
 
236
        end

powered by: WebSVN 2.1.0

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