OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Sep 25, 2017 4:40 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 95 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next
Author Message
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 7:46 am 
Offline
Member
Member

Joined: Thu Aug 13, 2015 4:57 pm
Posts: 334
Octacone wrote:
LtG wrote:
So what happens if you single-step/breakpoint at the first instruction in Kernel_Main, what's the value of EAX, EBX, and the two multiboot variables you are passing onto the function?

Test with both versions, are they both correct? Does the MBI structure that is being pointed at by EBX look valid with both versions?

Also, which of the two side-by-side versions of disasm you showed works and which doesn't?

How do you handle global objects?


Left one works, right one doesn't.

Actually I found out what is going on.
When I comment out Call_Constructors(); GRUB doesn't report 16 KB any more.

Code:
//"Borrowed" from @max, was lazy to consider looking at it myself
typedef void (*function_pointer)();
extern "C" void* start_constructors;
extern "C" void* end_constructors;

extern "C" void Call_Constructors()
{
   function_pointer* start = (function_pointer*) & start_constructors;
   function_pointer* end = (function_pointer*) & end_constructors;
   for(function_pointer* current = start; current != end; current++)
   {
      (*current)();
   }
}


Inside linker's data block:
Code:
start_constructors = .;
*(.ctor*)
KEEP(*(.init_array));
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*)));
end_constructors = .;



Where did you get the idea of doing it like that? Is there a reason you're doing it like that?

At least the Wiki doesn't seem to suggest anything like that..?


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 7:57 am 
Offline
Member
Member

Joined: Fri Aug 07, 2015 6:13 am
Posts: 863
LtG wrote:
Where did you get the idea of doing it like that? Is there a reason you're doing it like that?

At least the Wiki doesn't seem to suggest anything like that..?


It worked for other people, so I thought I would work for me too.
Wiki's article on that subject seems to be very clogged and bloated.

_________________
OS: Basic OS, Monolithic Kernel, Written in C++
Current Task: Physical Address Space Multi-functional Manager
Forever monolithic! Don't let the micro people reassure you.


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 10:25 am 
Offline
Member
Member

Joined: Fri Aug 19, 2016 10:28 pm
Posts: 199
Octacone wrote:
Wiki's article on that subject seems to be very clogged and bloated.
Here is another even more clogged and bloated article. :) There are detailed sections on initialization in it. (It is actually true that the Wiki shows the _init implementation for the init_array ABI, without handling .ctors.)

May be someone will correct me on this, but your approach should work in principle. You are not handling exceptions and per-thread storage, but that is not relevant. Still, it should be at least something like this in the linker script:
Code:
start_constructors = .;
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP(*(.init_array .ctors))
end_constructors = .;
Particularly, the ctors must be inside KEEP. Assuming that doesn't fix the issue, as always, you need to trace your code with gdb and track which ctors are called and what memory they write to.


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 10:38 am 
Offline
Member
Member

Joined: Fri Aug 07, 2015 6:13 am
Posts: 863
simeonz wrote:
Octacone wrote:
Wiki's article on that subject seems to be very clogged and bloated.
Here is another even more clogged and bloated article. :) There are detailed sections on initialization in it. (It is actually true that the Wiki shows the _init implementation for the init_array ABI, without handling .ctors.)

May be someone will correct me on this, but your approach should work in principle. You are not handling exceptions and per-thread storage, but that is not relevant. Still, it should be at least something like this in the linker script:
Code:
start_constructors = .;
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP(*(.init_array .ctors))
end_constructors = .;
Particularly, the ctors must be inside KEEP. Assuming that doesn't fix the issue, as always, you need to trace your code with gdb and track which ctors are called and what memory they write to.


That theme is just :-&, worse than "OMG Ponies". That article is just mind blowing, fame to anyone that can understand it.
Actually your example works too. I need it not to work in order for it to work, mind-blown yet? :P

_________________
OS: Basic OS, Monolithic Kernel, Written in C++
Current Task: Physical Address Space Multi-functional Manager
Forever monolithic! Don't let the micro people reassure you.


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 10:42 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 717
Location: Tallinn, Estonia
Looks like one of your ctors simply overwrites Multiboot_Info memory.

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 10:48 am 
Offline
Member
Member

Joined: Fri Aug 07, 2015 6:13 am
Posts: 863
dozniak wrote:
Looks like one of your ctors simply overwrites Multiboot_Info memory.


Is that my fault anyhow? :?

_________________
OS: Basic OS, Monolithic Kernel, Written in C++
Current Task: Physical Address Space Multi-functional Manager
Forever monolithic! Don't let the micro people reassure you.


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 11:00 am 
Offline
Member
Member

Joined: Thu Aug 13, 2015 4:57 pm
Posts: 334
Octacone wrote:
dozniak wrote:
Looks like one of your ctors simply overwrites Multiboot_Info memory.


Is that my fault anyhow? :?


Are we supposed to know/guess what _all_ of your constructors do?

Btw, do you make any allocations (new/malloc) in any of your constructors?


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 11:08 am 
Offline
Member
Member
User avatar

Joined: Mon Jul 18, 2016 2:46 pm
Posts: 170
Octacone wrote:
dozniak wrote:
Looks like one of your ctors simply overwrites Multiboot_Info memory.


Is that my fault anyhow? :?


Well obviously it is, Im pretty sure your using memory allocations in your constructor


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 11:15 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 2965
Location: Chichester, UK
I'm not convinced that C++ is a good language for beginners to use for OS development.


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 11:39 am 
Offline
Member
Member
User avatar

