Lesson 23, step 4, size_t usage

This commit is contained in:
Carlos 2015-08-18 10:38:09 +02:00
parent de3d442569
commit 6f09492f2b
3 changed files with 7 additions and 7 deletions

View File

@ -39,9 +39,11 @@ C99 introduces standard fixed-width data types like `uint32_t`
We need to include `<stdint.h>` which works even in `-ffreestanding` (but requires stdlibs) We need to include `<stdint.h>` which works even in `-ffreestanding` (but requires stdlibs)
and use those data types instead of our own, then delete them on `type.h` and use those data types instead of our own, then delete them on `type.h`
<stddef.h> to provide size\_t 4. Improperly aligned `kmalloc`
-------------------------------
First, since `kmalloc` uses a size parameter, we'll use the correct data type `size_t` instead
of `u32int_t`. `<stddef.h>` is required for `size_t`
5. Missing functions 5. Missing functions
-------------------- --------------------
@ -54,7 +56,4 @@ and use those data types instead of our own, then delete them on `type.h`
7. Structs and attributes 7. Structs and attributes
------------------------- -------------------------
8. Improperly aligned `kmalloc`
-------------------------------

View File

@ -18,7 +18,7 @@ void memory_set(uint8_t *dest, uint8_t val, uint32_t len) {
uint32_t free_mem_addr = 0x10000; uint32_t free_mem_addr = 0x10000;
/* Implementation is just a pointer to some free memory which /* Implementation is just a pointer to some free memory which
* keeps growing */ * keeps growing */
uint32_t kmalloc(uint32_t size, int align, uint32_t *phys_addr) { uint32_t kmalloc(size_t size, int align, uint32_t *phys_addr) {
/* Pages are aligned to 4K, or 0x1000 */ /* Pages are aligned to 4K, or 0x1000 */
if (align == 1 && (free_mem_addr & 0xFFFFF000)) { if (align == 1 && (free_mem_addr & 0xFFFFF000)) {
free_mem_addr &= 0xFFFFF000; free_mem_addr &= 0xFFFFF000;

View File

@ -2,11 +2,12 @@
#define MEM_H #define MEM_H
#include <stdint.h> #include <stdint.h>
#include <stddef.h>
void memory_copy(uint8_t *source, uint8_t *dest, int nbytes); void memory_copy(uint8_t *source, uint8_t *dest, int nbytes);
void memory_set(uint8_t *dest, uint8_t val, uint32_t len); void memory_set(uint8_t *dest, uint8_t val, uint32_t len);
/* At this stage there is no 'free' implemented. */ /* At this stage there is no 'free' implemented. */
uint32_t kmalloc(uint32_t size, int align, uint32_t *phys_addr); uint32_t kmalloc(size_t size, int align, uint32_t *phys_addr);
#endif #endif