~ubuntu-branches/ubuntu/quantal/seabios/quantal

« back to all changes in this revision

Viewing changes to debian/patches/01_optionrom_extboot.patch

  • Committer: Package Import Robot
  • Author(s): Michael Tokarev
  • Date: 2012-04-17 14:22:01 UTC
  • mfrom: (1.1.5) (1.2.10 sid)
  • Revision ID: package-import@ubuntu.com-20120417142201-jcoabss4bwrhkh8m
Tags: 1.7.0-1
* new upstream release (1.7.0), featuring vgabios.
* drop 1.6.3.1 patch
* do not require root in clean target
* split build procedure into several targets, move bios.bin
  out of out/ directory (preparing for the next change), and
  change clean target accordingly
* build and ship vgabios-{cirrus,stdvga,vmware,qxl,isavga}.bin
* patches/fix-==-in-shell.patch -- fix build error with dash
* move all optionrom files taken from qemu into debian/optionrom,
  instead of having them as patches in debian/patches.  While at
  it, update optionroms from current qemu (1.1) and add
  vapic.bin => kvmvapic.bin compatibility symlink.
* add myself to uploaders
* bump Standards-Version to 3.9.3 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Index: seabios/optionrom/extboot.S
2
 
===================================================================
3
 
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
4
 
+++ seabios/optionrom/extboot.S 2011-11-24 10:30:35.984542155 -0800
5
 
@@ -0,0 +1,691 @@
6
 
+/*
7
 
+ * Extended Boot Option ROM
8
 
+ *
9
 
+ * This program is free software; you can redistribute it and/or modify
10
 
+ * it under the terms of the GNU General Public License as published by
11
 
+ * the Free Software Foundation; either version 2 of the License, or
12
 
+ * (at your option) any later version.
13
 
+ *
14
 
+ * This program is distributed in the hope that it will be useful,
15
 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 
+ * GNU General Public License for more details.
18
 
+ *
19
 
+ * You should have received a copy of the GNU General Public License
20
 
+ * along with this program; if not, write to the Free Software
21
 
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
 
+ *
23
 
+ * Copyright IBM Corporation, 2007
24
 
+ *   Authors: Anthony Liguori <aliguori@us.ibm.com>
25
 
+ */
26
 
+
27
 
+#define OLD_INT19      (0x80 * 4)      /* re-use INT 0x80 BASIC vector */
28
 
+#define OLD_INT13      (0x81 * 4)      /* re-use INT 0x81 BASIC vector */
29
 
+
30
 
+.code16
31
 
+.text
32
 
+       .global _start
33
 
+_start:
34
 
+       .short 0xaa55
35
 
+       .byte (_end - _start) / 512
36
 
+       push %eax
37
 
+       push %ds
38
 
+
39
 
+       /* setup ds so we can access the IVT */
40
 
+       xor %ax, %ax
41
 
+       mov %ax, %ds
42
 
+
43
 
+       /* there is one more bootable HD */
44
 
+       incb 0x0475
45
 
+
46
 
+       /* save old int 19 */
47
 
+       mov (0x19*4), %eax
48
 
+       mov %eax, (OLD_INT19)
49
 
+
50
 
+       /* install out int 19 handler */
51
 
+       movw $int19_handler, (0x19*4)
52
 
+       mov %cs, (0x19*4+2)
53
 
+
54
 
+       pop %ds
55
 
+       pop %eax
56
 
+       lret
57
 
+
58
 
+int19_handler:
59
 
+       push %eax /* reserve space for lret */
60
 
+       push %eax
61
 
+       push %bx
62
 
+       push %cx
63
 
+       push %dx
64
 
+       push %ds
65
 
+
66
 
+       /* setup ds to access IVT */
67
 
+       xor %ax, %ax
68
 
+       mov %ax, %ds
69
 
+
70
 
+       /* save old int 13 to int 2c */
71
 
+       mov (0x13*4), %eax
72
 
+       mov %eax, (OLD_INT13)
73
 
+
74
 
+       /* install our int 13 handler */
75
 
+       movw $int13_handler, (0x13*4)
76
 
+       mov %cs, (0x13*4+2)
77
 
+
78
 
+       /* restore previous int $0x19 handler */
79
 
