Page 2 of 2

Re: [SOLVED] Code migration issues...

Posted: Mon Jul 26, 2021 11:28 am
by nexos
But are you putting it in a separate section as Bare Bones does? It may work now, but when the linker decides to do something different, it could break your OS. It is just good practice to keep multiboot data away from text data

Re: [SOLVED] Code migration issues...

Posted: Mon Jul 26, 2021 12:34 pm
by yuukidesu9
nexos wrote:But are you putting it in a separate section as Bare Bones does? It may work now, but when the linker decides to do something different, it could break your OS. It is just good practice to keep multiboot data away from text data
Oh, sure. I think this should work?

Code: Select all

global loader                   ; the entry symbol for ELF

    MAGIC_NUMBER equ 0x1BADB002     ; define the magic number constant
    FLAGS        equ 0x0            ; multiboot flags
    CHECKSUM     equ -MAGIC_NUMBER  ; calculate the checksum
                                    ; (magic number + checksum + flags should equal 0)
    KERNEL_STACK_SIZE equ 4096      ; size of stack in bytes
    
    section .multiboot              ; start of the multiboot header
    align 4                         ; align at 4 bytes
        dd MAGIC_NUMBER             ; write the magic number to the machine code,
        dd FLAGS                    ; the flags,
        dd CHECKSUM                 ; and the checksum
    
    section .text                   ; start of the text (code) section
    align 4                         ; the code must be 4 byte aligned
        .loop:
            jmp .loop
        
        kernel_stack:                   ; label points to beginning of memory
                resb KERNEL_STACK_SIZE      ; reserve stack for the kernel
                mov esp, kernel_stack + KERNEL_STACK_SIZE
         
        [extern loader_main]
        loader:
            call loader_main            ; load our kernel
        
    section .bss
        align 4                         ; align at 4 bytes
EDIT: I've put a .multiboot section in the linker script as well, above all other entries. It works normally.

Re: [SOLVED] Code migration issues...

Posted: Mon Jul 26, 2021 12:40 pm
by nexos
Good! I am glad that it works.

Re: [SOLVED] Code migration issues...

Posted: Mon Jul 26, 2021 2:37 pm
by Octocontrabass

Code: Select all

        .loop:
            jmp .loop
This code looks like it will never run. Why is it here?

Code: Select all

        kernel_stack:                   ; label points to beginning of memory
                resb KERNEL_STACK_SIZE      ; reserve stack for the kernel
You're reserving space for the kernel stack in the .text section. Did you want to put it in .bss instead?

Code: Select all

                mov esp, kernel_stack + KERNEL_STACK_SIZE
This instruction will never run. Your stack isn't being set up at all!

Re: [SOLVED] Code migration issues...

Posted: Tue Jul 27, 2021 6:37 pm
by yuukidesu9
Octocontrabass wrote: This code looks like it will never run. Why is it here?
...
You're reserving space for the kernel stack in the .text section. Did you want to put it in .bss instead?
...
This instruction will never run. Your stack isn't being set up at all!
Oh. I'm fixing them right now. Forgot about those details, it happens when we skip lunch lol