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

Subversion Repositories igor

[/] [igor/] [trunk/] [simulator/] [microcode.c] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 atypic
#include <sys/mman.h>
2
#include <sys/stat.h>
3
#include <fcntl.h>
4
#include <stdio.h>
5
#include <stdlib.h>
6
#include <unistd.h>
7
#include <err.h>
8
 
9
#include "types.h"
10
#include "microcode.h"
11
 
12
#define INSTR_SZ 6 // byte
13
 
14
static int microcodefd;
15
static uint8_t *microcodebuffer;
16
static size_t microcodesize;
17
 
18
int
19
microcode_init(const char *path)
20
{
21
        int fd;
22
        struct stat sb;
23
 
24
        if ((fd = open(path, O_RDONLY)) == -1)
25
                return 0;
26
 
27
        if (fstat(fd, &sb) == -1) {
28
                close(fd);
29
                return 0;
30
        }
31
 
32
        microcodebuffer = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
33
        if (microcodebuffer == MAP_FAILED) {
34
                close(fd);
35
                return 0;
36
        }
37
        microcodesize = sb.st_size;
38
        if ((microcodesize % INSTR_SZ) != 0) {
39
                close(fd);
40
                warnx("microcode size not dividable by INSTR_SZ (%d)", INSTR_SZ);
41
                return 0;
42
        }
43
 
44
        printf("Microcode size: %d\n", (int)microcodesize/INSTR_SZ);
45
        /*
46
        for (int i = 0; i < microcodesize/4; i++) {
47
                printf("inst: 0x%x\n", microcode_fetch_instr(i));
48
        }
49
        */
50
        microcodefd = fd;
51
 
52
        return 1;
53
}
54
 
55
uint64_t
56
microcode_fetch_instr(reg_t place)
57
{
58
        int byteplace, i;
59
        uint64_t val;
60
 
61
        if (place < 0 || place >= (microcodesize/INSTR_SZ))
62
                errx(1, "Trying to access out of bounds microcode: 0x%x", place);
63
        byteplace = place*INSTR_SZ;
64
        //printf("place: %d, byteplace: %d\n", place, byteplace);
65
 
66
        val = 0;
67
        for (i = 0; i < INSTR_SZ; i++) {
68
                val = (val << 8) | (microcodebuffer[byteplace+i]&0xFF);
69
        }
70
 
71
        return val;
72
}
73
 
74
size_t
75
microcode_size(void)
76
{
77
        return microcodesize/INSTR_SZ;
78
}

powered by: WebSVN 2.1.0

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