Skip to content

Commit 2c35bdd

Browse files
committed
Now k_memcpyToPhyMem accepts offsets into src & dest
1 parent c2d3713 commit 2c35bdd

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

include/kstdlib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void* k_memcpy (void* dest, const void* src, size_t n);
1818
void* k_memset (void* s, U8 c, size_t n);
1919

2020
/* Copies n bytes from src to physical dest memory.*/
21-
void k_memcpyToPhyMem (Physical dest, PTR src, SIZE n);
21+
void k_memcpyToPhyMem (Physical dest, PTR src, UINT destOffset, UINT srcOffset, SIZE n);
2222

2323
/* Fills memory with a multi byte pattern*/
2424
void* k_memset_pat4 (void* s, U32 p, SIZE szp, SIZE n);

src/kernel/kstdlib.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,28 +113,30 @@ void* k_memset (void* const s, U8 c, size_t n)
113113
* @Input n Number of bytes to copy.
114114
* @return Pointer to the start of the destination.
115115
***************************************************************************************************/
116-
void k_memcpyToPhyMem (Physical dest, PTR src, SIZE n)
116+
void k_memcpyToPhyMem (Physical dest, PTR src, UINT destOffset, UINT srcOffset, SIZE n)
117117
{
118118
FUNC_ENTRY ("Dest: %px, Src: %px, Len: %x bytes", dest.val, (PTR)src, n);
119119

120120
KERNEL_PHASE_VALIDATE (KERNEL_PHASE_STATE_VMM_READY);
121121

122122
Physical l_dest = dest;
123-
PTR l_src = src;
123+
PTR l_src = src + srcOffset;
124124
SIZE remBytes = n;
125125

126126
// Copy whole pages worth of bytes
127127
while (remBytes >= CONFIG_PAGE_FRAME_SIZE_BYTES) {
128-
k_memcpy (kpg_temporaryMap (l_dest), (void*)l_src, CONFIG_PAGE_FRAME_SIZE_BYTES);
128+
PTR dest_va = (PTR)kpg_temporaryMap (l_dest) + destOffset;
129+
destOffset = 0; // No offset from the 2nd iteration.
130+
k_memcpy ((void*)dest_va, (void*)l_src, CONFIG_PAGE_FRAME_SIZE_BYTES);
129131
kpg_temporaryUnmap();
130132
remBytes -= CONFIG_PAGE_FRAME_SIZE_BYTES;
131133
l_dest.val += CONFIG_PAGE_FRAME_SIZE_BYTES;
132134
l_src += CONFIG_PAGE_FRAME_SIZE_BYTES;
133135
}
134136

135137
// Copy remaining bytes
136-
void* bin_va = kpg_temporaryMap (l_dest);
137-
k_memcpy (bin_va, (void*)l_src, remBytes);
138+
PTR dest_va = (PTR)kpg_temporaryMap (l_dest) + destOffset;
139+
k_memcpy ((void*)dest_va, (void*)l_src, remBytes);
138140
kpg_temporaryUnmap();
139141
}
140142

src/kernel/x86/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static bool s_setupProcessBinaryMemory (void* processStartAddress, SIZE binLengt
262262
kvmm_setAddressSpaceMetadata (pinfo->context, pinfo->binary.virtualMemoryStart, "proc bin",
263263
&pinfo->processID);
264264

265-
k_memcpyToPhyMem (pa, (PTR)processStartAddress, binLengthBytes);
265+
k_memcpyToPhyMem (pa, (PTR)processStartAddress, 0, 0, binLengthBytes);
266266
return true;
267267
}
268268

0 commit comments

Comments
 (0)