summaryrefslogtreecommitdiff
path: root/boot/arch/amd64/mbr/mbr.S
blob: 4c8c99377c909bafe569bcfb571f3035d60febcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* Segment constants */
#define BOOT_SEG       0x7C0    /* Segment we reside on startup */
#define BOOT_RELOC_SEG 0x7A0    /* Relocation segment */

    .code16
_start:
    /* Normalize CS + other selectors */
    ljmp $BOOT_SEG,$1f
1:  xor %ax, %ax
    mov %ax, %ss
    mov %ax, %gs
    mov %ax, %fs

    /*
     * The second stage bootloader expects to be loaded to 0x7C00 but since we are
     * already executing at this address we'll need to relocate ourselves first before
     * we clobber it.
     */
    mov $BOOT_SEG, %ax
    mov %ax, %ds
    mov $BOOT_RELOC_SEG, %ax
    mov %ax, %es
    xor %si, %si
    xor %di, %di
    mov $0x200, %cx
    cld
    rep movsb

    /* Jump to our relocated self */
    ljmp $BOOT_RELOC_SEG,$reloc

reloc:
    cli
    hlt
    jmp reloc

    .org 510
    .byte 0x55
    .byte 0xAA