I’ve never been a big fan of censorship. If an idea is worth expressing then it’s worth discussing.
Kernel written in bytecode
Re: Kernel written in bytecode
Re: Kernel written in bytecode
Sure, I just got the impression that you didn't think it was worth discussing.
Maybe I was wrong. Let's discuss then. Let me elaborate.
I found that there are several examples of declarative config/code that are OS related, but created by different people and solve overlapping problems. ELF tells an OS how to load the binary code/data into memory. Systemd unit files and kubernetes yaml configs tell an OS what needs to run in what order, what are interdependencies and what to do on crash/failure (restart policy). Cron does a similar job. Maybe you can add some more relevant examples of text or binary code/config that is OS related.
I suggest that we can think of the core of an OS as an interpreter of the language that can express all these things. In this way of thinking, the OS consists of three parts: the interpreter, a very compact (a few hundred lines) config, and a bunch of binary blobs containing machine code.
Re: Kernel written in bytecode
It doesn't. Executable files (of any sort, ELF or PE) contain machine code and relocation information. The OS loader gets a chunk of memory and loads the ELF formatted image there, and then uses the relocation information to fixup the image so calls and references use the right addresses. You could also decide the OS image always is loaded at a fixed position, and let the linker locate your executable at that point, and then relocation is not necessary. Long mode images can also be built so they don't require relocation.
So, no, ELF doesn't tell the OS how to load an image. The purpose of ELF is to define how to relocate an image, where the entry point is, and to provide a debugger with symbolic information.
That's not how my OS works. I have a config file that contain which drivers should be part of the OS image (potentially with parameters), which services should be started and which apps. It's also possible to add environmental variables that drivers could use. I then run a tool (on Windows) to create the OS image, which is a single binary file. This binary file is then booted and the drivers are initialized in the order they are listed in the config file. I certainly don't want this to be done by an interpreter in the OS. I want full control of what is loaded and how it is configured.vlad9486 wrote: ↑Sun Jan 26, 2025 5:42 am Systemd unit files and kubernetes yaml configs tell an OS what needs to run in what order, what are interdependencies and what to do on crash/failure (restart policy). Cron does a similar job. Maybe you can add some more relevant examples of text or binary code/config that is OS related.
I suggest that we can think of the core of an OS as an interpreter of the language that can express all these things. In this way of thinking, the OS consists of three parts: the interpreter, a very compact (a few hundred lines) config, and a bunch of binary blobs containing machine code.
I have a special driver that I always include that handles crashes. It will enter a crash monitor (debug build) or create a log and reboot (release build). If it is a debug or release build is determined by code and depends on if a particular driver is loaded or not. Again, I would not want the OS to use an interpreter to decide this.
I can take other examples of "configuration" / "interpreters" that are relevant. For instance, PCI based devices are started by checking either for specific vendor device combinations, or class of device. It's the responsibility of the driver (if loaded) to determine if the PCI hardware is present or not, and then to initialize it in the proper way.
ACPI is a common source of "configuration" in many OSes, but I only use ACPI information in special cases when it's required, like when a driver needs to figure out how an IRQ is mapped to the physical interrupt controller and it doesn't support MSI or MSI-X. There are also syscalls to list ACPI information for debugging purposes.
Thus, the major types of configuration that an OS needs to handle is external:
* The physical memory map
* ACPI which has configuration information about legacy devices, and describes how devices are interconnected, and even contain byte code (AML).
* PCI device configuration which an OS needs to parse to be able to know what to do with PCI devices
* USB device configuration which an OS needs to parse to be able to determine what type of USB devices are connected.
Re: Kernel written in bytecode
Seriously? Are you going to catch all my words? It does. In simplest case, without any relocations it contains the address where each page of the binary is mapped to the userspace. Before paging, this process was called loading.It doesn't.
You know the subject very well, perhaps better than I do. I'm not here to measure who knows more.
Me too! That's why I propose the way of flexible control over it. You will have full control not only when you write the code, but also years after. If the hardware changes, you don't need to revisit your code. Another developer can do it by editing the config, written in a specially designed language, without having to recompile the kernel and dig into your code.I want full control of what is loaded and how it is configured.
Re: Kernel written in bytecode
That's why I don't like the idea of linking a huge kernel image. All my device drivers, including basic stuff like the scheduler, are linked as separate executable files, and I decide which to bring in by a configuration file, and not by recompiling the kernel or trying trying to figure out how to change the configuration in the target system. The kernel image only contains basic memory & exception handling, support for registering kernel and user entrypoints and patching code. I want to have configuration information in a single configuration file that doesn't need to be on the target system.vlad9486 wrote: ↑Sun Jan 26, 2025 7:46 am Me too! That's why I propose the way of flexible control over it. You will have full control not only when you write the code, but also years after. If the hardware changes, you don't need to revisit your code. Another developer can do it by editing the config, written in a specially designed language, without having to recompile the kernel and dig into your code.
Re: Kernel written in bytecode
I see, so the information is only available at build time. Does your kernel support dynamic loading of modules? Like insmod in Linux?rdos wrote: ↑Sun Jan 26, 2025 8:02 am That's why I don't like the idea of linking a huge kernel image. All my device drivers, including basic stuff like the scheduler, are linked as separate executable files, and I decide which to bring in by a configuration file, and not by recompiling the kernel or trying trying to figure out how to change the configuration in the target system. The kernel image only contains basic memory & exception handling, support for registering kernel and user entrypoints and patching code. I want to have configuration information in a single configuration file that doesn't need to be on the target system.
I have read about ACPI, it is very interesting and indeed useful. But I'm working with RISC-V, which has no ACPI analog.
-
- Member
- Posts: 5655
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Kernel written in bytecode
It doesn't need to since all modules are dynamic.
ACPI is not very useful on modern hardware. As long as you only have modern PCI devices, you don't need ACPI (or devicetree).
-
- Member
- Posts: 5655
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Kernel written in bytecode
There's no standard PCI configuration access mechanism on RISC-V platforms the way there is on x86 PCs. You still need ACPI or devicetree to tell you how to access the PCI configuration space.
Also, modern x86 PCs still have some non-PCI devices that can only be detected through ACPI.
Re: Kernel written in bytecode
I doubt that is completely different between RISC-V platforms, and there problably is a common standard just like for PCs.Octocontrabass wrote: ↑Mon Jan 27, 2025 12:13 pmThere's no standard PCI configuration access mechanism on RISC-V platforms the way there is on x86 PCs. You still need ACPI or devicetree to tell you how to access the PCI configuration space.
All legacy device can be probed, so that is no reason to support ACPI. Actually, I don't have ACPI on PCs with legacy PIC, as it will typically not work properly there. The legacy hardware I support will probe the standard IO ports. After all, these legacy devices are much older than ACPI, so you cannot rely on ACPI to find them. At least not if you want to support older hardware.Octocontrabass wrote: ↑Mon Jan 27, 2025 12:13 pm Also, modern x86 PCs still have some non-PCI devices that can only be detected through ACPI.
-
- Member
- Posts: 5655
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Kernel written in bytecode
It's not completely different, but it's different enough that you can't assume fixed addresses like you could with legacy PC hardware. You need either ACPI or devicetree.
Who said I was taking about legacy devices? Modern PCs have things like SPI and I2C buses that can't be probed, the only way to find devices on those buses is to use ACPI.
But speaking of probing legacy devices, that's a bad idea on a modern PC. If the legacy device isn't there, something else might be, and that something else might misbehave. Intel Macs that lock up when probing the nonexistent keyboard controller are the most famous example, but I'm sure there are others.
How old is "older"? ACPI has been pretty reliable for at least a decade now.
Re: Kernel written in bytecode
That's chipset related stuff. Some PCs also have GPIO, special serial ports with extended capabilities, or CAN controllers. However, I doubt it's better to use ACPI for this than to simply read the motherboard manual and write a driver for it. Which seems to be how Windows and Linux often handles this. Also, these things actually are PCI devices, as basically everything in modern chipsets build on PCI.Octocontrabass wrote: ↑Mon Jan 27, 2025 4:56 pmWho said I was taking about legacy devices? Modern PCs have things like SPI and I2C buses that can't be probed, the only way to find devices on those buses is to use ACPI.
The problem here is that ACPI name spaces are not strictly enough defined, and different manufacturers use different names for the same devices. Some manufacturers will not add these devices to the ACPI name space at all since they also provide motherboard drivers for Windows, or rely on Windows drivers for specific PCI vendor/product combinations.
It's a bit like the processor speed tuning objects that often are missing since the CPU manufacturer has processor drivers for Windows. Even if they are present, they might not be correct since Windows does't use them.
That is not how I do it. I install a legacy driver because I know the legacy function exists and I want to use it. It's not some type of automatic probing. If the driver is not part of the OS image, the legacy device will not be probed.Octocontrabass wrote: ↑Mon Jan 27, 2025 4:56 pm But speaking of probing legacy devices, that's a bad idea on a modern PC. If the legacy device isn't there, something else might be, and that something else might misbehave. Intel Macs that lock up when probing the nonexistent keyboard controller are the most famous example, but I'm sure there are others.
A decade is nothing. I want to support the first 386SX from the late 1980s / early 1990s.Octocontrabass wrote: ↑Mon Jan 27, 2025 4:56 pmHow old is "older"? ACPI has been pretty reliable for at least a decade now.
-
- Member
- Posts: 5655
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Kernel written in bytecode
Where are you finding motherboard manuals that include enough information to write drivers?
The I2C bus controller in my laptop is a PCI device. The I2C touchpad in my laptop is not a PCI device.
ACPI isn't perfect.rdos wrote: ↑Tue Jan 28, 2025 2:04 amThe problem here is that ACPI name spaces are not strictly enough defined, and different manufacturers use different names for the same devices. Some manufacturers will not add these devices to the ACPI name space at all since they also provide motherboard drivers for Windows, or rely on Windows drivers for specific PCI vendor/product combinations.
Me too, but I don't see why that would stop you from using ACPI on modern PCs.
Re: Kernel written in bytecode
It's a two step process. You indentify which chipset they use, and if it is Intel (but probably also for AMD), then you can find the chipset manual on their site.Octocontrabass wrote: ↑Tue Jan 28, 2025 2:05 pmWhere are you finding motherboard manuals that include enough information to write drivers?
The touchpad is probably an USB device, which means it's on top of XHCI, or some other USB controller, and USB controllers are always PCI devices.'Octocontrabass wrote: ↑Tue Jan 28, 2025 2:05 pmThe I2C bus controller in my laptop is a PCI device. The I2C touchpad in my laptop is not a PCI device.
ACPI doesn't know anything about USB devices, and it also doesn't know anything about PCI devices that are plugged into PCI slots.
I do, but if I started from scratch, I probably wouldn't.Octocontrabass wrote: ↑Tue Jan 28, 2025 2:05 pmMe too, but I don't see why that would stop you from using ACPI on modern PCs.
-
- Member
- Posts: 5655
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Kernel written in bytecode
That works for the chipset, but what about the rest of the motherboard?
No, it's definitely an I2C device attached to one of the chipset's I2C controllers.
Can you explain why supporting a 386SX prevents you from supporting ACPI?