Fix metal bugs so deathstar.com runs in qemu (#20)
- Remove XD bit in page tables
- Fix cylinder+head+sector arithmetic
- Implement fstat() for serial file descriptors on metal
Here's how to boot an Actually Portable Executable in QEMU:
make -j12 o//tool/viz/deathstar.com
qemu-system-x86_64 -serial stdio -fda o//tool/viz/deathstar.com
Here's a screenshot of DEATHSTAR.COM booted in QEMU:
https://justine.lol/cosmopolitan/cosmo-metal-qemu.png
Thus metal support is in much better shape now, but still incomplete.
Only a few system calls have been polyfilled. To figure out which ones
your program needs, simply boot it in the blinkenlights emulator with a
breakpoint, and press CTRL-C to continue to the system call breakpoint.
If it doesn't break then you should be good. (Note: to emulate normally
you can press 'c' and use CTRL-T and ALT-T to tune the speed.)
m=tiny
make -j12 SILENT=0 MODE=$m \
o/$m/tool/build/blinkenlights.com \
o/$m/tool/viz/deathstar.com
o/$m/tool/build/blinkenlights.com \
-r -t -b systemfive.linux \
o/$m/tool/viz/deathstar.com
Thank @Theldus for the bug report that made this change possible.
Fixes #20 which explains this change further.
This commit is contained in:
@ -1789,14 +1789,14 @@ static void OnDiskServiceBadCommand(void) {
|
||||
}
|
||||
|
||||
static void OnDiskServiceGetParams(void) {
|
||||
size_t lastsector, lasttrack, lasthead;
|
||||
lasthead = GetLastIndex(elf->mapsize, 512 * 63 * 1024, 0, 255);
|
||||
lasttrack = GetLastIndex(elf->mapsize, 512 * 63, 0, 1023);
|
||||
size_t lastsector, lastcylinder, lasthead;
|
||||
lastcylinder = GetLastIndex(elf->mapsize, 512 * 63 * 255, 0, 1023);
|
||||
lasthead = GetLastIndex(elf->mapsize, 512 * 63, 0, 255);
|
||||
lastsector = GetLastIndex(elf->mapsize, 512, 1, 63);
|
||||
m->dx[0] = 1;
|
||||
m->dx[1] = lasthead;
|
||||
m->cx[0] = lasttrack >> 8 << 6 | lastsector;
|
||||
m->cx[1] = lasttrack;
|
||||
m->cx[0] = lastcylinder >> 8 << 6 | lastsector;
|
||||
m->cx[1] = lastcylinder;
|
||||
m->ax[1] = 0;
|
||||
Write64(m->es, 0);
|
||||
Write16(m->di, 0);
|
||||
@ -1806,18 +1806,17 @@ static void OnDiskServiceGetParams(void) {
|
||||
static void OnDiskServiceReadSectors(void) {
|
||||
static int x;
|
||||
uint64_t addr, size;
|
||||
int64_t sectors, drive, head, track, sector, offset;
|
||||
int64_t sectors, drive, head, cylinder, sector, offset;
|
||||
sectors = m->ax[0];
|
||||
drive = m->dx[0];
|
||||
head = m->dx[1];
|
||||
track = (m->cx[0] & 0b11000000) << 2 | m->cx[1];
|
||||
cylinder = (m->cx[0] & 0b11000000) << 2 | m->cx[1];
|
||||
sector = (m->cx[0] & 0b00111111) - 1;
|
||||
offset = head * track * sector * 512;
|
||||
size = sectors * 512;
|
||||
offset = sector * 512 + track * 512 * 63 + head * 512 * 63 * 1024;
|
||||
offset = sector * 512 + head * 512 * 63 + cylinder * 512 * 63 * 255;
|
||||
VERBOSEF("bios read sectors %d "
|
||||
"@ sector %ld track %ld head %ld drive %ld offset %#lx",
|
||||
sectors, sector, track, head, drive, offset);
|
||||
"@ sector %ld cylinder %ld head %ld drive %ld offset %#lx",
|
||||
sectors, sector, cylinder, head, drive, offset);
|
||||
if (0 <= sector && offset + size <= elf->mapsize) {
|
||||
addr = Read64(m->es) + Read16(m->bx);
|
||||
if (addr + size <= m->real.n) {
|
||||
|
||||
Reference in New Issue
Block a user