Compare commits
	
		
			2 commits
		
	
	
		
			005ad4e987
			...
			b65b33da25
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							 | 
						b65b33da25 | ||
| 
							 | 
						1a31859a31 | 
					 5 changed files with 20 additions and 3 deletions
				
			
		| 
						 | 
					@ -24,6 +24,7 @@ CFLAGS += -fno-common#			# Do not use common sections
 | 
				
			||||||
CFLAGS += -march=rv64i#			# Use RV64I ISA, i.e., integer only
 | 
					CFLAGS += -march=rv64i#			# Use RV64I ISA, i.e., integer only
 | 
				
			||||||
CFLAGS += -mabi=lp64#			# Use LP64 ABI, i.e., 64-bit longs and pointers, 32-bit ints
 | 
					CFLAGS += -mabi=lp64#			# Use LP64 ABI, i.e., 64-bit longs and pointers, 32-bit ints
 | 
				
			||||||
CFLAGS += -Os#					# Optimize for size
 | 
					CFLAGS += -Os#					# Optimize for size
 | 
				
			||||||
 | 
					CFLAGS += -Wall -Wunused -O2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LDFLAGS += -T link.ld			# Use the linker script
 | 
					LDFLAGS += -T link.ld			# Use the linker script
 | 
				
			||||||
LDFLAGS += --no-dynamic-linker
 | 
					LDFLAGS += --no-dynamic-linker
 | 
				
			||||||
| 
						 | 
					@ -61,7 +62,7 @@ all: $(OBJS)
 | 
				
			||||||
	@echo "CC $<"
 | 
						@echo "CC $<"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Run the binary in QEMU
 | 
					# Run the binary in QEMU
 | 
				
			||||||
run: all	
 | 
					run: all
 | 
				
			||||||
	@echo "To exit: Ctrl+A, X"
 | 
						@echo "To exit: Ctrl+A, X"
 | 
				
			||||||
	@$(QEMU) $(QEMU_FLAGS) -bios $(TARGET)
 | 
						@$(QEMU) $(QEMU_FLAGS) -bios $(TARGET)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								link.ld
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								link.ld
									
										
									
									
									
								
							| 
						 | 
					@ -5,7 +5,7 @@ MEMORY {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SECTIONS {
 | 
					SECTIONS {
 | 
				
			||||||
    .text : {
 | 
					    .text : {
 | 
				
			||||||
        main.o(.text.*)
 | 
					        *(.text)
 | 
				
			||||||
        *(.text)
 | 
					        *(.text)
 | 
				
			||||||
        . = ALIGN(4);
 | 
					        . = ALIGN(4);
 | 
				
			||||||
    } > DRAM
 | 
					    } > DRAM
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								main.s
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								main.s
									
										
									
									
									
								
							| 
						 | 
					@ -25,7 +25,7 @@ test_routine:
 | 
				
			||||||
    ret
 | 
					    ret
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Prints "hello" manually
 | 
					# Prints "hello" manually
 | 
				
			||||||
hello_manual:	
 | 
					hello_manual:
 | 
				
			||||||
    addi a0, x0, 0x68
 | 
					    addi a0, x0, 0x68
 | 
				
			||||||
	li a1, 0x10000000
 | 
						li a1, 0x10000000
 | 
				
			||||||
	sb a0, (a1) # 'h'
 | 
						sb a0, (a1) # 'h'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										1
									
								
								square.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								square.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					int square(int, int);
 | 
				
			||||||
							
								
								
									
										15
									
								
								square.s
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								square.s
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,15 @@
 | 
				
			||||||
 | 
					square:
 | 
				
			||||||
 | 
					        addi    sp,sp,-32
 | 
				
			||||||
 | 
					        sd      ra,24(sp)
 | 
				
			||||||
 | 
					        sd      s0,16(sp)
 | 
				
			||||||
 | 
					        addi    s0,sp,32
 | 
				
			||||||
 | 
					        mv      a5,a0
 | 
				
			||||||
 | 
					        sw      a5,-20(s0)
 | 
				
			||||||
 | 
					        lw      a5,-20(s0)
 | 
				
			||||||
 | 
					        mulw    a5,a5,a5
 | 
				
			||||||
 | 
					        sext.w  a5,a5
 | 
				
			||||||
 | 
					        mv      a0,a5
 | 
				
			||||||
 | 
					        ld      ra,24(sp)
 | 
				
			||||||
 | 
					        ld      s0,16(sp)
 | 
				
			||||||
 | 
					        addi    sp,sp,32
 | 
				
			||||||
 | 
					        jr      ra
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue