updated before 3rd class

This commit is contained in:
Wang Chen
2021-04-15 14:47:40 +08:00
parent 5dbe7364e2
commit a9a5c2fdb3
19 changed files with 607 additions and 589 deletions

View File

@@ -1,5 +1,10 @@
/*
* a0 --> a
* a1 --> b
* c <-- a0
*/
int foo(int a, int b)
{
int sum = a + b;
return sum;
int c = a + b;
return c;
}

View File

@@ -1,23 +1,28 @@
# ASM call C
.text # Define beginning of text section
.global _start # Define entry _start
.global foo # foo is a C function defined in test.c
_start:
la sp, stack_end # prepare stack for calling functions
li a0, 1
li a1, 2
call foo
stop:
j stop # Infinite loop to stop execution
stack_start:
.rept 10
.word 0
.endr
stack_end:
.end # End of file
# ASM call C
.text # Define beginning of text section
.global _start # Define entry _start
.global foo # foo is a C function defined in test.c
_start:
la sp, stack_end # prepare stack for calling functions
# RISC-V uses a0 ~ a7 to transfer parameters
li a0, 1
li a1, 2
call foo
# RISC-V uses a0 & a1 to transfer return value
# check value of a0
stop:
j stop # Infinite loop to stop execution
nop # just for demo effect
stack_start:
.rept 10
.word 0
.endr
stack_end:
.end # End of file

View File

@@ -1,11 +1,19 @@
int foo(int a, int b)
{
int sum;
asm volatile(
"nop\n"
int c;
asm volatile (
"add %[sum], %[add1], %[add2]"
:[sum]"=r"(c)
:[add1]"r"(a), [add2]"r"(b)
);
/*
asm volatile (
"add %0, %1, %2"
:"=r"(sum)
:"=r"(c)
:"r"(a), "r"(b)
);
return sum;
*/
return c;
}

View File

@@ -14,6 +14,8 @@ _start:
stop:
j stop # Infinite loop to stop execution
nop # just for demo effect
stack_start:
.rept 10
.word 0

View File

@@ -1,5 +1,5 @@
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -march=rv32ima -mabi=ilp32 -g -Wall
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none

View File

@@ -1,5 +1,5 @@
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -march=rv32ima -mabi=ilp32 -g -Wall
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none

View File

@@ -1,5 +1,5 @@
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -march=rv32ima -mabi=ilp32 -g -Wall
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none

View File

@@ -1,5 +1,5 @@
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -march=rv32ima -mabi=ilp32 -g -Wall
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none

View File

@@ -1,5 +1,5 @@
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -march=rv32ima -mabi=ilp32 -g -Wall
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none

View File

@@ -1,5 +1,5 @@
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -march=rv32ima -mabi=ilp32 -g -Wall
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none

View File

@@ -1,5 +1,5 @@
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -march=rv32ima -mabi=ilp32 -g -Wall
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none

View File

@@ -1,5 +1,5 @@
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -march=rv32ima -mabi=ilp32 -g -Wall
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none

View File

@@ -1,5 +1,5 @@
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -march=rv32ima -mabi=ilp32 -g -Wall
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none

View File

@@ -1,5 +1,5 @@
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -march=rv32ima -mabi=ilp32 -g -Wall
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none

View File

@@ -1,5 +1,5 @@
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -march=rv32ima -mabi=ilp32 -g -Wall
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none

View File

@@ -1,5 +1,5 @@
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -march=rv32ima -mabi=ilp32 -g -Wall
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none

View File

@@ -1,7 +1,7 @@
SYSCALL = y
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -mcmodel=medany -march=rv32ima -mabi=ilp32 -g -Wall
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall
ifeq ($(SYSCALL), y)
CFLAGS += -D CONFIG_SYSCALL

File diff suppressed because it is too large Load Diff

Binary file not shown.