+       mov (OLD_INT19),%eax
80
 
+       mov %eax,(0x19*4)
81
 
+
82
 
+       /* write old handler as return address onto stack */
83
 
+       push %bp
84
 
+       mov %sp, %bp
85
 
+       mov %eax, 14(%bp)
86
 
+       pop %bp
87
 
+
88
 
+       pop %ds
89
 
+       pop %dx
90
 
+       pop %cx
91
 
+       pop %bx
92
 
+       pop %eax
93
 
+       lret
94
 
+
95
 
+#define FLAGS_CF       0x01
96
 
+
97
 
+/* The two macro below clear/set the carry flag to indicate the status
98
 
+ * of the interrupt execution. It is not enough to issue a clc/stc instruction,
99
 
+ * since the value of the flags register will be overwritten by whatever is
100
 
+ * in the stack frame
101
 
+ */
102
 
+.macro clc_stack
103
 
+       push %bp
104
 
+       mov %sp, %bp
105
 
+       /* 8 = 2 (bp, just pushed) + 2 (ip) + 3 (real mode interrupt frame) */
106
 
+       and $(~FLAGS_CF), 8(%bp)
107
 
+       pop %bp
108
 
+.endm
109
 
+
110
 
+.macro stc_stack
111
 
+       push %bp
112
 
+       /* 8 = 2 (bp, just pushed) + 2 (ip) + 3 (real mode interrupt frame) */
113
 
+       or $(FLAGS_CF), 8(%bp)
114
 
+       pop %bp
115
 
+.endm
116
 
+
117
 
+/* we clobber %bx */
118
 
+.macro alloca size
119
 
+       push %ds
120
 
+       push %bp
121
 
+       mov %sp, %bp  /* remember the current stack position */
122
 
+
123
 
+       mov %ss, %bx
124
 
+       mov %bx, %ds
125
 
+
126
 
+       sub \size, %sp
127
 
+       and $(~0x0F), %sp
128
 
+       mov %sp, %bx
129
 
+
130
 
+       push %bp
131
 
+       mov 0(%bp), %bp
132
 
+.endm
133
 
+
134
 
+/* we clobber %bp */
135
 
+.macro allocbpa size
136
 
+       mov %sp, %bp  /* remember the current stack position */
137
 
+       sub \size, %sp
138
 
+       and $(~0x0F), %sp
139
 
+       push %bp
140
 
+       mov %sp, %bp
141
 
+       add $2, %bp
142
 
+.endm
143
 
+
144
 
+.macro freea
145
 
+       pop %sp
146
 
+       add $2, %sp
147
 
+       pop %ds
148
 
+.endm
149
 
+
150
 
+.macro freebpa
151
 
+       pop %sp
152
 
+.endm
153
 
+
154
 
+.macro dump reg
155
 
+       push %ax
156
 
+       push %dx
157
 
+
158
 
+       mov \reg, %ax
159
 
+       mov $0x406, %dx
160
 
+       outw %ax, %dx
161
 
+
162
 
+       pop %dx
163
 
+       pop %ax
164
 
+.endm
165
 
+
166
 
+.macro callout value
167
 
+       push %bp
168
 
+       push %bx
169
 
+       mov %sp, %bp
170
 
+       alloca $16
171
 
+       push %ax
172
 
+       push %dx
173
 
+
174
 
+       mov %ax, 0(%bx)     /* ax */
175
 
+       mov 0(%bp), %ax     /* bx */
176
 
+       mov %ax, 2(%bx)
177
 
+       mov %cx, 4(%bx)     /* cx */
178
 
+       mov %dx, 6(%bx)     /* dx */
179
 
+       mov %si, 8(%bx)     /* si */
180
 
+       mov %ds, 10(%bx)    /* ds */
181
 
+       mov %es, 12(%bx)    /* ds */
182
 
+       movw \value, 14(%bx) /* value */
183
 
+
184
 
+       mov %bx, %ax
185
 
+       shr $4, %ax
186
 
+       mov %ds, %dx
187
 
+       add %dx, %ax
188
 
+
189
 
+       mov $0x407, %dx
190
 
+       outw %ax, %dx
191
 
+
192
 
+       pop %dx
193
 
+       pop %ax
194
 
