e06ca96fd3f4dc54c1200c2b3eee9f6ce2fe6a30
[external/syslinux.git] / core / init.inc
1 ; -*- fundamental -*-
2 ; -----------------------------------------------------------------------
3 ;
4 ;   Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
5 ;   Copyright 2009 Intel Corporation; author: H. Peter Anvin
6 ;
7 ;   This program is free software; you can redistribute it and/or modify
8 ;   it under the terms of the GNU General Public License as published by
9 ;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
10 ;   Boston MA 02111-1307, USA; either version 2 of the License, or
11 ;   (at your option) any later version; incorporated herein by reference.
12 ;
13 ; -----------------------------------------------------------------------
14
15 ;
16 ; init.inc
17 ;
18 ; Common initialization code (inline)
19 ;
20
21                 section .text16
22 common_init:
23                 ; Initialize PM invocation framework
24                 call pm_init
25
26                 ; Decompress PM code to its target location
27                 pm_call pm_decompress
28                 cmp eax,__pm_code_len
29                 jne kaboom
30
31 ;
32 ; Initialize timer
33 ;
34                 call timer_init
35
36 ;
37 ; Initialize configuration information
38 ;
39                 call reset_config
40
41 ;
42 ; Set up the COMBOOT APIs
43 ;
44                 call comboot_setup_api
45
46 ;
47 ; Now set up screen parameters
48 ;
49                 call adjust_screen
50
51 ;
52 ; CPU-dependent initialization and related checks.
53 ;
54 check_escapes:
55                 mov ah,02h                      ; Check keyboard flags
56                 int 16h
57                 mov [KbdFlags],al               ; Save for boot prompt check
58                 test al,04h                     ; Ctrl->skip 386 check
59                 jnz skip_checks
60
61 ;
62 ; Now check that there is sufficient low (DOS) memory
63 ;
64 ; NOTE: Linux doesn't use all of real_mode_seg, but we use the same
65 ; segment for COMBOOT images, which can use all 64K
66 ;
67                 int 12h
68                 mov edx,__lowmem_heap + min_lowmem_heap + 1023
69                 shr edx,10
70                 cmp ax,dx
71                 jae enough_ram
72                 mov ax,dx
73                 mov si,err_noram
74                 mov cl,10
75                 div cl
76                 add [si+err_noram.size-err_noram+2],ah
77                 cbw
78                 div cl
79                 add [si+err_noram.size-err_noram],ax
80                 call writestr_early
81                 jmp kaboom
82 enough_ram:
83 skip_checks:
84
85                 section .data16
86 err_noram       db 'It appears your computer has less than '
87 .size           db '000'
88                 db 'K of low ("DOS")'
89                 db CR, LF
90                 db 'RAM.  Syslinux needs at least this amount to boot.  If you get'
91                 db CR, LF
92                 db 'this message in error, hold down the Ctrl key while'
93                 db CR, LF
94                 db 'booting, and I will take your word for it.', CR, LF, 0
95
96                 section .text16
97 ;
98 ; The code to decompress the PM code and initialize other segments.
99 ;
100                 extern _lzo1x_decompress_asm_fast
101
102                 section .textnr
103                 bits 32
104 pm_decompress:
105                 push 0                          ; Space for decompressed size
106                 push esp                        ; Pointer to previous word
107                 push __pm_code_start            ; Target address
108                 push dword [lzo_data_size]      ; Compressed size
109                 push dword __pm_code_lma
110                 call _lzo1x_decompress_asm_fast
111                 add esp,16
112                 pop RM_EAX                      ; Decompressed size
113
114                 ; Zero bss sections (but not .earlybss, since it may
115                 ; contain already-live data.)
116                 xor eax,eax
117                 mov edi,__bss_start
118                 mov ecx,__bss_dwords
119                 rep stosd
120                 mov edi,__bss16_start
121                 mov ecx,__bss16_dwords
122                 rep stosd
123                 mov edi,__high_clear_start      ; .uibss, .auxseg, .lowmem
124                 mov ecx,__high_clear_dwords
125                 rep stosd
126
127                 ret
128
129                 section .data16
130 lzo_data_size   dd 0                            ; filled in by compressor
131
132                 section .text16
133                 bits 16