; ; PowerD startup code - the buggiest one ever? ; Disassembled from AmiGOD2 by Harry Sintonen. ; ; ; When started from shell: ; ; a0 - ptr to argument string, terminated by newline ; d0 - length of the argument string ; [some other registers are set too, only meaningful for BCPL programs] ; ; When started from Workbench/Ambient: ; ; ALL registers are undefined and random. Typically zero. ; _startup movem.l d0/a0,-(sp) move.l (4).w,a6 sub.l a1,a1 jsr (_LVOFindTask,a6) move.l d0,a4 tst.l (pr_CLI,a4) beq.b .iswb movem.l (sp)+,d0/a0 bra.b .from_wb .iswb lea (pr_MsgPort,a4),a0 jsr (_LVOWaitPort,a6) lea (pr_MsgPort,a4),a0 jsr (_LVOGetMsg,a6) move.l d0,(_wbmsg) movem.l (sp)+,d0/a0 .from_wb bsr.b .sub move.l d0,-(sp) tst.l (_wbmsg) beq.b .exit jsr (_LVOForbid,a6) move.l (_wbmsg,pc),a1 jsr (_LVOPermit,a6) .exit move.l (sp)+,d0 rts .sub ; Save commandline pointer and remove the terminating newline. move.l a0,(_cmdline) ; BUG: If started from Workbench/Ambient clr.b (-1,a0,d0.w) ; poke random memory (whatever is in reg ; a0/d0 initially). With Ambient writes to ; address -1 (0xffffffff) (a0 and d0 are ; 0). ; There is a 2nd bug here. If any of the library opens fail ; (pre-37 system for example), the returncode is random, as ; register d2 is not set yet. move.l (4).w,a6 move.l a6,(_execbase) lea (dosname,pc),a1 moveq #37,d0 jsr (_LVOOpenLibrary,a6) move.l d0,(_dosbase) beq.b .nodos move.l d0,a6 jsr (_LVOOutput,a6) move.l d0,(_stdout) jsr (_LVOInput,a6) move.l d0,(_stdin) move.l (4).w,a6 lea (intuiname,pc),a1 moveq #37,d0 jsr (_LVOOpenLibrary,a6) move.l d0,(_intuibase) beq.b .nointui lea (gfxname,pc),a1 moveq #37,d0 jsr (_LVOOpenLibrary,a6) move.l d0,(_gfxbase) beq.b .nogfx jsr (_main) move.l d0,d2 ; Possible 3rd bug here: the code assumes here that _main ; leaves a6 as execbase. If a6 is not execbase, wrong ; functions get called. If execbase is guaranteed by _main ; then this code is ok. move.l (_gfxbase,pc),a1 jsr (_LVOCloseLibrary,a6) .nogfx move.l (_intuibase,pc),a1 jsr (_LVOCloseLibrary,a6) .nointui move.l (_dosbase,pc),a1 jsr (_LVOCloseLibrary,a6) .nodos move.l d2,d0 rts _execbase dc.l 0 _dosbase dc.l 0 _intuibase dc.l 0 _gfxbase dc.l 0 _cmdline dc.l 0 _stdout dc.l 0 _stdin dc.l 0 _wbmsg dc.l 0 dosname dc.b 'dos.library',0 intuiname dc.b 'intuition.library',0 gfxname dc.b 'graphics.library',0