+       freea
195
 
+       pop %bx
196
 
+       pop %bp
197
 
+.endm
198
 
+
199
 
+send_command:
200
 
+       push %bp
201
 
+       mov %sp, %bp
202
 
+       push %ax
203
 
+       push %bx
204
 
+       push %dx
205
 
+
206
 
+       mov 4(%bp), %ax
207
 
+       shr $4, %ax
208
 
+       and $0x0FFF, %ax
209
 
+       mov %ss, %bx
210
 
+       add %bx, %ax
211
 
+
212
 
+       mov $0x405, %dx
213
 
+       outw %ax, %dx
214
 
+
215
 
+       pop %dx
216
 
+       pop %bx
217
 
+       pop %ax
218
 
+       pop %bp
219
 
+
220
 
+       push %ax
221
 
+       mov 2(%bx), %ax
222
 
+       pop %ax
223
 
+
224
 
+       ret
225
 
+
226
 
+add32:  /* lo, hi, lo, hi */
227
 
+       push %bp
228
 
+       mov %sp, %bp
229
 
+
230
 
+       movw 4(%bp), %cx  /* hi */
231
 
+       movw 6(%bp), %dx  /* lo */
232
 
+
233
 
+       add  10(%bp), %dx
234
 
+       jnc 1f
235
 
+       add $1, %cx
236
 
+1:     add 8(%bp), %cx
237
 
+
238
 
+       pop %bp
239
 
+       ret
240
 
+
241
 
+mul32:  /* lo,      hi,     lo,     hi */
242
 
+       /* 10(%bp), 8(%bp), 6(%bp), 4(%bp) */
243
 
+       push %bp
244
 
+       mov %sp, %bp
245
 
+       push %ax
246
 
+       push %bx
247
 
+
248
 
+       xor %cx, %cx
249
 
+       xor %dx, %dx
250
 
+
251
 
+       /* for (i = 0; i < 16;) */
252
 
+       xor %bx, %bx
253
 
+0:
254
 
+       cmp $16, %bx
255
 
+       jge 2f
256
 
+
257
 
+       mov 6(%bp), %ax
258
 
+       and $1, %ax
259
 
+       cmp $1, %ax
260
 
+       jne 1f
261
 
+       push 10(%bp)
262
 
+       push 8(%bp)
263
 
+       push %dx
264
 
+       push %cx
265
 
+       call add32
266
 
+       add $8, %sp
267
 
+1:
268
 
+       shlw $1, 8(%bp)
269
 
+       movw 10(%bp), %ax
270
 
+       and $0x8000, %ax
271
 
+       cmp $0x8000, %ax
272
 
+       jne 1f
273
 
+       orw $1, 8(%bp)
274
 
+1:
275
 
+       shlw $1, 10(%bp)
276
 
+       shrw $1, 6(%bp)
277
 
+
278
 
+       /* i++) { */
279
 
+       add $1, %bx
280
 
+       jmp 0b
281
 
+
282
 
+2:
283
 
+       pop %bx
284
 
+       pop %ax
285
 
+       pop %bp
286
 
+       ret
287
 
+
288
 
+disk_reset:
289
 
+       movb $0, %ah
290
 
+       clc_stack
291
 
+       ret
292
 
+
293
 
+/* this really should be a function, not a macro but i'm lazy */
294
 
+.macro read_write_disk_sectors cmd
295
 
+       push %ax
296
 
+       push %bx
297
 
+       push %cx
298
 
+       push %dx
299
 
+       push %si
300
 
+
301
 
+       push %bp
302
 
+       sub $10, %sp
303
 
+       mov %sp, %bp
304
 
+
305
 
+       /* save nb_sectors */
306
 
+       mov %al, 6(%bp)
307
 
+       movb $0, 7(%bp)
308
 
+
309
 
+       /* save buffer */
310
 
+       mov %bx, 8(%bp)
311
 
+
312
 
+       /* cylinders */
313
 
+       xor %ax, %ax
314
 
+       mov %cl, %al
315
 
+       shl $2, %ax
316
 
+       and $0x300, %ax
317
 
+       mov %ch, %al
318
 
+       mov %ax, 0(%bp)
319
 
+
320
 
+       /* heads */
321
 
