fns.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. int32_t(*)(Chan*,void*,int32_t,int64_t),
  27. int32_t(*)(Chan*,void*,int32_t,int64_t));
  28. void acmmuswitch(void);
  29. void acmodeset(int);
  30. void archfmtinstall(void);
  31. void archidle(void);
  32. int archmmu(void);
  33. int asmfree(uintmem, uintmem, int);
  34. uint64_t asmalloc(uintmem, uintmem, int, int);
  35. void asminit(void);
  36. void asmmapinit(uintmem, uintmem, int);
  37. extern void asmmodinit(uint32_t, uint32_t, char*);
  38. void noerrorsleft(void);
  39. void archinit(void);
  40. void archreset(void);
  41. int64_t 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*, uintmem);
  48. #define clearmmucache() /* x86 doesn't have one */
  49. void (*coherence)(void);
  50. int corecolor(int);
  51. uint32_t cpuid(uint32_t, uint32_t, uint32_t[4]);
  52. int dbgprint(char*, ...);
  53. int decref(Ref*);
  54. void delay(int);
  55. void dumpmmu(Proc*);
  56. void dumpmmuwalk(uint64_t pa);
  57. void dumpptepg(int lvl,uintptr_t pa);
  58. #define evenaddr(x) /* x86 doesn't care */
  59. void *findKSeg2(void);
  60. int fpudevprocio(Proc*, void*, int32_t, uintptr_t, 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(uintptr_t *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. int64_t i8254hz(uint32_t *info0, uint32_t *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. uint16_t ins(int);
  88. void inss(int, void*, int);
  89. uint32_t 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(uintptr_t);
  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(uint64_t, uint64_t);
  110. void mapupainit(uint64_t, uint32_t);
  111. void meminit(void);
  112. void mfence(void);
  113. void mmuflushtlb(void);
  114. void mmuinit(void);
  115. uintptr_t mmukmap(uintptr_t, uintptr_t, usize);
  116. int mmukmapsync(uint64_t);
  117. uintmem mmuphysaddr(uintptr_t);
  118. int mmuwalk(PTE*, uintptr_t, int, PTE**, PTE (*)(usize));
  119. int multiboot(uint32_t, uint32_t, 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, uint16_t);
  127. void outss(int, void*, int);
  128. void outl(int, uint32_t);
  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. uint64_t splhi(void);
  139. uint64_t spllo(void);
  140. void splx(uint64_t);
  141. void splxpc(uint64_t);
  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(uintptr_t, uint32_t, void*);
  149. uintptr_t sysexecstack(uintptr_t, int);
  150. void sysprocsetup(Proc*);
  151. void tssrsp0(Mach *, uint64_t);
  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, uintptr_t *g);
  157. int userureg(Ureg*);
  158. void* vmap(uintptr_t, usize);
  159. void vsvminit(int, int, Mach *);
  160. void vunmap(void*, usize);
  161. extern uint64_t rootget(void);
  162. extern void rootput(uintptr_t);
  163. extern void idtput(int, uint64_t);
  164. extern uint64_t 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*, uint32_t, uint32_t);
  171. int cas64(void*, uint64_t, uint64_t);
  172. int tas32(void*);
  173. uint64_t fas64(uint64_t*, uint64_t);
  174. #define CASU(p, e, n) cas64((p), (uint64_t)(e), (uint64_t)(n))
  175. #define CASV(p, e, n) cas64((p), (uint64_t)(e), (uint64_t)(n))
  176. #define CASP(p, e, n) cas64((p), (uint64_t)(e), (uint64_t)(n))
  177. #define CASW(p, e, n) cas32((p), (e), (n))
  178. #define TAS(addr) tas32((addr))
  179. #define FASP(p, v) ((void*)fas64((uint64_t*)(p), (uint64_t)(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) ((uintptr_t)(p))
  189. #define UINT2PTR(i) ((void*)(i))
  190. void* KADDR(uintptr_t);
  191. uintmem PADDR(void*);
  192. #define BIOSSEG(a) KADDR(((uint)(a))<<4)
  193. /*
  194. * apic.c
  195. */
  196. extern int apiceoi(int);
  197. extern void apicipi(int);
  198. extern void apicinit(int, uintmem, int);
  199. extern int apicisr(int);
  200. extern int apiconline(void);
  201. extern void apicpri(int);
  202. extern void apicsipi(int, uintmem);
  203. extern void ioapicinit(int, uintmem);
  204. extern void ioapicintrinit(int, int, int, int, uint32_t);
  205. extern void ioapiconline(void);
  206. /*
  207. * archamd64.c
  208. */
  209. extern void millidelay(int);
  210. extern void k10mwait(void*);
  211. /*
  212. * i8259.c
  213. */
  214. extern int i8259init(int);
  215. extern int i8259irqdisable(int);
  216. extern int i8259irqenable(int);
  217. extern int i8259isr(int);
  218. /*
  219. * mp.c
  220. */
  221. extern void mpsinit(int);
  222. /*
  223. * sipi.c
  224. */
  225. extern void sipi(void);
  226. /*
  227. * debug
  228. */
  229. void HERE(void);
  230. void DONE(void);
  231. /* all these go to 0x3f8 */
  232. void hi(char *s);
  233. Mach *machp(void);
  234. Proc *externup(void);
  235. /* temporary. */
  236. void die(char *);
  237. void dumpgpr(Ureg* ureg);
  238. /* debug support. */
  239. int backtrace_list(uintptr_t pc, uintptr_t fp, uintptr_t *pcs, size_t nr_slots);
  240. /* horror */
  241. static inline void __clobber_callee_regs(void)
  242. {
  243. // Arrived at through trial and error, this toolchain is a pain.
  244. asm volatile ("" : : : "x2", "x3", "x4", "x5", "x6", "x7", /*"x8", */"x9", "x10", "x11", "x12", "x13"/*, "x15"*/);
  245. // TODO: f0-f15?
  246. }
  247. int slim_setlabel(Label*) __attribute__((returns_twice));
  248. #define setlabel(label) ({int err; \
  249. __clobber_callee_regs(); \
  250. err = slim_setlabel(label); \
  251. err;})