C language compiler for new OS (theoretical questions)? [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
Let’s assume that I wrote a primitive bootloader using assembly language. The computer is still on real mode. Now I want to write a primitive kernel and shell using C language.
Questions:
1.Do I need to write a C Language compiler in assembly for this new OS or can I use a C compiler running on a different OS? I guess it could be both!
2.If I use a C compiler from a different OS, functions like printf () can be compiled to target the BIOS’s functions instead of the OS’s API to avoid dependencies?
3.If my bootloader switch the computer into protected mode the kernel will need to implement the equivalent to the BIOS functions?
4.Assuming a YES to question 3: If I use a C compiler from a different OS what is required to make it target the new OS kernel functions? Rewriting the headers files?
(EDIT) PD: These are theoretical questions. I don’t need specific details about the actual implementation. I just want to validate the concepts. Don’t feel obligated to answer all of them!

You can do either. I would strongly recommend to just use a standard compiler though. Writing a good compiler is very complex and time consuming.
As long as you do not have an implementation of the standard library just don't use it. You can tell C-compilers to assume that there is no standard library and write your own printf-like functions.
You lose access to the BIOS functions in real mode. If you need them you do need to reimplement them.
Not much change is required actually. Executables are incomplete and require to be linked against something that implements the used standard library functions and whatever other libraries used. All you need to do is link the executable against a (possible self-written) library that somehow implements the required functions.

Related

How does C access files? [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 11 months ago.
Improve this question
everyone! I'm learning how to access files in C but, I wonder how my program(or C) access files(drive sectors)? I'm searching the Internet for answers but they don't have some proper explanation on how C(or my program), loads drive sectors to memory. Please give me some clarity, and thanks in advance.
C programs use functions of the kernel or a device driver to access hardware. A computing platform (Windows, Linux, OSX, etc) that supports C provides an implementation of the C standard library for programmers. This library contains system specific implementations of functions for accessing files, like fopen. The systems implementation of the standard library is most often just a wrapper around their specific system calls. For example on Windows, the C standard library is going to end up calling these functions: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/

Is Rust entirely independent of the OS and C? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is Rust entirely independent of other languages and OSs like C is, or is it not?
Is Rust entirely independent of the OS and C?
Rust normally relies on the host system to support things like I/O. But it can be independent.
For OS development, you would use no_std: an environment for Rust without host support. This environment includes the core library (a subset of the std library) with no threads, no dynamic memory, no I/O. Implementing those would be part of developing the OS.
In C, there are a few constraints you should respect, such as not using any concurrency, limiting the use of the standard library, and such.
Not exactly. In freestanding C, there are a few standard library facilities that are guaranteed to be available.
Further, whether there may be several threads of execution is implementation-defined. When developing the usual OS with SMP etc, you will need a freestanding implementation with such support.
In Rust however, I have found that you should explicitly specify certain parts of your code to use C's linking implementation rather than Rust's, and taking many more aspects of your programming behaviour into consideration.
Not exactly either. One can program an operating system using only Rust's ABI to interface with assembly files and other bits. The problem is that such ABI is not going to be stable for the foreseeable future. Therefore, if you are willing to follow the changes, you could do it. But it is simpler to use C's instead.
Another possibility to avoid dealing with an ABI is trying to do everything with inline assembly instead.
So my question is, is Rust entirely independent of other languages and OSs like C is, or is it not?
Both can be, for freestanding purposes.

How to call a VHDL function written in a seperate file to a C program [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 6 years ago.
Improve this question
Say I have a function written in VHDL and I want to call it from C and execute it in the C program. How would I do that?
A simple example would be helpful. I searched and found this book, but it only shows how to call C functions from VHDL, not the other way round.
Can I include the VHDL code i want to implement in a device driver?.Using a tool like xilinx XPS a device driver can be made and the bitstream can be downloaded to an FPGA to make the hardware configurations .So in the end the C files will run in the microblaze and the VHDL implementation will be in the FPGA as a device driver.Can I call the driver then to the C file? because what i wanna do is to implement part of a C code in VHDL the rest of course in C and offload it to an FPGA and check whether the latency is reduced.Im using the pppd source code for this project.
The only standard interface between VHDL and other languages is the VHPI (new in the VHDL-2008 standard). There is a Modelsim specific interface called the FLI.
However, all of these languages are for VHDL to C/C++. As far as I can tell, there is no mechanism to call a subprogram from C/C++ into VHDL. And I have researched it extensively.
Depending upon the tool in use, it may be possible to call VHDL subprograms from SystemC or SystemVerilog (via SC_IMPORT or import "DPI-C", respectively), in my experience this support is very limited and very tool dependent (usually only available in very high-end commercial tools).
Now, if you want to implement some of pppd, you'd be better off implementing it via an entity/architecture pair, and then instantiating it in a SystemVerilog or SystemC environment and passing data into the VHDL entity via the given ports. Or if you insist on it being as a subprogram, use SystemVerilog or SystemC instead for implementation.

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.

How to write Hello World in pure c (Without using any c library)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I know that linux kernel source is in pure c. So I want to know how can I write simple Hello, World program in pure C without using printf api?
I know that linux kernel source is in pure c.
It is most certainly not. The Linux kernal is infamous for the frequent use of non-standard extensions from the GCC compiler.
So I want to know how can I write simple Hello, World program in pure C without using printf api?
printf is just a wrapper around the OS API functions. Do you mean to ask how to write printf using only Linux API functions? Becase "pure C" is defined in the C standard ISO 9899, which has nothing to do with the Linux OS.
When running in a process in any operating system, you have no direct access to hardware resources. So there's no way to print anything without asking the OS to do it for you.
Instead of printf, you can use a lower level API, such as write.
You can go further and issue a system call yourself, using the right machine instruction (which is OS and architecture dependent). This way you won't use any library, but will still rely on the OS.

Resources