Merge branch 'BetterTerm' of github.com:os-k-team/GNU-GPL-OS-K into BetterTerm

This commit is contained in:
Julian Barathieu 2019-03-19 13:59:16 +01:00
commit 94eccdc3d7
13 changed files with 288 additions and 149 deletions

View File

@ -127,8 +127,8 @@ $(KOBJDIR)/prog.o: $(KERNELDIR)/extras/prog.c
kal_kern_obj= $(KOBJDIR)/kernel/cpuid.o $(KOBJDIR)/kernel/init.o \
$(KOBJDIR)/kernel/table.o $(KOBJDIR)/kernel/cursor.o \
$(KOBJDIR)/kernel/term.o $(KOBJDIR)/kernel/vga.o \
$(KOBJDIR)/kernel/panic.o $(KOBJDIR)/kernel/heap.o \
$(KOBJDIR)/kernel/malloc.o
$(KOBJDIR)/kernel/panic.o $(KOBJDIR)/kernel/map.o \
$(KOBJDIR)/kernel/heap.o $(KOBJDIR)/kernel/malloc.o
$(KOBJDIR)/kernel/cpuid.o: $(KERNELDIR)/kernel/cpu/cpuid.c
@$(KCC) $< -o $@
@ -151,6 +151,9 @@ $(KOBJDIR)/kernel/vga.o: $(KERNELDIR)/kernel/io/vga.c
$(KOBJDIR)/kernel/panic.o: $(KERNELDIR)/kernel/ke/panic.c
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/map.o: $(KERNELDIR)/kernel/mm/map.c
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/heap.o: $(KERNELDIR)/kernel/mm/heap.c
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
@ -187,19 +190,17 @@ debug: all
install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg
@mkdir -p $(BINDIR)/disk
@echo ${CL2}[$@] ${NC}Installing MBR on image...${CL3}
-@$(MBRDIR)/umount.sh $(BINDIR)/disk
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@$(MBRDIR)/grub-install.sh $(BINDIR)/disk.img $(BINDIR)/disk $(MBRDIR)/grub.cfg
@rmdir $(BINDIR)/disk
@echo ${CL2}[$@] ${CL}Success.${CL3}
.PHONY: clean
clean:
-@$(MBRDIR)/umount.sh $(BINDIR)/disk
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@rm -Rvf ./ProjectTree
@rm -Rvf $(BINDIR)/*.*
@rm -Rvf $(OBJDIR)/*.o
@rm -Rvf $(OBJDIR)/*/*.o
@rm -Rvf $(OBJDIR)/*/*/*.o
@rm -Rvf $(BINDIR)/* $(OBJDIR)/*.o \
$(OBJDIR)/*/*.o $(OBJDIR)/*/*.x86_64 $(OBJDIR)/*/*/*.o
@echo ${CL2}[[$@]] ${CL}Cleaned.${CL3}
$(BINDIR)/kaleid: $(LOBJDIR)/kaleid.x86_64
@ -216,14 +217,14 @@ $(LOBJDIR)/kaleid.x86_64: $(kal_kern_obj) $(kal_com_obj) $(LOBJDIR)/loader.o
-o $(LOBJDIR)/kaleid.x86_64
@echo ${CL2}[$@] ${CL}Success.${CL3}
$(LOBJDIR)/loader.o: $(LOADERDIR)/loader.asm
$(LOBJDIR)/loader.o: $(LOADERDIR)/loader.asm $(LOADERDIR)/*/*.inc
@echo ${CL2}[$@] ${NC}Making loader...${CL3}
@$(ASM) $(ASMFLAGS) $(LOADERDIR)/loader.asm -o $(LOBJDIR)/loader.o > /dev/null
@echo ${CL2}[$@] ${CL}Success.${CL3}
$(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh
@echo ${CL2}[$@]${NC} Constructing disk image...${CL3}
-@$(MBRDIR)/umount.sh $(BINDIR)/disk
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@$(MBRDIR)/create_disk.sh $(BINDIR)/disk.img
@make install_mbr
@echo ${CL2}[$@]${NC} Constructing disk image...${CL3}
@ -232,7 +233,7 @@ $(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh
OS/K: $(BINDIR)/kaleid $(BINDIR)/disk.img ./ProjectTree
@mkdir -p $(BINDIR)/disk
@echo ${CL2}[[$@]] ${NC}Integrating kernel...${CL3}
-@$(MBRDIR)/umount.sh $(BINDIR)/disk
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@$(MBRDIR)/mount.sh $(BINDIR)/disk.img $(BINDIR)/disk
@cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid
@$(MBRDIR)/umount.sh $(BINDIR)/disk

View File

@ -62,9 +62,7 @@
│   ├── atol.o
│   ├── atoul.o
│   ├── atou.o
│   ├── crtlib
│   ├── ctype.o
│   ├── extras
│   ├── itoa.o
│   ├── kernel
│   │   ├── cpuid.o
@ -81,6 +79,7 @@
│   │   ├── ke
│   │   │   └── panic.o
│   │   ├── malloc.o
│   │   ├── map.o
│   │   ├── panic.o
│   │   ├── table.o
│   │   ├── term.o
@ -130,18 +129,17 @@
│   │   ├── kalbase.h
│   │   ├── kaleid.h
│   │   ├── kalext.h
│   │   ├── kernel
│   │   │   ├── base.h
│   │   │   ├── cpu.h
│   │   │   ├── heap.h
│   │   │   ├── iomisc.h
│   │   │   ├── mm.h
│   │   │   ├── panic.h
│   │   │   ├── proc.h
│   │   │   ├── sched.h
│   │   │   └── term.h
│   │   └── multiboot
│   │   └── multiboot.h
│   │   └── kernel
│   │   ├── base.h
│   │   ├── cpu.h
│   │   ├── heap.h
│   │   ├── iomisc.h
│   │   ├── mm.h
│   │   ├── multiboot.h
│   │   ├── panic.h
│   │   ├── proc.h
│   │   ├── sched.h
│   │   └── term.h
│   └── kernel
│   ├── cpu
│   │   └── cpuid.c
@ -157,7 +155,8 @@
│   │   └── panic.c
│   ├── mm
│   │   ├── heap.c
│   │   └── malloc.c
│   │   ├── malloc.c
│   │   └── map.c
│   └── proc
│   ├── Makefile
│   └── sched.c
@ -168,4 +167,4 @@
├── qemu.log
└── Readme.md
33 directories, 110 files
30 directories, 112 files

Binary file not shown.

View File

@ -28,7 +28,6 @@
;;VIDEO
%define TRAM 0xB8000 ; [T]ext[RAM]
%define VRAM 0xA0000 ; [V]ideo[RAM]
%define VGA_HEIGHT 80
;; GLOBAL DATA
@ -38,19 +37,6 @@ VGA_X32 dq 0
VGA_HEIGHT64 dq VGA_HEIGHT
VGA_X dq 0
testf:
push rsi
push rbx
mov esi, teststr
mov bl, 0xF
call write
pop rsi
pop rbx
ret
teststr: db "Salut",0
;-----------------------------------------------------------------------;
; x64/LM Clear Text Screen Function ;
;-----------------------------------------------------------------------;

View File

@ -32,6 +32,7 @@
%include "boot/loader/mem/structures.inc"
global MB_start
global MB_header
extern StartKern
[BITS 32]

View File

@ -42,6 +42,7 @@ typedef struct Terminal_t Terminal_t;
typedef struct ListHead_t ListHead_t;
typedef struct ListNode_t ListNode_t;
typedef struct Processor_t Processor_t;
typedef struct BootInfo_t BootInfo_t;
typedef enum ProcState_t ProcState_t;
typedef enum TermColor_t TermColor_t;
@ -61,6 +62,8 @@ typedef enum TermColor_t TermColor_t;
// Get Process_t structure of current CPU
#define GetCurCPU() (cpuTable[_GetCurCPU()])
//Get the BootInfo_t structure
#define GetBootInfo(x) bootTab.x
//------------------------------------------//
//
@ -91,11 +94,67 @@ struct Processor_t
ListHead_t *timeCritProcs;
};
#define FB_EGA_TEXT 2
#define FB_INDEXED 0
#define FB_RGB 1
#define BINFO_SIZE 4096
struct BootInfo_t
{
// The Bootloader infos (GRUB in our case)
struct {
uint grubFlags; //flags
uint modulesCount; //mods_count
void *modulesAddr; //mods_addr
uint grubName; //boot_loader_name
void *mbHeaderAddr;
} btldr;
// Informations about drives
struct {
uint bootDrv; //boot_device
uint bufferLength; //drives_length
void *bufferAddr; //drives_addr
} drives;
// Informations about memory
struct {
//BIOS provided low and up memory
uint lowMemory; //mem_lower
uint upMemory; //mem_upper
//GRUB provided memory map
uint mapLength; //mmap_length
void *mapAddr; //mmap_addr
} memory;
// Informations about the video drive
struct {
uint vbeControl; //vbe_control_info
uint vbeModeInfo; //vbe_mode_info
ushort vbeMode; //vbe_mode
ushort vbeInterfaceSeg; //vbe_interface_seg
ushort vbeInterfaceOff; //vbe_interface_off
ushort vbeInterfaceLen; //vbe_interface_len
void* framebufferAddr; //framebuffer_addr
uint framebufferPitch; //framebuffer_pitch
uint framebufferWidth; //framebuffer_width
uint framebufferHeight; //framebuffer_height
uchar framebufferBpp; //framebuffer_bpp
uchar framebufferType; //framebuffer_type
} video;
// Informations about the microcode firmware (BIOS/EFI)
struct {
uint apmTable; //apm_table
uint romTable; //config_table
} firmware;
};
//------------------------------------------//
extern int cpuCount;
extern Processor_t cpuTable[NCPUS];
extern BootInfo_t bootTab;
//------------------------------------------//
#define DEC_PER_CPU(name, field, type) \

View File

@ -31,13 +31,6 @@
//------------------------------------------//
void *GetMemoryMap(void);
size_t GetMemorySize(void);
size_t GetAvailZoneSize(void *);
//------------------------------------------//
#define _HEAP_START (4 * MB)
void InitHeap(void);

View File

@ -22,3 +22,17 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <kernel/multiboot.h>
#include <kernel/base.h>
//
// Returns a pointer to the first entry of the memory map
//
void *GetMemoryMap(void);
//
// Initializes the memory map structure
//
error_t InitMemoryMap(void);
// -------------------------------------------------------------------------- //

View File

@ -93,74 +93,74 @@
#ifndef ASM_FILE
typedef unsigned char multiboot_uint8_t;
typedef unsigned short multiboot_uint16_t;
typedef unsigned int multiboot_uint32_t;
typedef unsigned long long multiboot_uint64_t;
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long long ullong;
struct multiboot_header
{
/* Must be MULTIBOOT_MAGIC - see above. */
multiboot_uint32_t magic;
uint magic;
/* Feature flags. */
multiboot_uint32_t flags;
uint flags;
/* The above fields plus this one must equal 0 mod 2^32. */
multiboot_uint32_t checksum;
uint checksum;
/* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
multiboot_uint32_t header_addr;
multiboot_uint32_t load_addr;
multiboot_uint32_t load_end_addr;
multiboot_uint32_t bss_end_addr;
multiboot_uint32_t entry_addr;
uint header_addr;
uint load_addr;
uint load_end_addr;
uint bss_end_addr;
uint entry_addr;
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
multiboot_uint32_t mode_type;
multiboot_uint32_t width;
multiboot_uint32_t height;
multiboot_uint32_t depth;
uint mode_type;
uint width;
uint height;
uint depth;
};
/* The symbol table for a.out. */
struct multiboot_aout_symbol_table
{
multiboot_uint32_t tabsize;
multiboot_uint32_t strsize;
multiboot_uint32_t addr;
multiboot_uint32_t reserved;
uint tabsize;
uint strsize;
uint addr;
uint reserved;
};
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
/* The section header table for ELF. */
struct multiboot_elf_section_header_table
{
multiboot_uint32_t num;
multiboot_uint32_t size;
multiboot_uint32_t addr;
multiboot_uint32_t shndx;
uint num;
uint size;
uint addr;
uint shndx;
};
typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
struct multiboot_info
{
/* Multiboot info version number */
multiboot_uint32_t flags;
uint flags;
/* Available memory from BIOS */
multiboot_uint32_t mem_lower;
multiboot_uint32_t mem_upper;
uint mem_lower;
uint mem_upper;
/* "root" partition */
multiboot_uint32_t boot_device;
uint boot_device;
/* Kernel command line */
multiboot_uint32_t cmdline;
uint cmdline;
/* Boot-Module list */
multiboot_uint32_t mods_count;
multiboot_uint32_t mods_addr;
uint mods_count;
uint mods_addr;
union
{
@ -169,54 +169,54 @@ struct multiboot_info
} u;
/* Memory Mapping buffer */
multiboot_uint32_t mmap_length;
multiboot_uint32_t mmap_addr;
uint mmap_length;
uint mmap_addr;
/* Drive Info buffer */
multiboot_uint32_t drives_length;
multiboot_uint32_t drives_addr;
uint drives_length;
uint drives_addr;
/* ROM configuration table */
multiboot_uint32_t config_table;
uint config_table;
/* Boot Loader Name */
multiboot_uint32_t boot_loader_name;
uint boot_loader_name;
/* APM table */
multiboot_uint32_t apm_table;
uint apm_table;
/* Video */
multiboot_uint32_t vbe_control_info;
multiboot_uint32_t vbe_mode_info;
multiboot_uint16_t vbe_mode;
multiboot_uint16_t vbe_interface_seg;
multiboot_uint16_t vbe_interface_off;
multiboot_uint16_t vbe_interface_len;
uint vbe_control_info;
uint vbe_mode_info;
ushort vbe_mode;
ushort vbe_interface_seg;
ushort vbe_interface_off;
ushort vbe_interface_len;
multiboot_uint64_t framebuffer_addr;
multiboot_uint32_t framebuffer_pitch;
multiboot_uint32_t framebuffer_width;
multiboot_uint32_t framebuffer_height;
multiboot_uint8_t framebuffer_bpp;
ullong framebuffer_addr;
uint framebuffer_pitch;
uint framebuffer_width;
uint framebuffer_height;
uchar framebuffer_bpp;
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
multiboot_uint8_t framebuffer_type;
uchar framebuffer_type;
union
{
struct
{
multiboot_uint32_t framebuffer_palette_addr;
multiboot_uint16_t framebuffer_palette_num_colors;
uint framebuffer_palette_addr;
ushort framebuffer_palette_num_colors;
};
struct
{
multiboot_uint8_t framebuffer_red_field_position;
multiboot_uint8_t framebuffer_red_mask_size;
multiboot_uint8_t framebuffer_green_field_position;
multiboot_uint8_t framebuffer_green_mask_size;
multiboot_uint8_t framebuffer_blue_field_position;
multiboot_uint8_t framebuffer_blue_mask_size;
uchar framebuffer_red_field_position;
uchar framebuffer_red_mask_size;
uchar framebuffer_green_field_position;
uchar framebuffer_green_mask_size;
uchar framebuffer_blue_field_position;
uchar framebuffer_blue_mask_size;
};
};
};
@ -224,51 +224,51 @@ typedef struct multiboot_info multiboot_info_t;
struct multiboot_color
{
multiboot_uint8_t red;
multiboot_uint8_t green;
multiboot_uint8_t blue;
uchar red;
uchar green;
uchar blue;
};
struct multiboot_mmap_entry
{
multiboot_uint32_t size;
multiboot_uint64_t addr;
multiboot_uint64_t len;
uint size;
ullong addr;
ullong len;
#define MULTIBOOT_MEMORY_AVAILABLE 1
#define MULTIBOOT_MEMORY_RESERVED 2
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
#define MULTIBOOT_MEMORY_NVS 4
#define MULTIBOOT_MEMORY_BADRAM 5
multiboot_uint32_t type;
uint type;
} __attribute__((packed));
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
struct multiboot_mod_list
{
/* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
multiboot_uint32_t mod_start;
multiboot_uint32_t mod_end;
uint mod_start;
uint mod_end;
/* Module command line */
multiboot_uint32_t cmdline;
uint cmdline;
/* padding to take it to 16 bytes (must be zero) */
multiboot_uint32_t pad;
uint pad;
};
typedef struct multiboot_mod_list multiboot_module_t;
/* APM BIOS info. */
struct multiboot_apm_info
{
multiboot_uint16_t version;
multiboot_uint16_t cseg;
multiboot_uint32_t offset;
multiboot_uint16_t cseg_16;
multiboot_uint16_t dseg;
multiboot_uint16_t flags;
multiboot_uint16_t cseg_len;
multiboot_uint16_t cseg_16_len;
multiboot_uint16_t dseg_len;
ushort version;
ushort cseg;
uint offset;
ushort cseg_16;
ushort dseg;
ushort flags;
ushort cseg_len;
ushort cseg_16_len;
ushort dseg_len;
};
#endif /* ! ASM_FILE */

View File

@ -22,9 +22,58 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <multiboot/multiboot.h>
#include <kernel/multiboot.h>
#include <kernel/term.h>
#include <kernel/panic.h>
#include <kernel/mm.h>
//
// BootInfo_t initialization. It is necessary because grub will potentially be
// wiped since it is below 1MB....
//
void InitBootInfo(multiboot_info_t *mbi)
{
KalAssert(mbi);
extern uint MB_header;
//Retrieves the bootloader informations
GetBootInfo(btldr).grubFlags = mbi->flags;
GetBootInfo(btldr).grubName = (mbi->boot_loader_name);
GetBootInfo(btldr).modulesCount = mbi->mods_count;
GetBootInfo(btldr).modulesAddr = (void*)(ullong)mbi->mods_addr;
GetBootInfo(btldr).mbHeaderAddr = (void*)(ullong)&MB_header;
DebugLog("\n[InitBootInfo] %s\n", GetBootInfo(btldr).grubName);
DebugLog("[InitBootInfo] Header address : %p, modules address : %p\n",
GetBootInfo(btldr).mbHeaderAddr, GetBootInfo(btldr).modulesAddr);
DebugLog("[InitBootInfo] GRUB flags : %x\n", GetBootInfo(btldr).grubFlags);
//Retrieves the drives informations
GetBootInfo(drives).bootDrv = mbi->boot_device;
GetBootInfo(drives).bufferLength = mbi->drives_length;
GetBootInfo(drives).bufferAddr = (void*)(ullong)mbi->drives_addr;
DebugLog("[InitBootInfo] Root drive : %x\n",
GetBootInfo(drives).bootDrv);
//Retrieves the memory informations
GetBootInfo(memory).lowMemory = mbi->mem_lower;
GetBootInfo(memory).upMemory = mbi->mem_upper;
GetBootInfo(memory).mapAddr = (void*)(ullong)mbi->mmap_addr;
GetBootInfo(memory).mapLength = mbi->mmap_length;
DebugLog("[InitBootInfo] Low memory : %d Kio, Up memory : %d Mio\n",
GetBootInfo(memory).lowMemory, GetBootInfo(memory).upMemory / (MB/KB));
DebugLog("[InitBootInfo] Memory map address : %p, length : %d\n",
GetBootInfo(memory).mapAddr, GetBootInfo(memory).mapLength);
// XXX assign video infos, but unused at this time
// Retrieves the firmware infos
GetBootInfo(firmware).apmTable = mbi->apm_table;
GetBootInfo(firmware).romTable = mbi->config_table;
DebugLog("[InitBootInfo] APM Table : %p, ROM Table : %p\n",
GetBootInfo(firmware).apmTable, GetBootInfo(firmware).romTable);
}
//
// Entry point of the Kaleid kernel
@ -37,23 +86,19 @@ noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic)
// Kernel terminals
InitTerms();
KernLog( "We were loaded by : %s\n\n"
"We get\n"
" *mbInfo : %p\n"
" mbMagic : %x\n"
" mbBootdrv : %x\n"
" *mbMmap : %p\n"
" `-length : %d\n"
"\nGoodbye World :(",
//Hello world because why not
KernLog("%c%c%c OS/K\n\n", 219, 219, 219);
mbInfo->boot_loader_name,
mbInfo,
mbMagic,
mbInfo->boot_device,
mbInfo->mmap_addr,
mbInfo->mmap_length
);
KalAlwaysAssert(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC);
KernLog("[Init] We have magic : %x\n", mbMagic);
// Get out
CrashSystem();
//Initialize the BootInfo_t structure
InitBootInfo(mbInfo);
//Memory mapping
InitMemoryMap();
// We're out
KernLog("\n[Init] Evil never dies !");
CrashSystem(); //yay
}

View File

@ -27,6 +27,8 @@
int cpuCount = 1;
Processor_t cpuTable[NCPUS] = {0};
BootInfo_t bootTab = {0}
Terminal_t *StdOut = 0, *StdDbg = 0;
volatile char *PanicStr = 0;
Terminal_t *stdOut = 0, *stdDbg = 0;

View File

@ -66,5 +66,6 @@ error_t KalAllocMemory(void **ptr, size_t req, int flags, size_t align)
error_t KalFreeMemory(void *ptr)
{
(void)ptr;
return 0;
}

38
kaleid/kernel/mm/map.c Normal file
View File

@ -0,0 +1,38 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <kernel/mm.h>
#include <kernel/term.h>
error_t InitMemoryMap(void)
{
///uint MapIsValid = (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEM_MAP = MULTIBOOT_INFO_MEM_MAP ? 1 : 0);
KalAlwaysAssert(MapIsValid);
return EOK;
}
void *GetMemoryMap(void)
{
return (void*)0;
}