Code: Select all
%define IMAGE_RMODE_BASE 0x3000
%define IMAGE_PMODE_BASE 0xC0000000
bits 32
%include "Paging.inc"
BadImage db "*** FATAL: Invalid or corrupt kernel image. Halting system.", 0
Stage3:
;-------------------------------;
; Set registers ;
;-------------------------------;
mov ax, DATA_DESC ; set data segments to data selector (0x10)
mov ds, ax
mov ss, ax
mov es, ax
mov esp, 90000h ; stack begins from 90000h
call ClrScr32
call EnablePaging
CopyImage:
mov eax, dword [ImageSize]
movzx ebx, word [bpbBytesPerSector]
mul ebx
mov ebx, 4
div ebx
cld
mov esi, IMAGE_RMODE_BASE
mov edi, IMAGE_PMODE_BASE
mov ecx, eax
rep movsd ; copy image to its protected mode address
TestImage:
mov ebx, [IMAGE_PMODE_BASE+60]
add ebx, IMAGE_PMODE_BASE ; ebx now points to file sig (PE00)
mov esi, ebx
mov edi, ImageSig
cmpsw
je EXECUTE
mov ebx, BadImage
call Puts32
cli
hlt
Code: Select all
%define IMAGE_RMODE_BASE 0x3000
[b]%define IMAGE_PMODE_BASE 0x100000[/b]
bits 32
%include "Paging.inc"
BadImage db "*** FATAL: Invalid or corrupt kernel image. Halting system.", 0
Stage3:
;-------------------------------;
; Set registers ;
;-------------------------------;
mov ax, DATA_DESC ; set data segments to data selector (0x10)
mov ds, ax
mov ss, ax
mov es, ax
mov esp, 90000h ; stack begins from 90000h
call ClrScr32
CopyImage:
mov eax, dword [ImageSize]
movzx ebx, word [bpbBytesPerSector]
mul ebx
mov ebx, 4
div ebx
cld
mov esi, IMAGE_RMODE_BASE
mov edi, IMAGE_PMODE_BASE
mov ecx, eax
rep movsd ; copy image to its protected mode address
TestImage:
mov ebx, [IMAGE_PMODE_BASE+60]
add ebx, IMAGE_PMODE_BASE ; ebx now points to file sig (PE00)
mov esi, ebx
mov edi, ImageSig
cmpsw
[b]call EnablePaging[/b]
je EXECUTE
mov ebx, BadImage
call Puts32
cli
hlt
