fns.h 7.9 KB

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