WikiPendium

(beta)

BASEPAGE

WikiPendium :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ec2-3-22-209-115.us-east-2.compute.amazonaws.com

BASEPAGE structure


When an application is loaded in memory, the operating system allocates a block large enough to contain the program file, but it also needs to keep some informations about the loaded program, either to free it upon the program exit, or for the program itself to read for example its command line (for old applications that don't use ARGV? environment variable).

typedef struct basepage {
	VOIDP	p_lowtpa;		/* Pointer to self (bottom of TPA) */
	VOIDP	p_hitpa;		/* Pointer to top of TPA + 1 */
	VOIDP	p_tbase;		/* Pointer to base of TEXT segment */
	LONG	p_tlen;			/* Length of TEXT segment */
	VOIDP	p_dbase;		/* Pointer to base of DATA segment */
	LONG	p_dlen;			/* Length of DATA segment */
	VOIDP	p_bbase;		/* Pointer to base of BSS segment */
	LONG	p_blen;			/* Length of BSS segment */
	char	*p_dta;			/* Pointer to current DTA */
	struct basepage	*p_parent;	/* Pointer to parent's basepage */
	LONG	p_flags;		/* Memory usage flags */
	char	*p_env;			/* Pointer to environment string */

	char	undef[80];		/* Undefined bytes */

	char	p_cmdlin[128];		/* Copy of 128 first bytes of command line */
} BASEPAGE;




When the application is started, the value at 4(sp) in program stack contains a pointer to the application's basepage. This way, the application can know how many bytes it takes in memory, for example to keep itself resident (for a TSR application).

This is also needed because under TOS, all the memory has been allocated to the newly run program, so this one must free the unused memory, or the program will not be able to allocate memory from GEMDOS using Malloc(). The application must also sets its stack pointer.

For a GEM accessory, the basepage is in register a0. In this case, the program's memory has already been shrinked (using Mshrink()?) to the TEXT+DATA+BSS value.

	TEXT

	move.l	a0,d0	; a0 is not zero if the application is launched as a GEM accessory (.ACC file)
	bne.s	is_acc
	move.l	4(sp),d0	; Standard program, basepage is at 4(sp)
is_acc:
	move.l	d0,a0	; Put basepage pointer in an address register

	move.l	#256,d0		; Length of basepage
	add.l	12(a0),d0	; Add TEXT length
	add.l	20(a0),d0	; Add DATA length
	add.l	28(a0),d0	; Add BSS length
	
	lea	stack,sp	; Set new stack

	move.l	d0,-(sp)
	move.l	a0,-(sp)
	clr.w	-(sp)
	move.w	#$4a,-(sp)	; Mshrink()
	trap	#1

	; Here your application code

	clr.w	-(sp)	; Pterm()
	trap	#1

	BSS

	ds.b	8192
stack:
	ds.l	1

	END



See Also

Pexec()

Il n'y a pas de commentaire sur cette page. [Afficher commentaires/formulaire]