Commit a5fae552 authored by Stewart Brodie's avatar Stewart Brodie
Browse files

Build process improvements:

  !MkRam,fd7 added to enable RAM builds of all Toolbox modules
  MakeFile tidied up and support for RAM build added
Module now uses Toolbox memory allocation instead of calling OS_Module.
parent 2f546eaf
......@@ -41,7 +41,7 @@ CD = dir
LIBFILE = libfile
CFLAGS = -c -depend !Depend -Wap -zps0 ${INCLUDES} -fah -Fn ${DFLAGS}
CFLAGSZM = -c -depend !Depend -Wap -zps0 ${INCLUDES} -fah -Fn ${DFLAGS} -zM
CFLAGSZM = -c -depend !Depend -Wap -zps1 ${INCLUDES} -fah -Fn ${DFLAGS} -zM
CPFLAGS = ~cfr~v
WFLAGS = ~c~v
LIBFILEFLAGS = -c -o $@
......@@ -72,8 +72,8 @@ DEBUGLIBZM = debuglibm
EXPORTS = ${LIBDIR}.tboxlibint
OBJ = o.mem o.messages o.string32 o.rmensure o.objsupport o.slist
OBJZM = z.mem z.messages z.string32 z.rmensure z.objsupport z.slist
OBJ = o.mem o.messages o.string32 o.rmensure o.objsupport o.slist o.toolboxmem
OBJZM = z.mem z.messages z.string32 z.rmensure z.objsupport z.slist z.toolboxmem
DBG_OBJ = o.debug
DBG_OBJZM = z.debug
......@@ -84,6 +84,8 @@ DBG_OBJZM = z.debug
.SUFFIXES: .z .o .c .s
.c.o:; ${CC} ${CFLAGS} -o $@ $<
.c.z:; ${CCZM} -c -o $@ $<
.s.o:; ${AS} ${ASFLAGS} -o $@ $<
.s.z:; ${AS} ${ASFLAGS} -o $@ $<
#
# Build
......@@ -98,8 +100,8 @@ ${TBOXLIBZM}: ${OBJZM}
${DEBUGLIB}: ${OBJ} ${DBG_OBJ}
${LIBFILE} ${LIBFILEFLAGS} ${OBJ} ${DBG_OBJ}
${DEBUGLIBZM}: ${OBJZM} ${DBG_OBJAM}
${LIBFILE} ${LIBFILEFLAGS} ${OBJZM} ${DBG_OBJAM}
${DEBUGLIBZM}: ${OBJZM} ${DBG_OBJZM}
${LIBFILE} ${LIBFILEFLAGS} ${OBJZM} ${DBG_OBJZM}
clean:
${WIPE} o.* ${WFLAGS}
......
......@@ -41,6 +41,7 @@
#include "debug.h"
#include "mem.h"
#include "objects.toolbox.h"
#undef mem_allocate
#undef mem_free
......@@ -48,6 +49,11 @@
#undef mem_extend
#undef mem_chk
#include "toolboxmem.h"
#define calloc(m,s) toolbox_memory_alloc_c((m)*(s))
#define free(p) toolbox_memory_free_c(p)
#define reallocate(b,by) toolbox_memory_extend_c(b,by)
typedef struct block
{
struct block *next; /* next one in the chain */
......@@ -69,8 +75,33 @@ typedef struct block
static mem__Block *mem__block_list = 0; /* linked list of all allocated blocks */
enum {
memorysys_USE_TOOLBOX = 1,
memorysys_USE_OWN_CODE = 2
};
static int memory_sys_flag = 0;
/* This function must only ever be called by the Toolbox module and is used to bypass the
* problem of not being able to call our own SWIs during module initialisation.
*/
extern void mem_i_am_the_toolbox (void)
{
memory_sys_flag = memorysys_USE_TOOLBOX;
}
extern void mem_init (void)
{
if (_swix(Toolbox_Memory, _INR(0,2), 2, 0, 0) == NULL) {
/* Then a suitable Toolbox module *was* present */
memory_sys_flag = memorysys_USE_TOOLBOX;
}
else {
memory_sys_flag = memorysys_USE_OWN_CODE;
}
}
static void *reallocate (void *p, int by)
static void *(reallocate)(void *p, int by)
{
/*
* own implementation of realloc, cos broken in 3.10
......@@ -82,27 +113,66 @@ static void *reallocate (void *p, int by)
return 0;
else
{
_kernel_swi_regs r;
r.r[0] = 13; /* extend RMA block */
r.r[2] = (int)p;
r.r[3] = by;
if (_kernel_swi (OS_Module, &r, &r) != 0)
void *newp;
if (_swix (OS_Module, _IN(0)|_INR(2,3)|_OUT(2),
13, /* extend RMA block */
p,
by,
&newp
) != 0)
{
DEBUG debug_output ("memory", "Failed\n");
return 0;
}
else
{
DEBUG debug_output ("memory", "Old p %p, new p %p\n", p, (void *)r.r[2]);
return (void *)r.r[2];
DEBUG debug_output ("memory", "Old p %p, new p %p\n", p, newp);
return newp;
}
}
}
static void *toolbox_memory_alloc_c(int s)
{
if (memory_sys_flag == memorysys_USE_TOOLBOX)
return toolbox_memory_alloc(s);
else if (memory_sys_flag == memorysys_USE_OWN_CODE)
return (calloc)(s, 1);
else {
mem_init();
return toolbox_memory_alloc_c(s);
}
}
static void toolbox_memory_free_c(void *p)
{
if (memory_sys_flag == memorysys_USE_TOOLBOX)
toolbox_memory_free(p);
else if (memory_sys_flag == memorysys_USE_OWN_CODE)
(free)(p);
else {
mem_init();
toolbox_memory_free_c(p);
}
}
static void *toolbox_memory_extend_c(void *b, int by)
{
if (memory_sys_flag == memorysys_USE_TOOLBOX)
return toolbox_memory_extend(b, by);
else if (memory_sys_flag == memorysys_USE_OWN_CODE)
return (reallocate)(b, by);
else {
mem_init();
return toolbox_memory_extend_c(b, by);
}
}
static void mem__add_block (mem__Block *b)
{
/*
......@@ -354,15 +424,15 @@ extern void mem_free (void *block, char *msg)
/* --- free debug info from block --- */
if (b->fn)
{
free (b->fn);
free(b->fn);
}
if (b->tag)
{
free (b->tag);
free(b->tag);
}
/* --- ... and free the block itself --- */
free (b);
free(b);
debug_output ("memory", " => %d\n", mem__total_size());
}
......@@ -378,10 +448,10 @@ extern void mem_free_all (void)
mem__remove_block (b);
if (b->fn)
free (b->fn);
free(b->fn);
if (b->tag)
free (b->tag);
free (b);
free(b->tag);
free(b);
b = next;
}
......@@ -427,7 +497,7 @@ extern void *mem_allocate(unsigned int size, char *tag)
0);
/* --- allocate new block to put in list of all allocated blocks --- */
if ((new_block = (mem__Block *)calloc (sizeof(mem__Block) + size, sizeof(char))) == 0)
if ((new_block = (mem__Block *)calloc(sizeof(mem__Block) + size, sizeof(char))) == 0)
return 0;
mem__add_block (new_block);
......@@ -437,7 +507,7 @@ extern void *mem_allocate(unsigned int size, char *tag)
/* --- note the name of the calling function --- */
if (fn_name != NULL)
{
if ((new_block->fn = calloc (strlen (fn_name) + 1, sizeof(char))) == 0)
if ((new_block->fn = calloc(strlen (fn_name) + 1, sizeof(char))) == 0)
{
mem_free ((void *)(new_block+1), "no mem for fn name");
return 0;
......@@ -451,7 +521,7 @@ extern void *mem_allocate(unsigned int size, char *tag)
/* --- note tag passed by calling function --- */
if (tag != NULL)
{
if ((new_block->tag = calloc (strlen (tag) + 1, sizeof(char))) == 0)
if ((new_block->tag = calloc(strlen (tag) + 1, sizeof(char))) == 0)
{
mem_free ((void *)(new_block+1), "no mem for tag");
return 0;
......@@ -494,7 +564,7 @@ extern void *mem_extend (void *block, int by)
mem__total_size());
/* --- extend existing block --- */
if ((b = (mem__Block *)reallocate ((void *)b, by)) == 0)
if ((b = (mem__Block *)reallocate((void *)b, by)) == 0)
return 0;
/* --- check to see if block has moved, and if so, update pointers --- */
......@@ -536,7 +606,7 @@ extern void mem_free (void *block)
mem__remove_block (b);
/* --- ... and free the block itself --- */
free (b);
free(b);
}
......@@ -549,7 +619,7 @@ extern void mem_free_all (void)
next = b->next;
mem__remove_block (b);
free (b);
free(b);
b = next;
}
......@@ -572,7 +642,7 @@ extern void *mem_allocate (unsigned int size)
mem__Block *new_block;
/* --- allocate new block to put in list of all allocated blocks --- */
if ((new_block = (mem__Block *)calloc (sizeof(mem__Block) + size, sizeof(char))) == 0)
if ((new_block = (mem__Block *)calloc(sizeof(mem__Block) + size, sizeof(char))) == 0)
return 0;
mem__add_block (new_block);
......@@ -601,7 +671,7 @@ extern void *mem_extend (void *block, int by)
old_b = b;
/* --- extend existing block --- */
if ((b = (mem__Block *)reallocate ((void *)b, by)) == 0)
if ((b = (mem__Block *)reallocate((void *)b, by)) == 0)
return 0;
/* --- check to see if block has moved, and if so, update pointers --- */
......
......@@ -219,22 +219,13 @@ extern void raise_toolbox_oserror (_kernel_oserror *e, ObjectID object_id, Compo
extern _kernel_oserror *messages_file_open (char *messages_filename)
{
_kernel_swi_regs regs;
regs.r[0] = (int)messages_fd;
regs.r[1] = (int)messages_filename;
regs.r[2] = 0; /* use RMA */
return _kernel_swi(MessageTrans_OpenFile, &regs, &regs);
return _swix(MessageTrans_OpenFile, _INR(0,2), messages_fd, messages_filename, 0 /* use RMA */);
}
extern _kernel_oserror *messages_file_close (void)
{
_kernel_swi_regs regs;
regs.r[0] = (int)messages_fd;
return _kernel_swi (MessageTrans_CloseFile, &regs, &regs);
return _swix (MessageTrans_CloseFile, _IN(0), messages_fd);
}
......
......@@ -33,14 +33,14 @@
static _kernel_oserror *extract_gadget_info(char *tm,ComponentID id,void **p,int *l)
{
return _swix(Window_ExtractGadgetInfo, _IN(0) | _IN(1) |_IN(2) | _OUT(0) | _OUT(1),0,tm,id,p,l);
return _swix(Window_ExtractGadgetInfo, _INR(0,2) | _OUTR(0,1), 0,tm,id, p,l);
}
char *copy_template(char *name)
{
char *tm;
ObjectTemplateHeader *obj;
if(_swix(Toolbox_TemplateLookUp, _IN(0) | _IN(1) | _OUT(0),0,name,&obj)) tm = NULL;
if(_swix(Toolbox_TemplateLookUp, _INR(0,1) | _OUT(0),0,name,&obj)) tm = NULL;
else {
tm = mem_allocate(obj->total_size,"template copy");
if(tm) {
......@@ -85,7 +85,7 @@ _kernel_oserror *__zap_window(char *tm,int off,int val)
_kernel_oserror *create_from_template(char *template, ObjectID *handle)
{
_kernel_oserror *er=NULL;
if ((er=_swix(Toolbox_CreateObject, _IN(0) | _IN(1) | _OUT(0),
if ((er=_swix(Toolbox_CreateObject, _INR(0,1) | _OUT(0),
1, /* flags */
template,
handle)) != NULL) {
......
......@@ -16,6 +16,8 @@
* Purpose: ensuring a module is loaded
* Author: IDJ
* History: 24-Jun-94: IDJ: created
* 02-Dec-96: KJB: modified ROM conditional - RAM modules still need
* to use rmensure in TinyStubs
*/
......@@ -28,8 +30,13 @@
_kernel_oserror *rmensure (char *module_name, char *file_name, char *module_version)
{
#ifndef ROM
_kernel_swi_regs regs;
#if defined(ROM) && !defined(BUILDING_TINYSTUBS)
IGNORE(module_area);
IGNORE(file_name);
IGNORE(module_version);
return NULL;
#else
_kernel_oserror *e;
char command[256];
......@@ -37,23 +44,14 @@ _kernel_oserror *rmensure (char *module_name, char *file_name, char *module_vers
* see if the module is there at all!
*/
sprintf (command, "*RMEnsure %s %s *RMLoad System:modules.%s", module_name,
sprintf (command, "RMEnsure %s %s RMLoad System:Modules.%s", module_name,
module_version, file_name);
regs.r[0] = (int)command;
if ((e = _kernel_swi (OS_CLI, &regs, &regs)) != NULL)
if ((e = _swix (OS_CLI, _IN(0), command)) != NULL)
return e;
sprintf (command, "*RMEnsure %s %s", module_name, module_version);
sprintf (command, "RMEnsure %s %s", module_name, module_version);
regs.r[0] = (int)command;
if ((e = _kernel_swi (OS_CLI, &regs, &regs)) != NULL)
return e;
#else
IGNORE(module_name);
IGNORE(file_name);
IGNORE(module_version);
return _swix (OS_CLI, _IN(0), command);
#endif
return NULL;
}
......@@ -22,6 +22,7 @@ void *slist_add_new(void **_head,int size,char *tag)
SList *new,**head = (SList **)_head;
(void) tag;
new = mem_allocate(size,tag);
if (new) {
new->next = *head;
......
......@@ -41,6 +41,23 @@
extern void mem_free_all (void);
extern void mem_init (void);
extern void mem_i_am_the_toolbox (void);
/*
* Description: for internal use by the Toolbox module ONLY.
* in order to enable it to initialise the mem library
* correctly.
*
* Parameters: None
*
* Returns: void
*
*/
#define CHECK_HEAP (1u << 0)
......
......@@ -28,6 +28,8 @@
#define Service_StartWimp 0x49
#define Service_WimpCloseDown 0x53
#define Service_FilterManagerInstalled 0x87
#define Service_DynamicAreaRenumber 0x92
#endif
/* Copyright 1998 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Title: toolboxmem.h
* Purpose: Veneers onto Toolbox memory allocation SWIs
* Author: Kevin Bracey
* History: 22-Nov-96: KJB: created
*/
#ifndef __toolboxmem_h
#define __toolboxmem_h
extern void *toolbox_memory_alloc(size_t);
extern void *toolbox_memory_extend(void *, int);
extern void toolbox_memory_free(void *);
#endif
......@@ -42,6 +42,7 @@
#define Menu_Entry_GenerateSubMenuEvent 0x00000800
#define Menu_Entry_ClickShowTransient 0x00001000
#define Menu_Entry_ClickShowCentred 0x00002000
#define Menu_Entry_ClickShowAtPointer 0x00004000
/* templates */
......
......@@ -18,6 +18,7 @@
* History: 8-Dec-93: IDJ: created
* 18-Apr-94: IDJ: removed options string from object hdr.
* 02-Feb-97: EPW: Added Toolbox_ShowObject_AtPointer
* 03-Feb-98: SNB: Added Service_ToolboxDying, Toolbox_BadMemoryReason, Toolbox_Memory_*
*
*/
......@@ -162,6 +163,7 @@ typedef struct
#define Toolbox_Initialise (Toolbox_SWIChunkBase + 15)
#define Toolbox_LoadResources (Toolbox_SWIChunkBase + 16)
#define Toolbox_Memory (Toolbox_SWIChunkBase + 57)
#define Toolbox_DeRegisterObjectModule (Toolbox_SWIChunkBase + 58)
#define Toolbox_TemplateLookUp (Toolbox_SWIChunkBase + 59)
#define Toolbox_GetInternalHandle (Toolbox_SWIChunkBase + 60)
......@@ -242,6 +244,16 @@ typedef struct
/* flags and types for Toolbox_Memory */
#define Toolbox_Memory_ValidReasonBits 0xFF
#define Toolbox_Memory_Alloc 0x00
#define Toolbox_Memory_Free 0x01
#define Toolbox_Memory_Reallocate 0x02
/* ------------------------------------------- Toolbox Events ----------------------------------------- */
/* event codes */
......@@ -329,6 +341,7 @@ typedef struct
#define Toolbox_BadResFileVersion (Toolbox_ErrorBase + 0xc)
#define Toolbox_BadFlags (Toolbox_ErrorBase + 0xd)
#define Toolbox_BadGetSysInfoReason (Toolbox_ErrorBase + 0xe)
#define Toolbox_BadMemoryReason (Toolbox_ErrorBase + 0xf)
/* ------------------------------------------- Toolbox Service Calls ---------------------------------- */
......@@ -338,5 +351,6 @@ typedef struct
#define Service_ToolboxStarting (Service_ToolboxBase + 0)
#define Service_ToolboxTaskBorn (Service_ToolboxBase + 1)
#define Service_ToolboxTaskDied (Service_ToolboxBase + 2)
#define Service_ToolboxDying (Service_ToolboxBase + 3)
#endif
; Copyright 1998 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; File: toolboxmem.s
; Purpose: veneers onto Toolbox memory allocation SWIs
; Author: Kevin Bracey
; History: 22-Nov-96: KJB: created
XToolbox_Memory * &64EF9
AREA |ToolboxMemCode|,CODE,READONLY,PIC
EXPORT toolbox_memory_alloc
EXPORT toolbox_memory_free
EXPORT toolbox_memory_extend
toolbox_memory_alloc
MOV R12,LR
MOV R1,R0
MOV R0,#0
SWI XToolbox_Memory
MOVVS R0,#0
MOVS PC,R12
toolbox_memory_free
MOV R12,LR
MOV R1,R0
MOV R0,#1
SWI XToolbox_Memory
MOVS PC,R12
toolbox_memory_extend
MOV R12,LR
MOV R2,R1
MOV R1,R0
MOV R0,#2
SWI XToolbox_Memory
MOVVS R0,#0
MOVS PC,R12
END
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