Skip to content

Commit

Permalink
Add pi demo
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlohr committed Nov 29, 2023
1 parent 2ccd085 commit f3a3087
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ toolchain : buildroot

everything : toolchain
make -C hello_linux deploy
# make -C packages/duktapetest deploy
#make -C packages/duktapetest deploy
make -C packages/coremark deploy
cp -a configs/rootfsoverlay/* buildroot/output/target/
make -C buildroot
Expand Down
2 changes: 1 addition & 1 deletion configs/buildroot_config
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ BR2_PACKAGE_UCLIBC_SUPPORTS=y
# uClibc Options
#
BR2_PACKAGE_UCLIBC=y
BR2_UCLIBC_CONFIG="package/uclibc/uClibc-ng.config"
BR2_UCLIBC_CONFIG="uclibc_config"
BR2_UCLIBC_CONFIG_FRAGMENT_FILES=""
# BR2_TOOLCHAIN_BUILDROOT_WCHAR is not set
# BR2_TOOLCHAIN_BUILDROOT_LOCALE is not set
Expand Down
13 changes: 8 additions & 5 deletions hello_linux/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
all : hello_linux
all : hello_linux pi

PREFIX:=../buildroot/output/host/bin/riscv32-buildroot-linux-uclibc-
CC:=$(PREFIX)gcc
OBJDUMP:=$(PREFIX)objdump

# Note: regymm says to do -fPIE -pie -static, instead of -fPIC
CFLAGS:=-mabi=ilp32 -fPIE -pie -static -march=rv32ima -Os -s -g
LDFLAGS:=-Wl,-elf2flt=-r
CFLAGS:=-mabi=ilp32 -fPIE -pie -static -march=rv32ima -Os -s -g -ffunction-sections -fdata-sections
LDFLAGS:=-Wl,-elf2flt=-r -Wl,-gc-sections

C_S+=hello_linux.c

Expand All @@ -19,11 +19,14 @@ hello_linux : hello_linux.c
$(CC) $(CFLAGS) $(C_S) $(LDFLAGS) -o $@
$(OBJDUMP) -S $@.gdb > $@.S

deploy : hello_linux
pi : pi.c
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@

deploy : hello_linux pi
cp $^ ../buildroot/output/target/root

rebuild :
make -C.. toolchain

clean :
rm -rf hello_linux hello_linux.gdb hello_linux.S
rm -rf hello_linux hello_linux.gdb hello_linux.S pi pi.gdb pi.S
4 changes: 2 additions & 2 deletions hello_linux/hello_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
int main( int argc, char ** argv )
{
printf( "Hello, world %08x\n", argc );
float f = 7.3f;
printf( "f: %f\n", f );
float ft = 7.3f;
printf( "f: %f\n", ft );
}
7 changes: 7 additions & 0 deletions hello_linux/pi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// https://crypto.stanford.edu/pbc/notes/pi/code.html
#include <stdio.h>
int a=10000,b,c=2800,d,e,f[2801],g;int main(){for(;b-c;)f[b++]=a/5;
for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,
f[b]=d%--g,d/=g--,--b;d*=b);}


0 comments on commit f3a3087

Please sign in to comment.