-
Notifications
You must be signed in to change notification settings - Fork 0
/
WedgeStub.s
115 lines (68 loc) · 1.64 KB
/
WedgeStub.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
PA_ROM equ 0x00c00000
Me equ 0x310000
Middle equ 0x320000
NK equ 0x340000
Magic equ 'Wdg_'
MACRO
MakeFunction &fnName
EXPORT &fnName[DS]
EXPORT .&fnName[PR]
TC &fnName[TC], &fnName[DS]
CSECT &fnName[DS]
DC.L .&fnName[PR]
DC.L TOC[tc0]
CSECT .&fnName[PR]
FUNCTION .&fnName[PR]
ENDM
MACRO
lisori ®, &val
lis ®, ((&val) >> 16) & 0xffff
ori ®, ®, (&val) & 0xffff
ENDM
MakeFunction __start
import .Wedge
; Pointers in r20, scratch values in r0
; Need to reference MagicSentinel so that it gets put before the string table
; (There is probably a better way)
b * + 8
dc.l MagicSentinel{RO}
; Initial debug log
lisori r20, PA_ROM + Middle
lisori r0, 'WgLg'
stw r0, -8(r20)
; Search for the string table (tested, works)
bl * + 4
mflr r20 ; start here
@a lwzu r0, 4(r20) ; find the sentinel
xoris r0, r0, Magic >> 16
cmplwi r0, Magic & 0xffff
bne @a
@b lwzu r0, 4(r20) ; skip the csect padding
cmpwi r0, 0
beq @b
; Set RTOC and save string table ptr at -4(RTOC)
lisori RTOC, PA_ROM + Middle - 64
stw r20, -4(RTOC)
; Get a stack, just below the waistline
lisori SP, PA_ROM + Middle - 128
; Go
li r10, 0 ; isDryRun argument
b .Wedge
MakeFunction NanoKernel
lisori r0, PA_ROM + NK
mtlr r0
blr
MakeFunction asm_putc
; Just a stub/test function for now
lisori r6, PA_ROM + Middle
lwz r5, -4(r6)
; lbz r4, 0(r3)
stbx r3, r5, r6
addi r5, r5, 1
stw r5, -4(r6)
li r3, 0
blr
; Insert a sentinel value just before the C string table
; (Requires PPCLink -codeorder source -roistext on)
csect MagicSentinel[RO]
dc.l Magic