wad read, memalloc next
This commit is contained in:
parent
2355f99119
commit
8bb820aaaf
77 changed files with 594 additions and 118 deletions
BIN
src/boot/grub/eltor
Normal file
BIN
src/boot/grub/eltor
Normal file
Binary file not shown.
BIN
src/boot/kernel
BIN
src/boot/kernel
Binary file not shown.
|
|
@ -188,7 +188,7 @@ void W_AddFile (char *filename)
|
|||
//printf (" adding %s\n",filename);
|
||||
startlump = numlumps;
|
||||
|
||||
if (strcmpi (filename+strlen(filename)-3 , "wad" ) )
|
||||
if (strcmpi (filename+strlen(filename)-3 , "wad" ) /*== 69 hahahahahah funny number why arent you laughing*/)
|
||||
{
|
||||
// single lump file
|
||||
fileinfo = &singleinfo;
|
||||
|
|
|
|||
BIN
src/doomos.iso
BIN
src/doomos.iso
Binary file not shown.
|
|
@ -106,6 +106,7 @@ mkdir -p isodir/boot
|
|||
mkdir -p isodir/boot/grub
|
||||
# module doom.wad
|
||||
cp boot/kernel isodir/boot/kernel
|
||||
cp boot/grub/* isodir/boot/grub/
|
||||
cp doom.wad isodir
|
||||
cp bg.png isodir/boot
|
||||
cat > isodir/boot/grub/grub.cfg << EOF
|
||||
|
|
@ -114,7 +115,6 @@ set color_normal=white/black
|
|||
set color_highlight=black/white
|
||||
menuentry "DoomOS" {
|
||||
multiboot /boot/kernel
|
||||
module2 raw file=doom.wad
|
||||
}
|
||||
EOF
|
||||
grub-mkrescue -o doomos.iso isodir
|
||||
|
|
|
|||
BIN
src/isodir/boot/grub/eltor
Normal file
BIN
src/isodir/boot/grub/eltor
Normal file
Binary file not shown.
|
|
@ -3,5 +3,4 @@ set color_normal=white/black
|
|||
set color_highlight=black/white
|
||||
menuentry "DoomOS" {
|
||||
multiboot /boot/kernel
|
||||
module2 raw file=doom.wad
|
||||
}
|
||||
|
|
|
|||
6
src/isodir/boot/grub/menu.lst
Normal file
6
src/isodir/boot/grub/menu.lst
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
default 0
|
||||
|
||||
|
||||
title DoomOS
|
||||
kernel /boot/kernel
|
||||
module doom.wad
|
||||
BIN
src/isodir/boot/grub/stage2_eltorito
Normal file
BIN
src/isodir/boot/grub/stage2_eltorito
Normal file
Binary file not shown.
3
src/isodir/boot/grub/stage2_eltorito:Zone.Identifier
Normal file
3
src/isodir/boot/grub/stage2_eltorito:Zone.Identifier
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[ZoneTransfer]
|
||||
ZoneId=3
|
||||
HostUrl=about:internet
|
||||
Binary file not shown.
|
|
@ -3,15 +3,16 @@
|
|||
.set MEMINFO, 1 << 1
|
||||
.set FLAGS, ALIGN | MEMINFO
|
||||
.set MAGIC, 0x1BADB002
|
||||
.set ALIGN_MODULES, 0x00000001
|
||||
.set CHECKSUM, -(MAGIC + FLAGS)
|
||||
|
||||
# multiboot
|
||||
.section .multiboot
|
||||
.align 4
|
||||
.align 0x4
|
||||
.long MAGIC
|
||||
.long FLAGS
|
||||
.long CHECKSUM
|
||||
.long 0x36d76289
|
||||
# .long 0x36d76289
|
||||
|
||||
.section .bss
|
||||
.align 16
|
||||
|
|
@ -26,7 +27,6 @@ _start:
|
|||
movl $stack_top, %esp
|
||||
|
||||
pushl %ebx
|
||||
pushl %eax
|
||||
call main
|
||||
cli
|
||||
1:
|
||||
|
|
|
|||
32
src/kernel/bootNasm.s
Normal file
32
src/kernel/bootNasm.s
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
global entry
|
||||
section .__mbHeader
|
||||
|
||||
align 0x4
|
||||
MAGIC equ 0x1BADB002
|
||||
ALIGN_MODULES equ 0x00000001
|
||||
FLAGS equ 0
|
||||
SUM equ -(MAGIC + ALIGN_MODULES)
|
||||
|
||||
section .text
|
||||
align 4
|
||||
dd MAGIC
|
||||
dd ALIGN_MODULES
|
||||
dd FLAGS
|
||||
dd SUM
|
||||
|
||||
CSTACK_SIZE equ 80000 ; This is how big we want our stack to be
|
||||
|
||||
entry:
|
||||
mov esp, cstack + CSTACK_SIZE ; The ESP register holds the current position on the stack
|
||||
|
||||
extern main
|
||||
push ebx
|
||||
call main
|
||||
|
||||
jmp entry
|
||||
|
||||
section .bss:
|
||||
|
||||
align 16
|
||||
cstack:
|
||||
resb CSTACK_SIZE ; resb == "reserve bytes"
|
||||
|
|
@ -20,34 +20,21 @@
|
|||
|
||||
|
||||
typedef struct{
|
||||
char* ptr;
|
||||
char* _tmpfname;
|
||||
long int pos;
|
||||
int fd;
|
||||
int handle, pos, dataLen;
|
||||
char name[255];
|
||||
}FILE;
|
||||
|
||||
static int handleLen = 0;
|
||||
|
||||
|
||||
/*
|
||||
* Epic rambling
|
||||
*
|
||||
* so like the boot cd is ISO 9660
|
||||
* so we need to like
|
||||
* like like load the fs lamo lil c0akfd0 fl
|
||||
*
|
||||
* is that enough likes?
|
||||
*/
|
||||
static FILE files[255];
|
||||
|
||||
// Path Table Entry
|
||||
typedef struct {
|
||||
int dirIndentifierLen, extAttrRecordLen,
|
||||
locationOfExtent, dirNumOfPDir;
|
||||
char directoryIdentifier[256];
|
||||
|
||||
} PathTableEntry ;
|
||||
static unsigned int addrForWad;
|
||||
|
||||
|
||||
static char* reverse(int num) {
|
||||
|
||||
|
||||
/*static char* reverse(int num) {
|
||||
char full[100];
|
||||
int i = 0;
|
||||
while (num > 0) {
|
||||
|
|
@ -55,13 +42,31 @@ static char* reverse(int num) {
|
|||
num /= 10;
|
||||
}
|
||||
return full;
|
||||
}
|
||||
}*/
|
||||
|
||||
static void reverse(char str[], int length)
|
||||
{
|
||||
int start = 0;
|
||||
int end = length - 1;
|
||||
while (start < end) {
|
||||
char temp = str[start];
|
||||
str[start] = str[end];
|
||||
str[end] = temp;
|
||||
end--;
|
||||
start++;
|
||||
}
|
||||
}
|
||||
static uint32_t little_endian_to_uint32(uint8_t* bytes) {
|
||||
uint32_t value = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
value |= bytes[i] << (i * 8);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/*
|
||||
* Read from the Disk and
|
||||
* init the ISO 9660 FS
|
||||
*/
|
||||
|
||||
static void* mountBootDrive() {
|
||||
// Read volume descriptor
|
||||
uint16_t volumeDesc[2048];
|
||||
|
|
@ -79,33 +84,15 @@ static void* mountBootDrive() {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
int size;
|
||||
size += volumeDesc[132] | (volumeDesc[133] << 8) | (volumeDesc[134] << 16) | (volumeDesc[135] << 24);
|
||||
size = 420;
|
||||
|
||||
uint32_t lbaLoc;
|
||||
lbaLoc += volumeDesc[140] | (volumeDesc[141] << 8) | (volumeDesc[142] << 16) | (volumeDesc[142] << 24);
|
||||
char* f = reverse(size);
|
||||
char debugFull[512] = "Path table size: ";
|
||||
strcat(debugFull, f);
|
||||
t_out(debugFull);
|
||||
|
||||
// what ever, move on
|
||||
uint16_t pathTableSys[size];
|
||||
int c = read_cdrom(0x1F0, 0, lbaLoc, size / 2000, &pathTableSys);
|
||||
if (c < 0 || c > 0) {
|
||||
// panic!
|
||||
}
|
||||
*/
|
||||
// load entries
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void fs_SetWadFile(unsigned int memAddr) {
|
||||
addrForWad = memAddr;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
|
@ -144,36 +131,152 @@ typedef struct {
|
|||
uint8_t nameLen;
|
||||
} dirEntry;
|
||||
|
||||
#define SECTOR_SIZE 2048
|
||||
typedef struct {
|
||||
char name[32];
|
||||
uint8_t attributes;
|
||||
uint32_t size;
|
||||
uint32_t lba;
|
||||
} DirectoryRecord;
|
||||
|
||||
|
||||
|
||||
|
||||
static void* splitAtCharIndex(const char* string, const char split, int index, char* out) {
|
||||
int pos = 0, c = 0;
|
||||
char tmp[256];
|
||||
for (int i = 0; i < strlen(string); i++) {
|
||||
if (string[i] != split) {
|
||||
out[c++] = string[i];
|
||||
}
|
||||
else {
|
||||
if (pos == index) return;
|
||||
pos++;
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void* readFile(const char* file) {
|
||||
/*#define ROOTOFFSET 156
|
||||
// split
|
||||
|
||||
|
||||
|
||||
|
||||
// check file existence
|
||||
#define ROOTOFFSET 156
|
||||
// load PVD
|
||||
uint16_t pvd[2048];
|
||||
uint8_t pvd[2048];
|
||||
int c = read_cdrom(0x1F0, 0, 16, 1, &pvd);
|
||||
// get root directorywd
|
||||
dirEntry root;
|
||||
uint32_t rootLBA, rootExtentLength;
|
||||
rootLBA = (pvd[ROOTOFFSET + 2] & 0xFF) | ((pvd[ROOTOFFSET + 3] >> 8) & 0xFF) | ((pvd[ROOTOFFSET + 4] >> 16) & 0xFF) | ((pvd[ROOTOFFSET + 5] >> 24) & 0xFF);
|
||||
/*rootLBA |= pvd[ROOTOFFSET + 2] & 0xff;
|
||||
rootLBA |= (pvd[ROOTOFFSET + 3] << 8) & 0xFF;
|
||||
rootLBA |= (pvd[ROOTOFFSET + 4] << 16) & 0xFF;
|
||||
rootLBA |= (pvd[ROOTOFFSET + 5] << 24) & 0xFF;
|
||||
//rootLBA = (pvd[ROOTOFFSET + 2] & 0xFF) | ((pvd[ROOTOFFSET + 3] << 8) & 0xFF) | ((pvd[ROOTOFFSET + 4] << 16) & 0xFF) | ((pvd[ROOTOFFSET + 5] << 24) & 0xFF);
|
||||
//rootExtentLength = (pvd[ROOTOFFSET + 10] & 0xFF) | ((pvd[ROOTOFFSET + 11] << 8) & 0xFF) | ((pvd[ROOTOFFSET + 12] << 16) & 0xFF) | ((pvd[ROOTOFFSET + 13] << 24) & 0xFF);
|
||||
uint8_t LBAbytes[] = { pvd[ROOTOFFSET + 2], pvd[ROOTOFFSET + 3], pvd[ROOTOFFSET + 4], pvd[ROOTOFFSET + 5] };
|
||||
//uint8_t ExtentBytes[] = { pvd[ROOTOFFSET + 10], pvd[ROOTOFFSET + 11], pvd[ROOTOFFSET + 12], pvd[ROOTOFFSET + 13] };
|
||||
rootLBA = little_endian_to_uint32(LBAbytes);
|
||||
rootExtentLength = pvd[ROOTOFFSET];//little_endian_to_uint32(ExtentBytes);
|
||||
|
||||
uint32_t newof = (rootLBA);//+ ((rootExtentLength)));
|
||||
|
||||
uint8_t dirEntData[2048];
|
||||
c = read_cdrom(0x1F0, 0, newof, 1, &dirEntData);
|
||||
int currentpos = 000;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
||||
|
||||
uint8_t locOfExtent[] = { dirEntData[currentpos + 2], dirEntData[currentpos + 3], dirEntData[currentpos + 4], dirEntData[currentpos + 5] };
|
||||
uint32_t loc = little_endian_to_uint32(locOfExtent);
|
||||
|
||||
//rootExtentLength += pvd[ROOTOFFSET + 10] | (pvd[ROOTOFFSET + 11] << 8) | (pvd[ROOTOFFSET + 12] << 16) | (pvd[ROOTOFFSET + 13] << 24);
|
||||
// load
|
||||
uint16_t dirEntData[2048];
|
||||
c = read_cdrom(0x1F0, 0, rootLBA, 1, &dirEntData);
|
||||
char dirName[dirEntData[32]];
|
||||
for (int i = 0; i < dirEntData[32]; i++) {
|
||||
dirName[i] = dirEntData[33 + i];
|
||||
uint8_t lenBytes[] = { dirEntData[currentpos + 10], dirEntData[currentpos + 11], dirEntData[currentpos + 12], dirEntData[currentpos + 13] };
|
||||
uint32_t len = little_endian_to_uint32(lenBytes);
|
||||
|
||||
// Print
|
||||
uint8_t nameLength = dirEntData[currentpos + 32];
|
||||
char dirName[nameLength + 1];
|
||||
for (int i = 0; i < nameLength; i++) {
|
||||
dirName[i] = dirEntData[currentpos + 33 + i];
|
||||
if (dirName[i] == ';') {
|
||||
nameLength = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
dirName[nameLength] = '\0';
|
||||
|
||||
if (nameLength > 1) {
|
||||
char split[256];
|
||||
splitAtCharIndex(file, '/', 1, split);
|
||||
t_debug("GOT DIR: ");
|
||||
t_debug(dirName);
|
||||
//t_out(split);
|
||||
if (strcmp(dirName, split) == 0) {
|
||||
char debug[5];
|
||||
itoa(i, debug, 5, 10);
|
||||
//reverse(debug, 2);
|
||||
t_out(debug);
|
||||
|
||||
|
||||
|
||||
// we're done here. create a file struct and we're off.
|
||||
FILE tmp = {handleLen++, loc, len, dirName };
|
||||
files[handleLen] = tmp;
|
||||
return;
|
||||
}
|
||||
//t_out(dNum);
|
||||
t_out(dirName);*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Next
|
||||
currentpos += dirEntData[currentpos];
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Epic rambling
|
||||
*
|
||||
* so like the boot cd is ISO 9660
|
||||
* so we need to like
|
||||
* like like load the fs lamo lil c0akfd0 fl
|
||||
*
|
||||
* is that enough likes?
|
||||
*/
|
||||
/*
|
||||
// Path Table Entry
|
||||
typedef struct {
|
||||
int extentLoc, parentDirIndex;
|
||||
char id[256];
|
||||
|
||||
} PathTableEntry;
|
||||
|
||||
static void* readFile(const char* file) {
|
||||
#define ROOTOFFSET 140
|
||||
// Path table
|
||||
uint8_t pvd[2048];
|
||||
int c = read_cdrom(0x1F0, 0, 16, 1, &pvd);
|
||||
// get root directorywd
|
||||
uint32_t pathTableLBA;
|
||||
uint8_t LBAbytes[] = {pvd[ROOTOFFSET], pvd[ROOTOFFSET + 2], pvd[ROOTOFFSET + 3], pvd[ROOTOFFSET + 4] };
|
||||
pathTableLBA = little_endian_to_uint32(LBAbytes);
|
||||
char debug[5];
|
||||
itoa(pathTableLBA, debug, 5, 10);
|
||||
reverse(debug, 2);
|
||||
t_out(debug);
|
||||
// Alright lets read it
|
||||
uint8_t pathTable[2048];
|
||||
read_cdrom(0x1F0, 0, pathTableLBA, 1, &pathTable);
|
||||
char dirName[20];
|
||||
for (int i = 0; i < 19; i++) {
|
||||
dirName[i] = pathTable[8 + 10 + i];
|
||||
}
|
||||
t_out(dirName);
|
||||
}*/
|
||||
typedef struct stat {
|
||||
int st_size;
|
||||
}fileinfo;
|
||||
|
|
@ -181,7 +284,6 @@ typedef struct stat {
|
|||
static FILE* fopen(char* fileName, char* mode) {
|
||||
FILE* tmp;
|
||||
|
||||
// Load file from system
|
||||
|
||||
|
||||
return (void*)0;
|
||||
|
|
@ -219,15 +321,41 @@ static int mkdir(const char* path, int mode) {
|
|||
|
||||
static int FS_open(const char* path, ...) {
|
||||
t_out("FS_Open called");
|
||||
t_out(path);
|
||||
|
||||
return -1; // replace with handle
|
||||
readFile(path);
|
||||
return handleLen;
|
||||
}
|
||||
static int FS_close(int handle) {
|
||||
t_out("FS_Close called");
|
||||
return 1; // remove handle
|
||||
}
|
||||
static int read(int handle, void* buf, int count) {
|
||||
return 1;
|
||||
t_out("we reading bois");
|
||||
uint32_t loc = files[handleLen].pos;
|
||||
uint32_t size = files[handleLen].dataLen;
|
||||
|
||||
char debug[5];
|
||||
itoa(count, debug, 5, 10);
|
||||
//reverse(debug, 2);
|
||||
t_out(debug);
|
||||
|
||||
|
||||
|
||||
//asm("hlt");
|
||||
|
||||
// detemine buffer size
|
||||
|
||||
|
||||
int sec = 1;
|
||||
if (count > 2048) {
|
||||
sec = count / 2048;
|
||||
}
|
||||
|
||||
uint16_t bufAll[sec * 2048];
|
||||
|
||||
int c = read_cdrom(0x1F0, 0, loc, sec, &bufAll);
|
||||
|
||||
memcpy(buf, bufAll, count);
|
||||
|
||||
}
|
||||
static int write(int handle, void* buf, int count) {
|
||||
return 1;
|
||||
|
|
|
|||
BIN
src/kernel/isodir/boot/doom.wad
Normal file
BIN
src/kernel/isodir/boot/doom.wad
Normal file
Binary file not shown.
|
|
@ -1,7 +1,7 @@
|
|||
#include "disp/tty.c"
|
||||
#include "controller/file.h"
|
||||
#include "multiboot2.h"
|
||||
void main(unsigned long magic, unsigned long addr) {
|
||||
#include "multiboot.h"
|
||||
void main(multiboot_info_t* mbd) {
|
||||
t_init();
|
||||
// print out terminal stuff before we launch doom
|
||||
t_out("=======================");
|
||||
|
|
@ -16,48 +16,30 @@ void main(unsigned long magic, unsigned long addr) {
|
|||
t_out(" V0.1");
|
||||
t_out("=======================");
|
||||
|
||||
// read module
|
||||
struct multiboot_tag* tag;
|
||||
unsigned size;
|
||||
size = *(unsigned*)addr;
|
||||
for (tag = (struct multiboot_tag*)(addr + 8); tag->type != MULTIBOOT_TAG_TYPE_END; tag = (struct multiboot_tag*)((multiboot_uint8_t*)tag + ((tag->size + 7) & ~7))) {
|
||||
t_out("ran");
|
||||
switch (tag->type) {
|
||||
case MULTIBOOT_TAG_TYPE_MODULE:
|
||||
t_out("Module: ");
|
||||
t_out(((struct multiboot_tag_module*)tag)->cmdline);
|
||||
break;
|
||||
case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME:
|
||||
t_out("Bootloader: ");
|
||||
t_out(((struct multiboot_tag_string*)tag)->string);
|
||||
break;
|
||||
case MULTIBOOT_TAG_TYPE_END:
|
||||
t_out("MULTIBOOT_TAG_TYPE_END");
|
||||
break;
|
||||
case MULTIBOOT_TAG_TYPE_BOOTDEV:
|
||||
t_out("MULTIBOOT_TAG_TYPE_BOOTDEV");
|
||||
break;
|
||||
case MULTIBOOT_TAG_TYPE_CMDLINE:
|
||||
t_out("MULTIBOOT_TAG_TYPE_CMDLINE");
|
||||
break;
|
||||
case MULTIBOOT_TAG_TYPE_MMAP:
|
||||
t_out("MULTIBOOT_TAG_TYPE_MMAP");
|
||||
break;
|
||||
case MULTIBOOT_TAG_TYPE_FRAMEBUFFER:
|
||||
t_out("MULTIBOOT_TAG_TYPE_FRAMEBUFFER");
|
||||
break;
|
||||
|
||||
default:
|
||||
t_out("Idk: ");
|
||||
char t[200];
|
||||
itoa(tag->type, t, 200, 10);
|
||||
t_out(t);
|
||||
break;
|
||||
}
|
||||
}
|
||||
mountBootDrive();
|
||||
//t_out("Init FS, Test read WAD From boot medium...");
|
||||
//t_out("Test results: [not finished] ");
|
||||
|
||||
if (!(mbd->flags >> 6 & 0x1)) {
|
||||
t_out("Fatal Error: Invalid Memory Map.");
|
||||
asm("hlt");
|
||||
}
|
||||
// Load memory map
|
||||
for (int i = 0; i < mbd->mmap_length; i += sizeof(multiboot_memory_map_t)) {
|
||||
multiboot_memory_map_t* mmmt = (multiboot_memory_map_t*)(mbd->mmap_addr + i);
|
||||
// inform STDLIB where memory is
|
||||
if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE) {
|
||||
MEMORYLOC loc = { mmmt->addr_low, mmmt->addr_high, mmmt->len_low, mmmt->len_high, mmmt->type };
|
||||
addMemoryLocation(loc);
|
||||
}
|
||||
}
|
||||
processMemoryMap();
|
||||
char debugFull[20] = "Allocated blocks: ";
|
||||
char debug[5];
|
||||
itoa(blocloc, debug, 5, 10);
|
||||
reverse(debug, 2);
|
||||
strcat(debugFull, debug);
|
||||
t_out(debugFull);
|
||||
//
|
||||
t_out("DoomOS: Init complete.");
|
||||
t_out("DoomOS: Launching Doom...");
|
||||
t_out("=====================================");
|
||||
|
|
|
|||
276
src/kernel/multiboot.h
Normal file
276
src/kernel/multiboot.h
Normal file
|
|
@ -0,0 +1,276 @@
|
|||
/* multiboot.h - Multiboot header file. */
|
||||
/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
|
||||
* DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MULTIBOOT_HEADER
|
||||
#define MULTIBOOT_HEADER 1
|
||||
|
||||
/* How many bytes from the start of the file we search for the header. */
|
||||
#define MULTIBOOT_SEARCH 8192
|
||||
#define MULTIBOOT_HEADER_ALIGN 4
|
||||
|
||||
/* The magic field should contain this. */
|
||||
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
|
||||
|
||||
/* This should be in %eax. */
|
||||
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
|
||||
|
||||
/* Alignment of multiboot modules. */
|
||||
#define MULTIBOOT_MOD_ALIGN 0x00001000
|
||||
|
||||
/* Alignment of the multiboot info structure. */
|
||||
#define MULTIBOOT_INFO_ALIGN 0x00000004
|
||||
|
||||
/* Flags set in the ’flags’ member of the multiboot header. */
|
||||
|
||||
/* Align all boot modules on i386 page (4KB) boundaries. */
|
||||
#define MULTIBOOT_PAGE_ALIGN 0x00000001
|
||||
|
||||
/* Must pass memory information to OS. */
|
||||
#define MULTIBOOT_MEMORY_INFO 0x00000002
|
||||
|
||||
/* Must pass video information to OS. */
|
||||
#define MULTIBOOT_VIDEO_MODE 0x00000004
|
||||
|
||||
/* This flag indicates the use of the address fields in the header. */
|
||||
#define MULTIBOOT_AOUT_KLUDGE 0x00010000
|
||||
|
||||
/* Flags to be set in the ’flags’ member of the multiboot info structure. */
|
||||
|
||||
/* is there basic lower/upper memory information? */
|
||||
#define MULTIBOOT_INFO_MEMORY 0x00000001
|
||||
/* is there a boot device set? */
|
||||
#define MULTIBOOT_INFO_BOOTDEV 0x00000002
|
||||
/* is the command-line defined? */
|
||||
#define MULTIBOOT_INFO_CMDLINE 0x00000004
|
||||
/* are there modules to do something with? */
|
||||
#define MULTIBOOT_INFO_MODS 0x00000008
|
||||
|
||||
/* These next two are mutually exclusive */
|
||||
|
||||
/* is there a symbol table loaded? */
|
||||
#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
|
||||
/* is there an ELF section header table? */
|
||||
#define MULTIBOOT_INFO_ELF_SHDR 0X00000020
|
||||
|
||||
/* is there a full memory map? */
|
||||
#define MULTIBOOT_INFO_MEM_MAP 0x00000040
|
||||
|
||||
/* Is there drive info? */
|
||||
#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
|
||||
|
||||
/* Is there a config table? */
|
||||
#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
|
||||
|
||||
/* Is there a boot loader name? */
|
||||
#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
|
||||
|
||||
/* Is there a APM table? */
|
||||
#define MULTIBOOT_INFO_APM_TABLE 0x00000400
|
||||
|
||||
/* Is there video information? */
|
||||
#define MULTIBOOT_INFO_VBE_INFO 0x00000800
|
||||
#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000
|
||||
|
||||
#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;
|
||||
|
||||
struct multiboot_header
|
||||
{
|
||||
/* Must be MULTIBOOT_MAGIC - see above. */
|
||||
multiboot_uint32_t magic;
|
||||
|
||||
/* Feature flags. */
|
||||
multiboot_uint32_t flags;
|
||||
|
||||
/* The above fields plus this one must equal 0 mod 2^32. */
|
||||
multiboot_uint32_t 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;
|
||||
|
||||
/* 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;
|
||||
};
|
||||
|
||||
/* 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;
|
||||
};
|
||||
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;
|
||||
};
|
||||
typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
|
||||
|
||||
struct multiboot_info
|
||||
{
|
||||
/* Multiboot info version number */
|
||||
multiboot_uint32_t flags;
|
||||
|
||||
/* Available memory from BIOS */
|
||||
multiboot_uint32_t mem_lower;
|
||||
multiboot_uint32_t mem_upper;
|
||||
|
||||
/* "root" partition */
|
||||
multiboot_uint32_t boot_device;
|
||||
|
||||
/* Kernel command line */
|
||||
multiboot_uint32_t cmdline;
|
||||
|
||||
/* Boot-Module list */
|
||||
multiboot_uint32_t mods_count;
|
||||
multiboot_uint32_t mods_addr;
|
||||
|
||||
union
|
||||
{
|
||||
multiboot_aout_symbol_table_t aout_sym;
|
||||
multiboot_elf_section_header_table_t elf_sec;
|
||||
} u;
|
||||
|
||||
/* Memory Mapping buffer */
|
||||
multiboot_uint32_t mmap_length;
|
||||
multiboot_uint32_t mmap_addr;
|
||||
|
||||
/* Drive Info buffer */
|
||||
multiboot_uint32_t drives_length;
|
||||
multiboot_uint32_t drives_addr;
|
||||
|
||||
/* ROM configuration table */
|
||||
multiboot_uint32_t config_table;
|
||||
|
||||
/* Boot Loader Name */
|
||||
multiboot_uint32_t boot_loader_name;
|
||||
|
||||
/* APM table */
|
||||
multiboot_uint32_t 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;
|
||||
|
||||
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;
|
||||
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
|
||||
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
|
||||
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
|
||||
multiboot_uint8_t framebuffer_type;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
multiboot_uint32_t framebuffer_palette_addr;
|
||||
multiboot_uint16_t 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;
|
||||
};
|
||||
};
|
||||
};
|
||||
typedef struct multiboot_info multiboot_info_t;
|
||||
|
||||
struct multiboot_color
|
||||
{
|
||||
multiboot_uint8_t red;
|
||||
multiboot_uint8_t green;
|
||||
multiboot_uint8_t blue;
|
||||
};
|
||||
|
||||
struct multiboot_mmap_entry
|
||||
{
|
||||
multiboot_uint32_t size;
|
||||
multiboot_uint32_t addr_low;
|
||||
multiboot_uint32_t addr_high;
|
||||
multiboot_uint32_t len_low;
|
||||
multiboot_uint32_t len_high;
|
||||
#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;
|
||||
} __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;
|
||||
|
||||
/* Module command line */
|
||||
multiboot_uint32_t cmdline;
|
||||
|
||||
/* padding to take it to 16 bytes (must be zero) */
|
||||
multiboot_uint32_t 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;
|
||||
};
|
||||
|
||||
#endif /* ! ASM_FILE */
|
||||
|
||||
#endif /* ! MULTIBOOT_HEADER */
|
||||
|
|
@ -40,9 +40,58 @@ static int printf(char* str, ...) {
|
|||
|
||||
/*
|
||||
* memory (very sad)
|
||||
* this will be handled in the future
|
||||
*/
|
||||
|
||||
// When the kernel is given control, we find the size and location of memory
|
||||
|
||||
typedef struct {
|
||||
uint32_t addr_low, addr_high, length_low, length_high, size;
|
||||
int type;
|
||||
} MEMORYLOC;
|
||||
|
||||
static MEMORYLOC memorylocs[15];
|
||||
static int memPts = 0;
|
||||
|
||||
static void addMemoryLocation(MEMORYLOC location) {
|
||||
memorylocs[memPts++] = location;
|
||||
}
|
||||
|
||||
// allocate the memory
|
||||
|
||||
|
||||
typedef struct {
|
||||
#define MEMORY_FREE 0
|
||||
int used;
|
||||
|
||||
int adderess, size;
|
||||
|
||||
struct MEM_BLOCK* next;
|
||||
} MEM_BLOCK;
|
||||
|
||||
static MEM_BLOCK blocs[256];
|
||||
static int blocloc = 0;
|
||||
|
||||
static void processMemoryMap() {
|
||||
for (int i = 0; i < memPts; i++) {
|
||||
uint64_t size = memorylocs[i].length_high << 32 | memorylocs[i].length_low;
|
||||
uint64_t loc = memorylocs[i].addr_high << 32 | memorylocs[i].addr_low;
|
||||
int constant = 10; // some random constant
|
||||
|
||||
uint64_t offset = 0;
|
||||
for (int j = 0; i < size / constant; i++) {
|
||||
MEM_BLOCK tmp = { MEMORY_FREE, loc + offset, size / constant, 0};
|
||||
offset += loc + offset;
|
||||
if (blocloc > 0) {
|
||||
// We're not the first block, so we can set the last one to point to us
|
||||
blocs[blocloc - 1].next = &tmp;
|
||||
blocs[blocloc - 1].adderess = loc + offset;
|
||||
}
|
||||
blocs[blocloc++] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void* malloc(int size) {
|
||||
unsigned char* g;
|
||||
return &g;
|
||||
|
|
|
|||
|
|
@ -66,13 +66,14 @@ static int abs(int n) {
|
|||
|
||||
|
||||
static void exit(int code) {
|
||||
asm("hlt");
|
||||
// to do:
|
||||
|
||||
// 1. Disable graphics mode
|
||||
|
||||
// 2. print out error code
|
||||
|
||||
// 3. return control to OS
|
||||
// 3. panic
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
BIN
src/obj/boot.o
BIN
src/obj/boot.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
src/obj/hd.o
BIN
src/obj/hd.o
Binary file not shown.
BIN
src/obj/kernel.o
BIN
src/obj/kernel.o
Binary file not shown.
BIN
src/obj/tty.o
BIN
src/obj/tty.o
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue