Skip to content

Commit

Permalink
updated before 3rd class
Browse files Browse the repository at this point in the history
  • Loading branch information
unicornx committed Apr 15, 2021
1 parent 5dbe736 commit a9a5c2f
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 43 deletions.
9 changes: 7 additions & 2 deletions code/asm/asm2c/test.c
Original file line number Diff line number Diff line change
@@ -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;
}
51 changes: 28 additions & 23 deletions code/asm/asm2c/test.s
Original file line number Diff line number Diff line change
@@ -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
18 changes: 13 additions & 5 deletions code/asm/c2asm/test.c
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 2 additions & 0 deletions code/asm/c2asm/test.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ _start:
stop:
j stop # Infinite loop to stop execution

nop # just for demo effect

stack_start:
.rept 10
.word 0
Expand Down
2 changes: 1 addition & 1 deletion code/asm/rule.mk
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/os/00-bootstrap/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/os/01-helloRVOS/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/os/02-memanagement/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/os/03-contextswitch/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/os/04-multitask/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/os/05-traps/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/os/06-interrupts/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/os/07-hwtimer/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/os/08-preemptive/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/os/09-lock/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/os/10-swtimer/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/os/11-syscall/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Binary file renamed slides/exercises.pdf → exercises.pdf
Binary file not shown.
Binary file modified slides/ch05-assemble-programming.pdf
Binary file not shown.

0 comments on commit a9a5c2f

Please sign in to comment.