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

[SOLVED] Code migration issues...

Post by yuukidesu9 »

Hi, guys. It's been a long time since I don't use this forum, and if this issue has already been solved in another thread, please point me to it and I'll delete this post, to not bloat the forum with duplicate issues.

Well, I'm having a bit of an issue here. I want to migrate my OS to use GRUB without floppy emulation (namely, kernel as ELF file) instead of the way I'm currently doing (which is using a floppy image).

The thing is, I tried to create a multiboot-compliant header (using The Little Book About OS Development's structure). It linked and compiled normally, but once I boot the resulting ISO image, there's an error.

Just in case, here's a readelf dump of the resulting kernel file.

Code: Select all

Yuuki-kun@AI-CHAN: ~/Documents/SourceCode/yuuOS $ readelf -a kernel.elf
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Intel 80386
  Version:                           0x1
  Entry point address:               0x10375e
  Start of program headers:          52 (bytes into file)
  Start of section headers:          20972 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         3
  Size of section headers:           40 (bytes)
  Number of section headers:         12
  Section header string table index: 9

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00100000 001000 001ab8 00  AX  0   0 16
  [ 2] .rodata           PROGBITS        00102000 003000 000711 00   A  0   0 32
  [ 3] .text:            PROGBITS        00102714 003714 00000c 00   A  0   0  4
  [ 4] .bss:             PROGBITS        00102720 003720 001045 00   A  0   0  4
  [ 5] .eh_frame         PROGBITS        00103768 004768 000628 00   A  0   0  4
  [ 6] .bss              NOBITS          00104000 005000 000d30 00  WA  0   0 32
  [ 7] .data             PROGBITS        00105000 005000 000184 00  WA  0   0 32
  [ 8] .comment          PROGBITS        00000000 005184 000011 01  MS  0   0  1
  [ 9] .shstrtab         STRTAB          00000000 005195 000054 00      0   0  1
  [10] .symtab           SYMTAB          00000000 0053cc 0009e0 10     11  55  4
  [11] .strtab           STRTAB          00000000 005dac 000549 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  p (processor specific)

There are no section groups in this file.

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x001000 0x00100000 0x00100000 0x03d90 0x03d90 R E 0x1000
  LOAD           0x005000 0x00104000 0x00104000 0x00000 0x00d30 RW  0x1000
  LOAD           0x005000 0x00105000 0x00105000 0x00184 0x00184 RW  0x1000

 Section to Segment mapping:
  Segment Sections...
   00     .text .rodata .text: .bss: .eh_frame
   01     .bss
   02     .data

There is no dynamic section in this file.

There are no relocations in this file.

The decoding of unwind sections for machine type Intel 80386 is not currently supported.

Symbol table '.symtab' contains 158 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00100000     0 SECTION LOCAL  DEFAULT    1
     2: 00102000     0 SECTION LOCAL  DEFAULT    2
     3: 00102714     0 SECTION LOCAL  DEFAULT    3
     4: 00102720     0 SECTION LOCAL  DEFAULT    4
     5: 00103768     0 SECTION LOCAL  DEFAULT    5
     6: 00104000     0 SECTION LOCAL  DEFAULT    6
     7: 00105000     0 SECTION LOCAL  DEFAULT    7
     8: 00000000     0 SECTION LOCAL  DEFAULT    8
     9: 00000000     0 FILE    LOCAL  DEFAULT  ABS loader.c
    10: 00000000     0 FILE    LOCAL  DEFAULT  ABS cpu/interrupt.asm
    11: 00100390     0 NOTYPE  LOCAL  DEFAULT    1 isr_common_stub
    12: 001003b5     0 NOTYPE  LOCAL  DEFAULT    1 irq_common_stub
    13: 00000000     0 FILE    LOCAL  DEFAULT  ABS acpi.c
    14: 00000000     0 FILE    LOCAL  DEFAULT  ABS ahci.c
    15: 00000000     0 FILE    LOCAL  DEFAULT  ABS ata.c
    16: 00100797    25 FUNC    LOCAL  DEFAULT    1 ATA_wait_BSY
    17: 001007b0    31 FUNC    LOCAL  DEFAULT    1 ATA_wait_DRQ
    18: 00000000     0 FILE    LOCAL  DEFAULT  ABS keyboard.c
    19: 00104c20   256 OBJECT  LOCAL  DEFAULT    6 key_buffer
    20: 00104d20     4 OBJECT  LOCAL  DEFAULT    6 buffersize
    21: 00104d24     4 OBJECT  LOCAL  DEFAULT    6 isCaps
    22: 00104d28     4 OBJECT  LOCAL  DEFAULT    6 isShift
    23: 001007cf   337 FUNC    LOCAL  DEFAULT    1 keyboard_callback
    24: 00000000     0 FILE    LOCAL  DEFAULT  ABS net.c
    25: 00000000     0 FILE    LOCAL  DEFAULT  ABS pci.c
    26: 00000000     0 FILE    LOCAL  DEFAULT  ABS textmode.c
    27: 00000000     0 FILE    LOCAL  DEFAULT  ABS idt.c
    28: 00000000     0 FILE    LOCAL  DEFAULT  ABS isr.c
    29: 00000000     0 FILE    LOCAL  DEFAULT  ABS ports.c
    30: 00000000     0 FILE    LOCAL  DEFAULT  ABS timer.c
    31: 001014bb    18 FUNC    LOCAL  DEFAULT    1 timer_callback
    32: 00000000     0 FILE    LOCAL  DEFAULT  ABS utils.c
    33: 00000000     0 FILE    LOCAL  DEFAULT  ABS mem.c
    34: 00000000     0 FILE    LOCAL  DEFAULT  ABS stdio.c
    35: 00000000     0 FILE    LOCAL  DEFAULT  ABS string.c
    36: 00000000     0 FILE    LOCAL  DEFAULT  ABS boot/loader_entry.asm
    37: 1badb002     0 NOTYPE  LOCAL  DEFAULT  ABS MAGIC_NUMBER
    38: 00000000     0 NOTYPE  LOCAL  DEFAULT  ABS FLAGS
    39: e4524ffe     0 NOTYPE  LOCAL  DEFAULT  ABS CHECKSUM
    40: 00001000     0 NOTYPE  LOCAL  DEFAULT  ABS KERNEL_STACK_SIZE
    41: 00102720     0 NOTYPE  LOCAL  DEFAULT    4 kernel_stack
    42: 00103725     0 NOTYPE  LOCAL  DEFAULT    4 gdt_start
    43: 0010372d     0 NOTYPE  LOCAL  DEFAULT    4 gdt_code
    44: 00103735     0 NOTYPE  LOCAL  DEFAULT    4 gdt_data
    45: 0010373d     0 NOTYPE  LOCAL  DEFAULT    4 gdt_end
    46: 0010373d     0 NOTYPE  LOCAL  DEFAULT    4 gdt_descriptor
    47: 00000008     0 NOTYPE  LOCAL  DEFAULT  ABS CODE_SEG
    48: 00000010     0 NOTYPE  LOCAL  DEFAULT  ABS DATA_SEG
    49: 000b8000     0 NOTYPE  LOCAL  DEFAULT  ABS VIDEO_MEMORY
    50: 0000000f     0 NOTYPE  LOCAL  DEFAULT  ABS WHITE_ON_BLACK
    51: 00103743     0 NOTYPE  LOCAL  DEFAULT    4 print_string_pm
    52: 00103749     0 NOTYPE  LOCAL  DEFAULT    4 print_string_pm_loop
    53: 0010375c     0 NOTYPE  LOCAL  DEFAULT    4 print_string_pm_done
    54: 00000000     0 FILE    LOCAL  DEFAULT  ABS
    55: 00101421    29 FUNC    GLOBAL DEFAULT    1 inb
    56: 00101320    28 FUNC    GLOBAL DEFAULT    1 register_interru[...]
    57: 001017b8    35 FUNC    GLOBAL DEFAULT    1 printf
    58: 001003f6     0 NOTYPE  GLOBAL DEFAULT    1 isr4
    59: 001004c7     0 NOTYPE  GLOBAL DEFAULT    1 isr27
    60: 0010043f     0 NOTYPE  GLOBAL DEFAULT    1 isr13
    61: 001015e6    56 FUNC    GLOBAL DEFAULT    1 cpubrand
    62: 00100a47   447 FUNC    GLOBAL DEFAULT    1 print_char
    63: 0010196b   101 FUNC    GLOBAL DEFAULT    1 reverse
    64: 0010093c   186 FUNC    GLOBAL DEFAULT    1 kprint_at
    65: 00100571     0 NOTYPE  GLOBAL DEFAULT    1 irq12
    66: 00100495     0 NOTYPE  GLOBAL DEFAULT    1 isr22
    67: 0010044f     0 NOTYPE  GLOBAL DEFAULT    1 isr15
    68: 00102540    59 OBJECT  GLOBAL DEFAULT    2 sc_ascii_caps
    69: 0010055d     0 NOTYPE  GLOBAL DEFAULT    1 irq10
    70: 00100585     0 NOTYPE  GLOBAL DEFAULT    1 irq14
    71: 0010041d     0 NOTYPE  GLOBAL DEFAULT    1 isr9
    72: 00100549     0 NOTYPE  GLOBAL DEFAULT    1 irq8
    73: 001016f1    50 FUNC    GLOBAL DEFAULT    1 memcpy
    74: 0010049f     0 NOTYPE  GLOBAL DEFAULT    1 isr23
    75: 00100de0    32 FUNC    GLOBAL DEFAULT    1 set_idt
    76: 00100357    42 FUNC    GLOBAL DEFAULT    1 quit_sys
    77: 001004db     0 NOTYPE  GLOBAL DEFAULT    1 isr29
    78: 00101752   102 FUNC    GLOBAL DEFAULT    1 malloc
    79: 001004ef     0 NOTYPE  GLOBAL DEFAULT    1 isr31
    80: 00100c62   110 FUNC    GLOBAL DEFAULT    1 set_cursor_offset
    81: 001014cd   119 FUNC    GLOBAL DEFAULT    1 init_timer
    82: 0010048b     0 NOTYPE  GLOBAL DEFAULT    1 isr21
    83: 00100567     0 NOTYPE  GLOBAL DEFAULT    1 irq11
    84: 00105180     4 OBJECT  GLOBAL DEFAULT    7 free_mem_addr
    85: 001004d1     0 NOTYPE  GLOBAL DEFAULT    1 isr28
    86: 00102500    59 OBJECT  GLOBAL DEFAULT    2 sc_ascii
    87: 0010069e   249 FUNC    GLOBAL DEFAULT    1 PIO_writesec
    88: 00100415     0 NOTYPE  GLOBAL DEFAULT    1 isr8
    89: 0010052b     0 NOTYPE  GLOBAL DEFAULT    1 irq5
    90: 001014af    12 FUNC    GLOBAL DEFAULT    1 outdw
    91: 00100481     0 NOTYPE  GLOBAL DEFAULT    1 isr20
    92: 00100447     0 NOTYPE  GLOBAL DEFAULT    1 isr14
    93: 0010145c    31 FUNC    GLOBAL DEFAULT    1 inw
    94: 00100d36    27 FUNC    GLOBAL DEFAULT    1 get_offset
    95: 001003fd     0 NOTYPE  GLOBAL DEFAULT    1 isr5
    96: 00105100   128 OBJECT  GLOBAL DEFAULT    7 exception_messages
    97: 0010003f   628 FUNC    GLOBAL DEFAULT    1 user_input
    98: 00100535     0 NOTYPE  GLOBAL DEFAULT    1 irq6
    99: 00100503     0 NOTYPE  GLOBAL DEFAULT    1 irq1
   100: 00100599   261 FUNC    GLOBAL DEFAULT    1 PIO_readsec
   101: 00100000    63 FUNC    GLOBAL DEFAULT    1 loader_main
   102: 0010149b    20 FUNC    GLOBAL DEFAULT    1 indw
   103: 0010161e   211 FUNC    GLOBAL DEFAULT    1 pickStr
   104: 001003e1     0 NOTYPE  GLOBAL DEFAULT    1 isr1
   105: 00100553     0 NOTYPE  GLOBAL DEFAULT    1 irq9
   106: 00100e00  1221 FUNC    GLOBAL DEFAULT    1 isr_install
   107: 001004bd     0 NOTYPE  GLOBAL DEFAULT    1 isr26
   108: 0010042f     0 NOTYPE  GLOBAL DEFAULT    1 isr11
   109: 00101544   162 FUNC    GLOBAL DEFAULT    1 vendor
   110: 00105000   236 OBJECT  GLOBAL DEFAULT    7 sc_name
   111: 00101407    26 FUNC    GLOBAL DEFAULT    1 irq_install
   112: 001009f6    81 FUNC    GLOBAL DEFAULT    1 kprint_backspace
   113: 001017db   174 FUNC    GLOBAL DEFAULT    1 int_to_ascii
   114: 00102580    59 OBJECT  GLOBAL DEFAULT    2 sc_ascii_shift
   115: 00104d2c     4 OBJECT  GLOBAL DEFAULT    6 tick
   116: 0010143e    30 FUNC    GLOBAL DEFAULT    1 outb
   117: 0010057b     0 NOTYPE  GLOBAL DEFAULT    1 irq13
   118: 00100437     0 NOTYPE  GLOBAL DEFAULT    1 isr12
   119: 00101723    47 FUNC    GLOBAL DEFAULT    1 memset
   120: 001003da     0 NOTYPE  GLOBAL DEFAULT    1 isr0
   121: 0010050d     0 NOTYPE  GLOBAL DEFAULT    1 irq2
   122: 001012c5    91 FUNC    GLOBAL DEFAULT    1 isr_handler
   123: 001004a9     0 NOTYPE  GLOBAL DEFAULT    1 isr24
   124: 00100459     0 NOTYPE  GLOBAL DEFAULT    1 isr16
   125: 00101a53   101 FUNC    GLOBAL DEFAULT    1 strcmp
   126: 00104000  2048 OBJECT  GLOBAL DEFAULT    6 idt
   127: 001003ef     0 NOTYPE  GLOBAL DEFAULT    1 isr3
   128: 00104820  1024 OBJECT  GLOBAL DEFAULT    6 interrupt_handlers
   129: 00100404     0 NOTYPE  GLOBAL DEFAULT    1 isr6
   130: 0010375e     0 NOTYPE  GLOBAL DEFAULT    4 loader
   131: 0010053f     0 NOTYPE  GLOBAL DEFAULT    1 irq7
   132: 0010133c   203 FUNC    GLOBAL DEFAULT    1 irq_handler
   133: 001002b3   164 FUNC    GLOBAL DEFAULT    1 about
   134: 0010147b    32 FUNC    GLOBAL DEFAULT    1 outw
   135: 0010046d     0 NOTYPE  GLOBAL DEFAULT    1 isr18
   136: 00100c06    92 FUNC    GLOBAL DEFAULT    1 get_cursor_offset
   137: 001004f9     0 NOTYPE  GLOBAL DEFAULT    1 irq0
   138: 00100427     0 NOTYPE  GLOBAL DEFAULT    1 isr10
   139: 00100d95    75 FUNC    GLOBAL DEFAULT    1 set_idt_gate
   140: 001019f7    56 FUNC    GLOBAL DEFAULT    1 append
   141: 00100463     0 NOTYPE  GLOBAL DEFAULT    1 isr17
   142: 001003e8     0 NOTYPE  GLOBAL DEFAULT    1 isr2
   143: 00100d51    29 FUNC    GLOBAL DEFAULT    1 get_offset_row
   144: 00100477     0 NOTYPE  GLOBAL DEFAULT    1 isr19
   145: 00101889   226 FUNC    GLOBAL DEFAULT    1 hex_to_ascii
   146: 001004e5     0 NOTYPE  GLOBAL DEFAULT    1 isr30
   147: 00100d6e    39 FUNC    GLOBAL DEFAULT    1 get_offset_col
   148: 001019d0    39 FUNC    GLOBAL DEFAULT    1 strlen
   149: 00101a2f    36 FUNC    GLOBAL DEFAULT    1 backspace
   150: 0010058f     0 NOTYPE  GLOBAL DEFAULT    1 irq15
   151: 0010040b     0 NOTYPE  GLOBAL DEFAULT    1 isr7
   152: 00104800     6 OBJECT  GLOBAL DEFAULT    6 idt_reg
   153: 001004b3     0 NOTYPE  GLOBAL DEFAULT    1 isr25
   154: 00100cd0   102 FUNC    GLOBAL DEFAULT    1 clear_screen
   155: 00100920    28 FUNC    GLOBAL DEFAULT    1 init_keyboard
   156: 00100521     0 NOTYPE  GLOBAL DEFAULT    1 irq4
   157: 00100517     0 NOTYPE  GLOBAL DEFAULT    1 irq3

No version information found in this file.
The problem is that the loader_main routine is there, but I can't seem to run it correctly!
Any bit of help would be appreciated. [-o<
Attachments
Screenshot of QEMU running new image.
Screenshot of QEMU running new image.
Last edited by yuukidesu9 on Sat Jul 24, 2021 4:47 pm, edited 1 time in total.
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Code migration issues

Post by nexos »

What code did you use to link and compile the kernel? What does your entry point look like? Also, try running

Code: Select all

grub-file --is-x86-multiboot kernel.elf
Then run

Code: Select all

echo $?
And tell us what that says
"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: Code migration issues

Post by yuukidesu9 »

nexos wrote:What code did you use to link and compile the kernel? What does your entry point look like?
I'm trying to use the same-ish code as the book tutorial, but calling the main function from the kernel/loader C code I already have (from the Git repo). Here's the entry point, entry_loader.asm:

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 .text:                  ; start of the text (code) section
    align 4                         ; the code must be 4 byte aligned
        dd MAGIC_NUMBER             ; write the magic number to the machine code,
        dd FLAGS                    ; the flags,
        dd CHECKSUM                 ; and the checksum

    section .bss:
        align 4                         ; align at 4 bytes
        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            ; loads our kernel
    jmp $
Here's the linker script.

Code: Select all

ENTRY(loader)                /* the name of the entry label */
SECTIONS {
    . = 0x00100000;          /* the code should be loaded at 1 MB */
    .text ALIGN (0x1000) :   /* align at 4 KB */
    {
        *(.text)             /* all text sections from all files */
    }

    .rodata ALIGN (0x1000) : /* align at 4 KB */
    {
        *(.rodata*)          /* all read-only data sections from all files */
    }
    .bss ALIGN (0x1000) :    /* align at 4 KB */
    {
        *(COMMON)            /* all COMMON sections from all files */
        *(.bss)              /* all bss sections from all files */
    }
    .data ALIGN (0x1000) :   /* align at 4 KB */
    {
        *(.data)             /* all data sections from all files */
    }
}
nexos wrote:Also, try running

Code: Select all

grub-file --is-x86-multiboot kernel.elf
Then run

Code: Select all

echo $?
And tell us what that says
I currently use MSYS2, and there are no GRUB packages for it. The echo command prints 0.
Just a fox guy doing fox things.
Y'know, doing some music, developing stuff, procrastinating a lot...

yuuOS: https://gitlab.com/yuukidesu9/yuuos/
Octocontrabass
Member
Member
Posts: 5567
Joined: Mon Mar 25, 2013 7:01 pm

Re: Code migration issues

Post by Octocontrabass »

yuukidesu9 wrote:

Code: Select all

    section .bss:
...
loader:
    call loader_main            ; loads our kernel
    jmp $
Don't you get errors from putting initialized data in the .bss section? I think you forgot "section .text" somewhere.

Are you using Windows 10?
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Code migration issues

Post by nexos »

In your linker script, it would be good practice to put BSS last. Also, as Octocontrabass pointed out, there should be a text section directive before executable code.

Also, I would use the code in the wiki. That code looks like a ticking time bomb to me... They say not to use OSDev tutorials for a reason
"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: Code migration issues

Post by yuukidesu9 »

Octocontrabass wrote:Don't you get errors from putting initialized data in the .bss section? I think you forgot "section .text" somewhere.
Well, I do get a warning for the boot entry on assembly time.

Code: Select all

boot/loader_entry.asm:18: warning: uninitialized space declared in non-BSS section `.bss:': zeroing [-w+zeroing]
The .text section is up there, at the loader, with the ELF header data.
Octocontrabass wrote:Are you using Windows 10?
Nope, I'm using Windows 8.1 + MSYS2.
nexos wrote:In your linker script, it would be good practice to put BSS last. Also, as Octocontrabass pointed out, there should be a text section directive before executable code.
Oh. I'll try putting the .bss section after the function call, then. Maybe it works.
EDIT: it didn't. Same as before.
nexos wrote:Also, I would use the code in the wiki. That code looks like a ticking time bomb to me... They say not to use OSDev tutorials for a reason
I'm trying the boot code from the book, as I said in the first post. And yeah, I know about that. I'm just trying to wrap my head around this boot method.
Just a fox guy doing fox things.
Y'know, doing some music, developing stuff, procrastinating a lot...

yuuOS: https://gitlab.com/yuukidesu9/yuuos/
Octocontrabass
Member
Member
Posts: 5567
Joined: Mon Mar 25, 2013 7:01 pm

Re: Code migration issues

Post by Octocontrabass »

yuukidesu9 wrote:The .text section is up there, at the loader, with the ELF header data.
Yes it is, but right after that you have "section .bss" which puts the stack and the function call in the .bss section. You need to either add another "section .text" to put the function call in the .text section, or move the function call above the "section .bss" line so it'll end up in the .text section with the multiboot header.
yuukidesu9 wrote:Nope, I'm using Windows 8.1 + MSYS2.
Microsoft never actually shut down the free upgrade to Windows 10. If you upgrade to Windows 10, you can use WSL instead of MSYS2. WSL has GRUB packages. (Back up all of your data before trying to upgrade.)
yuukidesu9 wrote:Maybe it works.
EDIT: it didn't. Same as before.
Dump your symbols again. Is "loader" above or below 00102000? If it's above, that means your Multiboot header isn't in the first 8192 bytes of the kernel binary, so you'll need to change how you link your kernel.
User avatar
yuukidesu9
Posts: 12
Joined: Wed Nov 11, 2020 4:27 pm

Re: Code migration issues

Post by yuukidesu9 »

Octocontrabass wrote:Yes it is, but right after that you have "section .bss" which puts the stack and the function call in the .bss section. You need to either add another "section .text" to put the function call in the .text section, or move the function call above the "section .bss" line so it'll end up in the .text section with the multiboot header.
I'll try that.
Octocontrabass wrote:Dump your symbols again. Is "loader" above or below 00102000? If it's above, that means your Multiboot header isn't in the first 8192 bytes of the kernel binary, so you'll need to change how you link your kernel.
Here's the dump. The main kernel function seems to be at 0x00100000, though:

Code: Select all

ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Intel 80386
  Version:                           0x1
  Entry point address:               0x103727
  Start of program headers:          52 (bytes into file)
  Start of section headers:          20964 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         3
  Size of section headers:           40 (bytes)
  Number of section headers:         11
  Section header string table index: 8

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00100000 001000 001ab8 00  AX  0   0 16
  [ 2] .rodata           PROGBITS        00102000 003000 000711 00   A  0   0 32
  [ 3] .text:            PROGBITS        00102714 003714 001018 00   A  0   0  4
  [ 4] .eh_frame         PROGBITS        0010372c 00472c 000628 00   A  0   0  4
  [ 5] .bss              NOBITS          00104000 005000 000d30 00  WA  0   0 32
  [ 6] .data             PROGBITS        00105000 005000 000184 00  WA  0   0 32
  [ 7] .comment          PROGBITS        00000000 005184 000011 01  MS  0   0  1
  [ 8] .shstrtab         STRTAB          00000000 005195 00004e 00      0   0  1
  [ 9] .symtab           SYMTAB          00000000 00539c 000920 10     10  43  4
  [10] .strtab           STRTAB          00000000 005cbc 0004ba 00      0   0  1

...

 Section to Segment mapping:
  Segment Sections...
   00     .text .rodata .text: .eh_frame
   01     .bss
   02     .data

...

Symbol table '.symtab' contains 146 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00100000     0 SECTION LOCAL  DEFAULT    1
     2: 00102000     0 SECTION LOCAL  DEFAULT    2
     3: 00102714     0 SECTION LOCAL  DEFAULT    3
     4: 0010372c     0 SECTION LOCAL  DEFAULT    4
     5: 00104000     0 SECTION LOCAL  DEFAULT    5
     6: 00105000     0 SECTION LOCAL  DEFAULT    6
     7: 00000000     0 SECTION LOCAL  DEFAULT    7
     8: 00000000     0 FILE    LOCAL  DEFAULT  ABS loader.c
     9: 00000000     0 FILE    LOCAL  DEFAULT  ABS cpu/interrupt.asm
    10: 00100390     0 NOTYPE  LOCAL  DEFAULT    1 isr_common_stub
    11: 001003b5     0 NOTYPE  LOCAL  DEFAULT    1 irq_common_stub
    12: 00000000     0 FILE    LOCAL  DEFAULT  ABS acpi.c
    13: 00000000     0 FILE    LOCAL  DEFAULT  ABS ahci.c
    14: 00000000     0 FILE    LOCAL  DEFAULT  ABS ata.c
    15: 00100797    25 FUNC    LOCAL  DEFAULT    1 ATA_wait_BSY
    16: 001007b0    31 FUNC    LOCAL  DEFAULT    1 ATA_wait_DRQ
    17: 00000000     0 FILE    LOCAL  DEFAULT  ABS keyboard.c
    18: 00104c20   256 OBJECT  LOCAL  DEFAULT    5 key_buffer
    19: 00104d20     4 OBJECT  LOCAL  DEFAULT    5 buffersize
    20: 00104d24     4 OBJECT  LOCAL  DEFAULT    5 isCaps
    21: 00104d28     4 OBJECT  LOCAL  DEFAULT    5 isShift
    22: 001007cf   337 FUNC    LOCAL  DEFAULT    1 keyboard_callback
...
    40: 00102720     0 NOTYPE  LOCAL  DEFAULT    3 loader.loop
    41: 00102722     0 NOTYPE  LOCAL  DEFAULT    3 kernel_stack
...
    89: 00100000    63 FUNC    GLOBAL DEFAULT    1 loader_main
...
   143: 00100920    28 FUNC    GLOBAL DEFAULT    1 init_keyboard
   144: 00100521     0 NOTYPE  GLOBAL DEFAULT    1 irq4
   145: 00100517     0 NOTYPE  GLOBAL DEFAULT    1 irq3

No version information found in this file.
Just a fox guy doing fox things.
Y'know, doing some music, developing stuff, procrastinating a lot...

yuuOS: https://gitlab.com/yuukidesu9/yuuos/
Octocontrabass
Member
Member
Posts: 5567
Joined: Mon Mar 25, 2013 7:01 pm

Re: Code migration issues

Post by Octocontrabass »

yuukidesu9 wrote:The main kernel function seems to be at 0x00100000, though:
That's not the problem, though. The Multiboot header needs to be somewhere between 00100000 and 00102000 or GRUB won't find it. You don't have a label assigned to the location of the Multiboot header, so I'm trying to figure out where it is using nearby labels instead.
yuukidesu9 wrote:

Code: Select all

  [ 1] .text             PROGBITS        00100000 001000 001ab8 00  AX  0   0 16
  [ 3] .text:            PROGBITS        00102714 003714 001018 00   A  0   0  4
You wrote ".text:" instead of ".text" in one of your files. I bet your Multiboot header is in that ".text:" section.
User avatar
yuukidesu9
Posts: 12
Joined: Wed Nov 11, 2020 4:27 pm

Re: Code migration issues

Post by yuukidesu9 »

Octocontrabass wrote:You wrote ".text:" instead of ".text" in one of your files. I bet your Multiboot header is in that ".text:" section.
Tried changing it here, and it worked normally. Silly me with my low coding standards #-o

Thank you so much for helping me. :D

I declare this thread... closed. ;3
Just a fox guy doing fox things.
Y'know, doing some music, developing stuff, procrastinating a lot...

yuuOS: https://gitlab.com/yuukidesu9/yuuos/
Octocontrabass
Member
Member
Posts: 5567
Joined: Mon Mar 25, 2013 7:01 pm

Re: [SOLVED] Code migration issues...

Post by Octocontrabass »

I dunno, you'll probably run into the same error again in the future as your kernel grows. You don't have anything to ensure the Multiboot header will stay in the first 8kB of your binary.
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 »

What I would do as have a section that just has the multiboot header in it, and put that at the start of the file. That way, you can guarantee that the header will be in the first 8K
"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:What I would do as have a section that just has the multiboot header in it, and put that at the start of the file. That way, you can guarantee that the header will be in the first 8K
Octocontrabass wrote:I dunno, you'll probably run into the same error again in the future as your kernel grows. You don't have anything to ensure the Multiboot header will stay in the first 8kB of your binary.
Probably linking it first in the Makefile? Does it work?
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 »

No, I mean something like this
https://wiki.osdev.org/Bare_Bones
"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:No, I mean something like this
https://wiki.osdev.org/Bare_Bones
Yes, I'm passing the Multiboot header as the first object to ld.
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