I'm making a *really* simple x86 emulator that I'm going to use with my os.
Currently I'm writing it as a program for Windows to easily debug and finish. After it starts working, I'll port the sources to Agola.
I'm using Seabios as its BIOS.
It is 256 kb, then I map it to virtual RAM, 0xC0000 to 0xFFFFF.
I made cs:ip to point to 0xFFFF0 like real 8086.
Then the first instruction at 0xFFFF0 is jump 0xF000:0xE05B, it is correct.
That is the debug output from virtual cpu:
But after jump, something goes bad.CS: ffff EIP: 00000000 | long jump to fe05b
Code: Select all
.data:00000000 2e 66 83 3e 88 70 0f cmpl $0xf,%cs:0x7088
.data:00000007 85 96 f3 31 test %dx,0x31f3(%bp)
.data:0000000b d2 8e d2 66 rorb %cl,0x66d2(%bp)
.data:0000000f bc 07 00 mov $0x7,%sp
.data:00000012 06 push %es
.data:00000013 6b a1 a2 df 0e imul $0xe,-0x205e(%bx,%di),%sp
.data:00000018 98 cbtw
.data:00000019 71 e6 jno 0x00000001
.data:0000001b 65 56 gs push %si
.data:0000001d 65 76 65 gs jbe 0x00000085
.data:00000020 66 65 36 68 3e c7 06 68 gs ss pushl $0x6806c73e
.data:00000028 9c pushf
.data:00000029 76 76 jbe 0x000000a1
.data:0000002b 68 b7 04 push $0x4b7
.data:0000002e 2e 67 8a 9e 2c 0f 1f f2 mov %cs:-0xde0f0d4(%esi),%bl
.data:00000036 e6 78 out %al,$0x78
.data:00000038 a8 62 test $0x62,%al
.data:0000003a d0 (bad)
.data:0000003b f1 icebp
.data:0000003c ff 66 89 jmp *-0x77(%bp)
.data:0000003f c5 66 b9 lds -0x47(%bp),%sp
.data:00000042 10 00 adc %al,(%bx,%si)
.data:00000044 06 push %es
.data:00000045 76 68 jbe 0x000000af
.data:00000047 d5 42 aad $0x42
.data:00000049 48 dec %ax
.data:0000004a 66 89 f8 mov %edi,%eax
.data:0000004d 66 e8 26 f0 06 68 calll 0x6806f079
.data:00000053 5c pop %sp
.data:00000054 07 pop %es
.data:00000055 91 xchg %ax,%cx
.data:00000056 36 78 a4 ss js 0xfffffffd
.data:00000059 78 66 js 0x000000c1
.data:0000005b 83 c4 70 add $0x70,%sp
.data:0000005e 66 5b pop %ebx
.data:00000060 66 5e pop %esi
.data:00000062 66 5f pop %edi
.data:00000064 66 5d pop %ebp
.data:00000066 e9 70 9b jmp 0x00009bd9
.data:00000069 2e 67 66 8b b6 28 0f 1f f6 mov %cs:-0x9e0f0d8(%esi),%esi
.data:00000072 63 1d arpl %bx,(%di)
.data:00000074 26 78 07 es js 0x0000007e
.data:00000077 f8 clc
.data:00000078 2f das
.data:00000079 95 xchg %ax,%bp
.data:0000007a c2 66 4a ret $0x4a66
.data:0000007d 66 81 e2 00 01 67 66 and $0x66670100,%edx
.data:00000084 fb sti
.data:00000085 74 fa je 0x00000081
.data:00000087 66 fa data32 cli
.data:00000089 fc cld
.data:0000008a 16 push %ss
.data:0000008b 69 d0 66 89 imul $0x8966,%ax,%dx
.data:0000008f ea 66 83 ca 80 ljmp $0x80ca,$0x8366
.data:00000094 67 88 54 24 46 mov %dl,0x46(%esp)
.data:00000099 7c 64 jl 0x000000ff
.data:0000009b 42 inc %dx
.data:0000009c 45 inc %bp
.data:0000009d 86 7c 64 xchg %bh,0x64(%si)
.data:000000a0 42 inc %dx
.data:000000a1 42 inc %dx
.data:000000a2 ff 67 c6 jmp *-0x3a(%bx)
.data:000000a5 44 inc %sp
.data:000000a6 24 3f and $0x3f,%al
.data:000000a8 f6 6f b6 imulb -0x4a(%bx)
.data:000000ab db 66 c1 (bad) -0x3f(%bp)
.data:000000ae e3 10 jcxz 0x000000c0
.data:000000b0 66 81 cb 00 04 06 76 or $0x76060400,%ebx
.data:000000b7 68 95 c2 push $0xc295
.data:000000ba 41 inc %cx
.data:000000bb 86 76 6c xchg %dh,0x6c(%bp)
.data:000000be 74 42 je 0x00000102
.data:000000c0 41 inc %cx
.data:000000c1 c0 00 06 rolb $0x6,(%bx,%si)
.data:000000c4 76 6c jbe 0x00000132
.data:000000c6 74 42 je 0x0000010a
.data:000000c8 42 inc %dx
.data:000000c9 01 00 add %ax,(%bx,%si)
.data:000000cb 68 cd 16 push $0x16cd
.data:000000ce 6f outsw %ds:(%si),(%dx)
.data:000000cf b7 c9 mov $0xc9,%bh
.data:000000d1 66 c1 e1 46 shl $0x46,%ecx
.data:000000d5 76 68 jbe 0x0000013f
.data:000000d7 d5 4c aad $0x4c
.data:000000d9 46 inc %si
.data:000000da 76 68 jbe 0x00000144
.data:000000dc 95 xchg %ax,%bp
.data:000000dd 42 inc %dx
.data:000000de 42 inc %dx
.data:000000df 46 inc %si
.data:000000e0 76 6c jbe 0x0000014e
.data:000000e2 74 42 je 0x00000126
.data:000000e4 42 inc %dx
.data:000000e5 81 00 02 67 addw $0x6702,(%bx,%si)
.data:000000e9 66 8d 5c 24 lea 0x24(%si),%ebx
.data:000000ed 86 76 68 xchg %dh,0x68(%bp)
.data:000000f0 d1 41 96 rolw -0x6a(%bx,%di)
.data:000000f3 76 68 jbe 0x0000015d
.data:000000f5 95 xchg %ax,%bp
.data:000000f6 42 inc %dx
.data:000000f7 42 inc %dx
.data:000000f8 c6 (bad)
.data:000000f9 76 6c jbe 0x00000167
.data:000000fb 74 42 je 0x0000013f
.data:000000fd 43 inc %bx
.data:000000fe 00 08 add %cl,(%bx,%si)
.data:00000100 28 76 76 sub %dh,0x76(%bp)
.data:00000103 6c insb (%dx),%es:(%di)
.data:00000104 74 42 je 0x00000148
.data:00000106 43 inc %bx
.data:00000107 41 inc %cx
.data:00000108 80 00 67 addb $0x67,(%bx,%si)
.data:0000010b 66 c7 44 24 38 20 07 67 movl $0x67072038,0x24(%si)
.data:00000113 66 8d 54 c6 lea -0x3a(%si),%edx
.data:00000117 67 66 89 54 24 3c mov %edx,0x3c(%esp)
.data:0000011d 67 66 c7 44 24 40 00 05 06 76 movl $0x76060500,0x40(%esp)
.data:00000127 6c insb (%dx),%es:(%di)
.data:00000128 74 42 je 0x0000016c
.data:0000012a 44 inc %sp
.data:0000012b 40 inc %ax
.data:0000012c 00 06 76 6c add %al,0x6c76
.data:00000130 74 42 je 0x00000174
.data:00000132 44 inc %sp
.data:00000133 82 (bad)
.data:00000134 00 76 76 add %dh,0x76(%bp)
.data:00000137 68 95 42 push $0x4295
.data:0000013a 44 inc %sp
.data:0000013b c6 (bad)
.data:0000013c 76 68 jbe 0x000001a6
.data:0000013e 94 xchg %ax,%sp
.data:0000013f 42 inc %dx
.data:00000140 45 inc %bp
.data:00000141 06 push %es
.data:00000142 76 68 jbe 0x000001ac
.data:00000144 b7 67 mov $0x67,%bh
.data:00000146 66 89 44 24 mov %eax,0x24(%si)
.data:0000014a 54 push %sp
.data:0000014b 67 66 c7 44 24 58 10 03 67 66 movl $0x66670310,0x58(%esp)
.data:00000155 8d 44 c2 lea -0x3e(%si),%ax
.data:00000158 67 66 89 44 24 5c mov %eax,0x5c(%esp)
.data:0000015e 67 66 c7 44 24 60 10 07 67 66 movl $0x66670710,0x60(%esp)
.data:00000168 8d 44 c3 lea -0x3d(%si),%ax
.data:0000016b 67 66 89 44 24 64 mov %eax,0x64(%esp)
.data:00000171 67 66 c7 44 24 68 00 89 86 76 movl $0x76868900,0x68(%esp)
.data:0000017b 6c insb (%dx),%es:(%di)
.data:0000017c 74 42 je 0x000001c0
.data:0000017e 46 inc %si
.data:0000017f c0 00 06 rolb $0x6,(%bx,%si)
.data:00000182 76 68 jbe 0x000001ec
.data:00000184 d4 cc aam $0xcc
.data:00000186 18 66 89 sbb %ah,-0x77(%bp)
.data:00000189 f3 67 66 8d 56 2c repz lea 0x2c(%esi),%edx
.data:0000018f 88 c8 mov %cl,%al
.data:00000191 ee out %al,(%dx)
.data:00000192 66 89 c8 mov %ecx,%eax
.data:00000195 66 c1 e8 86 shr $0x86,%eax
.data:00000199 76 68 jbe 0x00000203
.data:0000019b d5 62 aad $0x62
.data:0000019d de e6 fsubrp %st,%st(6)
.data:0000019f 68 9c 86 push $0x869c
.data:000001a2 6c insb (%dx),%es:(%di)
.data:000001a3 1e push %ds
.data:000001a4 81 06 76 68 d5 62 addw $0x62d5,0x6876
Code looks like a garbage.
Also there is
at early start..data:0000003a d0 (bad)
Am I doing something wrong? How should I load BIOS to memory?
And if the BIOS is 256 kilobytes, there is no space for VGABIOS, does 256 kb SeaBIOS include SeaVGABIOS?
If not, where will I load the VGABIOS?
Also I'm compiling on Windows, how can I compile SeaBIOS from its source, I use MSYS with make but compilation fails full of errors.
Thanks.