From 222cb02431ba9d7f48cfc65523b1f71e5546c2a0 Mon Sep 17 00:00:00 2001
From: "adrian.spycher" <adrian.spycher@etu.hesge.ch>
Date: Tue, 5 Nov 2024 18:06:37 +0100
Subject: [PATCH] chore: rename macro REG for the ide

---
 guest/ide/ide_phys.c      | 19 ++++++++++---------
 shared/hypercall_params.h |  4 ----
 shared/ide_regs.h         |  6 +++---
 3 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/guest/ide/ide_phys.c b/guest/ide/ide_phys.c
index 84f2372..a82a9d6 100644
--- a/guest/ide/ide_phys.c
+++ b/guest/ide/ide_phys.c
@@ -1,8 +1,8 @@
 #include "ide.h"
 
+#include <stdint.h>
 #include "guest/pmio.h"
 #include "shared/ide_regs.h"
-#include <stdint.h>
 
 // --- DEFINE ---
 
@@ -15,7 +15,8 @@
  */
 static void wait_drive() {
 
-    while ((inb(IDE_STATUS_REG) & 0xC0) != 0x40);
+    // 0xC0 = 0b1100'0000, 0x40 = 0b0100'0000
+    while ((inb(REG_IDE_ST) & 0xC0) != 0x40);
 }
 
 /**
@@ -26,11 +27,11 @@ static void pio_prepare(uint32_t sector) {
 
     wait_drive();
 
-    outb(IDE_DATA_BASE_REG+2, 1);                               // sector count
-    outb(IDE_DATA_BASE_REG+3, sector & 0xff);                   // send bits 0-7 of LBA
-    outb(IDE_DATA_BASE_REG+4, (sector >> 8) & 0xff);            // send bits 8-15 of LBA
-    outb(IDE_DATA_BASE_REG+5, (sector >> 16) & 0xff);           // send bits 16-23 of LBA
-    outb(IDE_DATA_BASE_REG+6, ((sector >> 24) & 0x0f) | 0xe0);  // send bits 24-27 of LBA + set LBA mode; 0xe0 = 11100000b;
+    outb(REG_IDE_DATA+2, 1);                               // sector count
+    outb(REG_IDE_DATA+3, sector & 0xff);                   // send bits 0-7 of LBA
+    outb(REG_IDE_DATA+4, (sector >> 8) & 0xff);            // send bits 8-15 of LBA
+    outb(REG_IDE_DATA+5, (sector >> 16) & 0xff);           // send bits 16-23 of LBA
+    outb(REG_IDE_DATA+6, ((sector >> 24) & 0x0f) | 0xe0);  // send bits 24-27 of LBA + set LBA mode; 0xe0 = 11100000b;
 }
 
 // --- FUNCTION ---
@@ -39,13 +40,13 @@ void ide_phys_write_sector(uint32_t sector, void *data) {
 
     pio_prepare(sector);
 
-    outb(IDE_CMD_REG, 0x30);  // command port: write with retry
+    outb(REG_IDE_CMD, 0x30);  // command port: write with retry
     wait_drive();
 
     uint16_t *d = (uint16_t *)data;
     for (int i = 0; i < MAX_LOOP_IDE_DATA; i++) {
 
-        outw(IDE_DATA_BASE_REG, *d);
+        outw(REG_IDE_DATA, *d);
         d++;
     }
 }
diff --git a/shared/hypercall_params.h b/shared/hypercall_params.h
index 0fdc439..b58c333 100644
--- a/shared/hypercall_params.h
+++ b/shared/hypercall_params.h
@@ -22,10 +22,6 @@
 #define REG_GFX_INIT_CMD  0x4E700100
 #define REG_GFX_INIT_DATA 0x4E700200
 
-#define REG_IDE_ST    0x1F7
-#define REG_IDE_CMD   0x1F7
-#define REG_IDE_DATA  0x1F0
-
 // --- SHARED STRUCT ---
 
 typedef struct {
diff --git a/shared/ide_regs.h b/shared/ide_regs.h
index bbf52a2..93c524c 100644
--- a/shared/ide_regs.h
+++ b/shared/ide_regs.h
@@ -1,9 +1,9 @@
 #ifndef _IDE_REGS_H_
 #define _IDE_REGS_H_
 
-#define IDE_STATUS_REG     0x1F7  // Status register on the primary bus (read-only)
-#define IDE_CMD_REG        0x1F7  // Command register on the primary bus (write-only)
-#define IDE_DATA_BASE_REG  0x1F0  // Base port on primary bus (write-only)
+#define REG_IDE_ST    0x1F7  // Status register on the primary bus (read-only)
+#define REG_IDE_CMD   0x1F7  // Command register on the primary bus (write-only)
+#define REG_IDE_DATA  0x1F0  // Base port on primary bus (write-only)
 
 #define SECTOR_SIZE         512
 #define MAX_SECTOR_NUM      ((1UL << 28) - 1)
-- 
GitLab