diff options
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/ata.asm | 38 | ||||
-rw-r--r-- | src/kernel/ata.h | 23 | ||||
-rw-r--r-- | src/kernel/diskio.c | 49 | ||||
-rw-r--r-- | src/kernel/diskio.h | 57 | ||||
-rw-r--r-- | src/kernel/fat12.c | 58 | ||||
-rw-r--r-- | src/kernel/fat12.h | 48 | ||||
-rw-r--r-- | src/kernel/files.c | 115 | ||||
-rw-r--r-- | src/kernel/files.h | 70 | ||||
-rw-r--r-- | src/kernel/floppy.asm | 38 | ||||
-rw-r--r-- | src/kernel/floppy.h | 23 | ||||
-rw-r--r-- | src/kernel/gpt.c | 40 | ||||
-rw-r--r-- | src/kernel/gpt.h | 69 | ||||
-rw-r--r-- | src/kernel/ide.asm | 38 | ||||
-rw-r--r-- | src/kernel/ide.h | 23 | ||||
-rw-r--r-- | src/kernel/iso9660.c | 58 | ||||
-rw-r--r-- | src/kernel/iso9660.h | 96 | ||||
-rw-r--r-- | src/kernel/keyb.asm | 32 | ||||
-rw-r--r-- | src/kernel/keyb.c | 45 | ||||
-rw-r--r-- | src/kernel/keyb.h | 30 | ||||
-rw-r--r-- | src/kernel/link.ld | 9 | ||||
-rw-r--r-- | src/kernel/main.c | 470 | ||||
-rw-r--r-- | src/kernel/mem.c | 88 | ||||
-rw-r--r-- | src/kernel/mem.h | 47 | ||||
-rw-r--r-- | src/kernel/proc.c | 52 | ||||
-rw-r--r-- | src/kernel/proc.h | 36 | ||||
-rw-r--r-- | src/kernel/serial.asm | 107 | ||||
-rw-r--r-- | src/kernel/serial.h | 37 | ||||
-rw-r--r-- | src/kernel/stub.asm | 53 | ||||
-rw-r--r-- | src/kernel/vga.c | 146 | ||||
-rw-r--r-- | src/kernel/vga.h | 37 |
30 files changed, 0 insertions, 2032 deletions
diff --git a/src/kernel/ata.asm b/src/kernel/ata.asm deleted file mode 100644 index bbd1f47..0000000 --- a/src/kernel/ata.asm +++ /dev/null @@ -1,38 +0,0 @@ -;Copyright 2019 Benji Dial - -;Permission to use, copy, modify, and/or distribute this -;software for any purpose with or without fee is hereby -;granted, provided that the above copyright notice and this -;permission notice appear in all copies. - -;THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -;ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -;EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -;INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -;RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -;ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -;ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -;OF THIS SOFTWARE. - -global ata_read_sectors -global ata_write_sectors - -section .text -ata_read_sectors:;uint32_t ata_read_sectors(uint8_t number, uint32_t start, uint32_t count, void *buffer) - push ebp - mov ebp, esp - - xor eax, eax;TODO - - leave - ret - -ata_write_sectors:;uint32_t ata_write_sectors(uint8_t number, uint32_t start, uint32_t count, void *buffer) - push ebp - mov ebp, esp - - xor eax, eax;TODO - - leave - ret
\ No newline at end of file diff --git a/src/kernel/ata.h b/src/kernel/ata.h deleted file mode 100644 index 3a1f45e..0000000 --- a/src/kernel/ata.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include <stdint.h> - -uint32_t ata_read_sectors(uint8_t number, uint32_t start, uint32_t count, void *buffer); -uint32_t ata_write_sectors(uint8_t number, uint32_t start, uint32_t count, void *buffer);
\ No newline at end of file diff --git a/src/kernel/diskio.c b/src/kernel/diskio.c deleted file mode 100644 index 69f5964..0000000 --- a/src/kernel/diskio.c +++ /dev/null @@ -1,49 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include "diskio.h" -#include "floppy.h" -#include "ide.h" -#include "ata.h" - -read_sectors_t read_sectors_functions[] = { - &floppy_read_sectors, - &ide_read_sectors, - &ata_read_sectors -}; - -read_sectors_t get_read_sectors_function(uint8_t drive) { - return (drive >= 26) || !(drives[drive].flags & DISK_IN) ? 0 : - read_sectors_functions[drives[drive].interface]; -} - -write_sectors_t write_sectors_functions[] = { - &floppy_write_sectors, - &ide_write_sectors, - &ata_write_sectors -}; - -write_sectors_t get_write_sectors_function(uint8_t drive) { - return (drive >= 26) || !(drives[drive].flags & DISK_IN) ? 0 : - write_sectors_functions[drives[drive].interface]; -} - -void update_status(uint8_t drive) { - //TODO -} diff --git a/src/kernel/diskio.h b/src/kernel/diskio.h deleted file mode 100644 index 0e16423..0000000 --- a/src/kernel/diskio.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include <stdint.h> -#include <stdbool.h> - -#ifndef DISKIO_H -#define DISKIO_H - -enum interface { - FLOPPY, - IDE, - ATA -}; - -#define N_INTERFACES 3 - -typedef uint32_t (*const read_sectors_t)(uint8_t, uint32_t, uint32_t, void *); -typedef uint32_t (*const write_sectors_t)(uint8_t, uint32_t, uint32_t, void *); - -enum drive_flags { - SPUN = 0x01, - DISK_IN = 0x02, - PRESENT = 0x04 -}; - -struct drive_info { - uint8_t interface; - uint8_t number; - uint8_t flags; - uint8_t ssize;//log_2 of B - uint32_t length;//in kiB/2 -}; - -struct drive_info drives[26]; - -read_sectors_t get_read_sectors_function(uint8_t drive); -write_sectors_t get_write_sectors_function(uint8_t drive); -void update_status(uint8_t drive); - -#endif
\ No newline at end of file diff --git a/src/kernel/fat12.c b/src/kernel/fat12.c deleted file mode 100644 index ef09116..0000000 --- a/src/kernel/fat12.c +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include "iso9660.h" -#include "diskio.h" -#include "files.h" -#include "mem.h" - -bool iso_9660_parse_ph(uint8_t dn, uint8_t pn, uint32_t sector, uint8_t *buffer) { - uint32_t s = sector + 64; - read_sectors_t rsf = get_read_sectors_function(dn); - do { - rsf(drives[dn].number, s, 4, buffer); - if ((*buffer == 255) || (*(uint32_t *)&buffer[1] != 0x30304443) || - (buffer[5] != (uint8_t)'1')) - return false; - s += 4; - } while (*buffer != PRIM_VOLUME); - part_info[dn].partition_types[pn] = ISO_9660; - part_info[dn].partition_offsets[pn] = sector; - struct iso_9660_cache *cache = allocate_block(sizeof(struct iso_9660_cache), KERNEL); - struct iso_9660_primary_vd *as_vd = (struct iso_9660_primary_vd *)buffer; - part_info[dn].partition_cache[pn] = cache; - if ((cache->block_size = as_vd->block_size) & ~0x01ff) { - part_info[dn].partition_sizes[pn] = - (as_vd->block_size >> 9) * as_vd->size; - cache->path_table_sector = - (as_vd->block_size >> 9) * as_vd->path_table_block; - cache->optional_path_table_sector = - (as_vd->block_size >> 9) * as_vd->optional_path_table_block; - } - else { - part_info[dn].partition_sizes[pn] = - (as_vd->block_size * as_vd->size) >> 9; - cache->path_table_sector = - (as_vd->block_size * as_vd->path_table_block) >> 9; - cache->optional_path_table_sector = - (as_vd->block_size * as_vd->optional_path_table_block) >> 9; - } - cache->path_table_size = as_vd->path_table_size; - return true; -}
\ No newline at end of file diff --git a/src/kernel/fat12.h b/src/kernel/fat12.h deleted file mode 100644 index 250d877..0000000 --- a/src/kernel/fat12.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include <stdint.h> -#include <stdbool.h> - -#ifndef FAT12_H -#define FAT12_H - -struct bpb { - uint8_t jump[3]; - uint8_t oem[8]; - uint16_t bytes_per_sector; - uint8_t sectors_per_cluster; - uint16_t reserved_sectors; - uint8_t number_of_fats; - uint16_t root_size; - uint16_t short_sectors; - uint8_t media_type; - uint16_t sectors_per_fat; - uint16_t sectors_per_track; - uint16_t number_of_heads; - uint32_t hidden_sectors; - uint32_t long_sectors; -} __attribute__ ((__packed__)); - -struct fat12_cache { -}; - -bool fat12_parse_ph(uint8_t dn, uint8_t pn, uint32_t sector, uint8_t *buffer); - -#endif
\ No newline at end of file diff --git a/src/kernel/files.c b/src/kernel/files.c deleted file mode 100644 index 9747688..0000000 --- a/src/kernel/files.c +++ /dev/null @@ -1,115 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include "files.h" -#include "diskio.h" -#include "iso9660.h" -#include "mem.h" - -bool (*const parse_pts[N_PT_FORMATS])(uint8_t dn, uint8_t *buffer) = { - //&gpt_parse_pt, - //&mbr_parse_pt -}; - -bool (*const parse_phs[N_FS_FORMATS])(uint8_t dn, uint8_t pn, uint32_t sector, uint8_t *buffer) = { - &iso_9660_parse_ph -}; - -uint8_t working_drive; -uint8_t working_part; -uint8_t buffer[2048]; - -void set_working_drive(uint8_t name, uint8_t part) { - if ((name >= (uint8_t)'a') && (name <= (uint8_t)'z') && - (drives[name - (uint8_t)'a'].flags & PRESENT)) - working_drive = name - (uint8_t)'a'; - if (part_info[working_drive].format & ~DIRECT) - working_part = - (part >= (uint8_t)'0') && (name <= (uint8_t)'9') && - (part_info[working_drive].n_partitions > part) ? - (part & 0x0f) : 0; -} - -uint16_t open_file(uint8_t *name) { - return 0;//TODO -} - -void close_file(uint16_t handle) { - file_table[handle].first_sector = 0; -} - -uint32_t read_file(uint16_t handle, uint32_t length, void *buffer) { - //TODO -} - -void write_file(uint16_t handle, uint32_t length, void *buffer) { - //TODO -} - -void seek_file(uint16_t handle, int32_t by) { - //TODO -} - -uint32_t get_size(uint16_t handle) { - return 0;//TODO -} - -uint32_t read_line_file(uint16_t handle, uint32_t max, void *buffer) { - uint8_t *i = (uint8_t *)buffer; - while (i < (uint8_t *)buffer + max) { - if (!read_file(handle, 1, i) || (*i == (uint8_t)'\n')) { - *i = 0; - return i - (uint8_t *)buffer; - } - ++i; - } -} - -void detect_disk_parts(uint8_t drive) { - if ((drive >= (uint8_t)'a') && (drive <= (uint8_t)'z')) { - uint8_t dn = (drive & 0x1f) - 1; - for (uint8_t i = 0; i < part_info[dn].n_partitions; ++i) - if (part_info[dn].partition_cache[i]) - deallocate_block(part_info[dn].partition_cache[i]); - update_status(dn); - if (drives[dn].flags & (PRESENT | DISK_IN)) { - /*ISO 9660 often comes with a dummy MBR*/ - if (iso_9660_parse_ph(dn, 0, 0, buffer)) { - part_info[dn].format = DIRECT; - part_info[dn].n_partitions = 1; - return; - } - for (uint8_t ptt = 0; ptt < N_PT_FORMATS; ++ptt) - if (parse_pts[ptt](dn, buffer)) - return; - for (uint8_t fst = 0; fst < N_FS_FORMATS; ++fst) - if (parse_phs[fst](dn, 0, 0, buffer)) { - part_info[dn].format = DIRECT; - part_info[dn].n_partitions = 1; - return; - } - part_info[dn].format = UNKNOWN; - part_info[dn].n_partitions = 0; - } - else { - part_info[dn].format = NOT_PRESENT; - part_info[dn].n_partitions = 0; - } - } -}
\ No newline at end of file diff --git a/src/kernel/files.h b/src/kernel/files.h deleted file mode 100644 index 0a11a71..0000000 --- a/src/kernel/files.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include <stdint.h> - -#ifndef FILES_H -#define FILES_H - -struct file_info { - uint16_t first_sector; - uint16_t current_sector; - uint8_t *io_buffer; - uint32_t position; -}; - -enum fs_format { - ISO_9660 = 0 -}; - -#define N_FS_FORMATS 1 - -enum pt_format { - NOT_PRESENT = 0, - UNKNOWN = 1, - DIRECT = 2, - - //GPT = 3, - //MBR = 4, -}; - -#define N_PT_FORMATS 0 - -struct drive_parts { - uint8_t format; - uint8_t n_partitions; - uint8_t partition_types[10]; - uint32_t partition_offsets[10]; - uint32_t partition_sizes[10]; - void *partition_cache[10]; -}; - -struct drive_parts part_info[26]; -struct file_info file_table[65536]; -void set_working_drive(uint8_t drive, uint8_t part); -uint16_t open_file(uint8_t *name); -void close_file(uint16_t handle); -uint32_t read_file(uint16_t handle, uint32_t length, void *buffer); -void write_file(uint16_t handle, uint32_t length, void *buffer); -void seek_file(uint16_t handle, int32_t by); -uint32_t get_size(uint16_t handle); -uint32_t read_line_file(uint16_t handle, uint32_t max, void *buffer); -void detect_disk_parts(uint8_t drive); - -#endif
\ No newline at end of file diff --git a/src/kernel/floppy.asm b/src/kernel/floppy.asm deleted file mode 100644 index ffe6c99..0000000 --- a/src/kernel/floppy.asm +++ /dev/null @@ -1,38 +0,0 @@ -;Copyright 2019 Benji Dial - -;Permission to use, copy, modify, and/or distribute this -;software for any purpose with or without fee is hereby -;granted, provided that the above copyright notice and this -;permission notice appear in all copies. - -;THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -;ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -;EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -;INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -;RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -;ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -;ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -;OF THIS SOFTWARE. - -global floppy_read_sectors -global floppy_write_sectors - -section .text -floppy_read_sectors:;uint32_t floppy_read_sectors(uint8_t number, uint32_t start, uint32_t count, void *buffer) - push ebp - mov ebp, esp - - xor eax, eax;TODO - - leave - ret - -floppy_write_sectors:;uint32_t floppy_write_sectors(uint8_t number, uint32_t start, uint32_t count, void *buffer) - push ebp - mov ebp, esp - - xor eax, eax;TODO - - leave - ret
\ No newline at end of file diff --git a/src/kernel/floppy.h b/src/kernel/floppy.h deleted file mode 100644 index 9af534e..0000000 --- a/src/kernel/floppy.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include <stdint.h> - -uint32_t floppy_read_sectors(uint8_t number, uint32_t start, uint32_t count, void *buffer); -uint32_t floppy_write_sectors(uint8_t number, uint32_t start, uint32_t count, void *buffer);
\ No newline at end of file diff --git a/src/kernel/gpt.c b/src/kernel/gpt.c deleted file mode 100644 index 39add3a..0000000 --- a/src/kernel/gpt.c +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include "gpt.h" -#include "files.h" -#include "diskio.h" - -bool gpt_parse_pt(uint8_t dn, uint8_t *buffer) { - struct gpt_header *head = (struct gpt_header *)&buffer[0x200]; - struct drive_parts *pi = part_info + dn; - pi->format = GPT; - pi->n_partitions = (head->n_parts & 0xffffff00 ? 0x000000ff : head->n_parts); - uint32_t part_entry_size = head->part_size; - struct gpt_entry *as_entries = (struct gpt_entry *)buffer; - for (uint8_t i = 0; i < pi->n_partitions; ++i) { - if (!(i % 16)) - read_sectors(dn, 2 + i / 4, 4, buffer); - pi->partition_sizes[i] = ((as_entries[i % 16].last_sector + 1) >> 1) - (pi->partition_offsets[i] = ((as_entries[i % 16].sector) >> 1)); - switch (as_entries[i % 16].id.le) { - //TODO - } - } - return true; -}
\ No newline at end of file diff --git a/src/kernel/gpt.h b/src/kernel/gpt.h deleted file mode 100644 index fb872df..0000000 --- a/src/kernel/gpt.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include <stdint.h> -#include <stdbool.h> - -#ifndef GPT_H -#define GPT_H - -struct uuid { - uint64_t le; - uint64_t be; -} __attribute__ ((__packed__)); - -struct gpt_header { - uint8_t signature[8]; - uint32_t version; - uint32_t header_length; - uint32_t check;//crc - uint32_t spacing; - uint64_t head_sector; - uint64_t head_backup_sector; - uint64_t data_start; - uint64_t data_last; - struct uuid id; - uint64_t pt_sector; - uint32_t n_parts; - uint32_t part_size; - uint32_t pt_check; -} __attribute__ ((__packed__)); - -struct gpt_entry { - struct uuid type; - struct uuid id; - uint64_t sector; - uint64_t last_sector; - uint64_t flags; - uint8_t name[72]; -} __attribute__ ((__packed__)); - -enum type_le { - GPT_ESP_LE = 0xc12a7328f81f11d2, - GPT_BOOT_LE = 0x2168614864496e6f -}; - -enum type_be { - GPT_ESP_BE = 0x3bc93ec9a0004bba, - GPT_BOOT_BE = 0x4946456465654e74 -}; - -bool gpt_parse_pt(uint8_t dn, uint8_t *buffer); - -#endif
\ No newline at end of file diff --git a/src/kernel/ide.asm b/src/kernel/ide.asm deleted file mode 100644 index ccac986..0000000 --- a/src/kernel/ide.asm +++ /dev/null @@ -1,38 +0,0 @@ -;Copyright 2019 Benji Dial - -;Permission to use, copy, modify, and/or distribute this -;software for any purpose with or without fee is hereby -;granted, provided that the above copyright notice and this -;permission notice appear in all copies. - -;THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -;ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -;EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -;INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -;RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -;ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -;ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -;OF THIS SOFTWARE. - -global ide_read_sectors -global ide_write_sectors - -section .text -ide_read_sectors:;uint32_t ide_read_sectors(uint8_t number, uint32_t start, uint32_t count, void *buffer) - push ebp - mov ebp, esp - - xor eax, eax;TODO - - leave - ret - -ide_write_sectors:;uint32_t ide_write_sectors(uint8_t number, uint32_t start, uint32_t count, void *buffer) - push ebp - mov ebp, esp - - xor eax, eax;TODO - - leave - ret
\ No newline at end of file diff --git a/src/kernel/ide.h b/src/kernel/ide.h deleted file mode 100644 index 4592253..0000000 --- a/src/kernel/ide.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include <stdint.h> - -uint32_t ide_read_sectors(uint8_t number, uint32_t start, uint32_t count, void *buffer); -uint32_t ide_write_sectors(uint8_t number, uint32_t start, uint32_t count, void *buffer);
\ No newline at end of file diff --git a/src/kernel/iso9660.c b/src/kernel/iso9660.c deleted file mode 100644 index ef09116..0000000 --- a/src/kernel/iso9660.c +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include "iso9660.h" -#include "diskio.h" -#include "files.h" -#include "mem.h" - -bool iso_9660_parse_ph(uint8_t dn, uint8_t pn, uint32_t sector, uint8_t *buffer) { - uint32_t s = sector + 64; - read_sectors_t rsf = get_read_sectors_function(dn); - do { - rsf(drives[dn].number, s, 4, buffer); - if ((*buffer == 255) || (*(uint32_t *)&buffer[1] != 0x30304443) || - (buffer[5] != (uint8_t)'1')) - return false; - s += 4; - } while (*buffer != PRIM_VOLUME); - part_info[dn].partition_types[pn] = ISO_9660; - part_info[dn].partition_offsets[pn] = sector; - struct iso_9660_cache *cache = allocate_block(sizeof(struct iso_9660_cache), KERNEL); - struct iso_9660_primary_vd *as_vd = (struct iso_9660_primary_vd *)buffer; - part_info[dn].partition_cache[pn] = cache; - if ((cache->block_size = as_vd->block_size) & ~0x01ff) { - part_info[dn].partition_sizes[pn] = - (as_vd->block_size >> 9) * as_vd->size; - cache->path_table_sector = - (as_vd->block_size >> 9) * as_vd->path_table_block; - cache->optional_path_table_sector = - (as_vd->block_size >> 9) * as_vd->optional_path_table_block; - } - else { - part_info[dn].partition_sizes[pn] = - (as_vd->block_size * as_vd->size) >> 9; - cache->path_table_sector = - (as_vd->block_size * as_vd->path_table_block) >> 9; - cache->optional_path_table_sector = - (as_vd->block_size * as_vd->optional_path_table_block) >> 9; - } - cache->path_table_size = as_vd->path_table_size; - return true; -}
\ No newline at end of file diff --git a/src/kernel/iso9660.h b/src/kernel/iso9660.h deleted file mode 100644 index 271e5e0..0000000 --- a/src/kernel/iso9660.h +++ /dev/null @@ -1,96 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include <stdint.h> -#include <stdbool.h> - -#ifndef ISO9660_H -#define ISO9660_H - -enum iso_9660_vd_type { - BOOT_RECORD = 0, - PRIM_VOLUME = 1, - SUPP_VOLUME = 2, - PARTITION = 3 -}; - -struct iso_9660_timecode { - uint8_t year[4]; - uint8_t month[2]; - uint8_t day[2]; - uint8_t hour[2]; - uint8_t minute[2]; - uint8_t second[2]; - uint8_t centisecond[2]; - uint8_t tzone;//0 = -12, 100 = +13 -} __attribute__ ((__packed__)); - -struct iso_9660_directory { - uint8_t filler[34];//TODO -} __attribute__ ((__packed__)); - -struct iso_9660_primary_vd { - uint8_t type; - uint8_t id[5]; - uint8_t version; - uint8_t spacing; - uint8_t system_id[32]; - uint8_t volume_id[32]; - uint64_t spacing2; - uint32_t size;//in blocks - uint32_t size_be; - uint64_t spacing3[4]; - uint16_t set_size; - uint16_t set_size_be; - uint16_t set_index; - uint16_t set_index_be; - uint16_t block_size; - uint16_t block_size_be; - uint32_t path_table_size; - uint32_t path_table_size_be; - uint32_t path_table_block; - uint32_t optional_path_table_block; - uint32_t path_table_block_be; - uint32_t optional_path_table_block_be; - struct iso_9660_directory root_directory; - uint8_t set_name[128]; - uint8_t publisher[128]; - uint8_t data_preparer[128]; - uint8_t application[128]; - uint8_t copyright_file[38]; - uint8_t abstract_file[36]; - uint8_t bibliography_file[37]; - struct iso_9660_timecode created; - struct iso_9660_timecode modified; - struct iso_9660_timecode expires; - struct iso_9660_timecode effective; - uint8_t directory_format_version; -} __attribute__ ((__packed__)); - -struct iso_9660_cache { - uint16_t block_size; - struct iso_9660_directory root_directory; - uint32_t path_table_size; - uint32_t path_table_sector; - uint32_t optional_path_table_sector; -}; - -bool iso_9660_parse_ph(uint8_t dn, uint8_t pn, uint32_t sector, uint8_t *buffer); - -#endif
\ No newline at end of file diff --git a/src/kernel/keyb.asm b/src/kernel/keyb.asm deleted file mode 100644 index ba9fc87..0000000 --- a/src/kernel/keyb.asm +++ /dev/null @@ -1,32 +0,0 @@ -;Copyright 2019 Benji Dial - -;Permission to use, copy, modify, and/or distribute this -;software for any purpose with or without fee is hereby -;granted, provided that the above copyright notice and this -;permission notice appear in all copies. - -;THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -;ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -;EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -;INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -;RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -;ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -;ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -;OF THIS SOFTWARE. - -global get_key -global get_char -global get_line - -section .text -get_key:;uint16_t get_key(void) - push ebp - mov ebp, esp - - xor eax, eax - - ;TODO: return in ax - - leave - ret
\ No newline at end of file diff --git a/src/kernel/keyb.c b/src/kernel/keyb.c deleted file mode 100644 index 2c87422..0000000 --- a/src/kernel/keyb.c +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include "serial.h" -#include "vga.h" - -uint8_t get_char(bool echo) { - uint8_t ch = 0; - do - if (poll_port(COM2)) - ch = read_byte(COM2); - else - ;//TODO: get from get_key - while (!ch); - if (echo) - put_char(ch); - return ch; -} - -uint32_t get_line(uint32_t max, uint8_t *buffer, bool echo) { - uint8_t *i = (uint8_t *)buffer; - while (i < (uint8_t *)buffer + max) { - if ((*i = get_char(echo)) == (uint8_t)'\n') { - *i = 0; - return i - (uint8_t *)buffer; - } - ++i; - } -}
\ No newline at end of file diff --git a/src/kernel/keyb.h b/src/kernel/keyb.h deleted file mode 100644 index d4deba7..0000000 --- a/src/kernel/keyb.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include <stdint.h> -#include <stdbool.h> - -#ifndef KEYB_H -#define KEYB_H - -uint16_t get_key(void); -uint8_t get_char(bool echo); -uint32_t get_line(uint32_t max, uint8_t *buffer, bool echo); - -#endif
\ No newline at end of file diff --git a/src/kernel/link.ld b/src/kernel/link.ld deleted file mode 100644 index d0b7f46..0000000 --- a/src/kernel/link.ld +++ /dev/null @@ -1,9 +0,0 @@ -ENTRY(_start) -SECTIONS { - . = 0x01000000; - .mb_header : ALIGN(8) { *(.mb_header) } - .text : ALIGN(512) { *(.text) } - .rodata : ALIGN(512) { *(.rodata) } - .data : ALIGN(512) { *(.data) } - .bss : ALIGN(512) { *(.bss) } -}
\ No newline at end of file diff --git a/src/kernel/main.c b/src/kernel/main.c deleted file mode 100644 index 3377a76..0000000 --- a/src/kernel/main.c +++ /dev/null @@ -1,470 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include "vga.h" -#include "files.h" -#include "mem.h" -#include "proc.h" -#include <stdbool.h> - -enum tag_type { - BOOT_COMMAND = 0x00000001, - LOADER_NAME = 0x00000002, - BOOT_MODULE = 0x00000003, - MEMORY_INFO = 0x00000004, - BOOT_DEVICE = 0x00000005, - MEMORY_MAP = 0x00000006, - VBE_INFO = 0x00000007, - FBUF_INFO = 0x00000008, - ELF_SYMBOLS = 0x00000009, - APM_TABLE = 0x0000000a, - EFI_I386_TABLE = 0x0000000b, - EFI_AMD64_TABLE = 0x0000000c, - SMBIOS_TABLE = 0x0000000d, - RSDP_ACPI1 = 0x0000000e, - RSDP_ACPI2 = 0x0000000f, - NETWORK_INFO = 0x00000010, - EFI_MEMORY_MAP = 0x00000011, - EFI_SERVICES = 0x00000012, - EFI_I386_HANDLE = 0x00000013, - EFI_AMD64_HANDLE = 0x00000014, - IMAGE_BASE_ADDR = 0x00000015 -}; - -struct tag_start { - uint32_t type; - uint32_t size; -} __attribute__ ((__packed__)); - -struct boot_device_tag { - uint32_t bios_device; - uint32_t partition; - uint32_t subpartition; -} __attribute__ ((__packed__)); - -enum mem_type { - AVAILABLE = 1, - HARDWARET = 2, - ACPI = 3, - PRESERVE = 4, - DEFECTIVE = 5 -}; - -struct mmap_tag_entry { - uint64_t base; - uint64_t length; - uint32_t type; -} __attribute__ ((__packed__)); - -struct vbe_tag { - uint16_t mode; - uint16_t v2_segment; - uint16_t v2_offset; - uint16_t v2_length; - uint8_t control_info[512]; - uint8_t mode_info[256]; -} __attribute__ ((__packed__)); - -enum color_types { - PALETTE = 0x00, - RGB = 0x01, - TEXT = 0x02 -}; - -struct fbuf_tag { - uint32_t address_low; - uint32_t address_high; - uint32_t pitch; - uint32_t width; - uint32_t height; - uint8_t bpp; - uint8_t color_type; - uint8_t padding; -} __attribute__ ((__packed__)); - -struct fbuf_palette_entry { - uint8_t red; - uint8_t green; - uint8_t blue; -} __attribute__ ((__packed__)); - -struct fbuf_rgb_info { - uint8_t red_pos; - uint8_t red_mask; - uint8_t green_pos; - uint8_t green_mask; - uint8_t blue_pos; - uint8_t blue_mask; -} __attribute__ ((__packed__)); - -struct elf_tag { - uint16_t count; - uint16_t size; - uint16_t shndx; - uint16_t padding; -} __attribute__ ((__packed__)); - -struct module_tag { - uint32_t start; - uint32_t end; -} __attribute__ ((__packed__)); - -struct smbios_tag { - uint8_t major_version; - uint8_t minor_version; - uint16_t padding[3]; -} __attribute__ ((__packed__)); - -struct apm_table { - uint16_t version; - uint16_t cs_32; - uint32_t ip_32; - uint16_t cs_16; - uint16_t ds_16; - uint16_t flags; - uint16_t cs_32_length; - uint16_t cs_16_length; - uint16_t ds_16_lenth; -} __attribute__ ((__packed__)); - -struct boot_device_tag boot_device; -bool have_boot_device = false; -bool have_mmap = false; -uint32_t text_base; -bool have_text_base; - -enum error_codes { - NO_BOOT_DEVICE = 0x00000000, - NO_MMAP = 0x00000001, - INSUFF_MEMORY = 0x00000002, - MMAP_TOO_SMALL = 0x00000003, - MISSING_RC = 0x00000004, - BAD_RC_LINE = 0x00000005, - BAD_MMAP = 0x00000006 -}; - -struct tag_start *tag_pointer; - -uint32_t main(void) { - put_sz("Multiboot info:"); - while (tag_pointer->type) { - put_sz("\n Tag type 0x"); - put_32_hex(tag_pointer->type); - put_sz(" with size 0x"); - put_32_hex(tag_pointer->size); - switch (tag_pointer->type) { - - case BOOT_COMMAND: - put_sz(": boot arguments\n "); - put_sz(*(uint8_t *)(tag_pointer + 1) ? - (uint8_t *)(tag_pointer + 1) : (uint8_t *)"No arguments"); - break; - - case LOADER_NAME: - put_sz(": bootloader name\n "); - put_sz((uint8_t *)(tag_pointer + 1)); - break; - - case BOOT_MODULE: - put_sz(": boot module\n Loaded at: 0x"); - struct module_tag *module = (struct module_tag *)(tag_pointer + 1); - put_32_hex(module->start); - put_sz(" - "); - put_32_hex(module->end - 1); - if (*(uint8_t *)(module + 1)) { - put_sz("\n Argument: "); - put_sz((uint8_t *)(module + 1)); - } - break; - - case MEMORY_INFO: - put_sz(": memory size\n Lower memory: 0x"); - put_32_hex((tag_pointer + 1)->type); - put_sz("\n Upper memory: 0x"); - put_32_hex((tag_pointer + 1)->size); - break; - - case BOOT_DEVICE: - boot_device = *(struct boot_device_tag *)(tag_pointer + 1); - have_boot_device = true; - put_sz(": boot device\n BIOS code: "); - put_32_hex(boot_device.bios_device); - if (boot_device.partition != 0xffffffff) { - put_sz("\n Partition number: "); - put_32_hex(boot_device.partition); - if (boot_device.subpartition != 0xffffffff) { - put_sz("\n Subpartition number: "); - put_32_hex(boot_device.subpartition); - } - else - put_sz("\n No subpartition"); - } - else - put_sz("\n No partition"); - break; - - case MEMORY_MAP: { - mmap_start = (struct mmap_entry *)0; - uint32_t size = *(uint32_t *)(tag_pointer + 1); - struct mmap_tag_entry *tag = (struct mmap_tag_entry *)(tag_pointer + 2); - struct mmap_tag_entry *end = (struct mmap_tag_entry *)((uint32_t)tag_pointer + tag_pointer->size); - struct mmap_entry *entry = mmap_bss; - uint32_t bitmask = 0x00000001; - uint32_t byte = 0; - uint32_t usable = 0; - put_sz(": memory map\n Regions:\n"); - while (tag != end) { - if (!(tag->base & 0xffffffff00000000) && tag->length) { - entry->base = (uint32_t)tag->base; - entry->length = (tag->base + tag->length - 1) & 0xffffffff00000000 ? - 1 + ~(uint32_t)tag->base : (uint32_t)tag->length; - if (!entry->base) - mmap_start = entry; - put_sz(" 0x"); - put_32_hex(entry->base); - put_sz(" - 0x"); - put_32_hex(entry->base + entry->length - 1); - switch (tag->type) { - case AVAILABLE: - put_sz(": usable\n"); - entry->whose = FREE; - usable += entry->length; - break; - case HARDWARET: - case PRESERVE: - put_sz(": hardware use\n"); - entry->whose = HARDWARE; - break; - case ACPI: - put_sz(": ACPI info\n"); - entry->whose = HARDWARE; - break; - case DEFECTIVE: - put_sz(": defective\n"); - entry->whose = HARDWARE; - break; - default: - put_sz(": assuming hardware use (0x"); - put_32_hex(tag->type); - put_sz(")\n"); - entry->whose = HARDWARE; - break; - } - mmap_bitmap[byte] |= bitmask; - ++entry; - if (!(bitmask <<= 1)) { - bitmask = 0x00000001; - if (++byte == MMAP_SIZE) - return MMAP_TOO_SMALL; - } - } - tag = (struct mmap_tag_entry *)((uint32_t)tag + size); - } - - put_sz(" Total usable memory: 0x"); - put_32_hex(usable); - - for (struct mmap_entry *b = mmap_bss; b < entry; ++b) - for (struct mmap_entry *a = mmap_bss; a < entry; ++a) - if (b->base + b->length == a->base) - (b->after = a)->before = b; - - for (struct mmap_entry *p = mmap_start; p->after; p = p->after) - while (p->whose == p->after->whose) { - p->length += p->after->whose; - unmark_entry(p->after); - if (p->after = p->after->after) - p->after->before = p; - } - - if (mmap_start) { - have_mmap = true; - break; - } - return BAD_MMAP; - } - - case VBE_INFO: { - struct vbe_tag *vbe_info = (struct vbe_tag *)(tag_pointer + 1); - put_sz(": VBE information"); - if (vbe_info->v2_length) { - put_sz("\n v2: 0x"); - put_16_hex(vbe_info->v2_segment); - put_sz(":0x"); - put_16_hex(vbe_info->v2_offset); - put_sz(" + 0x"); - put_16_hex(vbe_info->v2_length); - } - put_sz("\n v3 mode: 0x"); - put_16_hex(vbe_info->mode); - break; - } - - case FBUF_INFO: { - struct fbuf_tag *fbuf_info = (struct fbuf_tag *)(tag_pointer + 1); - put_sz(": framebuffer information\n Address: 0x"); - put_32_hex(fbuf_info->address_high); - put_char('.'); - put_32_hex(fbuf_info->address_low); - put_sz("\n Pitch: "); - put_32_dec(fbuf_info->pitch); - put_sz("B\n Size: "); - put_32_dec(fbuf_info->width); - put_sz(" x "); - put_32_dec(fbuf_info->height); - put_sz(" x "); - put_8_dec(fbuf_info->bpp); - switch (fbuf_info->color_type) { - case PALETTE: - put_sz("b\n Palette:"); - uint32_t l = *(uint32_t *)(fbuf_info + 1); - struct fbuf_palette_entry *palette = (struct fbuf_palette_entry *)((uint32_t *)(fbuf_info + 1) + 1); - for (uint32_t i = 0; i < l; ++i) { - put_sz("\n #"); - put_8_hex(palette[i].red); - put_8_hex(palette[i].green); - put_8_hex(palette[i].blue); - } - break; - case RGB: - put_sz("b\n RGB:"); - //TODO - break; - case TEXT: - put_sz("b\n Text mode"); - break; - default: - put_sz("b\n Unknown mode 0x"); - put_8_hex(fbuf_info->color_type); - } - break; - } - - case ELF_SYMBOLS: { - struct elf_tag *tag = (struct elf_tag *)(tag_pointer + 1); - struct elf_shdr *p = (struct elf_shdr *)(tag + 1); - put_sz(": ELF shdr table\n shndx: 0x"); - put_16_hex(tag->shndx); - if (tag->count) - for (uint32_t i = 0; i < tag->count; ++i) { - ;//TODO - p = (struct elf_shdr *)((uint32_t)p + tag->size); - } - break; - } - - case APM_TABLE: { - struct apm_table *table = (struct apm_table *)(tag_pointer + 1); - put_sz(": APM table\n v"); - put_16_dec(table->version); - //TODO - break; - } - - case SMBIOS_TABLE: { - struct smbios_tag *tag = (struct smbios_tag *)(tag_pointer + 1); - put_sz(": SMBIOS\n v"); - put_8_dec(tag->major_version); - put_char('.'); - put_8_dec(tag->minor_version); - //TODO - break; - } - - case IMAGE_BASE_ADDR: - put_sz(": image address\n 0x"); - put_32_hex(text_base = *(uint32_t *)(tag_pointer + 1)); - have_text_base = true; - break; - - default: - put_sz(": ignoring"); - - } - tag_pointer = (struct tag_start *)(((uint32_t)tag_pointer + tag_pointer->size - 1 & ~0x00000007) + 8); - } - - if (!have_boot_device) - return NO_BOOT_DEVICE; - if (!have_mmap) - return NO_MMAP; - - put_sz("\n\nInfo:"); - if (have_text_base) { - put_sz("\n Text section: 0x"); - put_32_hex(text_base); - } - put_sz("\n Memory map size: 0x"); - put_32_hex(sizeof(struct mmap_entry) * MMAP_SIZE); - put_sz("\n Process table size: 0x"); - put_32_hex(sizeof(struct proc_info) * 65536); - put_sz("\n File table size: 0x"); - put_32_hex(sizeof(struct file_info) * 65536); - put_sz("\n\nDisks:"); - - for (uint8_t i = 0; i < 26; ++i) { - detect_disk_parts((uint8_t)'a' + i); - if (part_info[i].format) { - put_sz("\n "); - put_char((uint8_t)'a' + i); - if (part_info[i].n_partitions) { - put_char('0'); - uint8_t str[] = "\n 1"; - for (uint8_t m = part_info[i].n_partitions + (uint8_t)'0'; str[4] < m; ++(str[4])) - put_sz(str); - } - } - } - - put_sz("\n\n"); - - put_sz("No file support yet. Halting."); - while (1) - asm ("hlt"); - - uint8_t rc_buffer[4096]; - - uint16_t rc_handle = open_file("/cfg/init/once.rc"); - if (!rc_handle) - return MISSING_RC; - while (read_line_file(rc_handle, 4095, (void *)rc_buffer)) - if ((*rc_buffer != (uint8_t)'#') && !new_proc(rc_buffer)) - return BAD_RC_LINE; - close_file(rc_handle); - - rc_handle = open_file("/cfg/init/repeat.rc"); - if (!rc_handle) - return MISSING_RC; - while (1) { - while (read_line_file(rc_handle, 4095, (void *)rc_buffer)) - if ((*rc_buffer != (uint8_t)'#') && !new_proc(rc_buffer)) - return BAD_RC_LINE; - seek_file(rc_handle, -0x80000000); - seek_file(rc_handle, -0x80000000); - } -} - -void wrapped_main(void) { - clear(); - uint32_t error = main(); - set_color(0x47); - clear(); - put_sz("Error: 0x"); - put_32_hex(error); -} diff --git a/src/kernel/mem.c b/src/kernel/mem.c deleted file mode 100644 index d9322a9..0000000 --- a/src/kernel/mem.c +++ /dev/null @@ -1,88 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include "mem.h" - -uint32_t last_byte = 0; -uint32_t last_mask = 0x00000001; - -void *allocate_block(uint32_t size, uint16_t proc_n) { - for (struct mmap_entry *find = mmap_start; find; find = find->after) - if (!find->whose) { - if (find->length == size) { - find->whose = proc_n; - return (void *)find->base; - } - else if (find->length > size) { - uint32_t byte = last_byte; - uint32_t mask = last_mask; - while (mmap_bitmap[byte] & mask) { - if ((byte == last_byte) && (mask == last_mask)) { - while (find = find->after) - if (find->length == size) { - find->whose = proc_n; - return (void *)find->base; - } - return (void *)0; - } - if (!(mask <<= 1)) { - mask = 0x00000001; - if (++byte == MMAP_SIZE) - byte = 0; - } - } - mmap_bitmap[last_byte = byte] |= last_mask = mask; - struct mmap_entry *new = mmap_bss + (byte << 5); - while (mask >>= 1) - ++new; - ((((new->after = find->after)->before = new)->before = find)->after = new)->base = find->base + size; - new->length = find->length - size; - find->length = size; - find->whose = proc_n; - new->whose = FREE; - return (void *)find->base; - } - } - return (void *)0; -} - -void deallocate_block(void *start) { - struct mmap_entry *find = mmap_start; - while (find->base != (uint32_t)start) - if (find->after) - find = find->after; - else - return; - find->whose = FREE; - while (find->before && !find->before->whose) { - find->before->length += find->length; - if (find->before->after = find->after) - find->after->before = find->before; - unmark_entry(find); - find = find->before; - } - if (!find->before) - mmap_start = find; - while (find->after && !find->after->whose) { - find->length += find->after->length; - unmark_entry(find->after); - if (find->after = find->after->after) - find->after->before = find; - } -}
\ No newline at end of file diff --git a/src/kernel/mem.h b/src/kernel/mem.h deleted file mode 100644 index 4a35978..0000000 --- a/src/kernel/mem.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include <stdint.h> - -#ifndef MEM_H -#define MEM_H - -enum special_mmap_codes { - FREE = 0, - HARDWARE = 1, - KERNEL = 2 -}; - -struct mmap_entry { - uint32_t base; - uint32_t length; - uint16_t whose; - struct mmap_entry *after; - struct mmap_entry *before; -}; - -#define MMAP_SIZE 65536 -struct mmap_entry *mmap_start; -struct mmap_entry mmap_bss[MMAP_SIZE]; -uint32_t mmap_bitmap[MMAP_SIZE / 32]; -#define unmark_entry(entry) (mmap_bitmap[((entry) - mmap_bss) >> 5] ^= 1 << (((entry) - mmap_bss) & 0x0000001f)) -void *allocate_block(uint32_t size, uint16_t proc_n); -void deallocate_block(void *start); - -#endif
\ No newline at end of file diff --git a/src/kernel/proc.c b/src/kernel/proc.c deleted file mode 100644 index 0912f3c..0000000 --- a/src/kernel/proc.c +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include "proc.h" -#include "mem.h" -#include "files.h" - -uint16_t new_proc(uint8_t *file) { - uint16_t handle = open_file(file); - if (handle) - for (uint16_t id = 3; id; ++id) - if (!proc_table[id].text) { - uint32_t size = get_size(id); - void *mem; - proc_table[id].text = size + (proc_table[id].text = allocate_block(size, id)); - read_file(handle, size, mem); - close_file(handle); - //Process file header and make new process - return id; - } - close_file(handle); - return 0; -} - -void end_proc(uint16_t id) { - if (id && proc_table[id].text) { - deallocate_block(proc_table[id].text); - if (proc_table[id].rodata) - deallocate_block(proc_table[id].rodata); - if (proc_table[id].data) - deallocate_block(proc_table[id].data); - if (proc_table[id].bss) - deallocate_block(proc_table[id].bss); - proc_table[id].text = 0; - } -}
\ No newline at end of file diff --git a/src/kernel/proc.h b/src/kernel/proc.h deleted file mode 100644 index 94b0c53..0000000 --- a/src/kernel/proc.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include <stdint.h> - -#ifndef PROC_H -#define PROC_H - -struct proc_info { - void *text; - void *rodata; - void *data; - void *bss; -}; - -struct proc_info proc_table[65536]; -uint16_t new_proc(uint8_t *file); -void end_proc(uint16_t id); - -#endif
\ No newline at end of file diff --git a/src/kernel/serial.asm b/src/kernel/serial.asm deleted file mode 100644 index 2213fd8..0000000 --- a/src/kernel/serial.asm +++ /dev/null @@ -1,107 +0,0 @@ -;Copyright 2019 Benji Dial - -;Permission to use, copy, modify, and/or distribute this -;software for any purpose with or without fee is hereby -;granted, provided that the above copyright notice and this -;permission notice appear in all copies. - -;THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -;ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -;EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -;INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -;RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -;ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -;ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -;OF THIS SOFTWARE. - -global send_byte -global read_byte -global poll_port - -section .text -send_byte:;void send_byte(uint8_t value, uint8_t port) - push ebp - mov ebp, esp - - xor ecx, ecx - mov cl, byte [ebp + 12];port - - test cl, 0xfc - jnz .leave - - shl cl, 1 - mov dx, word [ecx + com_ports] - - or dx, 5 - -.check_ready: - in al, dx - test al, 0x20 - jz .check_ready - - and dx, 0xfff8 - - mov al, byte [ebp + 8];value - out dx, al - -.leave: - leave - ret - -read_byte:;uint8_t read_byte(uint8_t port) - push ebp - mov ebp, esp - - xor eax, eax - - xor ecx, ecx - mov cl, byte [ebp + 8];port - - test cl, 0xfc - jnz .leave - - shl cl, 1 - mov dx, word [ecx + com_ports] - - or dx, 5 - -.check_ready: - in al, dx - test al, 0x01 - jz .check_ready - - and dx, 0xfff8 - - in al, dx - -.leave: - leave - ret - -poll_port:;bool poll_port(uint8_t port) - push ebp - mov ebp, esp - - xor eax, eax - - xor ecx, ecx - mov cl, byte [ebp + 8];port - - test cl, 0xfc - jnz .leave - - shl cl, 1 - mov dx, word [ecx + com_ports] - - or dx, 5 - - in al, dx - and al, 0x01 - -.leave: - leave - ret - -section .rodata -com_ports dw 0x03f8, 0x02f8, 0x03e8, 0x02e8
\ No newline at end of file diff --git a/src/kernel/serial.h b/src/kernel/serial.h deleted file mode 100644 index 2588bee..0000000 --- a/src/kernel/serial.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include <stdint.h> -#include <stdbool.h> - -#ifndef SERIAL_H -#define SERIAL_H - -enum serials { - COM1 = 0, - COM2 = 1, - COM3 = 2, - COM4 = 3 -}; - -void send_byte(uint8_t value, uint8_t port); -uint8_t read_byte(uint8_t port); -bool poll_port(uint8_t port); - -#endif
\ No newline at end of file diff --git a/src/kernel/stub.asm b/src/kernel/stub.asm deleted file mode 100644 index d5d81ef..0000000 --- a/src/kernel/stub.asm +++ /dev/null @@ -1,53 +0,0 @@ -;Copyright 2019 Benji Dial - -;Permission to use, copy, modify, and/or distribute this -;software for any purpose with or without fee is hereby -;granted, provided that the above copyright notice and this -;permission notice appear in all copies. - -;THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -;ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -;EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -;INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -;RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -;ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -;ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -;OF THIS SOFTWARE. - -global _start -extern wrapped_main -extern tag_pointer - -section .mb_header -dd 0xe852_50d6;magic -dd 0x0000_0000;architecture - i386 -dd mb_end - $$;length -dd 0x17adaf2a - mb_end + $$;check - -;tags -dw 0x0001;info request -dw 0x0000;flags -dd mb_end - $$ - 16 -dd 5;boot device -dd 6;memory map -mb_end: - -section .text -bits 32 -_start: - add ebx, 8 - mov dword [tag_pointer], ebx - mov esp, stack - - call wrapped_main - - cli -halt: - hlt - jmp halt - -section .bss -info_pointer resd 1 -resb 0x1000 - $ + $$ -stack:
\ No newline at end of file diff --git a/src/kernel/vga.c b/src/kernel/vga.c deleted file mode 100644 index f83a2cf..0000000 --- a/src/kernel/vga.c +++ /dev/null @@ -1,146 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include "vga.h" -#include "serial.h" -#include <stdbool.h> - -#define VGA_BUFFER ((uint8_t *)0x000b8000) -#define cols 80 -#define rows 25 -uint16_t cursor_pos = 0; -uint8_t color = 0x70; - -void clear(void) { - uint32_t fill = 0x00200020 | (color << 24) | (color << 8); - for (uint32_t *i = (uint32_t *)VGA_BUFFER; i < (uint32_t *)(VGA_BUFFER + rows * cols * 2); ++i) - *i = fill; - cursor_pos = 0; -} - -void scroll(void) { - cursor_pos -= cols * 2; - for (uint32_t *i = (uint32_t *)VGA_BUFFER; i < (uint32_t *)(VGA_BUFFER + (rows - 1) * cols * 2); ++i) - *i = *(i + cols / 2); - uint32_t fill = (color << 8) | (color << 24) | 0x00200020; - for (uint32_t *i = (uint32_t *)(VGA_BUFFER + (rows - 1) * cols * 2); i < (uint32_t *)(VGA_BUFFER + rows * cols * 2); ++i) - *i = fill; -} - -void put_char(uint8_t ch) { - send_byte(ch, COM2); - switch (ch) { - case '\b': - if (cursor_pos) - VGA_BUFFER[cursor_pos -= 2] = (uint8_t)' '; - break; - case '\t': - while ((cursor_pos % (cols * 2)) % 20) - put_char(' '); - break; - case '\n': - if ((cursor_pos = (cursor_pos / (cols * 2) + 1) * (cols * 2)) >= cols * rows * 2) - scroll(); - break; - default: - VGA_BUFFER[cursor_pos++] = ch; - VGA_BUFFER[cursor_pos++] = color; - if (cursor_pos == (cols * rows * 2)) - scroll(); - } -} - -void put_sz(uint8_t *sz) { - while (*sz) - put_char(*(sz++)); -} - -void put_32_hex(uint32_t n) { - for (uint8_t i = 0; i < 4; ++i) { - put_char("0123456789abcdef"[n >> 28]); - n <<= 4; - } - put_char('.'); - for (uint8_t i = 0; i < 4; ++i) { - put_char("0123456789abcdef"[n >> 28]); - n <<= 4; - } -} - -void put_16_hex(uint16_t n) { - for (uint8_t i = 0; i < 4; ++i) { - put_char("0123456789abcdef"[n >> 12]); - n <<= 4; - } -} - -void put_8_hex(uint8_t n) { - put_char("0123456789abcdef"[n >> 4]); - put_char("0123456789abcdef"[n & 0x0f]); -} - -void put_32_dec(uint32_t n) { - if (n) { - bool sig = false; - for (uint32_t m = 1000000000; m; m /= 10) { - if (((n / m) % 10) || sig) { - sig = true; - put_char((uint8_t)'0' + (n / m) % 10); - } - } - } - else - put_char('0'); -} - -void put_16_dec(uint16_t n) { - if (n) { - bool sig = false; - for (uint16_t m = 10000; m; m /= 10) { - if (((n / m) % 10) || sig) { - sig = true; - put_char((uint8_t)'0' + (n / m) % 10); - } - } - } - else - put_char('0'); -} - -void put_8_dec(uint8_t n) { - if (n) { - bool sig = false; - for (uint8_t m = 100; m; m /= 10) { - if (((n / m) % 10) || sig) { - sig = true; - put_char((uint8_t)'0' + (n / m) % 10); - } - } - } - else - put_char('0'); -} - -void move_cursor(uint8_t col, uint8_t row) { - cursor_pos = (col + row * cols) * 2; -} - -void set_color(uint8_t c) { - color = c; -} diff --git a/src/kernel/vga.h b/src/kernel/vga.h deleted file mode 100644 index 85eb887..0000000 --- a/src/kernel/vga.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include <stdint.h> - -#ifndef VGA_H -#define VGA_H - -void clear(void); -void put_char(uint8_t ch); -void put_sz(uint8_t *s); -void put_32_hex(uint32_t n); -void put_16_hex(uint16_t n); -void put_8_hex(uint8_t n); -void put_32_dec(uint32_t n); -void put_16_dec(uint16_t n); -void put_8_dec(uint8_t n); -void move_cursor(uint8_t col, uint8_t row); -void set_color(uint8_t c); - -#endif
\ No newline at end of file |