I am trying to code a small OS, and when trying to compile the assembly file into a flat binary using NASM in the WSL (Windows Subsystem For Linux), it gives me this error:
secondary_bootloader.asm:15: error: instruction not supported in 64-bit mode secondary_bootloader.asm:17: error: instruction not supported in 64-bit mode secondary_bootloader.asm:20: error: instruction not supported in 64-bit mode
When my code is:
[BITS 64]
[ORG 0x1000]
start:
; Set up the GDT (Global Descriptor Table) for 64-bit mode
lgdt [gdt_descriptor]
; Enable long mode by setting the EFER.LME bit in the MSR
mov ecx, 0xC0000080 ; MSR_EFER
rdmsr
or rax, 0x100 ; Set EFER.LME (Long Mode Enable) bit
wrmsr
; Switch to 64-bit mode
mov eax, cr0
or eax, 0x80000001 ; Set PE (Protection Enable) and PG (Paging) bits
mov cr0, eax
; Far jump to flush the pipeline
jmp 0x08:protected_mode_entry
protected_mode_entry:
; Set up 64-bit mode segments
mov rax, 0x2000 ; Address of the kernel
jmp rax ; Jump to the kernel
gdt_start:
; GDT entries for 64-bit mode
dq 0x0000000000000000 ; Null descriptor
dq 0x00CF9A000000FFFF ; Code Segment Descriptor
dq 0x00CF92000000FFFF ; Data Segment Descriptor
gdt_descriptor:
dw gdt_end - gdt_start - 1 ; Limit
dd gdt_start ; Base address
gdt_end:
times 510 - ($ - $$) db 0
I tried nasm -f bin secondary_bootloader.asm -o secondary_bootloader.bin
and it gave me the error message. When I tried nasm -f win64 secondary_bootloader.asm -o secondary_bootloader.bin
, it then gave me:
secondary_bootloader.asm:2: error: unrecognized directive [ORG]
New contributor
arthur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4