mirror of
https://github.com/lcbcFoo/ReonV.git
synced 2025-04-18 18:44:43 -04:00
Initial code for posix
This commit is contained in:
parent
d0f8961346
commit
c9f61c9d40
13 changed files with 164 additions and 45 deletions
|
@ -16,7 +16,7 @@ CROSS=../../rv32i/rv32i-gnu/bin/riscv32-unknown-elf-
|
|||
DESIGN=leon3-digilent-nexys4ddr
|
||||
|
||||
# Leon3 designs might use a prom.srec to load boot code.
|
||||
# This is the binary to .srec converter this makefile will look for.
|
||||
# This is the binary to .srec converter this makefile will look for.
|
||||
# In need check this one under GPL: http://www.s-record.com/
|
||||
BIN2SREC=../../srec/bin2srec
|
||||
|
||||
|
@ -26,6 +26,7 @@ OBJCOPY=objcopy
|
|||
CFLAGS=-nostdlib
|
||||
OBJCPFLAGS=-O binary -j .text
|
||||
LD_SCRIPT=ld_script
|
||||
WRAP=-Wl,-wrap,exit,-wrap,open,-wrap,close,-wrap,write,-wrap,read
|
||||
|
||||
#####################################################################
|
||||
#
|
||||
|
@ -33,20 +34,23 @@ LD_SCRIPT=ld_script
|
|||
#
|
||||
#####################################################################
|
||||
# Compiled binary linked with reonv_crt0
|
||||
%.out : %.c reonv_crt0.o
|
||||
%.out : %.c reonv_crt0.o posix.o
|
||||
${CROSS}${CC} -static -march=rv32i -T${LD_SCRIPT} $< -o $@
|
||||
|
||||
# Targets for .S.
|
||||
# Targets for .S.
|
||||
# .o is for linking programs (i.e. crt0.S)
|
||||
# .hex is for other assembly programs
|
||||
# .hex is for other assembly programs
|
||||
%.hex : %.S
|
||||
${CROSS}$(AS) $< -o $@
|
||||
|
||||
%.o : %.S
|
||||
${CROSS}${CC} -c $< -o $@
|
||||
posix.o : posix.c
|
||||
${CROSS}${CC} -c $< -o $@ -nostdlib ${WRAP}
|
||||
|
||||
reonv_crt0.o : reonv_crt0.S
|
||||
${CROSS}${CC} -c $< -o $@ -nostdlib ${WRAP}
|
||||
|
||||
# Target raw binary to avoid grmon2 errors saying this is not SPARC '-'
|
||||
%.bin : %.out
|
||||
%.bin : %.out
|
||||
${CROSS}$(OBJCOPY) $(OBJCPFLAGS) $< $@
|
||||
|
||||
%.bin : %.hex
|
||||
|
@ -57,10 +61,10 @@ ahbrom.vhd : ahbrom boot_code.bin
|
|||
./ahbrom boot_code.bin ahbrom.vhd
|
||||
|
||||
bootcode : ahbrom.vhd
|
||||
cp ahbrom.vhd ../designs/${DESIGN}/ahbrom.vhd -f
|
||||
cp ahbrom.vhd ../designs/${DESIGN}/ahbrom.vhd -f
|
||||
@echo "Generated ahbrom.vhd and placed at ../../designs/${DESIGN}"
|
||||
|
||||
ahbrom : ../bin/ahbrom.c
|
||||
ahbrom : ../bin/ahbrom.c
|
||||
gcc ../bin/ahbrom.c -o ahbrom
|
||||
|
||||
clean:
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
.file "boot_code.S"
|
||||
.equ RAMSTART, 0x40000000
|
||||
.equ RAMSIZE, 0x08000000
|
||||
|
||||
.text
|
||||
.org 0x0
|
||||
|
||||
__boot_code:
|
||||
#li sp,RAMSTART+RAMSIZE-32
|
||||
li a5,RAMSTART
|
||||
jalr a5
|
||||
nop
|
||||
|
|
Binary file not shown.
|
@ -55,9 +55,10 @@ SECTIONS
|
|||
.text :
|
||||
{
|
||||
/*
|
||||
* Forced minimal ctr0 to be the first code
|
||||
* Forced minimal ctr0 to be the first code
|
||||
*/
|
||||
reonv_crt0.o
|
||||
posix.o
|
||||
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
|
||||
*(.text.exit .text.exit.*)
|
||||
*(.text.startup .text.startup.*)
|
||||
|
@ -236,4 +237,3 @@ SECTIONS
|
|||
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
|
||||
/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
|
||||
}
|
||||
|
||||
|
|
BIN
riscv/main.bin
BIN
riscv/main.bin
Binary file not shown.
|
@ -2,7 +2,7 @@ int mul();
|
|||
int fib();
|
||||
#include <stdio.h>
|
||||
int main(){
|
||||
int i = 19;
|
||||
int i = 3;
|
||||
int count = 0;
|
||||
|
||||
// Multiplies i by 4
|
||||
|
|
82
riscv/posix.c
Normal file
82
riscv/posix.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include "reonv.h"
|
||||
|
||||
#undef errno
|
||||
|
||||
extern int errno;
|
||||
char *__env[1] = { 0 };
|
||||
char **environ = __env;
|
||||
|
||||
#define SYS_RESTART 0x0
|
||||
#define SYS_EXIT 0x1
|
||||
#define SYS_FORK 0x2
|
||||
#define SYS_READ 0x3
|
||||
#define SYS_WRITE 0x4
|
||||
#define SYS_OPEN 0x5
|
||||
#define SYS_CLOSE 0x6
|
||||
#define SYS_WAIT 0x7
|
||||
#define SYS_CREAT 0x8
|
||||
#define SYS_LINK 0x9
|
||||
#define SYS_UNLINK 0xA
|
||||
#define SYS_EXECVE 0xB
|
||||
#define SYS_CHDIR 0xC
|
||||
#define SYS_MKNOD 0xE
|
||||
#define SYS_CHMOD 0xF
|
||||
#define SYS_LCHOW 0x10
|
||||
#define SYS_STAT 0x12
|
||||
#define SYS_LSEEK 0x13
|
||||
#define SYS_GETPID 0x14
|
||||
#define SYS_ALARM 0x1B
|
||||
#define SYS_FSTAT 0x6C
|
||||
#define SYS_KILL 0x25
|
||||
#define SYS_TIMES 0x2B
|
||||
#define SYS_BRK 0x2D
|
||||
#define SYS_GETTIMEOFDAY 0x4E
|
||||
#define SYS_SLEEP 0xA2
|
||||
#define SYS_ACCESS 0x21
|
||||
|
||||
|
||||
static unsigned *out_mem = (unsigned *)OUT_MEM_BEGIN;
|
||||
static unsigned current_position = 0;
|
||||
|
||||
// exit application
|
||||
extern void _exit_c( int status ) {
|
||||
__asm("ebreak");
|
||||
}
|
||||
|
||||
// Read from a file descriptor.
|
||||
extern int _read_c( int fd, char *buffer, int len ) {
|
||||
volatile register int r0 asm("t0") = fd;
|
||||
volatile register char* r1 asm("t1") = buffer;
|
||||
volatile register int r2 asm("t2") = len;
|
||||
volatile register unsigned r7 asm("a0") = SYS_READ;
|
||||
return r0;
|
||||
}
|
||||
|
||||
// Write to a file descriptor.
|
||||
extern int _write_c( int fd, char *buffer, int len ) {
|
||||
volatile register int r0 asm("t0") = fd;
|
||||
volatile register char* r1 asm("t1") = buffer;
|
||||
volatile register int r2 asm("t2") = len;
|
||||
volatile register unsigned r7 asm("a0") = SYS_WRITE;
|
||||
return r0;
|
||||
}
|
||||
|
||||
// Open a file.
|
||||
extern int _open_c( const char *path, int flags, int mode ) {
|
||||
volatile register const char* r0 asm("t0") = path;
|
||||
volatile register int r1 asm("t1") = flags;
|
||||
volatile register int r2 asm("t2") = mode;
|
||||
volatile register unsigned r7 asm("a0") = SYS_OPEN;
|
||||
return *(int*) r0;
|
||||
}
|
||||
|
||||
// Close a file descriptor.
|
||||
extern int _close_c( int fd ) {
|
||||
volatile register int r0 asm("t0") = fd;
|
||||
volatile register unsigned r7 asm("a0") = SYS_CLOSE;
|
||||
return r0;
|
||||
}
|
BIN
riscv/posix.o
Normal file
BIN
riscv/posix.o
Normal file
Binary file not shown.
4
riscv/reonv.h
Normal file
4
riscv/reonv.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
#define RAM_START 0x40000000
|
||||
#define RAM_SIZE 0x08000000
|
||||
#define SP_START 0X43FFFFF0
|
||||
#define OUT_MEM_BEGIN 0x45000000
|
|
@ -1,29 +1,74 @@
|
|||
#include "reonv.h"
|
||||
|
||||
.file "reonv_crt0.S"
|
||||
.extern _start
|
||||
.extern main
|
||||
.extern _exit
|
||||
.extern _open
|
||||
.extern _close
|
||||
.extern _write
|
||||
.extern _read
|
||||
|
||||
|
||||
.globl __reonv_startup
|
||||
.type "__reonv_startup",@function
|
||||
.type "exit",@function
|
||||
.type "open",@function
|
||||
.type "close",@function
|
||||
.type "write",@function
|
||||
.type "read",@function
|
||||
|
||||
# Build minimal crt0 in future
|
||||
.org 0x0
|
||||
// Reset Function
|
||||
__reonv_startup:
|
||||
# Set stack (maybe will change this to boot code)
|
||||
li sp,0x43FFFFF0
|
||||
mv x1,x0
|
||||
mv x2,x0
|
||||
mv x3,x0
|
||||
mv x4,x0
|
||||
mv x5,x0
|
||||
mv x6,x0
|
||||
mv x7,x0
|
||||
mv x8,x0
|
||||
mv x9,x0
|
||||
mv x10,x0
|
||||
mv x11,x0
|
||||
mv x12,x0
|
||||
mv x13,x0
|
||||
mv x14,x0
|
||||
mv x15,x0
|
||||
mv x16,x0
|
||||
mv x17,x0
|
||||
mv x18,x0
|
||||
mv x19,x0
|
||||
mv x20,x0
|
||||
mv x21,x0
|
||||
mv x22,x0
|
||||
mv x23,x0
|
||||
mv x24,x0
|
||||
mv x25,x0
|
||||
mv x26,x0
|
||||
mv x27,x0
|
||||
mv x28,x0
|
||||
mv x29,x0
|
||||
mv x30,x0
|
||||
mv x31,x0
|
||||
|
||||
li sp,SP_START
|
||||
call main
|
||||
jal __exit
|
||||
call __wrap_exit
|
||||
|
||||
# Exit routine
|
||||
__exit:
|
||||
ebreak
|
||||
// Wrap some existent glibc posix functions used by benchmarkers
|
||||
__wrap_exit:
|
||||
call _exit_c
|
||||
|
||||
# Interruptions vector
|
||||
__interruption_vector:
|
||||
|
||||
__wrap_open:
|
||||
call _open_c
|
||||
|
||||
__wrap_close:
|
||||
call _close_c
|
||||
|
||||
__wrap_write:
|
||||
call _write_c
|
||||
|
||||
# Interruptions handlers
|
||||
__ecall_handler:
|
||||
|
||||
|
||||
|
||||
|
||||
__wrap_read:
|
||||
call _read_c
|
||||
|
|
BIN
riscv/reonv_crt0.o
Normal file
BIN
riscv/reonv_crt0.o
Normal file
Binary file not shown.
|
@ -1,15 +0,0 @@
|
|||
.text
|
||||
.globl main
|
||||
.type "main",@function
|
||||
|
||||
main:
|
||||
li x4,0x40000100
|
||||
csrrw x0,3,x4
|
||||
csrrs x5,3,x0
|
||||
ecall
|
||||
li x30,0x98765
|
||||
ebreak
|
||||
|
||||
.org 0x100
|
||||
li x31,0x12345
|
||||
ebreak
|
Binary file not shown.
Loading…
Add table
Reference in a new issue