OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 3:46 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Common pitfalls
PostPosted: Tue Aug 15, 2017 9:23 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 12, 2016 10:21 am
Posts: 28
Location: London, UK
Hey,

Being the trying-not-to-be-abysmal newb I am, I've been doing a fair bit of OS theory, and trying to understand the different features of the x86 such as paging and interrupt handling. Is there anywhere I can find a small collection of common mistakes to make when implementing these? I know that there is a page ( http://wiki.osdev.org/I_Can%27t_Get_Interrupts_Working ) which explains different reasons why interrupts may not be working. I would be looking for a similar resource which covers topics such as paging and memory management (though actually the latter may be more implementation-dependent), which might come in useful when the time comes to implement those features.

I'm not looking for a tutorial or comprehensive description of these features, but rather looking for something which would help with debugging and fixing problems with the implementation of those features. I would be grateful for any which you may have found useful yourselves (since everyone had a first time, afaik :p) but if no such resource exists, or if it would be unsuitable for such a resource to exist, that's okay too. (even anything you learned from personal experience is fine)

I'm going to start writing actual code soon (as opposed to just looking things up) so it would be useful in advance to know which common pitfalls to avoid.

Thanks in advance c:

_________________
I'm bored.


Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 9:27 am 
Offline
Member
Member

Joined: Wed Aug 09, 2017 7:37 am
Posts: 80
Elttob wrote:
Hey,

Being the trying-not-to-be-abysmal newb I am, I've been doing a fair bit of OS theory, and trying to understand the different features of the x86 such as paging and interrupt handling. Is there anywhere I can find a small collection of common mistakes to make when implementing these? I know that there is a page ( http://wiki.osdev.org/I_Can%27t_Get_Interrupts_Working ) which explains different reasons why interrupts may not be working. I would be looking for a similar resource which covers topics such as paging and memory management (though actually the latter may be more implementation-dependent), which might come in useful when the time comes to implement those features.

I'm not looking for a tutorial or comprehensive description of these features, but rather looking for something which would help with debugging and fixing problems with the implementation of those features. I would be grateful for any which you may have found useful yourselves (since everyone had a first time, afaik :p) but if no such resource exists, or if it would be unsuitable for such a resource to exist, that's okay too. (even anything you learned from personal experience is fine)

I'm going to start writing actual code soon (as opposed to just looking things up) so it would be useful in advance to know which common pitfalls to avoid.

Thanks in advance c:


What do you actually want? I don't really understand what you want.

The Section 6 of the Intel Manual Volume 1 (Basic Architecture) out of 10 might be helpful. This has stuff about interrupt handling.
I have actually started reading it :)


Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 9:32 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 12, 2016 10:21 am
Posts: 28
Location: London, UK
stevewoods1986 wrote:
What do you actually want? I don't really understand what you want.

Apologies for being a bit vague. I'm looking for something which could suggest common mistakes to avoid when implementing things like paging, multitasking, networking etc. Anything like that would be okay, if it exists and is suitable.

stevewoods1986 wrote:
The Section 6 of the Intel Manual Volume 1 (Basic Architecture) out of 10 might be helpful. This has stuff about interrupt handling.
I have actually started reading it :)


That could be useful :D
I'll make sure to give it a read sometime.

_________________
I'm bored.


Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 10:12 am 
Offline
Member
Member

Joined: Wed Aug 09, 2017 7:37 am
Posts: 80
Elttob wrote:
stevewoods1986 wrote:
What do you actually want? I don't really understand what you want.

Apologies for being a bit vague. I'm looking for something which could suggest common mistakes to avoid when implementing things like paging, multitasking, networking etc. Anything like that would be okay, if it exists and is suitable.

stevewoods1986 wrote:
The Section 6 of the Intel Manual Volume 1 (Basic Architecture) out of 10 might be helpful. This has stuff about interrupt handling.
I have actually started reading it :)