+       xor %ax, %ax
322
 
+       mov %dh, %al
323
 
+       mov %ax, 2(%bp)
324
 
+
325
 
+       /* sectors - 1 */
326
 
+       xor %ax, %ax
327
 
+       mov %cl, %al
328
 
+       and $0x3F, %al
329
 
+       sub $1, %ax
330
 
+       mov %ax, 4(%bp)
331
 
+
332
 
+       alloca $16
333
 
+
334
 
+       movw $0, 0(%bx) /* read c,h,s */
335
 
+       push %bx
336
 
+       call send_command
337
 
+       add $2, %sp
338
 
+
339
 
+       mov 6(%bx), %ax /* total_sectors */
340
 
+       mov 2(%bp), %si /* *= heads */
341
 
+       mul %si
342
 
+       add 4(%bp), %ax /* += sectors - 1 */
343
 
+
344
 
+       push 4(%bx) /* total_heads */
345
 
+       push $0
346
 
+       push 6(%bx) /* total_sectors */
347
 
+       push $0
348
 
+       call mul32
349
 
+       add $8, %sp
350
 
+
351
 
+       push 0(%bp) /* cylinders */
352
 
+       push $0
353
 
+       push %dx
354
 
+       push %cx
355
 
+       call mul32
356
 
+       add $8, %sp
357
 
+
358
 
+       add %ax, %dx
359
 
+       jnc 1f
360
 
+       add $1, %cx
361
 
+1:
362
 
+       freea
363
 
+
364
 
+       alloca $16
365
 
+
366
 
+       movw \cmd, 0(%bx) /* read */
367
 
+       movw 6(%bp), %ax /* nb_sectors */
368
 
+       movw %ax, 2(%bx)
369
 
+       movw %es, 4(%bx) /* segment */
370
 
+       movw 8(%bp), %ax /* offset */
371
 
+       mov %ax, 6(%bx)
372
 
+       movw %dx, 8(%bx) /* sector */
373
 
+       movw %cx, 10(%bx)
374
 
+       movw $0, 12(%bx)
375
 
+       movw $0, 14(%bx)
376
 
+
377
 
+       push %bx
378
 
+       call send_command
379
 
+       add $2, %sp
380
 
+
381
 
+       freea
382
 
+
383
 
+       add $10, %sp
384
 
+       pop %bp
385
 
+
386
 
+       pop %si
387
 
+       pop %dx
388
 
+       pop %cx
389
 
+       pop %bx
390
 
+       pop %ax
391
 
+
392
 
+       mov $0, %ah
393
 
+       clc_stack
394
 
+       ret
395
 
+.endm
396
 
+
397
 
+read_disk_sectors:
398
 
+       read_write_disk_sectors $0x01
399
 
+
400
 
+write_disk_sectors:
401
 
+       read_write_disk_sectors $0x02
402
 
+
403
 
+read_disk_drive_parameters:
404
 
+       push %bx
405
 
+
406
 
+       /* allocate memory for packet, pointer gets returned in bx */
407
 
+       alloca $16
408
 
+
409
 
+       /* issue command */
410
 
+       movw $0, 0(%bx) /* cmd = 0, read c,h,s */
411
 
+       push %bx
412
 
+       call send_command
413
 
+       add $2, %sp
414
 
+
415
 
+       /* normalize sector value */
416
 
+       movb 6(%bx), %cl
417
 
+       andb $0x3F, %cl
418
 
+       movb %cl, 6(%bx)
419
 
+
420
 
+       /* normalize cylinders */
421
 
+       subw $2, 2(%bx)
422
 
+
423
 
+       /* normalize heads */
424
 
+       subw $1, 4(%bx)
425
 
+
426
 
+       /* return code */
427
 
+       mov $0, %ah
428
 
+
429
 
+       /* cylinders */
430
 
+       movb 2(%bx), %ch
431
 
+       movb 3(%bx), %cl
432
 
+       shlb $6, %cl
433
 
+       andb $0xC0, %cl
434
 
+
435
 
+       /* sectors */
436
 
+       orb 6(%bx), %cl
437
 
+
438
 
+       /* heads */
439
 
+       movb 4(%bx), %dh
440
 
+
441
 
+       /* drives */
442
 
