Skip to content

Commit

Permalink
ADD: add codes
Browse files Browse the repository at this point in the history
  • Loading branch information
T-K-233 committed Sep 4, 2023
0 parents commit e392609
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
riscv64-unknown-elf-gcc.exe -E -o ./main.i ./main.c

riscv64-unknown-elf-gcc.exe -S -o ./main.S ./main.c

riscv64-unknown-elf-gcc.exe -c -o ./main.o ./main.c


riscv64-unknown-elf-objdump.exe -h ./main.o


riscv64-unknown-elf-gcc.exe -nostdlib -T scratchpad.ld -o ./main.elf ./main.o
66 changes: 66 additions & 0 deletions main.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
.file "main.c"
.option nopic
.attribute arch, "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
.attribute unaligned_access, 0
.attribute stack_align, 16
.text
.align 1
.type simpleDelay, @function
simpleDelay:
addi sp,sp,-32
sd s0,24(sp)
addi s0,sp,32
sw zero,-20(s0)
j .L2
.L3:
#APP
# 16 "./main.c" 1
nop
# 0 "" 2
#NO_APP
lw a5,-20(s0)
addiw a5,a5,1
sw a5,-20(s0)
.L2:
lw a5,-20(s0)
sext.w a4,a5
li a5,999424
addi a5,a5,575
ble a4,a5,.L3
nop
nop
ld s0,24(sp)
addi sp,sp,32
jr ra
.size simpleDelay, .-simpleDelay
.align 1
.globl main
.type main, @function
main:
addi sp,sp,-16
sd ra,8(sp)
sd s0,0(sp)
addi s0,sp,16
li a5,268500992
li a4,1
sw a4,0(a5)
.L5:
li a5,268500992
lw a5,0(a5)
sext.w a4,a5
li a5,268500992
ori a4,a4,1
sext.w a4,a4
sw a4,0(a5)
call simpleDelay
li a5,268500992
lw a5,0(a5)
sext.w a4,a5
li a5,268500992
andi a4,a4,-2
sext.w a4,a4
sw a4,0(a5)
call simpleDelay
j .L5
.size main, .-main
.ident "GCC: (SiFive GCC-Metal 10.2.0-2020.12.8) 10.2.0"
30 changes: 30 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#define SET_BITS(REG, BIT) ((REG) |= (BIT))
#define CLEAR_BITS(REG, BIT) ((REG) &= ~(BIT))

#define GPIOA_BASE 0x10010000U

#define GPIO_PIN_0 0b0001U
#define GPIO_PIN_1 0b0001U
#define GPIO_PIN_2 0b0001U
#define GPIO_PIN_3 0b0001U




static inline void simpleDelay() {
for (int i=0; i<1000000; i+=1) {
__asm__("nop");
}
}

int main() {
*(unsigned int volatile *)(GPIOA_BASE + 0x00U) = GPIO_PIN_0;

while (1) {
SET_BITS(*(unsigned int volatile *)(GPIOA_BASE + 0x00U), GPIO_PIN_0);
simpleDelay();

CLEAR_BITS(*(unsigned int volatile *)(GPIOA_BASE + 0x00U), GPIO_PIN_0);
simpleDelay();
}
}
Binary file added main.elf
Binary file not shown.
22 changes: 22 additions & 0 deletions main.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 1 "./main.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "./main.c"
# 14 "./main.c"
static inline void simpleDelay() {
for (int i=0; i<1000000; i+=1) {
__asm__("nop");
}
}

int main() {
*(unsigned int volatile *)(0x10010000U + 0x00U) = 0b0001U;

while (1) {
((*(unsigned int volatile *)(0x10010000U + 0x00U)) |= (0b0001U));
simpleDelay();

((*(unsigned int volatile *)(0x10010000U + 0x00U)) &= ~(0b0001U));
simpleDelay();
}
}
Binary file added main.o
Binary file not shown.
12 changes: 12 additions & 0 deletions scratchpad.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

ENTRY(main)

MEMORY {
SCRATCHPAD(rwx): ORIGIN = 0x08000000, LENGTH = 4K
}

SECTIONS {
.text : {
*(.text)
}> SCRATCHPAD
}

0 comments on commit e392609

Please sign in to comment.