English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 19 October 2015, 11:33   #1
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 1,973
ReadArgs implementation for kickstart 1.3

Hi,

I'm "backporting" an asm code from kick 2.0 to kick 1.3, and the code uses ReadArgs, with a big arg structure.
Could re-write a custom args parser but if someone already wrote a similar args parser for kick 1.3 I could use it!

thanks
jotd is offline  
AdSense AdSense  
Old 19 October 2015, 11:44   #2
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 42
Posts: 19,943
Quote:
Originally Posted by jotd View Post
Hi,

I'm "backporting" an asm code from kick 2.0 to kick 1.3, and the code uses ReadArgs, with a big arg structure.
Could re-write a custom args parser but if someone already wrote a similar args parser for kick 1.3 I could use it!

thanks
1.3 (and older) have nearly identical function in DOS but because it is BCPL code, (simple) wrapper is all you need to call it. I'll attach example later today.
Toni Wilen is offline  
Old 19 October 2015, 11:46   #3
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 1,973
That's what I read on aminet but BCPL always puzzled me, and I did not want to invest in it (and the examples seems to be in C), thanks Tony, waiting for the asm example!
jotd is offline  
Old 19 October 2015, 19:10   #4
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 42
Posts: 19,943
I have used following code to simulate ReadArgs() under KS 1.x (based on AROS m68k BCPL support). Parameters are fetched from input stream automatically.

Code:
BCPL_RdArgs = 78

	; a1 = pointer to result array. Must be LONG aligned!
	; a0 = formatting string. BSTR!
	; d0 = size of result array (number of LONGs)
get_args:
	movem.l d2/d3/d4,-(sp)
	move.l d0,d3
	moveq #BCPL_RdArgs,d0
	move.l a0,d1
	lsr.l #2,d1
	move.l a1,d2
	lsr.l #2,d2
	moveq #0,d4
	bsr.s call_bcpl
	movem.l (sp)+,d2/d3/d4
	rts

	; d0 = gv index
	; d1-d4 = bcpl parms

call_bcpl:
	movem.l d2-d7/a2-a6,-(sp)

	move.l d0,d6
	move.l d1,d5

	move.l 4.w,a6
	lea dos(pc),a1
	moveq #0,d0
	jsr -$228(a6)
	move.l d0,a5

	sub.l a1,a1
	jsr -$126(a6) ;FindTask
	move.l d0,a4

	; allocate BCPL stack
	move.l #1500,d0
	move.l #65536+1,d1
	jsr -$c6(a6)
	move.l d0,d7
	beq.s .nomem
	
	movem.l d7/a5/a6,-(sp)

	moveq #0,d0
	move.l d5,d1
	sub.l a0,a0
	move.l d7,a1
	lea 3*4(a1),a1
	move.l 136(a4),a2
	lsl.w #2,d6
	move.l 0(a2,d6.w),a4
	movem.l 46(a5),a5/a6
	jsr (a5) ; call bcpl!
	
	movem.l (sp)+,d7/a5/a6

.nomem:
	move.l d7,a1
	move.l #1500,d0
	jsr -$d2(a6)

	move.l a5,a1
	jsr -$19e(a6)

	movem.l (sp)+,d2-d7/a2-a6
	rts
Example format string (from aca620 ram disk)

Code:
	cnop 0,4
argformat: ; BSTR!
	dc.b 71,"NOAUTOBOOT/S,BOOTPRI/N,OFS/S,DOSTYPE,FILESYS,HIGHCYL/N,BLOCKSPERTRACK/N"
Toni Wilen is offline  
Old 19 October 2015, 23:57   #5
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 1,973
ReadArgs & AllocDosObject

ok ReadArgs BCPL is working. thanks.

Another problem: this code works but needs V36

Code:
AllocInfoBlock:
	STORE_REGS	D1/D2/A0/A1/A6
	move.l	#DOS_FIB,D1
	moveq.l	#0,D2
	move.l	_DosBase,A6
	JSRLIB	AllocDosObject
	tst.l	D0
	beq	.error
	RESTORE_REGS	D1/D2/A0/A1/A6
	rts
This code is supposed to be equivalent but doesn't work (just freezes the process when passed to Examine...)

Code:
AllocInfoBlock:
	STORE_REGS	D1/D2/A0/A1/A6
	move.l	#fib_SIZEOF+4,D0
	move.l	#MEMF_CLEAR,D1
	move.l	_SysBase,A6
	JSRLIB	AllocMem
	tst.l	D0
	beq	.error

	move.l	d0,d1
	; align 4 byte
	addq.l	#4,d0
	and.l	#$FFFFFFFC,D0
	RESTORE_REGS	D1/D2/A0/A1/A6
	rts
Any idea?
And any solution to transparently handle the alignment and the FreeMem?
I was thinking of storing the offset before the returned pointer:
Allocating 1->4 more bytes depending on the alignment and put a 1->4 value here to substract to the passed value, so FreeMem works.

Well, if you have working code, I'd like it!!
jotd is offline  
Old 20 October 2015, 00:51   #6
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 46
Posts: 365
Quote:
Originally Posted by jotd View Post
...

