Skip to content

Commit

Permalink
Implemented all load/store instructions. Resolves Issue #4. FIXED a b…
Browse files Browse the repository at this point in the history
…ug in MOVT.
  • Loading branch information
snim2 committed Jun 28, 2015
1 parent 4321f62 commit 3a1d351
Show file tree
Hide file tree
Showing 32 changed files with 265 additions and 149 deletions.
88 changes: 50 additions & 38 deletions epiphany/execute_load_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
#-----------------------------------------------------------------------
def execute_ldstrpmd32(s, inst):
"""
address=RN;
address = RN;
EITHER:
RD=memory[address]; (LD)
RD = memory[address]; (LDR)
OR:
memory[address]=RD; (STR)
RN=RN +/- IMM11 << (log2(size_in_bits/8));
memory[address] = RD; (STR)
RN = RN +/- IMM11 << (log2(size_in_bits/8));
"""
address = s.rf[inst.rn]
address = (s.rf[inst.rn] - (inst.imm11 << inst.size) if inst.sub
else s.rf[inst.rn] + (inst.imm11 << inst.size))
if inst.s: # STORE
s.mem.write(address, 0b1 << inst.size, s.rf[inst.rd])
else: # LOAD
s.rf[inst.rd] = s.mem.read(address, 0b1 << inst.size)
imm = inst.imm11
if inst.sub: # Subtract
s.rf[inst.rn] = address - (imm << inst.size)
else:
s.rf[inst.rn] = address + (imm << inst.size)
s.rf[inst.rn] = address
s.pc += 4


#-----------------------------------------------------------------------
Expand All @@ -29,42 +27,56 @@ def make_ldstrdisp_executor(is16bit):
def ldstrdisp(s, inst):
"""
EITHER:
address= RN +/- IMM << (log2(size_in_bits/8)) ; (LD)
RD=memory[address];
address = RN +/- (IMM << (log2(size_in_bits/8))); (LDR)
RD = memory[address];
OR:
address = RN +/- IMM << (log2(size_in_bits/8)); (STR)
address = RN +/- (IMM << (log2(size_in_bits/8))); (STR)
memory[address] = RD;
"""
if is16bit:
inst.bits &= 0xffff
address = s.rf[inst.rn]
size = {0:1, 1:2, 2:4, 3:8}[inst.size] # Size in bytes.
imm = inst.imm11 << inst.size
address = (s.rf[inst.rn] - imm if inst.sub else s.rf[inst.rn] + imm)
if inst.s: # STORE
s.mem.write(address, 0b1 << inst.size, s.rf[inst.rd])
s.mem.write(address, size, s.rf[inst.rd])
else: # LOAD
s.rf[inst.rd] = s.mem.read(address, 0b1 << inst.size)
if inst.sub: # Subtract
s.rf[inst.rn] = address - (inst.imm11 << inst.size)
else:
s.rf[inst.rn] = address + (inst.imm11 << inst.size)
s.rf[inst.rd] = s.mem.read(address, size)
s.pc += 2 if is16bit else 4
return ldstrdisp


#-----------------------------------------------------------------------
# ldstrin16 and ldstrin32 - load or store with index.
#-----------------------------------------------------------------------
def make_ldstrind_executor(is16bit):
def ldstrind(s, inst):
raise NotImplementedError
return ldstrind


#-----------------------------------------------------------------------
# ldstrpm16 and ldstrpm32 - load or store post-modify.
#-----------------------------------------------------------------------
def make_ldstrpm_executor(is16bit):
def ldstrind(s, inst):
raise NotImplementedError
return ldstrind
def make_ldstrindpm_executor(is16bit, postmodify):
def ldstr(s, inst):
"""
EITHER:
address = RN +/- RM ; (LDR)
RD = memory[address];
For double data loads, only even RD registers can be used.
RN = RN +/- RM; (with postmodify)
OR:
address = RN +/- RM ; (STR)
memory[address] = RD;
RN = RN +/- RM; (with postmodify)
"""
if is16bit:
inst.bits &= 0xffff
address = (s.rf[inst.rn] - s.rf[inst.rm] if inst.sub20 == 1
else s.rf[inst.rn] + s.rf[inst.rm])
size = {0:1, 1:2, 2:4, 3:8}[inst.size] # Size in bytes.
print 'ADDRESS:', address, 'SIZE:', size
if inst.s: # STORE
s.mem.write(address, size, s.rf[inst.rd])
else: # LOAD
s.rf[inst.rd] = s.mem.read(address, size)
if postmodify:
s.rf[inst.rn] = address
s.pc += 2 if is16bit else 4
return ldstr


