Re: Native and global variables
Odd Arild Olsen <[email protected]> Wed, 23 Jun 2004 16:05:05 +0200
| Newsgroups | gmane.comp.hardware.microcontrollers.tini |
|---|---|
| Message-ID | <[email protected]> |
Following up, I propose this code to handle a simple case of global values.
Any comments?
First call this from the Java-code
void Native_InitA()
{
long p1= NatLib_LoadInt(0);
_asm
mov dptr, #LibraryID ; see if we have an ESB installed
lcall NatLib_GetEphemeralStateBlock
jnz Init_MallocEphemeral ;
;
; an ESB exists - some process
; has already called load since
; boot time
;
sjmp Init_Done ;
Init_MallocEphemeral:
mov R2, #8h ; request 8 bytes TODO: use p1 here
mov R3, #0 ;
lcall mm_Malloc ;
jnz Init_Err ;
mov dpl1, dpl ; copy address to
mov dph1, dph ; second dptr
mov dpx1, dpx ; handle is already in R3:R2
mov dptr, #LibraryID ; first dptr is our identifier
lcall NatLib_InstallEphemeralStateBlock
jz Init_Done
Init_Err:
mov a, #java_lang_NullPointerException
Init_Done:
_endasm;
}
Then call this from native functions to obtain the pointer to the data block
base address
void *GetBlockAddress(void)
{
_asm
mov dptr, #LibraryID
lcall NatLib_GetEphemeralStateBlock
//; we now have the pointer in dpl:dph:dpx
jz NM2_Exit
mov a, #java_lang_NullPointerException
NM2_Exit:
ret //; dpl:dph:dpx
_endasm;
return (void *)0;
}
_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini