Skip to content

Commit

Permalink
Make framework configurable for 64k intro (backported from dce1b96)
Browse files Browse the repository at this point in the history
  • Loading branch information
cahirwpz committed Dec 16, 2023
1 parent 9f2b150 commit 578cac2
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ LDSCRIPT := $(TOPDIR)/system/amiga.lds
# Don't reload library base for each call
CPPFLAGS += -D__CONSTLIBBASEDECL__=const
CPPFLAGS += -DCHIPMEM_KB=$(CHIPMEM) -DFASTMEM_KB=$(FASTMEM) -DLOGOUT=$(LOGOUT)
CPPFLAGS += -DPROFILER=$(PROFILER)
CPPFLAGS += -DPROFILER=$(PROFILER) -DMULTITASK=$(MULTITASK) -DMEMDEBUG=$(MEMDEBUG)

include $(TOPDIR)/config.mk

Expand Down
9 changes: 8 additions & 1 deletion config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ AMIGAOS := 0
# 1 => Turn on profiler that reports minimum-average-maximum number of raster
# lines measured between calls to ProfilerStart / ProfilerStop.
# The measurement is reported every 50 frames (i.e. once a second).
# 0 => Disable the profiler.
PROFILER := 1

# 1 => Enable multitasking feature. It can be necessary to run background thread
# that loads data from disk while the effects are running.
MULTITASK := 1

# 1 => Enable dynamic memory allocation debugging incl. nice diagnostic printout
# when memory corruption is detected or we run out of memory.
MEMDEBUG := 1

