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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [i386/] [pcmb/] [v2_0/] [include/] [pcmb.inc] - Blame information for rev 313

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
#ifndef CYGONCE_HAL_PCMB_INC
2
#define CYGONCE_HAL_PCMB_INC
3
##=============================================================================
4
##
5
##      pcmb.inc
6
##
7
##      PC platform support
8
##
9
##=============================================================================
10
#####ECOSGPLCOPYRIGHTBEGIN####
11
## -------------------------------------------
12
## This file is part of eCos, the Embedded Configurable Operating System.
13
## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14
##
15
## eCos is free software; you can redistribute it and/or modify it under
16
## the terms of the GNU General Public License as published by the Free
17
## Software Foundation; either version 2 or (at your option) any later version.
18
##
19
## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20
## WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22
## for more details.
23
##
24
## You should have received a copy of the GNU General Public License along
25
## with eCos; if not, write to the Free Software Foundation, Inc.,
26
## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27
##
28
## As a special exception, if other files instantiate templates or use macros
29
## or inline functions from this file, or you compile this file and link it
30
## with other works to produce a work based on this file, this file does not
31
## by itself cause the resulting work to be covered by the GNU General Public
32
## License. However the source code for this file must still be made available
33
## in accordance with section (3) of the GNU General Public License.
34
##
35
## This exception does not invalidate any other reasons why a work based on
36
## this file might be covered by the GNU General Public License.
37
##
38
## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39
## at http://sources.redhat.com/ecos/ecos-license/
40
## -------------------------------------------
41
#####ECOSGPLCOPYRIGHTEND####
42
##=============================================================================
43
#######DESCRIPTIONBEGIN####
44
##
45
## Author(s):   jskov
46
## Contributors:jskov, pjo, nickg
47
## Date:        1999-01-07
48
## Purpose:     PC platform support
49
## Description: This file contains any PC specific assembler macros needed to
50
##              run eCos on a standard i386 PC.
51
##
52
##
53
######DESCRIPTIONEND####
54
##
55
##=============================================================================
56
 
57
 
58
##=============================================================================
59
## CPU initialization
60
 
61
#ifndef CYGPKG_HAL_I386_CPU_INIT_DEFINED
62
 
63
#ifdef CYG_HAL_STARTUP_FLOPPY
64
 
65
#define CYGPKG_HAL_I386_CPU_INIT_DEFINED
66
 
67
        .macro  hal_cpu_init
68
 
69
        /* This code is loaded from a floppy disk when the PC powers up.  */
70
 
71
        .code16
72
 
73
        .extern _end
74
 
75
        sectorsPerTrack = 18
76
        bytesPerSector = 512
77
        esPerSector = 32        /* = 512/16 */
78
 
79
        cld                             /* always count up. */
80
 
81
        /* Configure a stack that we can use. */
82
 
83
        movl    $_start, %eax
84
        movw    %ax, %sp
85
        shr     $4, %eax
86
        andl    $0xF000, %eax
87
        movw    %ax, %ss
88
 
89
        /* Ask the BIOS for info about the amount of RAM available.  We push
90
         * these onto the stack for later use.
91
         */
92
 
93
        xorl    %eax, %eax
94
        movb    $0x88, %ah              /* Get the amount of extended memory. */
95
        int     $0x15
96
        shl     $10, %eax
97
        pushl   %eax
98
 
99
        xorl    %eax, %eax
100
        int     $0x12                   /* Get the amount of standard memory. */
101
        shl     $10, %eax
102
        pushl   %eax
103
 
104
        /* reset floppy */
105
        movb $0,%ah
106
        movb $0,%dl
107
        int $0x13
108
        jc _error1
109
 
110
        /* Read the rest of the image to _start.  This code works by reading
111
           only one sector at a time to avoid "buffer cross 64k boundary" fatal
112
           problem... This is slow but should work in almost all situations.
113
           _start should be aligned on a 512 bytes boundary to be sure.
114
        */
115
 
116
        /* destination pointer es:bx */
117
        /* With correct alignement, bx should be 0 and es should be a multiple
118
         * of 32. If not it may cause the "buffer cross 64k boundary" problem
119
         * (cf above)
120
         */
121
        movl    $_start,%eax
122
        movw    %ax,%bx
123
        andw    $0xF,%bx
124
        shrl    $4,%eax
125
        movw    %ax, %es
126
 
127
        /* initials head/track/sector */
128
        movw    $0,%dx
129
        movw    $1,%cx
130
 
131
        movl    $_edata,%edi
132
        addl    $(bytesPerSector-1),%edi
133
        shrl    $4,%edi
134
 
135
        jmp     _loadsector
136
 
137
_nextsector:
138
        movw    %es,%ax
139
        cmpw    %di,%ax
140
        jge     _endload
141
        addw    $esPerSector,%ax
142
        movw    %ax,%es
143
        incb    %cl
144
        cmpb    $sectorsPerTrack, %cl
145
        jbe     _loadsector     /* next head ?*/
146
        movb    $1, %cl
147
        incb    %dh
148
        cmpb    $1, %dh
