summaryrefslogtreecommitdiff
path: root/stage3
diff options
context:
space:
mode:
Diffstat (limited to 'stage3')
-rw-r--r--stage3/ata.c6
-rw-r--r--stage3/cheese3d.c10
-rw-r--r--stage3/cheese_demo.c12
-rw-r--r--stage3/font.c10
-rw-r--r--stage3/font_classic.c2
-rw-r--r--stage3/fs.c6
-rw-r--r--stage3/gfx.c2
-rw-r--r--stage3/heap.c24
-rw-r--r--stage3/heap.h8
-rw-r--r--stage3/interrupts.c6
-rw-r--r--stage3/main.c4
-rw-r--r--stage3/memory.c4
-rw-r--r--stage3/memory.h4
-rw-r--r--stage3/pci.c2
-rw-r--r--stage3/shell.c22
-rw-r--r--stage3/string.c4
-rw-r--r--stage3/thread.c16
17 files changed, 71 insertions, 71 deletions
diff --git a/stage3/ata.c b/stage3/ata.c
index 3a862fe..94396be 100644
--- a/stage3/ata.c
+++ b/stage3/ata.c
@@ -107,7 +107,7 @@ void ata_init()
if (inb(IO_ATA0_DATA + ATA_IO_LBA_MID) != 0 || inb(IO_ATA0_DATA + ATA_IO_LBA_HIGH) != 0)
panic(S("ata0-witch is not ATA\n"));
- u16 *idvec = malloc(256 * sizeof *idvec);
+ u16 *idvec = kmalloc(256 * sizeof *idvec);
ata_recv(idvec);
if (!(idvec[83] & (1 << 10)))
@@ -116,7 +116,7 @@ void ata_init()
// u64 lba48_sectors = *(u64 *) &idvec[100];
// print_num(lba48_sectors, 10, 0); print("\n");
- free(idvec);
+ kfree(idvec);
print(S("ata0-witch initialized\n"));
}
@@ -147,7 +147,7 @@ void ata_read(u64 lba, u16 sectors, void *buffer)
void *ata_read_full(u64 lba, u64 sectors)
{
- void *buffer = malloc(512 * sectors);
+ void *buffer = kmalloc(512 * sectors);
for (u64 off = 0; off < sectors; off += 0x10000) {
u64 sects = sectors - off;
diff --git a/stage3/cheese3d.c b/stage3/cheese3d.c
index 154ce58..bd0b3e0 100644
--- a/stage3/cheese3d.c
+++ b/stage3/cheese3d.c
@@ -11,8 +11,8 @@ cheese3d_ctx cheese3d_create(u32 width, u32 height, u32 pitch, u32 bgcolor)
.height = height,
.pitch = pitch,
.bgcolor = bgcolor,
- .depth_buffer = malloc(gfx_info->width * gfx_info->height * sizeof(u32)),
- .color_buffer = malloc(gfx_info->pitch * gfx_info->height),
+ .depth_buffer = kmalloc(gfx_info->width * gfx_info->height * sizeof(u32)),
+ .color_buffer = kmalloc(gfx_info->pitch * gfx_info->height),
};
}
@@ -23,8 +23,8 @@ cheese3d_ctx cheese3d_create_default(u32 bgcolor)
void cheese3d_destroy(cheese3d_ctx ctx)
{
- free(ctx.depth_buffer);
- free(ctx.color_buffer);
+ kfree(ctx.depth_buffer);
+ kfree(ctx.color_buffer);
}
void cheese3d_clear(cheese3d_ctx ctx, bool color, bool depth)
@@ -144,5 +144,5 @@ void cheese3d_render(cheese3d_ctx ctx, usize num, vertex *vertices, texture *tex
void cheese3d_display(cheese3d_ctx ctx)
{
- memcpy((void *) (u64) gfx_info->framebuffer, ctx.color_buffer, gfx_info->pitch * gfx_info->height);
+ lmemcpy((void *) (u64) gfx_info->framebuffer, ctx.color_buffer, gfx_info->pitch * gfx_info->height);
}
diff --git a/stage3/cheese_demo.c b/stage3/cheese_demo.c
index 11d8541..efbd728 100644
--- a/stage3/cheese_demo.c
+++ b/stage3/cheese_demo.c
@@ -6,7 +6,7 @@
static u32 *make_cheese_texture(u32 tex_w, u32 tex_h, u32 density_min, u32 density_max)
{
- u32 *texture = malloc(tex_h * tex_w * sizeof *texture);
+ u32 *texture = kmalloc(tex_h * tex_w * sizeof *texture);
for (u32 y = 0; y < tex_h; y++)
for (u32 x = 0; x < tex_w; x++) {
texture[y*tex_w+x] = 0xFFFFDE74;
@@ -49,8 +49,8 @@ static cheese make_cheese_model(u32 segments, float slice, u32 tex_w, u32 tex_h)
static u32 crust_back = 0xFFF2B71B;
usize num_verts = 12*segments+12;
- vertex *vertices = malloc(sizeof *vertices * num_verts);
- texture *textures = malloc(sizeof *textures * num_verts);
+ vertex *vertices = kmalloc(sizeof *vertices * num_verts);
+ texture *textures = kmalloc(sizeof *textures * num_verts);
float angle = 0.0;
float seg_delta = slice/segments;
@@ -175,7 +175,7 @@ void cheese_demo()
cheese3d_destroy(ctx);
- free(ch.textures);
- free(ch.vertices);
- free(ch.texture);
+ kfree(ch.textures);
+ kfree(ch.vertices);
+ kfree(ch.texture);
}
diff --git a/stage3/font.c b/stage3/font.c
index f2e6bea..f0b8d93 100644
--- a/stage3/font.c
+++ b/stage3/font.c
@@ -24,7 +24,7 @@ static u16 screen_width, screen_height;
void font_init()
{
- font = malloc(256 * 16);
+ font = kmalloc(256 * 16);
}
void font_set_size(u16 size)
@@ -56,12 +56,12 @@ term_pos font_get_size()
void font_load_blob(const void *blob)
{
- memcpy(font, blob, 256*16);
+ lmemcpy(font, blob, 256*16);
}
void font_load_builtin()
{
- memcpy(font, fs_fonts_ter_u16n_cuddlefont, 256*16);
+ lmemcpy(font, fs_fonts_ter_u16n_cuddlefont, 256*16);
}
void font_load_classic()
@@ -89,7 +89,7 @@ void font_load_classic()
}
}
- free(cfont);
+ kfree(cfont);
}
void font_clear_screen()
@@ -127,7 +127,7 @@ static void update_cursor()
while (cursor_y >= screen_height) {
cursor_y--;
- memcpy((void *) (u64) gfx_info->framebuffer,
+ lmemcpy((void *) (u64) gfx_info->framebuffer,
(void *) (u64) gfx_info->framebuffer + gfx_info->pitch * outer_height,
gfx_info->pitch * (gfx_info->height - outer_height));
diff --git a/stage3/font_classic.c b/stage3/font_classic.c
index 4346f16..c0fae25 100644
--- a/stage3/font_classic.c
+++ b/stage3/font_classic.c
@@ -4,7 +4,7 @@
classic_char *font_classic()
{
- classic_char *font = malloc(256 * sizeof *font);
+ classic_char *font = kmalloc(256 * sizeof *font);
memset(font, 0, 256 * sizeof *font);
font[' '] = (classic_char) {{
diff --git a/stage3/fs.c b/stage3/fs.c
index b1080b6..d96d014 100644
--- a/stage3/fs.c
+++ b/stage3/fs.c
@@ -14,7 +14,7 @@ void fs_walk(FS_WALKER(*fun), void *arg)
u8 *info = ata_read_full(lba, 1);
if (memcmp(info+257, "ustar", 5) != 0) {
- free(info);
+ kfree(info);
break;
}
@@ -26,7 +26,7 @@ void fs_walk(FS_WALKER(*fun), void *arg)
bool done = fun(filename, lba, fsize, fsect, arg);
- free(info);
+ kfree(info);
if (done)
break;
@@ -126,7 +126,7 @@ static FS_WALKER(fs_readdir_walker)
case HER_CHILD:
if (arg->result.len == arg->cap)
- arg->result.data = realloc(arg->result.data,
+ arg->result.data = krealloc(arg->result.data,
sizeof(dirent) * (arg->cap = arg->cap ? arg->cap*2 : 1));
arg->result.data[arg->result.len++] = (dirent) {
.name = str_clone(entn),
diff --git a/stage3/gfx.c b/stage3/gfx.c
index 70a68d9..7fe8df7 100644
--- a/stage3/gfx.c
+++ b/stage3/gfx.c
@@ -40,7 +40,7 @@ void gfx_draw_img(u16 x, u16 y, u16 w, u16 h, u32 *img)
{
void *cbeg = (void *) (u64) (gfx_info->framebuffer + y * gfx_info->pitch + x * sizeof(color));
for (u16 yi = 0; yi < h; cbeg += gfx_info->pitch, yi++)
- memcpy(cbeg, img + yi * w, w * sizeof(color));
+ lmemcpy(cbeg, img + yi * w, w * sizeof(color));
BARRIER_VAR(cbeg);
}
diff --git a/stage3/heap.c b/stage3/heap.c
index 71bbf7d..6addd6d 100644
--- a/stage3/heap.c
+++ b/stage3/heap.c
@@ -13,19 +13,19 @@ typedef struct __attribute__((packed)) Header {
static Header init_free_ptr;
static Header *free_ptr = nil;
-void free(void *ptr)
+void kfree(void *ptr)
{
Header *h = ((Header *) ptr) - 1;
if (h->next != MAGIC)
- panic(S("free: invalid pointer"));
+ panic(S("kfree: invalid pointer"));
Header *next = free_ptr->next;
free_ptr->next = h;
h->next = next;
}
-void *try_malloc(usize size)
+void *try_kmalloc(usize size)
{
for (Header *prev = free_ptr;; prev = prev->next) {
Header *h = prev->next;
@@ -54,31 +54,31 @@ void *try_malloc(usize size)
return nil;
}
-void *malloc(usize size)
+void *kmalloc(usize size)
{
void *p;
- p = try_malloc(size);
+ p = try_kmalloc(size);
if (p) return p;
panic(S("out of memory"));
return nil;
}
-void *realloc(void *ptr, usize size)
+void *krealloc(void *ptr, usize size)
{
if (ptr == nil)
- return malloc(size);
+ return kmalloc(size);
Header *h = ((Header *) ptr) - 1;
if (h->next != MAGIC)
- panic(S("realloc: invalid pointer"));
+ panic(S("krealloc: invalid pointer"));
- void *new = malloc(size);
+ void *new = kmalloc(size);
- memcpy(new, ptr, h->size);
- free(ptr);
+ lmemcpy(new, ptr, h->size);
+ kfree(ptr);
return new;
}
@@ -100,7 +100,7 @@ void heap_add(void *ptr, usize size)
h->next = MAGIC;
h->size = size - sizeof(Header);
- free(h + 1);
+ kfree(h + 1);
}
void heap_add_region(MemRegion *region)
diff --git a/stage3/heap.h b/stage3/heap.h
index 39bd70d..50a3fcf 100644
--- a/stage3/heap.h
+++ b/stage3/heap.h
@@ -9,9 +9,9 @@ void heap_init();
void heap_add(void *ptr, usize size);
void heap_add_region(MemRegion *region);
-void *try_malloc(usize size);
-void *malloc(usize siz);
-void free(void *ptr);
-void *realloc(void *ptr, usize size);
+void *try_kmalloc(usize size);
+void *kmalloc(usize siz);
+void kfree(void *ptr);
+void *krealloc(void *ptr, usize size);
#endif
diff --git a/stage3/interrupts.c b/stage3/interrupts.c
index 2bb64f1..9c7bcc8 100644
--- a/stage3/interrupts.c
+++ b/stage3/interrupts.c
@@ -27,9 +27,9 @@ void interrupt_handler(interrupt_frame *frame)
if (queue_write.len == queue_write.cap) {
panic(S("queue exceeded\n"));
/*
- // TODO: malloc would cause a race condition
+ // TODO: kmalloc would cause a race condition
queue_write.cap = queue_write.cap == 0 ? 1 : queue_write.cap * 2;
- queue_write.data = realloc(queue_write.data, queue_write.cap);
+ queue_write.data = krealloc(queue_write.data, queue_write.cap);
*/
}
@@ -64,7 +64,7 @@ void interrupts_init()
u32 zero;
} __attribute__((packed)) interrupt_descriptor;
- interrupt_descriptor *idt = malloc(256 * sizeof *idt);
+ interrupt_descriptor *idt = kmalloc(256 * sizeof *idt);
for (int i = 0; i < 255; i++) {
union {
diff --git a/stage3/main.c b/stage3/main.c
index b796fd1..9d2c43f 100644
--- a/stage3/main.c
+++ b/stage3/main.c
@@ -30,7 +30,7 @@ void keyboard_handler()
for (;;) {
event *e = yield(nil);
u8 code = e->data.scancode;
- free(e);
+ kfree(e);
bool stop = (code & (1 << 7)) != 0;
code &= ~(1 << 7);
@@ -52,7 +52,7 @@ void keyboard_handler()
} else if (c != '\0') {
print_char(c);
if (buffer.len == cap)
- buffer.data = realloc(buffer.data, cap = cap ? cap*2 : 1);
+ buffer.data = krealloc(buffer.data, cap = cap ? cap*2 : 1);
buffer.data[buffer.len++] = c;
}
}
diff --git a/stage3/memory.c b/stage3/memory.c
index 23dfb5c..1726755 100644
--- a/stage3/memory.c
+++ b/stage3/memory.c
@@ -1,14 +1,14 @@
#include "heap.h"
#include "memory.h"
-void *memcpy(void *dst, const void *src, usize bytes)
+void *lmemcpy(void *dst, const void *src, usize bytes)
{
for (usize i = 0; i < bytes; i++)
((unsigned char *) dst)[i] = ((const unsigned char *) src)[i];
return dst;
}
-void *memcpy_r(void *dst, const void *src, usize bytes)
+void *rmemcpy(void *dst, const void *src, usize bytes)
{
for (usize i = bytes; i > 0; i--)
((unsigned char *) dst)[i-1] = ((const unsigned char *) src)[i-1];
diff --git a/stage3/memory.h b/stage3/memory.h
index ceb412c..c3f4004 100644
--- a/stage3/memory.h
+++ b/stage3/memory.h
@@ -3,8 +3,8 @@
#include "def.h"
-void *memcpy(void *dst, const void *src, usize bytes);
-void *memcpy_r(void *dst, const void *src, usize bytes);
+void *lmemcpy(void *dst, const void *src, usize bytes);
+void *rmemcpy(void *dst, const void *src, usize bytes);
int memcmp(const void *s1, const void *s2, usize n);
u8 memsum(const void *ptr, usize size);
void *memset(void *s, int c, usize n);
diff --git a/stage3/pci.c b/stage3/pci.c
index 5cf5165..6839a9b 100644
--- a/stage3/pci.c
+++ b/stage3/pci.c
@@ -40,7 +40,7 @@ void pci_init()
outl(PCI_CONFIG_ADDRESS, BITCAST(addr, pci_config_addr, u32));
u32 reg_2 = inl(PCI_CONFIG_DATA);
- pci_devices = realloc(pci_devices, ++pci_num_devices * sizeof *pci_devices);
+ pci_devices = krealloc(pci_devices, ++pci_num_devices * sizeof *pci_devices);
pci_devices[pci_num_devices-1] = (pci_dev) {
.bus = addr.bus,
.dev = addr.dev,
diff --git a/stage3/shell.c b/stage3/shell.c
index c2fd377..0d24859 100644
--- a/stage3/shell.c
+++ b/stage3/shell.c
@@ -29,7 +29,7 @@ static void cmd_cat(str arg)
print(S("\n"));
} else {
print(f);
- free(f.data);
+ kfree(f.data);
}
}
@@ -47,7 +47,7 @@ static void cmd_font(str arg)
else
print(S("font: invalid file size\n"));
- free(f.data);
+ kfree(f.data);
}
}
@@ -86,7 +86,7 @@ static void cmd_img(str arg)
(void *) (f.data + 2 * sizeof(u32)));
}
- free(f.data);
+ kfree(f.data);
}
}
@@ -122,7 +122,7 @@ static void cmd_run(str arg)
shell_run_cmd(cmd);
}
- free(f.data);
+ kfree(f.data);
}
}
@@ -138,11 +138,11 @@ static void cmd_loadkeys(str arg)
print(S("\n"));
} else {
if (f.len == 256)
- memcpy(keymap, f.data, 256);
+ lmemcpy(keymap, f.data, 256);
else
print(S("loadkeys: invalid file size\n"));
- free(f.data);
+ kfree(f.data);
}
}
@@ -165,11 +165,11 @@ static void cmd_love(str arg)
if (start < 0 || start + arg.len > f.len) {
print(S("love: argument too long (owo it's too big for me)\n"));
} else {
- memcpy(f.data+start, arg.data, arg.len);
+ lmemcpy(f.data+start, arg.data, arg.len);
print(f);
}
- free(f.data);
+ kfree(f.data);
}
}
@@ -220,11 +220,11 @@ static void cmd_ls(str arg)
print(S(" files"));
}
print_char('\n');
- free(d.data[i].name.data);
+ kfree(d.data[i].name.data);
}
if (d.data != nil)
- free(d.data);
+ kfree(d.data);
}
void cmd_shutdown(str arg)
@@ -313,7 +313,7 @@ static void cmd_choose(str arg)
print_char('\n');
}
- free(f.data);
+ kfree(f.data);
}
}
diff --git a/stage3/string.c b/stage3/string.c
index 5669483..ce776ad 100644
--- a/stage3/string.c
+++ b/stage3/string.c
@@ -102,7 +102,7 @@ str str_intro(char *c)
str str_clone(str s)
{
- str c = { s.len, malloc(s.len) };
- memcpy(c.data, s.data, s.len);
+ str c = { s.len, kmalloc(s.len) };
+ lmemcpy(c.data, s.data, s.len);
return c;
}
diff --git a/stage3/thread.c b/stage3/thread.c
index 4609102..a7e0c29 100644
--- a/stage3/thread.c
+++ b/stage3/thread.c
@@ -24,7 +24,7 @@ void thread_resume(void *ret, thread *t)
// aligned on 16-byte boundary
static void *alloc_stack(void **alloc)
{
- usize stack = (usize) malloc(STACK_SIZE+16);
+ usize stack = (usize) kmalloc(STACK_SIZE+16);
if (alloc != nil)
*alloc = (void *) stack;
stack += 16 - stack % 16;
@@ -33,7 +33,7 @@ static void *alloc_stack(void **alloc)
thread *thread_create(str name, void *init)
{
- thread *t = malloc(sizeof *t);
+ thread *t = kmalloc(sizeof *t);
t->name = name;
t->stack = alloc_stack(&t->stack_bottom) + STACK_SIZE - 16;
*(void **) t->stack = init;
@@ -49,8 +49,8 @@ void thread_sched(yield_arg *arg, void *stack)
if (arg == nil) {
// TODO: add to some sort of runqueue? (nil means not polling for anything)
} else if (arg->exit) {
- free(current_thread->stack_bottom);
- free(current_thread);
+ kfree(current_thread->stack_bottom);
+ kfree(current_thread);
current_thread = nil;
} else if (arg->timeout >= 0) {
// TODO: meow
@@ -70,11 +70,11 @@ void thread_sched(yield_arg *arg, void *stack)
}
if (queue_read.len > 0) {
- event *e = malloc(sizeof *e);
+ event *e = kmalloc(sizeof *e);
*e = queue_read.data[--queue_read.len];
if (irq_services[e->irq] == nil)
- free(e); // *shrug*
+ kfree(e); // *shrug*
else
// this never returns. callee must free e
thread_resume(e, irq_services[e->irq]);
@@ -88,6 +88,6 @@ void thread_init()
{
thread_sched_stack = alloc_stack(nil)+STACK_SIZE-8;
- queue_read = (event_queue) { 0, 1024, malloc(1024 * sizeof(event)) };
- queue_write = (event_queue) { 0, 1024, malloc(1024 * sizeof(event)) };
+ queue_read = (event_queue) { 0, 1024, kmalloc(1024 * sizeof(event)) };
+ queue_write = (event_queue) { 0, 1024, kmalloc(1024 * sizeof(event)) };
}