wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Daniel Engström, Omicron Ceti AB, daniel@omicron.se |
| 4 | * |
| 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 | |
| 29 | |
| 30 | #define REALMODE_BASE ((char*)0x7c0) |
| 31 | #define REALMODE_MAILBOX ((char*)0xe00) |
| 32 | |
| 33 | |
| 34 | extern char realmode_enter; |
| 35 | |
| 36 | |
| 37 | int enter_realmode(u16 seg, u16 off, struct pt_regs *in, struct pt_regs *out) |
| 38 | { |
| 39 | |
| 40 | /* setup out thin bios emulation */ |
| 41 | if (bios_setup()) { |
| 42 | return -1; |
| 43 | } |
| 44 | |
| 45 | /* copy the realmode switch code */ |
| 46 | if (i386boot_realmode_size > (REALMODE_MAILBOX-REALMODE_BASE)) { |
| 47 | printf("realmode switch too large (%ld bytes, max is %d)\n", |
wdenk | ea909b7 | 2002-11-21 23:11:29 +0000 | [diff] [blame] | 48 | i386boot_realmode_size, (int)(REALMODE_MAILBOX-REALMODE_BASE)); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 49 | return -1; |
| 50 | } |
| 51 | |
wdenk | ea909b7 | 2002-11-21 23:11:29 +0000 | [diff] [blame] | 52 | memcpy(REALMODE_BASE, (void*)i386boot_realmode, i386boot_realmode_size); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 53 | |
| 54 | |
| 55 | in->eip = off; |
| 56 | in->xcs = seg; |
wdenk | ea909b7 | 2002-11-21 23:11:29 +0000 | [diff] [blame] | 57 | if (3>(in->esp & 0xffff)) { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 58 | printf("Warning: entering realmode with sp < 4 will fail\n"); |
| 59 | } |
| 60 | |
| 61 | memcpy(REALMODE_MAILBOX, in, sizeof(struct pt_regs)); |
| 62 | |
| 63 | __asm__ volatile ( |
| 64 | "lcall $0x20,%0\n" : : "i" (&realmode_enter) ); |
| 65 | |
| 66 | memcpy(out, REALMODE_MAILBOX, sizeof(struct pt_regs)); |
| 67 | |
| 68 | return out->eax; |
| 69 | } |
| 70 | |