dev: Make the IDE controller handle NULL simobject pointers.
authorGabe Black <gabeblack@google.com>
Tue, 26 Sep 2017 00:53:57 +0000 (17:53 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 26 Sep 2017 23:47:24 +0000 (23:47 +0000)
Only panic if there are disks which would actually be connected to it beyond
its limit. Also skip past disks which are set to NULL. This is useful since
it lets you set up disks on different ports of the controller instead of
filling them contiguously.

Change-Id: I92f1316d3ad6931e25bfffeb34fb2603c0b95ce7
Reviewed-on: https://gem5-review.googlesource.com/4848
Maintainer: Gabe Black <gabeblack@google.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
src/dev/storage/ide_ctrl.cc

index 6d507269f402454b8bfec4ea03169b292e2b2426..d1c9f7d73beea2ca1f222d031dbb4b8abf78f187 100644 (file)
@@ -102,23 +102,31 @@ IdeController::IdeController(Params *p)
     ioEnabled(false), bmEnabled(false),
     ioShift(p->io_shift), ctrlOffset(p->ctrl_offset)
 {
-    if (params()->disks.size() > 4)
-        panic("IDE controllers support a maximum of 4 devices attached!\n");
 
     // Assign the disks to channels
-    int numDisks = params()->disks.size();
-    if (numDisks > 0)
-        primary.master = params()->disks[0];
-    if (numDisks > 1)
-        primary.slave = params()->disks[1];
-    if (numDisks > 2)
-        secondary.master = params()->disks[2];
-    if (numDisks > 3)
-        secondary.slave = params()->disks[3];
-
     for (int i = 0; i < params()->disks.size(); i++) {
+        if (!params()->disks[i])
+            continue;
+        switch (i) {
+          case 0:
+            primary.master = params()->disks[0];
+            break;
+          case 1:
+            primary.slave = params()->disks[1];
+            break;
+          case 2:
+            secondary.master = params()->disks[2];
+            break;
+          case 3:
+            secondary.slave = params()->disks[3];
+            break;
+          default:
+            panic("IDE controllers support a maximum "
+                  "of 4 devices attached!\n");
+        }
         params()->disks[i]->setController(this);
     }
+
     primary.select(false);
     secondary.select(false);