Skip to content

Commit

Permalink
Fixed RPi-related word-length bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZipCPU committed Oct 11, 2017
1 parent d97aacb commit 7976f34
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The ZipCPU repository contains a couple of very basic cabilities, some very nece
- It contains my first attempt at building an Assembler. Well, it does until I eventually remove it from the repository as unnecessary ...
- It also contains the source code for an example assembly level [debugger](sw/zipdbg). This will probably be replaced in time with an implementation of gdb, but it remains for the time being.

Prior to building within the ZipCPU repository directory, you need to make certain you have a number of prerequisites. These include: texinfo gcc-dev g++-dev flex bison libbison-dev verilator libgmp10 libgmp-dev libmpfr-dev libmpc-dev libelf-dev and ncurses-dev.
Prior to building within the ZipCPU repository directory, you need to make certain you have a number of prerequisites. These include: texinfo gcc-dev g++-dev flex bison libbison-dev verilator libgmp10 libgmp-dev libmpfr-dev libmpc-dev libelf-dev, bc, ctags, and ncurses-dev.

To build all of the above, type _make_ in the main repository directory. This will build the tools and place them into a [local install directory](sw/install/cross-tools/bin). Sadly, this process will currently fail about halfway through. To get past this, add the [install directory](sw/install/cross-tools/bin) to your path and restart. _make_ will then pick up where it left off and finish the task.

Expand Down
2 changes: 1 addition & 1 deletion sim/cpp/zipelf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ assert(n != 0);

// Now, let's read in our section ...
if (lseek(fd, phdr.p_offset, SEEK_SET) < 0) {
fprintf(stderr, "Could not seek to file position %08lx\n", phdr.p_offset);
fprintf(stderr, "Could not seek to file position %08lx\n", (unsigned long)phdr.p_offset);
perror("O/S Err:");
exit(EXIT_FAILURE);
} if (phdr.p_filesz > phdr.p_memsz)
Expand Down
29 changes: 15 additions & 14 deletions sim/verilator/mpy_tb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <time.h>
#include <unistd.h>
#include <assert.h>
#include <stdint.h>

