diff options
author | Marvin Borner | 2020-08-01 18:37:15 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-01 18:37:15 +0200 |
commit | 1686173757af4e453e7a32d152ec4bd20d789652 (patch) | |
tree | 539d90855fa59c85c043976fcd9cd3075ebc8d8d /apps | |
parent | 928bf3f29d7a8b2163a3c1d5c15554d5b42c606b (diff) |
Started multitasking
Diffstat (limited to 'apps')
-rw-r--r-- | apps/Makefile | 6 | ||||
-rw-r--r-- | apps/a.c (renamed from apps/test.c) | 2 | ||||
-rw-r--r-- | apps/b.c | 46 | ||||
-rw-r--r-- | apps/root.c | 48 |
4 files changed, 98 insertions, 4 deletions
diff --git a/apps/Makefile b/apps/Makefile index 574f135..56e5472 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -1,6 +1,6 @@ # MIT License, Copyright (c) 2020 Marvin Borner -COBJS = test.o +COBJS = a.o b.o root.o CC = ../cross/opt/bin/i686-elf-gcc LD = ../cross/opt/bin/i686-elf-ld OC = ../cross/opt/bin/i686-elf-objcopy @@ -10,7 +10,7 @@ CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -ffunction- all: $(COBJS) %.o: %.c - @mkdir -p ../build/ + @mkdir -p ../build/apps/ @$(CC) -c $(CFLAGS) $< -o $@ @$(LD) -o $(@:.o=.elf) -Tlink.ld $@ - @$(OC) -O binary $(@:.o=.elf) ../build/$(@:.o=) + @$(OC) -O binary $(@:.o=.elf) ../build/apps/$(@:.o=) @@ -42,5 +42,5 @@ void serial_print(const char *data) void main() { - serial_print("Follow the white rabbit."); + serial_print("a"); } diff --git a/apps/b.c b/apps/b.c new file mode 100644 index 0000000..3de20bf --- /dev/null +++ b/apps/b.c @@ -0,0 +1,46 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#include <def.h> + +u32 strlen(const char *s) +{ + const char *ss = s; + while (*ss) + ss++; + return ss - s; +} + +u8 inb(u16 port) +{ + u8 value; + __asm__ volatile("inb %1, %0" : "=a"(value) : "Nd"(port)); + return value; +} + +void outb(u16 port, u8 data) +{ + __asm__ volatile("outb %0, %1" ::"a"(data), "Nd"(port)); +} + +int is_transmit_empty() +{ + return inb(0x3f8 + 5) & 0x20; +} + +void serial_put(char ch) +{ + while (is_transmit_empty() == 0) + ; + outb(0x3f8, (u8)ch); +} + +void serial_print(const char *data) +{ + for (u32 i = 0; i < strlen(data); i++) + serial_put(data[i]); +} + +void main() +{ + serial_print("b"); +} diff --git a/apps/root.c b/apps/root.c new file mode 100644 index 0000000..e7cbf4e --- /dev/null +++ b/apps/root.c @@ -0,0 +1,48 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#include <def.h> + +u32 strlen(const char *s) +{ + const char *ss = s; + while (*ss) + ss++; + return ss - s; +} + +u8 inb(u16 port) +{ + u8 value; + __asm__ volatile("inb %1, %0" : "=a"(value) : "Nd"(port)); + return value; +} + +void outb(u16 port, u8 data) +{ + __asm__ volatile("outb %0, %1" ::"a"(data), "Nd"(port)); +} + +int is_transmit_empty() +{ + return inb(0x3f8 + 5) & 0x20; +} + +void serial_put(char ch) +{ + while (is_transmit_empty() == 0) + ; + outb(0x3f8, (u8)ch); +} + +void serial_print(const char *data) +{ + for (u32 i = 0; i < strlen(data); i++) + serial_put(data[i]); +} + +void main() +{ + serial_print("root loaded\n"); + while (1) { + }; +} |