149
        je      _loadsector     /* next track ? */
150
        movb    $0, %dh
151
        incb    %ch
152
 
153
_loadsector:
154
 
155
        pushw   %es
156
        pushw   %di
157
        movw    $0x0201, %ax
158
        clc
159
        int     $0x13
160
        popw    %di
161
        popw    %es
162
        jc _error2
163
 
164
        movw    $(0x0E*256+'.'), %ax    /* print a dot */
165
        int     $0x10
166
 
167
        /* So go ahead and resume execution at the real starting address.  This
168
        only serves to move us quickly to the real starting location; and has
169
        no effect after reading additional tracks.  If we didn't jump after
170
        reading the first track, then we limit ourselves to reading images of
171
        30k bytes max before overwriting ourselves at 0x7C00.
172
        */
173
 
174
        ljmp $0,$_nextsector
175
 
176
_error1:
177
        movw    $(0x0E*256+'1'), %ax    /* print a ! */
178
        int     $0x10
179
        jmp     _error
180
 
181
_error2:
182
        mov     %ah,%al
183
        pushw   %ax
184
        shrw    $4,%ax
185
        andw    $15,%ax
186
        addw    $0x0E41,%ax
187
        int     $0x10
188
        popw    %ax
189
        andw    $15,%ax
190
        addw    $0x0E41,%ax
191
        int     $0x10
192
 
193
        movw    $(0x0E*256+'2'), %ax    /* print a ! */
194
        int     $0x10
195
        jmp     _error
196
 
197
_error:         /* halt on error */
198
        movw    $(0x0E*256+'!'), %ax    /* print a ! */
199
        int     $0x10
200
 
201
        cli
202
        hlt
203
        jmp _start
204
 
205
 
206
        /* Write the 0x55/0xAA signature at the end of the first
207
        block.  Without this signature the BIOS won't consider this
208
        block to be bootable.
209
        */
210
 
211
        . = _start + 510
212
        .byte   0x55
213
        .byte   0xAA
214
 
215
_endload:
216
1:
217
 
218
        /* Lets be nice and wait for the diskette drive motor to go off
219
         * before continuing. */
220
 
221
        movw    $0x40, %ax
222
        movw    %ax, %es
223
        movl    $0x40, %ebx
224
2:      es
225
        movb    (%bx), %al
226
        cmpb    $0, %al
227
        jne     2b
228
 
229
        /* Now we're all loaded up in memory. */
230
 
231
        /* Optionally switch to a high-res video before entering        */
232
        /* protected mode. The mode is controlled by an option in       */
233
        /* the RedBoot configuration, which is not readily visible      */
234
        /* in the application configuration. Therefore RedBoot also     */
235
        /* performs some information-related BIOS calls, getting the    */
236
        /* main SVGA BIOS information and the mode-specific             */
237
        /* information. These are placed in video memory, because       */
238
        /* nothing else should be touching that and it avoids having    */
239
        /* some other special buffer shared between RedBoot and the     */
240
        /* application. The disadvantage is possibly some strange junk  */
241
        /* visible on the screen after RedBoot has started.             */
242
#ifdef CYGNUM_HAL_I386_PC_STARTUP_VIDEO_MODE
243
        movw    $0x4f02, %ax
244
        movw    $ CYGNUM_HAL_I386_PC_STARTUP_VIDEO_MODE, %bx
245
        int     $0x10
246
 
247
        /* SVGA information @ 0x000A0000 */
248
        /* Placing VBE2 at this location before the int10 gives more information */
249
        movw    $0xA000, %ax
250
        movw    %ax, %es
251
        movw    $0x0, %di
252
        movb    $('V'), %es:0(%di)
253
        movb    $('B'), %es:1(%di)
254
        movb    $('E'), %es:2(%di)
255
        movb    $('2'), %es:3(%di)
256
        movw    $0x4f00, %ax
257
        int     $0x10
258
 
259
        /* Information about all supported modes starting @ 0x000A0400  */
260
        /* ds:si is used to index the main mode table, offset 14        */
261
        movw    %es:14(%di),%si
262
        movw    %es:16(%di),%ax
263
        movw    %ax,%ds
264
 
265
        /* es:di is used for the destination.                           */
266
        movw    $0xA000,%ax
267
        movw    %ax,%es
268
        movw    $0x0400,%di
269
 
270
modes_loop:
271
        /* The mode table is terminated by a -1 entry                   */
272
        movw    %ds:0(%si), %cx
273
        cmpw    $0xffff,%cx
274
        je      modes_done
275
        movw    $0x4f01, %ax
276
        int     $0x10
277
        addw    $0x0100, %di
278
        addw    $2,%si
279
        jmp     modes_loop
280
modes_done:
281
 
282
        /* Information about the current mode @ 0x000A0200      */
283
        movw    $0xA000, %ax
284
        movw    %ax, %es
285
        movw    $0x0200, %di
286
        movw    $0x4f01, %ax
287
        movw    $ CYGNUM_HAL_I386_PC_STARTUP_VIDEO_MODE, %cx
288
        int     $0x10
289
#endif
290
 
