:: limine / common / protos / multiboot_reloc.asm_x86 1.2 KB raw

1
section .data
2
3
bits 32
4
5
global multiboot_reloc_stub
6
multiboot_reloc_stub:
7
    jmp .code
8
9
    times 4-($-multiboot_reloc_stub) db 0
10
11
    ; EBX = self
12
    ; ESI = magic value
13
    ; EDI = protocol info
14
    ; ECX = entry point
15
    ; EAX = ranges
16
    ; EDX = ranges count
17
18
  .code:
19
    mov esp, ebx
20
    add esp, .mini_stack_top - multiboot_reloc_stub
21
22
    push edi
23
    push esi
24
    push ecx
25
26
  .ranges_loop:
27
    test edx, edx     ; Loop until we're done
28
    jz .ranges_loop_out
29
30
    mov esi, [eax]    ; ESI = range.elsewhere
31
    mov edi, [eax+8]  ; EDI = range.target
32
    mov ecx, [eax+16] ; ECX = range.length
33
    rep movsb         ; Copy range to target location
34
35
    add eax, 24       ; Move to the next range
36
37
    dec edx
38
    jmp .ranges_loop
39
40
  .ranges_loop_out:
41
    ; We're done relocating!
42
    pop ecx
43
    pop esi
44
    pop edi
45
46
    push ecx
47
48
    mov eax, esi ; EAX = magic value
49
    mov ebx, edi ; EBX = protocol info
50
    xor ecx, ecx
51
    xor edx, edx
52
    xor esi, esi
53
    xor edi, edi
54
    xor ebp, ebp
55
56
    ret
57
58
    align 16
59
 .mini_stack:
60
    times 3 dq 0
61
 .mini_stack_top:
62
63
global multiboot_reloc_stub_end
64
multiboot_reloc_stub_end:
65
66
section .note.GNU-stack noalloc noexec nowrite progbits
tab: 248 wrap: offon