Browse Source

Very, very simple malloc

Stephen D 10 months 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

@ -50,10 +50,7 @@ void main() {
50 50
51 51
	register_commands();
52 52
53
	/*char buffer[0x4800];
54
	strcpy(buffer, "writing this to the floppy drive");
55
	floppy_write_track(4, buffer);
56
	println(buffer);*/
53
	disk_cmd_init();
57 54
58 55
	while(1)
59 56
	{

+ 18 - 2
libc/mem.c

@ -1,13 +1,29 @@
1 1
#include "mem.h"
2 2
3
void memory_copy(u8 *source, u8 *dest, int nbytes) {
3
void memory_copy(u8 *source, u8 *dest, int nbytes)
4
{
4 5
	int i;
5 6
	for (i = 0; i < nbytes; i++) {
6 7
		*(dest + i) = *(source + i);
7 8
	}
8 9
}
9 10
10
void memory_set(u8 *dest, u8 val, u32 len) {
11
void memory_set(u8 *dest, u8 val, u32 len)
12
{
11 13
	u8 *temp = (u8 *)dest;
12 14
	for ( ; len != 0; len--) *temp++ = val;
13 15
}
16
17
//TODO:
18
//free()
19
//alignment
20
const u32 start_addr = 0x100000;
21
u32 cur_addr = start_addr;
22
const u32 end_addr =  0x10000000;
23
24
u32 malloc(u32 len)
25
{
26
	u32 addr = cur_addr;
27
	cur_addr += len;
28
	return addr;
29
}

+ 1 - 0
libc/mem.h

@ -5,5 +5,6 @@
5 5
6 6
void memory_copy(u8 *source, u8 *dest, int nbytes);
7 7
void memory_set(u8 *dest, u8 val, u32 len);
8
u32 malloc(u32 len);
8 9
9 10
#endif

+ 7 - 1
util/commands.c

@ -5,6 +5,7 @@
5 5
#include "../libc/string.h"
6 6
#include "../programs/texteditor.h"
7 7
#include "../drivers/floppy.h"
8
#include "../libc/mem.h"
8 9
9 10
void help(char *args)
10 11
{
@ -101,7 +102,12 @@ void video_debug(char *args)
101 102
	}
102 103
	}*/
103 104
104
char buffer[0x4800];
105
char *buffer;
106
107
void disk_cmd_init()
108
{
109
	buffer = (char *)malloc(0x4800);
110
}
105 111
106 112
void read_callback(int p)
107 113
{

+ 1 - 0
util/commands.h

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