fork download
  1. #ifndef __DTYPE_H__
  2. #define __DTYPE_H__
  3.  
  4. #define ACTIVATED 1<<0
  5. #define PERIODIC 1<<1
  6.  
  7. #define OK 0
  8. #define ERROR -1
  9. #define TRUE (1==1)
  10. #define FALSE (0==1)
  11. #define N 0
  12. #define BLOCKHEAD_SIGNATURE 0x0000F00D
  13. #define NAME_MAXLEN 20
  14. #define NULL 0
  15. #define MAX_PRIO 32
  16. #define MAX_TASK_NUM 256
  17. #define TASK_STACK_SIZE 0x1000
  18.  
  19.  
  20. /*general device commands*/
  21. #define DEVICE_SET_RESUME 0x01 //resume device
  22. #define DEVICE_SET_SUSPEND 0x02 //suspend device
  23.  
  24. //flags[0:3]: device mode
  25. //device mode
  26. #define DEVICE_RDONLY 1<<0
  27. #define DEVICE_WRONLY 1<<1
  28. #define DEVICE_RDWR DEVICE_RDONLY | DEVICE_WRONLY
  29. #define DEVICE_STANDALONERDLONLY 1<<2
  30.  
  31. //flags[4:7]:active or suspend
  32. //active or suspend
  33. #define DEVICE_ACTIVATED 1<<4
  34. #define DEVICE_SUSPENDED 1<<5
  35.  
  36.  
  37. //flags[8:11]:Tx and Rx flag
  38. //TX_RX mode
  39. #define DEVICE_RX_INT_MODE 1<<8 //INT mode on Rx
  40. #define DEVICE_RX_DMA_MODE 1<<9 //DMA mode on Rx
  41. #define DEVICE_TX_INT_MODE 1<<10 //INT mode on Tx
  42. #define DEVICE_TX_DMA_MODE 1<<11 //DMA mode on Tx
  43.  
  44. //flags[12:15]:device Open flag
  45. //OPEN flag
  46. #define DEVICE_OFLAG_RDONLY 1<<12
  47. #define DEVICE_OFLAG_WRONLY 1<<13
  48. #define DEVICE_OFLAG_RDWR DEVICE_OFLAG_RDONLY | DEVICE_OFLAG_WRONLY
  49. #define DEVICE_OFLAG_CLOSE 1<<14
  50. #define DEVICE_OFLAG_OPEN 1<<15
  51.  
  52.  
  53. typedef unsigned int u32int;
  54. typedef int s32int;
  55. typedef unsigned short u16int;
  56. typedef short s16int;
  57. typedef unsigned char u8int;
  58. typedef char s8int;
  59.  
  60.  
  61.  
  62.  
  63. /**********************************************************
  64. for node&list structures
  65. ***********************************************************/
  66. struct node{
  67. struct node *next;
  68. struct node *prev;
  69. };
  70. typedef struct node node_t;
  71.  
  72. struct list{
  73. node_t head;
  74. node_t tail;
  75. };
  76. typedef struct list list_t;
  77.  
  78.  
  79.  
  80. //I/O device structure
  81. typedef enum {
  82. Char_Device = 0, //character device
  83. Block_Device, //block device
  84. NetIf_Device, //net interface
  85. Sound_Device, //Sound device
  86. Unknown_Device //unkenown device
  87. } device_type;
  88.  
  89.  
  90. /*********************************************************
  91. for device
  92. *********************************************************/
  93. struct device;
  94. typedef struct device device_t;
  95.  
  96. struct device{
  97. node_t node; //the node of timer list
  98. char name[NAME_MAXLEN];
  99. device_type type;
  100.  
  101. //4bits: oflag, 4bits:TX_RX_flag, 4bits: active or suspend, 4bits: mode
  102. u16int flags;
  103.  
  104.  
  105.  
  106.  
  107.  
  108. //device interface
  109. s8int (*init)(device_t* dev);
  110. s8int (*close)(device_t* dev);
  111. s8int (*open) (device_t* dev, u16int oflag);
  112. u32int (*read) (device_t* dev, u32int pos, u32int size, void* buffer);
  113. u32int (*write) (device_t* dev, u32int pos, u32int size, const void* buffer);
  114. s8int (*ctrl) (device_t* dev, u8int cmd, void *args);
  115.  
  116. //device callback
  117. s8int (*rx)(device_t* dev, u32int size);
  118. s8int (*tx)(device_t* dev, void* buffer);
  119.  
  120. };
  121.  
  122.  
  123.  
  124.  
  125.  
  126. /**********************************************************
  127. task definition
  128. **********************************************************/
  129. /*state of task*/
  130. typedef enum{
  131. READY=0,
  132. RUNNING,
  133. BLOCK,
  134. CLOSE
  135. } TASK_STATE;
  136.  
  137. /**********************************************************
  138. for Timer Structure
  139. ***********************************************************/
  140. struct timer{
  141. node_t node;
  142. char name[NAME_MAXLEN];
  143. u8int flag; /* 0 bit:actived, 1 bit:type*/
  144. void (*timeout_func)(void* parameter);
  145. void *parameter;
  146. u32int init_tick; /*timer timeout tick.*/
  147. u32int timeout_tick; /*timeout tick.*/
  148. };
  149. typedef struct timer timer_t;
  150.  
  151.  
  152. /*structure of task*/
  153. struct task {
  154. node_t node;
  155.  
  156. /*stack point and entry*/
  157. void* sp;
  158. void* entry;
  159. void* parameter;
  160. void* stack_addr;
  161. u16int stack_size;
  162.  
  163. u8int priority;
  164.  
  165. u32int init_tick;
  166. u32int remaining_tick;
  167.  
  168. u32int task_id;
  169. TASK_STATE state;
  170. char name[NAME_MAXLEN];
  171.  
  172. timer_t* timer;
  173. };
  174. typedef struct task task_t;
  175.  
  176. typedef enum{
  177. WAITING_NO = 0,
  178. WAITING,
  179. WAITING_FOREVER
  180. } SEM_WAITING_TYPE;
  181.  
  182. typedef enum{
  183. FIFO = 0,
  184. PRIO
  185. } SEM_FLAG_TYPE;
  186.  
  187. /**********************************************************
  188. for mailbox
  189. ***********************************************************/
  190. struct mailbox {
  191. char name[NAME_MAXLEN];
  192. u32int *msg_pool;
  193. SEM_FLAG_TYPE flag;
  194. u16int size;
  195. u16int entry;
  196. u16int input_offset;
  197. u16int output_offset;
  198. list_t waiting_list;
  199. };
  200. typedef struct mailbox mailbox_t;
  201.  
  202. /*********************************************************
  203. for semaphore
  204. **********************************************************/
  205. /*
  206.  * semaphore
  207.  *
  208.  */
  209. struct semaphore{
  210. char name[NAME_MAXLEN];
  211. u16int value;
  212. SEM_FLAG_TYPE flag;
  213. list_t waiting_list;
  214. };
  215. typedef struct semaphore sem_t;
  216.  
  217.  
  218. /**********************************************************
  219. for schedule
  220. ***********************************************************/
  221. typedef enum{
  222. SCHED_TIME_EXPIRE=0,
  223. SCHED_TASK_REQUEST
  224. } SCHED_TYPE;
  225.  
  226.  
  227.  
  228. typedef enum{
  229. SET_TIME=0,
  230. GET_TIME,
  231. SET_ONESHOT,
  232. SET_PERIODIC
  233. } TIMER_CMD_TYPE;
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240. /**********************************************************
  241. for Memory Block Structure
  242. ***********************************************************/
  243. typedef struct blockHead{
  244. u32int signature;
  245. u8int allocated;
  246. u32int size;
  247. struct blockHead *next;
  248. struct blockHead *prev;
  249. }blockHead_t;
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256. /**********************************************************
  257. for descript table
  258. ***********************************************************/
  259. // This structure contains the value of one GDT entry.
  260. // We use the attribute 'packed' to tell GCC not to change
  261. // any of the alignment in the structure.
  262. struct gdt_entry_struct
  263. {
  264. u16int limit_low; // The lower 16 bits of the limit.
  265. u16int base_low; // The lower 16 bits of the base.
  266. u8int base_middle; // The next 8 bits of the base.
  267. u8int access; // Access flags, determine what ring this segment can be used in.
  268. u8int granularity;
  269. u8int base_high; // The last 8 bits of the base.
  270. } __attribute__((packed));
  271.  
  272. typedef struct gdt_entry_struct gdt_entry_t;
  273.  
  274. // This struct describes a GDT pointer. It points to the start of
  275. // our array of GDT entries, and is in the format required by the
  276. // lgdt instruction.
  277. struct gdt_ptr_struct
  278. {
  279. u16int limit; // The upper 16 bits of all selector limits.
  280. u32int base; // The address of the first gdt_entry_t struct.
  281. } __attribute__((packed));
  282.  
  283. typedef struct gdt_ptr_struct gdt_ptr_t;
  284.  
  285. // A struct describing an interrupt gate.
  286. struct idt_entry_struct
  287. {
  288. u16int base_lo; // The lower 16 bits of the address to jump to when this interrupt fires.
  289. u16int sel; // Kernel segment selector.
  290. u8int always0; // This must always be zero.
  291. u8int flags; // More flags. See documentation.
  292. u16int base_hi; // The upper 16 bits of the address to jump to.
  293. } __attribute__((packed));
  294.  
  295. typedef struct idt_entry_struct idt_entry_t;
  296.  
  297. // A struct describing a pointer to an array of interrupt handlers.
  298. // This is in a format suitable for giving to 'lidt'.
  299. struct idt_ptr_struct
  300. {
  301. u16int limit;
  302. u32int base; // The address of the first element in our idt_entry_t array.
  303. } __attribute__((packed));
  304.  
  305. typedef struct idt_ptr_struct idt_ptr_t;
  306.  
  307.  
  308. /************************************************************************************/
  309. /************************************************************************
  310. for regs
  311. ************************************************************************/
  312. /* This defines what the stack looks like after an ISR was running */
  313. struct regs
  314. {
  315. unsigned int gs, fs, es, ds;
  316. unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
  317. unsigned int int_no, err_code;
  318. unsigned int eip, cs, eflags, useresp, ss;
  319. };
  320.  
  321. //;typedef struct registers
  322. //;{
  323. //; unsigned int ds; // Data segment selector
  324. //; unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha.
  325. //; unsigned int int_no, err_code; // Interrupt number and error code (if applicable)
  326. //; unsigned int eip, cs, eflags, useresp, ss; // Pushed by the processor automatically.
  327. //;} __attribute__ ((packed)) registers_t;
  328.  
  329. typedef struct regs registers_t;
  330.  
  331. /************************************************************************************/
  332.  
  333.  
  334.  
  335. #endif
  336.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
stdout
Standard output is empty