Skip to content

Commit 28de691

Browse files
committed
WIP ti/vars: add os_DelVarArc() and deleteArchivedVariable()
1 parent fcd61c8 commit 28de691

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

src/ce/extravars.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <stdbool.h>
2+
#include <stdint.h>
3+
4+
// From <ti/error.h>
5+
int os_PushErrorHandler(void) __attribute__((returns_twice));
6+
void os_PopErrorHandler(void);
7+
// From <ti/vars.h>
8+
#define os_OP1 ((uint8_t*)0xD005F8)
9+
#define os_Flags ((uint8_t*)0xD00080)
10+
11+
void os_DelVar(void *entry)
12+
{
13+
int clobber_hl, clobber_de;
14+
unsigned int *tmp = (unsigned int *)(entry - 5);
15+
void *data = (void*)((*tmp & 0xFF) << 16 | (*tmp & 0xFF00) | (*tmp & 0xFF0000) >> 16);
16+
asm volatile (
17+
"call 021434h" // DelVarArc
18+
: "=l" (clobber_hl),
19+
"=e" (clobber_de)
20+
: [hl] "l" (entry),
21+
[de] "e" (data),
22+
[flags] "iyl" (os_Flags)
23+
: "cc", "a", "bc", "ix", "iy"
24+
);
25+
}
26+
27+
bool arcUnarcVariable(uint8_t varType, uint8_t nameLen, const char *name)
28+
{
29+
const int err = os_PushErrorHandler();
30+
if (err) {
31+
// dbg_printf("[ERROR caught] [arcUnarcVariable] errno = %d\n", err);
32+
return false;
33+
}
34+
*(os_OP1) = varType;
35+
__builtin_memcpy((char*)(os_OP1+1), name, nameLen);
36+
*(os_OP1+1+nameLen) = '\0';
37+
asm volatile (
38+
"call 021448h" // Arc_Unarc
39+
:
40+
: [flags] "iyl" (os_Flags)
41+
: "cc", "a", "bc", "de", "hl", "ix", "iy"
42+
);
43+
os_PopErrorHandler();
44+
return true;
45+
}

src/ce/include/ti/vars.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#ifndef TI_VARS_H
1313
#define TI_VARS_H
1414

15+
#include <stdbool.h>
1516
#include <stdint.h>
1617
#include <stddef.h>
1718
#include <ti/real.h>
@@ -291,6 +292,23 @@ void *os_NextSymEntry(void *entry, uint24_t *type, uint24_t *nameLength, char *n
291292
*/
292293
int os_DelSymEntry(void *entry);
293294

295+
/**
296+
* Delete a var from RAM or archive (Flash).
297+
*
298+
* @param[in] entry An entry as used in (or returned from) \c os_NextSymEntry or \c os_ChkFindSym.
299+
*/
300+
void os_DelVar(void *entry);
301+
302+
/**
303+
* Archive (if in RAM) or Unarchive (if in Flash) a variable.
304+
*
305+
* @param[in] varType The variable type ID (like \c OS_TYPE_PROT_PRGM etc.)
306+
* @param[in] nameLen Length of the variable name
307+
* @param[in] name Variable name
308+
* @return true on success, false on failure.
309+
*/
310+
bool arcUnarcVariable(uint8_t varType, uint8_t nameLen, const char *name);
311+
294312
/**
295313
* Creates an TIOS Str.
296314
*

src/ce/makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,30 @@
1616

1717
include $(CURDIR)/../common.mk
1818

19-
WILDCARD_SRC = $(wildcard *.src)
19+
BUILD_SRC := $(patsubst %,build/%.src,$(wildcard *.c *.cpp))
20+
21+
EZCFLAGS := -S -ffreestanding -Wall -Wextra -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz
22+
EZCFLAGS += -D_EZ80 -isystem ../libc/include -mllvm -profile-guided-section-prefix=false
23+
EZCXXFLAGS := $(EZCFLAGS) -fno-exceptions -fno-rtti
24+
EZCXXFLAGS += -isystem ../libc/include/c++
25+
26+
WILDCARD_SRC = $(wildcard *.src) $(BUILD_SRC)
2027
WILDCARD_H = $(wildcard include/*.h)
2128
WILDCARD_HW_H = $(wildcard include/sys/*.h)
2229
WILDCARD_TI_H = $(wildcard include/ti/*.h)
2330

2431
WILDCARD_CXX_H = $(wildcard include/c++/*)
2532
WILDCARD_CXX_TI_H = $(wildcard include/ti/c++/*)
2633

27-
all:
34+
all: $(BUILD_SRC)
35+
36+
build/%.c.src: %.c
37+
$(Q)$(call MKDIR,build)
38+
$(Q)$(EZCC) $(EZCFLAGS) $< -o $@
39+
40+
build/%.cpp.src: %.cpp
41+
$(Q)$(call MKDIR,build)
42+
$(Q)$(EZCC) $(EZCXXFLAGS) $< -o $@
2843

2944
install: $(addprefix install-,$(TARGETS))
3045
$(Q)$(call MKDIR,$(INSTALL_H))

src/linker.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ CRT_FILES := $(filter-out crt/crt0.src,$(wildcard crt/*.src) $(patsubst crt/%,cr
2323
LIBC_FILES := $(wildcard libc/*.src) $(patsubst libc/%,libc/build/%.src,$(wildcard libc/*.c libc/*.cpp))
2424
LIBCXX_FILES := $(wildcard libcxx/*.src) $(patsubst libcxx/%,libcxx/build/%.src,$(wildcard libcxx/*.c libcxx/*.cpp))
2525
SOFTFLOAT_FILES := $(wildcard softfloat/*.src) $(patsubst softfloat/%,softfloat/build/%.src,$(wildcard softfloat/*.c softfloat/*.cpp))
26-
CE_FILES := $(wildcard ce/*.src)
26+
CE_FILES := $(wildcard ce/*.src) $(patsubst ce/%,ce/build/%.src,$(wildcard ce/*.c ce/*.cpp))
2727

2828
linker_script: $(STATIC_FILES) $(LINKED_FILES) $(SHARED_FILES)
2929
$(Q)$(call REMOVE,$(call QUOTE_ARG,$@))

0 commit comments

Comments
 (0)