Operating System Development Short Cut [closed] - c

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 wanted to try my hand at making an OS however I don't really want to do all the hardware interfaces so I was thinking if it was possible to get the core from ubuntu or another linux distro with all the hardware driver interfaces and to build it from there. I really want to start where I can simply printf to the screen in c to create a console like interface or open a grapical interface with openGl or simple pixel buffer for systems without hardware acceleration without regard to hardware.
Sounds kinda cheaty but I think it could work with a little bit of work. It there anywhere I can look for a core like this, I don't need the UNIX part just the interface to the drivers and a kernal to start my code.
Thank you for any information you can shed onto the situation.

Drivers make out the biggest part of an operating system, so what you want to write probably is not an OS.
From what you say it rather sounds like you'd like to have an OS without any predefined graphical interface. This can be easily archieved by using Linux alone.
Note: linux is an operating system which the "distros" extend by adding lots of programs and configurations. The colorful login screens and desktop environments like Unity, Gnome or KDE are only a bunch of programs, configured to autostart as soon as the system is booted. Take those away and you have one single black'n'white terminal with a shell in it and no windows, icons, menus or pointer.
That said you could try two things: Arch Linux (https://www.archlinux.org/) which is a full fledged linux distribution that comes with no desktop environment by default. If you install Arch and start your computer you'll be presented a text login and a shell, no desktop at all. The good thing about this is that you can install any programs (e.g. desktop) any time if you wanted to since Arch comes with a really nice command line package manager and repositories. Without installing any extras this is a good way to learn how to write low-level code that runs on the command line and you'll learn a whole bunch of how to set up Linux too. The Arch Linux wiki is full of very well written guides from geeks for geeks. If you want a full-fledged system that runs just fine with no desktop, this is the way. This might be too easy for you, though.
The second thing is Linux From Scratch (http://www.linuxfromscratch.org/). This is an extensive guide on how to build your own minimal Linux from scratch (who would've guessed…). Here you're way more low-level and you have full control over everything. But since you want to make your own OS the short way this might be the way to go. There's no package managing system and only vanilla code here. The funny thing about LSF is that you can change the Linux source, recompile it and tinker around with everything without having to care about any side effects like common linux services or certain programs not working anymore.

Related

How do I talk to an X server in C without a graphics library? [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 7 years ago.
Improve this question
If I wanted to write a C program to talk to an X server on Linux and produce the simplest possible visual result, e.g. setting a single pixel on the display, how would I do it?
I want to use as few libraries as possible, to understand it from the ground up, no matter how inefficient/messy the code is.
Update - by "without a library", I mean basically without any of the helper libraries that are available for X, and without a graphics toolkit.
Update - the answer is "through a unix socket", specifically /tmp/.X11-unix/X0 (on this machine at least, presumably for display 0). Actually drawing a pixel is too complicated to get into in an answer here I think.
If you want to use no library at all, you need to do these steps:
Learn assembly for the platform you target
Learn how to make a binary without using the libc on your target. This likely involves writing assembly for setting up the initial stack frame
Learn how to do system calls without using the libc on your target. This likely involves assembly.
Learn and understand network programming and how the POSIX socket API works
Learn how to open network connections without using the libc on your target
Learn and understand the X11 protocol
Implement the subset of the X11 protocol you need
Open a network connection to the X server
Tell the X server to make a window
Negotiate a colour space with the X server
Tell the X server to colour a single pixel in the window
If you want to use the libc and the libsocket, then only the following steps (roughly) remain:
Learn and understand network programming and how the POSIX socket API works
Learn and understand the X11 protocol
Implement the subset of the X11 protocol you need
Open a network connection to the X server
Tell the X server to make a window
Negotiate a colour space with the X server
Tell the X server to colour a single pixel in the window
X11 is getting old. Consider Wayland and read its FAQ. And there are several X related protocols, read about X11 Core protocol, and also conventions like EWMH.
You'll need to read several thousands of pages. Just understanding the protocols would require several months. OReilly published (in the previous century) a serie of 8 to 10 books related to X11.
You might use a low level X11 library, like XCB -or the older Xlib -, it is used by graphical toolkits like Qt or GTK (or FOX, etc..), which are both free software toolkits so you could study their source code (and Xlib & XCB are also free software).
Notice that today's GUI are usually not displaying fonts using X11 text display requests. They often use Xft (and the font is on the client side, not in the Xorg server). Actually, I heard that most of the graphics rendering practically happens on the client side, and that today most X11 requests are just sending pixmaps to the server (so X11 core protocol requests for drawing lines or circles are barely used today). More generally, the trend in major X11 based toolkits like Qt or GTK is to avoid using
the server-side drawing abilities of X11 (e.g. Xlib's XDrawLine or XDrawText), because the toolkit is drawing a pixmap image client side and sending it to the server.
You could consider using a low-level library like libSDL
The important thing to understand is that X11 applications are event driven and based upon an event loop (generally provided by the toolkit) above some multiplexing syscall like poll(2). They are asked by X11 expose or damage events to redraw some screen area (and, of course, keyboard, mouse, and the Xorg server itself are sending events).
See also this answer to a similar question.

Salvage a nice mobile phone to learn embedded programming? [closed]

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 10 years ago.
Improve this question
I have a Galaxy S II with a wrecked screen. I was wondering if the internals could be salvaged as a tool to teach myself embedded programming. I know C and enough x86_64 ASM that I would be comfortable taking on ARM assembly.
What would the development environment / set up be like?
Would I use the USB connection or is there a more direct way to connect the phone to the computer?
Would I need to prepare the phone in some way?
Let's say I wanted to write a boot loader for it, are there any good resources of where to start?
Is the phone too much of a black box, should I get a board with more documentation than that?
Or alternatively, why this is a terrible idea. Would all the drivers be too difficult to deal with if I wanted to use things like the camera?
Thanks for the help. I have no idea where to start a project like this.
If ADB ("USB debugging") was turned on, you should be able to do some development by (mis-)using adb and the android ndk to write stand alone executables. You can also install a more complete arm linux (debian etc) runtime in a chroot. You could in theory write android apps, and there are ways to trigger them from the adb command line rather than the gui, but so much of android is gui-centric that your interaction with them would be limited. Still, an app could open a network socket and give you telnet/ssh interaction.
If you don't have ADB enabled you might be able to fastboot (or whatever samsung uses) the device into a customized system image where it is enabled, or even a non-android linux build, but that would depend on having an unlocked bootloader.
Depending on how the screen is broken, you might be able to see enough to turn on ADB, for example backlight problems might be solved by lighting at just the right angle, partial cracking by rotating the device to get the needed menu options in a visible area or even deducing what is on the invisible part of the screen from what is on the visible part and a knowledge of what the menus should look like.

Best gui for remote gdb [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 7 years ago.
Improve this question
I know this question has been brought up before but it was mostly in respect to gdb for a program running on the local machine.
I've had some success with eclipse-cdt but it only seems to work occasionally. Supposedly Insight was previously used to debug (this embedded x86 board) but it seems to be dead.
I only need C debugging not C++. If possible I would prefer to connect through gdbserver (as that is on the advice and I connect to it through the command line all the time) but if you think putting gdb or ssh on the device and using it through those is better please mention those solutions also.
P.S. The version of gdbserver on the device is 7.1 it would be nice if the solution can work with a compatible version of gdb but I might be able to install a different gdbserver version.
I'd recommend eclipse Indigo it has built-in support for remote debugging applications via gdbserver. I just don't know where the source code has to be located for it to work.
Sinec it uses the MI interface of gdb it should work as any other interface that interacts with gdb.
I recommend trying out Qt Creator. It's cross-platform, has pretty good "code insight" features, and is a hell of a lot lighter-weight than Eclipse. It is a full IDE, not just a debugger front-end. It does require a gdb built with python support (client only, I think), but does come with it in its cross-platform installer. It is definitely more geared to developing C++/Qt applications, but does support generic Makefile and CMake projects, and I use it as my everyday C IDE and debugger.
Depending on exactly what kind of remote target you're debugging, the answer to this question could vary a lot. If you're cross-debugging to a deeply embedded microcontroller target running an RTOS, your options are going to be more limited.
For Makefile-based projects, you want to use the "Generic Project" creation wizard, which by default adds all the source files under the specified directory to your project. It may take some manual work to maintain your project, if you want Qt Creator to "understand" things that you've specified in your Makefile like command-line include directories (go in your .includes file), command-line included headers (go in your .config file), and command-line symbol definitions (go in your .config file). The project file list and compile, deploy, and run commands can all be maintained from the GUI though.
How about using DDD? I haven't used it much to be honest, and there seems to be a way to do remote debugging using DDD http://www.gnu.org/s/ddd/manual/html_mono/ddd.html#Remote%20Program
Gdb itself has already built-in curses based pseudo gui. By default, it splits main screen on 2 windows. Upper window contains source code, lower window is command line interface. Also there are other modes allowing to show you register values and assembly. It works well over ssh, so if you can, copy gdb on your device and debug it over ssh. If not, everything above can be applied for debugging over gdbserver.
You can use NetBeans. NetBeans support remote debugging with gdb. Gdbserver support plug-in also exist. I don't test plug-in but remote debugging using ssh working well.
Try Affinic Debugger GUI. It has newer design.
DDD is too old, Affinic Debugger supports all major platforms and is more powerful than DDD.

Running linux gcc-compiled program under windows [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
Ok, guys, hope this is quite a simple question:
is there any way to run a C program compiled under linux with gcc on a windows operating system?
Please don't tell me to recompile it under windows, since I already tried but looks like no c windows compiler has 128 bit native type, and using bignum libraries makes my program like 10 to 100 times slower.
Is there any way to actually RUN the linux binary under windows?
Someone told me something about cygwin, but I don't know where to get started with it. (My program should be portable as well, so I souldn't need to install programs and stuff on my machine).
Thank you very much!!
Matteo
No direct way. A Linux executable has a radically different format than Windows. There are several other options.
cygwin. Compile the program with GCC under cygwin. I believe that will build a windows exe that uses the cygwin compatibility layer.
install a VM like VBox. Install a Linux in the VBox. Run the program there.
http://www.andlinux.org has a framework for doing this. I've never tried it, but there is a video tutorial http://www.youtube.com/watch?v=nULDHPCm9p4.
It seems to me, that flinux could do it.
From the description:
... is a dynamic binary translator ... capable of running unmodified Linux binaries on Windows ...
Note: I've not tested this.
Please don't tell me to recompile it
under windows
You'll have to recompile it under Windows. Sorry!
If you really can't find a compiler with support for 128 bit integers you should use some assembler to replicate the instructions that you Linux compiler emits.
Since Windows 10 Anniversary Update, Windows is able to natively run Linux binaries via Windows Subsystem for Linux (WSL), commonly known as Bash on Ubuntu on Windows.
See https://msdn.microsoft.com/en-us/commandline/wsl
After installation, you can open a bash session, navigate to /mnt/<driveletter>/<path to your program> and run your executable as if you were running Linux.
Note: WSL is still beta.
Use a Virtual machine for Linux as Guest OS on your Host Windows OS. Run your executable under the VM. But compiling under gcc-cygwin combine is best bet.

How can I do GUI programming in C? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I want to do Graphics programming in C. I had searched a lot about the compiler that provides a rich set of functions for doing GUI programming in C, but I couldn't find anything.
Basically I want to draw buttons and then accept the choice from the user and take an appropriate action. It would be helpful if you can suggest a C compiler, or a library that I can add to my compiler. I am working on the Windows operating system.
Presently, I am using TURBO C compiler that does not support direct methods for creating buttons. Any help would be appreciated.
This is guaranteed to have nothing to do with the compiler. All compilers do is compile the code that they are given. What you're looking for is a GUI library, which you can write code against using any compiler that you want.
Of course, that being said, your first order of business should be to ditch Turbo C. That compiler is about 20 years old and continuing to use it isn't doing you any favors. You can't write modern GUI applications, as it will only produce 16-bit code. All modern operating systems are 32-bit, and many are now 64-bit. It's also worth noting that 64-bit editions of Windows will not run 16-bit applications natively. You'll need an emulator for that; it's not really going to engender much feeling of accomplishment if you can only write apps that work in a DOS emulator. :-)
Microsoft's Visual Studio Express C++ is available as a free download. It includes the same compiler available in the full version of the suite. The C++ package also compiles pure C code.
And since you're working in Windows, the Windows API is a natural choice. It allows you to write native Windows applications that have access to the full set of GUI controls. You'll find a nice tutorial here on writing WinAPI applications in C. If you choose to go with Visual Studio, it also includes boilerplate code for a blank WinAPI application that will get you up and running quickly.
If you really care about learning to do this, Charles Petzold's Programming Windows is the canonical resource of the subject, and definitely worth a read. The entire Windows API was written in C, and it's entirely possible to write full-featured Windows applications in C. You don't need no stinkin' C++.
That's the way I'd do it, at least. As the other answers suggest, GTK is also an option. But the applications it generates are just downright horrible-looking on Windows.
EDIT: It looks like you're not alone in wanting to write "GUI" applications using an antiquated compiler. A Google search turns up the following library: TurboGUI: A GUI Framework for Turbo C/C++:
 
If you're required use Turbo C, this might be an option.
The most famous library to create some GUI in C language is certainly GTK.
With this library you can easily create some buttons (for your example). When a user clicks on the button, a signal is emitted and you can write a handler to do some actions.
Use win APIs in your main function:
RegisterClassEx() note: you have to provide a pointer to a function (usually called WndProc) which handles windows messages such as WM_CREATE, WM_COMMAND etc
CreateWindowEx()
ShowWindow()
UpdateWindow()
Then write another function which handles win's messages (mentioned in #1). When you receive the message WM_CREATE you have to call CreateWindow(). The class is what control is that window, for example "edit" is a text box and "button" is a.. button :). You have to specify an ID for each control (of your choice but unique among all). CreateWindow() returns a handle to that control, which needs to be memorized. When the user clicks on a control you receive the WM_COMMAND message with the ID of that control. Here you can handle that event. You might find useful SetWindowText() and GetWindowText() which allows you to set/get the text of any control.
You will need only the win32 SDK. You can get it here.
C is more of a hardware programming language, there are easy GUI builders for C, GTK, Glade, etc. The problem is making a program in C that is the easy part, making a GUI that is a easy part, the hard part is to combine both, to interface between your program and the GUI is a headache, and different GUI use different ways, some threw global variables, some use slots. It would be nice to have a GUI builder that would bind easily your C program variables, and outputs. CLI programming is easy when you overcome memory allocation and pointers, GUI you can use a IDE that uses drag and drop. But all around I think it could be simpler.
A C compiler itself won't provide you with GUI functionality, but there are plenty of libraries for that sort of thing. The most popular is probably GTK+, but it may be a little too complicated if you are just starting out and want to quickly get a GUI up and running.
For something a little simpler, I would recommend IUP. With it, you can use a simple GUI definition language called LED to layout controls (but you can do it with pure C, if you want to).
Windows API and Windows SDK if you want to build everything yourself (or) Windows API and Visual C Express. Get the 2008 edition. This is a full blown IDE and a remarkable piece of software by Microsoft for Windows development.
All operating systems are written in C. So, any application, console/GUI you write in C is the standard way of writing for the operating system.

Resources