OpenCores
URL https://opencores.org/ocsvn/s80186/s80186/trunk

Subversion Repositories s80186

[/] [s80186/] [trunk/] [bios/] [bios.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 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, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
#pragma once
19
 
20
#include "bda.h"
21
 
22
#define __unused __attribute__((unused))
23
 
24
/* Pushed by the INT handlers in the order that a PUSHA would. */
25
union reg {
26
    struct {
27
        unsigned char l;
28
        unsigned char h;
29
    };
30
    unsigned short x;
31
};
32
 
33
struct callregs {
34
    union reg di;
35
    union reg si;
36
    union reg bp;
37
    union reg sp;
38
    union reg bx;
39
    union reg dx;
40
    union reg cx;
41
    union reg ax;
42
    unsigned short ds;
43
    unsigned short flags;
44
};
45
 
46
enum FlagBitPos {
47
    CF_OFFS = 0,
48
    PF_OFFS = 2,
49
    AF_OFFS = 4,
50
    ZF_OFFS = 6,
51
    SF_OFFS = 7,
52
    TF_OFFS = 8,
53
    IF_OFFS = 9,
54
    DF_OFFS = 10,
55
    OF_OFFS = 11
56
};
57
 
58
enum Flag {
59
    CF = (1 << CF_OFFS),
60
    PF = (1 << PF_OFFS),
61
    AF = (1 << AF_OFFS),
62
    ZF = (1 << ZF_OFFS),
63
    SF = (1 << SF_OFFS),
64
    TF = (1 << TF_OFFS),
65
    IF = (1 << IF_OFFS),
66
    DF = (1 << DF_OFFS),
67
    OF = (1 << OF_OFFS),
68
};
69
 
70
#define VECTOR(vnum, handler)                                     \
71
    static void __attribute__((used)) handler(struct callregs *); \
72
    asm(".pushsection .text, \"ax\"\n"                            \
73
        "1:\n"                                                    \
74
        "cli\n"                                                   \
75
        "push $" #handler                                         \
76
        "\n"                                                      \
77
        "jmp irq_entry\n"                                         \
78
        ".pushsection .rodata.vectors\n"                          \
79
        ".align 4\n"                                              \
80
        ".word " #vnum                                            \
81
        "\n"                                                      \
82
        ".word 1b\n"                                              \
83
        ".popsection")
84
 
85
#define bda_write(field, val)                                                \
86
    ({                                                                       \
87
        typeof(((struct bios_data_area *)0)->field) _p = (val);              \
88
        if (__builtin_types_compatible_p(typeof(_p), unsigned short))        \
89
            writew(0x40, offsetof(struct bios_data_area, field), _p);        \
90
        else if (__builtin_types_compatible_p(typeof(_p), unsigned char))    \
91
            writeb(0x40, offsetof(struct bios_data_area, field), _p);        \
92
        else                                                                 \
93
            memcpy_seg(0x40, (void *)offsetof(struct bios_data_area, field), \
94
                       get_cs(), &_p, sizeof(_p));                           \
95
    })
96
 
97
#define bda_read(field)                                                   \
98
    ({                                                                    \
99
        typeof(((struct bios_data_area *)0)->field) _p;                   \
100
        if (__builtin_types_compatible_p(typeof(_p), unsigned short))     \
101
            _p = readw(0x40, offsetof(struct bios_data_area, field));     \
102
        else if (__builtin_types_compatible_p(typeof(_p), unsigned char)) \
103
            _p = readb(0x40, offsetof(struct bios_data_area, field));     \
104
        else                                                              \
105
            memcpy_seg(get_cs(), &_p, 0x40,                               \
106
                       (void *)offsetof(struct bios_data_area, field),    \
107
                       sizeof(_p));                                       \
108
        _p;                                                               \
109
    })
110
 
111
#define offsetof __builtin_offsetof
112
#define noinline __attribute__((noinline))
113
 
114
void irq_enable(int irq_num);
115
void irq_ack(void);
116
void printk(const char *fmt, ...);
117
 
118
#define ARRAY_SIZE(__a) (sizeof(__a) / sizeof(__a[0]))

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.