fns.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. /* assembly code support from asm.S */
  11. /* Startmach is passed an argument which is its own stack. */
  12. void startmach(void (*f)(void *), void *m, void *stack);
  13. Mach *machp(void);
  14. /* other functions */
  15. void intrac(Proc *);
  16. void acinit(void);
  17. int acpiinit(void);
  18. void actrapenable(int, char *(*)(Ureg *, void *), void *, char *);
  19. void apicipi(int);
  20. void apicpri(int);
  21. void acsysret(void);
  22. void actouser(void);
  23. void runacore(void);
  24. void aamloop(int);
  25. Dirtab *addarchfile(char *, int,
  26. i32 (*)(Chan *, void *, i32, i64),
  27. i32 (*)(Chan *, void *, i32, i64));
  28. void acmmuswitch(void);
  29. void acmodeset(int);
  30. void archfmtinstall(void);
  31. void archidle(void);
  32. int archmmu(void);
  33. int asmfree(u64, u64, int);
  34. u64 asmalloc(u64, u64, int, int);
  35. void asminit(void);
  36. void asmmapinit(u64, u64, int);
  37. extern void asmmodinit(u32, u32, char *);
  38. void noerrorsleft(void);
  39. void archinit(void);
  40. void archreset(void);
  41. i64 archhz(void);
  42. int cgaprint(int off, char *fmt, ...);
  43. int cgaclearln(int off, int c);
  44. void cgaconsputs(char *, int);
  45. void cgainit(void);
  46. void cgapost(int);
  47. void checkpa(char *, u64);
  48. #define clearmmucache() /* x86 doesn't have one */
  49. void (*coherence)(void);
  50. int corecolor(int);
  51. u32 cpuid(u32, u32, u32[4]);
  52. int dbgprint(char *, ...);
  53. int decref(Ref *);
  54. void delay(int);
  55. void dumpmmu(Proc *);
  56. void dumpmmuwalk(u64 pa);
  57. void dumpptepg(int lvl, usize pa);
  58. #define evenaddr(x) /* x86 doesn't care */
  59. void *findKSeg2(void);
  60. int fpudevprocio(Proc *, void *, i32, usize, int);
  61. void fpuinit(void);
  62. void fpunoted(void);
  63. void fpunotify(Ureg *);
  64. void fpuprocrestore(Proc *);
  65. void fpuprocsave(Proc *);
  66. void fpusysprocsetup(Proc *);
  67. void fpusysrfork(Ureg *);
  68. void fpusysrforkchild(Proc *, Proc *);
  69. Mach *getac(Proc *, int);
  70. char *getconf(char *);
  71. void gdb2ureg(usize *g, Ureg *u);
  72. void halt(void);
  73. void hardhalt(void);
  74. void mouseenable(void);
  75. void i8042systemreset(void);
  76. int mousecmd(int);
  77. void mouseenable(void);
  78. void i8250console(char *);
  79. void *i8250alloc(int, int, int);
  80. i64 i8254hz(u32 *info0, u32 *info1);
  81. void idlehands(void);
  82. void acidthandlers(void);
  83. void idthandlers(void);
  84. int inb(int);
  85. int incref(Ref *);
  86. void insb(int, void *, int);
  87. u16 ins(int);
  88. void inss(int, void *, int);
  89. u32 inl(int);
  90. void insl(int, void *, int);
  91. int intrdisable(void *);
  92. void *intrenable(int, void (*)(Ureg *, void *), void *, int, char *);
  93. void invlpg(usize);
  94. void iofree(int);
  95. void ioinit(void);
  96. int iounused(int, int);
  97. int ioalloc(int, int, int, char *);
  98. int ioreserve(int, int, int, char *);
  99. int iprint(char *, ...);
  100. int isaconfig(char *, int, ISAConf *);
  101. void kexit(Ureg *);
  102. void keybenable(void);
  103. void keybinit(void);
  104. #define kmapinval()
  105. void lfence(void);
  106. void links(void);
  107. void machinit(void);
  108. void mach0init(void);
  109. void mapraminit(u64, u64);
  110. void mapupainit(u64, u32);
  111. void meminit(void);
  112. void mfence(void);
  113. void mmuflushtlb(void);
  114. void mmuinit(void);
  115. usize mmukmap(usize, usize, usize);
  116. int mmukmapsync(u64);
  117. u64 mmuphysaddr(usize);
  118. int mmuwalk(PTE *, usize, int, PTE **, PTE (*)(usize));
  119. int multiboot(u32, u32, int);
  120. void ndnr(void);
  121. unsigned char nvramread(int);
  122. void nvramwrite(int, unsigned char);
  123. void optionsinit(char *);
  124. void outb(int, int);
  125. void outsb(int, void *, int);
  126. void outs(int, u16);
  127. void outss(int, void *, int);
  128. void outl(int, u32);
  129. void outsl(int, void *, int);
  130. void pcireset(void);
  131. int pickcore(int, int);
  132. void printcpufreq(void);
  133. void putac(Mach *);
  134. void runapcore(int);
  135. int screenprint(char *, ...); /* debugging */
  136. void sfence(void);
  137. void spldone(void);
  138. u64 splhi(void);
  139. u64 spllo(void);
  140. void splx(u64);
  141. void splxpc(u64);
  142. void kstackok(void); /* panic if kstack guards garbaged, works with and without externup */
  143. Stackframe *stackframe(void); /* asm.S */
  144. void stacksnippet(void);
  145. void stopac(void);
  146. void syncclock(void);
  147. void syscall(unsigned int scallnr, Ureg *ureg);
  148. void *sysexecregs(usize, u32, void *);
  149. usize sysexecstack(usize, int);
  150. void sysprocsetup(Proc *);
  151. void tssrsp0(Mach *, u64);
  152. void trapenable(int, void (*)(Ureg *, void *), void *, char *);
  153. void trapinit(void);
  154. void trap(Ureg *);
  155. void umeminit(void);
  156. void ureg2gdb(Ureg *u, usize *g);
  157. int userureg(Ureg *);
  158. void *vmap(usize, usize);
  159. void vsvminit(int, int, Mach *);
  160. void vunmap(void *, usize);
  161. extern u64 rootget(void);
  162. extern void rootput(usize);
  163. extern void idtput(int, u64);
  164. extern u64 rdtsc(void);
  165. extern int islo(void);
  166. extern void spldone(void);
  167. extern Mpl splhi(void);
  168. extern Mpl spllo(void);
  169. extern void splx(Mpl);
  170. int cas32(void *, u32, u32);
  171. int cas64(void *, u64, u64);
  172. int tas32(void *);
  173. u64 fas64(u64 *, u64);
  174. #define CASU(p, e, n) cas64((p), (u64)(e), (u64)(n))
  175. #define CASV(p, e, n) cas64((p), (u64)(e), (u64)(n))
  176. #define CASP(p, e, n) cas64((p), (u64)(e), (u64)(n))
  177. #define CASW(p, e, n) cas32((p), (e), (n))
  178. #define TAS(addr) tas32((addr))
  179. #define FASP(p, v) ((void *)fas64((u64 *)(p), (u64)(v)))
  180. void touser(Ureg *);
  181. void syscallentry(void);
  182. void acsyscallentry(void);
  183. void syscallreturn(void);
  184. void sysrforkret(void);
  185. #define waserror() setlabel(&up->errlab[up->nerrlab++])
  186. #define poperror() up->nerrlab--
  187. #define dcflush(a, b)
  188. #define PTR2UINT(p) ((usize)(p))
  189. #define UINT2PTR(i) ((void *)(i))
  190. void *KADDR(usize);
  191. u64 PADDR(void *);
  192. #define BIOSSEG(a) KADDR(((u32)(a)) << 4)
  193. /*
  194. * apic.c
  195. */
  196. extern int apiceoi(int);
  197. extern void apicipi(int);
  198. extern void apicinit(int, u64, int);
  199. extern int apicisr(int);
  200. extern int apiconline(void);
  201. extern void apicpri(int);
  202. extern void apicsipi(int, u64);
  203. extern void ioapicinit(int, u64);
  204. /*
  205. * archamd64.c
  206. */
  207. extern void millidelay(int);
  208. extern void k10mwait(void *);
  209. /*
  210. * i8259.c
  211. */
  212. extern int i8259init(int);
  213. extern int i8259irqdisable(int);
  214. extern int i8259irqenable(int);
  215. extern int i8259isr(int);
  216. /*
  217. * mp.c
  218. */
  219. extern void mpsinit(int);
  220. /*
  221. * sipi.c
  222. */
  223. extern void sipi(void);
  224. /*
  225. * debug
  226. */
  227. void HERE(void);
  228. void DONE(void);
  229. /* all these go to 0x3f8 */
  230. void hi(char *s);
  231. Mach *machp(void);
  232. Proc *externup(void);
  233. /* temporary. */
  234. void die(char *);
  235. void dumpgpr(Ureg *ureg);
  236. /* debug support. */
  237. int backtrace_list(usize pc, usize fp, usize *pcs, usize nr_slots);
  238. /* horror */
  239. static inline void
  240. __clobber_callee_regs(void)
  241. {
  242. // Arrived at through trial and error, this toolchain is a pain.
  243. asm volatile(""
  244. :
  245. :
  246. : "x2", "x3", "x4", "x5", "x6", "x7", /*"x8", */ "x9", "x10", "x11", "x12", "x13" /*, "x15"*/);
  247. // TODO: f0-f15?
  248. }
  249. int slim_setlabel(Label *) __attribute__((returns_twice));
  250. #define setlabel(label) ({int err; \
  251. __clobber_callee_regs(); \
  252. err = slim_setlabel(label); \
  253. err; })
  254. /* sbi calls. They are all too different to bother with a typedef. */
  255. void sbi_set_mtimecmp(u64 t);