Commit 40e55b9a authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

moved files around, added test sw

parent fa287419
# and don't touch the rest unless you know what you're doing.
CROSS_COMPILE ?= /opt/gcc-riscv/bin/riscv64-unknown-elf-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
CFLAGS = -m32
OBJS = test.S
LDS = ../ram.ld
OUTPUT=test1
$(OUTPUT): $(LDS) $(OBJS)
${CC} -m32 -o $(OUTPUT).elf -nostartfiles $(OBJS) -T $(LDS)
${OBJCOPY} -O binary $(OUTPUT).elf $(OUTPUT).bin
${OBJDUMP} -D $(OUTPUT).elf > disasm.S
$(SIZE) $(OUTPUT).elf
# ../genramvhd -p wrc_simulation_firmware $(OUTPUT).bin > wrc_simulation_firmware_pkg.vhd
../genraminit $(OUTPUT).bin 1000 > $(OUTPUT).ram
clean:
rm -f $(OUTPUT).elf $(OUTPUT).bin $(OBJS)
%.o: %.S
${CC} -c -m32 $^ -o $@
\ No newline at end of file
.section .boot, "ax", @progbits
.global _start
_start:
la x1, 1234
j lab2
sll x1, x1, 1
nop
addi x1,x1,1
lab2:
nop
nop
nop
/* sw x5,-16(x1)
nop
nop
lw x31, -16(x1)
la x30, 0x1235
beq x30, x31, pass1
fail1:
nop
j fail1
pass1:
lw x20,-8(x1) // x20 = 0xffec
lw x20,0(x20) // x20 = 0x1235
addi x20,x20,1
sw x20,-20(x1)
*/
/*
slli t0, t0, 0x1
sw t0,-4(sp)
slli t0, t0, 0x1
sw t0,-8(sp)
la t0, 0xffffffa0
srli t0, t0, 0x1
sw t0,-4(sp)
srli t0, t0, 0x1
sw t0,-8(sp)
*/
nop
nop
forever:
j forever
/*
# clear the bss segment
# la t0, _fbss
# la t1, _end
#1:
##ifdef __riscv64
# sd zero,0(t0)
# addi t0, t0, 8
#else
# sw zero,0(t0)
# addi t0, t0, 4
#endif
# bltu t0, t1, 1b
# call main*/
\ No newline at end of file
# and don't touch the rest unless you know what you're doing.
CROSS_COMPILE ?= /opt/gcc-riscv/bin/riscv64-unknown-elf-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
CFLAGS = -g -m32 -msoft-float -march=RV32I -O2
OBJS = crt0.o main.o
LDS = ram2.ld
OUTPUT=test2
$(OUTPUT): $(LDS) $(OBJS)
${CC} -g -m32 -msoft-float -march=RV32I -o $(OUTPUT).elf -nostartfiles $(OBJS) -lm -T $(LDS)
${OBJCOPY} -O binary $(OUTPUT).elf $(OUTPUT).bin
${OBJDUMP} -D main.o > disasm-m.S
${OBJDUMP} -D $(OUTPUT).elf > disasm.S
$(SIZE) $(OUTPUT).elf
# ../genramvhd -p wrc_simulation_firmware $(OUTPUT).bin > wrc_simulation_firmware_pkg.vhd
./genraminit $(OUTPUT).bin 1000 > $(OUTPUT).ram
clean:
rm -f $(OUTPUT).elf $(OUTPUT).bin $(OBJS)
%.o: %.S
${CC} -c -m32 $^ -o $@
\ No newline at end of file
.section .boot, "ax", @progbits
.global _start
_start:
la gp, _gp # Initialize global pointer
la sp, _fstack
# clear the bss segment
la t0, _fbss
la t1, _end
1:
#ifdef __riscv64
sd zero,0(t0)
addi t0, t0, 8
#else
sw zero,0(t0)
addi t0, t0, 4
#endif
bltu t0, t1, 1b
call main
\ No newline at end of file
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2011 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc < 3)
return -1;
FILE *f = fopen(argv[1], "rb");
if (!f)
return -1;
unsigned char x[4];
int i = 0;
int n = atoi(argv[2]);
while (!feof(f)) {
fread(x, 1, 4, f);
printf("write %x %02X%02X%02X%02X\n", i++, x[3], x[2], x[1],
x[0]);
}
for (; i < n;) {
printf("write %x %02X%02X%02X%02X\n", i++, 0, 0, 0, 0);
}
fclose(f);
return 0;
}
#include <math.h>
char dupa[64];
const char *hello="Hello, world";
volatile int *TX_REG = 0x100000;
void putc(char c)
{
*TX_REG = c;
}
void print_hex(int x)
{
const char *hexchars="0123456789abcdef";
int i;
for(i = 7; i >= 0; i--)
{
putc(hexchars[(x>>(4*i))&0xf]);
}
putc('\n');
}
int array[256];
#define SWAP(a,b) temp=(a);(a)=(b);(b)=temp;
#define INSERTION_THRESHOLD 7
// NSTACK is the required auxiliary storage.
// It must be at least 2*lg(DATA_SIZE)
#define NSTACK 50
void sort( int n, int arr[] )
{
int i,j,k;
int ir = n;
int l = 1;
int jstack = 0;
int a, temp;
int istack[NSTACK];
for (;;) {
#if HOST_DEBUG
printArray( "", n, arr );
#endif
// Insertion sort when subarray small enough.
if ( ir-l < INSERTION_THRESHOLD ) {
for ( j = l+1; j <= ir; j++ ) {
a = arr[j-1];
for ( i = j-1; i >= l; i-- ) {
if ( arr[i-1] <= a ) break;
arr[i] = arr[i-1];
}
arr[i] = a;
}
if ( jstack == 0 ) break;
// Pop stack and begin a new round of partitioning.
ir = istack[jstack--];
l = istack[jstack--];
}
else {
// Choose median of left, center, and right elements as
// partitioning element a. Also rearrange so that a[l-1] <= a[l] <= a[ir-].
k = (l+ir) >> 1;
SWAP(arr[k-1],arr[l])
if ( arr[l-1] > arr[ir-1] ) {
SWAP(arr[l-1],arr[ir-1])
}
if ( arr[l] > arr[ir-1] ) {
SWAP(arr[l],arr[ir-1])
}
if ( arr[l-1] > arr[l] ) {
SWAP(arr[l-1],arr[l])
}
// Initialize pointers for partitioning.
i = l+1;
j = ir;
// Partitioning element.
a = arr[l];
for (;;) { // Beginning of innermost loop.
do i++; while (arr[i-1] < a); // Scan up to find element > a.
do j--; while (arr[j-1] > a); // Scan down to find element < a.
if (j < i) break; // Pointers crossed. Partitioning complete.
SWAP(arr[i-1],arr[j-1]); // Exchange elements.
} // End of innermost loop.
// Insert partitioning element.
arr[l] = arr[j-1];
arr[j-1] = a;
jstack += 2;
// Push pointers to larger subarray on stack,
// process smaller subarray immediately.
#if HOST_DEBUG
if ( jstack > NSTACK ) { printf("NSTACK too small in sort.\n"); exit(1); }
#endif
if ( ir-i+1 >= j-l ) {
istack[jstack] = ir;
istack[jstack-1] = i;
ir = j-1;
}
else {
istack[jstack] = j-1;
istack[jstack-1] = l;
l = i;
}
}
}
}
void test_sort()
{
int i;
const int size = 16;
for(i=0;i<size;i++)
{
array[i] = 1000 - i;
print_hex(array[i]);// = 1000-i;
}
putc('\n');
sort(size, array);
for(i=0;i<size;i++)
print_hex(array[i]);// = 1000-i;
}
#if 0
void test_floats()
{
float x;
float y;
for(x=0.0; x <=1.0; x+=0.2)
{
y = cosf(x);
print_hex(*(int*)&x);
print_hex(*(int*)&y);
putc('\n');
}
}
#endif
main()
{
char *s = hello;
int i;
// test_floats();
test_sort();
// for(i=0;i<5;i++)
// float y = cos(x);
// unsigned int x = 1234;
// unsigned int y = x >> 2;
// print_hex(*(int*)&x);
// y = x << 2;
// print_hex(*(int*)&y);
for(;;);
/*
x = 0xfffffb2e;
y = x >> 2;
print_hex(*(int*)&y);
y = x << 2;
print_hex(*(int*)&y);
// x+=1.0;
// print_hex(*(int*)&x);
// print_hex(*(int*)&y);
// while(*s) { *TX_REG = *s++; }
*/
for(;;);
}
OUTPUT_FORMAT("elf32-littleriscv")
ENTRY(_start)
SECTIONS
{
/*--------------------------------------------------------------------*/
/* Code and read-only segment */
/*--------------------------------------------------------------------*/
/* Begining of code and text segment */
. = 0x00000000;
_ftext = .;
PROVIDE( eprol = . );
/* text: Program code section */
.text :
{
*(.boot)
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
}
/* init: Code to execute before main (called by crt0.S) */
.init :
{
KEEP( *(.init) )
}
/* fini: Code to execute after main (called by crt0.S) */
.fini :
{
KEEP( *(.fini) )
}
/* rodata: Read-only data */
.rodata :
{
*(.rdata)
*(.rodata)
*(.rodata.*)
*(.gnu.linkonce.r.*)
}
/* End of code and read-only segment */
PROVIDE( etext = . );
_etext = .;
/*--------------------------------------------------------------------*/
/* Global constructor/destructor segement */
/*--------------------------------------------------------------------*/
/* The .ctors/.dtors sections are special sections which contain a
list of constructor/destructor function pointers. crtbegin.o
includes code in a .init section which goes through the .ctors list
and calls each constuctor. crtend.o includes code in a .fini
section which goes through the .dtors list and calls each
destructor. crtbegin.o includes a special null pointer in its own
.ctors/.dtors sections which acts as a start indicator for those
lists. crtend.o also includes a special null pointer in its own
.ctors/.dtors sections which acts as an end indictor. The linker
commands below are setup so that crtbegin.o's .ctors/.dtors
sections are always first and crtend.o's .ctors/.dtors sections are
always last. This is the only way the list of functions will have
the begin and end indicators in the right place. */
/* ctors : Array of global constructor function pointers */
/*--------------------------------------------------------------------*/
/* Initialized data segment */
/*--------------------------------------------------------------------*/
/* Start of initialized data segment */
. = ALIGN(16);
_fdata = .;
/* data: Writable data */
.data :
{
*(.data)
*(.data.*)
*(.gnu.linkonce.d.*)
}
/* End of initialized data segment */
PROVIDE( edata = . );
_edata = .;
/* Have _gp point to middle of sdata/sbss to maximize displacement range */
. = ALIGN(16);
_gp = . + 0x800;
/* Writable small data segment */
.sdata :
{
*(.sdata)
*(.sdata.*)
*(.srodata.*)
*(.gnu.linkonce.s.*)
}
/*--------------------------------------------------------------------*/
/* Uninitialized data segment */
/*--------------------------------------------------------------------*/
/* Start of uninitialized data segment */
. = ALIGN(8);
_fbss = .;
/* Writable uninitialized small data segment */
.sbss :
{
*(.sbss)
*(.sbss.*)
*(.gnu.linkonce.sb.*)
}
/* bss: Uninitialized writeable data section */
. = .;
_bss_start = .;
.bss :
{
*(.bss)
*(.bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
}
/* End of uninitialized data segment (used by syscalls.c for heap) */
PROVIDE( end = . );
_end = ALIGN(8);
PROVIDE( _fstack = 0xfffc );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment