English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 27 March 2019, 17:14   #1
Geijer
Oldtimer
 
Geijer's Avatar
 
Join Date: Nov 2010
Location: VXO / Sweden
Posts: 153
Run different executables by Kickstart Version

Hi,

I've tried for a couple of years now to get a licens to include som Shell executables to be able to make a disk (ADF) distribution that uses SetPatch. But now I have given up!

The Startup-Sequence starts like this:
Code:
Version >NIL: 36 20
IF WARN
	Echo "	Running on Kickstart 1.x..."
	C:SetPatch_1x >NIL:
Else
and so on...
Version, IF, Echo, Else are all copyrighted and requires permissions to redistribute.


All Kickstarts before 36.20 should use SetPatch_1x command and all newer SetPatch_2x+ (SetPatch licens enables free distribution AFAIK).

Is this a good solution?
Code:
; exec.library
OldOpenLibrary = -$198
CloseLibrary   = -$19e
LIB_VERSION    = $14
LIB_REVISION   = $16

; dos.library
LoadSeg        = -$96
UnLoadSeg      = -$9c
CreateProc     = -$8a

Start:         movem.l    d1-d7/a0-a6,-(sp)
               move.l     4.w,a6

               lea        setpatch2x(pc),a2

               cmp.w      #36,LIB_VERSION(a6)
               bhi        continue
               bcs        pre2

               cmp.w      #20,LIB_REVISION(a6)
               bhi        continue

pre2:          lea        setpatch1x(pc),a2

continue:      move.l     #dosname,a1
               jsr        OldOpenLibrary(a6)      ; a1=libName
               move.l     d0,a6

               move.l     a2,d1
               jsr        LoadSeg(a6)             ; d0=seglist = LoadSeg( d1=name )

               move.l     d0,d3
               beq        closeandexit

               move.l     a2,d1
               move.l     #0,d2
               move.l     #4096,d4
               jsr        CreateProc(a6)          ; d0=process = CreateProc( d1=name, d2=pri, d3=seglist, d4=stackSize )

               move.l     d3,d1
               jsr        UnLoadSeg(a6)           ; d0=success = UnLoadSeg( d1=seglist )

closeandexit:  move.l     a6,a1
               move.l     4.w,a6
               jsr        CloseLibrary(a6)

exit:          movem.l    (sp)+,d1-d7/a0-a6
               moveq.l    #0,d0
               rts

dosname:       dc.b       "dos.library",0
setpatch1x:    dc.b       "C:SetPatch_1x",0
setpatch2x:    dc.b       "C:SetPatch_2x+",0
Is UnLoadSeg dangerous right after CreateProc, how do I wait for SetPatch to finish?

Is there a better way to solve this and be compatible with "all" kickstarts?

Thanks
/Geijer
Geijer is offline  
Old 02 June 2019, 20:57   #2
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,215
Quote:
Originally Posted by Geijer View Post
Is this a good solution? Is UnLoadSeg dangerous right after CreateProc,
No, it is not a good solution, because... you just said it. The segment is in use, so you cannot just release it. Why do you make things complicated? The dos.library v34 already included Execute(), which does everything you need. Just pass it the setpatch name as first argument, and 0 both for input and output.
Thomas Richter is offline  
Old 03 June 2019, 07:35   #3
Geijer
Oldtimer
 
Geijer's Avatar
 
Join Date: Nov 2010
Location: VXO / Sweden
Posts: 153
Quote:
Originally Posted by Thomas Richter View Post
Why do you make things complicated? The dos.library v34 already included Execute(), which does everything you need. Just pass it the setpatch name as first argument, and 0 both for input and output.
Of Course, how could I missed that one! Thanks!
Geijer is offline  
Old 26 June 2019, 23:43   #4
Geijer
Oldtimer
 
Geijer's Avatar
 
Join Date: Nov 2010
Location: VXO / Sweden
Posts: 153
Quote:
Originally Posted by Thomas Richter View Post
No, it is not a good solution, because... you just said it. The segment is in use, so you cannot just release it. Why do you make things complicated? The dos.library v34 already included Execute(), which does everything you need. Just pass it the setpatch name as first argument, and 0 both for input and output.
Hmpf, dos.library Execute() requires C:Run command to exist on Kickstarts pre 36 (or to be more exact, pre version 1.3.2).
Geijer is offline  
Old 27 June 2019, 12:13   #5
patrik
Registered User
 
patrik's Avatar
 
Join Date: Jan 2005
Location: Umeå
Age: 43
Posts: 922
There is no free run replacement?
patrik is offline  
Old 27 June 2019, 12:24   #6
Geijer
Oldtimer
 
Geijer's Avatar
 
Join Date: Nov 2010
Location: VXO / Sweden
Posts: 153
I have given up and will continue without running SetPatch on pre 36 kickstarts.
Geijer is offline  
Old 27 June 2019, 12:58   #7
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Instead of calling CreateProc, you can try calling the loaded code directly. After all, the bcpl return value of LoadSeg is a disguised pointer to the seglist.
So you can multiply it by 4 to get the seglist, do +4 to go to the start of the code, then simply call it.

Something like this :
Code:
 jsr LoadSeg(a6)
 tst.l d0
 beq closeandexit
 move.l d0,-(a7)
 lsl.l #2,d0
 addq.l #4,d0
 move.l d0,a0
 jsr (a0)
 move.l (a7)+,d1
 jsr UnLoadSeg(a6)
