MCPcopy
hub / github.com/copy/v86 / make_linux_boot_rom

Function make_linux_boot_rom

src/kernel.js:179–232  ·  view source on GitHub ↗
(real_mode_segment, heap_end)

Source from the content-addressed store, hash-verified

177}
178
179function make_linux_boot_rom(real_mode_segment, heap_end)
180{
181 // This rom will be executed by seabios after its initialisation
182 // It sets up segment registers, the stack and calls the kernel real mode entry point
183
184 const SIZE = 0x200;
185
186 const data8 = new Uint8Array(SIZE);
187 const data16 = new Uint16Array(data8.buffer);
188
189 data16[0] = 0xAA55;
190 data8[2] = SIZE / 0x200;
191
192 let i = 3;
193
194 data8[i++] = 0xFA; // cli
195 data8[i++] = 0xB8; // mov ax, real_mode_segment
196 data8[i++] = real_mode_segment >> 0;
197 data8[i++] = real_mode_segment >> 8;
198 data8[i++] = 0x8E; // mov es, ax
199 data8[i++] = 0xC0;
200 data8[i++] = 0x8E; // mov ds, ax
201 data8[i++] = 0xD8;
202 data8[i++] = 0x8E; // mov fs, ax
203 data8[i++] = 0xE0;
204 data8[i++] = 0x8E; // mov gs, ax
205 data8[i++] = 0xE8;
206 data8[i++] = 0x8E; // mov ss, ax
207 data8[i++] = 0xD0;
208 data8[i++] = 0xBC; // mov sp, heap_end
209 data8[i++] = heap_end >> 0;
210 data8[i++] = heap_end >> 8;
211 data8[i++] = 0xEA; // jmp (real_mode_segment+0x20):0x0
212 data8[i++] = 0x00;
213 data8[i++] = 0x00;
214 data8[i++] = real_mode_segment + 0x20 >> 0;
215 data8[i++] = real_mode_segment + 0x20 >> 8;
216
217 dbg_assert(i < SIZE);
218
219 const checksum_index = i;
220 data8[checksum_index] = 0;
221
222 let checksum = 0;
223
224 for(let i = 0; i < data8.length; i++)
225 {
226 checksum += data8[i];
227 }
228
229 data8[checksum_index] = -checksum;
230
231 return data8;
232}

Callers 1

load_kernelFunction · 0.85

Calls 1

dbg_assertFunction · 0.85

Tested by

no test coverage detected