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

Subversion Repositories hive

[/] [hive/] [trunk/] [v04.05/] [boot_code/] [boot_code_divide.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
        ----------------------------------------
37
        -- initialize: fill with default data --
38
        ----------------------------------------
39
        */
40
        integer i;
41
 
42
        initial begin
43
 
44
/*      // fill with nop (some compilers need this)
45
        for ( i = 0; i < CAPACITY; i = i+1 ) begin
46
                ram[i] = { `nop, `s0, `s0 };
47
        end
48
*/
49
 
50
        /*
51
        ---------------
52
        -- boot code --
53
        ---------------
54
        */
55
 
56
 
57
        /*
58
        ------------
59
        -- TEST 0 --
60
        ------------
61
        */
62
 
63
        // Divide - both inputs positive.
64
        // Thread 0 : Get input 32 bit GPIO 2x, divide, output 32 bit GPIO 2x.
65
        // Other threads : do nothing, loop forever
66
 
67
        ///////////////
68
        // clr space //
69
        ///////////////
70
 
71
        i='h0;   ram[i] = { `lit_u,            `__, `s1 };  // s1=addr
72
        i=i+1;   ram[i] =                      16'h0040  ;  // 
73
        i=i+1;   ram[i] = { `gto,              `P1, `__ };  // goto, pop s1 (addr)
74
        //
75
        i='h04;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
76
        i='h08;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
77
        i='h0c;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
78
        i='h10;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
79
        i='h14;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
80
        i='h18;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
81
        i='h1c;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
82
 
83
        ////////////////
84
        // intr space //
85
        ////////////////
86
 
87
        ///////////////////////
88
        // code & data space //
89
        ///////////////////////
90
 
91
        // read & write 32 bit GPIO data to & from s0 2x
92
        i='h40;  ram[i] = { `lit_u,            `__, `s3 };  // s3=addr
93
        i=i+1;   ram[i] =                      16'h0080  ;  // 
94
        i=i+1;   ram[i] = { `gsb,              `s3, `s3 };  // gsb
95
        i=i+1;   ram[i] = { `gsb,              `P3, `s3 };  // gsb, pop s3 (addr)
96
        // do s0/s1
97
        i=i+1;   ram[i] = { `lit_u,            `__, `s3 };  // s3=addr
98
        i=i+1;   ram[i] =                      16'h0090  ;  //
99
        i=i+1;   ram[i] = { `gsb,              `P3, `s7 };  // gsb, pop s3 (addr)
100
        // write s0 data to 32 bit GPIO 2x
101
        i=i+1;   ram[i] = { `lit_u,            `__, `s3 };  // s3=addr
102
        i=i+1;   ram[i] =                      16'h0070  ;  // 
103
        i=i+1;   ram[i] = { `gsb,              `s3, `s3 };  // gsb
104
        i=i+1;   ram[i] = { `pop,           8'b00000001 };  // pop s0
105
        i=i+1;   ram[i] = { `gsb,              `P3, `s3 };  // gsb, pop s3 (addr)
106
        // loop forever
107
        i=i+1;   ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
108
 
109
 
110
        // sub : read 32 bit GPIO => s0, return to (s3)
111
        i='h60;  ram[i] = { `dat_is,        `IO_LO, `s1 };  // s1=reg addr
112
        i=i+1;   ram[i] = { `reg_rs,           `P1, `s0 };  // s0=(s1), pop s1
113
        i=i+1;   ram[i] = { `dat_is,        `IO_HI, `s1 };  // s1=reg addr
114
        i=i+1;   ram[i] = { `reg_rh,           `P1, `P0 };  // s0=(s1), pop both
115
        i=i+1;   ram[i] = { `gto,              `P3, `__ };  // return, pop s3
116
 
117
 
118
        // sub : write s0 => 32 bit GPIO, return to (s3)
119
        i='h70;  ram[i] = { `dat_is,        `IO_LO, `s1 };  // s1=reg addr
120
        i=i+1;   ram[i] = { `reg_w,            `P1, `s0 };  // (s1)=s0, pop s1
121
        i=i+1;   ram[i] = { `dat_is,        `IO_HI, `s1 };  // s1=reg addr
122
        i=i+1;   ram[i] = { `reg_wh,           `P1, `s0 };  // (s1)=s0, pop s1
123
        i=i+1;   ram[i] = { `gto,              `P3, `__ };  // return, pop s3
124
 
125
 
126
        // sub : read & write 32 bit GPIO => s0, return to (s3)
127
        i='h80;  ram[i] = { `dat_is,        `IO_LO, `s1 };  // s1=reg addr
128
        i=i+1;   ram[i] = { `reg_rs,           `s1, `s0 };  // s0=(s1)
129
        i=i+1;   ram[i] = { `reg_w,            `P1, `s0 };  // (s1)=s0, pop s1
130
        i=i+1;   ram[i] = { `dat_is,        `IO_HI, `s1 };  // s1=reg addr
131
        i=i+1;   ram[i] = { `reg_rh,           `s1, `P0 };  // s0=(s1), pop s0
132
        i=i+1;   ram[i] = { `reg_wh,           `P1, `s0 };  // (s1)=s0, pop s1
133
        i=i+1;   ram[i] = { `gto,              `P3, `__ };  // return, pop s3
134
 
135
 
136
        // sub : unsigned divide & modulo remainder, return to (s7)
137
        //
138
        // algorithm: binary search
139
        //
140
        // s0 : N, D(top)/N(under) input, Q(top)/R(under) output
141
        // s1 : D
142
        // s2 : Q
143
        // s3 :
144
        // s4 :
145
        // s5 :
146
        // s6 : one-hot (& loop test)
147
        // s7 : sub return address
148
        //
149
        // (D=0)? is an error, return
150
        i='h90;  ram[i] = { `jmp_inz,         6'd1, `s0 };  // (s0!=0) ? skip return
151
        i=i+1;   ram[i] = { `gto,              `P7, `__ };  // return to (s7), pop s7
