.TITLE DBSLDR ... Database Template Loader .IDENT /020283/ .ENABL LC ; ; ; ; Written by Ray Di Marco ; 29-Apr-82. ; ; Version 290482/04 ; ; ;--------------------------------------------------------------------------- ; ; ; This module is called to load and re-locate database TEMPLATEs needed by ; DBSMNG CUSPs to access databases. The caller passes the address of a .ASICZ ; string to the module in register R0. The routine loads and relocates the ; specified file, and returns to the user the load address in R0. ; ; The structure of a TEMPLATE file is as produced by the DBSFRM macros. To ; allow the user more flexibility, this module can actualy load templates that ; have been linked with a DBSMNG CUSP (viz with DBSEDT), as long as the new ; version of the DBSFRM macros were used to assemble the template, and it was ; linked lowest in memory. ; ; The routine uses the RT-11 .SETTOP call to obtain as much memory as possible ; from the monitor, and the .LIMIT macro/linker dirrective to determine the ; amount of memory used by the program code. The TEMPLATE file is loaded ; dirrectly above the last location declared 'used' by the linked (ie the ; second word returned in the .LIMIT dirrective). ; ; As this is an initialization routine, it destroys all registers. ; .SBTTL Modifications ; ; ; 12-May-82 Logic error caused the size of the template to calculated as ; one word less than actually was; this resulted in last byte ; or two not being loaded. Fixed by adding an extra INC in ; template size calculation code. ; ; 04-Jan-83 make MEMTOP and MEMFRE globals ; ; 02-Feb-83 major modes so that MEMMNG routine used to gain memory ; needed to load template; new version based on code ; in DBSFOR (LOADER routine) used to load template. ; .SBTTL Declarations ; ; .MCALL .PRINT,.EXIT ; RT-11 .MCALL ABORT,.PUSH,.POP ; DBSLIB .MCALL FILSPT ; get file support macros FILSPT ; set up file support system ; .GLOBL DBSLDR ; entry point .GLOBL MEMMNG ; obtain memory ; ; .PSECT CODE ; open code section ; ====== ==== ; .SBTTL Routine - "DBSLDR" ... Load TEMPLATE into memory ; ; This routine is called to load the TEMPLATE contained in the file whose ; name is passed in R0 into MEMORY; the TEMPLATE is relocated by this routine ; and its load address returned in R0. ; ; We start of by associating a FDB via which we can access the template. ; DBSLDR: .PUSH ; save registers MOV R0,R4 ; R4 -> name PURGE #LDRFDB ; ensure FDB free NAME STRING=R4,EXTENS=#^RSAV,ERROR=700$ LOOKUP ERROR=700$ ; locate file BIS #F.NERR,FDB.FL(R5) ; disable error messages ; ; Have to read in file header so that can calculate the start address ; (as block number and offset within block) and size of TEMPLATE. ; MOV #HEADER,R4 ; R4 -> Buffer READ BUFFER=R4,SIZE=#40,ERROR=720$; read in header block ; ; Setup registers and read in template ; CALL 1000$ ; setup registers READ BUFFER=R1,BLOCK=R2,SIZE=R3,ERROR=720$; read in file ; ; ; ; Relocate pointers in the RDT and KDT tables. MOV R1,R2 ; R2 = start of template SUB R4,R1 ; R1 = relocation offset .IRP X,<0,2,16,20,22,30,32> ; ... relocate the index pointers ... ADD R1,X'(R2) ; reloacte pointers .ENDR ; ----------------------------------- .IRP X,<16,20,22> ; ... adjust the FDBs ... MOV X'(R2),R3 ; R3 -> FDB ADD R1,FDB.NR(R3) ; .RAD50 file name pointer ADD R1,FDB.NA(R3) ; .ASCII file name pointer ADD R1,FDB.BF(R3) ; buffer address .ENDR ; ----------------------------------- MOV 2(R2),R3 ; R3 -> first FDE MOV 4(R2),R4 ; R4 = number of field entries BEQ 750$ ; none -> fatal 600$: ADD R1,22(R3) ; update pointer to name ADD #40,R3 ; R3 -> next field entry SOB R4,600$ ; loop till all done ; ----------------------------------- MOV 32(R2),R3 ; R3 -> first KDE MOV 34(R2),R4 ; R4 = number of key entries BEQ 760$ ; none -> fatal 610$: ADD R1,22(R3) ; update pointer to name ADD #40,R3 ; R3 -> next key entry SOB R4,610$ ; loop till all done ; ----------------------------------- ; ; Exit with R0 pointing to start of template ; PURGE ; release the FDB MOV R2,R0 ; R0 -> template .POP ; restore RETURN ; all done ; ; ; Error abort points ; 700$: ABORT 720$: STATUS ABORT 750$: ABORT 760$: ABORT ; ; ; This code is called with R4 pointing to the start of the file header ; block that has been read into memory; its function is to set up the ; registers as follows ; ; R1 address at which TEMPLATE will be loaded ; R2 number of block in file at which TEMPLATE starts ; R3 size of TEMPLATE in words ; R4 original (in file) address of TEMPLATE ; ; 1000$: MOV 50(R4),R3 ; R3 = estimate of template top BIT #1,40(R4) ; is start address set up? BNE 500$ ; no -> skip MOV 40(R4),R3 ; R3 = better estimate of top address 500$: MOV 42(R4),R2 ; R2 = start of template BIC #777,R2 ; truncate to block boundary SUB R2,R3 ; R3 = estimated template size MOV 42(R4),R1 ; R1 = base address of template SUB R2,R1 ; R1 = template offset ASH #-9.,R2 ; R2 = base template, block number ADD #2,R3 ; R3 = number of words ... ASR R3 ; .... in template INC R3 ; allow for extra word MOV 42(R4),R4 ; R4 = original template address ; ; get block of memory to hold template and exit ; MOV R3,R0 ; R0 = words needed ASL R0 ; R0 = bytes needed CALL MEMMNG ; ask for space MOV R0,R1 ; R1 = load address RETURN .SBTTL Data area ; ; ; .PSECT DATA ; ====== ==== ; ; FDB LDRFDB,CHANNEL=1,SIZE=400 ; used to access database template HEADER: .BLKW 40 ; buffer to read header ; ; .END