This commit is contained in:
Julian Barathieu 2018-12-24 22:38:14 +01:00
parent 915490fa24
commit 003bd3be3c
19 changed files with 221 additions and 123 deletions

View File

@ -10,7 +10,7 @@
//----------------------------------------------------------------------------//
2018/10/?? - Started talking about making our own OS
2018/11/?? - Name decided & creation of gnu-os-k.eu
2018/11/?? - Name decided & creation of os-k.eu
2018/12/06 - Actually started project, began MBR, decided directories organization, created this file and others
2018/12/08 - MBR actually supports Long Mode Compatibility Verification
- Added A20 line Enabling to MBR

View File

@ -8,11 +8,11 @@
#----------------------------------------------------------------------------#
CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc"
CWARNS=-Wall -Wextra -Werror -pedantic
CLDSCR=-T kernel.ld
CWARNS= -pedantic -Wall -Wextra -Werror
CFLAGS=-nostdlib -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2
CDEFINES=-D_KALEID_KERNEL
CINCLUDES=-I./kaleid
CDEFINES=
CC=$(CCNAME) $(CWARNS) $(CLDSCR) $(CFLAGS) $(CDEFINES) $(CINCLUDES)
@ -57,23 +57,26 @@ COBJDIR=$(OBJDIR)/$(COMMDIR)
COMMDEPS=$(COMMDIR)/common.h $(COMMDIR)/assert.h $(COMMDIR)/atomic.h $(COMMDIR)/config.h \
$(COMMDIR)/status.h
COBJECTS=$(COBJDIR)/lib/string.o
COBJECTS=$(COBJDIR)/lib/string.o $(COBJDIR)/lib/status.o
common: common.lib.string.c $(COMMDEPS)
common: common.lib.string.c common.lib.status.c
common.lib.string.c: $(COMMDIR)/lib/string.c $(COMMDEPS)
$(CC) -c $(COMMDIR)/lib/string.c -o $(OBJDIR)/$(COMMDIR)/lib/string.o
$(CC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o
common.lib.status.c: $(COMMDIR)/lib/status.c $(COMMDEPS)
$(CC) -c $(COMMDIR)/lib/status.c -o $(COBJDIR)/lib/status.o
#----------------------------------------------------------------------------#
# KERNEL MAKEFILE
KOBJDIR=$(OBJDIR)/$(KERNDIR)
KERNDEPS=$(COMMDEPS) $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/io/ports.h
KERNDEPS=$(COMMDEPS) $(KERNDIR)/init.h $(KERNDIR)/io/terminal.h $(KERNDIR)/io/ports.h $(KERNDIR)/ke/panic.h
kernel: common kernel.io.terminal.c kernel.init.c kernel.io.ports.c
kernel: common kernel.io.terminal.c kernel.init.c kernel.io.ports.c kernel.ke.panic.c
$(CC) -o $(BINDIR)/kaleid-kernel.elf \
$(COBJECTS) $(KOBJDIR)/init.o \
$(COBJECTS) $(KOBJDIR)/init.o $(KOBJDIR)/ke/panic.o \
$(KOBJDIR)/io/terminal.o $(KOBJDIR)/io/ports.o
@ -85,44 +88,9 @@ kernel.io.ports.c: $(KERNDIR)/io/ports.c $(KERNDEPS)
kernel.io.terminal.c: $(KERNDIR)/io/terminal.c $(KERNDEPS)
$(CC) -c $(KERNDIR)/io/terminal.c -o $(KOBJDIR)/io/terminal.o
kernel.ke.panic.c: $(KERNDIR)/ke/panic.c $(KERNDEPS)
$(CC) -c $(KERNDIR)/ke/panic.c -o $(KOBJDIR)/ke/panic.o
#----------------------------------------------------------------------------#

View File

@ -5,7 +5,7 @@
; NeoX ;
; ;
; Desc: Kernel (second stage) Loader for OS/K INCLUDED FUNCTIONS ;
; (x86_64 architecture only) ;
; (x86_64 architecture only) ;
;=----------------------------------------------------------------------------=;
[BITS 64]
@ -34,7 +34,7 @@ write:
; bl : color code ;
; esi : string address ;
;-----------------------------------------------------------------------;
mov edi, [NextTRAM] ;TRAM ADDRESS
mov edi, [NextTRAM] ; TRAM ADDRESS
push rsi
push rdi
.pLoop:
@ -49,7 +49,7 @@ write:
mov al, bl
stosb ; color subpixel
add qword [NextTRAM], 0x2 ; Cursor moving
add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels
add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels
jmp .pLoop
.pEnd:
pop rdi
@ -73,3 +73,4 @@ write:
.scroll:
; XXX ;
jmp .pLoop

View File

@ -10,17 +10,19 @@
#ifndef _KALCOMM_ASSERT_H
#define _KALCOMM_ASSERT_H
extern const char *panicstr;
extern void panic(const char *) __dead;
#if !defined(_NO_DEBUG) && !defined(NDEBUG)
#if !defined(_NO_DEBUG)
// uses panic() in kernel, abort() in system
noreturn void ___assert_handler(const char *, const char *, int, const char *);
#define assert(x) do{if(!(x))panic(#x);}while(0);
#define assert(x) do{if(!(x))___assert_handler(#x, __FILE__, __LINE__, __func__);}while(0);
/*
#define assert_never_used(x) do{static bool __##x##_init = FALSE; \
assert(__##x##_init == FALSE); __##x##_init = TRUE;}while(0);
#define assert_used_once(x) do{static bool __##x##_init; assert(__##x##_init == TRUE);} while(0);
*/
#else // not debugging
@ -28,9 +30,13 @@ extern void panic(const char *) __dead;
#define NDEBUG 1
#endif
#if !defined(_NO_DEBUG)
#define _NO_DEBUG 1
#endif
#define assert(x)
#define assert_never_used(x)
#define assert_used_once(x)
#define assert_never_used(x)
#endif

View File

@ -12,9 +12,14 @@
// atomic_t defined in common/types.h
#ifdef _KALEID_KERNEL
// only available in the kernel
#define cli() asm volatile ("cli")
#define sti() asm volatile ("sti")
#define hlt() asm volatile ("hlt")
#endif
#endif

View File

@ -22,7 +22,7 @@
#define NULL ((void*)0)
#define PACKED __attribute__((packed))
#define __dead __attribute__((noreturn))
#define noreturn __attribute__((noreturn))
#define THROWS(...)
#define ERRS(...)

View File

@ -20,11 +20,22 @@
// General configuration choices //
//------------------------------------------//
// Enable multiprocessor support?
// Right now this has to be left to NO
//
// Enable/disable multiprocessor support
//
#define MULTIPROCESSOR NO
// etc...
//
// Enable/disable preemptivity
//
#define PREEMPTIVE YES
//
// Size of a tabulation in spaces
// Default: 4 spaces/tab
//
#define TABSIZE 4
// this file is to be progressively filled
#endif

View File

@ -20,11 +20,22 @@
// General configuration choices //
//------------------------------------------//
// Enable multiprocessor support?
// Right now this has to be left to NO
//
// Enable/disable multiprocessor support
//
#define MULTIPROCESSOR NO
// etc...
//
// Enable/disable preemptivity
//
#define PREEMPTIVE YES
//
// Size of a tabulation in spaces
// Default: 4 spaces/tab
//
#define TABSIZE 4
// this file is to be progressively filled
#endif

View File

@ -0,0 +1,31 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Implementation of describe_status() //
//----------------------------------------------------------------------------//
#include "common/common.h"
static const char *descriptions[] = {
[-SUCCESS] = "Success",
[-FAILED] = "Failed (no precision)",
[-NOT_PERMITTED] = "Operation not permitted",
[-ACCESS_DENIED] = "Access denied",
[-BAD_ARGUMENT] = "Bad argument",
[-BAD_ARG_RANGE] = "Bad argument (not in range)",
[-BAD_ARG_NULL] = "Bad argument (null pointer)",
};
const char *describe_status(status_t status)
{
(void)descriptions;
(void)status;
// XXX
return "";
}

View File

@ -4,21 +4,38 @@
// Authors: spectral` //
// NeoX //
// //
// Desc: strlen() function //
// Desc: String-related functions //
//----------------------------------------------------------------------------//
#include "common/string.h"
//
// Return str's length
// TODO multibyte, assembly
//
size_t strlen(const char *str)
{
const char *base = str;
while (str) str++;
return (str - base);
}
char *strcpy(char *dest, const char *src)
{
char *base = dest;
while ((*dest++ = *src++));
return base;
}
char *strncpy(char *dest, const char *src, size_t n)
{
size_t i;
for (i = 0; str; str++, i++);
for (i = 0; i < n && src[i]; i++) {
dest[i] = src[i];
}
return i;
while (i < n) dest[i++] = 0;
return dest;
}

View File

@ -14,6 +14,9 @@
#define STATUS_FAILED(x) ((x) < 0))
#define STATUS_SUCCESS(x) (!STATUS_FAILED(x))
// see in common/lib/status.c for status messages
const char *describe_status(status_t);
#define SUCCESS (0) // everything went fine
#define FAILED (-1)

View File

@ -13,7 +13,9 @@
#include "common/common.h"
size_t strlen(const char *s);
size_t strlen(const char *);
char *strcpy(char *, const char *);
char *strncpy(char *, const char *, size_t);
#endif

View File

@ -22,9 +22,10 @@ typedef short port_t;
typedef uint wchar_t;
typedef ulong size_t;
typedef long ssize_t;
typedef size_t off_t;
typedef int atomic_t;
typedef ulong pid_t;
typedef int atomic_t;
typedef ulong pid_t;
#endif

View File

@ -12,6 +12,7 @@
#include "common/common.h"
#include "common/string.h"
#include "kernel/ke/panic.h"
// kernel entry point
void kstart(void);

View File

@ -14,8 +14,8 @@
#define outb(port,val) asm volatile ("outb %1, %0" : : "dN" (port), "a" (value))
uchar inb(port_t port);
ushort inw(port_t port);
uchar inb(port_t);
ushort inw(port_t);
#endif

View File

@ -125,7 +125,7 @@ void kterm_putch_unlocked(struct kterm *kt, char ch)
else if (ch == '\t') {
prev_row = kt->kt_curr_y;
// compiler will optimize this away
for (i = 0; i < 4; i++) {
for (i = 0; i < TABSIZE; i++) {
// tabulations can't spread over two lines
if (kt->kt_curr_y == prev_row) {
kterm_putch_unlocked(kt, ' ');
@ -176,45 +176,11 @@ status_t kterm_print(struct kterm *kt, const char *str)
kterm_lock(kt);
while (*str) {
kterm_putch_unlocked(kt, *str);
s++;
kterm_putch_unlocked(kt, *str++);
}
kterm_unlock(kt);
return SUCCESS;
}
//
// Panic message
//
const char *panicstr = NULL;
//
// Your best boy panic()
//
void panic(const char *s)
{
cli();
ktclear();
if (s == NULL) {
s = "(no message given)";
}
if (panicstr) {
// shouldn't be possible
ktprint("double panic!\n");
hlt();
}
panicstr = s;
ktprint("panic! - ");
ktprint(s);
while (TRUE) {
hlt();
}
}

View File

@ -25,17 +25,15 @@ enum kterm_color {
};
struct kterm {
// flags?
void *kt_lock;
ushort *kt_buffer;
uchar kt_color;
size_t kt_width, kt_height;
size_t kt_curr_x, kt_curr_y;
void *kt_lock;
ushort *kt_buffer;
uchar kt_color;
size_t kt_width;
size_t kt_height;
off_t kt_curr_x;
off_t kt_curr_y;
#ifndef _NO_DEBUG
bool kt_init;
bool kt_init;
#endif
};
@ -50,13 +48,13 @@ status_t kterm_print(struct kterm *, const char *);
status_t kterm_change_color(struct kterm *, uchar);
#ifdef _UNLOCKED_IO
void kterm_putch_unlocked(struct kterm *, char ch);
void kterm_putch_unlocked(struct kterm *, char);
#endif
#define ktclear() kterm_clear(kt_stdout)
#define ktputch(c) kterm_putch(kt_stdout,c)
#define ktprint(s) kterm_print(kt_stdout,s)
#define ktchcol(c) kterm_change_color(kt_stdout, c)
#define ktputch(c) kterm_putch(kt_stdout, (c))
#define ktprint(s) kterm_print(kt_stdout, (s))
#define ktchcol(c) kterm_change_color(kt_stdout, (c))
#define kterm_lock(kt)
#define kterm_trylock(kt)

View File

@ -0,0 +1,59 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: How NOT to panic 101 //
//----------------------------------------------------------------------------//
#include "kernel/ke/panic.h"
//
// Panic message
//
const char *panicstr = NULL;
//
// Failed assert() handler
//
noreturn void ___assert_handler(const char *msg, const char *file, int line, const char *func)
{
// not getting out of here
cli();
(void)file; (void)line; (void)func;
// XXX sprintf() to create a proper panicstr
panic(msg);
}
//
// Your best boy panic()
//
void panic(const char *str)
{
cli();
ktclear();
if (str == NULL) {
str = "(no message given)";
}
if (panicstr) {
// shouldn't be possible
ktprint("double panic!\n");
hlt();
}
panicstr = str;
ktprint("panic! - ");
ktprint(str);
while (TRUE) {
hlt();
}
}

View File

@ -0,0 +1,18 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Looking to create some panic? Look no further! //
//----------------------------------------------------------------------------//
#ifndef _KALKERN_KE_PANIC_H
#define _KALKERN_KE_PANIC_H
#include "kernel/io/terminal.h"
extern const char *panicstr;
noreturn void panic(const char *);
#endif