Compare commits
2 commits
745cf9045c
...
d97ec36f8c
| Author | SHA1 | Date | |
|---|---|---|---|
| d97ec36f8c | |||
| 295e622fe1 |
7 changed files with 81 additions and 6 deletions
50
include/kdtables.h
Normal file
50
include/kdtables.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/* kdtables.h
|
||||
* Kernel Discriptor Tables
|
||||
*
|
||||
* Contains GDT, IDT, and any relevant functions and structs pertaining to them
|
||||
*
|
||||
*/
|
||||
#ifndef KDTABLES_H
|
||||
#define KDTABLES_H
|
||||
#include <stdint.h>
|
||||
|
||||
// TSS
|
||||
typedef struct tss_s {
|
||||
uint32_t LINK;
|
||||
uint32_t ESP0;
|
||||
uint32_t SS0;
|
||||
uint32_t ESP1;
|
||||
uint32_t SS1;
|
||||
uint32_t ESP2;
|
||||
uint32_t SS2;
|
||||
uint32_t CR3;
|
||||
uint32_t EIP;
|
||||
uint32_t EFLAGS;
|
||||
uint32_t EAX;
|
||||
uint32_t ECX;
|
||||
uint32_t EDX;
|
||||
uint32_t EBX;
|
||||
uint32_t ESP;
|
||||
uint32_t ESI;
|
||||
uint32_t EDI;
|
||||
uint32_t ES;
|
||||
uint32_t CS;
|
||||
uint32_t SS;
|
||||
uint32_t DS;
|
||||
uint32_t FS;
|
||||
uint32_t GS;
|
||||
uint32_t LDTR;
|
||||
uint32_t IOPB;
|
||||
uint32_t SSP;
|
||||
} __attribute__((packed)) tss_t;
|
||||
|
||||
extern tss_t tss;
|
||||
|
||||
void clear_tss();
|
||||
|
||||
// GDT
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,3 +1,8 @@
|
|||
/* kio.h
|
||||
* Kernel I/O
|
||||
*
|
||||
* Handles any in/output
|
||||
*/
|
||||
#ifndef KIO_H
|
||||
#define KIO_H
|
||||
#define VGA_GRID_COLS 80
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef KMULTIBOOT_H
|
||||
#define KMULTIBOOT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t flags;
|
||||
uint32_t mem_lower;
|
||||
|
|
@ -9,13 +11,13 @@ typedef struct {
|
|||
uint32_t cmdline;
|
||||
uint32_t mods_count;
|
||||
uint32_t mods_addr;
|
||||
} multiboot_info_t;
|
||||
} mb_info_t;
|
||||
|
||||
typedef struct multiboot_mmap_entry {
|
||||
uint32_t ssize; //size of the entry
|
||||
uint64_t addr; //physical location of memory
|
||||
uint64_t msize;
|
||||
uint32_t type;
|
||||
} __attribute__((packed));
|
||||
} __attribute__((packed)) mb_mmap_entry_t;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ ENTRY(start)
|
|||
SECTIONS
|
||||
{
|
||||
/*start me at 1Mb because below that is x86 essential stuff, which we dont want to be written on top of.*/
|
||||
. = 2M;
|
||||
. = 1M;
|
||||
|
||||
/* we're going to maintain 4K alignment - apparently useful for paging, and i'm not complaining about the lost space anyway. */
|
||||
|
||||
|
|
@ -20,6 +20,7 @@ SECTIONS
|
|||
.rodata BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.rodata*)
|
||||
*(.gdt_sect)
|
||||
}
|
||||
|
||||
/*initialized rw data. */
|
||||
|
|
@ -33,5 +34,6 @@ SECTIONS
|
|||
{
|
||||
*(COMMON)
|
||||
*(.bss)
|
||||
*(.tss_sect)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
7
src/kdtables.c
Normal file
7
src/kdtables.c
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/* kdtables.c
|
||||
* Kernel Descriptor Tables
|
||||
*
|
||||
* Contains GDT, LDT, and any relevant functions and structs pertaining to them
|
||||
*/
|
||||
|
||||
|
||||
|
|
@ -10,7 +10,6 @@ void kern_main(uint32_t multiboot_magic, multiboot_info_t* multiboot_info)
|
|||
{
|
||||
//wipe the screen
|
||||
vga_clear();
|
||||
|
||||
//We're going to use this buffer as our 8char hex representation for reading mem
|
||||
|
||||
vga_printf("Entry eax:%X\n", multiboot_magic);
|
||||
|
|
@ -24,6 +23,5 @@ void kern_main(uint32_t multiboot_magic, multiboot_info_t* multiboot_info)
|
|||
|
||||
vga_printf("MEM_LOWER:%X\n", multiboot_info->mem_lower);
|
||||
vga_printf("MEM_UPPER:%X\n", multiboot_info->mem_upper);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
13
src/start.s
13
src/start.s
|
|
@ -1,7 +1,6 @@
|
|||
//C main function for our kernel
|
||||
//See: kernel.c
|
||||
.extern kern_main
|
||||
|
||||
//This will be our entrypoint function name - gotta initialize it now as global so the linker knows later.
|
||||
.global start
|
||||
|
||||
|
|
@ -28,6 +27,18 @@
|
|||
//Remember, stack grows DOWNWARD! So the last thing in the section -> the highest memory address -> the very first thing on the stack!
|
||||
//Therefore, we put a label here to represent the top of our stack for later.
|
||||
stack_top:
|
||||
//Allocation of some space for our TSS.
|
||||
|
||||
|
||||
.section .tss_sect:
|
||||
.align 8
|
||||
tss:
|
||||
.skip 104
|
||||
|
||||
.section .gdt_sect:
|
||||
.align 8
|
||||
gdt:
|
||||
.skip 48
|
||||
|
||||
|
||||
//Actual code. Entry point goes here!
|
||||
|
|
|
|||
Loading…
Reference in a new issue