CeDOS - Commit f76f74b3

Restructured apps folder, enabling multiple different apps
Celina Sophie Kalus
Fri, 24 Mar 2023 23:24:22 +0100
18 files changed, 77 insertions(+), 42 deletions(-)
M makefilemakefile

@@ -69,7 +69,7 @@ > mkfs.fat -n "cedos" -S 512 -s 8 -r 32 $@

> mkdir -p ./mnt > sudo mount $@ ./mnt > sudo cp $(LOCAL_BUILD)/kernel.bin ./mnt -> sudo cp $(LOCAL_BUILD)/apps.o ./mnt +> sudo cp $(LOCAL_BUILD)/*.o ./mnt > sudo umount ./mnt $(GLOBAL_BUILD)/cedos.img: $(GLOBAL_BUILD)/fat.img | $(MODULES)

@@ -96,7 +96,7 @@ > $(MAKE) GLOBAL_BUILD=$(LOCAL_BUILD) -C src/kernel $(LOCAL_BUILD)/kernel.bin

.PHONY: apps apps: -> $(MAKE) GLOBAL_BUILD=$(LOCAL_BUILD) -C src/apps $(LOCAL_BUILD)/apps.o +> $(MAKE) GLOBAL_BUILD=$(LOCAL_BUILD) -C src/apps build .PHONY: clean clean:
M src/apps/cedos.csrc/apps/common/cedos.c

@@ -32,3 +32,8 @@ interrupt(0x30, res, 1, fd, buffer, size);

return res; } +int process_spawn(const char *fname, const char *args) { + int res = 0; + interrupt(0x30, res, 4, fname, args, 0); + return res; +}
M src/apps/cedos.hsrc/apps/common/cedos.h

@@ -8,6 +8,7 @@

int sysprint(const char *fmt, int arg1, int arg2); int yield(); int get_pid(); +int process_spawn(const char *fname, const char *args); int sc_file_read(int fd, char *buffer, uint32_t size); int sc_file_write(int fd, char *buffer, uint32_t size);
A src/apps/common/start.c

@@ -0,0 +1,11 @@

+#include "assembly.h" + +#include <stdint.h> + +extern void main(void); + +int _start(char *args) { + main(); + + while(1); +}
M src/apps/fibonacci.csrc/apps/fibonacci.c

@@ -2,7 +2,7 @@ #include "cedos.h"

#include <stdint.h> -void fib(void) { +void main(void) { uint32_t a = 0, b = 1, i = 0; while (1) { uint32_t tmp = a + b;
D src/apps/include/makefile

@@ -1,4 +0,0 @@

-.RECIPEPREFIX = > -.PHONY: build -build: ->
M src/apps/link.txtsrc/apps/link.txt

@@ -1,8 +1,6 @@

OUTPUT_ARCH(i386) OUTPUT_FORMAT(elf32-i386) -ENTRY(start) - MEMORY { HEADER : ORIGIN = 0x00000000, LENGTH = 0x10000000
M src/apps/makefilesrc/apps/makefile

@@ -4,29 +4,34 @@ LOCAL_BUILD = $(GLOBAL_BUILD)/apps

SRC_DIR := $(shell pwd) -C_SOURCES := $(wildcard *.c) $(wildcard **/*.c) -S_SOURCES := $(wildcard *.s) $(wildcard **/*.s) +C_SOURCES := $(wildcard common/*.c) +S_SOURCES := $(wildcard common/*.s) -C_OBJECTS := $(patsubst %.c,$(LOCAL_BUILD)/%.c.o,$(C_SOURCES)) -S_OBJECTS := $(patsubst %.s,$(LOCAL_BUILD)/%.s.o,$(S_SOURCES)) +C_OBJECTS := $(patsubst common/%.c,$(LOCAL_BUILD)/common/%.c.o,$(C_SOURCES)) +S_OBJECTS := $(patsubst common/%.s,$(LOCAL_BUILD)/common/%.s.o,$(S_SOURCES)) OBJECTS = $(S_OBJECTS) $(C_OBJECTS) -DIRS := $(sort $(dir $(OBJECTS))) +APP_SOURCES := $(wildcard *.c) +APP_OBJECTS := $(patsubst %.c,$(GLOBAL_BUILD)/%.o,$(APP_SOURCES)) + +DIRS := $(sort $(dir $(OBJECTS) $(APP_OBJECTS))) $(OBJECTS): | $(DIRS) $(DIRS): > $(MKDIR) $(DIRS) .PHONY: build -build: $(GLOBAL_BUILD)/apps.o -$(GLOBAL_BUILD)/apps.o: $(OBJECTS) +build: $(APP_OBJECTS) +$(GLOBAL_BUILD)/%.o: $(LOCAL_BUILD)/%.o $(OBJECTS) > $(LD) -T link.txt -Map=$(LOG_DIR)/apps_mapfile.txt -N $^ -o $@ # > $(OBJCOPY) -I binary -O elf32-i386 $(GLOBAL_BUILD)/apps.o $(GLOBAL_BUILD)/apps_raw.o # > $(LD) -T link.txt -r $^ -o $(GLOBAL_BUILD)/apps.o --oformat elf32-i386 - $(LOCAL_BUILD)/%.s.o: %.s > $(AS) -o $@ $< +$(LOCAL_BUILD)/%.o: %.c $(wildcard *.h) +> $(CC) -c -I$(INCLUDE_DIR) -I./common $(CCFLAGS) -o $@ $< + $(LOCAL_BUILD)/%.c.o: %.c $(wildcard *.h) -> $(CC) -c -I$(INCLUDE_DIR) $(CCFLAGS) -o $@ $< +> $(CC) -c -I$(INCLUDE_DIR) -I./common $(CCFLAGS) -o $@ $<
A src/apps/shell.c

@@ -0,0 +1,33 @@

+#include "cedos.h" + +#include <stdint.h> + +void read_line(char *buffer) { + int i = 0; + char c; + while (1) { + sc_file_read(1, &c, 1); + + if (c == '\n') { break; } + + buffer[i++] = c; + sc_file_write(0, &c, 1); + } + + buffer[i] = 0; + sc_file_write(0, &c, 1); +} + +void main(void) { + uint32_t a = 0, b = 1, i = 0; + while (1) { + uint32_t tmp = a + b; + a = b; + b = tmp; + printf("fib (%i) = %i\n", i, a); + i++; + char c = 0; + + printf("[%c]\n", (int)(uint32_t)c);//yield(); + } +}
D src/apps/start.c

@@ -1,20 +0,0 @@

-#include "assembly.h" - -#include <stdint.h> - -extern void fib(void); - -int start(char *args) { - //uint32_t eip, esp, ebp; - //__asm__ volatile ("call jump; jump: pop %0; mov %%esp, %1; mov %%ebp, %2" : "=m" (eip), "=m" (esp), "=m" (ebp)); - - int pid = get_pid(); - while (1) { - printf("Process #%i says: \"%s\".\n", pid, args); - yield(); - } - - fib(); - - while(1); -}
M src/kernel/main.csrc/kernel/main.c

@@ -169,13 +169,18 @@ }

printk("\n"); } + while (1) { + int c = std_kb->read(); + printk("a"); + } + // create test tasks printk("Creating tasks.\n"); - sched_spawn("apps.o", "Hello World!"); - sched_spawn("apps.o", "Hello World!"); - sched_spawn("apps.o", "Hello World!"); + sched_spawn("shell.o", "Hello World!"); + //sched_spawn("fibonacci.o", "Hello World!"); + //sched_spawn("fibonacci.o", "Hello World!"); printk("Starting scheduler.\n"); sched_start();
M src/kernel/syscall.csrc/kernel/syscall.c

@@ -15,7 +15,8 @@ void* SYSCALL_TABLE[] = {

file_read, file_write, sched_yield, - get_current_process + get_current_process, + sched_spawn }; extern void syscall_interrupt(void);