Recently, I decided to learn a new programming language and I know that C++(which is the language I am going to learn) is really good and fast.(fast execution)
And now I have a question about C++(and maybe C)
Is it possible to make a program that runs on every device?
like bypassing the OS and run commands/0s and 1s directly on the CPU?
or
run on a computer that does not have an OS installed, like creating your own OS?
And if it's possible then what is the difference between the .exes(windows executables) and the programs with No-OS support? (On compilation and on the file as file)
C is older than C++ but you are right that it is similar to C++ because it is compiled to binary code. When you write a C/C++ program you compile it to binary using a compiler.
Today, most desktop computers run on a variant of x86 architecture processor which started with Intel's 8086. The x86 processors are well documented. I never implemented an assembler so I can't tell exactly how to go from high level code (C/C++) to binary but I can link to the documentation which tells you how to do that. Here you have the download link for the Intel software developer manual: https://software.intel.com/content/www/us/en/develop/download/intel-64-and-ia-32-architectures-sdm-combined-volumes-1-2a-2b-2c-2d-3a-3b-3c-3d-and-4.html. Appendix B of volume 2 of this download link has the instruction encoding explanations. Here's a picture of the format of an instruction:
On x86 (and all other architectures like ARM), the instructions have a certain conventional encoding that the compiler knows and that it will use to compile your high level code to binary code. Today, when you write an OS, you use a screen and a compiler and other tools readily available to compile to binary code. With gcc/g++ on Linux you have the freestanding and static flags which allow to include all the code in your final executable and to make sure the code is self-standing.
If you write code on Linux and want to develop an OS, you need to know C/C++ quite well because you cannot use anything which relies on the standard libraries like printf() or cout. This means that you are left with the basic C/C++ like pointers (which are very important) and function calls and other stuff. You need to know quite well how the language works to control memory properly and to be able to not use stuff of the language which depends on the presence of an OS.
The .exe file is a conventional format which contains binary code. The Linux equivalent of a .exe file is a .elf file. There's nothing wrong about compiling an OS to a .exe file (or a .elf file) and parsing that file from a bootloader to jump to its entry point. The difference is that you need to tell your compiler and you need to write a program which doesn't rely on the presence of an OS to work (because you are the one who writes the OS). You are thus left with the basic C/C++ like pointers and structs. With C++ you can use classes as well because they are compiled to function calls.
For freestanding C/C++ code to work, you need to set up a hardware stack with the RSP register of the CPU. This will allow your code to call functions (other than main()). Freestanding C/C++ code relies on the presence of a stack but nothing else to work properly because all high level lines of code that you write will be compiled to CPU instructions which don't rely on anything else. If you wanted, you could even forget the stack and do everything in the main function and forget about functions. You would thus be left with pointers and structs. I think a minimum is to have functions so that you can organize your code properly. Linux is really just a freestanding, statically linked C program compiled to a .elf file and compressed with gzip. Linux follows the multiboot specification which tells how to boot it. It means that, to write Linux, the developers used only pointers, structs and functions. Pointers are compiled to memory fetch code which is one instruction in itself. Structs are compiled to data. Functions are compiled to relative jumps (short jumps), pop and push instructions (using the stack for the arguments). This is pretty much it.
You can definitely write your own OS because otherwise how would Microsoft develop Windows. To write an OS, you need to use tools at your disposition and compile freestanding and static code. Then you need to write a custom bootloader like a legacy bootloader in assembly or a UEFI bootloader in C compiled with specialized tools like EDK2. EDK2 is a compiler for UEFI bootloaders. Once you have an EFI app, you can launch that app and parse a statically linked freestanding .elf file (or .exe file) from the app. Then you can jump to the entry point of that .elf file. You can use the UEFI environment to load the .elf file from the hard disk.
Remember when you last installed an OS. You basically use a tool like Media Creation Tool from microsoft to write a small OS on a USB stick. Then you choose that USB stick to boot from the BIOS and you install the OS to an hard disk. Developing and OS is the same. You use an existing compiler and existing OS to write custom OS code. Then you write that code to a USB stick (or an hard disk) and then you test the code. A better option is emulation. You do that using specialized virtualization software like QEMU or Virtual Box to test your custom OS.
Related
I'm doing memory optimization and replacing the HAL implementation with commands that directly change bits in registers. To validate these changes, I'm changing the functions, debugging and putting the breakpoint after the function is executed, then taking snapshots of the peripheral registers through the SFR (Special Function Registers) feature of the CUBE IDE.
These snapshots are made with printscreen, my intention would be to snapshot with a log file, export all registers in a text file to use a difference program analyse. I do this for both the code using HAL and my version, then I can validate if it is stable, assuming that if the registers are equally configured, everything will work as expected.
See some sample:
implementation direct in register
implementation using HAL lib
I discovered a software (winIDEA Community Edition) that has this functionality to export to text file, it needs a little maintenance, last release was made in 06/2020. Using the examples themselves I had some problems, including one of them the software breaks and closes.
winIDEA Community Edition exporting SFR option
Does anyone have an alternative? Eclipse plugin or even a third-party tool that debugs with stlink and captures register values.
I just want to make an exe file in MATLAb to make a stand-alone application, after some research on the internet I found this link on the MATLAB website and download MATLAB Runtime compile and made my application.
It makes me a exe file but the problem is that if you want to run your code on another computer without installing MATLAB Runtime compiler it does not work.
In .Net application we install .Net framework it's OK but in this case MATLAB Runtime compiler has a huge size, it's about 1.7GB and it's little hard for user to download and install it on their computer.
Is there any way to handle it?
You can use the Matlab Coder to generate C code which you can then compile. It will not do graphics though, but it will do a lot (including some advanced signal processing). There is no way around installing the Matlab Runtime Compiler if you want graphics, although if your application runs on antiquated Matlab 5.3 (about 20 years old), this version of Matlab used to create standalone applications (with graphics) that did not require the runtime compiler.
I'm searching for options to make a GUI based application.
Application needs to intact with http servers, database and GUI.
so best option that I know is to have perl.
I'm searching for a way to Compile the code to ensure the security
also easy development of GUI.
I have started the same with Perl/TK but writing each and every lines of GUI is taking lot of time also its really hard to debug.
Is there any option to that the GUI building can be like QT or .NEt so that the GUI controls can be easily dragged and drop.
If I'm using PerlQT, is drag and drop possible?
Is it possible to compile the code in PerlQT?
Whether this will work in both linux and windows?
Is there any other option like PerlGTK or something else?
If you think “compiling” a Perl script will solve any problems, you are likely to face a disappointment.
Usually, the perl interpreter is just bundled with the plain source code and any used modules into one gargantuan executable. The script isn't really compiled. This makes nothing easier. Also, compilation has nothing to do with security, and can provide a bit of obscurity at best.
Otherwise, you could tread the crazy route and use something that serializes the Perl opcodes into C code, and compile that. Do note that while perl compiles the source into opcodes, it already executes parts of it, so that running the opcode serialization is not the same as running the actual program.
On *nix systems, compiling a Perl script is silly, as the interpreter is readily available.
If you want to fuse Perl and foreign code into one program (!= one executable), take a look at the XS language (binds C to Perl), or at the Inline family of modules.
(Perl-)Qt is pretty awesome, but the last time I looked at the recent bindings, that stuff looked undermaintained and experimental. I am sure that you could leverage the QtDesigner somehow for the designing part, and hook up Perl code with that. This should be pretty portable if you have a compiler on every target system. har har.
Other GUI Toolkits you should seriously consider are GTK and Wx. .Net is right out.
Please realize that Perl is a very dynamic language. While compilation isn't likely to be useful, you can use functional programming techniques like anonymous subroutines and metaprogramming techniques like compile time code generation to simplify your GUI coding. If you write Perl like you would write Java, or other fairly static (& compiled) languages, I wouldn't be suprised if Perl seems painful.
This is probably not a simple question so I am not looking for a definite answer but just some pointers to get me in the right direction.
I have absolutely no experience with C/C++ but have good knowledge of Objective-C. I also don't know much about different compilers and architectures so please be nice if I am talking stupid :)
I have some MatLab code that needs to be ported to Objective-C to run on an iPhone application. My first tentative path to get this done would be to check if MatLab can export the code as a static C/C++ library that I can call from within my Objective-C code.
This seems to be the case but I am not entirely sure what to do next, and what things I need to keep in mind when compiling the library on the MatLab side (i.e. architecture, compatibility, PC vs Mac, etc).
I have been provided with a .DLL and .LIB files which I believe are Windows compiled so they will not be useful for me, is this correct? From working with previous static libraries I can see they all have a .a extension - what do I need to do to get one that is compatible with the iPhone architecture?
And once I get the library compiled, how to I import and use it within my project? Will I just be able to call the public methods directly from within my code?
What else do I need to know or be aware of?
Any help is very much appreciated!
Thanks,
Rog
Static libraries contain binary code tailored for some specific operating system and platform. That means that it will use the OS to internally acquire memory (if it uses dynamic memory) or to perform any other OS specific operation (logging, output).
Even if the generated code was completely OS-agnostic (basic math could be implemented without OS support), the platform is completely different, matlab will generate code for an intel platform and the iPhone runs in an ARM architecture, with a different instruction set calling conventions...
Unless matlab is able to generate static libraries for the iPhone or at the very least for an ARM platform and make it OS-agnostic, you are out of luck.
I have some Matlab code and a GUI for it and I want to make a standalone .exe so that it can be used on computers that don't have Matlab installed.
I know about the Matlab compiler and how to use it, but that creates an .exe that only works if the user has the MATLAB Compiler Run-Time (MCR) installed.
What I'm interested in, is if there are any ways to create a standalone .exe that still uses the Matlab code but does not depend on the MCR. I want it to just run when you click it without needing anything else installed.
I know C can make use of Matlab, is there any way to use the code with C? How about any open source Matlab alternatives that can it?
As a last resort, if I were to rewrite the Matlab code in another language, what language would you recommend? I was thinking C or Python.
Thanks.
It's been a while since I looked at the MATLAB compiler but if I remember correctly it used to be able to generate C/C++ code rather than going all-out and generating an executable. The hangup was always in which toolboxes your code used and whether the compiler supported them or not. Any chance you could install the MATLAB application on a server and have a desktop client phone in for results?
As far as other languages go, I'd check out NumPy and SciPy in combination with matplotlib (matplotlib.sf.net). I'm working with a MATLAB developer right now and so far he's pretty pleased with the experience.
The MCR is required, but there's a trick: it doesn't actually have to be installed, just available on the PATH. Running MCR stuff doesn't require any registry entries or anything else special from the installation process. You just need the MCR files readable and the DLLs locatable by the normal lookup mechanism, which includes checking the PATH at the time of program launch.
For example, I've run compiled Matlab apps using an MCR that's "installed" on a network drive. You run the MCR installer on one machine and have it install to network drive X:\Matlab\MCR\R2010b-win32 instead of the usual C:\Program Files location. Then have your program be launched through a wrapper script that adds X:\Matlab\MCR\R2010b-win32\bin\win32 to the PATH before calling your actual .exe file, and it'll run on any other machine that sees the same drive, even if the MCR installer hasn't been run on them. (Eventually we stopped because loading the MCR from the network is a performance hit.)
You could use this trick to bundle the MCR with your application. Stick the whole MCR installation (the dir tree resulting from installation, not the installer program itself) in a subdirectory of your application's directory tree, and have the entry point to your app be a .bat file or other wrapper script that sticks that MCR dir on the PATH before running your MCR-dependent .exe file.
Of course, check with your legal folks to make sure this doesn't violate your licensing terms.
MathWorks recently introduced a new product MATLAB Coder. It is capable of generating C\C++ code from your MATLAB code (generates source code not executables). The generated code is portable and does not depend on the MCR, though it only supports a subset of core MATLAB language features.
I have researched a bit, and I am afraid that your only option is either using the MCR, or converting your code into another language. It makes sense that MathWorks would want you to use only their compiler in order to create .exe files.
Consider another language only if you are already familiar with them, and/or you have enough time for what you are trying to accomplish. Furthermore, if you are using functions in Matlab that you didn't write, then you will have to write those also, which may be very hard/impossible.
If none of the above is a problem, then what language you should use is really up to you. You are not just limited to C and Python. Matlab, im my opinion, is very much like other common languages, at least in terms of syntax. You will have to do some learning either way, so I would suggest that you either go with a language you know, or pick a language for which finding help is easy. C# and Java are two of the more 'famous' languages.
The Matlab 'compiler' is not a compiler. It translates Matlab m-code into C++ code and then sends that to an actual compiler like the one in Visual Studio, etc. The code it makes is not really human-readable.
To make a standalone app, install the following toolboxes (at whatever price you paid):
MATLAB Builder JA, MATLAB Builder NE, MATLAB Compiler
Set up the Matlab compiler by pointing it to the actual compiler on your drive (i.e. mbuild -setup).
Select a compiler:
[1] Microsoft Visual C++ 2008 SP1 in C:\Program Files (x86)\Microsoft Visual Studio 9.0
Then use the (i.e. type deploytool) to make the main and to define various helper functions etc. Sect windows console or standalone. Then click build. It will make the exe-file for you. You can also compile to DLL, etc as needed.
Newer versions of the 'compiler' support compiling of eval, all toolboxes that are licensed, and it supports import of java classes that will allow you to use for example, a DOM for xml-file parsing etc.
To use the resulting exe-file on a computer that does not have Matlab installed on it, you need to obtain the Matlab MCR and install it. The MCR must match exactly the version of Matlab you used to make the compiled code.
Regards,
Ivan