wok view linld/stuff/src/JUMP.ASM @ rev 20142

linld: tiny shrink
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Nov 11 10:57:19 2017 +0100 (2017-11-11)
parents e17c7b3f75a8
children f4bc280fe3c4
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %crefref
6 %noincl
7 %nomacs
8 ifdef NO386
9 p8086
10 else
11 p386
12 endif
14 group DGROUP _TEXT,_DATA,_BSS
15 assume cs:DGROUP,ds:DGROUP
17 segment _DATA byte public use16 'DATA'
19 overflow db "Loaded too close to 9000:0",0
21 ends _DATA
23 segment _BSS byte public use16 'BSS'
25 global _imgs:dword
27 ends _BSS
30 segment _TEXT byte public use16 'CODE'
32 ;***************************************************************
33 ;void boot_kernel();
34 ;****** Never returns
35 ;***************************************************************
36 global _boot_kernel:near
37 proc _boot_kernel near
39 p8086
40 ; Shrink stack: we won't need much of it now and have no malloc() plans
41 extrn _heap_top:word
42 mov ax,[_heap_top]
43 inc ah
44 cmp ax,sp
45 ja @@samesp
46 xchg ax,sp
47 @@samesp:
48 ifdef NO386
49 extrn _topseg:near
50 call near _topseg
51 mov es,ax
52 xchg ax,bx
53 mov cl,4
54 mov ax,sp
55 shr ax,cl
56 else
57 p386
58 mov bx,9000h
59 mov es,bx
60 mov ax,sp
61 shr ax,4
62 endif
63 mov dx,cs
64 add ax,dx
65 cmp ax,bx
66 jb @@nooverflow
67 ; Oops! We can stomp on our toes... better stop now
68 mov bx,offset overflow
69 extrn die:near
70 jmp near die
71 @@nooverflow:
72 cli ; we start doing destructive things to DOS
73 push es
74 pop ss
75 mov sp,0A000h
76 extrn _csip:dword
77 push [dword _csip]
78 extrn _rm_size:word
79 mov si,offset _rm_size ; _rm_size, _pm_high, _rm_buf
80 lodsw
81 xchg ax,cx ; _rm_size
82 lodsb ; _pm_high
83 mov si,[si] ; _rm_buf
84 xor di,di
85 ;cld
86 rep
87 movsb
88 extrn _cmdline:word
89 mov si,[_cmdline]
90 mov di,8000h
91 mov ch,10h ; 4k
92 rep
93 movsb
94 cmp al,cl ; load high ?
95 jne @@isbzimage
96 ifdef NO386
97 add bh,9
98 push bx ; topseg()+0x0900
99 else
100 push 9800h+(4096/16) ; 4096 bytes for cmdline
101 endif
102 ; finish loading
103 extrn @last_ditch$qv:near
104 push cs
105 call @last_ditch$qv
106 mov ax,[word _imgs+2+2] ; get pm->fallback high word
107 ; self move
108 ;cld
109 pop es ; min 2048 bytes for stack
110 xor si,si ; A000 -9000 -0800(>movedend)
111 xor di,di ; set ZF
112 mov cx,offset movedend
113 rep
114 movsb
115 push es
116 call near @@doretf ; mov cs,es
117 push ss
118 pop es
119 push cs
120 pop ds
121 push ax
122 extrn dos_shutdown:near
123 call near dos_shutdown
124 ;in al,70h
125 ;or al,80h ; disable NMI
126 ;out 70h,al
127 pop bx
128 ; move zImage pm
129 mov ax,8
130 cwd ; clear dx
131 cmp bx,ax
132 ja @@bufhigh
133 sub ax,bx
134 inc ax
135 @@bufhigh:
136 push ax
137 push dx ; size=up to 512k
138 push bx ; src ofs= pm.fallback
139 push dx
140 push dx ; srcseg=0
141 ifdef NO386
142 inc dx
143 push dx ; dst
144 dec dx
145 else
146 push 1 ; dst
147 endif
148 push dx ; ofs=64k
149 extrn _memcpy32:near
150 call _memcpy32
151 add sp,14
153 ifndef noelks
154 push ss
155 pop ds
156 ifndef NO386
157 cmp [dword 1E6h],'SKLE'
158 else
159 cmp [word 1E6h],'LE'
160 jne @@notelks
161 cmp [word 1E8h],'SK'
162 endif
163 jne @@notelks
164 ifdef NO386
165 mov cx,120h
166 push cx
167 mov cl,0h
168 push cx
169 else
170 push 120h
171 push 100h
172 endif
173 pop es
174 xor si,si
175 xor di,di
176 mov ch,05h
177 rep
178 movsw
179 push es
180 pop ss
181 push cx
182 @@notelks:
183 endif
184 @@isbzimage:
185 push ss
186 pop ds
187 ;push ss
188 ;pop es
189 ifndef NO386
190 push ss
191 pop fs
192 push ss
193 pop gs
194 endif
195 assume nothing
196 assume cs:DGROUP
197 @@doretf:
198 retf
200 movedend:
201 endp _boot_kernel
203 ends _TEXT
205 end
207 ;###### END OF FILE ############################################