Separate kernel code from test code

Eventually I want the kernel to be loaded from the SD card as well, but
it still needs to separate from user programs.

At some point there should be a folder just for the BIOS, which should
read from the boot block of the SD card and start executing, and thats
it.
This commit is contained in:
Byron Lathi
2022-04-16 21:58:37 -05:00
parent 238a4b6f98
commit c6098f2d1f
26 changed files with 5 additions and 5 deletions

View File

@@ -0,0 +1,73 @@
#include <conio.h>
#include <string.h>
#include "fat.h"
#include "devices/sd_card.h"
uint8_t fat_buf[512];
static full_bpb_t bpb;
static uint32_t data_region_start;
void fat_print_pbp_info(ebpb_t* epbp){
cprintf("Bytes per sector: %d\n", epbp->bpb3.bpb2.bytes_per_sector);
cprintf("Sectors per cluster: %d\n", epbp->bpb3.bpb2.sectors_per_cluster);
cprintf("Reserved Sectors: %d\n", epbp->bpb3.bpb2.reserved_sectors);
cprintf("Fat Count: %d\n", epbp->bpb3.bpb2.fat_count);
cprintf("Max Dir Entries: %d\n", epbp->bpb3.bpb2.max_dir_entries);
cprintf("Total Sector Count: %d\n", epbp->bpb3.bpb2.total_sector_count);
cprintf("Media Descriptor: 0x%x\n", epbp->bpb3.bpb2.media_descriptor);
cprintf("Sectors per Fat: %d\n", epbp->bpb3.bpb2.sectors_per_fat);
cprintf("\n");
cprintf("Sectors per track: %d\n", epbp->bpb3.sectors_per_track);
cprintf("Head Count: %d\n", epbp->bpb3.head_count);
cprintf("Hidden Sector Count: %ld\n", epbp->bpb3.hidden_sector_count);
cprintf("Logical Sector Count: %ld\n", epbp->bpb3.logical_sector_count);
cprintf("Sectors per Fat: %ld\n", epbp->bpb3.sectors_per_fat);
cprintf("Extended Flags: 0x%x\n", epbp->bpb3.extended_flags);
cprintf("Version: %d\n", epbp->bpb3.version);
cprintf("Root Cluster: 0x%lx\n", epbp->bpb3.root_cluster);
cprintf("System Information: 0x%x\n", epbp->bpb3.system_information);
cprintf("Backup Boot Sector: 0x%x\n", epbp->bpb3.backup_boot_sector);
cprintf("\n");
cprintf("Drive Number: %d\n", epbp->drive_num);
cprintf("Extended Signature: 0x%x\n", epbp->extended_signature);
cprintf("Volume ID: 0x%lx\n", epbp->volume_id);
cprintf("Partition Label: %.11s\n", &epbp->partition_label);
cprintf("Partition Label: %.8s\n", &epbp->filesystem_type);
cprintf("\n");
}
void fat_init(){
sd_readblock(0, fat_buf);
memcpy(&bpb, &fat_buf[11], sizeof(ebpb_t));
sd_readblock(1, fat_buf);
sd_readblock(32, fat_buf);
data_region_start = bpb.reserved_sectors + bpb.fat_count*bpb.sectors_per_fat_32;
}
void fat_read(char* filename, void* buf) {
vfat_dentry_t* vfat_dentry;
dos_dentry_t* dos_dentry;
uint32_t cluster;
(void)filename; //just ignore filename
sd_readblock(data_region_start, buf);
vfat_dentry = (vfat_dentry_t*)buf;
while(vfat_dentry->sequence_number == 0xe5)
vfat_dentry++;
dos_dentry = (dos_dentry_t*)(vfat_dentry + 1);
cluster = ((uint32_t)dos_dentry->first_cluster_h << 16) + dos_dentry->first_cluster_l;
sd_readblock(data_region_start + (cluster - 2) * 8, buf);
}

111
sw/kernel/filesystem/fat.h Normal file
View File

