diff options
author | Marvin Borner | 2020-08-09 17:27:08 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-09 17:27:08 +0200 |
commit | 544acef0986977ef9d3a05d87bb9f55163b1280a (patch) | |
tree | 764d28f454b818c3ac19d59df17ecd914f9d7ecf | |
parent | 162d024a53e1e31e00ff0b6f47dd4590edebc551 (diff) |
Temporary cpu and serial drivers in libc
-rw-r--r-- | apps/a.c | 34 | ||||
-rw-r--r-- | apps/b.c | 36 | ||||
-rw-r--r-- | apps/init.c | 35 | ||||
-rw-r--r-- | kernel/Makefile | 2 | ||||
-rw-r--r-- | kernel/main.c | 5 | ||||
-rw-r--r-- | lib/Makefile | 5 | ||||
-rw-r--r-- | lib/cpu.c (renamed from kernel/drivers/cpu.c) | 0 | ||||
-rw-r--r-- | lib/inc/cpu.h (renamed from kernel/inc/cpu.h) | 0 | ||||
-rw-r--r-- | lib/inc/mem.h | 7 | ||||
-rw-r--r-- | lib/inc/print.h | 1 | ||||
-rw-r--r-- | lib/inc/serial.h (renamed from kernel/inc/serial.h) | 0 | ||||
-rw-r--r-- | lib/print.c | 10 | ||||
-rw-r--r-- | lib/serial.c (renamed from kernel/drivers/serial.c) | 0 |
13 files changed, 27 insertions, 108 deletions
@@ -1,41 +1,11 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include <def.h> -#include <str.h> - -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]); -} +#include <print.h> void main() { while (1) { - serial_print("a"); + print("a"); } } @@ -1,42 +1,12 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include <def.h> -#include <str.h> - -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]); -} +#include <print.h> void main() { - serial_print("\nB loaded\n"); + print("\nB loaded\n"); while (1) { - serial_print("b"); + print("b"); } } diff --git a/apps/init.c b/apps/init.c index c35f26f..91f5083 100644 --- a/apps/init.c +++ b/apps/init.c @@ -1,43 +1,14 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include <def.h> +#include <print.h> #include <str.h> -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("Init loaded\n"); + print("Init loaded\n"); __asm__ volatile("int $0x80"); while (1) { - serial_print("b"); + print("b"); }; } diff --git a/kernel/Makefile b/kernel/Makefile index bbf13af..ed422a5 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -2,8 +2,6 @@ COBJS = main.o \ drivers/vesa.o \ - drivers/cpu.o \ - drivers/serial.o \ drivers/interrupts.o \ drivers/interrupts_asm.o \ drivers/keyboard.o \ diff --git a/kernel/main.c b/kernel/main.c index 17d6267..85c1103 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -9,16 +9,15 @@ #include <interrupts.h> #include <keyboard.h> #include <load.h> +#include <mem.h> #include <print.h> #include <serial.h> #include <syscall.h> #include <timer.h> -u32 HEAP = 0x00200000; -u32 HEAP_START; - void kernel_main(struct vid_info *vid_info) { + HEAP = 0x00200000; HEAP_START = HEAP; // For malloc function // Initialize VESA video diff --git a/lib/Makefile b/lib/Makefile index ad430d6..4190ec8 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,10 +1,13 @@ # MIT License, Copyright (c) 2020 Marvin Borner +# TODO: Remove serial and cpu from libc? COBJS = str.o \ mem.o \ math.o \ conv.o \ - print.o + print.o \ + serial.o \ + cpu.o CC = ../cross/opt/bin/i686-elf-gcc LD = ../cross/opt/bin/i686-elf-ld OC = ../cross/opt/bin/i686-elf-ar diff --git a/kernel/drivers/cpu.c b/lib/cpu.c index 5c27c51..5c27c51 100644 --- a/kernel/drivers/cpu.c +++ b/lib/cpu.c diff --git a/kernel/inc/cpu.h b/lib/inc/cpu.h index eb09291..eb09291 100644 --- a/kernel/inc/cpu.h +++ b/lib/inc/cpu.h diff --git a/lib/inc/mem.h b/lib/inc/mem.h index e700e42..e2d574f 100644 --- a/lib/inc/mem.h +++ b/lib/inc/mem.h @@ -5,12 +5,13 @@ #include <def.h> -u32 HEAP; -u32 HEAP_START; - #define malloc(n) ((void *)((HEAP += n) - n)) // TODO: Implement real/better malloc/free #define free(x) +// TODO: Use malloc as syscall +u32 HEAP; +u32 HEAP_START; + void *memcpy(void *dst, const void *src, u32 n); void *memset(void *dst, int c, u32 n); int memcmp(const void *s1, const void *s2, u32 n); diff --git a/lib/inc/print.h b/lib/inc/print.h index 925a5bd..04668b2 100644 --- a/lib/inc/print.h +++ b/lib/inc/print.h @@ -9,5 +9,6 @@ int printf(const char *format, ...); int vprintf(const char *format, va_list ap); int vsprintf(char *str, const char *format, va_list ap); +int print(const char *str); #endif diff --git a/kernel/inc/serial.h b/lib/inc/serial.h index 6511952..6511952 100644 --- a/kernel/inc/serial.h +++ b/lib/inc/serial.h diff --git a/lib/print.c b/lib/print.c index 738e42f..1cbed69 100644 --- a/lib/print.c +++ b/lib/print.c @@ -2,7 +2,7 @@ #include <conv.h> #include <def.h> #include <mem.h> -/* #include <serial.h> */ +#include <serial.h> #include <str.h> static void append(char *dest, char *src, int index) @@ -80,7 +80,7 @@ int vprintf(const char *format, va_list ap) char buf[1024]; memset(buf, 0, 1024); int len = vsprintf(buf, format, ap); - /* serial_print(buf); // TODO: Remove temporary serial print */ + serial_print(buf); // TODO: Remove temporary serial print return len; } @@ -94,3 +94,9 @@ int printf(const char *format, ...) return len; } + +int print(const char *str) +{ + serial_print(str); + return strlen(str); +} diff --git a/kernel/drivers/serial.c b/lib/serial.c index dcee4dd..dcee4dd 100644 --- a/kernel/drivers/serial.c +++ b/lib/serial.c |