From b70cdd13c45c61ec836f8054f09b5c82bee6e071 Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Thu, 18 Mar 2021 08:35:23 -0700 Subject: [PATCH] Add partial support for 8-bit loads We're big-endian. when we have this in memory: 00 01 02 03 And we need the first byte, we load the first 16-bit word: 0x0001 The first byte is then in the upper part of the word, and requires a right shift by 8. So any load into an 8-bit typed container needs to shift stuff. So far, stores from/to the stack are exempted, they always load/store full 16-bit words. And a few othe rminor things. Like string null terminators. And escaped characters in character literals. Can you believe it's spelled 'literal', with a single t? Me neither. --- cpu/cpu.vhdl | 6 +++++- dsp/main.c | 6 ++++-- tools/cc.ebnf | 2 +- tools/cc.py | 23 +++++++++++++++++++---- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/cpu/cpu.vhdl b/cpu/cpu.vhdl index b5c96ed..4afd788 100644 --- a/cpu/cpu.vhdl +++ b/cpu/cpu.vhdl @@ -121,7 +121,11 @@ begin end if; regn_0 := to_integer(unsigned(load_reg(3 downto 0))); - reg_d(regn_0) <= mem_in; + if load_addr(0) = '1' then -- 8-bit load + reg_d(regn_0) <= mem_in(7 downto 0) & x"00"; + else + reg_d(regn_0) <= mem_in; + end if; when BRANCH => inst := x"0000"; -- NOP reg_d(14) <= std_logic_vector(unsigned(reg_q(14)) + 2); diff --git a/dsp/main.c b/dsp/main.c index c09b058..8c75a08 100644 --- a/dsp/main.c +++ b/dsp/main.c @@ -9,11 +9,11 @@ void init() { } int main() { - led0->output = 37; init(); + led0->output = 42; + while(1) { - led0->output = 42; uint8_t c = uart_read(uart0); uint16_t period; if (c == 'c') { @@ -44,6 +44,8 @@ int main() { period = 791; // B4, 493.88 Hz, maybe uart_writen(uart0, "B4\r\n", 4); led0->output = 64; + } else { + led0->output = 37; } square0->period = period; diff --git a/tools/cc.ebnf b/tools/cc.ebnf index 997eef9..b3ae672 100644 --- a/tools/cc.ebnf +++ b/tools/cc.ebnf @@ -145,7 +145,7 @@ struct_field: type IDENTIFIER sized_array* ";" IDENTIFIER: /[_a-zA-Z]\w*/ COMMENT: /\/\/.*/ HEX_LITTERAL: /0x[a-fA-F0-9]+/ -CHARACTER: /'[^']'/ +CHARACTER: /'([^']|\\n|\\r|\\0|\\t)'/ %import common.WS diff --git a/tools/cc.py b/tools/cc.py index 3b76be7..df5ca23 100644 --- a/tools/cc.py +++ b/tools/cc.py @@ -366,7 +366,7 @@ class CcTransform(lark.visitors.Transformer): mul = _binary_op(lambda a, b: a*b) shl = _binary_op(lambda a, b: a<