3
0
mirror of https://github.com/XboxDev/nxdk.git synced 2026-02-05 03:55:49 +00:00

Merge pull request #1 from mborgerson/upstreaming

Various Improvements
This commit is contained in:
espes
2016-01-31 18:24:43 +10:00
139 changed files with 804 additions and 348 deletions

5
.gitignore vendored
View File

@ -1,7 +1,10 @@
.DS_Store
*.exe
*.exe.manifest
*.obj
*.o
*.xbe
*.inl
*.d
_*.cpp
_*.h

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "tools/extract-xiso"]
path = tools/extract-xiso
url = https://github.com/mborgerson/extract-xiso.git

190
Makefile
View File

@ -1,92 +1,142 @@
LLDLINK = /usr/local/opt/llvm/bin/lld -flavor link
CC = /usr/local/opt/llvm/bin/clang
CXX = /usr/local/opt/llvm/bin/clang++
ifeq ($(NXDK_DIR),)
NXDK_DIR = $(shell pwd)
endif
CGC = wine tools/cg/cgc.exe
ifeq ($(XBE_TITLE),)
XBE_TITLE = nxdk_app
endif
CXBE = tools/cxbe/cxbe
VP20COMPILER = tools/vp20compiler/vp20compiler
FP20COMPILER = tools/fp20compiler/fp20compiler
ifeq ($(OUTPUT_DIR),)
OUTPUT_DIR = bin
endif
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
LD = x86_64-w64-mingw32-ld
CC = clang
CXX = clang++
endif
ifeq ($(UNAME_S),Darwin)
LD = /usr/local/opt/llvm/bin/lld -flavor link
CC = /usr/local/opt/llvm/bin/clang
CXX = /usr/local/opt/llvm/bin/clang++
endif
CFLAGS = -target i386-pc-win32 -march=pentium3 \
-ffreestanding -nostdlib -fno-builtin -fno-exceptions \
-I. -Ixboxrt
TARGET = $(OUTPUT_DIR)/default.xbe
CGC = wine $(NXDK_DIR)/tools/cg/cgc.exe
CXBE = $(NXDK_DIR)/tools/cxbe/cxbe
VP20COMPILER = $(NXDK_DIR)/tools/vp20compiler/vp20compiler
FP20COMPILER = $(NXDK_DIR)/tools/fp20compiler/fp20compiler
EXTRACT_XISO = $(NXDK_DIR)/tools/extract-xiso/extract-xiso
TOOLS = cxbe vp20compiler fp20compiler extract-xiso
CFLAGS = -target i386-pc-win32 -march=pentium3 \
-ffreestanding -nostdlib -fno-builtin -fno-exceptions \
-I$(NXDK_DIR)/lib -I$(NXDK_DIR)/lib/xboxrt \
-Wno-ignored-attributes
SHADERINT = \
app/vs.vp \
app/ps.fp
ifeq ($(DEBUG),y)
CFLAGS += -g
endif
SHADEROBJ = \
app/vs.inl \
app/ps.inl
USB_SRCS = \
usb/host/ohci-hcd.c \
usb/core/message.c \
usb/core/hcd.c \
usb/core/hcd-pci.c \
usb/core/hub.c \
usb/core/usb.c \
usb/core/config.c \
usb/core/urb.c \
usb/core/buffer_simple.c \
usb/core/usb-debug.c \
usb/sys/BootUSB.c \
usb/sys/linuxwrapper.c \
usb/sys/xpad.c \
usb/sys/xremote.c \
usb/sys/usbkey.c \
usb/sys/usbmouse.c \
usb/misc/misc.c \
usb/misc/pci.c \
usb/misc/malloc.c
INCLUDES := $(wildcard xboxkrnl/*.h) \
$(wildcard xboxrt/*.h) \
$(wildcard hal/*.h) \
$(wildcard pbkit/*.h) \
$(wildcard app/*.h) \
$(SHADEROBJ)
SRCS := $(wildcard xboxrt/*.c) \
$(wildcard hal/*.c) \
$(wildcard pbkit/*.c) \
$(wildcard app/*.c) \
$(USB_SRCS)
include $(NXDK_DIR)/lib/Makefile
OBJS = $(SRCS:.c=.obj)
bin/default.xbe: app/main.exe
mkdir -p bin
$(CXBE) -OUT:bin/default.xbe -TITLE:0ldskoo1 app/main.exe
ifneq ($(GEN_XISO),)
TARGET += $(GEN_XISO)
endif
app/main.exe: $(OBJS)
$(LLDLINK) -subsystem:windows -dll -out:'$@' -entry:XboxCRT xboxkrnl/libxboxkrnl.lib $(OBJS)
V = 0
VE_0 := @
VE_1 :=
VE = $(VE_$(V))
%.obj: %.c ${INCLUDES}
$(CC) $(CFLAGS) -c -o '$@' '$<'
ifeq ($(V),1)
STDOUT_TO_NULL=
else
STDOUT_TO_NULL=>/dev/null
endif
app/vs.vp: app/vs.cg
$(CGC) -profile vp20 -o '$@' '$<'
DEPS := $(SRCS:.c=.c.d)
app/ps.fp: app/ps.cg
$(CGC) -profile fp20 -o '$@' '$<'
all: $(TARGET)
%.inl: %.vp
$(VP20COMPILER) '$<' > '$@'
$(OUTPUT_DIR)/default.xbe: $(OUTPUT_DIR) main.exe
@echo "[ CXBE ] $@"
$(VE)$(CXBE) -OUT:$@ -TITLE:$(XBE_TITLE) $^ $(STDOUT_TO_NULL)
%.inl: %.fp
$(FP20COMPILER) '$<' > '$@'
$(OUTPUT_DIR):
@mkdir -p $(OUTPUT_DIR);
ifneq ($(GEN_XISO),)
$(GEN_XISO): $(OUTPUT_DIR)/default.xbe
@echo "[ XISO ] $@"
$(VE) $(EXTRACT_XISO) -c $(OUTPUT_DIR) $(XISO_FLAGS) $@ $(STDOUT_TO_NULL)
endif
main.exe: $(OBJS) $(NXDK_DIR)/lib/xboxkrnl/libxboxkrnl.lib
@echo "[ LD ] $@"
ifeq ($(UNAME_S),Linux)
$(VE) $(LD) -m i386pe -shared --entry=_XboxCRT -o $@ $^
endif
ifeq ($(UNAME_S),Darwin)
$(VE) $(LD) -subsystem:windows -dll -out:'$@' -entry:XboxCRT $^
endif
%.obj: %.c
@echo "[ CC ] $@"
$(VE) $(CC) $(CFLAGS) -c -o '$@' '$<'
%.c.d: %.c
@echo "[ DEP ] $@"
$(VE) set -e; rm -f $@; \
$(CC) -M -MM -MG -MT '$*.obj' -MF $@ $(CFLAGS) $<; \
echo "\n$@ : $^\n" >> $@
%.inl: %.vs.cg
@echo "[ CG ] $@"
$(VE) $(CGC) -profile vp20 -o $@.$$$$ $< $(STDOUT_TO_NULL) && \
$(VP20COMPILER) $@.$$$$ > $@ && \
rm -rf $@.$$$$
%.inl: %.ps.cg
@echo "[ CG ] $@"
$(VE) $(CGC) -profile fp20 -o $@.$$$$ $< $(STDOUT_TO_NULL) && \
$(FP20COMPILER) $@.$$$$ > $@ && \
rm -rf $@.$$$$
tools: $(TOOLS)
.PHONY: tools $(TOOLS)
cxbe:
$(MAKE) -C tools/cxbe
@echo "[ BUILD ] $@"
$(VE)$(MAKE) -C $(NXDK_DIR)/tools/cxbe $(STDOUT_TO_NULL)
vp20compiler:
$(MAKE) -C tools/vp20compiler
@echo "[ BUILD ] $@"
$(VE)$(MAKE) -C $(NXDK_DIR)/tools/vp20compiler $(STDOUT_TO_NULL)
fp20compiler:
$(MAKE) -C tools/fp20compiler
@echo "[ BUILD ] $@"
$(VE)$(MAKE) -C $(NXDK_DIR)/tools/fp20compiler $(STDOUT_TO_NULL)
.PHONY: clean cxbe vp20compiler fp20compiler
extract-xiso:
@echo "[ BUILD ] $@"
$(VE)$(MAKE) -C $(NXDK_DIR)/tools/extract-xiso $(STDOUT_TO_NULL)
.PHONY: clean
clean:
rm -f bin/default.xbe app/main.exe $(OBJS) $(SHADERINT) $(SHADEROBJ)
$(VE)rm -f $(TARGET) \
main.exe main.exe.manifest \
$(OBJS) $(SHADER_OBJS) \
$(GEN_XISO)
.PHONY: distclean
distclean: clean
$(VE)$(MAKE) -C $(NXDK_DIR)/tools/extract-xiso clean $(STDOUT_TO_NULL)
$(VE)$(MAKE) -C $(NXDK_DIR)/tools/fp20compiler distclean $(STDOUT_TO_NULL)
$(VE)$(MAKE) -C $(NXDK_DIR)/tools/vp20compiler distclean $(STDOUT_TO_NULL)
$(VE)$(MAKE) -C $(NXDK_DIR)/tools/cxbe clean $(STDOUT_TO_NULL)
$(VE)bash -c "if [ -d $(OUTPUT_DIR) ]; then rmdir $(OUTPUT_DIR); fi"
$(VE)rm -f $(DEPS)
-include $(DEPS)

140
README.md
View File

@ -1,73 +1,111 @@
nxdk - the *new* open source xdk
nxdk - *the new open source xdk*
================================
What?
-----
nxdk is a software development kit for the original Xbox. nxdk is a revitalisation of [OpenXDK](http://openxdk.maturion.de/),
nxdk is a software development kit for the original Xbox. nxdk is a revitalization of [OpenXDK](http://openxdk.maturion.de/).
Notable features:
- No complicated cross-compiling or big library dependencies! Builds with `make` and just needs standard tools and llvm.
- 3D graphics! nxdk includes and expands on pbkit, a library for interfacing with the Xbox GPU.
nxdk is currently in early stages of development (read: it was hacked together over a weekend).
How?
----
You need:
- make
- A recent version of [clang](http://clang.llvm.org/) and [lld](http://lld.llvm.org/)
Status
------
nxdk is currently in early stages of development.
Getting Started
---------------
### Prerequisites
You will need the following tools:
- GNU make
- [clang](http://clang.llvm.org/)
- [GNU bison](https://www.gnu.org/software/bison/) and [flex](http://flex.sourceforge.net/)
- [wine](https://www.winehq.org/), to invoke the NVIDIA Cg compiler
- [lld](http://lld.llvm.org/) or the [MinGW](http://www.mingw.org/) flavor of GNU ld.
- [Git](http://git-scm.com/)
- *Temporarilly because I'm lazy*, [wine](https://www.winehq.org/) to invoke the NVIDIA Cg compiler
#### OS X
On OS X with [Homebrew](http://brew.sh/), this should do the job (XCode ships with make and bison and flex):
On OSX with [Homebrew](http://brew.sh/), this might do the job (XCode ships with make and bison and flex):
brew install wine llvm --with-lld --with-clang
brew install wine llvm --with-lld
#### Linux (Ubuntu)
On Ubuntu, the requried packages can be downloaded from the standard repositories:
Now you can compile your application and nxdk:
sudo apt-get install build-essential flex bison g++ clang wine binutils-mingw-w64 git
### Download nxdk
git clone https://github.com/xqemu/nxdk.git
cd nxdk
git submodule init
git submodule update --recursive
nxdk comes with a set of tools necessary for building. Build them with:
make tools
### Build Samples
To build the 0ldskoo1 sample, you can run:
cd samples/0ldskoo1
make
This will generate a single executable, default.xbe, in the bin/ directory which
can be executed on your Xbox (or XQEMU emulator).
### Generate XISO
To generate an ISO file that can be burned to a disc, or passed to the XQEMU
emulator via the `-drive index=1,media=cdrom,file=/path/to/your.iso` parameter,
define the `GEN_XISO` variable with the name of the ISO to be created in your
project Makefile. For example:
GEN_XISO=$(XBE_TITLE).iso
You can include additional files in the ISO (they must reside in the output
directory) like this:
...
ISO_DEPS = $(OUTPUT_DIR)/example.txt
GEN_XISO = $(XBE_TITLE).iso
include $(NXDK_DIR)/Makefile
$(GEN_XISO): $(ISO_DEPS)
$(OUTPUT_DIR)/example.txt:
echo "Hello" > $@
clean: clean_iso_deps
.PHONY: clean_iso_deps
clean_iso_deps:
rm -f $(ISO_DEPS)
For easy ISO generation, you can also just define it when you run `make`:
make -C samples/0ldskoo1 GEN_XISO=0ldskoo1.iso
Next Steps
----------
Copy one of the sample directories to get started. You can copy it anywhere you
like, but make sure that the `NXDK_DIR` variable in the Makefile points to
correct place. Then, in the directory, you can simply run `make`.
Credits
-------
- [OpenXDK](http://openxdk.maturion.de/) is inspiration for nxdk, and large parts are reused.
- License: GPLv2
- Large parts of [pbkit](http://forums.xbox-scene.com/index.php?/topic/573524-pbkit) by openxdkman are included, with modifications.
- License: Academic Free License
- A very barebones libc is included based on [lib43](https://github.com/lunixbochs/lib43)
- License: MIT
- vp20compiler is based on nvvertparse.c from [Mesa](http://www.mesa3d.org/)
- License: MIT
- [OpenXDK](http://openxdk.maturion.de/) is the inspiration for nxdk, and large parts of it have been reused. (License: GPLv2)
- Large parts of [pbkit](http://forums.xbox-scene.com/index.php?/topic/573524-pbkit), by openxdkman, are included, with modifications. (License: Academic Free License)
- A very barebones libc is included based on [lib43](https://github.com/lunixbochs/lib43) (License: MIT)
- vp20compiler is based on nvvertparse.c from [Mesa](http://www.mesa3d.org/) (License: MIT)
- fp20compiler is based on nvparse from the [NVIDIA SDK 9.52](https://www.nvidia.com/object/sdk-9.html).
- A (windows) copy of the NVIDIA Cg compiler 1.3 from the NVIDIA SDK is bundled.
- A (Windows) copy of the NVIDIA Cg compiler 1.3 from the NVIDIA SDK is bundled.
- extract-xiso developed by in et al. (License: BSD)
Code Overview
-------------
* `lib/hal/` - Barebones Hardware Abstraction Layer for the Xbox, from OpenXDK.
* `lib/pbkit/` - A low level library for interfacing with the Xbox GPU.
* `lib/usb/` - USB support from OpenXDK. Hacked together parts of an old Linux OHCI stack.
* `lib/xboxkrnl` - Stubs and import library for the interfacing with the Xbox kernel.
* `lib/xboxrt` - A very simple libc implementation.
* `tools/cxbe` - Simple converter for PE executables to the Xbox executable format, from OpenXDK.
* `tools/fp20compiler` - Translates register combiner descriptions to Xbox pushbuffer commands.
* `tools/vp20compiler` - Translates vertex program assembly to Xbox microcode.
* `tools/extract-xiso` - Generates and extracts ISO images compatible with the Xbox (and XQEMU).
* `samples/` - Sample applications to get started.
`app/` - code for your application. Currently contains the code for the "0ldskoo1" reversing challenge from 9447 CTF.
`bin/` - the output directory
`pbkit/` - A low level library for interfacing with the Xbox GPU.
`hal/` - Barebones Hardware Abstraction Layer for the Xbox, from OpenXDK.
`tools/cxbe` - Simple converter for PE executables to the Xbox executable format, from OpenXDK.
`tools/fp20compiler` - Translates register combiner descriptions to Xbox pushbuffer commands.
`tools/vp20compiler` - Translates vertex program assembly to Xbox microcode.
`usb/` - USB support from OpenXDK. Hacked together parts of an old Linux OHCI stack.
`xboxkrnl` - stubs and import library for the interfacing with the Xbox kernel.
`xboxrt` - A very simple libc implementation.

26
lib/Makefile Normal file
View File

@ -0,0 +1,26 @@
USB_SRCS := \
$(NXDK_DIR)/lib/usb/host/ohci-hcd.c \
$(NXDK_DIR)/lib/usb/core/message.c \
$(NXDK_DIR)/lib/usb/core/hcd.c \
$(NXDK_DIR)/lib/usb/core/hcd-pci.c \
$(NXDK_DIR)/lib/usb/core/hub.c \
$(NXDK_DIR)/lib/usb/core/usb.c \
$(NXDK_DIR)/lib/usb/core/config.c \
$(NXDK_DIR)/lib/usb/core/urb.c \
$(NXDK_DIR)/lib/usb/core/buffer_simple.c \
$(NXDK_DIR)/lib/usb/core/usb-debug.c \
$(NXDK_DIR)/lib/usb/sys/BootUSB.c \
$(NXDK_DIR)/lib/usb/sys/linuxwrapper.c \
$(NXDK_DIR)/lib/usb/sys/xpad.c \
$(NXDK_DIR)/lib/usb/sys/xremote.c \
$(NXDK_DIR)/lib/usb/sys/usbkey.c \
$(NXDK_DIR)/lib/usb/sys/usbmouse.c \
$(NXDK_DIR)/lib/usb/misc/misc.c \
$(NXDK_DIR)/lib/usb/misc/pci.c \
$(NXDK_DIR)/lib/usb/misc/malloc.c
SRCS += \
$(wildcard $(NXDK_DIR)/lib/xboxrt/*.c) \
$(wildcard $(NXDK_DIR)/lib/hal/*.c) \
$(wildcard $(NXDK_DIR)/lib/pbkit/*.c) \
$(USB_SRCS)

View File

Before

Width:  |  Height:  |  Size: 192 KiB

After

Width:  |  Height:  |  Size: 192 KiB

View File

Before

Width:  |  Height:  |  Size: 192 KiB

After

Width:  |  Height:  |  Size: 192 KiB

0
pbkit/nv20_shader.h → lib/pbkit/nv20_shader.h Executable file → Normal file
View File

0
pbkit/nv_objects.h → lib/pbkit/nv_objects.h Executable file → Normal file
View File

0
pbkit/outer.h → lib/pbkit/outer.h Executable file → Normal file
View File

0
pbkit/pbkit.c → lib/pbkit/pbkit.c Executable file → Normal file
View File

0
pbkit/pbkit.h → lib/pbkit/pbkit.h Executable file → Normal file
View File

View File

@ -254,7 +254,7 @@ static int usb_parse_interface(struct usb_interface *interface, unsigned char *b
return parsed;
}
int usb_parse_configuration(struct usb_host_config *config, char *buffer)
int usb_parse_configuration(struct usb_host_config *config, unsigned char *buffer)
{
int i, retval, size;
struct usb_descriptor_header *header;
@ -288,7 +288,7 @@ int usb_parse_configuration(struct usb_host_config *config, char *buffer)
for (i = 0; i < config->desc.bNumInterfaces; i++) {
int numskipped, len;
char *begin;
unsigned char *begin;
/* Skip over the rest of the Class Specific or Vendor */
/* Specific descriptors */
@ -487,7 +487,7 @@ int usb_get_configuration(struct usb_device *dev)
goto err;
}
dev->rawdescriptors[cfgno] = bigbuffer;
dev->rawdescriptors[cfgno] = (char *)bigbuffer;
result = usb_parse_configuration(&dev->config[cfgno], bigbuffer);
if (result > 0)

