wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
Albert ARIBAUD | fa82f87 | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 3 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 4 | * |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <asm/io.h> |
| 26 | #include <asm/ptrace.h> |
wdenk | ea909b7 | 2002-11-21 23:11:29 +0000 | [diff] [blame] | 27 | #include <asm/realmode.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 28 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 29 | #define REALMODE_MAILBOX ((char *)0xe00) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 30 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 31 | int realmode_setup(void) |
| 32 | { |
Gabe Black | 03228b2 | 2011-11-12 16:31:18 +0000 | [diff] [blame^] | 33 | /* |
| 34 | * The realmode section is not relocated and still in the ROM. The |
| 35 | * __realmode_start symbol was adjusted, though, so adjust it back. |
| 36 | */ |
| 37 | ulong realmode_start = (ulong)&__realmode_start - gd->reloc_off; |
Graeme Russ | 067f9b1 | 2010-10-07 20:03:31 +1100 | [diff] [blame] | 38 | ulong realmode_size = (ulong)&__realmode_size; |
Graeme Russ | cabe579 | 2009-11-24 20:04:20 +1100 | [diff] [blame] | 39 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 40 | /* copy the realmode switch code */ |
Graeme Russ | 3a25e94 | 2011-02-12 15:11:24 +1100 | [diff] [blame] | 41 | if (realmode_size > (REALMODE_MAILBOX - (char *)REALMODE_BASE)) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 42 | printf("realmode switch too large (%ld bytes, max is %d)\n", |
Graeme Russ | 3a25e94 | 2011-02-12 15:11:24 +1100 | [diff] [blame] | 43 | realmode_size, |
Gabe Black | 4c1c355 | 2011-10-20 18:29:17 +0000 | [diff] [blame] | 44 | (int)(REALMODE_MAILBOX - (char *)REALMODE_BASE)); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 45 | return -1; |
| 46 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 47 | |
Graeme Russ | 3a25e94 | 2011-02-12 15:11:24 +1100 | [diff] [blame] | 48 | memcpy((char *)REALMODE_BASE, (void *)realmode_start, realmode_size); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 49 | asm("wbinvd\n"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 50 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 51 | return 0; |
| 52 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 53 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 54 | int enter_realmode(u16 seg, u16 off, struct pt_regs *in, struct pt_regs *out) |
| 55 | { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 56 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 57 | /* setup out thin bios emulation */ |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 58 | if (bios_setup()) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 59 | return -1; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 60 | |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 61 | if (realmode_setup()) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 62 | return -1; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 63 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 64 | in->eip = off; |
| 65 | in->xcs = seg; |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 66 | if ((in->esp & 0xffff) < 4) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 67 | printf("Warning: entering realmode with sp < 4 will fail\n"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 68 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 69 | memcpy(REALMODE_MAILBOX, in, sizeof(struct pt_regs)); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 70 | asm("wbinvd\n"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 71 | |
| 72 | __asm__ volatile ( |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 73 | "lcall $0x20,%0\n" : : "i" (&realmode_enter)); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 74 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 75 | asm("wbinvd\n"); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 76 | memcpy(out, REALMODE_MAILBOX, sizeof(struct pt_regs)); |
| 77 | |
| 78 | return out->eax; |
| 79 | } |
| 80 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 81 | /* |
| 82 | * This code is supposed to access a realmode interrupt |
| 83 | * it does currently not work for me |
| 84 | */ |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 85 | int enter_realmode_int(u8 lvl, struct pt_regs *in, struct pt_regs *out) |
| 86 | { |
| 87 | /* place two instructions at 0x700 */ |
| 88 | writeb(0xcd, 0x700); /* int $lvl */ |
| 89 | writeb(lvl, 0x701); |
| 90 | writeb(0xcb, 0x702); /* lret */ |
| 91 | asm("wbinvd\n"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 92 | |
| 93 | enter_realmode(0x00, 0x700, in, out); |
| 94 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 95 | return out->eflags & 0x00000001; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 96 | } |