【发布时间】:2012-11-23 20:24:39
【问题描述】:
我想在不使用任何库函数的情况下将信息逐字节从一个内存位置移动到另一个位置。我使用在 qemu 中模拟的 16 位架构,这段代码是我正在编写的微小内核的一部分,所以我不能使用任何系统调用
// The struct i want to copy
struct procinfo info_tmp;
// here i put some stuff in my struct
info_tmp.pid = tablaprocesos[indiceProceso].pid;
kstrcpy(info_tmp.nombre, tablaprocesos[indiceProceso].nombre);
info_tmp.segmento = tablaprocesos[indiceProceso].memoria;
if(tablaprocesos[indiceProceso].estado==PROCESO_LISTO)
info_tmp.estado = 0;
else if(tablaprocesos[indiceProceso].estado==PROCESO_RUN)
info_tmp.estado = 1;
else if(tablaprocesos[indiceProceso].estado==BLOQ_TECLADO ||
tablaprocesos[indiceProceso].estado==PROCESO_SYSCALL)
info_tmp.estado = 2;
else
info_tmp.estado = 3; // Zombie
// Tiempo total = tiempoSYS + tiempoUSER
info_tmp.tiempo = tablaprocesos[indiceProceso].tiempoUSER +
tablaprocesos[indiceProceso].tiempoSYS;
// pointer to destination that i want to copy to
infoProc = (struct procinfo *)(((int)es << 16) + (0x0000ffff & ebx));
// now pointer to my source struct
procinfo * origen = &info_tmp;
int limit = sizeof(struct procinfo);
int i;
for(i=0;i<limit;i++){
// I need here to read only one byte from my source pointer to a variable "byte"
// macro written in ASM to copy one byte to a pointed location
// it writes in another data segment of another process
WRITE_POINTER_FAR(infoProc,byte);
// next byte
origen += 1;
infoProc += 1;
}
有没有直接的方法可以不用在 ASM 中编写小代码来手动完成?
注意:此代码是 16 位分段 OS 内核的一部分(每个进程一个 64KB 段),源结构在内核段中,我想将其复制到另一个进程段中的位置,它不能比如 *targetBytePointer = *sourceBytePointer。
【问题讨论】:
-
为什么 *targetBytePointer = *sourceBytePointer;工作?我一定在你的要求中遗漏了一些东西......
-
1) 风格:
else if ... else if ...:考虑一个 swith 构造,这将消除很多视觉混乱。 2)origen + 0x1;声明没有意义 3) 为什么十六进制常量为 1 ? -
它是一个 16 位分段 OS 内核(每个进程一个段),你看到的是在内核段中,我想将它复制到另一个进程段中的一个位置,它不能完成按照你的建议
-
wildplasser,由 origen + 0x1;我假装对指向我的源结构的指针求和一,这意味着指向我的源中的下一个字节(十六进制常量一无所获,只有一个)
-
Travis Griggs,此代码是 16 位分段 OS 内核(每个进程一个 64KB 段)的一部分,源结构位于内核段中,我想将其复制到另一个进程中的某个位置段,它不能像 *targetBytePointer = *sourceBytePointer.