2 * avr-sim: An atmel AVR simulator
3 * Copyright (C) 2008 Tom Haber
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "RuntimeException.h"
30 intVectors
.resize( intVectorsSize
);
34 std::for_each( hardware
.begin(), hardware
.end(), Delete
<Hardware
>() );
40 std::list
<Hardware
*>::iterator it
;
41 for(it
= hardware
.begin(); it
!= hardware
.end(); ++it
) {
48 bool Bus::isHoldingCPU() {
51 std::list
<Hardware
*>::const_iterator it
;
52 for(it
= hardware
.begin(); it
!= hardware
.end(); ++it
) {
53 holding
= holding
|| (*it
)->isHoldingCPU();
59 void Bus::addInterrupt(unsigned int vector
, unsigned int address
,
61 if( vector
>= intVectorsSize
)
62 throw util::RuntimeException(
63 util::format("Tried to add not existing interrupt %d") % vector
);
65 intVectors
[vector
] = IntVect( address
, name
);
68 void Bus::claimInterrupt(unsigned int vector
, Hardware
*hw
) {
69 if( vector
>= intVectorsSize
)
70 throw util::RuntimeException(
71 util::format("Hardware tried to claim not existing interrupt %d") % vector
);
73 if( intVectors
[vector
].hw
!= 0 )
74 throw util::RuntimeException(
75 util::format("Hardware tried to claim already claimed interrupt %d") % vector
);
77 intVectors
[vector
].hw
= hw
;
81 void Bus::beforeInvokeInterrupt(unsigned int vector
) {
82 clearInterrupt(vector
);
84 if( intVectors
[vector
].hw
!= 0 )
85 intVectors
[vector
].hw
->beforeInvokeInterrupt(vector
);