#-----------------------------------------------------------------------
Expand Down Expand Up @@ -93,19 +105,19 @@ def testset32(s, inst):
RD = 0;
}
"""
address = (s.rf[inst.rn] + s.rf[inst.rm] if inst.sub == 0
else s.rf[inst.rn] - s.rf[inst.rm])
address = (s.rf[inst.rn] - s.rf[inst.rm] if inst.sub20
else s.rf[inst.rn] + s.rf[inst.rm])
if address <= 0x00100000:
fail_msg = """testset32 has failed to write to address %s.
The absolute address used for the test and set instruction must be located
within the on-chip local memory and must be greater than 0x00100000 (2^20).
""" % str(hex(address))
raise ValueError(fail_msg)
size = {0:1, 2:4, 3:8, 4:16}[inst.size] # Size in bytes.
size = {0:1, 1:2, 2:4, 3:8}[inst.size] # Size in bytes.
value = s.mem.read(address, size)
if value == 0:
if value:
s.rf[inst.rd] = value
else:
s.mem.write(address, size, s.rf[inst.rd])
s.rf[inst.rd] = 0
else:
s.rf[inst.rd] = value
s.pc += 4
4 changes: 1 addition & 3 deletions epiphany/execute_mov.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def execute_movimm(s, inst):
"""
if is16bit:
inst.bits &= 0xffff
imm = inst.imm16
rd = inst.rd
s.rf[rd] = (rd | (imm << 16)) if is_t else imm
s.rf[inst.rd] = (s.rf[inst.rd] | (inst.imm16 << 16)) if is_t else inst.imm16
s.pc += 2 if is16bit else 4
return execute_movimm

Expand Down
4 changes: 4 additions & 0 deletions epiphany/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def size(self):
def sub(self):
return (self.bits >> 24) & 1

@property
def sub20(self):
return (self.bits >> 20) & 1

@property
def s(self):
return (self.bits >> 4) & 1
Expand Down
8 changes: 4 additions & 4 deletions epiphany/isa.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@
execute_ldstrpmd32 = execute_load_store.execute_ldstrpmd32
execute_ldstrdisp16 = execute_load_store.make_ldstrdisp_executor(True)
execute_ldstrdisp32 = execute_load_store.make_ldstrdisp_executor(False)
execute_ldstrind16 = execute_load_store.make_ldstrind_executor(True)
execute_ldstrind32 = execute_load_store.make_ldstrind_executor(False)
execute_ldstrpm16 = execute_load_store.make_ldstrpm_executor(True)
execute_ldstrpm32 = execute_load_store.make_ldstrpm_executor(False)
execute_ldstrind16 = execute_load_store.make_ldstrindpm_executor(True, False)
execute_ldstrind32 = execute_load_store.make_ldstrindpm_executor(False, False)
execute_ldstrpm16 = execute_load_store.make_ldstrindpm_executor(True, True)
execute_ldstrpm32 = execute_load_store.make_ldstrindpm_executor(False, True)
execute_testset32 = execute_load_store.testset32

