Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [BITS 32]
- MODULEALIGN equ 1<<0
- MEMINFO equ 1<<1
- AOUTKLUDGE equ 1<<16
- FLAGS equ MODULEALIGN | MEMINFO | AOUTKLUDGE
- MAGIC equ 0x1badb002
- CHECKSUM equ -(MAGIC + FLAGS)
- section .text
- align 4
- MULTIBOOTHEADER:
- MultiBootHeader:
- dd MAGIC
- dd FLAGS
- dd CHECKSUM
- dd MULTIBOOTHEADER - 0x00000010 + 0x00100000
- dd $$ - 0x00000010 + 0x00100000
- dd BOOTLOADER_END - 0x00000010 + 0x00100000
- dd BSS_END - 0x00000010 + 0x00100000
- dd START - 0x00000010 + 0x00100000
- STACKSIZE equ 0x1000
- START:
- mov eax, cr0 ; disable old paging before we set up our new one
- and eax, 01111111111111111111111111111111b
- mov cr0, eax
- mov edi, 0x1000 ; clear space for the paging tables
- mov cr3, edi ; set cr3 to edi ?????????????
- xor eax, eax
- mov ecx, 4096
- rep stosd
- mov edi, cr3 ; edi now contains address of PML4T
- mov dword[edi], 0x2003 ; set PML4T to point to PDPT
- add edi, 0x1000
- mov dword[edi], 0x3003 ; set PDPT to point to PDT
- add edi, 0x1000
- mov dword[edi], 0x4003 ; set PDT to point to PT
- add edi, 0x1000
- mov ebx, 0x3
- mov ecx, 512
- .setEntry: ; we want to map the first two MiB
- mov dword[edi], ebx ; 0x0003 on first run i.e. present and r/w
- add ebx, 0x1000 ; move to next page
- add edi, 8 ; move to next entry in PT
- loop .setEntry ; and loop until we are done
- mov eax, cr4 ; enable PAE-paging
- or eax, 1<<5
- mov cr4, eax
- mov ecx, 0xc0000080 ; set the LM-bit
- rdmsr
- or eax, 1<<8
- wrmsr
- mov eax, cr0 ; re-enable paging from when we disabled it at the beginning
- or eax, 1<<31
- mov cr0, eax
- ; jmp $
- lgdt [GDT64.Pointer] ; load our simple GDT
- ; jmp $
- jmp GDT64.Code:start64 ; and jump into 64-bit code
- GDT64: ; Global Descriptor Table (64-bit).
- .Null: equ $ - GDT64 ; The null descriptor.
- dw 0 ; Limit (low).
- dw 0 ; Base (low).
- db 0 ; Base (middle)
- db 0 ; Access.
- db 0 ; Granularity.
- db 0 ; Base (high).
- .Code: equ $ - GDT64 ; The code descriptor.
- dw 0 ; Limit (low).
- dw 0 ; Base (low).
- db 0 ; Base (middle)
- db 10011000b ; Access.
- db 00100000b ; Granularity.
- db 0 ; Base (high).
- ; dq 00000000b,0b,0b,1b,0b,0000b,1b,00b,1b,1b,0b,0b,0b,00000000b,00000000b,00000000b,00000000b,00000000b
- .Data: equ $ - GDT64 ; The data descriptor.
- dq 0x0000900000000000
- .Pointer: ; The GDT-pointer.
- dw $ - GDT64 - 1 ; Limit.
- dq GDT64 ; Base.
- [BITS 64]
- start64:
- cli
- mov ax, GDT64.Data
- mov ds, ax
- mov es, ax
- mov fs, ax
- mov gs, ax
- mov edi, 0xb8000
- mov rax, 0x1f201f201f201f20
- mov ecx, 500
- rep movsq
- stublet:
- hlt
- jmp stublet
- BOOTLOADER_END:
- BSS_START:
- section .bss
- align 4
- stack:
- resb STACKSIZE
- BSS_END:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement