lesson 23, step 3

This commit is contained in:
Carlos
2015-08-18 10:31:28 +02:00
parent 92ff191c3d
commit de3d442569
18 changed files with 124 additions and 127 deletions

View File

@@ -1,24 +1,24 @@
#include "mem.h"
void memory_copy(u8 *source, u8 *dest, int nbytes) {
void memory_copy(uint8_t *source, uint8_t *dest, int nbytes) {
int i;
for (i = 0; i < nbytes; i++) {
*(dest + i) = *(source + i);
}
}
void memory_set(u8 *dest, u8 val, u32 len) {
u8 *temp = (u8 *)dest;
void memory_set(uint8_t *dest, uint8_t val, uint32_t len) {
uint8_t *temp = (uint8_t *)dest;
for ( ; len != 0; len--) *temp++ = val;
}
/* This should be computed at link time, but a hardcoded
* value is fine for now. Remember that our kernel starts
* at 0x1000 as defined on the Makefile */
u32 free_mem_addr = 0x10000;
uint32_t free_mem_addr = 0x10000;
/* Implementation is just a pointer to some free memory which
* keeps growing */
u32 kmalloc(u32 size, int align, u32 *phys_addr) {
uint32_t kmalloc(uint32_t size, int align, uint32_t *phys_addr) {
/* Pages are aligned to 4K, or 0x1000 */
if (align == 1 && (free_mem_addr & 0xFFFFF000)) {
free_mem_addr &= 0xFFFFF000;
@@ -27,7 +27,7 @@ u32 kmalloc(u32 size, int align, u32 *phys_addr) {
/* Save also the physical address */
if (phys_addr) *phys_addr = free_mem_addr;
u32 ret = free_mem_addr;
uint32_t ret = free_mem_addr;
free_mem_addr += size; /* Remember to increment the pointer */
return ret;
}