problem with Higher_Half_x86_Bare_Bones

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.
Post Reply
stdcall
Member
Member
Posts: 78
Joined: Thu Mar 14, 2013 1:30 am

problem with Higher_Half_x86_Bare_Bones

Post by stdcall »

Hi.
Is it only me, or there is something wrong with the Barebones code.
The multiboot header is not placed in start of the text section, which causes grub to barf.

Is it OK to have 2 program headers ? I think that this might be the problem, but I'm not sure.

Here's the readelf output:

Code: Select all

$ readelf -l kernel.bin
Elf file type is EXEC (Executable file)
Entry point 0x10186c
There are 2 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x001000 0xc0100000 0x00100000 0x0250c 0x0250c R E 0x1000
  LOAD           0x004000 0xc0103000 0x00103000 0x02000 0x06e20 RW  0x1000

 Section to Segment mapping:
  Segment Sections...
   00     .text .eh_frame 
   01     .data .bss 
Additionaly, there's a warning from nasm regarding the assembly code:
boot/loader.s:48: warning: symbol `loader': GLOBAL directive after symbol definition is an experimental feature
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS
User avatar
Mikumiku747
Member
Member
Posts: 64
Joined: Thu Apr 16, 2015 7:37 am

Re: problem with Higher_Half_x86_Bare_Bones

Post by Mikumiku747 »

I'm not sure about the multiple program headers, but it seems that the linker script used in that tutorial is a little different from what's done in the regular x86 bare bones (Apart from the fact that it's a higher half kernel). For one thing, the multiboot header isn't explicitly placed anywhere in the linker script, it's just placed at the start of the start of bootstrap.asm text section, which could eventually get forced out of the area the multiboot bootloader checks when other text sections start getting linked into the kernel.

They also put the read only data section inside the text section of the output as well, instead of in its own section in the output? (I'm not actually sure there's a problem there, but it just differs from what I've seen, and it would make sense to put rodata in it's own section so that eventually the page could be marked read only when you eventually enable various protection schemes...) Either way, I'm sure the author did things they did for a reason, so if it doesn't work fully, it might be better to try and stick to something which you know and understand well, and use that as a basis for your higher half kernel.

I'm not really an expert on the subject, but I did use the higher half bare bones as a base for my own higher half kernel, if you'd like to take a look at that for a reference you can, but I'm not promising that it's a good example, and hopefully somebody more versed in the subject can provide a good reference and fully explain the design decisions in the higher half tutorial. I believe a little while ago one of the veterans on the forums had a better structured higher half tutorial, but I can't find it any more.

My own linker script and bootstrap for a higher half kernel, based heavily on the tutorial. I set up the bare minimum of paging needed to call into higher half C code in my bootstrap, which means that the bootstrap is really ugly and wastes lots of space, so feel free to come up with a better way to do that, I'm awful at assembler, and I'm sure that somebody could turn most of the bootstrap I wrote into macros and compiler options.

As for the multiple program headers, I have no idea, it might have something to do with compile settings, but that's all I have, hopefully you can get that working.
stdcall
Member
Member
Posts: 78
Joined: Thu Mar 14, 2013 1:30 am

Re: problem with Higher_Half_x86_Bare_Bones

Post by stdcall »

Eventually I fixed the issue.
I added a multi boot section and placed it in the text section in the linker script.
Then I ran into a different issue, where grub complained about loading point outside a section.
I solved that by crating a specific section only for the loader.

I don't understand how this tutorial ever worked.

I don't mind fixing it if the way I fixed it is the correct way...
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: problem with Higher_Half_x86_Bare_Bones

Post by glauxosdever »

Hi,

mellowcandle wrote:Eventually I fixed the issue.
I added a multi boot section and placed it in the text section in the linker script.
Then I ran into a different issue, where grub complained about loading point outside a section.
I solved that by crating a specific section only for the loader.

I don't understand how this tutorial ever worked.

I don't mind fixing it if the way I fixed it is the correct way...
This tutorial is utterly broken and I'm working on a replacement. However, it's not complete, so don't rely on anything written there.


Regards,
glauxosdever
Post Reply