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

Subversion Repositories raptor64

[/] [raptor64/] [trunk/] [software/] [c64/] [source/] [Register.c] - Blame information for rev 43

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

Line No. Rev Author Line
1 37 robfinch
// ============================================================================
2
// (C) 2012 Robert Finch
3
// All Rights Reserved.
4
// robfinch<remove>@opencores.org
5
//
6
// C64 - Raptor64 'C' derived language compiler
7
//  - 64 bit CPU
8
//
9
// This source file is free software: you can redistribute it and/or modify 
10
// it under the terms of the GNU Lesser General Public License as published 
11
// by the Free Software Foundation, either version 3 of the License, or     
12
// (at your option) any later version.                                      
13
//                                                                          
14
// This source file is distributed in the hope that it will be useful,      
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
17
// GNU General Public License for more details.                             
18
//                                                                          
19
// You should have received a copy of the GNU General Public License        
20
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
21
//                                                                          
22
// ============================================================================
23
//
24
#include <stdio.h>
25
#include "c.h"
26
#include "expr.h"
27
#include "Statement.h"
28
#include "gen.h"
29
#include "cglbdec.h"
30
 
31
int tmpregs[] = {3,4,5,6,7,8,9,10};
32
int regstack[8];
33
int rsp=7;
34
int regmask=0;
35
 
36
void initRegStack()
37
{
38
        for (rsp=0; rsp < 8; rsp=rsp+1)
39
                regstack[rsp] = tmpregs[rsp];
40
        rsp = 0;
41
}
42
 
43
void GenerateTempRegPush(int reg, int rmode)
44
{
45
        AMODE *ap1;
46
    ap1 = allocAmode();
47
    ap1->preg = reg;
48
    ap1->mode = rmode;
49
        GenerateTriadic(op_subui,0,makereg(30),makereg(30),make_immed(8));
50
        GenerateTriadic(op_sw,0,ap1,make_indirect(30),NULL);
51
}
52
 
53
void GenerateTempRegPop(int reg, int rmode)
54
{
55
        AMODE *ap1;
56
    ap1 = allocAmode();
57
    ap1->preg = reg;
58
    ap1->mode = rmode;
59
        GenerateTriadic(op_lw,0,ap1,make_indirect(30),NULL);
60
        GenerateTriadic(op_addui,0,makereg(30),makereg(30),make_immed(8));
61
}
62
 
63
void initstack()
64
{
65
        initRegStack();
66
}
67
 
68
AMODE *GetTempRegister()
69
{
70
        AMODE *ap;
71
    ap = allocAmode();
72
    ap->mode = am_reg;
73
    ap->preg = PopFromRstk();
74
    ap->deep = rsp;
75
    return ap;
76
}
77
 
78
int PopFromRstk()
79
{
80
        int reg = 0;
81
 
82
        if (rsp < 8) {
83
                reg = regstack[rsp];
84
                rsp = rsp + 1;
85
                regmask |= (1 << (reg));
86
        }
87
        else
88
                error(ERR_EXPRTOOCOMPLEX);
89
        return reg;
90
}
91
 
92
void PushOnRstk(int reg)
93
{
94
        if (rsp > 0) {
95
                rsp = rsp - 1;
96
                regstack[rsp] = reg;
97
                regmask &= ~(1 << (reg));
98
        }
99
        else
100
                printf("DIAG - register stack underflow.\r\n");
101
}
102
 
103
int SaveTempRegs()
104
{
105
        if (regmask != 0) {
106
                GenerateTriadic(op_subui,0,makereg(30),makereg(30),make_immed(popcnt(regmask)*8));
107
                GenerateTriadic(op_sm,0,make_indirect(30),make_mask(regmask),NULL);
108
        }
109
        return regmask;
110
}
111
 
112
void RestoreTempRegs(int rgmask)
113
{
114
        if (rgmask != 0) {
115
                GenerateTriadic(op_lm,0,make_indirect(30),make_mask(rgmask),NULL);
116
                GenerateTriadic(op_addui,0,makereg(30),makereg(30),make_immed(popcnt(rgmask)*8));
117
        }
118
}
119
 
120
void ReleaseTempRegister(struct amode *ap)
121
{
122
        if (ap==NULL) {
123
                printf("DIAG - NULL pointer in ReleaseTempRegister\r\n");
124
                return;
125
        }
126
        if( ap->mode == am_immed || ap->mode == am_direct )
127
        return;         // no registers used
128
        if(ap->preg < 11 && ap->preg >= 3)
129
                PushOnRstk(ap->preg);
130
}
131
 
132
 

powered by: WebSVN 2.1.0

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