New directory structure

This commit is contained in:
nigel 2021-05-02 15:23:50 -04:00
parent 5bd25a3737
commit b44f6761f1
12 changed files with 122 additions and 55 deletions

52
Makefile Normal file
View File

@ -0,0 +1,52 @@
EMULATOR = qemu-system-i386
AS = ${HOME}/opt/cross/bin/i686-elf-as
CC = ${HOME}/opt/cross/bin/i686-elf-gcc
CFLAGS = -std=gnu99 -ffreestanding -O2 -Wall -Wextra
OFILES = $(BUILD_DIR)/boot.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o
SRC_DIR = src
BUILD_DIR = build
CRTBEGIN_OBJ = $(shell $(CC) $(CFLAGS) -print-file-name=crtbegin.o)
CRTEND_OBJ = $(shell $(CC) $(CFLAGS) -print-file-name=crtend.o)
CRTI_OBJ = $(BUILD_DIR)/crti.o
CRTN_OBJ = $(BUILD_DIR)/crtn.o
OBJ_LINK_LIST = $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(OFILES) $(CRTEND_OBJ) $(CRTN_OBJ)
INTERNAL_OBJS = $(CRTI_OBJ) $(OFILES) $(CRTN_OBJ)
all: clean build
build: build_kernel run
run:
$(EMULATOR) -kernel $(BUILD_DIR)/myos.bin
build_kernel: $(OBJ_LINK_LIST)
$(CC) -T $(SRC_DIR)/kernel/arch/i386/linker.ld -o $(BUILD_DIR)/myos.bin \
-ffreestanding -O2 -nostdlib $(OBJ_LINK_LIST) -lgcc
build_x86_64:
$(AS) $(SRC_DIR)/cgc/x86_64/crti.s -o $(BUILD_DIR)/crti_64.o
$(AS) $(SRC_DIR)/cgc/x86_64/crtn.s -o $(BUILD_DIR)/crtn.o
clean:
rm -f $(BUILD_DIR)/myos.bin $(INTERNAL_OBJS)
$(BUILD_DIR)/kernel.o:
$(CC) -c $(SRC_DIR)/kernel/kernel.c -o $(BUILD_DIR)/kernel.o $(CFLAGS)
$(BUILD_DIR)/kterm.o:
$(CC) -c $(SRC_DIR)/kernel/arch/i386/tty/kterm.c -o $(BUILD_DIR)/kterm.o $(CFLAGS)
$(BUILD_DIR)/boot.o:
$(AS) $(SRC_DIR)/kernel/arch/i386/boot.s -o $(BUILD_DIR)/boot.o
$(BUILD_DIR)/crti.o:
$(AS) $(SRC_DIR)/kernel/arch/i386/crti.s -o $(BUILD_DIR)/crti.o
$(BUILD_DIR)/crtn.o:
$(AS) $(SRC_DIR)/kernel/arch/i386/crtn.s -o $(BUILD_DIR)/crtn.o

View File

@ -32,7 +32,9 @@ _start:
call _init
call kernel_main
cli
1: hlt

View File

@ -0,0 +1,14 @@
.section .init
.global _init
.type _init, @function
_init:
push %ebp
movl %esp, %ebp
/* gcc will nicely put the contents of crtbegin.o's .init section here. */
.section .fini
.global _fini
.type _fini, @function
_fini:
push %ebp
movl %esp, %ebp

View File

@ -0,0 +1,7 @@
.section .init
popl %ebp
ret
.section .fini
popl %ebp
ret

View File

@ -1,39 +1,14 @@
#include "kernel.h"
#include "kterm.h"
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;
size_t kterm_row;
size_t kterm_column;
uint8_t kterm_color;
uint16_t* kterm_buffer;
/**
* simple delay function
**/
void delay(int t){
volatile int i,j;
for(i=0;i<t;i++)
for(j=0;j<25000;j++)
asm("NOP");
}
void kernel_main (void) {
/** initialize terminal interface */
kterm_init();
/** Wrtite stuff to the screen to test the terminal**/
kterm_writestring("Hello world!\n");
kterm_writestring("We got newline support!\n");
for(;;){
delay(500);
kterm_writestring("We have implemented terminal scrolling!\n");
}
}
/**
* KTerm stuff
**/
static inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) {
static inline uint8_t vga_entry_color( enum vga_color fg, enum vga_color bg) {
return fg | bg << 4;
}
@ -110,7 +85,6 @@ void kterm_write(const char* data, size_t size) {
}
}
void kterm_writestring(const char* data ){
AS_KERNEL();
kterm_write(data, strlen(data));

View File

@ -1,13 +1,9 @@
#include <stdbool.h>
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#include "string.h"
#define KernelTag "[Kernel]: "
#define AS_KERNEL() ( kterm_setcolor(VGA_COLOR_LIGHT_BLUE),\
kterm_write(KernelTag, strlen(KernelTag)), \
kterm_resetcolor())
#include <stdbool.h>
#include "../vga/colors.h"
void kterm_init();
@ -20,5 +16,7 @@ void kterm_write(const char*, size_t);
void kterm_writestring(const char*);
void kterm_scrollup();
#define KernelTag "[Kernel]: "
#define AS_KERNEL() ( kterm_setcolor(VGA_COLOR_LIGHT_BLUE),\
kterm_write(KernelTag, 10 ), \
kterm_resetcolor())

View File

@ -1,3 +1,4 @@
#pragma once
enum vga_color {
VGA_COLOR_BLACK = 0,
VGA_COLOR_BLUE = 1,

27
src/kernel/kernel.c Normal file
View File

@ -0,0 +1,27 @@
#include "kernel.h"
/**
* simple delay function
**/
void delay(int t){
volatile int i,j;
for(i=0;i<t;i++)
for(j=0;j<25000;j++)
asm("NOP");
}
void kernel_main (void) {
/** initialize terminal interface */
kterm_init();
/** Wrtite stuff to the screen to test the terminal**/
kterm_writestring("Hello world!\n");
kterm_writestring("We got newline support!\n");
for(;;){
delay(500);
kterm_writestring("We have implemented terminal scrolling!\n");
}
}

3
src/kernel/kernel.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
#include "../libc/include/string.h"
#include "arch/i386/tty/kterm.h"

View File

@ -1,11 +0,0 @@
#include <stdint.h>
#include <stddef.h>
#include "vga_colors.h"
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;
size_t kterm_row;
size_t kterm_column;
uint8_t kterm_color;
uint16_t* kterm_buffer;