#-----------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions epiphany/test/asm/ldr_disp.S
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "epiphany-macros.h"
SET_UP
ldrb r31, [r2] ; loads byte
ldr r0, [r2, #1] ; loads word
mov r1, %low(0x00100000)
movt r1, %high(0x00100000)
ldr r0, [r1, #1] ; loads word
TEAR_DOWN
Binary file modified epiphany/test/asm/ldr_disp.elf
Binary file not shown.
6 changes: 6 additions & 0 deletions epiphany/test/asm/ldr_disp_pm.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "epiphany-macros.h"
SET_UP
mov r1, %low(0x00100000)
movt r1, %high(0x00100000)
ldr r0, [r1], #1 ; loads double, updates r2
TEAR_DOWN
Binary file added epiphany/test/asm/ldr_disp_pm.elf
Binary file not shown.
6 changes: 4 additions & 2 deletions epiphany/test/asm/ldr_index.S
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "epiphany-macros.h"
SET_UP
ldrb r31, [r2, r1] ; loads byte
ldr r0, [r2, r1] ; loads word
mov r1, %low(0x00100004)
movt r1, %high(0x00100004)
mov r2, #0
ldr r0, [r1,+r2] ; loads word
TEAR_DOWN
Binary file modified epiphany/test/asm/ldr_index.elf
Binary file not shown.
8 changes: 8 additions & 0 deletions epiphany/test/asm/ldr_pm.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "epiphany-macros.h"
SET_UP
mov r1, %low(0x80002)
movt r1, %high(0x80002)
mov r2, %low(0x80002)
movt r2, %high(0x80002)
ldr r0, [r1], r2 ; loads word, updates r1
TEAR_DOWN
Binary file added epiphany/test/asm/ldr_pm.elf
Binary file not shown.
5 changes: 0 additions & 5 deletions epiphany/test/asm/ldrdpm.S

This file was deleted.

Binary file removed epiphany/test/asm/ldrdpm.elf
Binary file not shown.
5 changes: 0 additions & 5 deletions epiphany/test/asm/ldrpm.S

This file was deleted.

Binary file removed epiphany/test/asm/ldrpm.elf
Binary file not shown.
7 changes: 5 additions & 2 deletions epiphany/test/asm/str_disp.S
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "epiphany-macros.h"
SET_UP
strb r31, [r2, #1] ;stores byte to addr in r2
str r0, [r2, #0x4] ;stores word to addr in r2
mov r0, %low(0xFFFFFFFF)
movt r0, %high(0xFFFFFFFF)
mov r1, %low(0x00100000)
movt r1, %high(0x00100000)
str r0, [r1, #0x1]
TEAR_DOWN
Binary file modified epiphany/test/asm/str_disp.elf
Binary file not shown.
8 changes: 8 additions & 0 deletions epiphany/test/asm/str_disp_pm.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "epiphany-macros.h"
SET_UP
mov r0, %low(0xFFFFFFFF)
movt r0, %high(0xFFFFFFFF)
mov r1, %low(0x00100000)
movt r1, %high(0x00100000)
str r0, [r1], #1
TEAR_DOWN
Binary file added epiphany/test/asm/str_disp_pm.elf
Binary file not shown.
5 changes: 0 additions & 5 deletions epiphany/test/asm/str_dpm.S

This file was deleted.

Binary file removed epiphany/test/asm/str_dpm.elf
Binary file not shown.
8 changes: 6 additions & 2 deletions epiphany/test/asm/str_index.S
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "epiphany-macros.h"
SET_UP
strb r31, [r2, r1] ;stores byte to addr in r2
str r0, [r2, r1] ;stores word to addr in r2
mov r0, %low(0xFFFFFFFF)
movt r0, %high(0xFFFFFFFF)
mov r1, %low(0x00100004)
movt r1, %high(0x00100004)
mov r2, #0
str r0, [r1, +r2] ; stores word to addr in r0
TEAR_DOWN
Binary file modified epiphany/test/asm/str_index.elf
Binary file not shown.
8 changes: 6 additions & 2 deletions epiphany/test/asm/str_pm.S
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "epiphany-macros.h"
SET_UP
strh r31, [r2], r1 ; stores short to addr in r2
strd r0, [r2], r3 ; stores double to addr in r2
mov r0, %low(0xFFFFFFFF)
movt r0, %high(0xFFFFFFFF)
mov r1, %low(0x00100000)
movt r1, %high(0x00100000)
mov r2, #4
str r0, [r1], r2
TEAR_DOWN
Binary file modified epiphany/test/asm/str_pm.elf
Binary file not shown.
2 changes: 1 addition & 1 deletion epiphany/test/asm/testset.S
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SET_UP
mov r0, #0xFFFF
mov r1, %low(0x00100000) ; sets all 32 bits
movt r1, %high(0x00100000) ; sets upper 16-bits
mov r2, #0x3 ; why is this not 0x4?
mov r2, #0x4
testset r0, [r2,+r1] ; test-set memory location: 0x00100004
sub r0, r0, #0 ; check result
TEAR_DOWN
Binary file modified epiphany/test/asm/testset.elf
Binary file not shown.
Loading

0 comments on commit 3a1d351

Please sign in to comment.