That could be useful :D
I'll make sure to give it a read sometime.


Well, I don't know too much about those kinds of things (I'm a beginner as well) but the rule of OS development is to never assume something is something (for example, AL could be 0x45, not 0x00). That was a mistake I did.


Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 11:55 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Paging and interrupt handling are really fairly simple once you grasp what is happening, and why. I'm not sure there is such a thing as a list of common mistakes (other than, perhaps, remembering that most hardware devices require an EOI instruction after processing the event).

You seem to have the right attitude, so I'd suggest that you have a go at coding. Highly recommended that you avoid the beginner's mistake of wanting to write your own bootloader, and just use GRUB. It will set things up for you and give you lots of informational. That means that you can get right on with the interesting stuff rather than reinventing a rather pedestrian wheel. Another common beginner's mistake is trying to do it all in assembler rather than using a high-level language; C is probably the easiest.

Read a lot, experiment, and learn to use a debugger (qemu + gdb makes a good combination). Try very hard to solve your own problems rather than posting questions as soon as you run into a problem. That way you will learn and get a deal of satisfaction. There are a lot of good resources here and on the net in general, plus loads of documentation, so you are starting from a far better place than many here did.


Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 12:07 pm 
Offline
Member
Member

Joined: Wed Aug 09, 2017 7:37 am
Posts: 80
iansjack wrote:
Paging and interrupt handling are really fairly simple once you grasp what is happening, and why. I'm not sure there is such a thing as a list of common mistakes (other than, perhaps, remembering that most hardware devices require an EOI instruction after processing the event).

You seem to have the right attitude, so I'd suggest that you have a go at coding. Highly recommended that you avoid the beginner's mistake of wanting to write your own bootloader, and just use GRUB. It will set things up for you and give you lots of informational. That means that you can get right on with the interesting stuff rather than reinventing a rather pedestrian wheel. Another common beginner's mistake is trying to do it all in assembler rather than using a high-level language; C is probably the easiest.

Read a lot, experiment, and learn to use a debugger (qemu + gdb makes a good combination). Try very hard to solve your own problems rather than posting questions as soon as you run into a problem. That way you will learn and get a deal of satisfaction. There are a lot of good resources here and on the net in general, plus loads of documentation, so you are starting from a far better place than many here did.


There are no beginner mistakes about that. You are a liar. Also, editing the Wiki page for Beginner Mistakes isn't going to do very well. We can just see the recent activity of the Wiki as well as the last modified date. The most successful OS projects have been done with Assembly. There are a lot of things C can't actually do. C is what you like to use. Good for you. Writing your own bootloader is common sense. Using someone's code for booting your kernel?

By syntax and features, Assembly would be your best option. Use Assembly, @Elltob. The Intel manuals speak in Assembly. C is a great language. However, Assembly would be the best for OS development.

Don't mislead the OP. He/she didn't want the complaining about another thread anyway. Use some C on the way for programs in your OS. Use Assembly mostly if you want to and C with some things.

@iansjack is just making it up because of another forum thread.


Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 12:14 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
Quote:
The most successful OS projects have been done with Assembly.
Windows, Linux, and Mac OS would like to have a word with you. Of course, other languages have also been used with success -- Java, Basic, and some custom.

If interested, I did write a custom boot loader - primarily in C. We encourage GrUB since it saves a lot of time and effort, and it is much easier for beginners to use an existing boot loader in order to get their feet off the ground. Writing a boot loader is no small task and has heavy prerequisites (i.e. you should already have experience with systems programming and architecture.) You are pushing away experienced developers and I don't understand what you believe you can gain from that.


Last edited by neon on Tue Aug 15, 2017 12:24 pm, edited 5 times in total.

Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 12:19 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 14, 2013 6:01 pm
Posts: 442
almost every os written in c. also, there are platforms exist without any standardised assembly for them.

_________________
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html


Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 12:49 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
stevewoods1986 wrote:
You are a liar. Also, editing the Wiki page for Beginner Mistakes isn't going to do very well.

