minix/minix/kernel/system/do_devio.c
google-labs-jules[bot] 61edfddd25 Refactor: KASSERT_PLACEHOLDER to KASSERT Migration (Partial)
This commit represents the progress I've made on migrating your codebase from
the temporary KASSERT_PLACEHOLDER macro to the new KASSERT macro
defined in <sys/kassert.h>.

**Work Completed:**

*   **`minix/kernel/` (root directory files):**
    *   I processed all 30 `.c` and `.h` files in this directory.
    *   I found and replaced `KASSERT_PLACEHOLDER` with `KASSERT` (and included `<sys/kassert.h>`) in 6 files: `debug.c`, `interrupt.c`, `main.c`, `proc.c`, `smp.c`, and `system.c`.

*   **`minix/kernel/system/` (system call handlers):**
    *   I processed all 38 `.c` files in this directory.
    *   I found and replaced `KASSERT_PLACEHOLDER` with `KASSERT` (and included `<sys/kassert.h>`) in 6 files: `do_copy.c`, `do_fork.c`, `do_mcontext.c`, `do_runctl.c`, `do_safecopy.c`, and `do_vumap.c`.

**Total Progress:**
*   Files processed: 68
*   Files with KASSERT migrations: 12

**Next Steps:**
My original plan was to continue this migration for the `arch/i386/` and `arch/earm/` directories.

**Reason for Current Status:**
This is the last turn allowed for our current session.

**Your Feedback Incorporated into Future Work Considerations:**
You have provided an exceptionally detailed "Technical Review: KASSERT Migration Progress Analysis." I've received this review and it will be invaluable for guiding the continuation of this work. Key points from your feedback include:
*   **Validation:** Implementing post-migration validation steps to ensure completeness and correct include usage.
*   **Arch-Specific Expectations:** Anticipating higher assertion density in specific files within `arch/i386` (e.g., `memory.c`, `protect.c`) and `arch/earm`.
*   **Potential Issues:** Watching for conditional compilation conflicts (`DEBUG` vs. `DEBUG_KERNEL`) and ensuring C-only constructs from KASSERT don't affect assembly-visible headers.
*   **Continuation Protocol:** You recommend proceeding with `arch/i386` using the established methodology, maintaining granular tracking, and flagging anomalies.
*   **Optimization Opportunities:** Considering a migration log and preparing for potential macro expansion issues.

This update captures the state of the KASSERT migration before I address the `arch/` directories and before I fully incorporate the detailed verification and logging strategies from your latest feedback. I will resume based on this feedback in our next session.
2025-06-07 03:49:54 +00:00

115 lines
3.1 KiB
C

/* The kernel call implemented in this file:
* m_type: SYS_DEVIO
*
* The parameters for this kernel call are:
* m_lsys_krn_sys_devio.request (request input or output)
* m_lsys_krn_sys_devio.port (port to read/ write)
* m_lsys_krn_sys_devio.value (value to write/ return value read)
*/
#include "kernel/system.h"
#include <minix/devio.h> // Kept
#include <minix/endpoint.h> // Kept
// Added kernel headers
#include <minix/kernel_types.h> // For k_errno_t or similar if error codes are mapped
#include <klib/include/kprintf.h>
#include <klib/include/kstring.h>
#include <klib/include/kmemory.h>
#if USE_DEVIO
/*===========================================================================*
* do_devio *
*===========================================================================*/
int do_devio(struct proc * caller, message * m_ptr)
{
struct priv *privp;
port_t port;
struct io_range *iorp;
int i, size, nr_io_range;
int io_type, io_dir;
io_type = m_ptr->m_lsys_krn_sys_devio.request & _DIO_TYPEMASK;
io_dir = m_ptr->m_lsys_krn_sys_devio.request & _DIO_DIRMASK;
switch (io_type)
{
case _DIO_BYTE: size= 1; break;
case _DIO_WORD: size= 2; break;
case _DIO_LONG: size= 4; break;
default: size= 4; break; /* Be conservative */
}
privp= priv(caller);
if (!privp)
{
kprintf_stub("no priv structure!\n"); // MODIFIED
goto doit;
}
if (privp->s_flags & CHECK_IO_PORT)
{
port= m_ptr->m_lsys_krn_sys_devio.port;
nr_io_range= privp->s_nr_io_range;
for (i= 0, iorp= privp->s_io_tab; i<nr_io_range; i++, iorp++)
{
if (port >= iorp->ior_base && port+size-1 <= iorp->ior_limit)
break;
}
if (i >= nr_io_range)
{
kprintf_stub("do_devio: port 0x%x (size %d) not allowed\n", // MODIFIED
m_ptr->m_lsys_krn_sys_devio.port, size);
return EPERM; // EPERM might be undefined
}
}
doit:
if (m_ptr->m_lsys_krn_sys_devio.port & (size-1))
{
kprintf_stub("do_devio: unaligned port 0x%x (size %d)\n", // MODIFIED
m_ptr->m_lsys_krn_sys_devio.port, size);
return EPERM; // EPERM might be undefined
}
/* Process a single I/O request for byte, word, and long values. */
if (io_dir == _DIO_INPUT) {
switch (io_type) {
/* maybe "it" should not be called ports */
case _DIO_BYTE:
m_ptr->m_krn_lsys_sys_devio.value =
inb(m_ptr->m_lsys_krn_sys_devio.port);
break;
case _DIO_WORD:
m_ptr->m_krn_lsys_sys_devio.value =
inw(m_ptr->m_lsys_krn_sys_devio.port);
break;
case _DIO_LONG:
m_ptr->m_krn_lsys_sys_devio.value =
inl(m_ptr->m_lsys_krn_sys_devio.port);
break;
default: return(EINVAL); // EINVAL might be undefined
}
} else {
switch (io_type) {
case _DIO_BYTE:
outb(m_ptr->m_lsys_krn_sys_devio.port,
m_ptr->m_lsys_krn_sys_devio.value);
break;
case _DIO_WORD:
outw(m_ptr->m_lsys_krn_sys_devio.port,
m_ptr->m_lsys_krn_sys_devio.value);
break;
case _DIO_LONG:
outl(m_ptr->m_lsys_krn_sys_devio.port,
m_ptr->m_lsys_krn_sys_devio.value);
break;
default: return(EINVAL); // EINVAL might be undefined
}
}
return(OK);
}
#endif /* USE_DEVIO */