From f6c5d6164b64c3f903fe196daf8f3c3eb220cf4d Mon Sep 17 00:00:00 2001 From: mpabi Date: Thu, 16 May 2024 07:34:58 +0100 Subject: [PATCH] init --- cpp/Makefile | 7 ++-- cpp/_crt0.S | 2 +- cpp/_rvmain.cpp | 91 +++++++++++++++++++++++++++++++------------------ 3 files changed, 64 insertions(+), 36 deletions(-) diff --git a/cpp/Makefile b/cpp/Makefile index ad6a34c..1456d22 100644 --- a/cpp/Makefile +++ b/cpp/Makefile @@ -2,10 +2,13 @@ TOP=./ include $(TOP)/Make.rules LDLIBS= -CFLAGS+=-O0 -g +#CFLAGS+=-O0 -g +# CFLAGS+=-Og -ggdb3 +CFLAGS+=-O0 -ggdb3 LDFLAGS+=-Wl,--no-relax -LDFLAGS+=-Wl,-Tdata=0x10000 +LDFLAGS+=-Wl,-Ttext=0x80000000,-Tdata=0x80010000 +# LDFLAGS+=-T murax_128k_ram.ld PROGS=prog prog.bin prog.lst diff --git a/cpp/_crt0.S b/cpp/_crt0.S index 99b1460..50a0e46 100644 --- a/cpp/_crt0.S +++ b/cpp/_crt0.S @@ -9,7 +9,7 @@ _start: la gp, __global_pointer$ .option pop - li sp, 0x1fff0 + li sp, 0x800ffff0 # Clear the bss segment la a0, __bss_start diff --git a/cpp/_rvmain.cpp b/cpp/_rvmain.cpp index 0f70993..ac953e8 100644 --- a/cpp/_rvmain.cpp +++ b/cpp/_rvmain.cpp @@ -1,48 +1,73 @@ #include -//szymon -//#include "myfunc.h" -//int8_t x = 1, y = 2, z[10]; -//int8_t *ip; /* ip to wskaźnik do obiektu typu int */ +char * ptr1 = "janek"; +char * ptr2 = "kowalskii"; -void swap_ptr (int8_t *x, int8_t *y) { - - int8_t tmp; - tmp = *x; - *x = *y; - *y = tmp; - +int strlen(char *s) +{ + char *p = s; + while (*p != '\0') + p++; + return p - s; } -// ----------------------------------------------- - -void swap(int8_t x, int8_t y) { - - int8_t tmp; - tmp = x; - x = y; - y = tmp; - +void strcpy(char *s, char *t) +{ + while (*s++ = *t++); } +#define ALLOCSIZE 10000 + +static char allocbuf[ALLOCSIZE]; +static char *allocp = allocbuf; + +char *alloc(int n) +{ + + if (n % 4 != 0) { + n += 4 - (n % 4); + } + + + if (allocbuf + ALLOCSIZE - allocp >= n) { + allocp += n; + return allocp - n; + } else + return 0; +} + int main() { -// ip = &x; /* ip wskazuje teraz x */ -// y = *ip; /* y ma teraz wartość 1 */ -// *ip = 0; /* x ma teraz wartość 0 */ -// ip = &z[0]; /* ip wskazuje teraz z[0] */ + char * s = "mpabi"; + + + uint8_t wynik =0; + wynik = strlen (s); - int8_t mx = 1, my = 2, mz[10]= {1,2,3,4,5}; - int8_t *mip; /* ip to wskaźnik do obiektu typu int */ - mip = &mx; /* ip wskazuje teraz x */ - my = *mip; /* y ma teraz wartość 1 */ - *mip = 0; /* x ma teraz wartość 0 */ - mip = &mz[0]; /* ip wskazuje teraz z[0] */ + asm("nop"); - swap (mx, my); - swap_ptr (&mx, &my); - return 1; + char * p1 = alloc(strlen(ptr1)); + strcpy (p1, ptr1); + asm("nop"); + + char * p2 = alloc(strlen(ptr2)); + strcpy (p2, ptr2); + asm("nop"); + + struct point { + int16_t x; + int16_t y; + }; + + struct point * ptrS = (struct point *) alloc(sizeof(point)); + ptrS->x=0x10; + ptrS->y=0x20; + asm("nop"); + + (*ptrS).y= strlen (p1)+ strlen(p2); + + return 1; }