forked from plctlab/riscv-operating-system-mooc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
665 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
EXEC = test | ||
|
||
SRC = ${EXEC}.s | ||
|
||
GDBINIT = ../gdbinit | ||
|
||
CROSS_COMPILE = riscv64-unknown-elf- | ||
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall | ||
|
||
QEMU = qemu-system-riscv32 | ||
QFLAGS = -nographic -smp 1 -machine virt -bios none | ||
|
||
GDB = gdb-multiarch | ||
CC = ${CROSS_COMPILE}gcc | ||
OBJCOPY = ${CROSS_COMPILE}objcopy | ||
OBJDUMP = ${CROSS_COMPILE}objdump | ||
|
||
.DEFAULT_GOAL := all | ||
all: | ||
@${CC} ${CFLAGS} ${SRC} -Ttext=0x80000000 -o ${EXEC}.elf | ||
@${OBJCOPY} -O binary ${EXEC}.elf ${EXEC}.bin | ||
|
||
.PHONY : run | ||
run: all | ||
@echo "Press Ctrl-A and then X to exit QEMU" | ||
@echo "------------------------------------" | ||
@echo "No output, please run 'make debug' to see details" | ||
@${QEMU} ${QFLAGS} -kernel ./${EXEC}.elf | ||
|
||
.PHONY : debug | ||
debug: all | ||
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU" | ||
@echo "-------------------------------------------------------" | ||
@${QEMU} ${QFLAGS} -kernel ${EXEC}.elf -s -S & | ||
@${GDB} ${EXEC}.elf -q -x ${GDBINIT} | ||
|
||
.PHONY : code | ||
code: all | ||
@${OBJDUMP} -S ${EXEC}.elf | less | ||
|
||
.PHONY : hex | ||
hex: all | ||
@hexdump -C ${EXEC}.bin | ||
|
||
.PHONY : clean | ||
clean: | ||
rm -rf *.o *.bin *.elf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.text | ||
.global _start | ||
_start: | ||
li a0, 1 | ||
li a1, 2 | ||
li a2, 3 | ||
add a3, a0, a1 | ||
sub a4, a3, a2 | ||
j _start | ||
.end # End of file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
EXEC = test | ||
|
||
SRC = ${EXEC}.s | ||
|
||
GDBINIT = ./gdbinit | ||
|
||
CROSS_COMPILE = riscv64-unknown-elf- | ||
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall | ||
|
||
QEMU = qemu-system-riscv32 | ||
QFLAGS = -nographic -smp 1 -machine virt -bios none | ||
|
||
GDB = gdb-multiarch | ||
CC = ${CROSS_COMPILE}gcc | ||
OBJCOPY = ${CROSS_COMPILE}objcopy | ||
OBJDUMP = ${CROSS_COMPILE}objdump | ||
|
||
.DEFAULT_GOAL := all | ||
all: | ||
@${CC} ${CFLAGS} ${SRC} -Ttext=0x80000000 -o ${EXEC}.elf | ||
@${OBJCOPY} -O binary ${EXEC}.elf ${EXEC}.bin | ||
|
||
.PHONY : run | ||
run: all | ||
@echo "Press Ctrl-A and then X to exit QEMU" | ||
@echo "------------------------------------" | ||
@echo "No output, please run 'make debug' to see details" | ||
@${QEMU} ${QFLAGS} -kernel ./${EXEC}.elf | ||
|
||
.PHONY : debug | ||
debug: all | ||
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU" | ||
@echo "-------------------------------------------------------" | ||
@${QEMU} ${QFLAGS} -kernel ${EXEC}.elf -s -S & | ||
@${GDB} ${EXEC}.elf -q -x ${GDBINIT} | ||
|
||
.PHONY : code | ||
code: all | ||
@${OBJDUMP} -S ${EXEC}.elf | less | ||
|
||
.PHONY : hex | ||
hex: all | ||
@hexdump -C ${EXEC}.bin | ||
|
||
.PHONY : clean | ||
clean: | ||
rm -rf *.o *.bin *.elf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
display/z $a0 | ||
display/z $a1 | ||
display/z $a2 | ||
display/z $a3 | ||
display/z $a4 | ||
display/z $a5 | ||
display/z $a6 | ||
|
||
set disassemble-next-line on | ||
b _start | ||
target remote : 1234 | ||
c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.text | ||
.global _start | ||
_start: | ||
li a0, 1 | ||
li a1, 2 | ||
li a2, 3 | ||
li a3, 4 | ||
add a4, a0, a1 | ||
add a5, a2, a3 | ||
sub a6, a4, a5 | ||
j _start | ||
.end # End of file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
EXEC = test | ||
|
||
SRC = ${EXEC}.s | ||
|
||
GDBINIT = ./gdbinit | ||
|
||
CROSS_COMPILE = riscv64-unknown-elf- | ||
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall | ||
|
||
QEMU = qemu-system-riscv32 | ||
QFLAGS = -nographic -smp 1 -machine virt -bios none | ||
|
||
GDB = gdb-multiarch | ||
CC = ${CROSS_COMPILE}gcc | ||
OBJCOPY = ${CROSS_COMPILE}objcopy | ||
OBJDUMP = ${CROSS_COMPILE}objdump | ||
|
||
.DEFAULT_GOAL := all | ||
all: | ||
@${CC} ${CFLAGS} ${SRC} -Ttext=0x80000000 -o ${EXEC}.elf | ||
@${OBJCOPY} -O binary ${EXEC}.elf ${EXEC}.bin | ||
|
||
.PHONY : run | ||
run: all | ||
@echo "Press Ctrl-A and then X to exit QEMU" | ||
@echo "------------------------------------" | ||
@echo "No output, please run 'make debug' to see details" | ||
@${QEMU} ${QFLAGS} -kernel ./${EXEC}.elf | ||
|
||
.PHONY : debug | ||
debug: all | ||
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU" | ||
@echo "-------------------------------------------------------" | ||
@${QEMU} ${QFLAGS} -kernel ${EXEC}.elf -s -S & | ||
@${GDB} ${EXEC}.elf -q -x ${GDBINIT} | ||
|
||
.PHONY : code | ||
code: all | ||
@${OBJDUMP} -S ${EXEC}.elf | less | ||
|
||
.PHONY : hex | ||
hex: all | ||
@hexdump -C ${EXEC}.bin | ||
|
||
.PHONY : clean | ||
clean: | ||
rm -rf *.o *.bin *.elf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
display/z $a0 | ||
display/z $a1 | ||
display/z $a2 | ||
|
||
set disassemble-next-line on | ||
b _start | ||
target remote : 1234 | ||
c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
unsigned int a = 0x87654321; | ||
unsigned int low = a & 0xffff; | ||
unsigned int high = a >> 16; | ||
printf("low: %x, high: %x\n", low, high); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.text | ||
.global _start | ||
_start: | ||
li a0, 0x87654321 | ||
slli a1, a0, 16 | ||
srli a1, a1, 16 | ||
srli a2, a0, 16 | ||
j _start | ||
.end # End of file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
EXEC = test | ||
|
||
SRC = ${EXEC}.s | ||
|
||
GDBINIT = ./gdbinit | ||
|
||
CROSS_COMPILE = riscv64-unknown-elf- | ||
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall | ||
|
||
QEMU = qemu-system-riscv32 | ||
QFLAGS = -nographic -smp 1 -machine virt -bios none | ||
|
||
GDB = gdb-multiarch | ||
CC = ${CROSS_COMPILE}gcc | ||
OBJCOPY = ${CROSS_COMPILE}objcopy | ||
OBJDUMP = ${CROSS_COMPILE}objdump | ||
|
||
.DEFAULT_GOAL := all | ||
all: | ||
@${CC} ${CFLAGS} ${SRC} -Ttext=0x80000000 -o ${EXEC}.elf | ||
@${OBJCOPY} -O binary ${EXEC}.elf ${EXEC}.bin | ||
|
||
.PHONY : run | ||
run: all | ||
@echo "Press Ctrl-A and then X to exit QEMU" | ||
@echo "------------------------------------" | ||
@echo "No output, please run 'make debug' to see details" | ||
@${QEMU} ${QFLAGS} -kernel ./${EXEC}.elf | ||
|
||
.PHONY : debug | ||
debug: all | ||
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU" | ||
@echo "-------------------------------------------------------" | ||
@${QEMU} ${QFLAGS} -kernel ${EXEC}.elf -s -S & | ||
@${GDB} ${EXEC}.elf -q -x ${GDBINIT} | ||
|
||
.PHONY : code | ||
code: all | ||
@${OBJDUMP} -S ${EXEC}.elf | less | ||
|
||
.PHONY : hex | ||
hex: all | ||
@hexdump -C ${EXEC}.bin | ||
|
||
.PHONY : clean | ||
clean: | ||
rm -rf *.o *.bin *.elf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
display/z $a0 | ||
display/z $a1 | ||
display/z $t0 | ||
|
||
set disassemble-next-line on | ||
b _start | ||
target remote : 1234 | ||
c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.data | ||
array: .word 0x11111111, 0xffffffff | ||
|
||
.text | ||
.global _start | ||
_start: | ||
la t0, array # load address of array into t0 | ||
lw a0, 0(t0) # load first element of array into a0 (i) | ||
lw a1, 4(t0) # load second element of array into a1 (j) | ||
j _start # Jump to _start | ||
.end # End of file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
EXEC = test | ||
|
||
SRC = ${EXEC}.s | ||
|
||
GDBINIT = ./gdbinit | ||
|
||
CROSS_COMPILE = riscv64-unknown-elf- | ||
CFLAGS = -nostdlib -fno-builtin -march=rv32ima -mabi=ilp32 -g -Wall | ||
|
||
QEMU = qemu-system-riscv32 | ||
QFLAGS = -nographic -smp 1 -machine virt -bios none | ||
|
||
GDB = gdb-multiarch | ||
CC = ${CROSS_COMPILE}gcc | ||
OBJCOPY = ${CROSS_COMPILE}objcopy | ||
OBJDUMP = ${CROSS_COMPILE}objdump | ||
|
||
.DEFAULT_GOAL := all | ||
all: | ||
@${CC} ${CFLAGS} ${SRC} -Ttext=0x80000000 -o ${EXEC}.elf | ||
@${OBJCOPY} -O binary ${EXEC}.elf ${EXEC}.bin | ||
|
||
.PHONY : run | ||
run: all | ||
@echo "Press Ctrl-A and then X to exit QEMU" | ||
@echo "------------------------------------" | ||
@echo "No output, please run 'make debug' to see details" | ||
@${QEMU} ${QFLAGS} -kernel ./${EXEC}.elf | ||
|
||
.PHONY : debug | ||
debug: all | ||
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU" | ||
@echo "-------------------------------------------------------" | ||
@${QEMU} ${QFLAGS} -kernel ${EXEC}.elf -s -S & | ||
@${GDB} ${EXEC}.elf -q -x ${GDBINIT} | ||
|
||
.PHONY : code | ||
code: all | ||
@${OBJDUMP} -S ${EXEC}.elf | less | ||
|
||
.PHONY : hex | ||
hex: all | ||
@hexdump -C ${EXEC}.bin | ||
|
||
.PHONY : clean | ||
clean: | ||
rm -rf *.o *.bin *.elf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
display/z $a0 | ||
display/z $a1 | ||
display/z $t0 | ||
|
||
set disassemble-next-line on | ||
b _start | ||
target remote : 1234 | ||
c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.data | ||
s: .word 0, 0 | ||
|
||
.macro set_struct st | ||
la t0, \st | ||
sw a0, 0(t0) | ||
sw a1, 4(t0) | ||
.endm | ||
|
||
.macro get_struct st | ||
la t0, \st | ||
lw a0, 0(t0) | ||
lw a1, 4(t0) | ||
.endm | ||
|
||
.text | ||
.global _start | ||
_start: | ||
li a0, 0x12345678 # a = 0x12345678 | ||
li a1, 0x87654321 # b = 0x87654321 | ||
set_struct s | ||
li a0, 0 | ||
li a1, 0 | ||
get_struct s | ||
j _start | ||
.end |
Oops, something went wrong.