The boot environment will read the boot sector from the sd card, verify
that it has the boot signature at the end, then jump to the start of it.
From there, there should be a bootloader written to the boot segment
that can handle the rest.
It might be tight to fit everything into the boot sector but do remember
that you do not have to initialize or select the sd card, and those
functions take up a lot of space.
This allows you to find the cluster number of a file in the root
directory by name. The main program is a simple demo where you can type
in a filename and it will tell you the cluster number.
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.
All of the SD card commands are moved into their own file, with
functions sd_init, sd_get_rca, sd_select_card, sd_get_status, and
sd_readblock.
The FAT functions are movied into fat.c and give functions fat_init and
fat_read. Note that the filename is ignored for now, it always reads the
first file in the root directory.
The loading of o65 files is done in o65.c, and executing is done in
exec.c
This cleans up the main file signifigantly and leaves the project open
to expansion.
This will read the data from the sd card, copy it to the originally
linked address (no relocation), then execute it.
I am lazy and wrote it in C using weird function pointer casting but
this would probably be more efficient if it were to be written in
assembly instead.
The test program simply returns 'A', but that is enough to prove that it
is actually running.
This adds a test program which can be loaded and executed by the host.
It simply returns a value in the `a` register.
The linker script is modified so that it will output an o65 file, and
the memory sgments are changed as well. There is no STARTUP segment
defined, so it uses the default `none` crt0, which sets up the stack
and does initialization and deconstruction.
The Makefile is modified to not turn the output into an intel hex file,
and instead keep it as the o65 file.
Prints out information about the drive, now inside its own function.
Also changes the read function to take in a 32 bit address instead of a
16 bit one.
Attempts to read the first file on the disk
The but count should be set to 7 when entering RXDATA. previously it was
not reset or left at 0, which caused the first byte to only have the lsb
set and all other bits to be read incorrectly.
After a data read (e.g. CMD17) the data received from the SD card is
stored into a buffer which can be read back one byte at a time by the
CPU through address 5.
There is also a flag which is set when data is received. This can be
checked by reading the CMD register, which doubles as the status
register.
Polls the sd controller until the read flag is set, at which point it
reads 32 bits of data from the controller.
long response codes (such as CID) are not supported in hw or sw.
Read flag is set when the sd controller reads response data in from the
sd card. When the cpu reads from the controller, the flag is reset.
This flag does not trigger an interrupt, it mmust be polled.
These series of commands are enough to read the first 512b block off of
the sd card. The RCA is hard coded to the sd card that I have on hand,
since response codes are not supported
The SD card expects data to transition on falling edges and be stable on
rising edges.
Additionally, writes from the CPU were not handled with correct timing.
Now, there is an extra state when writing to the command register so
that the command is properly latched before the CRC is calculated.