64-bit bootloader from scratch in AT&T assembly, Part-3

Published: (February 5, 2026 at 05:39 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

32‑bit entry point

.code32  # 32-bit mode
entry32:
    # Proper 32-bit segment initialization
    movw $(gdt_data_segment - gdt_start), %ax
    movw %ax, %ds
    movw %ax, %es
    movw %ax, %ss

    # 1. Setup paging structures
    mov $0x1000, %edi
    mov %edi, %cr3
    xor %eax, %eax
    mov $4096, %ecx
    rep stosl   # fill page tables with zeros

    mov %cr3, %edi
    movl $0x2003, (%edi)          # PML4 → PDPT
    movl $0x3003, 0x1000(%edi)    # PDPT → PD
    movl $0x00000083, 0x2000(%edi)# PD → 2 MiB huge page (identity‑map 02 MiB)

    # 2. Enable PAE (fixed)
    mov %cr4, %eax
    or $(1 << 5), %eax            # set PAE bit
    mov %eax, %cr4                # write back

    # 3. Enable long mode via EFER
    mov $0xC0000080, %ecx
    rdmsr
    or $(1 << 8), %eax            # set LME bit
    wrmsr

    # 4. Enable paging
    mov %cr0, %eax
    or $(1 << 31), %eax           # set PG bit
    mov %eax, %cr0

    # 5. Jump to 64‑bit mode
    lgdt gdt64_ptr
    ljmp $0x08, $entry64          # far jump to 64‑bit entry point
Back to Blog

Related posts

Read more »

I write games in C (yes, C) (2016)

Why I Write Games in C yes, C I am an unusual beast. All my solo project games I've been making recently have been written in vanilla C. Nobody does this, so I...

I write games in C (yes, C)

Why I Write Games in C yes, C I am an unusual beast. All my solo‑project games I've been making recently have been written in vanilla C. Nobody does this, so I...