[SOLVED] Code migration issues...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: [SOLVED] Code migration issues...

Post 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
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
User avatar
yuukidesu9
Posts: 12
Joined: Wed Nov 11, 2020 4:27 pm

Re: [SOLVED] Code migration issues...

Post 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.
Just a fox guy doing fox things.
Y'know, doing some music, developing stuff, procrastinating a lot...

yuuOS: https://gitlab.com/yuukidesu9/yuuos/
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: [SOLVED] Code migration issues...

Post by nexos »

Good! I am glad that it works.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: [SOLVED] Code migration issues...

Post 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!
User avatar
yuukidesu9
Posts: 12
Joined: Wed Nov 11, 2020 4:27 pm

Re: [SOLVED] Code migration issues...

Post 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
Just a fox guy doing fox things.
Y'know, doing some music, developing stuff, procrastinating a lot...

yuuOS: https://gitlab.com/yuukidesu9/yuuos/
Post Reply