function to return pointers to functions to read from a constant interface, so we only have to check the interface once per macro operation

This commit is contained in:
Benji Dial 2020-01-05 22:26:40 -05:00
parent 3ec928b8ca
commit 243e28075e
10 changed files with 219 additions and 13 deletions

View file

@ -11,6 +11,9 @@ files: out
cp -r src/skel/* out/fs/ cp -r src/skel/* out/fs/
kernel: obj out kernel: obj out
nasm src/kernel/ata.asm -o obj/kata.o -f elf32
nasm src/kernel/floppy.asm -o obj/kfloppy.o -f elf32
nasm src/kernel/ide.asm -o obj/kide.o -f elf32
nasm src/kernel/keyb.asm -o obj/kkeyba.o -f elf32 nasm src/kernel/keyb.asm -o obj/kkeyba.o -f elf32
nasm src/kernel/serial.asm -o obj/kserial.o -f elf32 nasm src/kernel/serial.asm -o obj/kserial.o -f elf32
nasm src/kernel/stub.asm -o obj/kstub.o -f elf32 nasm src/kernel/stub.asm -o obj/kstub.o -f elf32
@ -23,8 +26,9 @@ kernel: obj out
gcc -c src/kernel/mem.c -o obj/kmem.o -ffreestanding -nostdlib -m32 gcc -c src/kernel/mem.c -o obj/kmem.o -ffreestanding -nostdlib -m32
gcc -c src/kernel/proc.c -o obj/kproc.o -ffreestanding -nostdlib -m32 gcc -c src/kernel/proc.c -o obj/kproc.o -ffreestanding -nostdlib -m32
gcc -c src/kernel/vga.c -o obj/kvga.o -ffreestanding -nostdlib -m32 gcc -c src/kernel/vga.c -o obj/kvga.o -ffreestanding -nostdlib -m32
ld obj/kkeyba.o obj/kserial.o obj/kstub.o obj/kdiskio.o obj/kfiles.o \ ld obj/kata.o obj/kfloppy.o obj/kide.o obj/kkeyba.o obj/kserial.o \
obj/kiso9660.o obj/kkeybc.o obj/kmain.o obj/kmem.o obj/kproc.o obj/kvga.o \ obj/kstub.o obj/kdiskio.o obj/kfiles.o obj/kiso9660.o obj/kkeybc.o \
obj/kmain.o obj/kmem.o obj/kproc.o obj/kvga.o \
-o out/kernel.elf -T src/kernel/link.ld -s --orphan-handling=discard -melf_i386 -o out/kernel.elf -T src/kernel/link.ld -s --orphan-handling=discard -melf_i386
clean: clean:

38
src/kernel/ata.asm Normal file
View file

@ -0,0 +1,38 @@
;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
;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
;TODO
leave
ret

23
src/kernel/ata.h Normal file
View file

@ -0,0 +1,23 @@
/*
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);

View file

@ -18,17 +18,30 @@ OF THIS SOFTWARE.
*/ */
#include "diskio.h" #include "diskio.h"
#include "floppy.h"
#include "ide.h"
#include "ata.h"
uint32_t read_sectors(uint8_t drive, uint32_t start, uint32_t count, void *buffer) { read_sectors_t read_sectors_functions[] = {
if ((drive >= 26) || !(drives[drive].flags & DISK_IN)) &floppy_read_sectors,
return 0; &ide_read_sectors,
return 0;//TODO &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];
} }
uint32_t write_sectors(uint8_t drive, uint32_t start, uint32_t count, void *buffer) { write_sectors_t write_sectors_functions[] = {
if ((drive >= 26) || !(drives[drive].flags & DISK_IN)) &floppy_write_sectors,
return 0; &ide_write_sectors,
return 0;//TODO &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) { void update_status(uint8_t drive) {

View file

@ -29,6 +29,11 @@ enum interface {
ATA 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 { enum drive_flags {
SPUN = 0x01, SPUN = 0x01,
DISK_IN = 0x02, DISK_IN = 0x02,
@ -45,8 +50,8 @@ struct drive_info {
struct drive_info drives[26]; struct drive_info drives[26];
uint32_t read_sectors(uint8_t drive, uint32_t start, uint32_t count, void *buffer); read_sectors_t get_read_sectors_function(uint8_t drive);
uint32_t write_sectors(uint8_t drive, uint32_t start, uint32_t count, void *buffer); write_sectors_t get_write_sectors_function(uint8_t drive);
void update_status(uint8_t drive); void update_status(uint8_t drive);
#endif #endif

38
src/kernel/floppy.asm Normal file
View file

@ -0,0 +1,38 @@
;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
;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
;TODO
leave
ret

23
src/kernel/floppy.h Normal file
View file

@ -0,0 +1,23 @@
/*
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);

38
src/kernel/ide.asm Normal file
View file

@ -0,0 +1,38 @@
;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
;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
;TODO
leave
ret

23
src/kernel/ide.h Normal file
View file

@ -0,0 +1,23 @@
/*
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);

View file

@ -24,8 +24,9 @@ OF THIS SOFTWARE.
bool iso_9660_parse_ph(uint8_t dn, uint8_t pn, uint32_t sector, uint8_t *buffer) { bool iso_9660_parse_ph(uint8_t dn, uint8_t pn, uint32_t sector, uint8_t *buffer) {
uint32_t s = sector + 64; uint32_t s = sector + 64;
read_sectors_t rsf = get_read_sectors_function(dn);
do { do {
read_sectors(dn, s, 4, buffer); rsf(drives[dn].number, s, 4, buffer);
if ((*buffer == 255) || (*(uint32_t *)&buffer[1] != 0x30304443) || if ((*buffer == 255) || (*(uint32_t *)&buffer[1] != 0x30304443) ||
(buffer[5] != (uint8_t)'1')) (buffer[5] != (uint8_t)'1'))
return false; return false;