• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2001-2008 H. Peter Anvin - All Rights Reserved
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8  *   Boston MA 02111-1307, USA; either version 2 of the License, or
9  *   (at your option) any later version; incorporated herein by reference.
10  *
11  * ----------------------------------------------------------------------- */
12 
13 /*
14  * memdisk.h
15  *
16  * Miscellaneous header definitions
17  */
18 
19 #ifndef MEMDISK_H
20 #define MEMDISK_H
21 
22 #include <stddef.h>
23 
24 /* We use the com32 interface for calling 16-bit code */
25 #include <com32.h>
26 
27 /* define it only for i386 */
28 #if __SIZEOF_POINTER__ == 4
29 #define __cdecl __attribute__((cdecl,regparm(0)))
30 #endif
31 
32 void __cdecl intcall(uint8_t, com32sys_t *, com32sys_t *);
33 
34 /* Structure passed in from the real-mode code */
35 struct real_mode_args {
36     uint32_t rm_return;
37     uint32_t rm_intcall;
38     uint32_t rm_bounce;
39     uint32_t rm_base;
40     uint32_t rm_handle_interrupt;
41     uint32_t rm_gdt;
42     uint32_t rm_size;
43     uint32_t rm_pmjmp;
44     uint32_t rm_rmjmp;
45 };
46 extern struct real_mode_args rm_args;
47 #define sys_bounce ((void *)rm_args.rm_bounce)
48 
49 /* This is the header in the boot sector/setup area */
50 struct setup_header {
51     char cmdline[0x1f1];
52     uint8_t setup_secs;
53     uint16_t syssize;
54     uint16_t swap_dev;
55     uint16_t ram_size;
56     uint16_t vid_mode;
57     uint16_t root_dev;
58     uint16_t boot_flag;
59     uint16_t jump;
60     char header[4];
61     uint16_t version;
62     uint32_t realmode_swtch;
63     uint32_t start_sys;
64     uint8_t type_of_loader;
65     uint8_t loadflags;
66     uint16_t setup_move_size;
67     uint32_t code32_start;
68     uint32_t ramdisk_image;
69     uint32_t ramdisk_size;
70     uint32_t bootsect_kludge;
71     uint16_t head_end_ptr;
72     uint16_t pad1;
73     uint32_t cmd_line_ptr;
74     uint32_t initrd_addr_max;
75     uint32_t esdi;
76     uint32_t edx;
77     uint32_t sssp;
78     uint32_t csip;
79 };
80 #define shdr ((struct setup_header *)rm_args.rm_base)
81 
82 /* Standard routines */
83 void *memcpy(void *, const void *, size_t);
84 void *memset(void *, int, size_t);
85 void *memmove(void *, const void *, size_t);
86 
87 #define strcpy(a,b)   __builtin_strcpy(a,b)
88 
strlen(const char * __a)89 static inline size_t strlen(const char *__a)
90 {
91     const char *__D;
92     size_t __c;
93 
94 asm("repne;scasb":"=D"(__D), "=c"(__c)
95 :	"D"(__a), "c"(-1), "a"(0), "m"(*__a));
96 
97     return __D - __a - 1;
98 }
99 
100 /* memcpy() but returns a pointer to end of buffer */
mempcpy(void * __d,const void * __s,unsigned int __n)101 static inline void *mempcpy(void *__d, const void *__s, unsigned int __n)
102 {
103     memcpy(__d, __s, __n);
104     return (void *)((char *)__d + __n);
105 }
106 
107 /* memcmp() */
memcmp(const void * __a,const void * __b,unsigned int __n)108 static inline int memcmp(const void *__a, const void *__b, unsigned int __n)
109 {
110     const unsigned char *__aa = __a;
111     const unsigned char *__bb = __b;
112     int __d;
113 
114     while (__n--) {
115 	__d = *__bb++ - *__aa++;
116 	if (__d)
117 	    return __d;
118     }
119 
120     return 0;
121 }
122 
sti(void)123 static inline void sti(void)
124 {
125     asm volatile("sti");
126 }
127 
cli(void)128 static inline void cli(void)
129 {
130     asm volatile("cli");
131 }
132 
133 /* Decompression */
134 extern int check_zip(void *indata, uint32_t size, uint32_t * zbytes_p,
135 		     uint32_t * dbytes_p, uint32_t * orig_crc,
136 		     uint32_t * offset_p);
137 extern void *unzip(void *indata, uint32_t zbytes, uint32_t dbytes,
138 		   uint32_t orig_crc, void *target);
139 
140 #endif
141