Skip to content

Commit b9dfe51

Browse files
Rework the builtin kernel code
- provide imports in the linker to reduce code size - btu_task no longer deadlocks - fsa shim no longer crashes when being closed
1 parent 96697a0 commit b9dfe51

File tree

14 files changed

+100
-55
lines changed

14 files changed

+100
-55
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Don't worry if building the emulator itself fails due to missing SDL headers. Ju
2121
1. Download the `bluubomb` binary and the `sd_kernels.zip` from the [releases page](https://github.com/GaryOderNichts/bluubomb/releases).
2222
Copy a kernel binary of your choice from the `sd_kernels.zip` to the root of your SD Card and rename it to `bluu_kern.bin`.
2323
Take a look at [Kernel binaries](#kernel-binaries) for more information.
24-
1. Power on the Wii U, insert your SD Card and press the sync button.
24+
1. Power on the Wii U, insert your SD Card and press the sync button. Make sure there are no other controllers connected.
2525
1. Open a new terminal and make the bluubomb file executable by running `chmod +x bluubomb`
2626
1. Run `sudo ./bluubomb` and wait for the pairing process to complete.
2727
This might take a minute.

arm_kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ CFLAGS := -Wall -std=gnu11 -Os -flto $(MACHDEP) $(INCLUDE)
4545
ASFLAGS := $(MACHDEP)
4646

4747
LDFLAGS := -nostartfiles -nodefaultlibs -mbig-endian -flto \
48-
-Wl,-Map,$(notdir $*.map),-T $(TOPDIR)/link.ld
48+
-Wl,-L $(TOPDIR) -Wl,-Map,$(notdir $*.map),-T $(TOPDIR)/link.ld
4949

5050
LIBS := -lgcc
5151

arm_kernel/imports.ld

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
PROVIDE(kernel_memcpy = 0x08131D04);
2+
PROVIDE(kernel_memset = 0x08131DA0);
3+
PROVIDE(kernel_strncpy = 0x081329B8);
4+
PROVIDE(kernel_disable_interrupts = 0x0812E778);
5+
PROVIDE(kernel_enable_interrupts = 0x0812E78C);
6+
PROVIDE(kernel_bsp_command_5 = 0x0812EC40);
7+
PROVIDE(kernel_vsnprintf = 0x0813293c);
8+
PROVIDE(kernel_snprintf = 0x08132988);
9+
PROVIDE(kernel_strncmp = 0x08132a14);
10+
PROVIDE(kernel_invalidate_icache = 0x0812DCF0);
11+
PROVIDE(kernel_invalidate_dcache = 0x08120164);
12+
PROVIDE(kernel_ios_shutdown = 0xffffdc48);
13+
PROVIDE(kernel_ios_reset = 0x08129760);
14+
PROVIDE(kernel_flush_dcache = 0x08120160);
15+
PROVIDE(setClientCapability = 0x081260a8);

arm_kernel/link.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
OUTPUT_ARCH(arm)
22

3+
INCLUDE "imports.ld"
4+
35
SECTIONS {
46
. = (0x08135000);
57

arm_kernel/source/imports.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
#pragma once
22

33
#include <stdint.h>
4+
#include <stdarg.h>
45

56
#define ALIGNAS(x, align) (((x) + ((align) - 1)) & ~((align) - 1))
67

78
// Kernel functions
8-
9-
#define kernel_memcpy ((void* (*)(void*, const void*, int)) 0x08131D04)
10-
#define kernel_memset ((void* (*)(void*, int, unsigned int)) 0x08131DA0)
11-
#define kernel_strncpy ((char* (*)(char*, const char*, unsigned int)) 0x081329B8)
12-
#define kernel_disable_interrupts ((int (*)(void)) 0x0812E778)
13-
#define kernel_enable_interrupts ((int (*)(int)) 0x0812E78C)
14-
#define kernel_bsp_command_5 ((int (*)(const char*, int offset, const char*, int size, void *buffer)) 0x0812EC40)
15-
#define kernel_vsnprintf ((int (*)(char *, size_t, const char *, va_list)) 0x0813293c)
16-
#define kernel_snprintf ((int (*)(char *, size_t, const char *, ...)) 0x08132988)
17-
#define kernel_strncmp ((int (*)(const char *, const char *, size_t)) 0x08132a14)
18-
#define kernel_invalidate_icache ((void (*)(void)) 0x0812DCF0)
19-
#define kernel_invalidate_dcache ((void (*)(unsigned int, unsigned int)) 0x08120164)
20-
#define kernel_ios_shutdown ((void (*)(int)) 0xffffdc48)
21-
#define kernel_ios_reset ((void (*)(void)) 0x08129760)
22-
#define kernel_flush_dcache ((void (*)(unsigned int, unsigned int)) 0x08120160)
9+
void* kernel_memcpy(void*, const void*, int);
10+
void* kernel_memset(void*, int, unsigned int);
11+
char* kernel_strncpy(char*, const char*, unsigned int);
12+
int kernel_disable_interrupts(void);
13+
int kernel_enable_interrupts(int);
14+
int kernel_bsp_command_5(const char*, int offset, const char*, int size, void *buffer);
15+
int kernel_vsnprintf(char *, size_t, const char *, va_list);
16+
int kernel_snprintf(char *, size_t, const char *, ...);
17+
int kernel_strncmp(const char *, const char *, size_t);
18+
void kernel_invalidate_icache(void);
19+
void kernel_invalidate_dcache(unsigned int, unsigned int);
20+
void kernel_ios_shutdown(int);
21+
void kernel_ios_reset(void);
22+
void kernel_flush_dcache(unsigned int, unsigned int);
23+
int setClientCapability(int pid, int fid, uint64_t mask);
2324

2425
static inline unsigned int disable_mmu(void)
2526
{

arm_kernel/source/main.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "../../arm_user/arm_user.bin.h"
55

6+
#define ARM_B(addr, func) (0xEA000000 | ((((uint32_t) (func) - (uint32_t) (addr) -8) >> 2) & 0x00FFFFFF))
67
#define ARM_BL(addr, func) (0xEB000000 | ((((uint32_t)(func) - (uint32_t)(addr) - 8) >> 2) & 0x00FFFFFF))
78

89
#define SD_KERNEL_CODE_LOCATION 0x08135400
@@ -28,15 +29,7 @@ int _main()
2829
*(volatile uint32_t*) 0x08129a24 = 0xe12fff1e; // bx lr
2930

3031
// replace the custom kernel syscall
31-
*(volatile uint32_t*) 0x0812cd2c = ARM_BL(0x0812cd2c, kernel_syscall_0x81);
32-
33-
// patch ios-pad fsa handle check to always succeed
34-
*(volatile uint32_t*) 0x11f7f418 = 0xe3a00001; // mov r0, #1
35-
*(volatile uint32_t*) 0x11f7f41c = 0xe12fff1e; // bx lr
36-
37-
// give everything full access to fsa (we need this to access the sd from ios-pad)
38-
*(volatile uint32_t*) 0x107043e4 = 0xe3e02000; // mvn r2, #0
39-
*(volatile uint32_t*) 0x107043e8 = 0xe3e03000; // mvn r3, #0
32+
*(volatile uint32_t*) 0x0812cd2c = ARM_B(0x0812cd2c, kernel_syscall_0x81);
4033

4134
// load arm_user
4235
kernel_memcpy((void*) 0x11f85800, arm_user, arm_user_size);
@@ -45,11 +38,14 @@ int _main()
4538
restore_mmu(control_register);
4639

4740
// invalidate all cache
48-
// kernel_invalidate_dcache(0x081298BC, 0x4001);
41+
kernel_invalidate_dcache(0x081298BC, 0x4001);
4942
kernel_invalidate_icache();
5043

5144
// restore interrupts
5245
kernel_enable_interrupts(level);
5346

47+
// give IOS-PAD full access to FS
48+
setClientCapability(6, 11, 0xFFFFFFFFFFFFFFFF);
49+
5450
return 0;
5551
}

arm_user/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ CFLAGS := -Wall -std=gnu11 -Os -flto $(MACHDEP) $(INCLUDE)
4545
ASFLAGS := $(MACHDEP)
4646

4747
LDFLAGS := -nostartfiles -nodefaultlibs -mbig-endian -flto \
48-
-Wl,-Map,$(notdir $*.map),-T $(TOPDIR)/link.ld
48+
-Wl,-L $(TOPDIR) -Wl,-Map,$(notdir $*.map),-T $(TOPDIR)/link.ld
4949

5050
LIBS := -lgcc
5151

arm_user/imports.ld

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
PROVIDE(IOS_CancelThread = 0x11f82e78);
2+
PROVIDE(IOS_AllocAligned = 0x11f82fa8);
3+
PROVIDE(IOS_Free = 0x11f82fb0);
4+
PROVIDE(IOS_Open = 0x11f83000);
5+
PROVIDE(IOS_Close = 0x11f83008);
6+
PROVIDE(IOS_Ioctlv = 0x11f83030);
7+
PROVIDE(IOS_Shutdown = 0x11f831f8);
8+
9+
PROVIDE(kernel_syscall_0x81 = 0x11f83270);
10+
11+
PROVIDE(strncpy = 0x11f83e80);
12+
PROVIDE(memset = 0x11f83488);
13+
14+
PROVIDE(FSAShimOpen = 0x11f7f7fc);
15+
PROVIDE(FSAShimClose = 0x11f7f728);
16+
17+
PROVIDE(FSA_AllocIoBuf = 0x11f7f554);
18+
PROVIDE(FSA_FreeIoBuf = 0x11f7f59c);
19+
20+
PROVIDE(FSA_CloseFile = 0x11f7fae8);
21+
PROVIDE(FSA_StatFile = 0x11f7fbc4);
22+
PROVIDE(FSA_ReadWriteFile = 0x11f7fccc);
23+
PROVIDE(FSA_OpenFile = 0x11f80024);

arm_user/link.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
OUTPUT_ARCH(arm)
22

3+
INCLUDE "imports.ld"
4+
35
SECTIONS {
46
. = (0x11f85800);
57

arm_user/source/crt0.s

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@
66
.type _main, %function
77

88
_start:
9-
b _main
9+
bl _main
10+
11+
@ restore the original stack pointer
12+
ldr sp, =0x12156424
13+
14+
@ jump back into the btu_task loop
15+
ldr pc, =0x11f1bebc

0 commit comments

Comments
 (0)