Skip to content

Commit

Permalink
Integrated kmc gcc for matching libgultra
Browse files Browse the repository at this point in the history
Any source files in the src/ultra directory will be compiled using it
Moved epiread and sptaskyield as examples
  • Loading branch information
Mr-Wiseguy committed Mar 25, 2021
1 parent f03f08a commit 3b4a233
Show file tree
Hide file tree
Showing 52 changed files with 625 additions and 26 deletions.
13 changes: 11 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ async def main():
depfile="$out.d",
deps="gcc")
n.newline()
# KMC gcc crashes if the argument string is too long, so preprocess input separately to minimize arguments
# KMC gcc doesn't support input on stdin, so a temp file has to be made for the preprocessor output
n.rule("cc_kmc",
command=f"bash -o pipefail -c '{cpp} -Iver/$version/build/include -Iinclude -Iinclude/PR -Isrc -D _LANGUAGE_C -D _FINALROM -D VERSION=$version -ffreestanding -DF3DEX_GBI_2 -D_MIPS_SZLONG=32 {args.cflags} -MD -MF $out.d $in -o $out.i && export WINEPATH=tools/kmc/BIN && wine exew32 gcc -O3 -c -G0 -mgp32 -mfp32 -mips3 $out.i -o $out' && {cross}strip $out -N $in",
description="dsl $in",
depfile="$out.d",
deps="gcc")
n.newline()

with open("tools/permuter_settings.toml", "w") as f:
version = versions[0]
Expand Down Expand Up @@ -287,7 +295,7 @@ async def main():
n.newline()

n.rule("as",
command="${cross}as -EB -march=vr4300 -mtune=vr4300 -Iinclude $in -o $out",
command="${cross}as -EB -O0 -G0 -mtune=vr4300 -march=vr4300 -mabi=32 -Iinclude $in -o $out",
description="assemble $in")
n.newline()

Expand Down Expand Up @@ -561,9 +569,10 @@ def add_generated_header(h: str):