Now you are beginning to try my patience. It is not adult behaviour to call someone a liar just becasue you disagree with them As for editing the Wiki page, I have no idea what you are on about. I think you need to start behaving like an adult.

stevewoods1986 wrote:
@iansjack is just making it up because of another forum thread.

My advice is fairly standard, straightforward stuff - based on observations over the years of the problems that beginners have - and is nothing to do with any other thread.

To say that most successful operating systems are written in assembler is just to display a deep ignorance of these things. Assembler, particularly for beginners, is a poor choice of language for a complicated program such as an operating system. It seems easy enough when writing a simple "Hello World", but once you start needing to access structured data - such as a filesystem, a network packet, etc. - it becomes very cumbersome and difficult to maintain. It is ironic that assembler is so often chosen by beginners when it is really only suitable for use by very experienced programmers. Start using a proer language - one designed from the ground up to writ an operating system - now and avoid future heartache.

I'm afraid your attitude - know it all, but also ask it all - is going to win you very few friends here. When you have a body of work to back up your assertions then you may command some respect. But your current advice, from a self-confessed beginner, is misleading and not helpful.


Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 1:11 pm 
Offline
Member
Member

Joined: Wed Aug 09, 2017 7:37 am
Posts: 80
neon wrote:
Quote:
The most successful OS projects have been done with Assembly.
Windows, Linux, and Mac OS would like to have a word with you. Of course, other languages have also been used with success -- Java, Basic, and some custom.

If interested, I did write a custom boot loader - primarily in C. We encourage GrUB since it saves a lot of time and effort, and it is much easier for beginners to use an existing boot loader in order to get their feet off the ground. Writing a boot loader is no small task and has heavy prerequisites (i.e. you should already have experience with systems programming and architecture.) You are pushing away experienced developers and I don't understand what you believe you can gain from that.


KolibriOS and MenuetOS? The most successful OS projects. DOS was fully written in Assembly.
iansjack wrote:
stevewoods1986 wrote:
You are a liar. Also, editing the Wiki page for Beginner Mistakes isn't going to do very well.

Now you are beginning to try my patience. It is not adult behaviour to call someone a liar just becasue you disagree with them As for editing the Wiki page, I have no idea what you are on about. I think you need to start behaving like an adult.

stevewoods1986 wrote:
@iansjack is just making it up because of another forum thread.

My advice is fairly standard, straightforward stuff - based on observations over the years of the problems that beginners have - and is nothing to do with any other thread.

To say that most successful operating systems are written in assembler is just to display a deep ignorance of these things. Assembler, particularly for beginners, is a poor choice of language for a complicated program such as an operating system. It seems easy enough when writing a simple "Hello World", but once you start needing to access structured data - such as a filesystem, a network packet, etc. - it becomes very cumbersome and difficult to maintain. It is ironic that assembler is so often chosen by beginners when it is really only suitable for use by very experienced programmers. Start using a proer language - one designed from the ground up to writ an operating system - now and avoid future heartache.

I'm afraid your attitude - know it all, but also ask it all - is going to win you very few friends here. When you have a body of work to back up your assertions then you may command some respect. But your current advice, from a self-confessed beginner, is misleading and not helpful.


Assembly and C have both been used for Windows, macOS (OS X) and Linux. C is portable. I like C. It's just Assembly is a good language. There is nothing wrong with Assembly.

Fine, why don't we all use C then? It's going to be harder when you visit the Intel manual. Sorry but people have survived with Assembly. C didn't even exist before 1972. Tim Patterson made DOS in Asssembly.

Assembler? Assembly. The spelling mistakes.

I don't want to cause a fight please. I want things to be nice, OK?


Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 1:15 pm 
Offline
Member
Member
User avatar

Joined: Mon Sep 12, 2016 10:21 am
Posts: 28
Location: London, UK
Let's not veer too far off :p

