Clean: harmonizing & header-commenting code
This commit is contained in:
@@ -1,22 +1,11 @@
|
||||
// Global descriptor table setup
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#include "gdt.h"
|
||||
#include "../libc/stdio.h"
|
||||
|
||||
struct gdt_entry
|
||||
{
|
||||
unsigned short limit_low;
|
||||
unsigned short base_low;
|
||||
unsigned char base_middle;
|
||||
unsigned char access;
|
||||
unsigned char granularity;
|
||||
unsigned char base_high;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct gdt_ptr
|
||||
{
|
||||
unsigned short limit;
|
||||
unsigned int base;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct gdt_entry gdt[3];
|
||||
struct gdt_ptr gp;
|
||||
|
||||
|
||||
@@ -1,8 +1,28 @@
|
||||
// Global descriptor table setup header
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#ifndef GDT_H
|
||||
#define GDT_H
|
||||
|
||||
void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
|
||||
struct gdt_entry
|
||||
{
|
||||
unsigned short limit_low;
|
||||
unsigned short base_low;
|
||||
unsigned char base_middle;
|
||||
unsigned char access;
|
||||
unsigned char granularity;
|
||||
unsigned char base_high;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct gdt_ptr
|
||||
{
|
||||
unsigned short limit;
|
||||
unsigned int base;
|
||||
} __attribute__((packed));
|
||||
|
||||
void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
|
||||
void gdt_install();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
// Interrupt descriptor table setup
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#include "idt.h"
|
||||
#include "system.h"
|
||||
#include "../libc/stdio.h"
|
||||
|
||||
struct idt_entry
|
||||
{
|
||||
unsigned short base_lo;
|
||||
unsigned short sel;
|
||||
unsigned char always0;
|
||||
unsigned char flags;
|
||||
unsigned short base_hi;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct idt_ptr
|
||||
{
|
||||
unsigned short limit;
|
||||
unsigned int base;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct idt_entry idt[256];
|
||||
struct idt_ptr idtp;
|
||||
|
||||
|
||||
@@ -1,8 +1,27 @@
|
||||
// Interrupt descriptor table setup header
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#ifndef IDT_H
|
||||
#define IDT_H
|
||||
|
||||
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags);
|
||||
struct idt_entry
|
||||
{
|
||||
unsigned short base_lo;
|
||||
unsigned short sel;
|
||||
unsigned char always0;
|
||||
unsigned char flags;
|
||||
unsigned short base_hi;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct idt_ptr
|
||||
{
|
||||
unsigned short limit;
|
||||
unsigned int base;
|
||||
} __attribute__((packed));
|
||||
|
||||
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags);
|
||||
void idt_install();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#ifndef INCLUDE_IO_H
|
||||
#define INCLUDE_IO_H
|
||||
// Raw CPU port I/O kernel module header
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#ifndef IO_H
|
||||
#define IO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
; Raw CPU port I/O kernel module
|
||||
; Author: xamidev
|
||||
; Licensed under the Unlicense. See the repo below.
|
||||
; https//github.com/xamidev/blankos
|
||||
|
||||
global outb
|
||||
|
||||
outb:
|
||||
mov al, [esp + 8]
|
||||
mov dx, [esp + 4]
|
||||
out dx, al
|
||||
ret
|
||||
mov al, [esp + 8]
|
||||
mov dx, [esp + 4]
|
||||
out dx, al
|
||||
ret
|
||||
|
||||
global inb
|
||||
|
||||
inb:
|
||||
mov dx, [esp + 4]
|
||||
in al, dx
|
||||
ret
|
||||
mov dx, [esp + 4]
|
||||
in al, dx
|
||||
ret
|
||||
|
||||
global x86_div64_32
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
// Interrupt Requests setup
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#include "system.h"
|
||||
#include "io.h"
|
||||
#include "idt.h"
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
// Interrupt service routines setup
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#include "system.h"
|
||||
#include "../libc/stdio.h"
|
||||
#include "idt.h"
|
||||
@@ -37,7 +42,6 @@ extern void isr31();
|
||||
|
||||
void isr_install()
|
||||
{
|
||||
|
||||
idt_set_gate(0, (unsigned)isr0, 0x08, 0x8E);
|
||||
idt_set_gate(1, (unsigned)isr1, 0x08, 0x8E);
|
||||
idt_set_gate(2, (unsigned)isr2, 0x08, 0x8E);
|
||||
@@ -116,4 +120,3 @@ void fault_handler(struct regs *r)
|
||||
for (;;);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#include "kheap.h"
|
||||
// Kernel heap management
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#include "kheap.h"
|
||||
#include <stdint.h>
|
||||
|
||||
extern uint32_t end;
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
// Kernel heap management header
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#ifndef KHEAP_H
|
||||
#define KHEAP_H
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
; Kernel loader assembly stub and multiboot2 header
|
||||
; Author: xamidev
|
||||
; Licensed under the Unlicense. See the repo below.
|
||||
; https//github.com/xamidev/blankos
|
||||
|
||||
global loader
|
||||
|
||||
section .multiboot_header
|
||||
@@ -6,9 +11,9 @@ align 8
|
||||
|
||||
; ASM macros
|
||||
|
||||
MAGIC_NUMBER equ 0xe85250d6 ; multiboot2 magic
|
||||
FLAGS equ 0x0 ; 32-bit protected mode for i386
|
||||
HEADER_LEN equ 44 ; Tags=2+2+4+4+4+4+2+2+4=28
|
||||
MAGIC_NUMBER equ 0xe85250d6 ; multiboot2 magic
|
||||
FLAGS equ 0x0 ; 32-bit protected mode for i386
|
||||
HEADER_LEN equ 44 ; Tags=2+2+4+4+4+4+2+2+4=28
|
||||
CHECKSUM equ -(MAGIC_NUMBER + FLAGS + HEADER_LEN)
|
||||
|
||||
; Multiboot 2 header, according to specification (16bytes)
|
||||
@@ -43,14 +48,12 @@ KERNEL_STACK_SIZE equ 4096
|
||||
extern kmain
|
||||
|
||||
loader:
|
||||
cli
|
||||
; mov eax, 0xCAFEBABE
|
||||
; push dword 42
|
||||
push ebx
|
||||
call kmain
|
||||
cli
|
||||
push ebx
|
||||
call kmain
|
||||
|
||||
.loop:
|
||||
jmp .loop
|
||||
jmp .loop
|
||||
|
||||
global gdt_flush
|
||||
extern gp
|
||||
@@ -206,5 +209,5 @@ irq_common_stub:
|
||||
section .bss
|
||||
align 4
|
||||
kernel_stack:
|
||||
resb KERNEL_STACK_SIZE
|
||||
mov esp, kernel_stack + KERNEL_STACK_SIZE
|
||||
resb KERNEL_STACK_SIZE
|
||||
mov esp, kernel_stack + KERNEL_STACK_SIZE
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
// Paging kernel module
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#include <stdint.h>
|
||||
#include "paging.h"
|
||||
#include "../libc/stdio.h"
|
||||
#include "system.h"
|
||||
#include "kheap.h"
|
||||
|
||||
|
||||
uint32_t *frames;
|
||||
uint32_t nframes;
|
||||
|
||||
extern uint32_t placement_address;
|
||||
|
||||
#define INDEX_FROM_BIT(a) (a/(8*4))
|
||||
#define OFFSET_FROM_BIT(a) (a%(8*4))
|
||||
|
||||
static void set_frame(uint32_t frame_addr)
|
||||
{
|
||||
uint32_t frame = frame_addr/0x1000;
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
// Paging kernel module header
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#ifndef PAGING_H
|
||||
#define PAGING_H
|
||||
|
||||
#include "system.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define INDEX_FROM_BIT(a) (a/(8*4))
|
||||
#define OFFSET_FROM_BIT(a) (a%(8*4))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t present : 1;
|
||||
uint32_t rw : 1;
|
||||
uint32_t rw : 1;
|
||||
uint32_t user : 1;
|
||||
uint32_t accessed : 1;
|
||||
uint32_t dirty : 1;
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
// Basic shell and commands kernel module
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#include "system.h"
|
||||
#include "../libc/stdio.h"
|
||||
#include "../libc/string.h"
|
||||
@@ -6,8 +11,7 @@
|
||||
|
||||
#define BUFFER_SIZE 256
|
||||
#define MAX_COMMANDS 16
|
||||
#define MAX_ARGS 64
|
||||
|
||||
#define MAX_ARGS 64
|
||||
|
||||
char* ascii_title =
|
||||
"\n"
|
||||
@@ -17,7 +21,6 @@ char* ascii_title =
|
||||
"----------------------------------------------\n"
|
||||
"\n";
|
||||
|
||||
|
||||
typedef void (*command_func_t)(int argc, char *argv[]);
|
||||
|
||||
typedef struct
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
// System information kernel module
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#include "../libc/stdio.h"
|
||||
#include "../libc/string.h"
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
// System information kernel module header
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#ifndef SYSINFO_H
|
||||
#define SYSINFO_H
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
// System utilities and routines kernel module
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#include "system.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
// System utilities and routines kernel module header
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https//github.com/xamidev/blankos
|
||||
|
||||
#ifndef SYSTEM_H
|
||||
#define SYSTEM_H
|
||||
|
||||
|
||||
Reference in New Issue
Block a user