LInux vs BSD for kernel development [closed] - c

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I recently updated my rusty C skills, and I've been trying to find a project to try them out on, so I picked kernel development (after all, C is a systems language). So, I was wondering which would be easier to start out with, Linux or one of the BSDs? Linux has a larger userbase (so I would probably have more support), but it also has a humongous codebase (9 million lines last time I checked), would the BSDs be easier to start out with because they combine the userbase and kernel into one large codebase? Also, is it best to just start reading the kernel source code? And, are they trying to implement new features aside from SMP and new drivers?

Unfortunately, I can only speak of Linux kernel hacking for myself. Currently I'm in an internship where I am working on a kernel, and I never did this before. But I was able to learn a lot of stuff in a quite short time, due to several reasons (again, I want to point out that I don't know how much of this is covered withint he BSD community):
Tutorials. The Linux Community is quite big and therefore you will find a lot of beginners information on kernel hacking. I feel like the standard to begin with was this guide. If you read it you will see, that even kernel hacking starts with hello world ;)
Linux Cross Reference. A great tool. It covers the complete Vanilla source code and shows you where each function/struct/define/whatever was defined and implemented, so no long searching for some stuff
The modular build of linux (I assume the same goes for BSD) Clearly you won't be able to look through 9 mio lines of code. But you can start easy with a little loadable kernel module and then go deeper. Maybe look at other modules first, hack them, and finally dig into the directly compiled stuff
The sheer community size. Not only kernel mailing lists, but also a huge number of forums or Q&A sites like this one where you can be sure to get help if you don't know what to do ;)
Just my 2 cents ;)

I am using and developing for Linux for many years, but am lacking any real experience with BSD to recommend either way.
You sound lacking experience for kernel hacking. Just reading kernel source might be insightful, but won't really teach you much. There is a lot going on in Linux kernel besides drivers. For example, latest 2.6.38 was focused on desktop responsiveness. DRM stack is ever changing and could use more man power.
I'd suggest start easy, small fixes for beta drivers, etc.

Related

