Comments (6)
You're using qemu-system-i386
but cosmpolitan needs x86_64. Please be warned the bootloader has undergone some recent changes that haven't been tested with qemu yet. If you could help us fix any bugs in the bare metal process then I would adore you, since it's so challenging, but so rewarding at the same time.
Intel CPU bugs like Spectre and Meltdown have significantly increased the performance overhead of having an operating system. If we can find a way to democratize ring0 privileges by making each executable its own unikernel, then we can gain back the performance edge that was lost. Unikernels can move memory without copying it. They can do i/o without the 1us syscall cost. It feels like the next logical evolution for cloud computing environments, where diskless servers that just need network is the norm.
from cosmopolitan.
Thanks again @Theldus. The change is now integrated. I confirmed it's still working for me, in both Blinkenlights and QEMU.
from cosmopolitan.
Hi @jart,
After analyzing the cosmopolitan boot process, I identified at least three points that prevent 'hello.com' from working as expected:
- In
__map_image
, the XD bit is set for the data segment; it turns out that according to the Intel SDM V3A ยง 4.5, Table 4-20:
63 (XD) - If IA32_EFER.NXE = 1, execute-disable (if 1, instruction fetches are not allowed from the 4-KByte page controlled by this entry; see Section 4.6); otherwise, reserved (must be 0).
Hence, the NXE bit of the EFER register must be set if XD is used. Otherwise, a page fault is triggered, with the RSVD error bit set.
-
The
pcread
(ape.S) function incorrectly reads the sectors of the disk: the cylinder counter register (cx) is incremented before the head counter (dh), thus, when the first sectors are read (usually 18 in 1.44MiB floppy), pcread jumps to the reading of the 36 sector, instead of the 19 (CHS (1, 0, 1) instead of (0, 1, 1)); that loads an inconsistent image from disk to the memory. -
When 1) and 2) are fixed, the code runs fine until _start, which during the execution of
ischardev
tries to execute the syscall fstat as if it were from a Linux environment, which is not the case. The 'call trace' looks like this:
#0 systemfive.linux
#1 __fstat$sysv
#2 fstat$sysv
#3 ischardev
#4 _init_g_stdout2
#5 _construct
#6 _spawn
#7 _executive
#8 _start
As the code tries to perform a syscall, a triple fault occurs. I believe that systemfive.linux
should not be invoked from bare metal, but I also don't know what should be done instead.
Anyway, I have the fixes for 1) and 2), and I can send a PR separately for each of the two if you wish. As for 3), I'm still trying to understand.
from cosmopolitan.
You're using qemu-system-i386 but cosmpolitan needs x86_64.
As I said before, I tried with both qemu-system-i386
and qemu-system-x86_64
, but in the latter Qemu just hangs in
Booting from Hard Disk...
.
Please be warned the bootloader has undergone some recent changes that haven't been tested with qemu yet. If you could help us fix any bugs in the bare metal process then I would adore you, since it's so challenging, but so rewarding at the same time.
Make sense, and sure, I have to study better how cosmopolitan works under the hood and how it integrates with bare metal, but as I find something that I can contribute, I will for sure.
Intel CPU bugs like Spectre and Meltdown have significantly increased the performance overhead of having an operating system. If we can find a way to democratize ring0 privileges by making each executable its own unikernel, then we can gain back the performance edge that was lost. Unikernels can move memory without copying it. They can do i/o without the 1us syscall cost. It feels like the next logical evolution for cloud computing environments, where diskless servers that just need network is the norm.
I completely agree with you, it would be amazing to see cosmopolitan moving in that direction in the future.
from cosmopolitan.
@Theldus deathstar.com now boots in qemu, thanks to you! https://justine.lol/cosmopolitan/cosmo-metal-qemu.png
make -j12 o//tool/viz/deathstar.com
qemu-system-x86_64 -serial stdio -fda o//tool/viz/deathstar.com # boot in qemu
o//tool/viz/deathstar.com # run on local computer from userspace
I'm very impressed by how quickly and perfectly you diagnosed the issue. The project should be fully caught up with all the claims I've made. New binaries are now published to https://justine.lol/. I hope I'll get the chance to review more issues and/or pull requests from you in the future.
from cosmopolitan.
My pleasure, I am very happy to be able to contribute and also to see cosmopolitan finally* working on baremetal, now I can really play with it, and of course, whenever I find something I will try to contribute.
* In fact there is still a tiny issue when trying to run deathstar.com or even hello.com: in your patch that corrects the CHS arithmetic, you compare the number of heads with the sector counter (cx) instead of head counter (dh), I believe something like:
diff --git a/ape/ape.S b/ape/ape.S
index 6dd6e08e..c07ee98f 100644
--- a/ape/ape.S
+++ b/ape/ape.S
@@ -348,8 +348,8 @@ pcread: push %ax
jbe 2f
mov $1,%al
inc %dh # ++head
- cmp XLM(DRIVE_LAST_HEAD),%cx
- jb 2f
+ cmp XLM(DRIVE_LAST_HEAD),%dh
+ jbe 2f
xor %dh,%dh
inc %cx # ++cylinder
2: ret
@@ -1571,4 +1571,4 @@ __data_start:
.type __ubsan_types_end,@object
Fixing this, everything works like a charm. Thanks for your time on this issue, I really appreciate it.
from cosmopolitan.
Related Issues (20)
- [readbean] Allow "localhost" in LaunchBrowser
- [redbean] os.tmpname crashes redbean
- Redbean 2.2 performance benchmarking is unexpectedly out of line with claims HOT 3
- Missing Cosmos v3.3 builds? HOT 4
- Fake virus warning Trojan:Win32/Wacatac.B!ml using Redbean at Windows 11 arm64 HOT 1
- Wireguard: permissions dropped/missing? HOT 1
- git in cosmos HOT 3
- How to build cosmopolitan without downloadimng any extra files? HOT 11
- redbean-demo-2.2.com (under Debian 12) uses 100% CPU and does not serve anything
- Daemonized redbean doesn't exit when run from ssh HOT 2
- cosmoc++: fatal error: -pie flag not supported HOT 3
- hello world bazel build, Segmentation fault HOT 6
- [Feature Request] [Redbean] Add libcurl to enable more advanced http/websocket client
- Ctrl+C has unusual behaviour while Python waits on `input()` HOT 4
- [windows] UTF-8 Console IO HOT 1
- git fails to run on Linux with the error `this ape program lacks support` HOT 2
- [redbean] Expose more of mbedtls to Lua HOT 10
- [redbean] Disable repl in foreground mode HOT 3
- [windows] fork() ReadFile_SIZE_CHECK() failed with win32 code 0 HOT 1
- Compiling luatex HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cosmopolitan.