English Amiga Board


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

 
 
Thread Tools
Old 19 October 2015, 10:33   #1
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
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  
Old 19 October 2015, 10:44   #2
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
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, 10:46   #3
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
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, 18:10   #4
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
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, 22:57   #5
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
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 19 October 2015, 23:51   #6
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
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, 00:49   #7
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
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, 07:27   #8
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
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, 19:38   #9
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 3,334
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, 00:56   #10
NorthWay
Registered User
 
Join Date: May 2013
Location: Grimstad / Norway
Posts: 839
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 offline  
Old 21 October 2015, 10:53   #11
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
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, 12:21   #12
NorthWay
Registered User
 
Join Date: May 2013
Location: Grimstad / Norway
Posts: 839
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 offline  
Old 21 October 2015, 12:25   #13
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
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, 18:03   #14
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
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, 22:10   #15
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
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, 06:09   #16
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
@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  
Old 31 December 2018, 14:00   #17
PR77
Registered User
 
Join Date: Oct 2017
Location: Germany
Posts: 193
I've put together a based C program (vbcc) to exercise an IO Port on an accelerator card I've developed. Here is the code;

https://github.com/PR77/A500_ACCEL_R...tware/IOTest.c

I am trying to get ReadArgs to compile / work with KS 1.2/1.3. Does anyone know if this KS versions supports ReadArgs and if so, the correct Header file to use?

P.S., If I compile with NDK39 is works super perfect.

EDIT: I know this is an ASM thread but I like to piggyback on existing topics.
PR77 is offline  
Old 31 December 2018, 14:51   #18
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
v36+ (KS2.0).
a/b is offline  
Old 31 December 2018, 15:16   #19
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,161
@PR77 did you read the original question? because no it doesn't, and yes, there's an undocumented way of doing almost the same with Kick 1.3. You can check jst source, I used ReadArgs or kick 1.3 equivalent when < kick 2.0/V36 so JST runs with kickstart 1.3
jotd is offline  
Old 06 February 2023, 12:45   #20
Wepl
Moderator
 
Wepl's Avatar
 
Join Date: Nov 2001
Location: Germany
Posts: 866
if the call to RDARGS is done at program start then the provided BCPL environment can be used:
Code:
BUFLEN = 100    ;in LONGs

                sub.l   a0,a0           ;BCPL standard value
                sub     #BUFLEN*4,a7

                lea     (.template,pc),a3
                move.l  a3,d1
                lsr.l   #2,d1           ;D1 = template
                move.l  a7,d2
                lsr.l   #2,d2           ;D2 = arg array + buffer
                moveq   #BUFLEN-1,d3    ;D3 = size of arg array + buffer (LONGs)
                move.l  (78*4,a2),a4    ;G_RDARGS
                moveq   #12,d0          ;used BCPL stack (a1)
                jsr     (a5)            ;call BCPL
                tst.l   d1              ;result from G_RDARGS
                beq     .badargs

                lea     (.fmt,pc),a3
                move.l  a3,d1
                lsr.l   #2,d1           ;D1 = format
                movem.l (a7),d2-d4
                move.l  (74*4,a2),a4    ;G_WRITEF
                moveq   #12,d0          ;used BCPL stack (a1)
                jsr     (a5)            ;call BCPL
                moveq   #0,d0           ;RETURN_OK
                bra     .end

.badargs        lea     (.e_badargs,pc),a3
                move.l  a3,d1
                lsr.l   #2,d1
                move.l  (73*4,a2),a4    ;G_WRITES
                moveq   #12,d0          ;used BCPL stack (a1)
                jsr     (a5)            ;call BCPL
                moveq   #20,d0          ;RETURN_FAIL

.end            add     #BUFLEN*4,a7
                rts

        CNOP 0,4
.template       dc.b    .template_e-.template_s
.template_s     dc.b    "Arg,Switch/S,Num/K/N"
.template_e
        CNOP 0,4
.e_badargs      dc.b    9,"Bad args",10
        CNOP 0,4
.fmt            dc.b    .fmt_e-.fmt_s
.fmt_s          dc.b    "Arg=%S Switch=%X8 Num=%S",10
.fmt_e
there are still some differences to dos.ReadArgs of course...
Wepl is offline  
 


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 01:15
StormC V4 sleep() implementation Vot Coders. C/C++ 3 26 May 2013 16:23
Using ReadArgs() from asm oRBIT Coders. General 4 11 May 2010 16:11
Best Amiga E implementation Madcrow Coders. General 1 25 June 2008 00:54
Latest WinUAE Kaillera Implementation Amigaboy project.WinUAE - Kaillera 19 06 December 2004 13: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 22:06.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.11494 seconds with 15 queries