291
        /* Disable interrupt handling. */
292
        cli
293
 
294
        /* Load GDTR and IDTR. */
295
 
296
        lgdt    %cs:gdt
297
        lidt    %cs:idt
298
 
299
        /* Switch to protected mode. */
300
        movl    %cr0,%eax
301
        orb     $1, %al
302
        movl    %eax,%cr0
303
        ljmp    $8, $3f
304
 
305
        hlt
306
 
307
        .align  4, 0xFF
308
gdt:
309
        .word   gdtEnd - gdtStart
310
        .long   gdtStart
311
 
312
        .align  4, 0xFF
313
idt:
314
        .extern idtStart
315
        .word   0x07FF          # space for 256 entries
316
        .long   idtStart
317
 
318
gdtStart:
319
        /* Selector 0x00 == invalid. */
320
        .word   0x0000
321
        .word   0x0000
322
        .byte   0x00
323
        .byte   0x00
324
        .byte   0x00
325
        .byte   0x00
326
 
327
        /* Selector 0x08 == code. */
328
        .word   0xFFFF
329
        .word   0x0000
330
        .byte   0x00
331
        .byte   0x9B
332
        .byte   0xCF
333
        .byte   0x00
334
 
335
        /* Selector 0x10 == data. */
336
        .word   0xFFFF
337
        .word   0x0000
338
        .byte   0x00
339
        .byte   0x93
340
        .byte   0xCF
341
        .byte   0x00
342
 
343
        /* Selector 0x18 == shorter code: faults any code
344
         * access 0xF0000000-0xFFFFFFFF.
345
         */
346
        .word   0xFFFF
347
        .word   0x0000
348
        .byte   0x00
349
        .byte   0x9B
350
        .byte   0xC7
351
        .byte   0x00
352
 
353
        /* Selector 0x20 == data; faults any access 0xF0000000-0xFFFFFFFF. */
354
        .word   0xFFFF
355
        .word   0x0000
356
        .byte   0x00
357
        .byte   0x93
358
        .byte   0xC7
359
        .byte   0x00
360
 
361
        .align  4, 0xFF
362
gdtEnd:
363
 
364
        .code32
365
3:
366
 
367
        movw    $0x10, %ax
368
        movw    %ax, %ds
369
        movw    %ax, %es
370
        movw    %ax, %fs
371
        movw    %ax, %gs
372
 
373
        /* Make our new stack point to the same place as the old one. */
374
        xorl    %ebx, %ebx
375
        movw    %ss, %bx
376
        shl     $4, %ebx
377
        addl    %esp, %ebx
378
        movw    %ax, %ss
379
        movl    %ebx, %esp
380
        movl    $0, %ebp
381
 
382
        /* Reset the flags register. */
383
        pushl   $0
384
        popfl
385
 
386
hal_cpu_init_end:
387
        nop
388
 
389
        .endm /* hal_cpu_init */
390
 
391
#endif /* CYG_HAL_STARTUP_FLOPPY */
392
 
393
#endif // CYGPKG_HAL_I386_CPU_INIT_DEFINED
394
 
395
##=============================================================================
396
## Interrupt controller support
397
 
398
#define CYGPKG_HAL_I386_INTC_INIT_DEFINED
399
 
400
#ifndef CYG_HAL_STARTUP_RAM
401
 
402
        .macro  hal_intc_init
403
 
404
        # The interrupt controller is configured so that IRQ levels 0-7 trigger
405
        #  interrupt vector 32-39; levels 8-15 trigger 40-47.
406
        movb    $0x11, %al
407
        outb    %al, $0x20
408
        movb    $0x20, %al
409
        outb    %al, $0x21
410
        movb    $0x04, %al
411
        outb    %al, $0x21
412
        movb    $0x01, %al
413
        outb    %al, $0x21
414
        movb    $0xFB, %al                      /* Mask off all interrupts except 2. */
415
        outb    %al, $0x21
416
 
417
        movb    $0x11, %al
418
        outb    %al, $0xA0
419
        movb    $0x28, %al
420
        outb    %al, $0xA1
421
        movb    $0x02, %al
422
        outb    %al, $0xA1
423
        movb    $0x01, %al
424
        outb    %al, $0xA1
425
        movb    $0xFF, %al                      /* Mask off all interrupts. */
426
        outb    %al, $0xA1
427
 
428
        .endm /* hal_intc_init */
429
 
430
#else
431
 
432
        # No need to do any initialization in RAM startup
433
        .macro  hal_intc_init
434
        .endm
435
 
436
#endif
437
 
438
        .macro hal_intc_ack vector
439
        # Use any registers you like.
440
        movl    \vector, %edx
441
        movb    $0x20, %al
442
        cmpl    $0x20, %edx
443
        jl      8f
444
        cmpl    $0x28, %edx
445
        jl      9f
446
        outb    %al, $0xA0
447
9:      outb    %al, $0x20
448
8:      nop
449
        .endm
450
 
451
##=============================================================================
452
#endif // ifndef CYGONCE_HAL_PCMB_INC
453
## end of pcmb.inc

powered by: WebSVN 2.1.0

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