Beginner Mistakes: Difference between revisions

m
gr comma
[unchecked revision][unchecked revision]
m (Grammar and formatting touch-ups. Meaning adjustment in Popularity section.)
m (gr comma)
 
(12 intermediate revisions by 8 users not shown)
Line 15:
 
=== A Hard Truth ===
'''''NoProgramming onenovices whoshould isn't already a seasoned developer with years of experience in several languages and environments shouldprobably evennot be considering OS Dev yet. AExperience decade of programming, including a few years ofin low-level coding in assembly language and/or a systems language, such as C, is pretty much the minimum necessary to even understand the topic well enough to work in it.'''''
 
What's more, this is growing ever more true by the year, as the number of different 'standards', computer and mobile device models, peripherals, and design concepts continues to expand.
Line 48:
 
=== Commercial OSDev ===
Also, donDon't get your mind set that building such a great OS will make you rich. If anything, history has shown us that the best operating systems never receive any commercial success, while the ones that have a near total lack of design and inspiration do, because of clever business moves and being in the right place, at the right time, with the right cover-up.
There really is no such topic. OSDev will probably never land you a job. (As shown in the "Jobs" section of the forum.)
 
Despite that, and despite the relative emptiness of the "Jobs" section of the forum, a few sole-developer operating systems have had some commercial success. One example is [[User:01000101|01000101]] with "Drop-in Network Security", an OS designed to act as a specialized deep-packet analyzer. Note that it's specialized to a particular application. To market your OS in this way, you need to understand the application just as well as you do OS dev, perhaps more, and you need to be quite good at coding both. Your customers will expect you to be professional.
Also, don't get your mind set that building such a great OS will make you rich. If anything, history has shown us that the best operating systems never receive any commercial success, while the ones that have a near total lack of design and inspiration do, because of clever business moves and being in the right place, at the right time, with the right cover-up.
 
Another possibility is marketing your OS to companies which presently use MS-DOS for process control. This may seem easier in that you're not responsible for the final application, but you will need to be professional and responsive to your clients problems and queries. They may require long-term support. They may not like a feature you really want to implement.
 
=== Assuming It Will Go Nowhere ===
Line 60 ⟶ 62:
Beginners often ask "What is the ''easiest'' way to do X?" rather than "What is the best, proper, correct way to do X?" This is dangerous as the newcomer doesn't invest time into understanding the superior way to implement something but instead picks a conceptually simpler method copied from a tutorial. Indeed, the simpler route is often ''too simple'' and ends up causing more problems in the long run, because the beginner is ignorant of the superior alternative and doesn't know when it is better to switch. What's so bad about taking the hard route instead?
 
Common examples include being too lazy to use a [[GCC Cross-Compiler|Cross-Compiler]], not understanding [[Real Mode]], [[Unreal Mode]], [[Protected Mode]], and [[Long Mode]] and jumping far too fast from one to the other without first understanding how to gather all of the vital configuration and use all of its capabilities fully (especially detecting basic capabilities with the BIOS during boot and initialization), relying on [[BIOS]] calls or DOS services that are not standard, not learning to write hardware drivers in your own OS and under Windows and Linux for greatest convenience, exposing test capabilities globally, using flat binaries instead of [[ELF]], not learning about executable, archive, graphics, document and other file formats and compression algorithms, and so on. Experienced developers use the superior alternatives for a reason, which you might not understand yet. Experienced developers choose to use the inferior method in some cases, but that's because they can carefully analyseanalyze whether it is appropriate, and they know when ''not'' to use it. As a beginner or intermediate developer you will likely not know these methods and technologies well enough to reason whether the inferior solution is good enough for you. Remember that if you oppose a method, you should know it well enough to know everything that is wrong (and right) with it. Either way, laziness and ignorance only leads to trouble down the road. When in doubt, pick what appears to be the conservative choice rather than the simpler.
 
== Design ==
Line 81 ⟶ 83:
''I want to use less than a couple of kilobytes for my OS!''
 
Sorry, that's probably impossible. An OS using such little memory will be almost unusable. Forget about filesystem drivers, disk drivers, usb drivers, etc. IfFor you want to developdeveloping something small, just make a simple bootloader, not an OS.
 
Another option would be to try a native Forth; it's like a little OS with the kernel, command interpreter, and assembler all in one tiny binary! Parts of the kernel can even be scripted. It doesn't even need a filesystem; many Forths directly edit and load disk sectors. There's a big catch: Forth is not light on skill. Writing good Forth is a whole other planet which programmers would need to understand to get beyond the bare basics. Surprisingly, some Forth fans are good at writing Forth interpreters but are poor Forth programmers. An OS developer will need to be a good(-ish) Forth programmer to fit OS design concepts to Forth, or to figure out which concepts are not needed. Otherwise, the OS would be ''much larger'' than it needs to be. ;)
 
It can take a lot of time and thought to write compact Forth code. Charles Moore, inventor of Forth, wrote a CAD program which was structured around just 5 lines of code; it took him about 2 years.
 
=== OS Emulation ===
Line 96 ⟶ 102:
=== Booting Problems ===
Especially in early stages and with a self-built bootloader, the reason for booting problems is frequently that too few sectors are fetched from disk. Either adjust the amount of sectors you fetch from disk, or have the boot loader/second stage loader parse the file system.
<!-- TODO: Hmm, this doesn't seem appropriate for this particular tutorial and is somewhat outdated as we always recommend using a cross-compiler. I'll just comment this out for now. --~~~~
=== Strings ===
When your Kernel is written in C, gcc puts strings and constants in a special section called ''read-only data''. This section needs to be explicitly added in your linker script, otherwise it can cause all sorts of weird problems (unable to print text to the screen, kernel suddenly becoming 1MB larger, GRUB giving a loading error saying ''kernel too large'', etc). The section is called ''.rodata'' in [[ELF]] and ''.rdata'' in COFF/PE (the output format for MinGW/Cygwin). Building a [[GCC Cross-Compiler]] will help you to safely assume ''.rodata'' everywhere.
 
You could also tweak your linker script to include ''either'' section:
 
<source lang="c">
// ...
.text 0x100000 {
*(.text)
*(.rodata*) /* <---- ELF Cross Compiler or ELF *NIX (eg. Linux) */
*(.rdata*) /* <---- COFF/PE MinGW or Cygwin on Windows */
}
// ...
</source>
-->
 
== Troubleshooting / Asking for Help ==
Before asking for help on the forums or IRC, you should be taking all the possible steps to diagnose the nature of the problem yourself. In the case of problems like triple faults or "random" exceptions, it's a common mistake to make assumptions about the cause of a problem. Make use of a debugger or print statements to locate the exact point when an exception occurs. Using and emulator and a debugger (such as GDB and Bochs/QEMU) will help you to locate problems which are difficult to trace. If you provide some theory about the problem and actions you have already taken to solve it, people will be able to help you much easier (even if your theory is not correct, it at least gives people an idea of your views on the problem and the strategies you might have already tried, as well as what you might have missed).