Browse Source

Very, very simple malloc

master
Stephen D 1 year ago
parent
commit
5246f7c577
5 changed files with 28 additions and 7 deletions
  1. +1
    -4
      kernel/kernel.c
  2. +18
    -2
      libc/mem.c
  3. +1
    -0
      libc/mem.h
  4. +7
    -1
      util/commands.c
  5. +1
    -0
      util/commands.h

+ 1
- 4
kernel/kernel.c View File

@@ -50,10 +50,7 @@ void main() {

register_commands();

/*char buffer[0x4800];
strcpy(buffer, "writing this to the floppy drive");
floppy_write_track(4, buffer);
println(buffer);*/
disk_cmd_init();

while(1)
{


+ 18
- 2
libc/mem.c View File

@@ -1,13 +1,29 @@
#include "mem.h"

void memory_copy(u8 *source, u8 *dest, int nbytes) {
void memory_copy(u8 *source, u8 *dest, int nbytes)
{
int i;
for (i = 0; i < nbytes; i++) {
*(dest + i) = *(source + i);
}
}

void memory_set(u8 *dest, u8 val, u32 len) {
void memory_set(u8 *dest, u8 val, u32 len)
{
u8 *temp = (u8 *)dest;
for ( ; len != 0; len--) *temp++ = val;
}

//TODO:
//free()
//alignment
const u32 start_addr = 0x100000;
u32 cur_addr = start_addr;
const u32 end_addr = 0x10000000;

u32 malloc(u32 len)
{
u32 addr = cur_addr;
cur_addr += len;
return addr;
}

+ 1
- 0
libc/mem.h View File

@@ -5,5 +5,6 @@

void memory_copy(u8 *source, u8 *dest, int nbytes);
void memory_set(u8 *dest, u8 val, u32 len);
u32 malloc(u32 len);

#endif

+ 7
- 1
util/commands.c View File

@@ -5,6 +5,7 @@
#include "../libc/string.h"
#include "../programs/texteditor.h"
#include "../drivers/floppy.h"
#include "../libc/mem.h"

void help(char *args)
{
@@ -101,7 +102,12 @@ void video_debug(char *args)
}
}*/

char buffer[0x4800];
char *buffer;

void disk_cmd_init()
{
buffer = (char *)malloc(0x4800);
}

void read_callback(int p)
{


+ 1
- 0
util/commands.h View File

@@ -1,4 +1,5 @@
#ifndef commands
#define commands
void register_commands();
void disk_cmd_init();
#endif

Loading…
Cancel
Save