Page 1 of 1

Higher Half Kernel Entry Point Isn't Segment Error

Posted: Wed Oct 18, 2023 7:10 am
by leventkaya
Hello,

I am trying to convert my x86 kernel into a higher half kernel. I'm using GNU GRUB version 2.06 and without higer half modification my kernel works perfectly.
But when i tried the convert it to higher half i get

Code: Select all

error: entry point isn't a segment
. Here is my updated bootloader code:

loader.asm:

Code: Select all

MBALIGN     equ  1<<0
MEMINFO     equ  1<<1
FLAGS       equ  MBALIGN | MEMINFO
MAGIC       equ  0x1BADB002
CHECKSUM    equ -(MAGIC + FLAGS)
;constants for loading higher half kernel
VM_BASE     equ 0xC0000000
PDE_INDEX   equ (VM_BASE >> 22)
PSE_BIT     equ 0x00000010
PG_BIT      equ 0x80000000

section .multiboot
align 4
    dd MAGIC
    dd FLAGS
    dd CHECKSUM

section .data
align 4096
global TEMP_PAGE_DIRECTORY
TEMP_PAGE_DIRECTORY:
    dd 0x00000083
    times(PDE_INDEX - 1) dd 0
    dd 0x00000083
    times(1024 - PDE_INDEX - 1) dd 0 

section .initial_stack, nobits
align 4
stack_bottom:
    ; 1mb of uninitialized data(1024*1024=104856)
    resb 104856
stack_top:

; Kernel entry
section .text
global kernel_entry
global low_kernel_entry
low_kernel_entry equ (kernel_entry - VM_BASE)
kernel_entry:
    mov ecx, (TEMP_PAGE_DIRECTORY - VM_BASE)
    mov cr3, ecx

    mov ecx, cr4;
    or ecx, PSE_BIT
    mov cr4, ecx

    mov ecx, cr0
    or ecx, PG_BIT
    mov cr0, ecx

    lea ecx, [higher_half]
    jmp ecx
higher_half:
    mov dword[TEMP_PAGE_DIRECTORY], 0
    invlpg[0]

    mov esp, stack_top
    extern kernel_main
    push ebx
    call kernel_main
loop:
    jmp loop
and here is my linker.ld:

Code: Select all

OUTPUT_FORMAT("elf32-i386")
ENTRY(low_kernel_entry)
SECTIONS
{
    
    . = 0xC0100000;
    
    .text ALIGN(4K) : AT(ADDR(.text)-0xC0000000)
    {
        *(.multiboot)
        *(.text)
    }
    .rodata ALIGN (4K) : AT(ADDR(.rodata)-0xC0000000)
    {
        *(.rodata)
    }
     
    .bss ALIGN(4K) : AT(ADDR(.bss)-0xC0000000)
    {
        *(.COMMON)
        *(.bss)
        *(.initial_stack)
    }
    .data ALIGN(4K) : AT(ADDR(.data)-0xC0000000)
    {
        *(.data)
    }

    
    end = .;
}
I tried to change manipulate -0xC0000000 parts by assigning them to variables and substracking the variables instead of constants but nothing changed.
I will be thankfull for any help!

Re: Higher Half Kernel Entry Point Isn't Segment Error

Posted: Wed Oct 18, 2023 7:37 pm
by Octocontrabass