M kernel/Makefile => kernel/Makefile +2 -1
@@ 3,7 3,7 @@ ARCH = x86_64
CC = cc
LD = ld
NASM = nasm
-CFLAGS = -isystem ../mlibc/include/ -nostdlib -nostdinc -ffreestanding -fno-builtin -O3 -m32
+CFLAGS = -isystem ../mlibc/include/ -Iinclude/ -nostdlib -nostdinc -ffreestanding -fno-builtin -O3 -m32
LDFLAGS = -m elf_i386
NASMFLAGS = -f elf32
@@ 17,6 17,7 @@ ASM_SOURCES =\
$(wildcard src/arch/$(ARCH)/*.asm)
ASM_OBJECTS = $(patsubst %.asm, %.o, $(ASM_SOURCES))
C_SOURCES =\
+ $(wildcard src/arch/$(ARCH)/boot/*.c)\
$(wildcard src/arch/$(ARCH)/*.c)\
$(wildcard src/*.c)
C_OBJECTS = $(patsubst %.c, %.o, $(C_SOURCES))
A kernel/include/kernel/config.h => kernel/include/kernel/config.h +15 -0
@@ 0,0 1,15 @@
+/* see LICENSE for copyright information */
+#ifndef _KERNEL_CONFIG_H_
+#define _KERNEL_CONFIG_H_
+
+/* true/false values (defined for true, undefined for false) */
+#define SERIAL_DEBUG
+
+#define CONFIG_ASCII_ART\
+ "welcome to...\n\n"\
+ "_______ ________________________\n"\
+ "__ __ `__ \\ __ \\_ ___/_ ___/\n"\
+ "_ / / / / / /_/ /(__ )_(__ ) \n"\
+ "/_/ /_/ /_/\\____//____/ /____/ \n\n"
+
+#endif
D kernel/include/kernel/tty.h => kernel/include/kernel/tty.h +0 -21
@@ 1,21 0,0 @@
-/* see LICENSE for copyright information */
-#ifndef _MOSS_TTY_H_
-#define _MOSS_TTY_H_
-
-#include <stdtype.h>
-
-typedef void (*tty_flush_function)(struct tty*);
-
-struct tty {
- u16 lines;
- u16 columns;
- u8 *line_buffer
- tty_flush_function flush_func;
-};
-
-void tty_print(struct tty*, u16, u16, const char *text);
-void tty_put(struct tty*, const char *text, size_t);
-void tty_putc(struct tty*, const char);
-void tty_puts(struct tty*, const char*);
-
-#endif
M kernel/src/arch/x86_64/boot/boot.asm => kernel/src/arch/x86_64/boot/boot.asm +3 -3
@@ 16,11 16,11 @@ header_end:
section .bss
align 16
stack_bottom: ; stack grows from the _bottom_
- resb 16384 ; 16 KiB
+ resb 1024 * 16; 16 KiB
stack_top:
-[GLOBAL start]
-[EXTERN kmain]
+global start
+extern kmain
section .text
A kernel/src/arch/x86_64/boot/boot.h => kernel/src/arch/x86_64/boot/boot.h +22 -0
@@ 0,0 1,22 @@
+/* see LICENSE for copyright information */
+#ifndef _KERNEL_X86_BOOT_H_
+#define _KERNEL_X86_BOOT_H_
+
+#include <stdtype.h>
+
+/* port i/o */
+static inline void
+outb(u16 port, u8 v)
+{
+ asm volatile("outb %0, %1" : : "a" (v), "dN" (port));
+}
+
+static inline u8
+inb(u16 port)
+{
+ u8 v;
+ asm volatile("inb %1, %0" : "=a" (v) : "dN" (port));
+ return v;
+}
+
+#endif
A kernel/src/arch/x86_64/boot/early_serial.c => kernel/src/arch/x86_64/boot/early_serial.c +44 -0
@@ 0,0 1,44 @@
+/* see LICENSE for copyright information */
+#include <stdtype.h>
+
+#include "early_serial.h"
+#include "boot.h"
+
+#define PORT 0x3f8 /* serial port for COM1 */
+
+static bool
+transmit_empty()
+{
+ return inb(PORT + 5) & 0x20;
+}
+
+void
+serial_init()
+{
+ /* copied from OSdev.org */
+ outb(PORT + 1, 0x00); /* Disable all interrupts */
+ outb(PORT + 3, 0x80); /* Enable DLAB (set baud rate divisor) */
+ outb(PORT + 0, 0x03); /* Set divisor to 3 (lo byte) 38400 baud */
+ outb(PORT + 1, 0x00); /* (hi byte) */
+ outb(PORT + 3, 0x03); /* 8 bits, no parity, one stop bit */
+ outb(PORT + 2, 0xC7); /* Enable FIFO, clear them, with 14-byte threshold */
+ outb(PORT + 4, 0x0B); /* IRQs enabled, RTS/DSR set */
+}
+
+void
+serial_putc(char c)
+{
+ while (!transmit_empty());
+
+ outb(PORT, c);
+}
+
+void
+serial_put(char *s, size_t s_len)
+{
+}
+
+void
+serial_puts(char *s)
+{
+}
A kernel/src/arch/x86_64/boot/early_serial.h => kernel/src/arch/x86_64/boot/early_serial.h +12 -0
@@ 0,0 1,12 @@
+/* see LICENSE for copyright information */
+#ifndef _KERNEL_X86_BOOT_EARLY_SERIAL_H_
+#define _KERNEL_X86_BOOT_EARLY_SERIAL_H_
+
+#include <stdtype.h>
+
+void serial_init();
+void serial_putc(char);
+void serial_put(char*, size_t);
+void serial_puts(char*);
+
+#endif
A kernel/src/arch/x86_64/boot/early_tty.c => kernel/src/arch/x86_64/boot/early_tty.c +24 -0
@@ 0,0 1,24 @@
+/* see LICENSE for copyright information */
+
+#include <early_tty.h>
+
+void
+etty_clear()
+{
+ /* clear the vga */
+}
+
+void
+etty_putc(char c)
+{
+}
+
+void
+etty_put(char *s, size_t s_len)
+{
+}
+
+void
+etty_puts(char *s)
+{
+}
A kernel/src/arch/x86_64/boot/early_tty.h => kernel/src/arch/x86_64/boot/early_tty.h +15 -0
@@ 0,0 1,15 @@
+/* see LICENSE for copyright information */
+#ifndef _KERNEL_X86_BOOT_EARLY_TTY_H_
+#define _KERNEL_X86_BOOT_EARLY_TTY_H_
+
+#include <stdtype.h>
+
+#include "vga.h"
+#include "early_serial.h"
+
+void etty_clear();
+void etty_putc(char);
+void etty_put(char*, size_t);
+void etty_puts(char*);
+
+#endif
R kernel/src/arch/x86_64/main.c => kernel/src/arch/x86_64/boot/main.c +8 -8
@@ 1,6 1,8 @@
#include <stdtype.h>
-#include "multiboot.h"
+#include <kernel/config.h>
+
+#include "early_serial.h"
#include "vga.h"
#define VGA_COLS 80
@@ 58,13 60,11 @@ void term_print(const char* str)
void
-kmain(struct multiboot_header *mbh)
+kmain()
{
term_init();
- term_print("welcome to...\n\n");
- term_print("_______ ________________________\n");
- term_print("__ __ `__ \\ __ \\_ ___/_ ___/\n");
- term_print("_ / / / / / /_/ /(__ )_(__ ) \n");
- term_print("/_/ /_/ /_/\\____//____/ /____/ \n\n");
- term_print("starting up...");
+ term_print(CONFIG_ASCII_ART);
+ term_print("starting up...\n");
+
+ serial_init();
}
R kernel/src/arch/x86_64/vga.c => kernel/src/arch/x86_64/boot/vga.c +0 -0
R kernel/src/arch/x86_64/vga.h => kernel/src/arch/x86_64/boot/vga.h +2 -2
@@ 1,6 1,6 @@
/* see LICENSE for copyright information */
-#ifndef _MOSS_ARCH_X86_VGA_H_
-#define _MOSS_ARCH_X86_VGA_H_
+#ifndef _KERNEL_X86_BOOT_VGA_H_
+#define _KERNEL_X86_BOOT_VGA_H_
#include <stdtype.h>
A kernel/src/arch/x86_64/config.h => kernel/src/arch/x86_64/config.h +5 -0
@@ 0,0 1,5 @@
+/* see LICENSE for copyright information */
+#ifndef _MOSS_X86_CONFIG_H_
+#define _MOSS_X86_CONFIG_H_
+
+#endif
D kernel/src/arch/x86_64/multiboot.h => kernel/src/arch/x86_64/multiboot.h +0 -45
@@ 1,45 0,0 @@
-/* see LICENSE for copyright information */
-#ifndef _MOSS_ARCH_X86_MULTIBOOT_H_
-#define _MOSS_ARCH_X86_MULTIBOOT_H_
-
-#include <stdtype.h>
-
-#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
-#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
-#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
-
-struct multiboot_header {
- u32 flags;
- u32 mem_lower;
- u32 mem_upper;
- u32 boot_device;
- u32 cmdline;
- u32 mods_count;
- u32 mods_addr;
- u32 num;
- u32 size;
- u32 addr;
- u32 shndx;
- u32 mmap_length;
- u32 mmap_addr;
- u32 drives_length;
- u32 drives_addr;
- u32 config_table;
- u32 boot_loader_name;
- u32 apm_table;
- u32 vbe_control_info;
- u32 vbe_mode_info;
- u16 vbe_mode;
- u16 vbe_interface_seg;
- u16 vbe_interface_off;
- u16 vbe_interface_len;
-
- u64 framebuffer_addr;
- u32 framebuffer_pitch;
- u32 framebuffer_width;
- u32 framebuffer_height;
- u8 framebuffer_bpp;
- u8 framebuffer_type;
-} __attribute__((packed));
-
-#endif
M mlibc/Makefile => mlibc/Makefile +28 -2
@@ 1,11 1,16 @@
ARCH = x86_64
+STATIC_LIB = build/libc.a
+SHARED_LIB = build/libc.so
+
CC = cc
LD = ld
NASM = nasm
-CFLAGS = -nostdlib -nostdinc -ffreestanding -fno-builtin -O3 -m32 -c
-LDFLAGS =
+AR = ar
+CFLAGS = -nostdlib -nostdinc -ffreestanding -fno-builtin -O3 -m32 -c -fPIC
+LDFLAGS = -shared
NASMFLAGS =
+ARFLAGS = rcf
ASM_SOURCES=\
$(wildcaard src/arch/$(ARCH)/*.asm
@@ 14,3 19,24 @@ C_SOURCES =\
$(wildcard src/arch/$(ARCH)/*.c)\
$(wildcard src/*.c)
C_OBJECTS = $(patsubst %.c, %.o, $(C_SOURCES))
+
+.PHONY: all clean
+
+all: $(STATIC_LIB) $(SHARED_LIB)
+
+clean:
+ @rm -rf $(ASM_OBJECTS)
+ @rm -rf $(C_OBJECTS)
+
+$(SHARED_LIB): $(C_OBJECTS) $(ASM_OBJECTS)
+ mkdir build/
+
+$(STATIC_LIB):
+ mkdir build/
+ $(AR) $(ARFLAGS) $(STATIC_LIB) $(C_OBJECTS) $(ASM_OBJECTS) -o
+
+$(ASM_OBJECTS): %.o: %.asm
+ $(NASM) $(NASMFLAGS) $< -o $@
+
+$(C_OBJECTS): %.o: %.c
+ $(CC) $(CFLAGS) $< -c -o $@
A mlibc/include/mem.h => mlibc/include/mem.h +8 -0
@@ 0,0 1,8 @@
+/* see LICENSE for copyright information */
+#ifndef _MLIBC_MEM_H_
+#define _MLIBC_MEM_H_
+#include <stdtype.h>
+
+void memset(void*, const u8, size_t);
+
+#endif
A mlibc/src/mem.c => mlibc/src/mem.c +10 -0
@@ 0,0 1,10 @@
+/* see LICENSE for copyright information */
+#include <mem.h>
+
+void
+memset(void *p, const u8 b, size_t n)
+{
+ for (size_t i = 0; i < n;i++) {
+ p[i] = b;
+ }
+}