# [only when AMIGAOS=1] Amount of chip and fast (or public) memory
# (in kilobytes!) passed to our custom memory allocator.
# To calculate total memory taken after an executable file
Expand Down
4 changes: 4 additions & 0 deletions include/effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,13 @@ typedef struct Profile {
#define ProfilerStop(NAME)
#endif

#if MULTITASK
/* Puts a task into sleep waiting for Vertical Blank interrupt.
* Let's background task do its job. */
void TaskWaitVBlank(void);
#else
#define TaskWaitVBlank WaitVBlank
#endif

void _ProfilerStart(ProfileT *prof);
void _ProfilerStop(ProfileT *prof);
Expand Down
2 changes: 1 addition & 1 deletion include/system/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void Log(const char *format, ...)
__noreturn void Panic(const char *format, ...)
__attribute__ ((format (printf, 1, 2)));
#else
#define Log(...)
#define Log(...) ((void)0)
#define Panic(...) HALT()
#endif
#endif
Expand Down
5 changes: 5 additions & 0 deletions include/system/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
#endif

#ifdef _SYSTEM
#if MEMDEBUG
void MemCheck(int verbose);
u_int MemAvail(u_int attributes);
#else
#define MemCheck(_) { (void)0; }
#define MemAvail(_) 0
#endif
void AddMemory(void *ptr, u_int byteSize, u_int attributes);
#endif

Expand Down
10 changes: 10 additions & 0 deletions include/system/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

struct Task;

#if MULTITASK
typedef struct Mutex {
volatile struct Task *owner;
TAILQ_HEAD(, Task) waitList;
Expand All @@ -23,5 +24,14 @@ static inline void MutexInit(MutexT *mtx) {

void MutexLock(MutexT *mtx);
void MutexUnlock(MutexT *mtx);
#else
typedef struct Mutex {} MutexT;

#define MUTEX(name) MutexT name = (MutexT){}

static inline void MutexInit(MutexT *mtx) { (void)mtx; }
static inline void MutexLock(MutexT *mtx) { (void)mtx; }
static inline void MutexUnlock(MutexT *mtx) { (void)mtx; }
#endif

#endif /* !__SYSTEM_MUTEX_H__ */
10 changes: 8 additions & 2 deletions system/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ SOURCES := \
kernel/interrupt.c \
kernel/intr-entry.S \
kernel/memory.c \
kernel/mutex.c \
kernel/task.c \
kernel/trap-entry.S \
kernel/trap.c

include $(TOPDIR)/config.mk

ifeq ($(MULTITASK), 1)
SOURCES += \
kernel/mutex.c \
kernel/task.c
endif

CFLAGS.amigaos = -Wno-strict-prototypes

BUILD-FILES = crt0.o
Expand Down
2 changes: 1 addition & 1 deletion system/kernel/exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void SetupExceptionVector(BootDataT *bd) {
ExcVec[EXC_FMTERR] = FmtErrTrap;

/* Intialize TRAP instruction handlers. */
ExcVec[EXC_TRAP(0)] = YieldHandler;
ExcVec[EXC_TRAP(0)] = MULTITASK ? YieldHandler : TrapInstTrap;

for (i = EXC_TRAP(1); i <= EXC_TRAP(15); i++)
ExcVec[i] = TrapInstTrap;
Expand Down
18 changes: 18 additions & 0 deletions system/kernel/interrupt.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <debug.h>
#include <system/cpu.h>
#include <system/exception.h>
#include <system/interrupt.h>
#include <system/task.h>
Expand All @@ -24,6 +25,23 @@ void SetIntVector(u_int irq, IntHandlerT code, void *data) {
iv->data = data;
}

#if MULTITASK
#define IntrNest CurrentTask->intrNest
#else
static __code short IntrNest = 0;
#endif

void IntrEnable(void) {
Assume(IntrNest > 0);
if (--IntrNest == 0)
CpuIntrEnable();
}

void IntrDisable(void) {
CpuIntrDisable();
IntrNest++;
}

/* List of interrupt servers. */
typedef struct IntChain {
IntServerT *head;
Expand Down
4 changes: 4 additions & 0 deletions system/kernel/intr-entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ ENTRY(EnterIntr)
END(EnterIntr)

ENTRY(LeaveIntr)
#if MULTITASK
/*
* Check if we need to reschedule a task - usually as a result waking
* up a higher priorty task while running interrupt service routine.
Expand All @@ -91,6 +92,7 @@ ENTRY(LeaveIntr)
clr.b (a0) /* clear reschedule flag */
movem.l (sp)+,d0-d1/a0-a1 /* restore registers */
jra _L(YieldHandler)+4 /* force a task switch (skip or.w to sr) */
#endif

.Lnoswitch:
movem.l (sp)+,d0-d1/a0-a1
Expand Down Expand Up @@ -140,10 +142,12 @@ END(DummyInterruptHandler)
rte /* restore SR and PC */
.endm

#if MULTITASK
ENTRY(YieldHandler)
SAVECTX
jsr _L(TaskSwitch)
LOADCTX
END(YieldHandler)
#endif

# vim: ft=gas:ts=8:sw=8:noet:
8 changes: 6 additions & 2 deletions system/kernel/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static inline WordT *BtPrev(WordT *bt) {
return (void *)bt - BtSize(ft);
}

static const char *MemoryName(u_int attributes) {
__unused static const char *MemoryName(u_int attributes) {
if (attributes & MEMF_CHIP)
return "chip";
if (attributes & MEMF_FAST)
Expand Down Expand Up @@ -364,6 +364,7 @@ static void *ArenaMemResize(ArenaT *ar, void *old_ptr, u_int size) {
return new_ptr;
}

#if MEMDEBUG
#define Msg(...) if (verbose) Log(__VA_ARGS__)

static void ArenaCheck(ArenaT *ar, int verbose) {
Expand All @@ -380,7 +381,7 @@ static void ArenaCheck(ArenaT *ar, int verbose) {

for (; bt < ar->end; prev = bt, bt = BtNext(bt)) {
int flag = !!BtGetPrevFree(bt);
int is_last = !!BtGetIsLast(bt);
__unused int is_last = !!BtGetIsLast(bt);
Msg("$%08lx: [%c%c:%ld] %c\n", (uintptr_t)bt, "FU"[BtUsed(bt)], " P"[flag],
BtSize(bt), " *"[is_last]);
if (BtFree(bt)) {
Expand Down Expand Up @@ -410,6 +411,7 @@ static void ArenaCheck(ArenaT *ar, int verbose) {

MutexUnlock(&MemMtx);
}
#endif

static ArenaT *ArenaOf(void *ptr) {
ArenaT *ar;
Expand Down Expand Up @@ -480,6 +482,7 @@ void *MemResize(void *old_ptr, u_int size) {
return NULL;
}

#if MEMDEBUG
void MemCheck(int verbose) {
ArenaT *ar;
for (ar = FirstArena; ar != NULL; ar = ar->succ)
Expand All @@ -494,3 +497,4 @@ u_int MemAvail(u_int attributes) {
avail += ar->totalFree;
return avail;
}
#endif
11 changes: 0 additions & 11 deletions system/kernel/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ static TaskListT ReadyList = TAILQ_HEAD_INITIALIZER(ReadyList);
static TaskListT WaitList = TAILQ_HEAD_INITIALIZER(WaitList);
u_char NeedReschedule = 0;

void IntrEnable(void) {
Assume(CurrentTask->intrNest > 0);
if (--CurrentTask->intrNest == 0)
CpuIntrEnable();
}

void IntrDisable(void) {
CpuIntrDisable();
CurrentTask->intrNest++;
}

void TaskInit(TaskT *tsk, const char *name, void *stkptr, u_int stksz) {
bzero(tsk, sizeof(TaskT));
strlcpy(tsk->name, name, MAX_TASK_NAME_SIZE);
Expand Down
4 changes: 3 additions & 1 deletion system/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ void Loader(BootDataT *bd) {
/* Lower interrupt priority level to nominal. */
SetIPL(IPL_NONE);

#if MULTITASK
TaskInit(CurrentTask, "main", bd->bd_stkbot, bd->bd_stksz);
#endif
CallFuncList(&__INIT_LIST__);

{
int retval = main();
__unused int retval = main();
Log("[Loader] main() returned %d.\n", retval);
}

Expand Down

0 comments on commit 578cac2

Please sign in to comment.