Commit graph

4672 commits

Author SHA1 Message Date
Christian Schnell
b63e488844 cleanup: cd-rom device now exists unconditionally 2025-06-07 21:33:46 +07:00
Christian Schnell
0257cb83c9 added "Insert/Eject CD" button to web UI 2025-06-07 21:33:46 +07:00
Christian Schnell
f3e29baa9c bugfix: cd-rom device now exists unconditionally 2025-06-07 21:33:46 +07:00
Christian Schnell
add68c3202 restored IDEInterface.device_reset() back to its original code 2025-06-07 21:33:46 +07:00
Christian Schnell
56cab05d26 documented IDENTIFY binary response, and more code cleanup 2025-06-07 21:33:46 +07:00
Christian Schnell
3f121c831f fixed SCSI Sense responses (CHECK CONDITION)
The SCSI Status field ("Status Key" and "Additional Status Code" aka. ASC) was incorrectly passed from the SCSI layer to the ATA register layer, and ATAPI command "TEST UNIT READY" was not implemented correctly.

This led to Linux not properly detecting when no CD was inserted into the CD-ROM device, which led to error output in "hwinfo" like (it attempted to read a disk that's no inserted):

> root@debian-iscsi:~# hwinfo --cdrom
> > block.5.1: /dev/sr0 cache[   78.371349] I/O error, dev sr0, sector 64 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 2
> [   78.412349] I/O error, dev sr0, sector 64 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 2
> [   78.412349] Buffer I/O error on dev sr0, logical block 16, async page read
> [   78.448365] I/O error, dev sr0, sector 68 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 2
> [   78.448369] Buffer I/O error on dev sr0, logical block 17, async page read 08: SCSI 100.0: 10602 CD-ROM

This commit fixes that problem by now properly returning SCSI Sense and Additional Sense responses to the ATAPI host.
2025-06-07 21:33:46 +07:00
Christian Schnell
2add432dbf added some comments to IDE CMOS setup 2025-06-07 21:33:46 +07:00
Christian Schnell
40dab74fa5 added references to MMC-2 (SCSI-2 Multimedia Commands) 2025-06-07 21:33:46 +07:00
Christian Schnell
20acdacfcc downgraded ATAPI CD-ROM commands from SCSI-3 to SCSI-2
In the context of ATAPI there's only a single linked document in ide.js: https://www.t10.org/ftp/x3t9.2/document.87/87-106r0.txt.

This link points to "PROPOSAL FOR CD-ROM IN SCSI-2" from 1987 (!) and its content matches the current code in v86, which the SCSI-3 documents did not at all (only the command codes matched, but otherwise SCSI-3 is very different from SCSI-2).
2025-06-07 21:33:46 +07:00
Christian Schnell
c51a0c1f53 reintroduced ATA status register bit DSC
In the original code, status register bit DSC (Drive Seek Complete, 0x10) is always set when completing without error, but ATA/ATAPI-6 specifies this bit to be command dependent. This PR now sets the status register exactly like it was before, just using named constants instead of magic numbers.

Also replaced most of the remaining magic number assignments to the ATA status register.
2025-06-07 21:33:46 +07:00
Christian Schnell
a000334266 added references to SAM-3 (SCSI Architecture Model) 2025-06-07 21:33:46 +07:00
Christian Schnell
03d0b402fb added references to SPC-3 (SCSI Primary Commands) 2025-06-07 21:33:46 +07:00
Christian Schnell
64df9aef35 added named constants for SCSI commands 2025-06-07 21:33:46 +07:00
Christian Schnell
f253f8b67e replaced more magic numbers 2025-06-07 21:33:46 +07:00
Christian Schnell
588dcaa876 replaced more magic numbers with named constants 2025-06-07 21:33:46 +07:00
Christian Schnell
81483e41fa first round of ATA command overhaul 2025-06-07 21:33:46 +07:00
Christian Schnell
4131aa709f renamed register members to better align with the standard
Renamed members that carry register values to better align with the actual wording in the ATA/ATAPI-6 standard.

Other changes in this commit include:

- added a bunch of named constants for ATA registers and their bits
- improved PCI configuration space setup
- renamed class IDEPCIAdapter to IDEController
2025-06-07 21:33:46 +07:00
Christian Schnell
b9e6445baa improved dbg_log() formatting
Merged and improved on the work from JoeOsborn in respect to formatting in dbg_log() output.
Used register names from the standard for better readability of the output, and added a few missing logs.
2025-06-07 21:33:46 +07:00
Christian Schnell
2564e30950 implemented ATA command GET_MEDIA_STATUS 2025-06-07 21:33:46 +07:00
Christian Schnell
e538b849ce renamed class IDEDevice to IDEChannel
In v86, the name "device" is already used in the context of PCI, and additionally, in the ATA/ATAPI standard the term "device" is used for disk drives.

The name used for this entity (IDEDevice) in the ATA/ATAPI standard is "channel", and since "channel" is not otherwise used in ide.js it seems right to rename IDEDevice to IDEChannel.
2025-06-07 21:33:46 +07:00
Christian Schnell
9c929e1547 fixed set/get_state()-related error 2025-06-07 21:33:46 +07:00
Christian Schnell
17d92c56d6 fixed eslint errors 2025-06-07 21:33:46 +07:00
Christian Schnell
1e645e0f06 improved single-device implementation
- immplemented Command and Status register requirements from the standard, ignored all others
- rearranged IDE register definitions, added a descriptive comment to each (standard lingo)
- fixed the EXECUTE DEVICE DIAGNOSTIC (90h) ATA command
2025-06-07 21:33:46 +07:00
Christian Schnell
f5e35644da improved documentation 2025-06-07 21:33:46 +07:00
Christian Schnell
f37e0eb5ad added boolean member IDEInterface.drive_connected 2025-06-07 21:33:46 +07:00
Christian Schnell
a04af85852 added hacky shortcut to indicate missing slave drive 2025-06-07 21:33:46 +07:00
Christian Schnell
c64d1d2dbe code cleanup 2025-06-07 21:33:46 +07:00
Christian Schnell
bcaf02af5f added IDEPCIAdapter.channels[] and IDEDevice.interfaces[] for index-based access to IDEDevice and IDEInterface objects 2025-06-07 21:33:46 +07:00
Christian Schnell
1b90d2e74e create a single PCI device instead of two
Implement a single PCI IDE device in Compatibility Mode for up to 4 drives.

Changes to ide.js:
- added new exported class IDEPCIAdapter, the root class for up to 4 drives
- introduced new config scheme for IDEPCIAdapter (see comment about adapter_config)
- moved PCI-device related members from IDEDevice to IDEPCIAdapter
- rewrote constructor of IDEDevice (no longer exported)
- fixed (?) write-access to ata_port registers 1-6 (see comment below)
- added missing declarations for BAR2 and BAR3 in pci_bars[]
- made definition of the PCI configuration space a bit more more verbose
- renamed "master_port" to "bus_master_port" to avoid confusion
- added a few comments here and there

Regarding write-access to ata_port registers 1-6: It is not clear why these 6
functions simultaneously modify master and slave attributes instead of just
modifying this.current_interface (as is the case everywhere else in the code).
This patch changes that to use this.current_interface, experimental until
there is some explanation.

Also changed cpu.js to now use IDEPCIAdapter instead of IDEDevice.

TODO:
1. clear up the matter around write-access to ata_port registers 1-6
2. in ide.js, a single-device channel needs to be better supported, currently
   the code reports a Hard-Disk device of size 0 for an unconnected slave drive,
   and there must be a better way to signal this case.
3. in cpu.js, this.devices.hda and this.devices.cdrom point to a IDEDevice, they
   should point to an IDEInterface for this.devices.hdb to make sense. This needs
   to be better understood and fixed for slave drives to work.
4. getting some very early output under SeaBIOS, but the screen clears so quickly
   that I cannot read it and it's also not printed to the serial console
2025-06-07 21:33:46 +07:00
Christian Schnell
3c944a02e0 merge changes from JoeOsborn's last changeset into current master
Merged all functionally relevant changes, omitted:

1. Left out almost all of the "dbg_log()" changes, they're like 90% of the original PR and make the essential changes in the diffs a bit hard to read, these can be added back in at a later point in time.
2. Also left out the "wants_cdrom" option and implemented its desired effect with "cdrom: { ejected: true }" as was suggested.
3. The test "tests/api/cdrom-insert-eject.js" is also left out, can be added later back in.

This patch should behave like the last changeset from JoeOsborn in 2023.
2025-06-07 21:33:46 +07:00
SuperMaxusa
760fff6af8 rtc: implement update interrupt 2025-06-04 12:04:52 +07:00
ConfusedPenguin
45d045cc44 Fix serial not handling end of line properly 2025-06-03 23:05:20 +07:00
SuperMaxusa
a07e43bc31 remove local_http flag, small fixes 2025-05-26 23:15:59 +08:00
SuperMaxusa
add1d741c5 run emulator after server, small cleanup 2025-05-26 23:15:59 +08:00
SuperMaxusa
a1c0f12961 move remaining code into if statement 2025-05-26 23:15:59 +08:00
SuperMaxusa
f344f0f40c change v86local.http to external, inline all server code into test and bench scripts, always use random available port 2025-05-26 23:15:59 +08:00
SuperMaxusa
6ce3b69be0 run a server when the emulator is ready (fixes ci) 2025-05-26 23:15:59 +08:00
SuperMaxusa
ad77448248 fix parentPort 2025-05-26 23:15:59 +08:00
SuperMaxusa
3367bedec8 use random port for server, fix console parsing for benchmark 2025-05-26 23:15:59 +08:00
SuperMaxusa
06f33e4a76 remove "use strict" after sync 2025-05-26 23:15:59 +08:00
SuperMaxusa
fc5d381c7f another fix 2025-05-26 23:15:59 +08:00
SuperMaxusa
5dc5cd249b fix closure compiler 2025-05-26 23:15:59 +08:00
SuperMaxusa
8c0fdb9f9d FetchNetworkAdapter.respond_text_and_close() method, form_response_head returns bytes instead of a string 2025-05-26 23:15:59 +08:00
SuperMaxusa
4fd2478d67 fix headers and worker error handling 2025-05-26 23:15:59 +08:00
SuperMaxusa
5f088cc066 release build for bench, check non-zero exit codes 2025-05-26 23:15:59 +08:00
SuperMaxusa
c8391e5347 fetch benchmark 2025-05-26 23:15:59 +08:00
SuperMaxusa
5e16fa3d7b docs about local_http 2025-05-26 23:15:59 +08:00
SuperMaxusa
b0b5fbee12 fix eslint 2025-05-26 23:15:59 +08:00
SuperMaxusa
6ddb163284 test with local server 2025-05-26 23:15:59 +08:00
SuperMaxusa
577b464aa4 allow access from vm to localhost 2025-05-26 23:15:59 +08:00