And any solution to transparently handle the alignment and the FreeMem?
I was thinking of storing the offset before the returned pointer:
Allocating 1->4 more bytes depending on the alignment and put a 1->4 value here to substract to the passed value, so FreeMem works.

Well, if you have working code, I'd like it!!
No need to handle the alignment. From the autodocs, on AllocMem:
Code:
RESULT
	memoryBlock - a pointer to the newly allocated memory block.
		If there are no free memory regions large enough to satisfy
		the request, zero will be returned.  The pointer must be
		checked for zero before the memory block may be used!
		The memory block returned is long word aligned.
Are you sure it doesn't freeze on FreeInfoBlock? You probably pass not the correct address to FreeMem. Anyways, eliminating the 'alignment handling' will fix both.
alkis is offline  
Old 20 October 2015, 01:49   #7
Leffmann

 
Join Date: Jul 2008
Location: Sweden
Posts: 2,029
Simplest solution is to reserve space for it in your data segment. No need to allocate, align, zero-fill, or free during run-time.
Leffmann is offline  
Old 20 October 2015, 08:27   #8
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 1,973
The problem of static fib is when you use recursive calls.
Well, I had temporarily commented the FreeMem instruction.
I had some random lockups forever when scanning the directories...
jotd is offline  
Old 20 October 2015, 20:38   #9
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,700
Quote:
Originally Posted by jotd View Post
Code:
	move.l	d0,d1
	; align 4 byte
	addq.l	#4,d0
	and.l	#$FFFFFFFC,D0
As mentioned, you don't need to manually longword-align. But if you are doing that, you probably want to do addq.l #3,d0 instead.
mark_k is offline  
Old 21 October 2015, 01:56   #10
NorthWay
Registered User
 
Join Date: May 2013
Location: Grimstad / Norway
Posts: 391
I could have sworn that AllocMem is quad aligned and documented as such, but if that is what the autodocs says then it is long aligned.
No need to mess with alignment of the return value if all you need is long alignment then.

And yes, you want "add #3" if you are dropping low bits. With 4 you have a fair chance of mushing 4 bytes past your memory - be nice to the guru.

Memwall is always recommended when having memory trouble, and I like to use BDebug from Barfly with history mode so I can backtrack and see what happened before I crash. If I crash cleanly enough to catch it.
NorthWay is online now  
Old 21 October 2015, 11:53   #11
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 1,973
Well, adding 3 bytes kills the chance of freeing it properly unless you return both aligned and misaligned memory.
But anyway, there isn't any alignment problem with AllocMem. Just a problem when you declare your BCPL pointer in assembly code without "CNOP 0,4" directive before.

The problems comes from somewhere else. I hope that some talented fellow will find it.
Happens only randomly when I scan files, and on a "new" amiga with OS3, PFS or SFS... (never happens on a classic 1.3 amiga)
jotd is offline  
Old 21 October 2015, 13:21   #12
NorthWay
Registered User
 
Join Date: May 2013
Location: Grimstad / Norway
Posts: 391
If you have some complete source I can assemble myself then I wouldn't mind testing and see if I can spot anything.
NorthWay is online now  
Old 21 October 2015, 13:25   #13
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 1,973
Yes, complete source of JST 5.0 is in the zone with phxass makefile
needs gnu make & phxass, and assign INCLUDE: to dev_include and include subdirs to reassemble. The source code is quite big (binary is 70Ko) and messy.

If you're familiar with JST/whdload: run a game with a lot of files: Final Fight for instance. Sometimes it locks up during Examine/ExNext phase. I had watched this piece of code for ages and cound not find why it does not work.
Well, apart from that one, I must have improved since I spotted 2 bugs in 1 hour after 19 years of starting the project
jotd is offline  
Old 21 October 2015, 19:03   #14
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 46
Posts: 365
Your FreeInfoBlock, frees the allocated (address+4) and 4 bytes longer size.

ps: by longer size, I mean you free 4 bytes at the end that don't belong to the original allocation
alkis is offline  
Old 21 October 2015, 23:10   #15
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 1,973
nice. I'll fix that. But the bug already occurred when I was using Alloc/FreeDosObject.
and if you notice, FreeMem call is commented
jotd is offline  
Old 13 November 2017, 07:09   #16
jotd
Cat freak
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 46
Posts: 1,973
@Toni (or anyone who can answer) so this works in pre-v36 as it's in a 1.3 command

NOAUTOBOOT/S,BOOTPRI/N,OFS/S,DOSTYPE,FILESYS,HIGHCYL/N,BLOCKSPERTRACK/N

but do the /K options work? I want to use /K/N for instance. Is there some documentation about this feature somewhere?
jotd is offline  
AdSense AdSense  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Best AGA implementation on FPGA? eXeler0 Amiga scene 171 04 February 2016 02:15
StormC V4 sleep() implementation Vot Coders. C/C++ 3 26 May 2013 17:23
Using ReadArgs() from asm oRBIT Coders. General 4 11 May 2010 17:11
Best Amiga E implementation Madcrow Coders. General 1 25 June 2008 01:54
Latest WinUAE Kaillera Implementation Amigaboy project.WinUAE - Kaillera 19 06 December 2004 14:53

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:30.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.29736 seconds with 12 queries