// -*- c++ -*-
//
// main.cc:
//
#include <iostream>
#include "sim.h"
#include "memory.h"
#include "loader.h"
#include "cache.h"
#include "cpu.h"
#include "mips.h"

using namespace std;

int main(int argc, char *argv[])
{
    if (argc < 2) {
        cerr << "usage: " << argv[0] << " <program name>" << endl;
        return 1;
    }

    loader ld(argv[1]);
    memory mem;
    cpu cpu;
    cache icache;
    cache dcache;

    ld >> mem;				// program loading onto memory

    icache.connect_memory(&mem);	// connect I-cache and memory
    dcache.connect_memory(&mem);	// connect D-cache and memory

    cpu.connect_icache(&icache);	// connect CPU and I-cache
    cpu.connect_dcache(&dcache);	// connect CPU and D-cache

    // allocate stack area
    mem.alloc(0x7fff8000, 0x4000);	// initially 16KB allocated
    sim_addr init_sp = 0x7fff8000 + 0x4000 - 4;

    cpu.execute(ld.entry_address(), init_sp);

    return 0;
}

// end of main.cc