Skip to content

Commit

Permalink
Merge pull request #1652 from grumpycoders/toolchain-upgrade
Browse files Browse the repository at this point in the history
Upgrading gcc/gdb.
  • Loading branch information
nicolasnoble committed May 9, 2024
2 parents 9966742 + 642479b commit ba75605
Show file tree
Hide file tree
Showing 19 changed files with 117 additions and 74 deletions.
33 changes: 22 additions & 11 deletions src/mips/common/hardware/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,26 @@ SOFTWARE.
#include <stdint.h>

enum IRQ {
IRQ_VBLANK = 1 << 0,
IRQ_GPU = 1 << 1,
IRQ_CDROM = 1 << 2,
IRQ_DMA = 1 << 3,
IRQ_TIMER0 = 1 << 4,
IRQ_TIMER1 = 1 << 5,
IRQ_TIMER2 = 1 << 6,
IRQ_CONTROLLER = 1 << 7,
IRQ_SIO = 1 << 8,
IRQ_SPU = 1 << 9,
IRQ_PIO = 1 << 10,
IRQ_VBLANK_NUMBER = 0,
IRQ_VBLANK = 1 << IRQ_VBLANK_NUMBER,
IRQ_GPU_NUMBER = 1,
IRQ_GPU = 1 << IRQ_GPU_NUMBER,
IRQ_CDROM_NUMBER = 2,
IRQ_CDROM = 1 << IRQ_CDROM_NUMBER,
IRQ_DMA_NUMBER = 3,
IRQ_DMA = 1 << IRQ_DMA_NUMBER,
IRQ_TIMER0_NUMBER = 4,
IRQ_TIMER0 = 1 << IRQ_TIMER0_NUMBER,
IRQ_TIMER1_NUMBER = 5,
IRQ_TIMER1 = 1 << IRQ_TIMER1_NUMBER,
IRQ_TIMER2_NUMBER = 6,
IRQ_TIMER2 = 1 << IRQ_TIMER2_NUMBER,
IRQ_CONTROLLER_NUMBER = 7,
IRQ_CONTROLLER = 1 << IRQ_CONTROLLER_NUMBER,
IRQ_SIO_NUMBER = 8,
IRQ_SIO = 1 << IRQ_SIO_NUMBER,
IRQ_SPU_NUMBER = 9,
IRQ_SPU = 1 << IRQ_SPU_NUMBER,
IRQ_PIO_NUMBER = 10,
IRQ_PIO = 1 << IRQ_PIO_NUMBER,
};
2 changes: 1 addition & 1 deletion src/mips/openbios/card/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ static const struct Device s_cardDevice = {
.flags = 0x14,
.blockSize = 0x80,
.desc = "MEMORY CARD",
.init = psxdummy,
.init = (void (*)())psxdummy,
.open = dev_bu_open,
.action = psxdummy,
.close = dev_bu_close,
Expand Down
8 changes: 3 additions & 5 deletions src/mips/openbios/cdrom/cdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ void initializeCDRomHandlersAndEvents() {

static void initializeSoftwareAndHardware() {
initializeCDRomHandlersAndEvents();
while (!syscall_cdromInnerInit())
;
while (!syscall_cdromInnerInit());
}

void initCDRom() {
Expand All @@ -78,8 +77,7 @@ int cdromBlockGetStatus() {
uint8_t status;

int cyclesToWait = 9;
while (!syscall_cdromGetStatus(&status) && (--cyclesToWait > 0))
;
while (!syscall_cdromGetStatus(&status) && (--cyclesToWait > 0));
if (cyclesToWait < 1) {
syscall_exception(0x44, 0x1f);
return -1;
Expand All @@ -101,7 +99,7 @@ static const struct Device s_cdromDevice = {
.flags = 0x14,
.blockSize = 0x800,
.desc = "CD-ROM",
.init = psxdummy,
.init = (void (*)())psxdummy,
.open = dev_cd_open,
.action = psxdummy,
.close = psxdummy,
Expand Down
22 changes: 11 additions & 11 deletions src/mips/openbios/handlers/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,48 +77,48 @@ static __attribute__((section(".ramtext"))) int IRQVerifier(void) {
// guaranteed to not lose any IRQs.
if ((IMASK & IREG & IRQ_CDROM) != 0) {
deliverEvent(EVENT_CDROM, 0x1000);
if (s_IRQsAutoAck[IRQ_CDROM]) IREG &= ~IRQ_CDROM;
if (s_IRQsAutoAck[IRQ_CDROM_NUMBER]) IREG &= ~IRQ_CDROM;
}
if ((IMASK & IREG & IRQ_SPU) != 0) {
deliverEvent(EVENT_SPU, 0x1000);
if (s_IRQsAutoAck[IRQ_SPU]) IREG &= ~IRQ_SPU;
if (s_IRQsAutoAck[IRQ_SPU_NUMBER]) IREG &= ~IRQ_SPU;
}
if ((IMASK & IREG & IRQ_GPU) != 0) {
deliverEvent(EVENT_GPU, 0x1000);
if (s_IRQsAutoAck[IRQ_GPU]) IREG &= ~IRQ_GPU;
if (s_IRQsAutoAck[IRQ_GPU_NUMBER]) IREG &= ~IRQ_GPU;
}
if ((IMASK & IREG & IRQ_PIO) != 0) {
deliverEvent(EVENT_PIO, 0x1000);
if (s_IRQsAutoAck[IRQ_PIO]) IREG &= ~IRQ_PIO;
if (s_IRQsAutoAck[IRQ_PIO_NUMBER]) IREG &= ~IRQ_PIO;
}
if ((IMASK & IREG & IRQ_SIO) != 0) {
deliverEvent(EVENT_SIO, 0x1000);
if (s_IRQsAutoAck[IRQ_SIO]) IREG &= ~IRQ_SIO;
if (s_IRQsAutoAck[IRQ_SIO_NUMBER]) IREG &= ~IRQ_SIO;
}
if ((IMASK & IREG & IRQ_VBLANK) != 0) {
deliverEvent(EVENT_VBLANK, 0x1000);
if (s_IRQsAutoAck[IRQ_VBLANK]) IREG &= ~IRQ_VBLANK;
if (s_IRQsAutoAck[IRQ_VBLANK_NUMBER]) IREG &= ~IRQ_VBLANK;
}
if ((IMASK & IREG & IRQ_TIMER0) != 0) {
deliverEvent(EVENT_RTC0, 0x1000);
if (s_IRQsAutoAck[IRQ_TIMER0]) IREG &= ~IRQ_TIMER0;
if (s_IRQsAutoAck[IRQ_TIMER0_NUMBER]) IREG &= ~IRQ_TIMER0;
}
if ((IMASK & IREG & IRQ_TIMER1) != 0) {
deliverEvent(EVENT_RTC1, 0x1000);
if (s_IRQsAutoAck[IRQ_TIMER1]) IREG &= ~IRQ_TIMER1;
if (s_IRQsAutoAck[IRQ_TIMER1_NUMBER]) IREG &= ~IRQ_TIMER1;
}
if ((IMASK & IREG & IRQ_TIMER2) != 0) {
// Keeping this copy/paste mistake this way to avoid breaking stuff.
deliverEvent(EVENT_RTC1, 0x1000);
if (s_IRQsAutoAck[IRQ_TIMER2]) IREG &= ~IRQ_TIMER2;
if (s_IRQsAutoAck[IRQ_TIMER2_NUMBER]) IREG &= ~IRQ_TIMER2;
}
if ((IMASK & IREG & IRQ_CONTROLLER) != 0) {
deliverEvent(EVENT_CONTROLLER, 0x1000);
if (s_IRQsAutoAck[IRQ_CONTROLLER]) IREG &= ~IRQ_CONTROLLER;
if (s_IRQsAutoAck[IRQ_CONTROLLER_NUMBER]) IREG &= ~IRQ_CONTROLLER;
}
if ((IMASK & IREG & IRQ_DMA) != 0) {
deliverEvent(EVENT_DMA, 0x1000);
if (s_IRQsAutoAck[IRQ_DMA]) IREG &= ~IRQ_DMA;
if (s_IRQsAutoAck[IRQ_DMA_NUMBER]) IREG &= ~IRQ_DMA;
}
return 0;
}
Expand Down
6 changes: 4 additions & 2 deletions src/mips/openbios/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SOFTWARE.

#include <alloca.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>

#include "common/hardware/cop0.h"
Expand Down Expand Up @@ -130,7 +131,8 @@ static char s_binaryPath[128];
// the tabulation character ('\t', or character 9) or a space.
// Last but not least, the retail bios will screw things up
// fairly badly if the file isn't terminated using CRLFs.
static void findWordItem(const char *systemCnf, uint32_t *item, const char *name) {
static void findWordItem(const char *systemCnf, void *item_, const char *name) {
uint32_t *item = (uint32_t *)item_;
char c;
const unsigned size = strlen(name);
while (strncmp(systemCnf, name, size) != 0) {
Expand Down Expand Up @@ -378,7 +380,7 @@ static void boot(char *systemCnfPath, char *binaryPath) {
psxprintf("EXEC:PC0(%08x) T_ADDR(%08x) T_SIZE(%08x)\n", s_binaryInfo.pc, s_binaryInfo.text_addr,
s_binaryInfo.text_size);
psxprintf("boot address : %08x %08x\nExecute !\n\n", s_binaryInfo.pc, s_configuration.stackBase);
s_binaryInfo.stack_start = s_configuration.stackBase;
s_binaryInfo.stack_start = (uintptr_t)s_configuration.stackBase;
s_binaryInfo.stack_size = 0;
// the original format string says S_SIZE(%08), which is obviously wrong...
psxprintf(" S_ADDR(%08x) S_SIZE(%08x)\n", s_configuration.stackBase, 0);
Expand Down
3 changes: 2 additions & 1 deletion src/mips/openbios/patches/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ static inline uint32_t hashone(uint32_t a) {
return a;
}

uint32_t patch_hash(const uint32_t* ptr, uint8_t* maskPtr, unsigned len) {
uint32_t patch_hash(const uint32_t* ptr, const void* maskPtr_, unsigned len) {
const uint8_t* maskPtr = (const uint8_t*)maskPtr_;
uint32_t hash = 0x5810d659;
uint32_t mask = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/mips/openbios/patches/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ SOFTWARE.

#include <stdint.h>

uint32_t patch_hash(const uint32_t* ptr, uint8_t* mask, unsigned len);
uint32_t patch_hash(const uint32_t* ptr, const void* mask, unsigned len);
4 changes: 2 additions & 2 deletions src/mips/openbios/patches/patch_pad_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ enum patch_behavior patch_pad_1_execute(uint32_t *ra) {
ptr <<= 16;
addend = ra[4] & 0xffff;
ptr += addend;
*((uint32_t *)ptr) = patch_startPad;
*((uint32_t *)ptr) = (uint32_t)patch_startPad;

ptr = ra[6] & 0xffff;
ptr <<= 16;
addend = ra[7] & 0xffff;
ptr += addend;
*((uint32_t *)ptr) = patch_stopPad;
*((uint32_t *)ptr) = (uint32_t)patch_stopPad;

ra[2] = 11 | 0x10000000;
ra[3] = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/mips/openbios/patches/patch_pad_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ enum patch_behavior patch_pad_2_execute(uint32_t *ra) {
ptr <<= 16;
addend = ra[3] & 0xffff;
ptr += addend;
*((uint32_t *)ptr) = patch_startPad;
*((uint32_t *)ptr) = (uint32_t)patch_startPad;

ptr = ra[4] & 0xffff;
ptr <<= 16;
addend = ra[7] & 0xffff;
ptr += addend;
*((uint32_t *)ptr) = patch_stopPad;
*((uint32_t *)ptr) = (uint32_t)patch_stopPad;

ra[2] = 10 | 0x10000000;
ra[3] = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/mips/openbios/patches/patches.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ void patch_hook(uint32_t* ra, enum patch_table table) {
// already patched, bail out
if ((ra[0] == 0) && (ra[1] == 0) && (ra[3] == 0)) return;

uint32_t* hash_mask = NULL;
const uint32_t* hash_mask = NULL;

struct patch* patches = NULL;
const struct patch* patches = NULL;
unsigned size = 0;
char t = 'x';
switch (table) {
Expand Down
2 changes: 1 addition & 1 deletion src/mips/openbios/patches/send_pad_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ enum patch_behavior send_pad_1_execute(uint32_t* ra) {
ptr <<= 16;
addend = ra[8] & 0xffff;
ptr += addend;
*((uint32_t*)ptr) = patch_setPadOutputData;
*((uint32_t*)ptr) = (uint32_t)patch_setPadOutputData;

ra[2] = 15 | 0x10000000;
ra[3] = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/mips/openbios/patches/send_pad_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ enum patch_behavior send_pad_2_execute(uint32_t* ra) {
ptr <<= 16;
addend = ra[7] & 0xffff;
ptr += addend;
*((uint32_t*)ptr) = patch_setPadOutputData;
*((uint32_t*)ptr) = (uint32_t)patch_setPadOutputData;

ra[2] = 12 | 0x10000000;
ra[3] = 0;
Expand Down
14 changes: 7 additions & 7 deletions src/mips/openbios/tty/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ static const struct Device s_ttyDevice = {
.write = psxdummy,
.erase = psxdummy,
.undelete = psxdummy,
.firstFile = psxdummy,
.nextFile = psxdummy,
.firstFile = (struct DirEntry * (*)(struct File *, const char *, struct DirEntry *)) psxdummy,
.nextFile = (struct DirEntry * (*)(struct File *, struct DirEntry *)) psxdummy,
.format = psxdummy,
.chdir = psxdummy,
.rename = psxdummy,
.deinit = psxdummy,
.deinit = (void (*)())psxdummy,
.check = psxdummy,
};

Expand All @@ -76,7 +76,7 @@ static const struct Device s_dummyDevice = {
.flags = 1,
.blockSize = 1,
.desc = "CONSOLE",
.init = psxdummy,
.init = (void (*)()) psxdummy,
.open = psxdummy,
.action = psxdummy,
.close = psxdummy,
Expand All @@ -85,12 +85,12 @@ static const struct Device s_dummyDevice = {
.write = psxdummy,
.erase = psxdummy,
.undelete = psxdummy,
.firstFile = psxdummy,
.nextFile = psxdummy,
.firstFile = (struct DirEntry * (*)(struct File *, const char *, struct DirEntry *)) psxdummy,
.nextFile = (struct DirEntry * (*)(struct File *, struct DirEntry *)) psxdummy,
.format = psxdummy,
.chdir = psxdummy,
.rename = psxdummy,
.deinit = psxdummy,
.deinit = (void (*)())psxdummy,
.check = psxdummy,
};

Expand Down
6 changes: 3 additions & 3 deletions tools/linux-mips/spawn-compiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ make
make install-strip
cd ..

wget https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz
tar xvfz gcc-13.2.0.tar.gz
cd gcc-13.2.0
wget https://ftp.gnu.org/gnu/gcc/gcc-14.1.0/gcc-14.1.0.tar.gz
tar xvfz gcc-14.1.0.tar.gz
cd gcc-14.1.0
./contrib/download_prerequisites
mkdir build
cd build
Expand Down
4 changes: 2 additions & 2 deletions tools/macos-mips/mipsel-none-elf-gcc.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class MipselNoneElfGcc < Formula
desc "The GNU compiler collection for mipsel"
homepage "https://gcc.gnu.org"
url "https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.xz"
sha256 "e275e76442a6067341a27f04c5c6b83d8613144004c0413528863dc6b5c743da"
url "https://ftp.gnu.org/gnu/gcc/gcc-14.1.0/gcc-14.1.0.tar.xz"
sha256 "e283c654987afe3de9d8080bc0bd79534b5ca0d681a73a11ff2b5d3767426840"

depends_on "gmp"
depends_on "mipsel-none-elf-binutils"
Expand Down
4 changes: 2 additions & 2 deletions tools/vscode-extension/scripts/mipsel-none-elf-gcc.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class MipselNoneElfGcc < Formula
desc "The GNU compiler collection for mipsel"
homepage "https://gcc.gnu.org"
url "https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.xz"
sha256 "e275e76442a6067341a27f04c5c6b83d8613144004c0413528863dc6b5c743da"
url "https://ftp.gnu.org/gnu/gcc/gcc-14.1.0/gcc-14.1.0.tar.xz"
sha256 "e283c654987afe3de9d8080bc0bd79534b5ca0d681a73a11ff2b5d3767426840"

depends_on "gmp"
depends_on "mipsel-none-elf-binutils"
Expand Down
31 changes: 31 additions & 0 deletions tools/vscode-extension/scripts/mipsel-none-elf-gdb.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class MipselNoneElfGdb < Formula
desc "GDB: The GNU Project Debugger compiled for Mips"
homepage "https://sourceware.org/gdb/"
url "https://ftp.gnu.org/gnu/gdb/gdb-14.2.tar.xz"
sha256 "2d4dd8061d8ded12b6c63f55e45344881e8226105f4d2a9b234040efa5ce7772"

# inspired by https://github.com/orgs/Homebrew/discussions/1114#discussioncomment-8863715

depends_on "texinfo" => :build
depends_on "gmp"
depends_on "mpfr"
depends_on "python@3.10"

def install
mkdir "mipsel-none-elf-gdb-build" do
system "../configure", "--target=mipsel-none-elf",
"--prefix=#{prefix}",
"--enable-tui=yes",
"--without-isl",
"--disable-werror"
system "make"
system "make", "install"
end
end

# not sure what to test...
# test do
# assert_match "f()", shell_output("#{bin}/mipsel-none-elf-c++filt _Z1fv")
# end

end
16 changes: 8 additions & 8 deletions tools/win32-gdb/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# escape=`

# Dockerfile to generate the Windows gdb-multiarch-14.1.zip package.
# Dockerfile to generate the Windows gdb-multiarch-14.2.zip package.

FROM mcr.microsoft.com/windows/servercore:ltsc2022
WORKDIR C:\windows\temp
Expand Down Expand Up @@ -45,23 +45,23 @@ RUN C:\msys64\usr\bin\bash.exe -l -c 'pacman -S --needed --noconfirm mingw-w64-x
RUN C:\msys64\usr\bin\bash.exe -l -c 'pacman -S --needed --noconfirm mingw-w64-x86_64-python mingw-w64-x86_64-readline'
RUN C:\msys64\usr\bin\bash.exe -l -c 'pacman -Scc --noconfirm'

ARG GDB=https://ftp.gnu.org/gnu/gdb/gdb-14.1.tar.xz
ARG GDB=https://ftp.gnu.org/gnu/gdb/gdb-14.2.tar.xz

RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; `
Invoke-WebRequest $env:GDB -OutFile "C:\Windows\Temp\gdb-14.1.tar.xz"; `
Start-Process -FilePath "C:\7-Zip\7z.exe" -ArgumentList e, "C:\Windows\Temp\gdb-14.1.tar.xz", `-oC:\Windows\Temp\ -NoNewWindow -PassThru -Wait; `
Start-Process -FilePath "C:\7-Zip\7z.exe" -ArgumentList x, "C:\Windows\Temp\gdb-14.1.tar", `-oC:\ -NoNewWindow -PassThru -Wait; `
Invoke-WebRequest $env:GDB -OutFile "C:\Windows\Temp\gdb-14.2.tar.xz"; `
Start-Process -FilePath "C:\7-Zip\7z.exe" -ArgumentList e, "C:\Windows\Temp\gdb-14.2.tar.xz", `-oC:\Windows\Temp\ -NoNewWindow -PassThru -Wait; `
Start-Process -FilePath "C:\7-Zip\7z.exe" -ArgumentList x, "C:\Windows\Temp\gdb-14.2.tar", `-oC:\ -NoNewWindow -PassThru -Wait; `
Remove-Item @('C:\Windows\Temp\*', 'C:\Users\*\Appdata\Local\Temp\*') -Force -Recurse;

ENV MSYSTEM MINGW64

RUN C:\msys64\usr\bin\bash.exe -l -c 'mkdir /BUILD && cd /BUILD && /c/gdb-14.1/configure --disable-gdbtk --disable-shared --disable-readline --with-system-readline --with-expat --with-system-zlib --without-guile --without-babeltrace --enable-tui --with-lzma --without-python --with-xxhash --with-mpfr=/mingw64 --enable-64-bit-bfd --enable-targets=all --disable-sim --prefix=/DIST || (cat /BUILD/config.log && exit 1)'
RUN C:\msys64\usr\bin\bash.exe -l -c 'mkdir /BUILD && cd /BUILD && /c/gdb-14.2/configure --disable-gdbtk --disable-shared --disable-readline --with-system-readline --with-expat --with-system-zlib --without-guile --without-babeltrace --enable-tui --with-lzma --without-python --with-xxhash --with-mpfr=/mingw64 --enable-64-bit-bfd --enable-targets=all --disable-sim --prefix=/DIST || (cat /BUILD/config.log && exit 1)'

RUN C:\msys64\usr\bin\bash.exe -l -c 'LOADLIBES=-lws2_32\ -lbcrypt make -C /BUILD all'
RUN C:\msys64\usr\bin\bash.exe -l -c 'make -C /BUILD install-strip'
RUN C:\msys64\usr\bin\bash.exe -l -c 'cd /DIST/bin && ldd *.exe | cut -f2 -d\> | cut -f2 -d\ | grep mingw64 | while read f ; do cp $f . ; done'
RUN C:\msys64\usr\bin\bash.exe -l -c 'cp /c/gdb-14.1/COPYING* /DIST'
RUN C:\msys64\usr\bin\bash.exe -l -c 'cp /c/gdb-14.2/COPYING* /DIST'
RUN C:\msys64\usr\bin\bash.exe -l -c 'cp /DIST/bin/gdb.exe /DIST/bin/gdb-multiarch.exe'
RUN C:\msys64\usr\bin\bash.exe -l -c 'cd /DIST && zip /c/gdb-multiarch-14.1.zip . -r'
RUN C:\msys64\usr\bin\bash.exe -l -c 'cd /DIST && zip /c/gdb-multiarch-14.2.zip . -r'

CMD C:\msys64\usr\bin\bash.exe -l
Loading

0 comments on commit ba75605

Please sign in to comment.