1 #ifndef MYSTUFF_H 2 #define MYSTUFF_H 3 4 #include <inttypes.h> 5 #include <stddef.h> 6 7 unsigned int skip_atou(const char **s); 8 unsigned int atou(const char *s); 9 isdigit(int ch)10static inline int isdigit(int ch) 11 { 12 return (ch >= '0') && (ch <= '9'); 13 } 14 15 struct diskio { 16 uint32_t startsector; 17 uint16_t sectors; 18 uint16_t bufoffs, bufseg; 19 } __attribute__ ((packed)); 20 int int25_read_sector(unsigned char drive, struct diskio *dio); 21 int int26_write_sector(unsigned char drive, struct diskio *dio); 22 23 struct psp { 24 uint16_t int20; 25 uint16_t nextpara; 26 uint8_t resv1; 27 uint8_t dispatcher[5]; 28 uint32_t termvector; 29 uint32_t ctrlcvector; 30 uint32_t criterrvector; 31 uint16_t resv2[11]; 32 uint16_t environment; 33 uint16_t resv3[23]; 34 uint8_t fcb[2][16]; 35 uint32_t resv4; 36 uint8_t cmdlen; 37 char cmdtail[127]; 38 } __attribute__((packed)); 39 40 extern struct psp _PSP; 41 42 static inline __attribute__((const)) ds(void)43uint16_t ds(void) 44 { 45 uint16_t v; 46 asm("movw %%ds,%0":"=rm"(v)); 47 return v; 48 } 49 set_fs(uint16_t seg)50static inline void set_fs(uint16_t seg) 51 { 52 asm volatile("movw %0,%%fs"::"rm" (seg)); 53 } 54 get_8_fs(size_t offs)55static inline uint8_t get_8_fs(size_t offs) 56 { 57 uint8_t v; 58 asm volatile("movb %%fs:%1,%0" 59 : "=q" (v) : "m" (*(const uint8_t *)offs)); 60 return v; 61 } 62 get_16_fs(size_t offs)63static inline uint16_t get_16_fs(size_t offs) 64 { 65 uint16_t v; 66 asm volatile("movw %%fs:%1,%0" 67 : "=r" (v) : "m" (*(const uint16_t *)offs)); 68 return v; 69 } 70 get_32_fs(size_t offs)71static inline uint32_t get_32_fs(size_t offs) 72 { 73 uint32_t v; 74 asm volatile("movl %%fs:%1,%0" 75 : "=r" (v) : "m" (*(const uint32_t *)offs)); 76 return v; 77 } 78 79 #endif /* MYSTUFF_H */ 80