vesacon: if a custom font is loaded, use it instead of the BIOS font
[syslinux.git] / highmem.inc
blobb8949350b9c2c81414bc0bbc4621a8c04d1c9c41
1 ;; -----------------------------------------------------------------------
2 ;;
3 ;;   Copyright 1994-2004 H. Peter Anvin - All Rights Reserved
4 ;;
5 ;;   This program is free software; you can redistribute it and/or modify
6 ;;   it under the terms of the GNU General Public License as published by
7 ;;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 ;;   Boston MA 02111-1307, USA; either version 2 of the License, or
9 ;;   (at your option) any later version; incorporated herein by reference.
11 ;; -----------------------------------------------------------------------
14 ;; highmem.inc
16 ;; Probe for the size of high memory.  This can be overridden by a
17 ;; mem= command on the command line while booting a new kernel.
20                 section .text
23 ; This is set up as a subroutine; it will set up the global variable
24 ; HighMemSize.  All registers are preserved.  Assumes DS == CS.
26 highmemsize:
27                 push es
28                 pushad
31 ; First, try INT 15:E820 (get BIOS memory map)
33 get_e820:
34                 xor ebx,ebx                     ; Start with first record
35                 mov dword [E820Max],-(1 << 20)  ; Max amount of high memory
36                 mov dword [E820Mem],ebx         ; Detected amount of high memory
37                 mov es,bx                       ; Need ES = DS = 0 for now
38                 jmp short .do_e820              ; Skip "at end" check first time!
39 .int_loop:      and ebx,ebx                     ; If we're back at beginning...
40                 jz .e820_done                   ; ... we're done
41 .do_e820:       mov eax,0000E820h
42                 mov edx,534D4150h               ; "SMAP" backwards
43                 xor ecx,ecx
44                 mov cl,20                       ; ECX <- 20
45                 mov di,E820Buf
46                 int 15h
47                 jnc .no_carry
48                 ; If carry, ebx == 0 means error, ebx != 0 means we're done
49                 and ebx,ebx
50                 jnz .e820_done
51                 jmp no_e820
52 .no_carry:
53                 cmp eax,534D4150h
54                 jne no_e820
56 ; Look for a memory block starting at <= 1 MB and continuing upward
58                 cmp dword [E820Buf+4], byte 0
59                 ja .int_loop                    ; Start >= 4 GB?
60                 mov edx, (1 << 20)
61                 sub edx, [E820Buf]
62                 jnb .ram_range                  ; Start >= 1 MB?
63                 ; If we get here, it starts > 1 MB but < 4 GB; if this is a
64                 ; *non*-memory range, remember this as unusable; some BIOSes
65                 ; get the length of primary RAM wrong!
66                 cmp dword [E820Buf+16], byte 1
67                 je .int_loop                    ; If it's memory, don't worry about it
68                 neg edx                         ; This means what for memory limit?
69                 cmp edx,[E820Max]               ; Better or worse
70                 jnb .int_loop
71                 mov [E820Max],edx
72                 jmp .int_loop
74 .ram_range:
75                 stc
76                 sbb eax,eax                     ; eax <- 0xFFFFFFFF
77                 cmp dword [E820Buf+12], byte 0
78                 ja .huge                        ; Size >= 4 GB
79                 mov eax, [E820Buf+8]
80 .huge:          sub eax, edx                    ; Adjust size to start at 1 MB
81                 jbe .int_loop                   ; Completely below 1 MB?
83                 ; Now EAX contains the size of memory 1 MB...up
84                 cmp dword [E820Buf+16], byte 1
85                 jne .int_loop                   ; High memory isn't usable memory!!!!
87                 ; We're good!
88                 mov [E820Mem],eax
89                 jmp .int_loop                   ; Still need to add low 1 MB
91 .e820_done:
92                 mov eax,[E820Mem]
93                 and eax,eax
94                 jz no_e820                      ; Nothing found by E820?
95                 cmp eax,[E820Max]               ; Make sure we're not limited
96                 jna got_highmem_add1mb
97                 mov eax,[E820Max]
98                 jmp got_highmem_add1mb
101 ; INT 15:E820 failed.  Try INT 15:E801.
103 no_e820:
104                 mov ax,0e801h                   ; Query high memory (semi-recent)
105                 int 15h
106                 jc no_e801
107                 cmp ax,3c00h
108                 ja no_e801                      ; > 3C00h something's wrong with this call
109                 jb e801_hole                    ; If memory hole we can only use low part
111                 mov ax,bx
112                 shl eax,16                      ; 64K chunks
113                 add eax,(16 << 20)              ; Add first 16M
114                 jmp short got_highmem
117 ; INT 15:E801 failed.  Try INT 15:88.
119 no_e801:
120                 mov ah,88h                      ; Query high memory (oldest)
121                 int 15h
122                 cmp ax,14*1024                  ; Don't trust memory >15M
123                 jna e801_hole
124                 mov ax,14*1024
125 e801_hole:
126                 and eax,0ffffh
127                 shl eax,10                      ; Convert from kilobytes
128 got_highmem_add1mb:
129                 add eax,(1 << 20)               ; First megabyte
130 got_highmem:
131 %if HIGHMEM_SLOP != 0
132                 sub eax,HIGHMEM_SLOP
133 %endif
134                 mov [HighMemSize],eax
135                 popad
136                 pop es
137                 ret                             ; Done!
139                 section .bss
140                 alignb 4
141 E820Buf         resd 5                  ; INT 15:E820 data buffer
142 E820Mem         resd 1                  ; Memory detected by E820
143 E820Max         resd 1                  ; Is E820 memory capped?
144 HighMemSize     resd 1                  ; End of memory pointer (bytes)