fns.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "../port/portfns.h"
  10. void intrac(Proc*);
  11. void acinit(void);
  12. int acpiinit(void);
  13. void acpistart(void);
  14. int mpacpi(int);
  15. void actrapenable(int, char* (*)(Ureg*, void*), void*, char*);
  16. void apicipi(int);
  17. void apicpri(int);
  18. void acsysret(void);
  19. void actouser(void);
  20. void runacore(void);
  21. void aamloop(int);
  22. Dirtab* addarchfile(char*, int,
  23. int32_t(*)(Chan*,void*,int32_t,int64_t),
  24. int32_t(*)(Chan*,void*,int32_t,int64_t));
  25. void acmmuswitch(void);
  26. void acmodeset(int);
  27. void archfmtinstall(void);
  28. void archidle(void);
  29. int archmmu(void);
  30. int asmfree(uintmem, uintmem, int);
  31. uint64_t asmalloc(uintmem, uintmem, int, int);
  32. void asminit(void);
  33. void asmmapinit(uintmem, uintmem, int);
  34. extern void asmmodinit(uint32_t, uint32_t, char*);
  35. void noerrorsleft(void);
  36. void archinit(void);
  37. void archreset(void);
  38. int64_t archhz(void);
  39. int cgaprint(int off, char *fmt, ...);
  40. int cgaclearln(int off, int c);
  41. void cgaconsputs(char*, int);
  42. void cgainit(void);
  43. void cgapost(int);
  44. void checkpa(char*, uintmem);
  45. #define clearmmucache() /* x86 doesn't have one */
  46. void (*coherence)(void);
  47. int corecolor(int);
  48. uint32_t cpuid(uint32_t, uint32_t, uint32_t[4]);
  49. int cpuidinfo(uint32_t, uint32_t, uint32_t[4]);
  50. char *cpuidname(uint32_t *);
  51. int dbgprint(char*, ...);
  52. int decref(Ref*);
  53. void delay(int);
  54. void dumpmmu(Proc*);
  55. void dumpmmuwalk(uint64_t pa);
  56. void dumpptepg(int lvl,uintptr_t pa);
  57. #define evenaddr(x) /* x86 doesn't care */
  58. int fpudevprocio(Proc*, void*, int32_t, uintptr_t, int);
  59. void fpuinit(void);
  60. void fpunoted(void);
  61. void fpunotify(Ureg*);
  62. void fpuprocrestore(Proc*);
  63. void fpuprocsave(Proc*);
  64. void fpusysprocsetup(Proc*);
  65. void fpusysrfork(Ureg*);
  66. void fpusysrforkchild(Proc*, Proc*);
  67. Mach* getac(Proc*, int);
  68. char* getconf(char*);
  69. void gdb2ureg(uintptr_t *g, Ureg *u);
  70. void halt(void);
  71. void hardhalt(void);
  72. void mouseenable(void);
  73. void i8042systemreset(void);
  74. int mousecmd(int);
  75. void mouseenable(void);
  76. void i8250console(char*);
  77. void* i8250alloc(int, int, int);
  78. int64_t i8254hz(uint32_t *info0, uint32_t *info1);
  79. void idlehands(void);
  80. void acidthandlers(void);
  81. void idthandlers(void);
  82. int inb(int);
  83. int incref(Ref*);
  84. void insb(int, void*, int);
  85. uint16_t ins(int);
  86. void inss(int, void*, int);
  87. uint32_t inl(int);
  88. void insl(int, void*, int);
  89. int intrdisable(void*);
  90. void* intrenable(int, void (*)(Ureg*, void*), void*, int, char*);
  91. void invlpg(uintptr_t);
  92. void iofree(int);
  93. void ioinit(void);
  94. int iounused(int, int);
  95. int ioalloc(int, int, int, char*);
  96. int ioreserve(int, int, int, char*);
  97. int iprint(char*, ...);
  98. int isaconfig(char*, int, ISAConf*);
  99. void kexit(Ureg*);
  100. void keybenable(void);
  101. void keybinit(void);
  102. #define kmapinval()
  103. void lfence(void);
  104. void links(void);
  105. void machinit(void);
  106. void mach0init(void);
  107. void mapraminit(uint64_t, uint64_t);
  108. void mapupainit(uint64_t, uint32_t);
  109. void meminit(void);
  110. void mfence(void);
  111. void mmuflushtlb(void);
  112. void mmuinit(void);
  113. uintptr_t mmukmap(uintptr_t, uintptr_t, usize);
  114. int mmukmapsync(uint64_t);
  115. uintmem mmuphysaddr(uintptr_t);
  116. int mmuwalk(PTE*, uintptr_t, int, PTE**, PTE (*)(usize));
  117. int multiboot(uint32_t, uint32_t, int);
  118. void ndnr(void);
  119. unsigned char nvramread(int);
  120. void nvramwrite(int, unsigned char);
  121. void optionsinit(char*);
  122. void outb(int, int);
  123. void outsb(int, void*, int);
  124. void outs(int, uint16_t);
  125. void outss(int, void*, int);
  126. void outl(int, uint32_t);
  127. void outsl(int, void*, int);
  128. int pcicap(Pcidev*, int);
  129. int pcicfgr8(Pcidev*, int);
  130. int pcicfgr16(Pcidev*, int);
  131. int pcicfgr32(Pcidev*, int);
  132. void pcicfgw8(Pcidev*, int, int);
  133. void pcicfgw16(Pcidev*, int, int);
  134. void pcicfgw32(Pcidev*, int, int);
  135. void pciclrbme(Pcidev*);
  136. void pciclrmwi(Pcidev*);
  137. int pcigetpms(Pcidev*);
  138. void pcihinv(Pcidev*);
  139. Pcidev* pcimatch(Pcidev*, int, int);
  140. Pcidev* pcimatchtbdf(int);
  141. void pcireset(void);
  142. void pcisetbme(Pcidev*);
  143. void pcisetmwi(Pcidev*);
  144. int pcisetpms(Pcidev*, int);
  145. void pcishowdev(Pcidev*);
  146. int pickcore(int, int);
  147. void printcpufreq(void);
  148. void putac(Mach*);
  149. void runapcore(int);
  150. int screenprint(char*, ...); /* debugging */
  151. void sfence(void);
  152. void spldone(void);
  153. uint64_t splhi(void);
  154. uint64_t spllo(void);
  155. void splx(uint64_t);
  156. void splxpc(uint64_t);
  157. void kstackok(void); /* panic if kstack guards garbaged, works with and without externup */
  158. Stackframe *stackframe(void); /* l64v.S */
  159. void stacksnippet(void);
  160. void stopac(void);
  161. void syncclock(void);
  162. void syscall(unsigned int scallnr, Ureg *ureg);
  163. void* sysexecregs(uintptr_t, uint32_t, void*);
  164. uintptr_t sysexecstack(uintptr_t, int);
  165. void sysprocsetup(Proc*);
  166. void tssrsp0(Mach *, uint64_t);
  167. void trapenable(int, void (*)(Ureg*, void*), void*, char*);
  168. void trapinit(void);
  169. void trap(Ureg*);
  170. void umeminit(void);
  171. void ureg2gdb(Ureg *u, uintptr_t *g);
  172. int userureg(Ureg*);
  173. void* vmap(uintptr_t, usize);
  174. void vsvminit(int, int, Mach *);
  175. void vunmap(void*, usize);
  176. extern uint64_t cr0get(void);
  177. extern void cr0put(uint64_t);
  178. extern uint64_t cr2get(void);
  179. extern uint64_t cr3get(void);
  180. extern void cr3put(uint64_t);
  181. extern uint64_t cr4get(void);
  182. extern void cr4put(uint64_t);
  183. extern void gdtget(void*);
  184. extern void gdtput(int, uint64_t, uint16_t);
  185. extern void idtput(int, uint64_t);
  186. extern uint64_t rdmsr(uint32_t);
  187. extern uint64_t rdtsc(void);
  188. extern void trput(uint64_t);
  189. extern void wrmsr(uint32_t, uint64_t);
  190. // TODO(aki): once we figure this out, these will go.
  191. extern int infected_with_std(void);
  192. extern void disinfect_std(void);
  193. extern int islo(void);
  194. extern void spldone(void);
  195. extern Mpl splhi(void);
  196. extern Mpl spllo(void);
  197. extern void splx(Mpl);
  198. int cas32(void*, uint32_t, uint32_t);
  199. int cas64(void*, uint64_t, uint64_t);
  200. int tas32(void*);
  201. uint64_t fas64(uint64_t*, uint64_t);
  202. #define CASU(p, e, n) cas64((p), (uint64_t)(e), (uint64_t)(n))
  203. #define CASV(p, e, n) cas64((p), (uint64_t)(e), (uint64_t)(n))
  204. #define CASP(p, e, n) cas64((p), (uint64_t)(e), (uint64_t)(n))
  205. #define CASW(p, e, n) cas32((p), (e), (n))
  206. #define TAS(addr) tas32((addr))
  207. #define FASP(p, v) ((void*)fas64((uint64_t*)(p), (uint64_t)(v)))
  208. void touser(uintptr_t);
  209. void syscallentry(void);
  210. void acsyscallentry(void);
  211. void syscallreturn(void);
  212. void sysrforkret(void);
  213. #define waserror() setlabel(&up->errlab[up->nerrlab++])
  214. #define poperror() up->nerrlab--
  215. #define dcflush(a, b)
  216. #define PTR2UINT(p) ((uintptr_t)(p))
  217. #define UINT2PTR(i) ((void*)(i))
  218. void* KADDR(uintptr_t);
  219. uintmem PADDR(void*);
  220. #define BIOSSEG(a) KADDR(((uint)(a))<<4)
  221. /*
  222. * apic.c
  223. */
  224. extern int apiceoi(int);
  225. extern void apicipi(int);
  226. extern void apicinit(int, uintmem, int);
  227. extern int apicisr(int);
  228. extern int apiconline(void);
  229. extern void apicpri(int);
  230. extern void apicsipi(int, uintmem);
  231. extern void apicnmi(int, int, int);
  232. extern void ioapicinit(int, int, uintmem);
  233. extern void ioapiconline(void);
  234. /*
  235. * archamd64.c
  236. */
  237. extern void millidelay(int);
  238. extern void k10mwait(void*);
  239. /*
  240. * i8259.c
  241. */
  242. extern int i8259init(int);
  243. extern int i8259irqdisable(int);
  244. extern int i8259irqenable(int);
  245. extern int i8259isr(int);
  246. /*
  247. * mp.c
  248. */
  249. extern int mpsinit(int);
  250. void*sigscan(uint8_t* address, int length, char* signature);
  251. /*
  252. * sipi.c
  253. */
  254. extern void sipi(void);
  255. /*
  256. * debug
  257. */
  258. void HERE(void);
  259. void DONE(void);
  260. /* all these go to 0x3f8 */
  261. void hi(char *s);
  262. Mach *machp(void);
  263. Proc *externup(void);
  264. /* temporary. */
  265. void die(char *);
  266. void dumpgpr(Ureg* ureg);
  267. /* debug support. */
  268. int backtrace_list(uintptr_t pc, uintptr_t fp, uintptr_t *pcs, size_t nr_slots);
  269. /* horror */
  270. static inline void __clobber_callee_regs(void)
  271. {
  272. __asm__ volatile ("" : : : "rbx", "r12", "r13", "r14", "r15");
  273. }
  274. int slim_setlabel(Label*) __attribute__((returns_twice));
  275. #ifndef __clang__
  276. #pragma GCC diagnostic push
  277. #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
  278. #endif
  279. #define setlabel(label) ({int err; \
  280. __clobber_callee_regs(); \
  281. err = slim_setlabel(label); \
  282. err;})
  283. #ifndef __clang__
  284. #pragma GCC diagnostic pop
  285. #endif