+       movb $1, %dl
443
 
+
444
 
+       /* status */
445
 
+       mov $0, %ah
446
 
+
447
 
+       freea
448
 
+
449
 
+       pop %bx
450
 
+
451
 
+       /* do this last since it's the most sensitive */
452
 
+       clc_stack
453
 
+       ret
454
 
+
455
 
+alternate_disk_reset:
456
 
+       movb $0, %ah
457
 
+       clc_stack
458
 
+       ret
459
 
+
460
 
+read_disk_drive_size:
461
 
+       push %bx
462
 
+       alloca $16
463
 
+
464
 
+       movw $0, 0(%bx) /* cmd = 0, read c,h,s */
465
 
+       push %bx
466
 
+       call send_command
467
 
+       add $2, %sp
468
 
+
469
 
+       /* cylinders - 1 to cx:dx */
470
 
+       mov 2(%bx), %dx
471
 
+       xor %cx, %cx
472
 
+       sub $1, %dx
473
 
+
474
 
+       /* heads */
475
 
+       push 4(%bx)
476
 
+       push $0
477
 
+       push %dx
478
 
+       push %cx
479
 
+       call mul32
480
 
+       add $8, %sp
481
 
+
482
 
+       /* sectors */
483
 
+       push 6(%bx)
484
 
+       push $0
485
 
+       push %dx
486
 
+       push %cx
487
 
+       call mul32
488
 
+       add $8, %sp
489
 
+
490
 
+       /* status */
491
 
+       mov $3, %ah
492
 
+
493
 
+       freea
494
 
+       pop %bx
495
 
+
496
 
+       clc_stack
497
 
+       ret
498
 
+
499
 
+check_if_extensions_present:
500
 
+       mov $0x30, %ah
501
 
+       mov $0xAA55, %bx
502
 
+       mov $0x07, %cx
503
 
+       clc_stack
504
 
+       ret
505
 
+
506
 
+.macro extended_read_write_sectors cmd
507
 
+       cmpb $10, 0(%si)
508
 
+       jg 1f
509
 
+       mov $1, %ah
510
 
+       stc_stack
511
 
+       ret
512
 
+1:
513
 
+       push %ax
514
 
+       push %bp
515
 
+       allocbpa $16
516
 
+
517
 
+       movw \cmd, 0(%bp) /* read */
518
 
+       movw 2(%si), %ax   /* nb_sectors */
519
 
+       movw %ax, 2(%bp)
520
 
+       movw 4(%si), %ax   /* offset */
521
 
+       movw %ax, 6(%bp)
522
 
+       movw 6(%si), %ax   /* segment */
523
 
+       movw %ax, 4(%bp)
524
 
+       movw 8(%si), %ax   /* block */
525
 
+       movw %ax, 8(%bp)
526
 
+       movw 10(%si), %ax
527
 
+       movw %ax, 10(%bp)
528
 
+       movw 12(%si), %ax
529
 
+       movw %ax, 12(%bp)
530
 
+       movw 14(%si), %ax
531
 
+       movw %ax, 14(%bp)
532
 
+
533
 
+       push %bp
534
 
+       call send_command
535
 
+       add $2, %sp
536
 
+
537
 
+       freebpa
538
 
+       pop %bp
539
 
+       pop %ax
540
 
+
541
 
+       mov $0, %ah
542
 
+       clc_stack
543
 
+       ret
544
 
+.endm
545
 
+
546
 
+extended_read_sectors:
547
 
+       extended_read_write_sectors $0x01
548
 
+
549
 
+extended_write_sectors:
550
 
+       extended_read_write_sectors $0x02
551
 
+
552
 
+get_extended_drive_parameters:
553
 
+       push %ax
554
 
+       push %bp
555
 
+       push %cx
556
 
+       push %dx
557
 
+
558
 
+       allocbpa $16
559
 
+
560
 
+       movw $0, 0(%bp) /* read c,h,s */
561
 
+       push %bp
562
 
+       call send_command
563
 
+       add $2, %sp
564
 
+
565
 
+       /* write size */
566
 
+       movw $26, 0(%si)
567
 
+
568
 
+       /* set flags to 2 */
569
 
+       movw $2, 2(%si)
570
 
+
571
 
