forked from pixelomer/PongoBRIX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pongo.h
216 lines (188 loc) · 6.45 KB
/
pongo.h
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
//
// Copyright (c) 2019-2020 checkra1n team
// This file is part of pongoOS.
//
#ifndef __PONGO_H
#define __PONGO_H
#include <mach-o/loader.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define DT_KEY_LEN 0x20
struct Boot_Video {
unsigned long v_baseAddr; /* Base address of video memory */
unsigned long v_display; /* Display Code (if Applicable */
unsigned long v_rowBytes; /* Number of bytes per pixel row */
unsigned long v_width; /* Width */
unsigned long v_height; /* Height */
unsigned long v_depth; /* Pixel Depth and other parameters */
};
typedef struct boot_args {
uint16_t Revision; /* Revision of boot_args structure */
uint16_t Version; /* Version of boot_args structure */
uint64_t virtBase; /* Virtual base of memory */
uint64_t physBase; /* Physical base of memory */
uint64_t memSize; /* Size of memory */
uint64_t topOfKernelData; /* Highest physical address used in kernel data area */
struct Boot_Video Video; /* Video Information */
uint32_t machineType; /* Machine Type */
void *deviceTreeP; /* Base of flattened device tree */
uint32_t deviceTreeLength; /* Length of flattened tree */
char CommandLine[256]; /* Passed in command line */
uint64_t bootFlags; /* Additional flags specified by the bootloader */
uint64_t memSizeActual; /* Actual size of memory */
} boot_args;
typedef struct
{
uint32_t nprop;
uint32_t nchld;
char prop[];
} dt_node_t;
typedef struct
{
char key[DT_KEY_LEN];
uint32_t len;
char val[];
} dt_prop_t;
typedef struct
{
const char* name;
dt_node_t* node;
} dt_find_cb_t;
typedef struct
{
const char* key;
void* val;
uint32_t len;
} dt_prop_cb_t;
struct memmap {
uint64_t addr;
uint64_t size;
};
/* Device Tree manipulation */
extern int dt_check(void* mem, uint32_t size, uint32_t* offp);
extern int dt_parse(dt_node_t* node, int depth, uint32_t* offp, int (*cb_node)(void*, dt_node_t*), void* cbn_arg, int (*cb_prop)(void*, dt_node_t*, int, const char*, void*, uint32_t), void* cbp_arg);
extern dt_node_t* dt_find(dt_node_t* node, const char* name);
extern void* dt_prop(dt_node_t* node, const char* key, uint32_t* lenp);
extern struct memmap* dt_alloc_memmap(dt_node_t* node, const char* name);
extern uint32_t dt_get_u32_prop(const char* device, const char* prop);
extern uint64_t dt_get_u64_prop(const char* device, const char* prop);
extern uint64_t dt_get_u64_prop_i(const char* device, const char* prop, uint32_t idx);
/* Task management */
#define TASK_CAN_CRASH 1
#define TASK_LINKED 2
#define TASK_IRQ_HANDLER 4
#define TASK_PREEMPT 8
#define TASK_MASK_NEXT_IRQ 16
#define TASK_HAS_EXITED 32
#define TASK_WAS_LINKED 64
#define TASK_HAS_CRASHED 128
struct event {
struct task* task_head;
};
struct task {
uint64_t x[30];
uint64_t lr;
uint64_t sp;
uint64_t runcnt;
uint64_t real_lr;
uint64_t fp[18];
struct task* irq_ret;
uint64_t entry;
void* task_ctx;
uint64_t stack[0x2000 / 8];
uint64_t irq_count;
uint32_t irq_type;
uint64_t wait_until;
uint32_t sched_count;
uint32_t pid;
struct task* eq_next;
uint64_t anchor[0];
uint64_t t_flags;
char name[32];
uint32_t flags;
struct task* next;
struct task* prev;
void (*crash_callback)();
};
extern struct task *task_current();
extern void task_switch_irq(struct task* to_task);
extern void task_exit_irq();
extern void task_switch(struct task* to_task);
extern void task_link(struct task* to_task);
extern void task_unlink(struct task* to_task);
extern void task_irq_dispatch(uint32_t intr);
extern void task_yield_asserted();
extern void task_register_unlinked(struct task* task, void (*entry)());
extern void task_register_irq(struct task* task, void (*entry)(), int irq_id);
extern void register_irq_handler(uint16_t irq_v, struct task *irq_handler);
/* Core functions */
struct pongo_exports {
const char* name;
void * value;
};
extern void panic(const char* string);
extern void spin(uint32_t usec);
extern uint64_t get_ticks();
extern void usleep(uint32_t usec);
extern void sleep(uint32_t sec);
extern volatile uint8_t get_el(void);
extern void cache_invalidate(void *address, size_t size);
extern void cache_clean_and_invalidate(void *address, size_t size);
extern void clock_gate(uint64_t addr, char val);
extern void disable_preemption();
extern void enable_preemption();
extern void enable_interrupts();
extern void disable_interrupts();
/* Shell */
extern void command_putc(char val);
extern void command_puts(const char* val);
extern void command_register(const char* name, const char* desc, void (*cb)(const char* cmd, char* args));
extern char* command_tokenize(char* str, uint32_t strbufsz);
extern void queue_rx_string(char* string);
/* WDT */
extern void wdt_reset();
extern void wdt_enable();
extern void wdt_disable();
/* Global variables */
extern void (*preboot_hook)();
extern boot_args * gBootArgs;
extern void* gEntryPoint;
extern dt_node_t *gDeviceTree;
extern uint64_t gIOBase;
extern uint64_t gPMGRBase;
extern char* gDevType;
extern void* ramdisk_buf;
extern uint32_t ramdisk_size;
extern uint32_t autoboot_count;
extern uint8_t * loader_xfer_recv_data;
extern uint32_t loader_xfer_recv_count;
/* Screen */
extern char overflow_mode;
extern uint32_t* gFramebuffer;
extern uint32_t gWidth;
extern uint32_t gHeight;
extern uint32_t gRowPixels;
extern uint32_t y_cursor;
extern uint32_t x_cursor;
extern uint8_t scale_factor;
#endif