@@ -0,0 +1,111 @@
#ifndef _FAT_H
#define _FAT_H
#include <stdint.h>
extern uint8_t fat_buf[];
typedef struct {
uint16_t bytes_per_sector;
uint8_t sectors_per_cluster;
uint16_t reserved_sectors;
uint8_t fat_count;
uint16_t max_dir_entries;
uint16_t total_sector_count;
uint8_t media_descriptor;
uint16_t sectors_per_fat;
} dos_2_bpb_t;
typedef struct {
dos_2_bpb_t bpb2;
uint16_t sectors_per_track;
uint16_t head_count;
uint32_t hidden_sector_count;
uint32_t logical_sector_count;
uint32_t sectors_per_fat;
uint16_t extended_flags;
uint16_t version;
uint32_t root_cluster;
uint16_t system_information;
uint16_t backup_boot_sector;
uint8_t reserved[12];
} dos_3_bpb_t;
typedef struct {
dos_3_bpb_t bpb3;
uint8_t drive_num;
uint8_t reserved;
uint8_t extended_signature;
uint32_t volume_id;
uint8_t partition_label[11];
uint8_t filesystem_type[8];
} ebpb_t;
typedef struct {
uint16_t bytes_per_sector;
uint8_t sectors_per_cluster;
uint16_t reserved_sectors;
uint8_t fat_count;
uint16_t max_dir_entries;
uint16_t total_sector_count;
uint8_t media_descriptor;
uint16_t sectors_per_fat_16;
uint16_t sectors_per_track;
uint16_t head_count;
uint32_t hidden_sector_count;
uint32_t logical_sector_count;
uint32_t sectors_per_fat_32;
uint16_t extended_flags;
uint16_t version;
uint32_t root_cluster;
uint16_t system_information;
uint16_t backup_boot_sector;
uint8_t reserved[12];
uint8_t drive_num;
uint8_t reserved2;
uint8_t extended_signature;
uint32_t volume_id;
uint8_t partition_label[11];
uint8_t filesystem_type[8];
} full_bpb_t;
typedef struct {
uint32_t sig;
uint8_t reserved[480];
uint32_t sig2;
uint32_t free_data_clusters;
uint32_t last_allocated_data_cluster;
uint32_t reserved2;
uint32_t sig3;
} fs_info_sector_t;
typedef struct {
uint8_t sequence_number;
uint16_t filename0[5];
uint8_t attributes;
uint8_t type;
uint8_t checksum;
uint16_t filename1[6];
uint16_t reserved;
uint16_t filename[2];
} vfat_dentry_t;
typedef struct {
uint8_t filename[8];
uint8_t extension[3];
uint8_t attributes;
uint8_t reserved;
uint8_t create_time_10ms;
uint32_t create_date;
uint16_t access_date;
uint16_t first_cluster_h;
uint32_t modify_cluster;
uint16_t first_cluster_l;
uint32_t file_size;
} dos_dentry_t;
void fat_print_pbp_info(ebpb_t* epbp);
void fat_init();
void fat_read(char* filename, void* buf);
#endif

View File

@@ -0,0 +1,28 @@
#include <conio.h>
#include "o65.h"
void o65_print_option(o65_opt_t* opt) {
int i;
cprintf("Option Length: %d\n", opt->olen);
cprintf("Option Type: %x ", opt->type);
switch (opt->type) {
case O65_OPT_FILENAME: cprintf("Filename\n"); break;
case O65_OPT_OS: cprintf("OS\n"); break;
case O65_OPT_ASSEMBLER: cprintf("Assembler\n"); break;
case O65_OPT_AUTHOR: cprintf("Author\n"); break;
case O65_OPT_DATE: cprintf("Creation Date\n"); break;
default: cprintf("Invalid\n"); break;
}
if (opt->type != O65_OPT_OS) {
for (i = 0; i < opt->olen - 2; i++) {
cprintf("%c", opt->data[i]);
}
} else {
cprintf("%x", opt->data[0]);
}
cprintf("\n\n");
}

View File

@@ -0,0 +1,65 @@
#ifndef _O65_H
#define _O65_H
#include <stdint.h>
#define O65_NON_C64 0x0001
#define O65_MAGIC_0 0x6f
#define O65_MAGIC_1 0x36
#define O65_MAGIC_2 0x35
#define O65_OPT_FILENAME 0
#define O65_OPT_OS 1
#define O65_OPT_ASSEMBLER 2
#define O65_OPT_AUTHOR 3
#define O65_OPT_DATE 4
#define O65_OS_OSA65 1
#define O65_OS_LUNIX 2
#define O65_OS_CC65 3
#define O65_OS_OPENCBM 4
#define O65_OS_SUPER6502 5
typedef union {
struct {
int cpu : 1;
int reloc : 1;
int size : 1;
int obj : 1;
int simple : 1;
int chain : 1;
int bsszero : 1;
int cpu2 : 4;
int align : 2;
};
uint16_t _mode;
} o65_mode_t;
typedef struct {
uint16_t c64_marker;
uint8_t magic[3];
uint8_t version;
o65_mode_t mode;
uint16_t tbase;
uint16_t tlen;
uint16_t dbase;
uint16_t dlen;
uint16_t bbase;
uint16_t blen;
uint16_t zbase;
uint16_t zlen;
uint16_t stack;
} o65_header_t;
typedef struct {
uint8_t olen;
uint8_t type;
uint8_t data[1]; //This is actually variable length
} o65_opt_t;
void o65_print_option(o65_opt_t* opt);
#endif