root/memdisk/memdisk.h

Revision 69bb4b204e8d29c89597961e94807d1acba2cd4b, 3.3 KB (checked in by H. Peter Anvin <hpa@…>, 3 years ago)

memdisk: additional cleanups

Additional stylistic cleanups. Rename "syscall" to "intcall" (we
can't call it intcall without clashing with com32.h); use macros
instead of copying variables to different places with only the type
being different.

Also, only change the rm/pm jump instructions when actually relocating
the code.

Signed-off-by: H. Peter Anvin <hpa@…>

  • Property mode set to 100644
Line 
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 __cdecl __attribute__((cdecl,regparm(0)))
28
29void __cdecl intcall(uint8_t, com32sys_t *, com32sys_t *);
30
31/* Structure passed in from the real-mode code */
32struct real_mode_args {
33    uint32_t rm_return;
34    uint32_t rm_intcall;
35    uint32_t rm_bounce;
36    uint32_t rm_base;
37    uint32_t rm_handle_interrupt;
38    uint32_t rm_gdt;
39    uint32_t rm_size;
40    uint32_t rm_pmjmp;
41    uint32_t rm_rmjmp;
42};
43extern struct real_mode_args rm_args;
44#define sys_bounce ((void *)rm_args.rm_bounce)
45
46/* This is the header in the boot sector/setup area */
47struct setup_header {
48    char cmdline[0x1f1];
49    uint8_t setup_secs;
50    uint16_t syssize;
51    uint16_t swap_dev;
52    uint16_t ram_size;
53    uint16_t vid_mode;
54    uint16_t root_dev;
55    uint16_t boot_flag;
56    uint16_t jump;
57    char header[4];
58    uint16_t version;
59    uint32_t realmode_swtch;
60    uint32_t start_sys;
61    uint8_t type_of_loader;
62    uint8_t loadflags;
63    uint16_t setup_move_size;
64    uint32_t code32_start;
65    uint32_t ramdisk_image;
66    uint32_t ramdisk_size;
67    uint32_t bootsect_kludge;
68    uint16_t head_end_ptr;
69    uint16_t pad1;
70    uint32_t cmd_line_ptr;
71    uint32_t initrd_addr_max;
72    uint32_t esdi;
73    uint32_t edx;
74    uint32_t sssp;
75    uint32_t csip;
76};
77#define shdr ((struct setup_header *)rm_args.rm_base)
78
79/* Standard routines */
80void *memcpy(void *, const void *, size_t);
81void *memset(void *, int, size_t);
82void *memmove(void *, const void *, size_t);
83
84#define strcpy(a,b)   __builtin_strcpy(a,b)
85
86static inline size_t strlen(const char *__a)
87{
88    const char *__D;
89    size_t __c;
90
91asm("repne;scasb":"=D"(__D), "=c"(__c)
92:       "D"(__a), "c"(-1), "a"(0), "m"(*__a));
93
94    return __D - __a - 1;
95}
96
97/* memcpy() but returns a pointer to end of buffer */
98static inline void *mempcpy(void *__d, const void *__s, unsigned int __n)
99{
100    memcpy(__d, __s, __n);
101    return (void *)((char *)__d + __n);
102}
103
104/* memcmp() */
105static inline int memcmp(const void *__a, const void *__b, unsigned int __n)
106{
107    const unsigned char *__aa = __a;
108    const unsigned char *__bb = __b;
109    int __d;
110
111    while (__n--) {
112        __d = *__bb++ - *__aa++;
113        if (__d)
114            return __d;
115    }
116
117    return 0;
118}
119
120static inline void sti(void)
121{
122    asm volatile("sti");
123}
124
125static inline void cli(void)
126{
127    asm volatile("cli");
128}
129
130/* Decompression */
131extern int check_zip(void *indata, uint32_t size, uint32_t * zbytes_p,
132                     uint32_t * dbytes_p, uint32_t * orig_crc,
133                     uint32_t * offset_p);
134extern void *unzip(void *indata, uint32_t zbytes, uint32_t dbytes,
135                   uint32_t orig_crc, void *target);
136
137#endif
Note: See TracBrowser for help on using the browser.