diff --git a/fpga/zsbl/boot.c b/fpga/zsbl/boot.c index 52473ab46..566393cb6 100644 --- a/fpga/zsbl/boot.c +++ b/fpga/zsbl/boot.c @@ -1,3 +1,32 @@ +/////////////////////////////////////////////////////////////////////// +// boot.c +// +// Written: Jacob Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: Main bootloader entry point +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + #include #include "boot.h" #include "gpt.h" @@ -8,54 +37,6 @@ #include "riscv.h" #include "fail.h" -/* int disk_read(BYTE * buf, LBA_t sector, UINT count, BYTE card_type) { */ - -/* /\* This is not needed. This has everything to do with the FAT */ -/* filesystem stuff that I'm not including. All I need to do is */ -/* initialize the SD card and read from it. Anything in here that is */ -/* checking for potential errors, I'm going to have to temporarily */ -/* do without. */ -/* *\/ */ -/* // if (!count) return RES_PARERR; */ -/* /\* if (drv_status & STA_NOINIT) return RES_NOTRDY; *\/ */ - -/* uint32_t response[4]; */ -/* struct sdc_regs * regs = (struct sdc_regs *)SDC; */ - -/* /\* Convert LBA to byte address if needed *\/ */ -/* if (!(card_type & CT_BLOCK)) sector *= 512; */ -/* while (count > 0) { */ -/* UINT bcnt = count > MAX_BLOCK_CNT ? MAX_BLOCK_CNT : count; */ -/* unsigned bytes = bcnt * 512; */ -/* if (send_data_cmd(bcnt == 1 ? CMD17 : CMD18, sector, buf, bcnt, response) < 0) return 1; */ -/* if (bcnt > 1 && send_cmd(CMD12, 0, response) < 0) return 1; */ -/* sector += (card_type & CT_BLOCK) ? bcnt : bytes; */ -/* count -= bcnt; */ -/* buf += bytes; */ -/* } */ - -/* return 0;; */ -/* } */ - -// Need to convert this -/* void print_progress(size_t count, size_t max) { */ -/* const int bar_width = 50; */ - -/* float progress = (float) count / max; */ -/* int bar_length = progress * bar_width; */ - -/* printf("\r["); */ -/* for (int i = 0; i < bar_length; ++i) { */ -/* printf("#"); */ -/* } */ -/* for (int i = bar_length; i < bar_width; ++i) { */ -/* printf("-"); */ -/* } */ -/* printf("] %.2f%%", progress * 100); */ - -/* fflush(stdout); */ -/* } */ - int disk_read(BYTE * buf, LBA_t sector, UINT count) { uint64_t r; UINT i; diff --git a/fpga/zsbl/boot.h b/fpga/zsbl/boot.h index 25b8a5fcc..0c09a1e52 100644 --- a/fpga/zsbl/boot.h +++ b/fpga/zsbl/boot.h @@ -1,3 +1,32 @@ +/////////////////////////////////////////////////////////////////////// +// boot.h +// +// Written: Jaocb Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: Header for boot.c, main bootloader entry point +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + #ifndef WALLYBOOT #define WALLYBOOT 10000 diff --git a/fpga/zsbl/fail.c b/fpga/zsbl/fail.c index 4e6cd8db0..4430c4a8f 100644 --- a/fpga/zsbl/fail.c +++ b/fpga/zsbl/fail.c @@ -1,3 +1,33 @@ +/////////////////////////////////////////////////////////////////////// +// fail.c +// +// Written: Jaocb Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: Prints information on the uart when a fatal bug is +// encountered. Will expand this later. +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + #include "fail.h" #include "uart.h" #include "riscv.h" diff --git a/fpga/zsbl/fail.h b/fpga/zsbl/fail.h index da1a2e405..c965265d1 100644 --- a/fpga/zsbl/fail.h +++ b/fpga/zsbl/fail.h @@ -1,3 +1,32 @@ +/////////////////////////////////////////////////////////////////////// +// fail.h +// +// Written: Jaocb Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: Function prototype for fail, +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + #pragma once #include diff --git a/fpga/zsbl/gpt.c b/fpga/zsbl/gpt.c index 99f74ec3a..e21176f05 100644 --- a/fpga/zsbl/gpt.c +++ b/fpga/zsbl/gpt.c @@ -1,3 +1,32 @@ +/////////////////////////////////////////////////////////////////////// +// gpt.c +// +// Written: Jaocb Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: Code to read GPT Partitions off of an SD card. +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + #include "gpt.h" #include "boot.h" #include "uart.h" diff --git a/fpga/zsbl/gpt.h b/fpga/zsbl/gpt.h index 5ce5e1d4b..8cd3ecc11 100644 --- a/fpga/zsbl/gpt.h +++ b/fpga/zsbl/gpt.h @@ -1,3 +1,32 @@ +/////////////////////////////////////////////////////////////////////// +// gpt.h +// +// Written: Jaocb Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: Header for gpt.c, contains gpt structs +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + #pragma once #include diff --git a/fpga/zsbl/riscv.S b/fpga/zsbl/riscv.S index 7f400b1b2..b2d86599c 100644 --- a/fpga/zsbl/riscv.S +++ b/fpga/zsbl/riscv.S @@ -1,3 +1,32 @@ +/////////////////////////////////////////////////////////////////////// +// riscv.S +// +// Written: Jaocb Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: Basic utility functions for reading registers +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + .section .text .globl read_mcycle .type read_mcycle, @function diff --git a/fpga/zsbl/riscv.h b/fpga/zsbl/riscv.h index a27cd48d6..543fe5cde 100644 --- a/fpga/zsbl/riscv.h +++ b/fpga/zsbl/riscv.h @@ -1,3 +1,32 @@ +/////////////////////////////////////////////////////////////////////// +// riscv.h +// +// Written: Jaocb Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: Function prototypes for riscv utility functions +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + #pragma once #include diff --git a/fpga/zsbl/sd.c b/fpga/zsbl/sd.c index 484fd65c0..1f95d8477 100644 --- a/fpga/zsbl/sd.c +++ b/fpga/zsbl/sd.c @@ -1,3 +1,32 @@ +/////////////////////////////////////////////////////////////////////// +// sd.c +// +// Written: Jaocb Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: SD Card protocol functions +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + #include "sd.h" #include "spi.h" #include "uart.h" diff --git a/fpga/zsbl/sd.h b/fpga/zsbl/sd.h index f695b83e5..f66686560 100644 --- a/fpga/zsbl/sd.h +++ b/fpga/zsbl/sd.h @@ -1,3 +1,33 @@ +/////////////////////////////////////////////////////////////////////// +// sd.h +// +// Written: Jaocb Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: Header file for SD card protocol functions. Defines some +// useful macros. +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + #pragma once #include diff --git a/fpga/zsbl/spi.c b/fpga/zsbl/spi.c index 5b23c85b6..04d609648 100644 --- a/fpga/zsbl/spi.c +++ b/fpga/zsbl/spi.c @@ -29,31 +29,6 @@ #include "spi.h" -// Write to a register -/* inline void write_reg(uintptr_t addr, uint32_t value) { */ -/* volatile uint32_t * loc = (volatile uint32_t *) addr; */ -/* *loc = value; */ -/* } */ - -/* // Read a register */ -/* inline uint32_t read_reg(uintptr_t addr) { */ -/* return *(volatile uint32_t *) addr; */ -/* } */ - -/* // Queues a single byte in the transfer fifo */ -/* inline void spi_sendbyte(uint8_t byte) { */ -/* // Write byte to transfer fifo */ -/* write_reg(SPI_TXDATA, byte); */ -/* } */ - -/* inline void waittx() { */ -/* while(!(read_reg(SPI_IP) & 1)) {} */ -/* } */ - -/* inline void waitrx() { */ -/* while(read_reg(SPI_IP) & 2) {} */ -/* } */ - uint8_t spi_txrx(uint8_t byte) { spi_sendbyte(byte); waittx(); @@ -64,10 +39,6 @@ uint8_t spi_dummy() { return spi_txrx(0xff); } -/* inline uint8_t spi_readbyte() { */ -/* return read_reg(SPI_RXDATA); */ -/* } */ - uint64_t spi_read64() { uint64_t r; uint8_t rbyte; diff --git a/fpga/zsbl/time.c b/fpga/zsbl/time.c index 43ac085b7..c265eea05 100644 --- a/fpga/zsbl/time.c +++ b/fpga/zsbl/time.c @@ -1,3 +1,32 @@ +/////////////////////////////////////////////////////////////////////// +// time.c +// +// Written: Jaocb Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: Gets and prints the current time. +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + #include "time.h" #include "boot.h" #include "riscv.h" diff --git a/fpga/zsbl/time.h b/fpga/zsbl/time.h index 6cd928b88..8bf7064af 100644 --- a/fpga/zsbl/time.h +++ b/fpga/zsbl/time.h @@ -1,3 +1,32 @@ +/////////////////////////////////////////////////////////////////////// +// spi.c +// +// Written: Jaocb Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: Time function prototypes +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + #pragma once #include diff --git a/fpga/zsbl/uart.c b/fpga/zsbl/uart.c index 8c25f17ca..580265d98 100644 --- a/fpga/zsbl/uart.c +++ b/fpga/zsbl/uart.c @@ -1,3 +1,33 @@ +/////////////////////////////////////////////////////////////////////// +// uart.c +// +// Written: Jaocb Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: Uart printing functions, as well as functions for printing +// hex, decimal, and floating point numbers. +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + #include "uart.h" void write_reg_u8(uintptr_t addr, uint8_t value) diff --git a/fpga/zsbl/uart.h b/fpga/zsbl/uart.h index cbdcc5941..96c55ffe8 100644 --- a/fpga/zsbl/uart.h +++ b/fpga/zsbl/uart.h @@ -1,3 +1,32 @@ +/////////////////////////////////////////////////////////////////////// +// uart.h +// +// Written: Jaocb Pease jacob.pease@okstate.edu 7/22/2024 +// +// Purpose: Header for the UART functions. +// +// +// +// A component of the Wally configurable RISC-V project. +// +// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University +// +// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 +// +// Licensed under the Solderpad Hardware License v 2.1 (the +// “License”); you may not use this file except in compliance with the +// License, or, at your option, the Apache License version 2.0. You +// may obtain a copy of the License at +// +// https://solderpad.org/licenses/SHL-2.1/ +// +// Unless required by applicable law or agreed to in writing, any work +// distributed under the License is distributed on an “AS IS” BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////// + #pragma once #include #include "riscv.h"