Esempio n. 1
0
func New(assemblyFileName string, config *config.Config) (*Processor, error) {

	p := &Processor{
		&processor{
			done:                  false,
			instructionsFetched:   []string{},
			instructionsCompleted: []uint32{},
			dataLog:               map[uint32][]LogEvent{},

			branchHistoryTable:    map[uint32]uint32{},
			conditionalBranches:   0,
			unconditionalBranches: 0,
			mispredictedBranches:  0,
			noTakenBranches:       0,
			branchPredictorBits:   0,
			speculativeJumps:      0,

			instructionsMap: map[uint32]string{},
			instructionsSet: set.Init(),
			config:          config,

			programCounter:    0,
			registerMemory:    memory.New(config.RegistersMemorySize()),
			instructionMemory: memory.New(config.InstructionsMemorySize()),
			dataMemory:        memory.New(config.DataMemorySize()),
		},
	}

	logger.Print(config.ToString())

	// Instanciate functional units
	instructionsFinished := func() bool {
		return p.processor.done && p.InstructionsFetchedCounter() == p.InstructionsCompletedCounter() && p.SpeculativeJumps() == 0
	}
	p.processor.clockUnit = clock.New(config.CyclePeriod(), instructionsFinished)

	err := p.loadInstructionsMemory(assemblyFileName)
	if err != nil {
		return p, err
	}
	return p, nil
}