[main] Fix multiboot in some instances. Enabling paging can squash the multiboot header, so we want to back it up to somewhere safe.
This commit is contained in:
parent
dc5c3855de
commit
018fe42d40
28
core/array.h
Normal file
28
core/array.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef ARRAY_H
|
||||||
|
#define ARRAY_H
|
||||||
|
#include <system.h>
|
||||||
|
|
||||||
|
typedef void * type_t;
|
||||||
|
typedef signed char (*lessthan_predicate_t)(type_t, type_t);
|
||||||
|
typedef struct {
|
||||||
|
type_t *array;
|
||||||
|
uint32_t size;
|
||||||
|
uint32_t max_size;
|
||||||
|
lessthan_predicate_t less_than;
|
||||||
|
} ordered_array_t;
|
||||||
|
|
||||||
|
signed char standard_lessthan_predicate(type_t a, type_t b);
|
||||||
|
|
||||||
|
ordered_array_t create_ordered_array(uint32_t max_size, lessthanpredicate_t less_than);
|
||||||
|
ordered_array_t place_ordered_array(void *addr, uint32_t max_size, lessthan_predicate_t less_than);
|
||||||
|
|
||||||
|
void destroy_ordered_array(ordered_array_t *array);
|
||||||
|
|
||||||
|
void insert_ordered_array(type_t item, ordered_array_t *array);
|
||||||
|
|
||||||
|
type_t loopup_ordered_array(uint32_t i, ordered_array_t *array);
|
||||||
|
|
||||||
|
void remove_ordered_array(uint32_t i, ordered_array_t *array);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
11
core/mem.c
11
core/mem.c
@ -5,6 +5,17 @@
|
|||||||
|
|
||||||
#include <system.h>
|
#include <system.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t magic;
|
||||||
|
char is_hole;
|
||||||
|
uint32_t size;
|
||||||
|
} header_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t magic;
|
||||||
|
header_t * header;
|
||||||
|
} footer_t;
|
||||||
|
|
||||||
extern uintptr_t end;
|
extern uintptr_t end;
|
||||||
uintptr_t placement_pointer = &end;
|
uintptr_t placement_pointer = &end;
|
||||||
|
|
||||||
|
@ -145,5 +145,6 @@ resettextcolor() {
|
|||||||
*/
|
*/
|
||||||
void init_video() {
|
void init_video() {
|
||||||
textmemptr = (unsigned short *)0xB8000;
|
textmemptr = (unsigned short *)0xB8000;
|
||||||
cls();
|
csr_y = 10;
|
||||||
|
move_csr();
|
||||||
}
|
}
|
||||||
|
140
main.c
140
main.c
@ -48,7 +48,7 @@ memsetw(
|
|||||||
unsigned short *dest,
|
unsigned short *dest,
|
||||||
unsigned short val,
|
unsigned short val,
|
||||||
int count
|
int count
|
||||||
) {
|
) {
|
||||||
int i;
|
int i;
|
||||||
i = 0;
|
i = 0;
|
||||||
for ( ; i < count; ++i ) {
|
for ( ; i < count; ++i ) {
|
||||||
@ -97,27 +97,53 @@ outportb(
|
|||||||
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
|
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
struct multiboot *
|
||||||
* 99 Bottles of Beer on the -Wall
|
copy_multiboot(
|
||||||
* Sample kernel mode program.
|
struct multiboot *mboot_ptr
|
||||||
*/
|
) {
|
||||||
void beer() {
|
struct multiboot *new_header = (struct multiboot *)kmalloc(sizeof(struct multiboot));
|
||||||
int i = 99;
|
memcpy(new_header, mboot_ptr, sizeof(struct multiboot));
|
||||||
while (i > 0) {
|
return new_header;
|
||||||
if (i == 1) {
|
}
|
||||||
puts ("One bottle of beer on the wall, one bottle of beer. Take one down, pass it around, ");
|
|
||||||
} else {
|
void
|
||||||
kprintf("%d bottles of beer on the wall, %d bottles of beer...\n", i, i);
|
dump_multiboot(
|
||||||
}
|
struct multiboot *mboot_ptr
|
||||||
i--;
|
) {
|
||||||
if (i == 1) {
|
resettextcolor();
|
||||||
puts("One bottle of beer on the wall.\n");
|
kprintf("MULTIBOOT header at 0x%x:\n", (uintptr_t)mboot_ptr);
|
||||||
} else {
|
settextcolor(7,0);
|
||||||
kprintf("%d bottles of beer on the wall.\n", i);
|
kprintf("Flags : 0x%x ", mboot_ptr->flags);
|
||||||
}
|
kprintf("Mem Lo: 0x%x ", mboot_ptr->mem_lower);
|
||||||
timer_wait(3);
|
kprintf("Mem Hi: 0x%x ", mboot_ptr->mem_upper);
|
||||||
}
|
kprintf("Boot d: 0x%x\n", mboot_ptr->boot_device);
|
||||||
puts("No more bottles of beer on the wall.\n");
|
kprintf("cmdlin: 0x%x ", mboot_ptr->cmdline);
|
||||||
|
kprintf("Mods : 0x%x ", mboot_ptr->mods_count);
|
||||||
|
kprintf("Addr : 0x%x ", mboot_ptr->mods_addr);
|
||||||
|
kprintf("Syms : 0x%x\n", mboot_ptr->num);
|
||||||
|
kprintf("Syms : 0x%x ", mboot_ptr->size);
|
||||||
|
kprintf("Syms : 0x%x ", mboot_ptr->addr);
|
||||||
|
kprintf("Syms : 0x%x ", mboot_ptr->shndx);
|
||||||
|
kprintf("MMap : 0x%x\n", mboot_ptr->mmap_length);
|
||||||
|
kprintf("Addr : 0x%x ", mboot_ptr->mmap_addr);
|
||||||
|
kprintf("Drives: 0x%x ", mboot_ptr->drives_length);
|
||||||
|
kprintf("Addr : 0x%x ", mboot_ptr->drives_addr);
|
||||||
|
kprintf("Config: 0x%x\n", mboot_ptr->config_table);
|
||||||
|
kprintf("Loader: 0x%x ", mboot_ptr->boot_loader_name);
|
||||||
|
kprintf("APM : 0x%x ", mboot_ptr->apm_table);
|
||||||
|
kprintf("VBE Co: 0x%x ", mboot_ptr->vbe_control_info);
|
||||||
|
kprintf("VBE Mo: 0x%x\n", mboot_ptr->vbe_mode_info);
|
||||||
|
kprintf("VBE In: 0x%x ", mboot_ptr->vbe_mode);
|
||||||
|
kprintf("VBE se: 0x%x ", mboot_ptr->vbe_interface_seg);
|
||||||
|
kprintf("VBE of: 0x%x ", mboot_ptr->vbe_interface_off);
|
||||||
|
kprintf("VBE le: 0x%x\n", mboot_ptr->vbe_interface_len);
|
||||||
|
resettextcolor();
|
||||||
|
kprintf("Started with: %s\n", (char *)mboot_ptr->cmdline);
|
||||||
|
kprintf("Booted from: %s\n", (char *)mboot_ptr->boot_loader_name);
|
||||||
|
kprintf("%dkB lower memory\n", mboot_ptr->mem_lower);
|
||||||
|
kprintf("%dkB higher memory ", mboot_ptr->mem_upper);
|
||||||
|
int mem_mb = mboot_ptr->mem_upper / 1024;
|
||||||
|
kprintf("(%dMB)\n", mem_mb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -125,80 +151,20 @@ void beer() {
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
main(struct multiboot *mboot_ptr) {
|
main(struct multiboot *mboot_ptr) {
|
||||||
|
mboot_ptr = copy_multiboot(mboot_ptr);
|
||||||
gdt_install();
|
gdt_install();
|
||||||
idt_install();
|
idt_install();
|
||||||
isrs_install();
|
isrs_install();
|
||||||
irq_install();
|
irq_install();
|
||||||
init_video();
|
init_video();
|
||||||
paging_install(mboot_ptr->mem_upper + 1024);
|
settextcolor(12,0);
|
||||||
|
kprintf("[%s %s]\n", KERNEL_UNAME, KERNEL_VERSION_STRING);
|
||||||
|
paging_install(mboot_ptr->mem_upper);
|
||||||
|
dump_multiboot(mboot_ptr);
|
||||||
timer_install();
|
timer_install();
|
||||||
keyboard_install();
|
keyboard_install();
|
||||||
/* Yes, yes, these are #define'd strings, consider this a nice test of kprintf */
|
/* Yes, yes, these are #define'd strings, consider this a nice test of kprintf */
|
||||||
settextcolor(12,0);
|
|
||||||
kprintf("[%s %s]\n", KERNEL_UNAME, KERNEL_VERSION_STRING);
|
|
||||||
settextcolor(1,0);
|
|
||||||
/* Multiboot Debug */
|
|
||||||
kprintf("Received the following MULTIBOOT data:\n");
|
|
||||||
settextcolor(7,0);
|
|
||||||
kprintf("Flags : 0x%x ", mboot_ptr->flags);
|
|
||||||
kprintf("Mem Lo: 0x%x ", mboot_ptr->mem_lower);
|
|
||||||
kprintf("Mem Hi: 0x%x ", mboot_ptr->mem_upper);
|
|
||||||
kprintf("Boot d: 0x%x\n", mboot_ptr->boot_device);
|
|
||||||
kprintf("cmdlin: 0x%x ", mboot_ptr->cmdline);
|
|
||||||
kprintf("Mods : 0x%x ", mboot_ptr->mods_count);
|
|
||||||
kprintf("Addr : 0x%x ", mboot_ptr->mods_addr);
|
|
||||||
kprintf("Syms : 0x%x\n", mboot_ptr->num);
|
|
||||||
kprintf("Syms : 0x%x ", mboot_ptr->size);
|
|
||||||
kprintf("Syms : 0x%x ", mboot_ptr->addr);
|
|
||||||
kprintf("Syms : 0x%x ", mboot_ptr->shndx);
|
|
||||||
kprintf("MMap : 0x%x\n", mboot_ptr->mmap_length);
|
|
||||||
kprintf("Addr : 0x%x ", mboot_ptr->mmap_addr);
|
|
||||||
kprintf("Drives: 0x%x ", mboot_ptr->drives_length);
|
|
||||||
kprintf("Addr : 0x%x ", mboot_ptr->drives_addr);
|
|
||||||
kprintf("Config: 0x%x\n", mboot_ptr->config_table);
|
|
||||||
kprintf("Loader: 0x%x ", mboot_ptr->boot_loader_name);
|
|
||||||
kprintf("APM : 0x%x ", mboot_ptr->apm_table);
|
|
||||||
kprintf("VBE Co: 0x%x ", mboot_ptr->vbe_control_info);
|
|
||||||
kprintf("VBE Mo: 0x%x\n", mboot_ptr->vbe_mode_info);
|
|
||||||
kprintf("VBE In: 0x%x ", mboot_ptr->vbe_mode);
|
|
||||||
kprintf("VBE se: 0x%x ", mboot_ptr->vbe_interface_seg);
|
|
||||||
kprintf("VBE of: 0x%x ", mboot_ptr->vbe_interface_off);
|
|
||||||
kprintf("VBE le: 0x%x\n", mboot_ptr->vbe_interface_len);
|
|
||||||
resettextcolor();
|
|
||||||
kprintf("(End multiboot raw data)\n");
|
|
||||||
kprintf("Started with: %s\n", (char *)mboot_ptr->cmdline);
|
|
||||||
kprintf("Booted from: %s\n", (char *)mboot_ptr->boot_loader_name);
|
|
||||||
|
|
||||||
kprintf("%dkB lower memory\n", mboot_ptr->mem_lower);
|
|
||||||
kprintf("%dkB higher memory ", mboot_ptr->mem_upper);
|
|
||||||
int mem_mb = mboot_ptr->mem_upper / 1024;
|
|
||||||
kprintf("(%dMB)\n", mem_mb);
|
|
||||||
|
|
||||||
|
|
||||||
settextcolor(7,0);
|
|
||||||
kprintf("Testing colors...\n");
|
|
||||||
resettextcolor();
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < 16; ++i) {
|
|
||||||
settextcolor(i,i);
|
|
||||||
putch(' ');
|
|
||||||
}
|
|
||||||
putch('\n');
|
|
||||||
resettextcolor();
|
resettextcolor();
|
||||||
|
|
||||||
settextcolor(9,0);
|
|
||||||
kprintf(" = Roadmap = \n");
|
|
||||||
kprintf("- Paging\n");
|
|
||||||
kprintf("- Heap\n");
|
|
||||||
kprintf("- VFS\n");
|
|
||||||
kprintf("- Initial ramdisk\n");
|
|
||||||
kprintf("- Task switching\n");
|
|
||||||
kprintf("- User mode execution\n");
|
|
||||||
kprintf("- EXT2\n");
|
|
||||||
resettextcolor();
|
|
||||||
|
|
||||||
kprintf("Kernel is finished booting. Press `q` to produce a page fault.\n");
|
|
||||||
|
|
||||||
//for (;;);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user