for version in versions:
s_glob = "ver/" + version + "/" + re.sub("src/", "asm/nonmatchings/", c_file)[:-2] + "/*.s"
rule = "cc_kmc" if c_file.startswith("src/ultra/") else ("cc_dsl" if status == 0 else "cc")
n.build(
obj(c_file),
"cc_dsl" if status == 0 else "cc",
rule,
c_file,
implicit = None if not args.depend_on_s else glob(s_glob),
order_only="generated_headers_" + version,
Expand Down
2 changes: 1 addition & 1 deletion src/os/code_47ae0_len_e0.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

INCLUDE_ASM(s32, "os/code_47ae0_len_e0", osSpGetStatus);

INCLUDE_ASM(s32, "os/code_47ae0_len_e0", osSpSetStatus);
INCLUDE_ASM(s32, "os/code_47ae0_len_e0", __osSpSetStatus);

INCLUDE_ASM(s32, "os/code_47ae0_len_e0", osSpSetPc);

Expand Down
12 changes: 0 additions & 12 deletions src/os/osEPiReadIo.c

This file was deleted.

3 changes: 0 additions & 3 deletions src/os/osSpTaskYield.c

This file was deleted.

10 changes: 10 additions & 0 deletions src/ultra/epiread.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <os_internal.h>
#include "piint.h"

s32 osEPiReadIo(OSPiHandle *pihandle, u32 devAddr, u32 *data) {
register s32 ret;
__osPiGetAccess();
ret = osEPiRawReadIo(pihandle, devAddr, data);
__osPiRelAccess();
return ret;
}
145 changes: 145 additions & 0 deletions src/ultra/piint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#ifndef _PIINT_H
#define _PIINT_H
#include <os_internal.h>
#include <rcp.h>

//https://github.com/LuigiBlood/64dd/wiki/Memory-Map

#define LEO_BASE_REG 0x05000000

#define LEO_CMD (LEO_BASE_REG + 0x508)
#define LEO_STATUS (LEO_BASE_REG + 0x508)

#define LEO_BM_CTL (LEO_BASE_REG + 0x510)
#define LEO_BM_STATUS (LEO_BASE_REG + 0x510)

#define LEO_SEQ_CTL (LEO_BASE_REG + 0x518)
#define LEO_SEQ_STATUS (LEO_BASE_REG + 0x518)

#define LEO_C2_BUFF (LEO_BASE_REG + 0x000) //C2 Sector Buffer
#define LEO_SECTOR_BUFF (LEO_BASE_REG + 0x400) //Data Sector Buffer
#define LEO_DATA (LEO_BASE_REG + 0x500) //Data
#define LEO_MISC_REG (LEO_BASE_REG + 0x504) //Misc Register
#define LEO_CUR_TK (LEO_BASE_REG + 0x50C) //Current Track
#define LEO_ERR_SECTOR (LEO_BASE_REG + 0x514) //Sector Error Status
#define LEO_CUR_SECTOR (LEO_BASE_REG + 0x51C) //Current Sector
#define LEO_HARD_RESET (LEO_BASE_REG + 0x520) //Hard Reset
#define LEO_C1_S0 (LEO_BASE_REG + 0x524) //C1
#define LEO_HOST_SECBYTE (LEO_BASE_REG + 0x528) //Sector Size (in bytes)
#define LEO_C1_S2 (LEO_BASE_REG + 0x52C) //C1
#define LEO_SEC_BYTE (LEO_BASE_REG + 0x530) //Sectors per Block, Full Size
#define LEO_C1_S4 (LEO_BASE_REG + 0x534) //C1
#define LEO_C1_S6 (LEO_BASE_REG + 0x538) //C1
#define LEO_CUR_ADDR (LEO_BASE_REG + 0x53C) //Current Address?
#define LEO_ID_REG (LEO_BASE_REG + 0x540) //ID
#define LEO_TEST_REG (LEO_BASE_REG + 0x544) //Test Read
#define LEO_TEST_PIN_SEL (LEO_BASE_REG + 0x548) //Test Write
#define LEO_RAM_ADDR (LEO_BASE_REG + 0x580) //Microsequencer RAM

#define LEO_STATUS_PRESENCE_MASK 0xFFFF

#define LEO_STATUS_DATA_REQUEST 0x40000000
#define LEO_STATUS_C2_TRANSFER 0x10000000
#define LEO_STATUS_BUFFER_MANAGER_ERROR 0x08000000
#define LEO_STATUS_BUFFER_MANAGER_INTERRUPT 0x04000000
#define LEO_STATUS_MECHANIC_INTERRUPT 0x02000000
#define LEO_STATUS_DISK_PRESENT 0x01000000
#define LEO_STATUS_BUSY_STATE 0x00800000
#define LEO_STATUS_RESET_STATE 0x00400000
#define LEO_STATUS_MOTOR_NOT_SPINNING 0x00100000
#define LEO_STATUS_HEAD_RETRACTED 0x00080000
#define LEO_STATUS_WRITE_PROTECT_ERROR 0x00040000
#define LEO_STATUS_MECHANIC_ERROR 0x00020000
#define LEO_STATUS_DISK_CHANGE 0x00010000

#define LEO_STATUS_MODE_MASK (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED)
#define LEO_STATUS_MODE_SLEEP (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED)
#define LEO_STATUS_MODE_STANDBY (LEO_STATUS_HEAD_RETRACTED)
#define LEO_STATUS_MODE_ACTIVE 0

#define LEO_CUR_TK_INDEX_LOCK 0x60000000

#define LEO_BM_STATUS_RUNNING 0x80000000 //Running
#define LEO_BM_STATUS_ERROR 0x04000000 //Error
#define LEO_BM_STATUS_MICRO 0x02000000 //Micro Status?
#define LEO_BM_STATUS_BLOCK 0x01000000 //Block Transfer
#define LEO_BM_STATUS_C1CORRECTION 0x00800000 //C1 Correction
#define LEO_BM_STATUS_C1DOUBLE 0x00400000 //C1 Double
#define LEO_BM_STATUS_C1SINGLE 0x00200000 //C1 Single
#define LEO_BM_STATUS_C1ERROR 0x00010000 //C1 Error

#define LEO_BM_CTL_START 0x80000000 //Start Buffer Manager
#define LEO_BM_CTL_MODE 0x40000000 //Buffer Manager Mode
#define LEO_BM_CTL_IMASK 0x20000000 //BM Interrupt Mask
#define LEO_BM_CTL_RESET 0x10000000 //Buffer Manager Reset
#define LEO_BM_CTL_DISABLE_OR 0x08000000 //Disable OR Check?
#define LEO_BM_CTL_DISABLE_C1 0x04000000 //Disable C1 Correction
#define LEO_BM_CTL_BLOCK 0x02000000 //Block Transfer
#define LEO_BM_CTL_CLR_MECHANIC_INTR 0x01000000 //Mechanic Interrupt Reset

#define LEO_BM_CTL_CONTROL_MASK 0xFF000000
#define LEO_BM_CTL_SECTOR_MASK 0x00FF0000
#define LEO_BM_CTL_SECTOR_SHIFT 16

#define LEO_CMD_TYPE_0 0 //TODO: name
#define LEO_CMD_TYPE_1 1 //TODO: name
#define LEO_CMD_TYPE_2 2 //TODO: name

#define LEO_ERROR_GOOD 0
#define LEO_ERROR_4 4 //maybe busy?
#define LEO_ERROR_22 22 //
#define LEO_ERROR_23 23 //unrecovered read error?
#define LEO_ERROR_24 24 //no reference position found?
#define LEO_ERROR_29 29 //

extern OSDevMgr __osPiDevMgr;
extern OSPiHandle *__osCurrentHandle[2];
extern OSPiHandle CartRomHandle;
extern OSPiHandle LeoDiskHandle;
extern OSMesgQueue __osPiAccessQueue;
extern u32 __osPiAccessQueueEnabled;

int __osPiDeviceBusy(void);
void __osDevMgrMain(void *);
void __osPiCreateAccessQueue(void);
void __osPiRelAccess(void);
void __osPiGetAccess(void);
OSMesgQueue *osPiGetCmdQueue(void);

#define OS_RAMROM_STACKSIZE 1024

#define WAIT_ON_IOBUSY(stat) \
stat = IO_READ(PI_STATUS_REG); \
while (stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) \
stat = IO_READ(PI_STATUS_REG);

#define UPDATE_REG(reg, var) \
if (cHandle->var != pihandle->var) \
IO_WRITE(reg, pihandle->var);

#define EPI_SYNC(pihandle, stat, domain) \
\
WAIT_ON_IOBUSY(stat) \
\
domain = pihandle->domain; \
if (__osCurrentHandle[domain] != pihandle) \
{ \
OSPiHandle *cHandle = __osCurrentHandle[domain]; \
if (domain == PI_DOMAIN1) \
{ \
UPDATE_REG(PI_BSD_DOM1_LAT_REG, latency); \
UPDATE_REG(PI_BSD_DOM1_PGS_REG, pageSize); \
UPDATE_REG(PI_BSD_DOM1_RLS_REG, relDuration); \
UPDATE_REG(PI_BSD_DOM1_PWD_REG, pulse); \
} \
else \
{ \
UPDATE_REG(PI_BSD_DOM2_LAT_REG, latency); \
UPDATE_REG(PI_BSD_DOM2_PGS_REG, pageSize); \
UPDATE_REG(PI_BSD_DOM2_RLS_REG, relDuration); \
UPDATE_REG(PI_BSD_DOM2_PWD_REG, pulse); \
} \
__osCurrentHandle[domain] = pihandle; \
}

#endif
6 changes: 6 additions & 0 deletions src/ultra/sptaskyield.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <os_internal.h>
#include <rcp.h>

void osSpTaskYield(void) {
__osSpSetStatus(SP_SET_YIELD);
}
Binary file added tools/kmc/BIN/AR.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/AR.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/AS.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/AS.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/CC1.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/CC1.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/CELF.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/CELF.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/CPP.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/CPP.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/ELFTBL.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/ELFTBL.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/EXEW32.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/GCC.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/GCC.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/LD.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/LD.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/MAKE.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/MAKE.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/MAKEMASK.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/MAKEMASK.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/MILD.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/MILD.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/NM.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/NM.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/OBJDUMP.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/OBJDUMP.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/RANLIB.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/RANLIB.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/SGI2GAS.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/SGI2GAS.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/SIZE.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/SIZE.OUT
Binary file not shown.
Binary file added tools/kmc/BIN/STRIP.EXE
Binary file not shown.
Binary file added tools/kmc/BIN/STRIP.OUT
Binary file not shown.
Loading

0 comments on commit 3b4a233

Please sign in to comment.