I'm definitely gonna have a shot at using GRUB, though I do know how bootloaders work now it's probably better to use that. Also I think Assembly versus C is a topic for another day; I'll likely use C because it's easier to think of code like C rather than like Assembly; it's simpler to think of if/else statements and while loops than it is to think of labels, conditional branches and individual instructions. I will use inline Assembly when I need it, though. You can't load a GDT in pure C :p

Also, yes, never making assumptions is one of the cornerstones of basically anything I do with programming. If I don't know for certain, it's probably better to make sure.

_________________
I'm bored.


Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 1:17 pm 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
Please don't listen to @stevewoods1986

He is not aware of his words. Assembly is the worst programming language you could choose for such a task.
It gets very very complicated and messy very shortly. It is not easily maintainable.
I would only suggest it to people that can dream in it and have more than 20+ years of experience in it.
(omarx024 is the only person I know that hasn't been swallowed by Assembly, yet. Even he had to use C code to do the networking)
It is just such a pain in the @$$ to keep track of all the registers in your head and worrying about doing something wrong,
whereas you have a chance not to worry about any of those and use a higher level language.
Higher level languages are there to replace Assembly, it was superior 30 years ago, not anymore. Other options exist.
It is only good for making super low level stuff such as bootloaders.

@stevewoods1986 can you please stop suggesting new members to learn it and stop being ignorant. You are not doing them any good.
I fully agree with @iansjack.
Don't get offended or anything like that, but dude you are making a bootloader without knowing what filesystem are you using... :wink:

@Elttob You can load anything you want using assembly, see inline assembly for more info. Only things that are better done in assembly are: interrupt stubs, context switching, bootloaders,
when you can't use the registers but have to preserve them situations.

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Last edited by Octacone on Tue Aug 15, 2017 1:37 pm, edited 3 times in total.

Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 1:19 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
stevewoods1986 wrote:
KolibriOS and MenuetOS? The most successful OS projects.
If you think those projects are more successful than Windows, OS/2, OS/X, FreeBSD, NetBSD, Linux, Solaris, BeOS, etc., etc. then I think there is little hope for you.

Once again, I think you should learn about the subject before seeking to advise others.

@OP - sorry. Just trying to stop you from possibly being mislead by some really bad advice. Of course, as you say, "some assembly is required" - but you might be surprised how little. I've had my say and I'll bow out now, but I'd strongly recommend you to take the advice of the more experienced developers here.


Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 1:26 pm 
Offline
Member
Member
User avatar

Joined: Mon Sep 12, 2016 10:21 am
Posts: 28
Location: London, UK
iansjack wrote:
@OP - sorry. Just trying to stop you from possibly being mislead by some really bad advice. Of course, as you say, "some assembly is required" - but you might be surprised how little. I've had my say and I'll bow out now, but I'd strongly recommend you to take the advice of the more experienced developers here.


It's okay, I've been looking into osdev for *ages* and I've picked up a lot of information. I believe I've posted here once before about a programming language I was working on. I've decided to keep that separate from my first operating system project - it's actually come along very well, I'm pleased with the syntax and I've finished about a quarter of the sdk, but I'll probably first use it to write programs for my C-based operating system, to test it's working properly before diving head-first into writing an entire OS in it. It's *definitely* different to what I posted here before.

Back on-topic; I'll make sure to triple-check something before taking advice. I think at this point it's more important to do something the generic but correct way, and save the doing-it-differently way for later.

_________________
I'm bored.


Top
 Profile  
 
 Post subject: Re: Common pitfalls
PostPosted: Tue Aug 15, 2017 1:27 pm 
Offline
Member
Member
User avatar

Joined: Mon Sep 12, 2016 10:21 am
Posts: 28
Location: London, UK
And anyway, most people do it in C. If I do it in C, then more people can help out if I run into a serious issue.

_________________
I'm bored.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot], SemrushBot [Bot] and 112 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