total failure
This commit is contained in:
parent
2cc45e996f
commit
bc7c6f835e
12 changed files with 7246 additions and 11 deletions
8
Makefile
8
Makefile
|
@ -1,12 +1,16 @@
|
|||
|
||||
all: mtgos
|
||||
all: mtgos user
|
||||
|
||||
mtgos:
|
||||
make -C kernel
|
||||
mv kernel/mtgos mtgos
|
||||
|
||||
user:
|
||||
make -C user
|
||||
mv user/*.elf .
|
||||
|
||||
clean:
|
||||
make -C kernel clean
|
||||
rm -rf mtgos
|
||||
|
||||
.PHONY: all mtgos clean
|
||||
.PHONY: all mtgos user clean
|
||||
|
|
3567
kernel/hal/dummy/c_include/elf.h
Normal file
3567
kernel/hal/dummy/c_include/elf.h
Normal file
File diff suppressed because it is too large
Load diff
3569
kernel/hal/x86/c_include/elf.h
Normal file
3569
kernel/hal/x86/c_include/elf.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -10,7 +10,7 @@
|
|||
#include <blockdev.hpp>
|
||||
#include <pmm.hpp>
|
||||
extern "C" void intr_stub_0(void);
|
||||
void main();
|
||||
void main(void ** programs);
|
||||
namespace MTGosHAL {
|
||||
Serial debug;
|
||||
Screen out;
|
||||
|
@ -44,7 +44,17 @@ namespace MTGosHAL {
|
|||
idt.setEntry(8, (void *)((uint32_t)&intr_stub_0+128), SEG_DBL_FAULT, IDT_TASK_GATE | IDT_SEG_32_BIT | IDT_RING_0 | IDT_USED);
|
||||
idt.apply();
|
||||
mm.init(ebx);
|
||||
::main();
|
||||
multiboot_mod_list *mods = (multiboot_mod_list*) ebx->mods_addr;
|
||||
void** progs=nullptr;
|
||||
void* tmp;
|
||||
mm >> tmp;
|
||||
progs=(void**)tmp;
|
||||
uint32_t i;
|
||||
for(i=0;i<(ebx->mods_count<1023?ebx->mods_count:1023);i++) { //Basically until MIN(ebx->mods_count, 1023), as we only support loading up to 1023 programs directly.
|
||||
progs[i]=(void*)(mods[i].mod_start);
|
||||
}
|
||||
progs[i]=nullptr;
|
||||
::main(progs);
|
||||
sti();
|
||||
for(;;);
|
||||
}
|
||||
|
|
|
@ -57,6 +57,13 @@ auto PMM::init(struct multiboot_info * mb_info) -> void {
|
|||
addr+=0x1000;
|
||||
}
|
||||
markUsed(nullptr);
|
||||
multiboot_mod_list *mods = (multiboot_mod_list*) mb_info->mods_addr;
|
||||
for(uint32_t i=0;i<mb_info->mods_count;i++) {
|
||||
markUsed((void*)((uint32_t)(&mods[i])&(~0xFFF))); //Mark all of the module table as used
|
||||
for(uint32_t start=(uint32_t)(mods[i].mod_start)&(~0xFFF);start<(uint32_t)(mods[i].mod_end);start+=0x1000) {
|
||||
markUsed((void*)start); //Protect all multiboot modules
|
||||
}
|
||||
}
|
||||
}
|
||||
auto PMM::markUsed(void * addr) -> void {
|
||||
unsigned int address=(unsigned int)addr;
|
||||
|
|
16
kernel/kernel/elf.cpp
Normal file
16
kernel/kernel/elf.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include <elf.hpp>
|
||||
auto load(Elf32_Ehdr* file) -> void* {
|
||||
if((file->e_ident[0]!=ELFMAG0)||
|
||||
(file->e_ident[1]!=ELFMAG1)||
|
||||
(file->e_ident[2]!=ELFMAG2)||
|
||||
(file->e_ident[3]!=ELFMAG3) )
|
||||
return nullptr;
|
||||
Elf32_Phdr *phdr = (Elf32_Phdr*)((uint32_t)(file->e_phoff)+(uint32_t)file);
|
||||
for(int i=0;i<file->e_phnum;i++) {
|
||||
uint32_t start=phdr[i].p_vaddr;
|
||||
uint32_t end=start+phdr[i].p_memsz;
|
||||
if((start < file->e_entry) && (file->e_entry < end))
|
||||
return (void*) (file->e_entry-start+phdr[i].p_offset+(uint32_t)file); //Calculate _start address
|
||||
}
|
||||
return nullptr;
|
||||
}
|
2
kernel/kernel/include/elf.hpp
Normal file
2
kernel/kernel/include/elf.hpp
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include <elf.h>
|
||||
auto load(Elf32_Ehdr* file) -> void*;
|
|
@ -5,6 +5,7 @@
|
|||
#include <keyboard.hpp>
|
||||
#include <Multitasking.h>
|
||||
#include <blockdev.hpp>
|
||||
#include <elf.hpp>
|
||||
using namespace MTGosHAL;
|
||||
void pid_null() {
|
||||
for(;;);
|
||||
|
@ -25,11 +26,14 @@ void task_d() {
|
|||
while(true)
|
||||
MTGosHAL::out << "d";
|
||||
}
|
||||
void main() {
|
||||
MTGosHAL::out << "Initializing Kernel!\n";
|
||||
MTGosHAL::tasks.initTask(&pid_null);
|
||||
MTGosHAL::tasks.initTask(&task_a);
|
||||
MTGosHAL::tasks.initTask(&task_b);
|
||||
MTGosHAL::tasks.initTask(&task_c);
|
||||
MTGosHAL::tasks.initTask(&task_d);
|
||||
void main(void** files) {
|
||||
MTGosHAL::out << "Initializing Kernel!\n";
|
||||
Elf32_Ehdr** programs=(Elf32_Ehdr**)files;
|
||||
MTGosHAL::tasks.initTask(&pid_null);
|
||||
for(int i=0;programs[i];i++) {
|
||||
void(*start)()=(void(*)())load(programs[i]);
|
||||
if(!start)
|
||||
continue;
|
||||
MTGosHAL::tasks.initTask(start);
|
||||
}
|
||||
}
|
||||
|
|
BIN
test.elf
Executable file
BIN
test.elf
Executable file
Binary file not shown.
17
user/Makefile
Normal file
17
user/Makefile
Normal file
|
@ -0,0 +1,17 @@
|
|||
include ../kernel.settings
|
||||
SRCS = $(shell find -name '*.c')
|
||||
OBJS = $(addsuffix .o,$(basename $(SRCS)))
|
||||
CC = $(PREFIX)gcc
|
||||
LD = $(PREFIX)ld
|
||||
ASFLAGS = -m32
|
||||
CFLAGS = -m32 -w -g -fno-stack-protector -nostdinc -I include -fpie
|
||||
LDFLAGS = -melf_i386 -Ttest.ld
|
||||
test.elf: $(OBJS)
|
||||
$(LD) $(LDFLAGS) -o $@ $^
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c -o $@ $^
|
||||
|
||||
clean:
|
||||
rm $(OBJS)
|
||||
.PHONY: clean
|
11
user/test.c
Normal file
11
user/test.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
unsigned short* videomem = (unsigned short*) 0xb8000;
|
||||
|
||||
void _start(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 3; i++) {
|
||||
*videomem++ = (0x07 << 8) | ('0' + i);
|
||||
}
|
||||
|
||||
while(1);
|
||||
}
|
28
user/test.ld
Normal file
28
user/test.ld
Normal file
|
@ -0,0 +1,28 @@
|
|||
ENTRY(_start)
|
||||
OUTPUT_FORMAT(elf32-i386)
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x0;
|
||||
.text : {
|
||||
*(.text)
|
||||
}
|
||||
.data ALIGN(4096) : {
|
||||
start_ctors = .;
|
||||
KEEP(*( .init_array ));
|
||||
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* )));
|
||||
*(.ctors)
|
||||
end_ctors = .;
|
||||
start_dtors = .;
|
||||
*(.dtors)
|
||||
end_dtors = .;
|
||||
*(.data)
|
||||
*(.got)
|
||||
}
|
||||
.rodata ALIGN(4096) : {
|
||||
*(.rodata)
|
||||
}
|
||||
.bss ALIGN(4096) : {
|
||||
*(.bss)
|
||||
}
|
||||
. = ALIGN(4096);
|
||||
}
|
Loading…
Reference in a new issue