meynaf is offline  
Old 27 June 2019, 14:10   #8
Geijer
Oldtimer
 
Geijer's Avatar
 
Join Date: Nov 2010
Location: VXO / Sweden
Posts: 153
Interesting, thanks.
Geijer is offline  
Old 27 June 2019, 14:33   #9
Geijer
Oldtimer
 
Geijer's Avatar
 
Join Date: Nov 2010
Location: VXO / Sweden
Posts: 153
Quote:
Originally Posted by meynaf View Post
Instead of calling CreateProc, you can try calling the loaded code directly. After all, the bcpl return value of LoadSeg is a disguised pointer to the seglist.
So you can multiply it by 4 to get the seglist, do +4 to go to the start of the code, then simply call it.

Something like this :
Code:
 jsr LoadSeg(a6)
 tst.l d0
 beq closeandexit
 move.l d0,-(a7)
 lsl.l #2,d0
 addq.l #4,d0
 move.l d0,a0
 jsr (a0)
 move.l (a7)+,d1
 jsr UnLoadSeg(a6)
Didn't work. SetPatch 1.38 gurus on kickstart 1.2 with #81000009 and SetPatch 45.15 on 3.1 says "has been installed. Patchlist: None."
Geijer is offline  
Old 27 June 2019, 15:31   #10
patrik
Registered User
 
patrik's Avatar
 
Join Date: Jan 2005
Location: Umeå
Age: 43
Posts: 922
It might be that SetPatch uses the arguments sent to first function in an exe - d0 (doscmdlen) and a0 (doscmdbuf, should be the argument string which ends with \n\0).

Also it probably doesn’t hurt to save all non-scratch-registers (d2-d7,a2-a6) before calling and restoring afterwards before you call anything more, I am not sure the first exe function is required to save and restore all non-scratch-registers.
patrik is offline  
Old 27 June 2019, 15:50   #11
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Well, at least i forgot a6 in the code. Better should be :
Code:
 jsr LoadSeg(a6)
 tst.l d0
 beq closeandexit
 movem.l d0/a6,-(a7)
 lsl.l #2,d0
 addq.l #4,d0
 move.l d0,a0
 jsr (a0)
 movem.l (a7)+,d1/a6
 jsr UnLoadSeg(a6)
meynaf is offline  
Old 27 June 2019, 15:51   #12
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
For my productions I've made a Setpatch1.38+FastMemFirst replacement for KS1.x.
Tiny (1084 bytes), 588 resident memory bytes used, fully compatible with the original.
rossPatch hunk0\trampoline (acrx2):      516 bytes

rossPatch hunk1\resident_module (acrx2): 588 bytes


Harmless on KS2.0+.

So a simple solution can be to launch in s-s rossPatch and SetPatch_43.6b in sequence and all systems are patched.
ross is offline  
Old 29 June 2019, 19:04   #13
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,215
Setpatch uses, same as most other executables, ReadArgs() to parse its command line. It does not use arguments fro *a0 and d0. The ReadArgs() parameters are in the (buffered) input stream of process->pr_CIS. It is not so easy to clone a suitable execution environment for ReadArgs(). dos.library RunCommand() does that for you. But then again, System() or Execute() is a much simpler solution. It loads the program and runs it. Execute() already works for kickstart 1.3, though there needs C:Run to be available (at least until SetPatch v34 run).
Thomas Richter is offline  
Old 29 June 2019, 19:15   #14
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,215
Quote:
Originally Posted by patrik View Post
There is no free run replacement?
It would be hard to write one as Run depends on some internals on how to start a shell, and the details changed from 1.x to 2.x. In 1.x, Run is a BCPL program that looks for the shell in the system seglist, then builds a startup-message for the shell and launches (the BCPL) shell through createtask, a function only available on the globvec.

From 2.x up, Run goes through System() (as it should), and let System() do the magic of creating a startup message.

Unfortunately, the way how the startup message for the shell needs to look like differs between the systems.

The Manx C compiler had an (albeit somewhat buggy) fexec() command which let you execute a binary without requiring Run, dos V37 and up has RunCommand(), which is also used by the shell to execute a program in its own context.

I should have an assembler version of fexec() somewhere, but beware, I do not even know whether this works under 2.x as it is mostly not maintained anymore, and it also depends on some deep system knowledge that may no longer be up to date.
Thomas Richter is offline  
Old 30 June 2019, 00:17   #15
Geijer
Oldtimer
 
Geijer's Avatar
 
Join Date: Nov 2010
Location: VXO / Sweden
Posts: 153
Thank you so much for your commitment to the issue, I have now solved it as @ross and @thomas suggested. Starts by always running SetPatch 1.38 and then Execute() SetPatch for 2.0+ if Kickstart is 36+.

Have tested it in several configurations and it seems to work as expected.
Geijer 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
Kickstart 1.3 (v34) Execute without c:run matburton Coders. System 15 30 April 2018 10:58
A500 Kickstart 2.04 won't run any disk drfresh support.Hardware 3 29 December 2016 10:45
How to get Dungeon Master II to run as fast as the PC version? dex support.WinUAE 9 08 September 2016 21:03
run executables as df0: jbl007 support.WinUAE 6 10 March 2015 20:39
What is the best Windows version to run WinUAE ? Torkio support.WinUAE 2 08 May 2013 15:30

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 15:30.

Top

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