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

Subversion Repositories hive

[/] [hive/] [trunk/] [v04.05/] [boot_code/] [boot_code_v_stacks.h] - Blame information for rev 8

Go to most recent revision | 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 stack 1 for depth and error reporting
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
        // and the rest
68
        i='h04;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
69
        i='h08;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
70
        i='h0c;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
71
        i='h10;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
72
        i='h14;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
73
        i='h18;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
74
        i='h1c;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
75
 
76
 
77
        ////////////////
78
        // intr space //
79
        ////////////////
80
 
81
        ///////////////////////
82
        // code & data space //
83
        ///////////////////////
84
 
85
 
86
        // test s1 for correct stack depth and error reporting, result in s0
87
        // Correct functioning is s0 = 'd7 ('h7).
88
        //
89
        // s0 : final test result
90
        // s1 : test stack
91
        // s2 : sub addr
92
        // s3 : running test result, subroutine return address
93
        //
94
        // setup running test result:
95
        i='h100; ram[i] = { `dat_is,          6'd0, `s7 };  // s7=0
96
        // check for no stack errors
97
        i=i+1;   ram[i] = { `lit_u,            `__, `s7 };  // s7=addr
98
        i=i+1;   ram[i] =                      16'h0910  ;  // addr
99
        i=i+1;   ram[i] = { `gsb,              `P7, `s7 };  // gsb, pop s7 (addr), return to s7
100
        i=i+1;   ram[i] = { `jmp_iz,          6'd1, `P4 };  // (s4==0) ? skip, pop s4
101
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3-- (Y)
102
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
103
        // fill s1
104
        i=i+1;   ram[i] = { `lit_u,            `__, `s7 };  // s7=addr
105
        i=i+1;   ram[i] =                      16'h0940  ;  // addr
106
        i=i+1;   ram[i] = { `gsb,              `P7, `s7 };  // gsb, pop s7 (addr), return to s7
107
        // check for push error
108
        i=i+1;   ram[i] = { `lit_u,            `__, `s7 };  // s7=addr
109
        i=i+1;   ram[i] =                      16'h0910  ;  // addr
110
        i=i+1;   ram[i] = { `gsb,              `P7, `s7 };  // gsb, pop s7 (addr), return to s7
111
        i=i+1;   ram[i] = { `psu_i,          -6'd8, `P4 };  // s4>>=8
112
        i=i+1;   ram[i] = { `jmp_iz,          6'd1, `P4 };  // (s4==0) ? skip, pop s4
113
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3--
114
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
115
        // pop&push s/b OK
116
        i=i+1;   ram[i] = { `add_is,          6'd0, `P1 };  // s1=s1
117
        // check for no stack errors
118
        i=i+1;   ram[i] = { `lit_u,            `__, `s7 };  // s7=addr
119
        i=i+1;   ram[i] =                      16'h0910  ;  // addr
120
        i=i+1;   ram[i] = { `gsb,              `P7, `s7 };  // gsb, pop s7 (addr), return to s7
121
        i=i+1;   ram[i] = { `jmp_iz,          6'd1, `P4 };  // (s4==0) ? skip, pop s4
122
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3--
123
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
124
        // s/b one push over the line
125
        i=i+1;   ram[i] = { `add_is,          6'd0, `s1 };  // s1=>s1
126
        // check for a push error
127
        i=i+1;   ram[i] = { `lit_u,            `__, `s7 };  // s7=addr
128
        i=i+1;   ram[i] =                      16'h0910  ;  // addr
129
        i=i+1;   ram[i] = { `gsb,              `P7, `s7 };  // gsb, pop s7 (addr), return to s7
130
        i=i+1;   ram[i] = { `psu_i,          -6'd8, `P4 };  // s4>>=8
131
        i=i+1;   ram[i] = { `jmp_inz,         6'd1, `P4 };  // (s4!=0) ? skip, pop s4
132
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3--
133
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
134
        // empty s1
135
        i=i+1;   ram[i] = { `lit_u,            `__, `s7 };  // s7=addr
136
        i=i+1;   ram[i] =                      16'h0950  ;  // addr
137
        i=i+1;   ram[i] = { `gsb,              `P7, `s7 };  // gsb, pop s7 (addr), return to s7
138
        // check for no stack errors
139
        i=i+1;   ram[i] = { `lit_u,            `__, `s7 };  // s7=addr
140
        i=i+1;   ram[i] =                      16'h0910  ;  // addr
141
        i=i+1;   ram[i] = { `gsb,              `P7, `s7 };  // gsb, pop s7 (addr), return to s7
142
        i=i+1;   ram[i] = { `jmp_iz,          6'd1, `P4 };  // (s4==0) ? skip, pop s4
143
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3--
144
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
145
        // s/b one pop under the line
146
        i=i+1;   ram[i] = { `pop,           8'b00000010 };  // pop s1
147
        // check for a pop error        
148
        i=i+1;   ram[i] = { `lit_u,            `__, `s7 };  // s7=addr
149
        i=i+1;   ram[i] =                      16'h0910  ;  // addr
150
        i=i+1;   ram[i] = { `gsb,              `P7, `s7 };  // gsb, pop s7 (addr), return to s7
151
        i=i+1;   ram[i] = { `shl_is,         6'd24, `P4 };  // s4<<=24
152
        i=i+1;   ram[i] = { `jmp_inz,         6'd1, `P4 };  // (s4!=0) ? skip, pop s4
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
        // check for no opcode errors
156
        i=i+1;   ram[i] = { `lit_u,            `__, `s7 };  // s7=addr
157
        i=i+1;   ram[i] =                      16'h0900  ;  // addr
158
        i=i+1;   ram[i] = { `gsb,              `P7, `s7 };  // gsb, pop s7 (addr), return to s7
159
        i=i+1;   ram[i] = { `jmp_iz,          6'd1, `P4 };  // (s4==0) ? skip, pop s4
160
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P3 };  // s3--
161
        i=i+1;   ram[i] = { `add_is,          6'd1, `P3 };  // s3++
162
        // copy result to s0
163
        i=i+1;   ram[i] = { `cpy,              `P3, `s0 };  // s0=s3, pop s3
164
        // loop forever
165
        i=i+1;   ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
166
 
167
 
168
 
169
        /////////////////
170
        // subroutines //
171
        /////////////////
172
 
173
 
174
        // sub : read & clear opcode errors for this thread => s4, return to (s7)
175
        // avoid the use of s1!
176
        i='h900; ram[i] = { `dat_is,      `THRD_ID, `s6 };  // s6=reg addr
177
        i=i+1;   ram[i] = { `reg_rs,           `P6, `s5 };  // s5=(s6), pop s6
178
        i=i+1;   ram[i] = { `pow,              `P5, `s4 };  // s4=1<<s5, pop s5
179
        i=i+1;   ram[i] = { `dat_is,        `OP_ER, `s6 };  // s6=reg addr
180
        i=i+1;   ram[i] = { `reg_rs,           `s6, `s5 };  // s5=(s6)
181
        i=i+1;   ram[i] = { `and,              `P5, `P4 };  // s4&=s5, pop s5
182
        i=i+1;   ram[i] = { `reg_w,            `P6, `s4 };  // (s6)=s4, pop s6
183
        i=i+1;   ram[i] = { `gto,              `P7, `__ };  // return to (s7), pop s7
184
 
185
 
186
        // sub : read & clear stack errors for this thread => s4, return to (s7)
187
        // avoid the use of s1!
188
        i='h910; ram[i] = { `dat_is,      `THRD_ID, `s6 };  // s6=reg addr
189
        i=i+1;   ram[i] = { `reg_rs,           `P6, `s5 };  // s5=(s6), pop s6
190
        i=i+1;   ram[i] = { `pow,              `P5, `s4 };  // s4=1<<s5, pop s5
191
        i=i+1;   ram[i] = { `cpy,              `s4, `s5 };  // s5=s4
192
        i=i+1;   ram[i] = { `shl_is,          6'd8, `P5 };  // s5<<=8
193
        i=i+1;   ram[i] = { `orr,              `P5, `P4 };  // s4|=s5, pop s5
194
        i=i+1;   ram[i] = { `dat_is,       `STK_ER, `s6 };  // s6=reg addr
195
        i=i+1;   ram[i] = { `reg_rs,           `s6, `s5 };  // s5=(s6)
196
        i=i+1;   ram[i] = { `and,              `P5, `P4 };  // s4&=s5, pop s5
197
        i=i+1;   ram[i] = { `reg_w,            `P6, `s4 };  // (s6)=s4, pop s6
198
        i=i+1;   ram[i] = { `gto,              `P7, `__ };  // return to (s7), pop s7
199
 
200
 
201
        // sub : read 32 bit GPIO => s0, return to (s7)
202
        i='h920; ram[i] = { `dat_is,        `IO_LO, `s3 };  // s3=reg addr
203
        i=i+1;   ram[i] = { `reg_rs,           `P3, `s0 };  // s0=(s3), pop s3
204
        i=i+1;   ram[i] = { `dat_is,        `IO_HI, `s3 };  // s3=reg addr
205
        i=i+1;   ram[i] = { `reg_rh,           `P3, `P0 };  // s0=(s3), pop both
206
        i=i+1;   ram[i] = { `gto,              `P7, `__ };  // return, pop s7
207
 
208
 
209
        // sub : write s0 => 32 bit GPIO, return to (s7)
210
        i='h930; ram[i] = { `dat_is,        `IO_LO, `s3 };  // s3=reg addr
211
        i=i+1;   ram[i] = { `reg_w,            `P3, `s0 };  // (s3)=s0, pop s3
212
        i=i+1;   ram[i] = { `dat_is,        `IO_HI, `s3 };  // s3=reg addr
213
        i=i+1;   ram[i] = { `reg_wh,           `P3, `s0 };  // (s3)=s0, pop s3
214
        i=i+1;   ram[i] = { `gto,              `P7, `__ };  // return, pop s7
215
 
216
 
217
        // sub : push 32x to s1, return to (s7)
218
        // loop setup:
219
        i='h940; ram[i] = { `dat_is,         6'd31, `s1 };  // s1=31  // first push (& loop index)
220
        // loop
221
        i=i+1;   ram[i] = { `add_is,         -6'd1, `s1 };  // s1=s1-1
222
        i=i+1;   ram[i] = { `jmp_inz,        -6'd2, `s1 };  // (s1!=0) ? do again
223
        i=i+1;   ram[i] = { `gto,              `P7, `__ };  // return, pop s7
224
 
225
 
226
        // sub : pop 32x from s1, return to (s7)
227
        // loop setup:
228
        i='h950; ram[i] = { `dat_is,         6'd31, `s2 };  // s2=31
229
        // loop
230
        i=i+1;   ram[i] = { `pop,           8'b00000010 };  // pop s1
231
        i=i+1;   ram[i] = { `add_is,         -6'd1, `P2 };  // s2--
232
        i=i+1;   ram[i] = { `jmp_inlz,       -6'd3, `s2 };  // (s2>=0) ? do again
233
        i=i+1;   ram[i] = { `gto,              `P7, `P2 };  // return, pop s7 & s2
234
 
235
 
236
        end

powered by: WebSVN 2.1.0

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