#include <stdlib.h>
#include <ctype.h>
Expand Down Expand Up @@ -142,10 +143,10 @@ class CPUOPS_TB : public TESTB<Vcpuops> {
#define r_mpy_b_input VVAR(_genblk2__DOT__genblk2__DOT__genblk2__DOT__genblk1__DOT__r_mpy_b_input)
#define r_smpy_result VVAR(_genblk2__DOT__genblk2__DOT__genblk2__DOT__genblk1__DOT__r_smpy_result)
#define mpypipe VVAR(_genblk2__DOT__genblk2__DOT__genblk2__DOT__genblk1__DOT__mpypipe)
sprintf(s, "3,MPY[%08x][%08x][%016lx], P[%d]",
sprintf(s, "3,MPY[%08x][%08x][%016llx], P[%d]",
m_core->r_mpy_a_input,
m_core->r_mpy_b_input,
m_core->r_smpy_result,
(long long)m_core->r_smpy_result,
m_core->mpypipe);

#endif
Expand Down Expand Up @@ -210,7 +211,7 @@ class CPUOPS_TB : public TESTB<Vcpuops> {
// the CPU may need to do that if a jump is made and the pipeline needs
// to be cleared.
//
unsigned op(int op, int a, int b) {
uint32_t op(int op, int a, int b) {
// Make sure we start witht he core idle
if (m_core->o_valid)
clear_ops();
Expand All @@ -222,7 +223,7 @@ class CPUOPS_TB : public TESTB<Vcpuops> {
m_core->i_a = a;
m_core->i_b = b;

unsigned long now = m_tickcount;
uint64_t now = m_tickcount;

// Tick once to get it going
tick();
Expand All @@ -240,8 +241,8 @@ class CPUOPS_TB : public TESTB<Vcpuops> {
// be using. OPT_MULTIPLY is *supposed* to be equal to this
// number.
if((m_tickcount - now)!=OPT_MULTIPLY) {
printf("%ld ticks seen, %d ticks expected\n",
m_tickcount-now, OPT_MULTIPLY);
printf("%lld ticks seen, %d ticks expected\n",
(unsigned long long)(m_tickcount-now), OPT_MULTIPLY);
dbgdump();
printf("TEST-FAILURE!\n");
closetrace();
Expand All @@ -262,17 +263,17 @@ class CPUOPS_TB : public TESTB<Vcpuops> {
// any mismatch, an error message is printed and the test fails.
void mpy_test(int a, int b) {
const int OP_MPY = 0x08, OP_MPYSHI=0xb, OP_MPYUHI=0x0a;
long ia, ib, sv;
unsigned long ua, ub, uv;
int64_t ia, ib, sv;
uint64_t ua, ub, uv;
unsigned r, s, u;

clear_ops();

printf("MPY-TEST: 0x%08x x 0x%08x\n", a, b);

ia = (long)a; ib = (long)b; sv = ia * ib;
ua = ((unsigned long)a)&0x0ffffffffu;
ub = ((unsigned long)b)&0x0ffffffffu;
ua = ((uint64_t)a)&0x0ffffffffu;
ub = ((uint64_t)b)&0x0ffffffffu;
uv = ua * ub;

r = op(OP_MPY, a, b);
Expand All @@ -283,27 +284,27 @@ class CPUOPS_TB : public TESTB<Vcpuops> {
// Let's check our answers, and see if we got the right results
if ((r ^ sv)&0x0ffffffffu) {
printf("TEST FAILURE(MPY), MPY #1\n");
printf("Comparing 0x%08x to 0x%016lx\n", r, sv);
printf("Comparing 0x%08x to 0x%016llx\n", r, (long long)sv);
printf("TEST-FAILURE!\n");
closetrace();
exit(EXIT_FAILURE);
} if ((r ^ uv)&0x0ffffffffu) {
printf("TEST FAILURE(MPY), MPY #2\n");
printf("Comparing 0x%08x to 0x%016lx\n", r, uv);
printf("Comparing 0x%08x to 0x%016llx\n", r, (unsigned long long)uv);
printf("TEST-FAILURE!\n");
closetrace();
exit(EXIT_FAILURE);
}

if ((s^(sv>>32))&0x0ffffffffu) {
printf("TEST FAILURE(MPYSHI), MPY #3\n");
printf("Comparing 0x%08x to 0x%016lx\n", s, sv);
printf("Comparing 0x%08x to 0x%016llx\n", s, (long long)sv);
printf("TEST-FAILURE!\n");
closetrace();
exit(EXIT_FAILURE);
} if ((u^(uv>>32))&0x0ffffffffu) {
printf("TEST FAILURE(MPYUHI), MPY #4\n");
printf("Comparing 0x%08x to 0x%016lx\n", u, uv);
printf("Comparing 0x%08x to 0x%016llx\n", u, (unsigned long long)uv);
printf("TEST-FAILURE!\n");
closetrace();
exit(EXIT_FAILURE);
Expand Down
8 changes: 4 additions & 4 deletions sim/verilator/testb.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ template <class VA> class TESTB {
public:
VA *m_core;
VerilatedVcdC* m_trace;
unsigned long m_tickcount;
uint64_t m_tickcount;

TESTB(void) : m_trace(NULL), m_tickcount(0l) {
m_core = new VA;
Expand Down Expand Up @@ -92,14 +92,14 @@ template <class VA> class TESTB {
// logic depends. This forces that logic to be recalculated
// before the top of the clock.
eval();
if (m_trace) m_trace->dump(10*m_tickcount-2);
if (m_trace) m_trace->dump((uint64_t)(10*m_tickcount-2));
m_core->i_clk = 1;
eval();
if (m_trace) m_trace->dump(10*m_tickcount);
if (m_trace) m_trace->dump((uint64_t)(10*m_tickcount));
m_core->i_clk = 0;
eval();
if (m_trace) {
m_trace->dump(10*m_tickcount+5);
m_trace->dump((uint64_t)(10*m_tickcount+5));
m_trace->flush();
}
}
Expand Down

0 comments on commit 7976f34

Please sign in to comment.