home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
458.lha
/
MoveSSP_v1.1
/
MoveSSP.a
< prev
next >
Wrap
Text File
|
1990-12-12
|
8KB
|
349 lines
; MoveSSP.a
; Copy the system's stack from Chip RAM to Fast RAM, generally to be called
; as part of one's Startup-Sequence.
;
; Written by Christoper A. Wichura (caw@miroc.chi.il.us)
; Created: 3/4/90
;
; Version 1.1 modified by J. Edward Hanway (jeh) - 4/18/90
; - Frees the 6K of chip memory used by the original SSP.
; - Treats memory outside of 24-bit address space as FAST RAM.
; - User Supervisor() instead of SuperState()/UserState() so it can (and should)
; be run ahead of SetPatch 1.34.
; (Assemble with A68K & BLINK)
;
; This is really a conversion of MoveSSP.c by Roger Uzun into 68k code,
; with various `optimizations' being made as well.
;
; The arp library is required to use this program. I used it for its
; FPrintf function as well as getting an easy way out of not having to
; decide if I needed to close the stdout filehanle, which is opened with
; ArpOpen() and closed (if needed) by ArpExit().
;
; It is fully residentiable, though to do so would be stupid as it will
; not do anything after the first invocation.
;
; This file supports being called by WorkBench. However, you will have
; to supply your own `.info' file for it (if anyone comes up with a really
; nice looking one then UUencode it and send it to me).
;
; I moved it to ML to make it smaller (i.e., no longer needed the Lattice
; startup code which eats a bunch of memory up). I also added some
; messages to let you know what has happened, which MoveSSP.c didn't do.
;
; I have not noticed any tremendous speed increase in using this program,
; but it can't really hurt. The people who will get the biggest benefit
; from it are those with 32 bit RAM.
;
; The UserState() function is broken in 1.3 and earlier, but SetPatch for 1.3.2
; fixes it. However, it's best to run this thing before SetPatch so that the
; old stack space can be merged into a larger region of CHIP RAM. (SetPatch
; allocates a few bytes at the very top of CHIP RAM.) So this function uses the
; Supervisor() function instead.
NOLIST
INCLUDE "libraries/ArpBase.i"
INCLUDE "exec/execbase.i"
INCLUDE "exec/memory.i"
INCLUDE "libraries/dosextens.i"
LIST
XREF _LVOOpenLibrary
XREF _LVOCloseLibrary
XREF _LVOForbid
XREF _LVOWaitPort
XREF _LVOGetMsg
XREF _LVOReplyMsg
XREF _LVOAllocMem
XREF _LVODisable
XREF _LVOEnable
XREF _LVOSupervisor
XREF _LVOFreeMem
CALL MACRO
jsr _LVO\1(a6)
ENDM
SECTION MoveSSP,CODE
; arp resident tag goes here
RESIDENT 4*1024
init:
movem.l d2-d7/a2-a5,-(sp)
movea.l 4,a6
lea ARPlib(pc),a1
moveq #39,d0
CALL OpenLibrary
tst.l d0
bne.s __main
lea DOSlib(pc),a1
CALL OpenLibrary
tst.l d0
beq.s bomb
move.l d0,a6
CALL Output
move.l d0,d1
beq.s bomb
lea Msg1(pc),a0
move.l a0,d2
moveq #Msg1Len,d3
CALL Write
move.l a6,a1
movea.l 4,a6
CALL CloseLibrary
moveq #0,d0
bomb:
addq.l #8,sp
rts
WBMSG EQUR d7
LOMEM EQUR d6
HIMEM EQUR d5
SIZE EQUR d4
STDOUT EQUR d3
NEWMEM EQUR a2
MYPROC EQUR a3
__main:
movea.l a6,a5 ; save exec base pointer
movea.l d0,a6 ; put arp base where we can use it
CALL Output ; get stdout handle
move.l d0,STDOUT
move.l ThisTask(a5),MYPROC ; get pointer to our process
; check for workbench
moveq #0,WBMSG ; clear wb flag
tst.l pr_CLI(MYPROC)
bne.s FromCLI
exg a5,a6 ; get exec base
lea pr_MsgPort(MYPROC),a0
CALL WaitPort
lea pr_MsgPort(MYPROC),a0
CALL GetMsg
move.l d0,WBMSG ; save wbench startup message
exg a5,a6 ; get back arp base
; we need a console window for workbench users
lea Console.MSG(pc),a0
move.l a0,d1
move.l #MODE_NEWFILE,d2
; we use arpopen to get the console. thus the ArpExit call at the end of
; this file will free it for us automatically if we got it.
CALL ArpOpen
move.l d0,STDOUT ; did we get the console
beq Exit ; no so die
lsl.l #2,d0
movea.l d0,a0
move.l fh_Type(a0),pr_ConsoleTask(a3)
FromCLI:
lea Banner.MSG(pc),a0 ; print a blurb
move.l STDOUT,d0 ; get stdout
CALL FPrintf
move.l SysStkLower(a5),LOMEM ; get low stack ptr
move.l SysStkUpper(a5),HIMEM ; get high stack ptr
; check if we are already in fast memory
cmpi.l #$200000,HIMEM
bcs.s 1$ ; in chip memory
cmpi.l #$C00000,HIMEM
bcs.s 3$ ; in FAST autoconfig memory
cmpi.l #$1000000,HIMEM
bcs.s 1$ ; in slow $C00000 memory
3$ lea AlreadyFast.MSG(pc),a0
move.l STDOUT,d0 ; get stdout
CALL FPrintf
bra Exit
; we need to move the thing over so figure out its size. we will print
; its current start address before moving it, though.
1$: move.l HIMEM,SIZE
sub.l LOMEM,SIZE
move.l SIZE,-(sp) ; push size onto stack for printf
move.l HIMEM,-(sp) ; push himem onto stack for printf
move.l LOMEM,-(sp) ; push lomem onto stack for printf
movea.l sp,a1 ; get address of args array
lea OldLoc.MSG(pc),a0 ; get message to print
move.l STDOUT,d0 ; get stdout
CALL FPrintf ; call ARP print command
lea 12(sp),sp ; pop values off stack
; we need to allocate a new stack in fast memory for these folks
move.l SIZE,d0
move.l #MEMF_FAST|MEMF_CLEAR,d1
exg a5,a6
CALL AllocMem
exg a5,a6
tst.l d0
bne.s 2$
lea NoFast.MSG(pc),a0
move.l STDOUT,d0 ; get stdout
CALL FPrintf
bra Exit
2$ movea.l d0,NEWMEM
; ok we have new memory so now we need to copy the stack over
exg a5,a6 ; get execbase in a6
CALL Disable ; freeze the system while we do the copy
movea.l LOMEM,a0
movea.l NEWMEM,a1
move.l SIZE,d0
lsr.l #2,d0 ; size in longwords
; now fix pointers in exec base
move.l NEWMEM,HIMEM ; make new himem pointer
add.l SIZE,HIMEM
move.l NEWMEM,SysStkLower(a6)
move.l HIMEM,SysStkUpper(a6)
move.l a5,-(sp)
lea.l SuperCode(pc),a5
CALL Supervisor ; go to supervisor mode
move.l (sp)+,a5
; now find the free CHIP memory list and change its upper bound
move.l LOMEM,HIMEM ; get HIMEM again
add.l SIZE,HIMEM
move.l MemList+LH_HEAD(a6),d0 ; first MemHeader node of free memory list
WalkMemList:
move.l d0,a0
; test for chip memory -- commented out so that $C00000 memory will also be freed
; btst.b #MEMB_CHIP,MH_ATTRIBUTES+1(a0) ; is it a chip memory node?
; beq.s 1$
cmp.l MH_UPPER(a0),LOMEM ; SSP should have been at the top of CHIP RAM
bne.s 1$
move.l HIMEM,MH_UPPER(a0) ; Extend the CHIP memory region
bra.s ReEnable
1$: move.l (a0),d0 ; try next node
bne.s WalkMemList
moveq #0,HIMEM ; indicate that memory wasn't freed
ReEnable:
CALL Enable ; re-enable interrupts
exg a5,a6 ; reload ARP base
; ok we have fixed everything up so print new address of stack
move.l NEWMEM,-(sp) ; push new location onto stack for printf
movea.l sp,a1 ; get address of args array
lea NewLoc.MSG(pc),a0 ; get message to print
move.l STDOUT,d0 ; get stdout
CALL FPrintf ; call ARP print command
addq #4,sp ; pop value off stack
; if the original stack can't freed, print a warning
tst.l HIMEM
beq.s 1$
; free the old stack space.
move.l LOMEM,a1 ; address of MemChunk
move.l SIZE,d0
exg a5,a6
CALL FreeMem
exg a5,a6
bra.s Exit
1$: lea CantFree.MSG(pc),a0
move.l STDOUT,d0 ; get stdout
CALL FPrintf
Exit:
tst.l WBMSG ; started from workbench?
beq.s 1$
; if we started from workbench then call dos' Delay() function to give
; them time to see what we said
move.l #300,d1
CALL Delay
exg a5,a6 ; get exec base
CALL Forbid ; forbid and return startup message to
movea.l WBMSG,a1 ; workbench
CALL ReplyMsg
exg a5,a6 ; get back arp base
1$ movem.l (sp)+,d2-d7/a2-a5
moveq #0,d0
CALL ArpExit
; The supervisor code which actually adjusts the ssp
SuperCode:
bra.s 2$
1$: move.l (a0)+,(a1)+ ; copy the entire stack
2$: dbra d0,1$
sub.l LOMEM,sp ; find position in old stack
add.l NEWMEM,sp ; get position in new stack
rte
; here we have all the text and whatnot for this program
DOSlib dc.b "dos.library",0
Msg1 dc.b "You need "
ARPlib dc.b "arp.library",0
dc.b " V39+",10,0
Msg1Len EQU *-Msg1
Console.MSG:
dc.b 'CON:40/30/560/45/MoveSSP',0
Banner.MSG:
dc.b 'MoveSSP v1.1 ',$a9,' 1990 by Christoper A. Wichura '
dc.b '(caw@miroc.chi.il.us)',10
dc.b 'Modifications by J. Edward Hanway',10,0
AlreadyFast.MSG:
dc.b 'SSP is already located in fast memory.',10,0
NoFast.MSG:
dc.b 'Could not allocate fast memory for new SSP.',10,0
OldLoc.MSG:
dc.b 'SSP currently located at $%08lx-$%08lx (%ld bytes).',10,0
NewLoc.MSG:
dc.b 'Moved to $%08lx in fast memory.',10,0
CantFree.MSG:
dc.b 'Could not free the original SSP memory.',10,0
END