Add base code
This commit is contained in:
22
os/Makefile
Normal file
22
os/Makefile
Normal file
@@ -0,0 +1,22 @@
|
||||
CC = arm-none-eabi-gcc
|
||||
AS = arm-none-eabi-as
|
||||
LD = arm-none-eabi-ld
|
||||
CPU = -mcpu=cortex-m4
|
||||
THUMB = -mthumb
|
||||
|
||||
LDFLAGS = -T linker.ld
|
||||
CFLAGS = -c $(CPU) $(THUMB) -g
|
||||
|
||||
all: main.o process.o scheduler.o
|
||||
|
||||
main.o: main.c
|
||||
$(CC) $(CFLAGS) main.c -o main.o
|
||||
|
||||
scheduler.o: scheduler.c
|
||||
$(CC) $(CFLAGS) scheduler.c -o scheduler.o
|
||||
|
||||
process.o: process.c
|
||||
$(CC) $(CFLAGS) process.c -o process.o
|
||||
|
||||
clean:
|
||||
rm -f *.elf *.o *.i
|
||||
14
os/alloc.c
Normal file
14
os/alloc.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "alloc.h"
|
||||
#include "stdint.h"
|
||||
|
||||
void* *first_mem_avail = (void*) 0x20000000;
|
||||
|
||||
void init_allocator() {
|
||||
*first_mem_avail = (void*) 0x20000000 +sizeof(void*);
|
||||
}
|
||||
|
||||
void* malloc(size_t size) {
|
||||
void* block = *first_mem_avail;
|
||||
*first_mem_avail += size;
|
||||
return block;
|
||||
}
|
||||
4
os/alloc.h
Normal file
4
os/alloc.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#include <stddef.h>
|
||||
|
||||
void init_allocator();
|
||||
void* malloc (size_t size);
|
||||
17
os/main.c
Normal file
17
os/main.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "process.h"
|
||||
#include "scheduler.h"
|
||||
#include "alloc.h"
|
||||
|
||||
extern int task1(void);
|
||||
extern int task2(void);
|
||||
|
||||
int main(void) {
|
||||
init_allocator();
|
||||
ProcessTable *ptable;
|
||||
create_process_table(&ptable);
|
||||
|
||||
create_process(ptable, task1);
|
||||
create_process(ptable, task2);
|
||||
|
||||
run(ptable);
|
||||
}
|
||||
Reference in New Issue
Block a user