Joined: Mon Jul 18, 2016 2:46 pm
Posts: 170
iansjack wrote:
I'm not convinced that C++ is a good language for beginners to use for OS development.


Im somehow convinced that C++ and OOP itself is not truly meant for any critical hardware close running code.
I mean, you can use it in userspace as much as you love, but imo the kernel should be written in a language where you can manage memory perfectly even though it can be annoying.
OOP is a waste of memory and speed even on fast processors, ofcourse it obviously depends on functions and abstraction layers used such as virtual tables / jump tables whatsoever.


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 11:45 am 
Offline
Member
Member

Joined: Thu Aug 13, 2015 4:57 pm
Posts: 334
Ch4ozz wrote:
iansjack wrote:
I'm not convinced that C++ is a good language for beginners to use for OS development.


Im somehow convinced that C++ and OOP itself is not truly meant for any critical hardware close running code.
I mean, you can use it in userspace as much as you love, but imo the kernel should be written in a language where you can manage memory perfectly even though it can be annoying.
OOP is a waste of memory and speed even on fast processors.


I agree with most of what you two are saying, but OOP being a waste of memory and speed? You do realize that speed/RAM is orthogonal to OOP or lack thereof.

Of course it really depends on what type of kernel you are doing whether or not C++, or even plain old C, is a good idea. For a monolithic kernel I would think OOP is quite useful. While I'm not a huge fan of Linux, AFAIK they use OOP, though not C++.


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 12:49 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 2965
Location: Chichester, UK
I've nothing against OOP. My favourite OS was object oriented.

But I think C++ has too many pitfalls for beginners when it comes to low-level programming, linking with assembler routines, and the like. It's hard enough for some to realize that they can't use the C standard library when using C, let alone appreciating what they can and can't do with C++. I'm sure it's a fine language to use for someone who understands it fully.


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 12:54 pm 
Offline
Member
Member

Joined: Fri Aug 19, 2016 10:28 pm
Posts: 199
When you manipulate different object types uniformly, you have polymorhism, C++ or not. Behavior variation requires data that specifies it, and the single pointer in C++ is pretty minimal cost. Error handling with branches, even if properly predicted by the CPU, should still be marginally slower in the normal path. It makes for a horribly looking coding style as well. Exceptions are slower in the failure path only, and it is rarely taken. Together with RAII, they make error handling much more capsulated affair. Templates offers type safe alternative to macros, and although it is true that sometimes compilers fail to chew them info efficient code, that depends on how extensively they are used and how deeply they are nested, as well as the compiler. Genericity is a very convenient library feature.

On the other hand, it is true that templates come at the cost of making the project header centric, and dependent on inclusion order. Also, polymorphism with some syntax features make the semantics so flexible, that the code looses its self-contained meaning and can become unpredictable. Exceptions introduce hidden control flow, which must be tracked at all times, and good knowledge of RAII becomes necessity. The biggest caveat in my opinion however is that people tend to produce high-level abstractions that eventually become costly. But this is not due to C++ in itself, but due to the comfort with which such abstractions are produced in OOP style. It is abstraction that is expensive, not C++.


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 1:12 pm 
Offline
Member
Member

Joined: Thu Aug 13, 2015 4:57 pm
Posts: 334
iansjack wrote:
I've nothing against OOP. My favourite OS was object oriented.

But I think C++ has too many pitfalls for beginners when it comes to low-level programming, linking with assembler routines, and the like. It's hard enough for some to realize that they can't use the C standard library when using C, let alone appreciating what they can and can't do with C++. I'm sure it's a fine language to use for someone who understands it fully.


I agree, especially as it appears to be the case in this thread. While the relevant Wiki articles might not be the most straightforward and easiest to read, choosing to "ignore" them seems to have caused almost endless problems..

What is this favorite OS? Btw, I'm sure you've made the distinction of having an OO OS as opposed to creating an OS in an OOP language.


Top
 Profile  
 
 Post subject: Re: Undefined Array Triple Fault
PostPosted: Mon Jul 17, 2017 1:26 pm 
Offline
Member
Member
User avatar

Joined: Mon Jul 18, 2016 2:46 pm
Posts: 170
simeonz wrote:
When you manipulate different object types uniformly, you have polymorhism, C++ or not. Behavior variation requires data that specifies it, and the single pointer in C++ is pretty minimal cost. Error handling with branches, even if properly predicted by the CPU, should still be marginally slower in the normal path. It makes for a horribly looking coding style as well. Exceptions are slower in the failure path only, and it is rarely taken. Together with RAII, they make error handling much more capsulated affair. Templates offers type safe alternative to macros, and although it is true that sometimes compilers fail to chew them info efficient code, that depends on how extensively they are used and how deeply they are nested, as well as the compiler. Genericity is a very convenient library feature.

On the other hand, it is true that templates come at the cost of making the project header centric, and dependent on inclusion order. Also, polymorphism with some syntax features make the semantics so flexible, that the code looses its self-contained meaning and can become unpredictable. Exceptions introduce hidden control flow, which must be tracked at all times, and good knowledge of RAII becomes necessity. The biggest caveat in my opinion however is that people tend to produce high-level abstractions that eventually become costly. But this is not due to C++ in itself, but due to the comfort with which such abstractions are produced in OOP style. It is abstraction that is expensive, not C++.


Branch prediction works in 95% of the cases very well, I really dislike the way exceptions look like and work though.
Anyways you are are completely right, its not the fault of OOP languages but the people using them, I think I should have made that a bit more clear in my previous post.
The problem is the easier languages get for people, the more such people exist which leads to alot of bad written and slow software these days.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 95 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 15 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