Skip to content

Instantly share code, notes, and snippets.

@faraazahmad
Last active July 6, 2017 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save faraazahmad/7a02b190382ce272846ccfbb30fca28f to your computer and use it in GitHub Desktop.
Save faraazahmad/7a02b190382ce272846ccfbb30fca28f to your computer and use it in GitHub Desktop.
error on make
global start
section .text
bits 32
start:
; point the first entry of the level 4 page table
; to the first entry in level 3 page table
mov eax, p3_table
or eax, 0b11
mov dword [p4_table + 0], eax
; Point the first entry of the level 3 page table
; to the first entry in level 2 page table
mov eax, p2_table
or eax, 0b11
mov dword [p3_table + 0], eax
; point each page table level two entry to a page
mov ecx, 0 ; counter variable
.map_p2_table:
mov eax, 0x200000 ; 2 MiB
mul ecx
or eax, 0b10000011
mov [p2_table + ecx * 8], eax
inc ecx
cmp ecx, 512
jne .map_p2_table
; move page address to cr3
mov eax, p4_table
mov cr3, eax
; enable PAE
mov eax, cr4
or eax, 1 << 5
mov cr4, eax
; set the long mode bits
mov ecx, 0xc00000080
rdmsr
or eax, 1 << 8
wrmsr
; enable paging
mov eax, cr0
or eax, 1 << 31
or eax, 1 << 16
mov cr0, eax
lgdt [gdt64.pointer]
; update selectors
mov ax, gdt64.data
mov ss, ax
mov ds, ax
mov es, ax
; jump to long mode!
jmp gdt64.code:long_mode_start
hlt
section .bss
align 4096
p4_table:
resb 4096
p3_table:
resb 4096
p2_table:
resb 4096
section .rodata
gdt64:
dq 0
.code: equ $ - gdt64
dq (1 << 4) | (1 << 47) | (1 << 41) | (1 << 43) | (1 << 53)
.data: equ $ - gdt64
dq (1 << 24) | (1 << 47) | (1 << 41)
.pointer:
dw .pointer - gdt64 - 1
dq gdt64
section .text
bits 64
long_mode_start:
mov rax, 0x2f592f412f4b2f4f
mov qword [0xb8000], rax
hlt
$ make
qemu-system-x86_64 -cdrom build/os.iso
warning: TCG doesn't support requested feature: CPUID.01H:ECX.vmx [bit 5]
qemu-system-x86_64: Trying to execute code outside RAM or ROM at 0x00000000001000aa
This usually means one of the following happened:
(1) You told QEMU to execute a kernel for the wrong machine type, and it crashed on startup (eg trying to run a raspberry pi kernel on a versatilepb QEMU machine)
(2) You didn't give QEMU a kernel or BIOS filename at all, and QEMU executed a ROM full of no-op instructions until it fell off the end
(3) Your guest kernel has a bug and crashed by jumping off into nowhere
This is almost always one of the first two, so check your command line and that you are using the right type of kernel for this machine.
If you think option (3) is likely then you can try debugging your guest with the -d debug options; in particular -d guest_errors will cause the log to include a dump of the guest register state at this point.
Execution cannot continue; stopping here.
Makefile:25: recipe for target 'run' failed
make: *** [run] Error 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment