From b9294c0bd1c96ddf17ad1de04e1acfb430083b12 Mon Sep 17 00:00:00 2001 From: PurplePower <60787289+PurplePower@users.noreply.github.com> Date: Tue, 23 Jan 2024 21:35:09 +0800 Subject: [PATCH] added c source files back --- lab2/csrc/CMakeLists.txt | 2 +- lab2/csrc/simpletest.c | 12 ++++++++++ lab3/csrc/CMakeLists.txt | 2 +- lab3/csrc/hazard.S | 48 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 lab2/csrc/simpletest.c create mode 100644 lab3/csrc/hazard.S diff --git a/lab2/csrc/CMakeLists.txt b/lab2/csrc/CMakeLists.txt index ee07b00..0cf3160 100644 --- a/lab2/csrc/CMakeLists.txt +++ b/lab2/csrc/CMakeLists.txt @@ -5,7 +5,7 @@ project(yatcpu-programs C CXX ASM) # Setting variables set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 --target=riscv32-unknown-elf -march=rv32i -mabi=ilp32") set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -O0 --target=riscv32-unknown-elf -march=rv32i -mabi=ilp32") -set(C_PROGRAMS tetris hello fibonacci quicksort paging tetris_mmu) +set(C_PROGRAMS tetris hello fibonacci quicksort paging tetris_mmu simpletest) set(ASM_PROGRAMS mmio sb) set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/link.lds) set(LINKER_FLAGS -T ${LINKER_SCRIPT}) diff --git a/lab2/csrc/simpletest.c b/lab2/csrc/simpletest.c new file mode 100644 index 0000000..3993a24 --- /dev/null +++ b/lab2/csrc/simpletest.c @@ -0,0 +1,12 @@ + +extern void enable_interrupt(); + +void trap_handler(void *epc, unsigned int cause){ + *((int*)0x4) = 0x2022; +} + +int main(){ + *((int*)0x4) = 0xDEADBEEF; + enable_interrupt(); + for(;;); +} \ No newline at end of file diff --git a/lab3/csrc/CMakeLists.txt b/lab3/csrc/CMakeLists.txt index ee07b00..5512cea 100644 --- a/lab3/csrc/CMakeLists.txt +++ b/lab3/csrc/CMakeLists.txt @@ -6,7 +6,7 @@ project(yatcpu-programs C CXX ASM) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 --target=riscv32-unknown-elf -march=rv32i -mabi=ilp32") set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -O0 --target=riscv32-unknown-elf -march=rv32i -mabi=ilp32") set(C_PROGRAMS tetris hello fibonacci quicksort paging tetris_mmu) -set(ASM_PROGRAMS mmio sb) +set(ASM_PROGRAMS mmio sb hazard) set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/link.lds) set(LINKER_FLAGS -T ${LINKER_SCRIPT}) set(OBJCOPY_ARGS -O binary -j .text -j .data) diff --git a/lab3/csrc/hazard.S b/lab3/csrc/hazard.S new file mode 100644 index 0000000..e17ed33 --- /dev/null +++ b/lab3/csrc/hazard.S @@ -0,0 +1,48 @@ +# Copyright 2022 Canbin Huang +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.globl _start +_start: + csrr a0, cycle + + addi t0, zero, 1 + sub t1, zero, t0 + and t2, t0, t1 + sw t2, 4(zero) + j skip1 + or t2, t0, t1 + xor t2, t0, t1 + +skip1: + addi t1, t2, 1 + add t2, t1, t2 + and t2, t1, t2 + lw t2, 2(t2) + or t3, t1, t2 + blt t2, t3, skip2 + or t3, t0, t0 + xor t3, t0, t1 + +skip2: + addi t4, zero, 3 + bne t3, t4, skip1 + sw t3, 8(zero) + auipc t4, 0 + jalr t4, 8(t4) + jalr t4, 4(t4) + csrr a1, cycle + sub ra, a1, a0 + +loop: + j loop \ No newline at end of file