Microsoft Macro Assembler Version 5.10 5/22/07 09:03:11 sysinit Page 1-1 ; Initialization for Steve's C&T CS8230 System ; It works or else complain to admin@stevedeppe.com 0000 primary segment use16 assume cs:primary,ds:primary,ss:primary 00E0 org 0e0h dss 4,mctl ;memory controller data dss 1,extf ;if zero, E800-EFFF region found unused 0100 org 100h 0100 main proc near 0100 B8 0305 mov ax,305h 0103 33 DB xor bx,bx 0105 CD 16 int 16h ;max keyboard rate, min delay 0107 B8 351E mov ax,351eh ;address diskette parameter table 010A CD 21 int 21h 010C 26: C6 47 0A 04 mov mb es:[bx+10],4 ;500ms startup 0111 26: C6 47 02 FF mov mb es:[bx+2],-1 ;14-second delay until motor off 0116 E8 048C R call sychk ;80386 or later else barf 0119 0F 01 E0 smsw ax 011C 24 01 and al,1 011E 0F 85 029E R jnz pmode ;cpu not in real mode 0122 B0 0A mov al,0ah 0124 E6 22 out 22h,al 0126 E4 23 in al,23h 0128 0A C0 or al,al 012A 0F 85 02A5 R jnz mcnp ;system has no 82c302 ; enable 64k ram at A000, 160k-192k ram at C000 012E B9 0003 mcp: mov cx,3 0131 33 DB xor bx,bx 0133 FA cli ;disable interrupts 0134 BA 0022 rmcl: mov dx,22h ;82c302 controller index port 0137 B0 0C mov al,0ch 0139 02 C1 add al,cl 013B EE out dx,al ;address configuration register 013C 66| C1 E3 08 shl ebx,8 0140 42 inc dx ;82c302 controller data port 0141 EC in al,dx ;read configuration register 0142 8A D8 mov bl,al 0144 E2 EE loop rmcl ;read for FE,DC,BA 0146 FB sti ;enable interrupts 0147 66| 89 1E 00E0 R mov ml mctl,ebx ;save configuration 014C 66| 89 1E 0488 R mov ml mv2,ebx 0151 66| B8 0003FFFF mov eax,3ffffh 0157 66| 23 D8 and ebx,eax 015A 66| 33 D8 xor ebx,eax 015D 0F 85 02AC R jnz mcerr ;A000-E7FF must be on I/O channel to start 0161 FA cli ;disable interrupts 0162 B8 0DF0 mov ax,0df0h ;register D, data F0 (B,A) 0165 E8 01D4 R call wctl ;set A000-AFFF system ram, B000-BFFF I/O 0168 32 C0 xor al,al ;register E, data 00 (D,C) 016A E8 01D4 R call wctl ;set C000-DFFF system ram 016D A0 00E2 R mov al,mctl+2 ;prior setting 03-FF (F,E) 0170 50 push ax 0171 24 F0 and al,0f0h 0173 E8 01D4 R call wctl ;set E000-EFFF system ram, F000-FFFF unchanged 0176 58 pop ax 0177 24 0C and al,0ch ;check whether E800-EFFF was in use 0179 34 0C xor al,0ch 017B A2 00E4 R mov extf,al ;zero if entire region not used 017E FB sti ;enable interrupts ; initialize enabled ram to set parity 017F B8 A000 mov ax,0a000h 0182 B9 4000 mov cx,4000h ;64k/4 (16k dwords) 0185 E8 01DE R call wram ;initialize segment A000-AFFF 0188 80 C4 20 add ah,20h 018B E8 01DE R call wram ;initialize segment C000-CFFF 018E 80 C4 10 add ah,10h 0191 E8 01DE R call wram ;initialize segment D000-DFFF 0194 80 C4 10 add ah,10h 0197 F6 06 00E4 R FF test mb extf,-1 019C 74 02 jz s @f ;region not in use, clear 64k 019E D1 E9 shr cx,1 ;clear 32k only 01A0 E8 01DE R @@: call wram ;initialize segment E000-E[7F]FF ; find last mcb in chain 01A3 B4 52 mov ah,52h 01A5 CD 21 int 21h 01A7 26: 8B 47 FE mov ax,es:[bx-2] 01AB 8E C0 mov es,ax ;addr 1st mcb 01AD 33 F6 mcbl: xor si,si 01AF 26: 8B 5C 03 mov bx,es:[si+3] ;size of block 01B3 43 inc bx ;include mcb 01B4 26: 8A 04 mov al,es:[si] ;mcb flag 01B7 3C 5A cmp al,'Z' 01B9 74 2D jz s lmcb ;end of mcb chain 01BB 3C 4D cmp al,'M' 01BD 0F 85 02B3 R jnz merr ;not an mcb 01C1 8C C0 mov ax,es 01C3 03 C3 add ax,bx 01C5 8E C0 mov es,ax ;address next mcb 01C7 80 FC F0 cmp ah,0f0h 01CA 72 E1 jb mcbl ;continue if not into rom 01CC BE 0333 R abug: mov si,os mbug 01CF B0 FF mov al,-1 01D1 E9 028E R jmp errms ; write middle ram enable mask register 01D4 86 E0 wctl: xchg ah,al 01D6 E6 22 out 22h,al ;index 01D8 40 inc ax 01D9 86 C4 xchg al,ah 01DB E6 23 out 23h,al ;data 01DD C3 ret ; write ram segment ax, length cx 01DE 8E C0 wram: mov es,ax 01E0 33 FF xor di,di ;start at 0 01E2 51 push cx 01E3 F3/ 66| AB rep stosd ;initialize segment 01E6 59 pop cx 01E7 C3 ret ; end block 01E8 26: 8B 44 01 lmcb: mov ax,es:[si+1] ;owner 01EC 0B C0 or ax,ax 01EE 74 40 jz s lbok ;last block is free 01F0 3D 0008 cmp ax,8 01F3 75 35 jnz s lbpgm ;not system block ; block may be a vdisk header, in which case it must be removed 01F5 26: 66| 8B 44 22 mov eax,ml es:[si+22h] 01FA 66| 3D 53494456 cmp eax,53494456h 0200 75 CA jnz s abug ;system block but not vdisk header 0202 06 push es ;save mcb segment 0203 B8 3519 mov ax,3519h 0206 CD 21 int 21h ;get int 19h vector in es:bx 0208 8C C0 mov ax,es 020A 48 dec ax ;s/b address of mcb 020B 59 pop cx 020C 3B C1 cmp ax,cx 020E 75 BC jnz s abug ;int 19 does not vector to this block 0210 26: 8A 07 mov al,es:[bx] ;first op code 0213 3C EA cmp al,0eah 0215 75 B5 jnz s abug ;not far jump 0217 51 push cx ;last mcb segment 0218 1E push ds ;program data segment 0219 B8 2519 mov ax,2519h 021C 26: C5 57 01 lds dx,es:[bx+1] ;far jump operand 0220 CD 21 int 21h ;vector to far jump target instead 0222 1F pop ds 0223 07 pop es 0224 26: 89 74 01 mov es:[si+1],si ;set block as free 0228 EB 06 jmp s lbok 022A 8C CB lbpgm: mov bx,cs 022C 3B C3 cmp ax,bx 022E 75 9C jnz s abug ;if not this program, then what? ; extend mcb chain into enabled middle ram 0230 8C C0 lbok: mov ax,es 0232 26: 03 44 03 add ax,es:[si+3] 0236 3D 9FFF cmp ax,9fffh 0239 75 91 jnz s abug ;ram must end at 9FFF:0 023B 26: 81 44 03 0FFF add mw es:[si+3],0fffh ;extend block to seg AFFE 0241 26: C6 04 4D mov mb es:[si],'M' ;not last block 0245 B8 AFFF mov ax,0afffh 0248 8E C0 mov es,ax 024A 26: C6 04 4D mov mb es:[si],'M' 024E 26: 66| C7 44 01 10000008 mov ml es:[si+1],10000008h ;set 64k system block over video area 0257 B8 C000 mov ax,0c000h 025A 8E C0 mov es,ax 025C 26: C6 04 5A mov mb es:[si],'Z' ;new last block 0260 B8 3000 mov ax,3000h ;set 192k size 0263 F6 06 00E4 R FF test mb extf,-1 0268 74 03 jz s @f ;E800-EFFF region not in use 026A 80 EC 08 sub ah,8 ;reduce 32k (160k) 026D 26: 89 44 03 @@: mov es:[si+3],ax ;set size 0271 26: 89 74 01 mov es:[si+1],si ;owner (free) 0275 C1 E8 06 shr ax,6 ;from paragraphs to kilobytes 0278 05 02C0 add ax,704 ;total with ram added to mcb chain 027B 8E C6 mov es,si 027D 26: A3 0413 mov mw es:[413h],ax ;system memory size 0281 B8 5801 mov ax,5801h 0284 BB 0001 mov bx,1 0287 CD 21 int 21h ;set best-fit allocation strategy ; Termination 0289 BE 0366 R exit: mov si,os mcrlf 028C 32 C0 xor al,al 028E 66| C7 06 0484 R 035B errms: mov ml mv1,os pmsg R 0297 E8 038B R call msout ;write message to stdout 029A B4 4C error: mov ah,4ch 029C CD 21 int 21h ;exit ; Problems 029E BE 02BA R pmode: mov si,os pmms 02A1 B0 01 mov al,1 02A3 EB E9 jmp s errms 02A5 BE 02D7 R mcnp: mov si,os not302 02A8 B0 02 mov al,2 02AA EB E2 jmp s errms 02AC BE 02FC R mcerr: mov si,os ooctl 02AF B0 03 mov al,3 02B1 EB DB jmp s errms 02B3 BE 0320 R merr: mov si,os mcbms 02B6 B0 04 mov al,4 02B8 EB D4 jmp s errms 02BA pmms: da <êcannot run in virtual modeà>,0 02D7 not302: da <ê82c302 memory controller not foundà>,0 02FC ooctl: da <êunexpected middle ram mapping: è6à>,0 0320 mcbms: da <êbroken mcb chainà>,0 0333 mbug: da <êincomprehensible memory configurationà>,0 035B pmsg: da <àsysinit: >,0 0366 mcrlf: da <êmiddle ram enabled and initializedà>,0 038B main endp 04E1 primary ends end main