OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 6:16 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: [SOLVED] Code migration issues...
PostPosted: Mon Jul 26, 2021 11:28 am 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
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


Top
 Profile  
 
 Post subject: Re: [SOLVED] Code migration issues...
PostPosted: Mon Jul 26, 2021 12:34 pm 
Offline
User avatar

Joined: Wed Nov 11, 2020 4:27 pm
Posts: 12
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:
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/


Top
 Profile  
 
 Post subject: Re: [SOLVED] Code migration issues...
PostPosted: Mon Jul 26, 2021 12:40 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
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


Top
 Profile  
 
 Post subject: Re: [SOLVED] Code migration issues...
PostPosted: Mon Jul 26, 2021 2:37 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Code:
        .loop:
            jmp .loop

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

Code:
        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:
                mov esp, kernel_stack + KERNEL_STACK_SIZE

This instruction will never run. Your stack isn't being set up at all!


Top
 Profile  
 
 Post subject: Re: [SOLVED] Code migration issues...
PostPosted: Tue Jul 27, 2021 6:37 pm 
Offline
User avatar

Joined: Wed Nov 11, 2020 4:27 pm
Posts: 12
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/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: SemrushBot [Bot] and 67 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group