Enhance included bios tables.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 2 Mar 2008 16:24:36 +0000 (11:24 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 2 Mar 2008 16:24:36 +0000 (11:24 -0500)
Moved floppy parameter table to its 0xefc7 location.
Define floppy base table as a struct.
Cleaned up definitions in romlayout.S
Fixed bug in handle_15c0 - wasn't clearing cf.
Clean up some post.c usages of bios tables.

13 files changed:
Makefile
TODO
src/biosvar.h
src/boot.c
src/cbt.c
src/config.h
src/disk.h
src/floppy.c
src/floppy_dbt.c [new file with mode: 0644]
src/post.c
src/romlayout.S
src/system.c
src/util.h

index 33136da6e400b83fcdf62f4bacee90b6ec9507f6..f198767a33d970c720916c751d8c9bfa0dbb64ed 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,7 @@ OUT=out/
 SRC16=floppy.c disk.c system.c clock.c serial.c kbd.c mouse.c output.c \
       boot.c ata.c
 SRC32=post.c output.c
+TABLESRC=font.c cbt.c floppy_dbt.c
 
 cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
               /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
@@ -25,7 +26,8 @@ CFLAGS = $(COMMONCFLAGS) -g
 CFLAGS16 = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables
 CFLAGS16WHOLE = $(CFLAGS16) -g -fwhole-program
 
-all: $(OUT) $(OUT)rom.bin
+TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
+all: $(OUT) $(OUT)rom.bin $(TABLETMP)
 
 # Run with "make V=1" to see the actual compile commands
 ifdef V
@@ -64,7 +66,8 @@ $(OUT)blob.16.s:
        @echo "  Generating whole program assembler $@"
        $(Q)$(CC) $(CFLAGS16WHOLE) -S -combine -c $(addprefix src/, $(SRC16)) -o $@
 
-$(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(OUT)font.proc.16.s $(OUT)cbt.proc.16.s
+TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
+$(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(TABLEASM)
        @echo "  Generating 16bit layout of $@"
        $(Q)$(CC) $(CFLAGS16) -c $< -o $@
 
diff --git a/TODO b/TODO
index bd3bbe99d5c6b11eda15725c2d6bd8cf95538ddf..b63351224dc9b8a9a0b1faa2c4814df58a4701a1 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,5 +1,7 @@
 Find out why ubuntu compiles are failing.  Find work around.
 
+Audit all sti/cli calls.
+
 Code assumes ebda segment is static - it doesn't read 0x40e.
 
 See if using an ld script for 16bit mode is a good idea.
@@ -9,8 +11,6 @@ is unnecessary.
 
 Fix makefiles so that they rebuild the required files automatically.
 
-Make sure gdt/idt tables are properly aligned
-
 Cleanup setting of ES on GET/SET_BDA
 
 Make sure inline assembly isn't preventing inlining of calling
index c34bb666abf81631486ddfe22734ee4127acc965..5f362a0b0a5aeca7bc15e8b4af2e7ce82707610f 100644 (file)
@@ -326,9 +326,12 @@ set_cf(struct bregs *regs, int cond)
  ****************************************************************/
 
 struct bios_config_table_s {
-    // XXX
-    u8 x;
-};
+    u16 size;
+    u8 model;
+    u8 submodel;
+    u8 biosrev;
+    u8 feature1, feature2, feature3, feature4, feature5;
+} PACKED;
 
 extern struct bios_config_table_s BIOS_CONFIG_TABLE;
 
index 8595b7f32f05bd6892e3aa24b49c46ac62e6a990..19a4929d8fd9722dc95ee6daa13ce5fe83a322f2 100644 (file)
 #include "cmos.h" // inb_cmos
 #include "ata.h" // ata_detect
 
+// We need a copy of this string, but we are not actually a PnP BIOS,
+// so make sure it is *not* aligned, so OSes will not see it if they
+// scan.
+char pnp_string[] VISIBLE __attribute__((aligned (2))) = " $PnP";
+
 //--------------------------------------------------------------------------
 // print_boot_device
 //   displays the boot device
index 015f16f17fa12777b7778137c16ba65e78c2c073..26744ca036e2d89c2a4db2e2bfa3d82abb94d27d 100644 (file)
--- a/src/cbt.c
+++ b/src/cbt.c
@@ -1,8 +1,42 @@
+// BIOS configuration table.
+//
+// Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
+// Copyright (C) 2002  MandrakeSoft S.A.
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
 #include "biosvar.h" // CONFIG_BIOS_TABLE
 
-// bios variables
+// DMA channel 3 used by hard disk BIOS
+#define CBT_F1_DMA3USED (1<<7)
+// 2nd interrupt controller (8259) installed
+#define CBT_F1_2NDPIC   (1<<6)
+// Real-Time Clock installed
+#define CBT_F1_RTC      (1<<5)
+// INT 15/AH=4Fh called upon INT 09h
+#define CBT_F1_INT154F  (1<<4)
+// wait for external event (INT 15/AH=41h) supported
+#define CBT_F1_WAITEXT  (1<<3)
+// extended BIOS area allocated (usually at top of RAM)
+#define CBT_F1_EBDA     (1<<2)
+// bus is Micro Channel instead of ISA
+#define CBT_F1_MCA      (1<<1)
+// system has dual bus (Micro Channel + ISA)
+#define CBT_F1_MCAISA   (1<<0)
+
+// INT 16/AH=09h (keyboard functionality) supported
+#define CBT_F2_INT1609  (1<<6)
 
 struct bios_config_table_s BIOS_CONFIG_TABLE = {
-    // XXX
-    18,
+    .size     = sizeof(BIOS_CONFIG_TABLE) - 2,
+    .model    = CONFIG_MODEL_ID,
+    .submodel = CONFIG_SUBMODEL_ID,
+    .biosrev  = CONFIG_BIOS_REVISION,
+    .feature1 = (
+        CBT_F1_2NDPIC | CBT_F1_RTC | CBT_F1_EBDA
+        | (CONFIG_KBD_CALL_INT15_4F ? CBT_F1_INT154F : 0)),
+    .feature2 = CBT_F2_INT1609,
+    .feature3 = 0,
+    .feature4 = 0,
+    .feature5 = 0,
 };
index feb8f27f9bd60d8449f4cd2f608c83a519ddf760..a440201df4ab02e114ecedff67c71e76842b1c6d 100644 (file)
@@ -13,4 +13,8 @@
 #define CONFIG_STACK_SEGMENT 0x00
 #define CONFIG_STACK_OFFSET  0xfffe
 
+#define CONFIG_MODEL_ID      0xFC
+#define CONFIG_SUBMODEL_ID   0x00
+#define CONFIG_BIOS_REVISION 0x01
+
 #endif // config.h
index b77dd69d1b88852f386e71327ea7080edf3b73ab..a82857e40d35f76ed4d84acde6eb68f7715fd9b4 100644 (file)
@@ -65,6 +65,28 @@ struct int13dpt_s {
 #define SET_INT13DPT(regs,var,val)                                      \
     SET_FARVAR((regs)->ds, ((struct int13dpt_s*)((regs)->si+0))->var, (val))
 
+// Floppy "Disk Base Table"
+struct floppy_dbt_s {
+    u8 specify1;
+    u8 specify2;
+    u8 shutoff_ticks;
+    u8 bps_code;
+    u8 sectors;
+    u8 interblock_len;
+    u8 data_len;
+    u8 gap_len;
+    u8 fill_byte;
+    u8 settle_time;
+    u8 startup_time;
+};
+
+struct floppy_ext_dbt_s {
+    struct floppy_dbt_s dbt;
+    // Extra fields
+    u8 max_track;
+    u8 data_rate;
+    u8 drive_type;
+};
 
 // floppy.c
 void floppy_13(struct bregs *regs, u8 drive);
index 0ff22a200aaa95cc5e103653056d30880fdab45b..9131d98b8bfe7fe3a178183051377bce554ef88c 100644 (file)
 
 #define BX_FLOPPY_ON_CNT 37   /* 2 seconds */
 
-// XXX - //.org 0xefc7
-
-// Since no provisions are made for multiple drive types, most
-// values in this table are ignored.  I set parameters for 1.44M
-// floppy here
-char diskette_param_table[11] = {
-    0xAF,
-    0x02, // head load time 0000001, DMA used
-    0x25,
-    0x02,
-    18,
-    0x1B,
-    0xFF,
-    0x6C,
-    0xF6,
-    0x0F,
-    0x08,
-};
-
 // New diskette parameter table adding 3 parameters from IBM
 // Since no provisions are made for multiple drive types, most
 // values in this table are ignored.  I set parameters for 1.44M
 // floppy here
-char diskette_param_table2[14] VISIBLE = {
-    0xAF,
-    0x02, // head load time 0000001, DMA used
-    0x25,
-    0x02,
-    18,
-    0x1B,
-    0xFF,
-    0x6C,
-    0xF6,
-    0x0F,
-    0x08,
-    79,   // maximum track
-    0,    // data transfer rate
-    4,    // drive type in cmos
+struct floppy_ext_dbt_s diskette_param_table2 VISIBLE = {
+    .dbt = {
+        .specify1       = 0xAF,
+        .specify2       = 0x02, // head load time 0000001, DMA used
+        .shutoff_ticks  = 0x25,
+        .bps_code       = 0x02,
+        .sectors        = 18,
+        .interblock_len = 0x1B,
+        .data_len       = 0xFF,
+        .gap_len        = 0x6C,
+        .fill_byte      = 0xF6,
+        .settle_time    = 0x0F,
+        .startup_time   = 0x08,
+    },
+    .max_track      = 79,   // maximum track
+    .data_rate      = 0,    // data transfer rate
+    .drive_type     = 4,    // drive type in cmos
 };
 
 // Oddities:
@@ -196,7 +179,7 @@ floppy_cmd(struct bregs *regs, u16 count, u8 *cmd, u8 cmdlen)
         // read
         mode_register = 0x46;
 
-    DEBUGF("floppy dma c2");
+    //DEBUGF("floppy dma c2\n");
     outb(0x06, PORT_DMA1_MASK_REG);
     outb(0x00, PORT_DMA1_CLEAR_FF_REG); // clear flip-flop
     outb(base_address, PORT_DMA_ADDR_2);
@@ -660,7 +643,7 @@ floppy_1308(struct bregs *regs, u8 drive)
 
     /* set es & di to point to 11 byte diskette param table in ROM */
     regs->es = SEG_BIOS;
-    regs->di = (u16)diskette_param_table2;
+    regs->di = (u16)&diskette_param_table2;
     /* disk status not changed upon success */
 }
 
diff --git a/src/floppy_dbt.c b/src/floppy_dbt.c
new file mode 100644 (file)
index 0000000..dc8ebc0
--- /dev/null
@@ -0,0 +1,24 @@
+// Floppy controller parameter table.
+//
+// Copyright (C) 2002  MandrakeSoft S.A.
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
+#include "disk.h" // diskette_param_table
+
+// Since no provisions are made for multiple drive types, most
+// values in this table are ignored.  I set parameters for 1.44M
+// floppy here
+struct floppy_dbt_s diskette_param_table VISIBLE = {
+    .specify1       = 0xAF,
+    .specify2       = 0x02, // head load time 0000001, DMA used
+    .shutoff_ticks  = 0x25,
+    .bps_code       = 0x02,
+    .sectors        = 18,
+    .interblock_len = 0x1B,
+    .data_len       = 0xFF,
+    .gap_len        = 0x6C,
+    .fill_byte      = 0xF6,
+    .settle_time    = 0x0F,
+    .startup_time   = 0x08,
+};
index 3fcc25126bb9d030a570a251760f40487a5cc60a..0af8c0c47e490d34fe40d42718017f538d11cf19 100644 (file)
@@ -33,7 +33,7 @@ init_bda()
 
     int i;
     for (i=0; i<256; i++) {
-        bda->ivecs[i].seg = 0xf000;
+        bda->ivecs[i].seg = SEG_BIOS;
         bda->ivecs[i].offset = OFFSET_dummy_iret_handler;
     }
 
@@ -451,8 +451,8 @@ callrom(u16 seg, u16 offset)
 {
     struct bregs br;
     memset(&br, 0, sizeof(br));
-    br.es = 0xf000;
-    br.di = OFFSET_pnp_string;
+    br.es = SEG_BIOS;
+    br.di = OFFSET_pnp_string + 1; // starts 1 past for alignment
     br.cs = seg;
     br.ip = offset;
     call16(&br);
@@ -533,7 +533,7 @@ post()
     init_boot_vectors();
     rom_scan(0xc8000, 0xe0000);
 
-    callrom(0xf000, OFFSET_begin_boot);
+    callrom(SEG_BIOS, OFFSET_begin_boot);
 }
 
 static void
index 4a067e13ed21a4afc1fd97ee9e5c9d373ab9caa0..0a4bf5d3857a01b4da3ee8ac358c7ef161bba8c0 100644 (file)
@@ -224,6 +224,7 @@ rombios32_gdt_48:
         .word rombios32_gdt
         .word 0x000f
 
+        .balign 8
 rombios32_gdt:
         .word 0, 0, 0, 0
         .word 0, 0, 0, 0
@@ -236,15 +237,6 @@ rombios32_gdt:
         // 16 bit data segment base=0x0 limit=0xffff (REAL_MODE_DS)
         .word 0xffff, 0, 0x9300, 0x0000
 
-// We need a copy of this string, but we are not actually a PnP BIOS,
-// so make sure it is *not* aligned, so OSes will not see it if they
-// scan.
-        .align 2
-        .byte 0
-        .globl pnp_string
-pnp_string:
-        .ascii "$PnP"
-
 
 /****************************************************************
  * Interrupt entry points
@@ -342,7 +334,8 @@ entry_18:
         IRQ_ENTRY 0e
 
         .org 0xefc7
-        // XXX - Diskette Controller Parameter Table
+.include "out/floppy_dbt.proc.16.s"
+        .text
 
         .org 0xefd2
         IRQ_ENTRY 17
@@ -404,8 +397,7 @@ dummy_iret_handler:
         .ascii "06/23/99"
 
         .org 0xfffe
-        // XXX - model byte 0xFC = AT
-        .byte 0xfc
+        .byte CONFIG_MODEL_ID
         .byte 0x00
 
         .end
index be38c3d50edc9c01f2f7944adcfc366b66f2452c..310a17e28e6bf991083c682ef8207505f072dbac 100644 (file)
@@ -250,6 +250,7 @@ handle_15c0(struct bregs *regs)
 {
     regs->es = SEG_BIOS;
     regs->bx = (u16)&BIOS_CONFIG_TABLE;
+    handle_ret(regs, 0);
 }
 
 static void
index 6689b062a90f2f3b571d409c380e221dbe59728b..b858e8cb43fb07b2455c6a6186a88e4b9e54274f 100644 (file)
@@ -82,7 +82,7 @@ void call16(struct bregs *callregs)
 static inline
 void __call16_int(struct bregs *callregs, u16 offset)
 {
-    callregs->cs = 0xf000;
+    callregs->cs = SEG_BIOS;
     callregs->ip = offset;
     call16(callregs);
 }