06 October 2017, 21:27 | #1 |
Zone Friend
Join Date: Apr 2006
Location: Gothenburg/Sweden
Age: 48
Posts: 339
|
Coding a .library in asm?
I'm interested in writing a .library in assembler. What I would be interested in would be some kind of basic example on how to do this properly.. I've got some (very) old assembler-example but I'm having troubles with it so..
Anyone got a library example (suitable for Asm-Pro/Asm-One) lying around? I also notice, experimenting with this, is that once my test-library has loaded I can't seem to compile it again and add new code (without restarting). Obviously once the library has loaded once it stays in memory. I am pretty sure there's a way of "unloading" the library from memory but have no idea how..? I wish we had some kind of stackoverflow for Amiga assembly-coders sometimes. |
06 October 2017, 21:31 | #2 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
|
The command to unload unused libraries is "avail flush" from the shell.
Sent from my Prism II using Tapatalk |
06 October 2017, 21:33 | #3 |
Registered User
Join Date: Oct 2014
Location: Europe
Posts: 470
|
there is also a 'flushlibs' command somewhere.
Edit http://aminet.net/package/util/cli/FlushLibs391 for WB3+ |
06 October 2017, 21:36 | #4 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,335
|
There's assembly source for a sample library in the Amiga ROM Kernel Reference Manual: Libraries.
|
06 October 2017, 21:51 | #5 |
Zone Friend
Join Date: Apr 2006
Location: Gothenburg/Sweden
Age: 48
Posts: 339
|
Thanks guys, looks like my code I already had is pretty similar to that example. However my test-library never seems to get "flushed" (even with flushlibs/avail flush) so the constant rebooting keeps annoying me.
Back to bughunting... |
06 October 2017, 21:54 | #6 |
Registered User
Join Date: Oct 2014
Location: Europe
Posts: 470
|
It only gets flushed if the opencounter is =0.
|
07 October 2017, 14:48 | #7 |
Registered User
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
|
Here is my example code (for PhxAss):
Code:
incdir "include:" include "exec/execbase.i" include "exec/initializers.i" include "exec/resident.i" include "lvo/LVOs.i" ;-------------------------------------------------------------------------- RTS ROMTag DC.W RTC_MATCHWORD DC.L ROMTag DC.L LibEnd DC.B RTF_AUTOINIT Ver DC.B 1 ; library version DC.B NT_LIBRARY Pri DC.B 0 DC.L LibName DC.L LibId DC.L LibInit LibInit DC.L LIB_SIZE + 8 ; 8 = private data DC.L FuncTable DC.L DataTable DC.L Init FuncTable DC.W -1 DC.W Open - FuncTable DC.W Close - FuncTable DC.W Expunge - FuncTable DC.W Null - FuncTable DC.W Func1 - FuncTable DC.W Func2 - FuncTable DC.W -1 DataTable INITBYTE LIB_FLAGS,LIBF_SUMUSED|LIBF_CHANGED INITWORD LIB_REVISION,2 ; library revision DC.W 0 Init MOVEA.L D0,A1 ; testbase MOVEM.L A0/A6,LIB_SIZE(A1) ; seglist, execbase RTS Open ADDQ.W #1,LIB_OPENCNT(A6) BCLR.B #LIBB_DELEXP,LIB_FLAGS(A6) MOVE.L A6,D0 RTS Close SUBQ.W #1,LIB_OPENCNT(A6) BNE.S Null BTST.B #LIBB_DELEXP,LIB_FLAGS(A6) BEQ.S Null Expunge TST.W LIB_OPENCNT(A6) BEQ.S kickout BSET.B #LIBB_DELEXP,LIB_FLAGS(A6) Null MOVEQ #0,D0 RTS kickout MOVEM.L A5-A6,-(SP) MOVEA.L A6,A5 ; testbase MOVEA.L (A6)+,A0 ; removing lib node MOVEA.L (A6),A6 MOVE.L A0,(A6) MOVE.L A6,4(A0) MOVEA.L A5,A1 ; testbase MOVEQ #0,D0 MOVE.W LIB_NEGSIZE(A5),D0 SUBA.W D0,A1 ; start of memblock ADD.W LIB_POSSIZE(A5),D0 MOVEM.L LIB_SIZE(A5),A5-A6 ; seglist, execbase JSR _LVOFreeMem(A6) MOVE.L A5,D0 ; seglist MOVEM.L (SP)+,A5-A6 RTS LibName DC.B "test.library",0 LibId DC.B "test.library 1.2",0 ; just an ID-string ;-------------------------------------------------------------------------- CNOP 0,4 Func1 RTS Func2 RTS CNOP 0,4 LibEnd Last edited by PeterK; 10 October 2017 at 01:51. |
07 October 2017, 16:32 | #8 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Hi PeterK, are you sure about this line?
Code:
FuncTable DC.W -1 InitTable->dataTable is not mandatory, you can construct it 'by hand' in InitRoutine. Last edited by ross; 14 November 2017 at 22:43. |
07 October 2017, 16:43 | #9 |
Registered User
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
|
Yes, if you enclose the FuncTable with -1 at the top and at the bottom, then you can use word distances relative to FuncTable instead of absolute long addresses.
Of course, there are different possibilities to init a library, it's just my favourite example how to do it. |
07 October 2017, 17:01 | #10 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Thanks for the tips
Last edited by ross; 14 November 2017 at 22:43. |
09 October 2017, 04:30 | #11 |
Registered User
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
|
Hey oRBIT "Alter Schwede", how is it going with your library? Any progress so far?
|
09 October 2017, 11:57 | #12 |
Zone Friend
Join Date: Apr 2006
Location: Gothenburg/Sweden
Age: 48
Posts: 339
|
Still experimenting with it, thanks for asking. Real life (kids and stuff you know) taking too much time.
By the way, you're using custom includes with your example? |
09 October 2017, 20:02 | #13 |
Registered User
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
|
Ok, I understand, you have your duties. I've no wife, no kids, no job and my life is boring.
No, there are no custom includes for my libraries. I'm using the OS 3.9 includes and a few related to PhxAss. LVOs.i is just an all-in-one collection of many single LVO files. If you like, I could upload my IconLibDevKit.7z to the Zone, which comes with PhxAss, PhxLnk, PhxAssGUI, some other tools, all includes, autodocs and my configuration. |
09 October 2017, 20:14 | #14 |
Zone Friend
Join Date: Apr 2006
Location: Gothenburg/Sweden
Age: 48
Posts: 339
|
The includes/autodocs (and your LVO-file) might be interesting. I probably have (some of) them but scattered everywhere...
|
09 October 2017, 20:27 | #15 |
Registered User
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
|
The DevKit is zoned now.
|
09 October 2017, 21:24 | #16 |
Zone Friend
Join Date: Apr 2006
Location: Gothenburg/Sweden
Age: 48
Posts: 339
|
Thanks. Got it running in Asm-Pro and it seems to working nicely with "avail flush" aswell.
Thanks. Only one question..How do I know the offsets for my functions? I mean "func1" and "func2" for example in your code? How do I reach them properly? "jsr -???(a6)" Last edited by oRBIT; 09 October 2017 at 21:31. |
09 October 2017, 21:50 | #17 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,335
|
Offset is (-6) × function_number
So Func1 being the fifth function, offset is -30. |
23 October 2017, 23:29 | #18 |
Moderator
Join Date: Nov 2001
Location: Germany
Posts: 866
|
There should be a 'moveq #-1,d0' before the rts at the start.
With that AmigaDOS will tell 'not excutable' when started from the CLI. |
23 October 2017, 23:38 | #19 |
Registered User
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
|
That MOVEQ #-1,D0 and RTS is only for the idiots who are trying to execute a library directly. Nothing bad will happen if you reduce it to the RTS except that the idiots may get a random return code for RC.
But without this MOVEQ #-1,D0 the following resident structure gets a better longword alignment. That's why I remove this useless instruction. Last edited by PeterK; 24 October 2017 at 01:54. Reason: some typos |
24 October 2017, 00:04 | #20 |
Semi-Retired
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,994
|
You could add a nop after the rts if you want alignment. For a library coded in asm you could check source of the sonnet's powerpc.library. Google sonnet Amiga git.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Anyone up for an ASM coding competition? | DanScott | Coders. Asm / Hardware | 526 | 22 September 2018 21:38 |
asm coding compo | meynaf | Coders. Asm / Hardware | 66 | 01 July 2017 22:59 |
3rd tutorial on ASM- and HW-coding | Vikke | Coders. Asm / Hardware | 6 | 26 March 2013 15:57 |
First tutorial on ASM- and HW-coding | Vikke | Coders. Asm / Hardware | 46 | 18 March 2013 12:33 |
2nd tutorial on ASM- and HW-coding | Vikke | Coders. Asm / Hardware | 10 | 17 March 2013 11:49 |
|
|