Microcontroller IDE like simulink [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I have a query that, is there any simulation software available (like simulink in matlab) for micro controllers.
I have tested my system on simulink and generated a c code for it.Now I want to verify the code by running it on a micro controller simulator which also have such scopes etc(so i can easily verify my embedded code).
Xcos is a simulink analogous in Scilab very helpful for most who can't afford a matlab license. The Arduino library will help you making whatever project you want.
You can download it free here https://www.scilab.org/
Now I want to verify the code by running it on a micro controller simulator which also have such scopes et (so i can easily verify my embedded code)
You might consider a static program analysis approach. Tools like Frama-C or Coverity or Clang analyzer come to mind. But they are difficult to learn or use. If your code is compilable by some recent GCC-based cross-compiler, consider also developing your GCC plugin.
For some microcontrollers, you might find software emulators for them (e.g. sourceforge lists several of them). Qemu could be a possibility (but again, there is a learning curve).
See also this report....
Take into account your time (including learning efforts). You might decide that buying an arduino (or a RaspBerryPi) is cheaper than learning to use emulators for it. For example GCC is free software, but you'll need months of efforts to dive into its source code (many millions lines of code). Scilab is also free software. So is GHDL.
If you have access to the entire documentation of your micro-controller (including cycle times of every machine instruction), writing the emulator is also a possibility. Again, budget months of efforts. JIT compilation libraries such as libgccjit or libjit could be interesting to use for that. Or higher-level languages (e.g. SBCL).
Be also aware of Rice's theorem, C compilers like CompCert, and processor architectures like RISC-V or simulator frameworks like UniSIM
Notice that automatically assisted verification of C code reduce program bugs, but not software design bugs. You basically move bugs from programs to their specifications (as described by the V-model of software development). There is No Silver Bullet

Windows programmer moving to linux - Coding conventions [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have been developing for Windows for a long time, mainly WinApi (and .Net).
I'v started learning basic Linux, and I have some questions regarding the differences:
In Windows I have barely used the C Standard library.
If I needed an API, I would search MSDN and find the appropriate library\function.
From what it seems like, in Linux the C Standard library is EVERYTHING.
All the code samples I have seen used the standard library (Instead of using some Linux internal functions, like a Linux "CreateFile").
Is this really how writing "proper" linux code is done ? Using the C standard library ?
If I wish to read a file, or allocate memory are fopen\malloc the way to go ?
If the answer to my first question is yes (And I guess it will be)
The C standard library is POWERLESS compared to the powerful WinApi.
Lets say I wish to get a list of running process (CreateToolhelp32Snapshot) or create a thread or a process (CreateThread\CreateProcess), How should I do that in Linux ?
Documentation.
In Windows, all I need can be found in MSDN.
If I have a "how do I do" question (Like the questions above) where should I go ?
Where is my main source of documentation.
Thanks a lot,
Michael.
Perhaps you've forgotten that the Standard C Library isn't environment-specific, it specifies least-common-denominator functionality among all systems that can run C programs, and C runs on systems that don't even have processes.
If you want an API that provides consistent common GUI/multithread/etc. APIs, pick a likely-looking GUI/multithread/etc. API. You might start with Qt, it's quite comprehensive and produces good-looking, near-native UIs on a host of systems.
It's not generally considered polite to point this out, but most questions that get asked publicly are asked by people who lack the discipline to do even simple research. Once people can do that, they don't need to ask very many, and that's why what you see is so ... trivial. You're past that. For more options, you could start here.
For more general-purpose tools, the top hit on a search for important linux tools might be helpful.

linux kernel step by step [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
i know c language.my goal is to read linux kernel.so what languages should i learn(write books too) before start reading kernel and is there any book to help reading linux kernel
This book is a little outdated, but Understanding The Linux Kernel is an amazing reference. It will also give you a crash course in i386 features that make a lot of the kernel facilities possible (such as the MMU and how interrupts work. With operating systems, it's sometimes hard to understand where the hardware ends and the OS begins), and reference a lot of the critical source directly.
Also, look into the LWN Kernel article index for more up-to-date references.
One good way to start is come up with a really simple feature that you'd like to add to the kernel and start hacking away at it. (Something I did in college was count how many times each process got preempted and export that value via the /proc file system. Taught me a lot about scheduling, /proc, the process structure, and many other facilities). Also a recommendation, do this in a VM unless you plan to reboot every fifteen minutes.
For ad hoc questions, searching Google works, or asking questions on IRC. (Respectfully, of course.)
The Linux kernel is over 11.5 million lines long! It takes years to be a good programmer and you have to be one if you want to hack the Linux kernel. Taking your age and experience into account, you will most probably fail if you make that your first C project. I recommend getting your hands wet on some other cool stuffs using C. For Example, port the codes in the GreyHat Python book (debuggers, hooking, fuzzing and e.t.c) to C and add interesting features to them. If you are really into OS development, I recommend reading good books on Assembly and writing your own little real time OS. I've seen a real time OS written by a 13 year old kid so it's possible. Good luck!
Not so long ago there was a Linux kernel workshop at Hackerspace Brussels. You can take a look at the links on the event page https://hackerspace.be/LinuxKernelWorkshop
I raised this question myself years ago. I've then got stuck into lines of Linux kernel source code to figure out how it works. Till now my understanding on Linux kernel is still a mix. I think the best way to understand a program is write it by yourself. To build an OS, I think this is the minimum:
computer hardware & architecture
assembler & compiler
assembly
C language
There are lots of books out there that could help you read Linux kernel piece by piece. You still have a lot of time to rewrite it yourself.

What open source C projects are worth studying for learning good design? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
What small open source projects in C are interesting for learning good design?
The project should be:
Not too large (like the linux kernel)
Well documented
Perhaps still under active development
I've just started learning C, and while the language itself is not too difficult, i'm struggling how to design larger applications, so i thought checking out other open source projects would be a good starting point.
Thanks!
Redis (nosql db) is:
under active development
a manageable size
portable and robust
has no external dependancies
very well written, understandable code
In my opinion, good examples of moderately sized projects written in C are:
GNU Scientific Library (besides the source code, don't miss their design document)
Kazlib
Git
Posix threads are a perfect example of good C design
I like gnucash: http://www.gnucash.org/
No too large like Linux kernel, but still big I think.
You can start learning from small and well structured applications like http://abygaelle.guillaume-fr.net/trac/gemmes
It all depends what kind of projects you are interested in. And what aspect of it (specific algorithms, UI, networking, etc, etc...)
Head over to freshmeat, sourceforge or ohloh and browse the projects for your area of interest.
Alternatively if you want to look at projects that were chosen for a particular reason google summer of code might be interesting for you - even though these rarely include full projects.
EDIT:
Also alternatively, you might take something like linux kernel, but instead of trying to understand everything try to
get the big picture
then concentrate on one tiny piece of it and inspect how the code changed over time (and for what reasons - it should be quite well documented)

How should I get started on writing device drivers? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I would like to learn how to write device drivers because I think it would be fun. I use a Mac OS X Macbook, but I also have an Ubuntu machine (running on a Mac Min). I am pretty familiar with C and currently am reading this book. I have found some links online such as Mac Dev Center. I am doing this because it would be fun. I think there would be real gratification to see hardware operate because of software I wrote.
I guess what I would like is some tips or advice and guidance, and does anyone know of a list of devices that don't have drivers or can I write a driver for something that's already supported (would prefer the former so I'm actually providing value). What's a good device to get started with? Am I biting off more than I can chew? I'm not afraid of low level programming or assembly or whatever amount of effort is required. I'd like a challenge really!
For Linux, you might look into picking up the O'Reilly Linux Device Drivers book or reading PDFs online. In my opinion, it is one of the better texts around on the subject.
The Linux Kernel Module Programming Guide is another good resource.
You may also want to pick up a book specifically on the Linux Kernel. I picked up a copy of Robert Love's Linux Kernel Development (2nd Edition) for this purpose (3rd Edition on the way).
Writing a device driver can be pretty simple, or it can be almost arbitrarily complicated. For instance, I've been involved in a project where it took six of us almost three years to solve ONE bug in a device driver. Of course, we cleared out dozens of other bugs while looking for it... the code improved immensely. The fix turned out to be an eight line patch, that cost, conservatively, about a million dollars.
But, as a side project to that, I wrote an ethernet driver from the chip data sheet in a week, and took another week to debug it. Haven't needed to touch it since.
There's no way to say in general how much work a driver will be; a GPU driver could cost hundreds of millions, a driver for a single LED costs a couple of hours work at the most.
If you want to go for Linux device driver development, the freely available O'Reilly book Linux Device Drivers, Third Edition is a must read.
In order to find unsupported hardware pieces for which you could write a driver, ask on the Linux mailing lists. Maybe some USB 3.0 device? ;)
For Mac you might want to take a look at Mac OS X Internals book. It's think and heavy but fun to read. It is mostly about PowerPC-based Macs but has an appendix about Intel-based ones. For Linux take a look at Linux Device Drivers, 3rd Edition - it's lighter (free PDFs online :) and is really device driver-oriented, might be a better start.

Resources