View File

@ -420,7 +420,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
/* non-generic request */
urb->status = hcd->driver->hub_control (hcd,
typeReq, wValue, wIndex,
ubuf, wLength);
(char *)ubuf, wLength);
break;
error:
/* "protocol stall" on error */

View File

@ -287,7 +287,7 @@ struct usbdevfs_hub_portinfo
#define MODULE_AUTHOR(a)
#define MODULE_DESCRIPTION(a)
#define MODULE_LICENSE(a)
#define MODULE_DEVICE_TABLE(type,name) void* module_table_##name=&name
#define MODULE_DEVICE_TABLE(type,name) const void* module_table_##name=&name
#define __devinit
#define __exit
@ -567,7 +567,7 @@ void my_wait_for_completion(struct completion*);
#define dev_warn(x,f,arg...) do {} while (0)
#define dev_err(x,f,arg...) do {} while (0)
#define pr_debug(x,f,arg...) do {} while (0)
#define usbprintk
#define usbprintk(f,arg...)
#endif

View File

@ -555,7 +555,7 @@ static unsigned char ucUSBtoAsciiShifted[256] =
'Z', //XKEY_Z,
'!', //XKEY_1,
'"', //XKEY_2,
'£', //XKEY_3,
'\xA3', //XKEY_3, (£)
'$', //XKEY_4,
'%', //XKEY_5,
'^', //XKEY_6,
@ -573,10 +573,10 @@ static unsigned char ucUSBtoAsciiShifted[256] =
'{', //XKEY_LBRACE,
'}', //XKEY_RBRACE,
'|', //XKEY_BACKSLASH,
'¬', //XKEY_GRAVE,
'\xAC', //XKEY_GRAVE, (¬)
':', //XKEY_SEMICOLON,
'@', //XKEY_QUOTE,
'¬', //XKEY_GRAVE,
'\xAC', //XKEY_GRAVE, (¬)
'<', //XKEY_COMMA,
'>', //XKEY_PERIOD,
'?', //XKEY_SLASH,

View File

@ -55,6 +55,7 @@ static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_i
usb_submit_urb(urb,GFP_ATOMIC);
usb_set_intfdata(intf,usbmouse);
return 0;
}

Some files were not shown because too many files have changed in this diff Show More