wok annotate linld/stuff/src/MEMTOP.ASM @ rev 20794

Update some WEB_SITE
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Feb 15 11:29:31 2019 +0100 (2019-02-15)
parents a5b6457fb890
children be1594cae466
rev   line source
pascal@19515 1 ;***************************************************************
pascal@19515 2 ;****** This file is distributed under GPL
pascal@19515 3 ;***************************************************************
pascal@19515 4 ideal
pascal@19515 5 %crefref
pascal@19515 6 %noincl
pascal@19515 7 %nomacs
pascal@19636 8 ifdef NO386
pascal@19636 9 p8086
pascal@19636 10 else
pascal@19515 11 p386
pascal@19636 12 endif
pascal@19515 13
pascal@20451 14 group DGROUP _TEXT,_BSS
pascal@19515 15 assume cs:DGROUP,ds:DGROUP
pascal@19515 16
pascal@19515 17
pascal@19515 18 segment _BSS byte public use16 'BSS'
pascal@19515 19
pascal@19515 20 saved15 dd ?
pascal@19515 21
pascal@19515 22 ends _BSS
pascal@19515 23
pascal@19515 24
pascal@19515 25 segment _TEXT byte public use16 'CODE'
pascal@19515 26
pascal@19515 27 ;***************************************************************
pascal@19515 28 ;u32 memtopz();
pascal@19515 29 ;***************************************************************
pascal@19515 30 proc _memtopz near
pascal@19515 31 ;***************************************************************
pascal@19515 32 ;u32 memtop_e801()
pascal@19515 33 ;***************************************************************
pascal@19515 34 ; proc _memtop_e801 near
pascal@19515 35
pascal@19515 36 xor cx,cx ;fix to work around buggy
pascal@19515 37 xor dx,dx ; BIOSes which dont clear/set
pascal@19515 38 stc ; carry on pass/error of
pascal@19515 39 mov ax,0E801h
pascal@19515 40 int 15h
pascal@19515 41 jc @@err
pascal@20453 42
pascal@20453 43 xchg ax,cx ;kludge to handle BIOSes
pascal@20453 44 jcxz @@use_cxdx ; which report their extended
pascal@20453 45 ; memory in AX/BX rather than
pascal@20453 46 ; CX/DX. The spec I have read
pascal@19515 47 @@use_axbx: mov dx,bx ; seems to indicate AX/BX
pascal@19882 48 xchg ax,cx ; are more reasonable anyway...
pascal@20453 49 @@use_cxdx: ;now: dx=64k units above 16m
pascal@20453 50 ; ax=1k units above 1m below 16m (max 3c00h)
pascal@20510 51 or dx,dx
pascal@19515 52 jz tokb ;dx=0 here, ax=kbs above 1m
pascal@19515 53 xor ax,ax ;ignore info on low 16M (assume full)
pascal@19515 54 ;add dx,100h ;account for low 16M
pascal@19515 55 inc dh ;account for low 16M (optimized)
pascal@19515 56 ret
pascal@19515 57 @@err:
pascal@19515 58 ; xor ax,ax
pascal@19515 59 ; cwd
pascal@19515 60 ; ret
pascal@19515 61 ; endp _memtop_e801
pascal@19515 62
pascal@19515 63
pascal@19515 64 ;***************************************************************
pascal@19515 65 ;u32 memtop_88()
pascal@19515 66 ;***************************************************************
pascal@19515 67 ; proc _memtop_88 near
pascal@19515 68
pascal@19515 69 mov ah,88h
pascal@19515 70 int 15h ;ax=kbs above 1m
pascal@20142 71 cmc ; error: cf=1 or ax=0
pascal@20142 72 sbb dx,dx
pascal@20142 73 and ax,dx ;
pascal@20142 74 jnz tokb ;happens on big mem systems
pascal@19879 75
pascal@19879 76 ;***************************************************************
pascal@19879 77 ;u32 memtop_cmos()
pascal@19879 78 ;***************************************************************
pascal@19879 79
pascal@19879 80 ;memtop_cmos:
pascal@19879 81 pushf
pascal@19879 82 call rdcmos17
pascal@19879 83 popf
pascal@19515 84 tokb:
pascal@19634 85 xor dx,dx
pascal@19515 86 add ah,4h ;account for 1024 low kb
pascal@19515 87 adc dx,dx ; (optimized to death)
pascal@19883 88 mov cl,10 ;multiply by 1024
pascal@19515 89 ifndef NO386
pascal@19883 90 shld dx,ax,cl
pascal@19883 91 shl ax,cl ; (kbytes -> bytes)
pascal@19515 92 else
pascal@20528 93 db 0A9h ; test ax,04B1h
pascal@20528 94 global N_LXLSH@4:near
pascal@20528 95 N_LXLSH@4:
pascal@20528 96 mov cl,4
pascal@20142 97 global N_LXLSH@:near
pascal@20142 98 N_LXLSH@:
pascal@19883 99 mov ch,0
pascal@19515 100 @@lp:
pascal@19883 101 shl ax,1
pascal@19515 102 rcl dx,1
pascal@19515 103 loop @@lp
pascal@19515 104 endif
pascal@19883 105 ret
pascal@19883 106
pascal@19515 107 ; endp _memtop_88
pascal@19515 108
pascal@19884 109 ifdef NO386
pascal@19884 110 global N_LXURSH@:near
pascal@19884 111 global N_LXURSH@4:near
pascal@19884 112 ; proc N_LXURSH@4 near
pascal@19884 113 N_LXURSH@4:
pascal@19884 114 mov cl,4
pascal@19884 115 N_LXURSH@:
pascal@19884 116 mov ch,0
pascal@19884 117 @@loop:
pascal@19884 118 shr dx,1
pascal@19884 119 rcr ax,1
pascal@19884 120 loop @@loop
pascal@19884 121 ret
pascal@19884 122
pascal@19884 123 ; endp N_LXURSH@4
pascal@19884 124
pascal@19884 125 endif
pascal@19884 126
pascal@19884 127
pascal@19515 128 ; proc _memtopz near
pascal@19515 129
pascal@19515 130 ; call _memtop_e801
pascal@19515 131 ; jnz @@ok
pascal@19515 132 ; call _memtop_88
pascal@19515 133 ; jnz @@ok
pascal@19879 134 ; jmp memtop_cmos
pascal@19515 135
pascal@20142 136 rdcmos17: cli
pascal@20142 137 mov al,18h ; read bytes 17-18 from CMOS
pascal@19515 138 call @@rdcmos
pascal@19515 139 mov ah,al
pascal@19515 140 mov al,17h
pascal@19515 141 @@rdcmos: out 70h,al
pascal@19515 142 call @@ret
pascal@19515 143 in al,71h
pascal@19515 144 @@ret:
pascal@19515 145 ret
pascal@19515 146
pascal@19515 147
pascal@19515 148 ;***************************************************************
pascal@19515 149 ;u32 memtop();
pascal@19515 150 ;***************************************************************
pascal@19515 151 global _memtop:near
pascal@19515 152 _memtop:
pascal@19515 153 call _memtopz
pascal@19515 154 mov cx,40h ; min 4m
pascal@19515 155 ; If reported mem is ridiculously low, presume
pascal@19515 156 ; we had trouble detecting memory size
pascal@19515 157 cmp dx,cx
pascal@19515 158 jb @@set
pascal@20451 159 extrn _topmem:dword
pascal@20528 160 mov cx,[word _topmem+2]
pascal@20528 161 inc cx ; jcxnz
pascal@20528 162 loop @@topmemset
pascal@20528 163 mov ch,10h ; default = max 256m
pascal@20528 164 @@topmemset:
pascal@19515 165 ; Kernel can have trouble with initrd at very high addr:
pascal@19515 166 ; limit mem top to 256m
pascal@19515 167 cmp dh,ch
pascal@19515 168 jb @@done
pascal@19515 169 @@set:
pascal@19515 170 xchg ax,cx
pascal@19515 171 cwd
pascal@19515 172 xchg ax,dx
pascal@19515 173 @@done:
pascal@19515 174 ; Round down to page boundary.
pascal@19515 175 ; Or else initrd's tail may end up in last, partial page.
pascal@19515 176 ; Kernel will refuse to use such initrd.
pascal@19515 177 and ax,0f000h
pascal@19515 178 ;@@ok:
pascal@19515 179 ret
pascal@19515 180
pascal@19515 181 endp _memtopz
pascal@19515 182
pascal@19515 183 ;***************************************************************
pascal@19515 184 ;void hook_int15_88();
pascal@19515 185 ;***************************************************************
pascal@19515 186 global _hook_int15_88:near
pascal@19515 187 proc _hook_int15_88 near
pascal@19515 188
pascal@19515 189 ifndef xmm_hook
pascal@19515 190 mov ax,4300h
pascal@19515 191 int 2fh
pascal@19571 192 cmp al,80h ; 80h = XMS driver installed
pascal@19515 193 je @@skip
pascal@19515 194 endif
pascal@19883 195 xor bx,bx
pascal@19883 196 mov es,bx
pascal@19571 197 ifndef NO386
pascal@19876 198 push cs
pascal@19876 199 push offset int15_88
pascal@19876 200 pop eax
pascal@19883 201 xchg eax,[es:bx+15*4]
pascal@19515 202 mov [saved15],eax
pascal@19515 203 else
pascal@19876 204 mov ax,offset int15_88
pascal@19883 205 xchg ax,[es:bx+15*4]
pascal@19515 206 mov [word saved15],ax
pascal@19876 207 mov ax,cs
pascal@19883 208 xchg ax,[es:bx+15*4+2]
pascal@19515 209 mov [word saved15+2],ax
pascal@19515 210 endif
pascal@19515 211 @@skip:
pascal@19515 212 ret
pascal@19515 213 int15_88:
pascal@19515 214 cmp ah,88h
pascal@19515 215 je @@do88
pascal@19876 216 @@jmp_saved15:
pascal@19515 217 jmp [saved15]
pascal@19515 218 @@do88:
pascal@19515 219 pushf
pascal@19876 220 call @@jmp_saved15
pascal@20510 221 or ax,ax
pascal@19515 222 jnz @@iret
pascal@19515 223
pascal@19515 224 ;****** Read extended mem size (CMOS bytes 17h,18h (lo,hi))
pascal@19515 225 call rdcmos17
pascal@19515 226 @@iret:
pascal@19515 227 iret
pascal@19515 228
pascal@19515 229 endp _hook_int15_88
pascal@19515 230
pascal@19515 231 ends _TEXT
pascal@19515 232
pascal@19515 233 end
pascal@19515 234
pascal@19515 235 ;###### END OF FILE ############################################