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

Subversion Repositories hive

[/] [hive/] [trunk/] [v04.05/] [boot_code/] [boot_code_sqrt.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, `s0, `s0 };
46
        end
47
*/
48
 
49
        /*
50
        ---------------
51
        -- boot code --
52
        ---------------
53
        */
54
 
55
 
56
        /*
57
        ------------
58
        -- TEST 0 --
59
        ------------
60
        */
61
 
62
        // Square root
63
        // Thread 0 : Get input 32 bit GPIO, calculate square root, output 32 bit GPIO.
64
        // Other threads : do nothing, loop forever
65
 
66
        ///////////////
67
        // clr space //
68
        ///////////////
69
 
70
        i='h0;   ram[i] = { `lit_u,            `__, `s1 };  // s1=addr
71
        i=i+1;   ram[i] =                      16'h0040  ;  // 
72
        i=i+1;   ram[i] = { `gto,              `P1, `__ };  // goto, pop s1 (addr)
73
        //
74
        i='h04;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
75
        i='h08;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
76
        i='h0c;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
77
        i='h10;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
78
        i='h14;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
79
        i='h18;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
80
        i='h1c;  ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
81
 
82
        ////////////////
83
        // intr space //
84
        ////////////////
85
 
86
        ///////////////////////
87
        // code & data space //
88
        ///////////////////////
89
 
90
        // read & write 32 bit GPIO data to & from s0
91
        i='h40;  ram[i] = { `lit_u,            `__, `s3 };  // s3=addr
92
        i=i+1;   ram[i] =                      16'h0080  ;  // 
93
        i=i+1;   ram[i] = { `gsb,              `P3, `s3 };  // gsb, pop s3 (addr)
94
        // do s0=sqrt(s0)
95
        i=i+1;   ram[i] = { `lit_u,            `__, `s3 };  // s3=addr
96
        i=i+1;   ram[i] =                      16'h0090  ;  //
97
        i=i+1;   ram[i] = { `gsb,              `P3, `s7 };  // gsb, pop s3 (addr)
98
        // write s0 data to 32 bit GPIO
99
        i=i+1;   ram[i] = { `lit_u,            `__, `s3 };  // s3=addr
100
        i=i+1;   ram[i] =                      16'h0070  ;  // 
101
        i=i+1;   ram[i] = { `gsb,              `P3, `s3 };  // gsb, pop s3 (addr)
102
        // loop forever
103
        i=i+1;   ram[i] = { `jmp_ie,    -4'd1, `s0, `s0 };  // loop forever
104
 
105
 
106
        // sub : read 32 bit GPIO => s0, return to (s3)
107
        i='h60;  ram[i] = { `dat_is,        `IO_LO, `s1 };  // s1=reg addr
108
        i=i+1;   ram[i] = { `reg_rs,           `P1, `s0 };  // s0=(s1), pop s1
109
        i=i+1;   ram[i] = { `dat_is,        `IO_HI, `s1 };  // s1=reg addr
110
        i=i+1;   ram[i] = { `reg_rh,           `P1, `P0 };  // s0=(s1), pop both
111
        i=i+1;   ram[i] = { `gto,              `P3, `__ };  // return, pop s3
112
 
113
 
114
        // sub : write s0 => 32 bit GPIO, return to (s3)
115
        i='h70;  ram[i] = { `dat_is,        `IO_LO, `s1 };  // s1=reg addr
116
        i=i+1;   ram[i] = { `reg_w,            `P1, `s0 };  // (s1)=s0, pop s1
117
        i=i+1;   ram[i] = { `dat_is,        `IO_HI, `s1 };  // s1=reg addr
118
        i=i+1;   ram[i] = { `reg_wh,           `P1, `s0 };  // (s1)=s0, pop s1
119
        i=i+1;   ram[i] = { `gto,              `P3, `__ };  // return, pop s3
120
 
121
 
122
        // sub : read & write 32 bit GPIO => s0, return to (s3)
123
        i='h80;  ram[i] = { `dat_is,        `IO_LO, `s1 };  // s1=reg addr
124
        i=i+1;   ram[i] = { `reg_rs,           `s1, `s0 };  // s0=(s1)
125
        i=i+1;   ram[i] = { `reg_w,            `P1, `s0 };  // (s1)=s0, pop s1
126
        i=i+1;   ram[i] = { `dat_is,        `IO_HI, `s1 };  // s1=reg addr
127
        i=i+1;   ram[i] = { `reg_rh,           `s1, `P0 };  // s0=(s1), pop s0
128
        i=i+1;   ram[i] = { `reg_wh,           `P1, `s0 };  // (s1)=s0, pop s1
129
        i=i+1;   ram[i] = { `gto,              `P3, `__ };  // return, pop s3
130
 
131
 
132
        // sub : s0=sqrt(s0), return to (s7)
133
        //
134
        // input is unsigned 32 integer
135
        // output is unsigned 16.16 integer
136
        //
137
        // algorithm: binary search
138
        // iterate 32 times
139
        //
140
        // s0 : input (x), output (Q)
141
        // s1 : running q
142
        // s2 : temp: q^2 + q
143
        // s3 : 
144
        // s4 : 
145
        // s5 : 
146
        // s6 : one-hot (& loop test)
147
        // s7 : sub return address
148
        //
149
        // loop setup
150
        i='h90;  ram[i] = { `dat_is,          6'd0, `s1 };  // s1=0 (init Q)
151
        i=i+1;   ram[i] = { `psu_i,         6'd31, `s6 };  // s6 MSB=1 (init OH)
152
        // loop start
153
        i=i+1;   ram[i] = { `add,              `s6, `P1 };  // s1+=s6
154
        i=i+1;   ram[i] = { `mul_xu,           `s1, `s1 };  // s1=s1*s1 (square, integer portion)
155
        // jump start
156
        i=i+1;   ram[i] = { `jmp_ilu,    4'd1, `s0, `P1 };  // (s1<s0) ? jump 1  pop s1 (skip restore)
157
        i=i+1;   ram[i] = { `sub,              `s6, `P1 };  // s1-=s6 (restore)
158
        // jump end
159
        i=i+1;   ram[i] = { `psu_i,          -6'd1, `P6 };  // s6>>=1 (new OH)
160
        i=i+1;   ram[i] = { `jmp_inz,        -6'd6, `s6 };  // (s6!=0) ? do again
161
        // loop end
162
        i=i+1;   ram[i] = { `mul_xu,           `s1, `s1 };  // s1=s1*s1 (square, integer portion)
163
        i=i+1;   ram[i] = { `sub,              `P1, `P0 };  // s0-=s1, pop s1 : x -= q^2
164
        i=i+1;   ram[i] = { `add,              `s1, `P0 };  // s0+=s1 : Q = q + x - q^2
165
        i=i+1;   ram[i] = { `mul,              `s1, `s1 };  // s1=s1*s1 (square, decimal portion) : (q>>n)^2
166
        i=i+1;   ram[i] = { `cpy,              `P1, `s2 };  // s2=s1, move
167
        i=i+1;   ram[i] = { `add_xu,           `P1, `P2 };  // s2+=s1 (carry out, integer portion), pop s1 : int[q>>n + (q>>n)^2]
168
        i=i+1;   ram[i] = { `sub,              `P2, `P0 };  // s0+=s2, pop s2 : Q = q + (x - q^2) - int[q>>n + (q>>n)^2]
169
        i=i+1;   ram[i] = { `gto,              `P7, `P6 };  // return, pop s7 & s6
170
        // end sub
171
 
172
        end

powered by: WebSVN 2.1.0

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