+       /* cylinders */
572
 
+       mov 2(%bp), %ax
573
 
+       mov %ax, 4(%si)
574
 
+       xor %ax, %ax
575
 
+       mov %ax, 6(%si)
576
 
+
577
 
+       /* heads */
578
 
+       mov 4(%bp), %ax
579
 
+       mov %ax, 8(%si)
580
 
+       xor %ax, %ax
581
 
+       mov %ax, 10(%si)
582
 
+
583
 
+       /* sectors */
584
 
+       mov 6(%bp), %ax
585
 
+       mov %ax, 12(%si)
586
 
+       xor %ax, %ax
587
 
+       mov %ax, 14(%si)
588
 
+
589
 
+       /* set total number of sectors */
590
 
+       mov 8(%bp), %ax
591
 
+       mov %ax, 16(%si)
592
 
+       mov 10(%bp), %ax
593
 
+       mov %ax, 18(%si)
594
 
+       mov 12(%bp), %ax
595
 
+       mov %ax, 20(%si)
596
 
+       mov 14(%bp), %ax
597
 
+       mov %ax, 22(%si)
598
 
+
599
 
+       /* number of bytes per sector */
600
 
+       movw $512, 24(%si)
601
 
+
602
 
+       freebpa
603
 
+
604
 
+       pop %dx
605
 
+       pop %cx
606
 
+       pop %bp
607
 
+       pop %ax
608
 
+
609
 
+       mov $0, %ah
610
 
+       clc_stack
611
 
+       ret
612
 
+
613
 
+terminate_disk_emulation:
614
 
+       mov $1, %ah
615
 
+       stc_stack
616
 
+       ret
617
 
+
618
 
+int13_handler:
619
 
+       cmp $0x80, %dl
620
 
+       je 1f
621
 
+
622
 
+       /* write old handler as return address onto stack */
623
 
+       push %eax
624
 
+       push %eax
625
 
+       push %ds
626
 
+       push %bp
627
 
+       mov %sp, %bp
628
 
+       xor %ax, %ax
629
 
+       mov %ax, %ds
630
 
+       mov (OLD_INT13), %eax
631
 
+       mov %eax, 8(%bp)
632
 
+       pop %bp
633
 
+       pop %ds
634
 
+       pop %eax
635
 
+       lret
636
 
+1:
637
 
+       cmp $0x0, %ah
638
 
+       jne 1f
639
 
+       call disk_reset
640
 
+       iret
641
 
+1:
642
 
+       cmp $0x2, %ah
643
 
+       jne 1f
644
 
+       call read_disk_sectors
645
 
+       iret
646
 
+1:
647
 
+       cmp $0x8, %ah
648
 
+       jne 1f
649
 
+       call read_disk_drive_parameters
650
 
+       iret
651
 
+1:
652
 
+       cmp $0x15, %ah
653
 
+       jne 1f
654
 
+       call read_disk_drive_size
655
 
+       iret
656
 
+1:
657
 
+       cmp $0x41, %ah
658
 
+       jne 1f
659
 
+       call check_if_extensions_present
660
 
+       iret
661
 
+1:
662
 
+       cmp $0x42, %ah
663
 
+       jne 1f
664
 
+       call extended_read_sectors
665
 
+       iret
666
 
+1:
667
 
+       cmp $0x48, %ah
668
 
+       jne 1f
669
 
+       call get_extended_drive_parameters
670
 
+       iret
671
 
+1:
672
 
+       cmp $0x4b, %ah
673
 
+       jne 1f
674
 
+       call terminate_disk_emulation
675
 
+       iret
676
 
+1:
677
 
+       cmp $0x0d, %ah
678
 
+       jne 1f
679
 
+       call alternate_disk_reset
680
 
+       iret
681
 
+1:
682
 
+       cmp $0x03, %ah
683
 
+       jne 1f
684
 
+       call write_disk_sectors
685
 
+       iret
686
 
+1:
687
 
+       cmp $0x43, %ah
688
 
+       jne 1f
689
 
+       call extended_write_sectors
690
 
+       iret
691
 
+1:
692
 
+       int $0x18  /* boot failed */
693
 
+       iret
694
 
+
695
 
+.align 512, 0
696
 
+_end: