fns.h 8.2 KB

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