reading path tables now, need to make kheap sooner or later
This commit is contained in:
@@ -1,36 +1,53 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
"file": "kernel/drivers/iso/iso.c",
|
||||||
"arguments": [
|
"arguments": [
|
||||||
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
"-c",
|
"-c",
|
||||||
|
"kernel/drivers/iso/iso.c",
|
||||||
|
"-o",
|
||||||
|
"obj/kernel/drivers/iso/iso.o",
|
||||||
"-ffreestanding",
|
"-ffreestanding",
|
||||||
"-O2",
|
"-O2",
|
||||||
"-Wall",
|
"-Wall",
|
||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Ikernel",
|
"-Ikernel"
|
||||||
"-o",
|
|
||||||
"obj/kernel/drivers/atapi/ata.o",
|
|
||||||
"kernel/drivers/atapi/ata.c"
|
|
||||||
],
|
],
|
||||||
"directory": "/home/slinky/source/RockOS",
|
"directory": "/home/slinky/source/RockOS",
|
||||||
"file": "/home/slinky/source/RockOS/kernel/drivers/atapi/ata.c",
|
"output": "obj/kernel/drivers/iso/iso.o"
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/drivers/atapi/ata.o"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"file": "kernel/kmain.c",
|
||||||
"arguments": [
|
"arguments": [
|
||||||
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
"-c",
|
"-c",
|
||||||
|
"kernel/kmain.c",
|
||||||
|
"-o",
|
||||||
|
"obj/kernel/kmain.o",
|
||||||
"-ffreestanding",
|
"-ffreestanding",
|
||||||
"-O2",
|
"-O2",
|
||||||
"-Wall",
|
"-Wall",
|
||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Ikernel",
|
"-Ikernel"
|
||||||
"-o",
|
|
||||||
"obj/kernel/kmain.o",
|
|
||||||
"kernel/kmain.c"
|
|
||||||
],
|
],
|
||||||
"directory": "/home/slinky/source/RockOS",
|
"directory": "/home/slinky/source/RockOS",
|
||||||
"file": "/home/slinky/source/RockOS/kernel/kmain.c",
|
"output": "obj/kernel/kmain.o"
|
||||||
"output": "/home/slinky/source/RockOS/obj/kernel/kmain.o"
|
},
|
||||||
|
{
|
||||||
|
"file": "kernel/drivers/pic/pic_stubs.S",
|
||||||
|
"arguments": [
|
||||||
|
"/home/slinky/opt/cross/bin/i686-elf-gcc",
|
||||||
|
"-c",
|
||||||
|
"kernel/drivers/pic/pic_stubs.S",
|
||||||
|
"-o",
|
||||||
|
"obj/kernel/drivers/pic/pic_stubs.o",
|
||||||
|
"-ffreestanding",
|
||||||
|
"-O2",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Ikernel"
|
||||||
|
],
|
||||||
|
"directory": "/home/slinky/source/RockOS",
|
||||||
|
"output": "obj/kernel/drivers/pic/pic_stubs.o"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -226,7 +226,7 @@ void scan_drives() {
|
|||||||
ident_device(IDE_SECONDARY_IO_BASE, IDE_DRIVE_MASTER, 0);
|
ident_device(IDE_SECONDARY_IO_BASE, IDE_DRIVE_MASTER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ide_device_t* get_device(uint8_t slot) {
|
ide_device_t* get_ide_device(uint8_t slot) {
|
||||||
if (slot > 3) return NULL;
|
if (slot > 3) return NULL;
|
||||||
return &ide_devices[slot];
|
return &ide_devices[slot];
|
||||||
}
|
}
|
||||||
@@ -237,3 +237,5 @@ int ide_read_blks(ide_device_t* dev, uint32_t lba, uint32_t sectors, void* buf)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ typedef struct __attribute__((packed)) {
|
|||||||
} ide_device_t;
|
} ide_device_t;
|
||||||
|
|
||||||
void scan_drives();
|
void scan_drives();
|
||||||
ide_device_t* get_device(uint8_t slot);
|
ide_device_t* get_ide_device(uint8_t slot);
|
||||||
int ide_read_blks(ide_device_t* dev, uint32_t lba, uint32_t sectors, void* buf);
|
int ide_read_blks(ide_device_t* dev, uint32_t lba, uint32_t sectors, void* buf);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,18 +7,21 @@
|
|||||||
|
|
||||||
uint8_t sector_buf[2048];
|
uint8_t sector_buf[2048];
|
||||||
void read_iso(ide_device_t* dev) {
|
void read_iso(ide_device_t* dev) {
|
||||||
kprintf("Reading ISO Filesystem from CDROM Disk\n");
|
int success = ide_read_blks(dev, 16, 1, sector_buf);
|
||||||
|
if (!success) {
|
||||||
ide_read_blks(dev, 16, 1, sector_buf);
|
kprintf("Failed to read PVD\n");
|
||||||
if (sector_buf[0] != 1) {
|
|
||||||
kprintf("Couldn't find PVD\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
iso_pvd_t pvd = *(iso_pvd_t*)sector_buf;
|
if (sector_buf[0] != 1) {
|
||||||
|
kprintf("Couldn't find PVD in sector 0x10\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
iso_pvd_t* pvd = (iso_pvd_t*)sector_buf;
|
||||||
|
|
||||||
char pvd_identifier[6];
|
char pvd_identifier[6];
|
||||||
memcpy(pvd.header.identifier, pvd_identifier, 5);
|
memcpy(pvd->header.identifier, pvd_identifier, 5);
|
||||||
pvd_identifier[5] = 0;
|
pvd_identifier[5] = 0;
|
||||||
|
|
||||||
if (strcmp(pvd_identifier, "CD001") > 0) {
|
if (strcmp(pvd_identifier, "CD001") > 0) {
|
||||||
@@ -26,15 +29,32 @@ void read_iso(ide_device_t* dev) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char system_identifier[33];
|
char volume_identifier[33];
|
||||||
memcpy(&pvd.sys_ident[0], system_identifier, 32);
|
memset((uint8_t*)volume_identifier, 0, 33);
|
||||||
system_identifier[32] = 0;
|
memcpy(&pvd->volume_ident[0], volume_identifier, 32);
|
||||||
if (strlen(system_identifier) > 0) {
|
|
||||||
kprintf("System Identifier: %s\n", system_identifier);
|
kprintf("Reading ISO Filesystem from CDROM Disk %s\n", volume_identifier);
|
||||||
|
|
||||||
|
uint32_t lba_path_table = pvd->path_table_l_loc;
|
||||||
|
uint32_t path_table_sz = pvd->path_table_sz_le;
|
||||||
|
uint32_t sectors = path_table_sz / 2048;
|
||||||
|
if (sectors % 2048 > 0) {
|
||||||
|
sectors++;
|
||||||
}
|
}
|
||||||
|
|
||||||
char volume_identifier[33];
|
uint8_t path_table_sec[2048 * sectors];
|
||||||
memcpy(&pvd.volume_ident[0], volume_identifier, 32);
|
memset(path_table_sec, 0, 2048);
|
||||||
volume_identifier[32] = 0;
|
success = ide_read_blks(dev, lba_path_table, 1, path_table_sec);
|
||||||
kprintf("Volume Identifier: %s\n", volume_identifier);
|
if (!success) {
|
||||||
|
kprintf("could not read path table at lba 0x%x\n", lba_path_table);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
kprintf("iterating path table\n");
|
||||||
|
iso_path_table_entry_t* path = (iso_path_table_entry_t*)path_table_sec;
|
||||||
|
while ((uint32_t)path - (uint32_t)path_table_sec < 2048) {
|
||||||
|
size_t entry_sz = sizeof(iso_path_table_entry_t) + (path->dir_ident_len - 1);
|
||||||
|
if (path->dir_ident_len % 2 > 0) entry_sz++;
|
||||||
|
path = (iso_path_table_entry_t*)((uint32_t)path + entry_sz);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,10 @@ typedef struct __attribute__((packed)) {
|
|||||||
uint8_t version;
|
uint8_t version;
|
||||||
} vd_header_t;
|
} vd_header_t;
|
||||||
|
|
||||||
|
typedef struct __attribute__((packed)) {
|
||||||
|
|
||||||
|
} iso_dec_datetime_t;
|
||||||
|
|
||||||
typedef struct __attribute__((packed)) {
|
typedef struct __attribute__((packed)) {
|
||||||
vd_header_t header;
|
vd_header_t header;
|
||||||
uint8_t unused;
|
uint8_t unused;
|
||||||
@@ -26,8 +30,36 @@ typedef struct __attribute__((packed)) {
|
|||||||
uint16_t logical_blk_sz_be;
|
uint16_t logical_blk_sz_be;
|
||||||
uint32_t path_table_sz_le;
|
uint32_t path_table_sz_le;
|
||||||
uint32_t path_table_sz_be;
|
uint32_t path_table_sz_be;
|
||||||
|
uint32_t path_table_l_loc;
|
||||||
|
uint32_t opt_path_table_l_loc;
|
||||||
|
uint32_t path_table_m_loc;
|
||||||
|
uint32_t opt_path_table_m_loc;
|
||||||
|
uint8_t root_dir_entry[34];
|
||||||
|
uint8_t vol_set_ident_strd[128];
|
||||||
|
uint8_t publisher_ident_stra[128];
|
||||||
|
uint8_t data_prep_ident_stra[128];
|
||||||
|
uint8_t app_ident_stra[128];
|
||||||
|
uint8_t copyright_ident_strd[37];
|
||||||
|
uint8_t abs_file_ident_strd[37];
|
||||||
|
uint8_t bib_file_ident_strd[37];
|
||||||
|
iso_dec_datetime_t vol_creation_datetime;
|
||||||
|
iso_dec_datetime_t vol_modif_datetime;
|
||||||
|
iso_dec_datetime_t vol_expr_datetime;
|
||||||
|
iso_dec_datetime_t vol_effective_datetime;
|
||||||
|
uint8_t file_struct_version;
|
||||||
|
uint8_t unused_3;
|
||||||
|
uint8_t app_reserved[512];
|
||||||
|
uint8_t reserved[653];
|
||||||
} iso_pvd_t;
|
} iso_pvd_t;
|
||||||
|
|
||||||
|
typedef struct __attribute__((packed)) {
|
||||||
|
uint8_t dir_ident_len;
|
||||||
|
uint8_t ext_attrib_len;
|
||||||
|
uint32_t location;
|
||||||
|
uint16_t parent_idx;
|
||||||
|
uint8_t dir_ident_start;
|
||||||
|
} iso_path_table_entry_t;
|
||||||
|
|
||||||
void read_iso(ide_device_t* dev);
|
void read_iso(ide_device_t* dev);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
#include "multiboot.h"
|
#include "multiboot.h"
|
||||||
|
#include "idt.h"
|
||||||
|
#include "elf.h"
|
||||||
|
|
||||||
#include <lib/print.h>
|
#include <lib/print.h>
|
||||||
#include <lib/stream.h>
|
#include <lib/stream.h>
|
||||||
|
#include <lib/memory.h>
|
||||||
#include <idt.h>
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "memory/mm.h"
|
#include "memory/mm.h"
|
||||||
|
|
||||||
#include "elf.h"
|
#include "drivers/iso/iso.h"
|
||||||
|
#include "drivers/ide/ide.h"
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
extern void init_idt();
|
extern void init_idt();
|
||||||
extern void init_gdt();
|
extern void init_gdt();
|
||||||
@@ -132,19 +135,18 @@ void kmain(uint32_t magic, multiboot_info* mbi) {
|
|||||||
init_pit();
|
init_pit();
|
||||||
kprintf("PIT initialized\n");
|
kprintf("PIT initialized\n");
|
||||||
|
|
||||||
// int result = init_ps2();
|
|
||||||
// if (result == -1) {
|
|
||||||
// kprintf("PS2 init failed\n");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// kprintf("PS2 initialized\n");
|
|
||||||
|
|
||||||
init_page_tables();
|
init_page_tables();
|
||||||
kprintf("Page tables initialized\n");
|
kprintf("Page tables initialized\n");
|
||||||
|
|
||||||
|
kheap_init();
|
||||||
|
kprintf("Allocated 4kb for kernel heap\n");
|
||||||
|
|
||||||
kprintf("scanning for drives\n");
|
kprintf("scanning for drives\n");
|
||||||
extern void scan_drives();
|
extern void scan_drives();
|
||||||
scan_drives();
|
scan_drives();
|
||||||
|
|
||||||
|
ide_device_t* boot_cd_rom = get_ide_device(0);
|
||||||
|
read_iso(boot_cd_rom);
|
||||||
|
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include "memory.h"
|
#include "lib/memory.h"
|
||||||
|
#include "memory/mm.h"
|
||||||
|
|
||||||
|
|
||||||
void memcpy(const void* src, void* dst, size_t sz) {
|
void memcpy(const void* src, void* dst, size_t sz) {
|
||||||
for (size_t i = 0; i < sz; i++) {
|
for (size_t i = 0; i < sz; i++) {
|
||||||
@@ -6,6 +8,12 @@ void memcpy(const void* src, void* dst, size_t sz) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void memset(const uint8_t* dst, uint8_t val, size_t sz) {
|
||||||
|
for (size_t i = 0; i < sz; i++) {
|
||||||
|
((uint8_t*)dst)[i] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int strcmp(const char* s1, const char* s2) {
|
int strcmp(const char* s1, const char* s2) {
|
||||||
while (*s1 && (*s1 == *s2)) {
|
while (*s1 && (*s1 == *s2)) {
|
||||||
s1++;
|
s1++;
|
||||||
@@ -22,3 +30,18 @@ int strlen(const char* str) {
|
|||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void* kernel_heap = (void*)0xE0000000;
|
||||||
|
static size_t kernel_heap_sz = 0;
|
||||||
|
|
||||||
|
void kheap_init() {
|
||||||
|
if (kernel_heap_sz == 0) {
|
||||||
|
void* frame = p_alloc_frame();
|
||||||
|
map_page((uint32_t)kernel_heap, (uint32_t)frame, PAGE_PRESENT | PAGE_WRITABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void* alloc(size_t sz) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,9 +5,13 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
void memcpy(const void* src, void* dst, size_t sz);
|
void memcpy(const void* src, void* dst, size_t sz);
|
||||||
void memset(const void* dst, uint8_t val, size_t sz);
|
void memset(const uint8_t* dst, uint8_t val, size_t sz);
|
||||||
|
|
||||||
int strcmp(const char *s1, const char *s2);
|
int strcmp(const char *s1, const char *s2);
|
||||||
int strlen(const char* str);
|
int strlen(const char* str);
|
||||||
|
|
||||||
|
void kheap_init();
|
||||||
|
void* alloc(size_t sz);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
#define PAGE_WRITABLE 0x2
|
#define PAGE_WRITABLE 0x2
|
||||||
#define PAGE_USER 0x4
|
#define PAGE_USER 0x4
|
||||||
|
|
||||||
|
#define PAGE_SIZE 4096
|
||||||
|
|
||||||
typedef struct __attribute__((packed)) {
|
typedef struct __attribute__((packed)) {
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
} mem_page_t;
|
} mem_page_t;
|
||||||
|
|||||||
Reference in New Issue
Block a user