152
        // loop setup
153
        i=i+1;   ram[i] = { `cpy,              `P0, `s1 };  // s0=>s1 (s1=D, s0=N)
154
        i=i+1;   ram[i] = { `dat_is,          6'd0, `s2 };  // s2=0 (s2=init Q)
155
        i=i+1;   ram[i] = { `lzc,              `s1, `s6 };  // s6=lzc(s1)
156
        i=i+1;   ram[i] = { `pow,              `s6, `P6 };  // s6=1<<s6, pop s6 (s6=init OH)
157
        // loop start
158
        i=i+1;   ram[i] = { `add,              `s6, `P2 };  // s2+=s6 (s2=new trial Q)
159
        i=i+1;   ram[i] = { `mul,              `s2, `s1 };  // s1=s1*s2 (s1=D*Q)
160
        // jump start
161
        i=i+1;   ram[i] = { `jmp_inlu,   4'd1, `P1, `s0 };  // (s0>=s1) ? skip restore, pop s1 (N>=D*Q)
162
        i=i+1;   ram[i] = { `sub,              `s6, `P2 };  // s2-=s6 (s2=restored Q)
163
        // jump end
164
        i=i+1;   ram[i] = { `psu_i,          -6'd1, `P6 };  // s6>>=1 (new OH)
165
        i=i+1;   ram[i] = { `jmp_inz,        -6'd6, `s6 };  // (s6!=0) ? do again
166
        // loop end
167
        // calc remainder, move Q
168
        i=i+1;   ram[i] = { `mul,              `s2, `P1 };  // s1*=s2 (s1=D*Q)
169
        i=i+1;   ram[i] = { `sub,              `P1, `P0 };  // s0-=s1, pop both (s0=N-D*Q=R)
170
        i=i+1;   ram[i] = { `cpy,              `P2, `s0 };  // s0=s2, pop s2 (s0=Q)
171
        // return
172
        i=i+1;   ram[i] = { `gto,              `P7, `P6 };  // return to (s7), pop s7 & s6
173
        // end sub
174
 
175
 
176
        end

powered by: WebSVN 2.1.0

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