Ticket #5163: boot_keys3.patch

File boot_keys3.patch, 4.3 KB (added by Grey, 14 years ago)
  • src/system/boot/platform/bios_ia32/bios.S

     
    2222#define SAVED_EAX       0x10008
    2323#define SAVED_ES        0x1000c
    2424#define SAVED_FLAGS     0x10010
     25#define SAVED_EBP       0x10014
    2526    // we're overwriting the start of our boot loader to hold some
    2627    // temporary values - the first 1024 bytes of it are used at
    2728    // startup only, and we avoid some linking issues this way
     
    7475    // setup protected stack frame again
    7576    movl    SAVED_ESP, %eax
    7677    movl    %eax, %esp
    77     movl    %eax, %ebp
     78    movl    SAVED_EBP, %ebp
    7879
    7980    // copy the return address to the current stack
    8081    movl    REAL_MODE_STACK, %eax
     
    9697    movl    %esp, %eax
    9798    movl    %eax, SAVED_ESP
    9899
     100    movl    %ebp, SAVED_EBP
     101
    99102    // put the return address on the real mode stack
    100103    movl    (%esp), %eax
    101104    movl    %eax, REAL_MODE_STACK
     
    232235
    233236//--------------------------------------------------------------
    234237
     238/** uint32  search_keyboard_buffer()
     239 *  Search in keyboard buffer keycodes for F8, F12 or Space
     240 *  if not found - search ESC keycode.
     241 */
     242
     243FUNCTION(search_keyboard_buffer)
     244    pushal
     245    pushfl
     246
     247    // make sure the correct IDT is in place
     248    lidt    idt_descriptor
     249
     250    call    switch_to_real_mode
     251    .code16
     252
     253    cld
     254    push    %ds
     255    xorl    %eax, %eax
     256    mov %ax, %ds
     257    mov $0x41E, %si // BIOS kbd buffer
     258search_cycle1:
     259    lodsw
     260    cmp $0x4200, %ax    // test F8 key
     261    jz  to_ret
     262    cmp $0x8600, %ax    // test F12 key
     263    jz  to_ret
     264    cmp $0x3920, %ax    // test Space key
     265    jz  to_ret
     266    cmp $0x440, %si
     267    jnz search_cycle1
     268
     269    movw    $0x41E, %si // BIOS kbd buffer
     270search_cycle2:
     271    lodsw
     272    cmp $0x011B, %ax    // test ESC key
     273    jz  to_ret
     274    cmp $0x440, %si
     275    jnz search_cycle2
     276to_ret:
     277    pop %ds
     278
     279    // save %eax
     280    movl    %eax, (SAVED_EAX - 0x10000)
     281
     282    call    switch_to_protected_mode
     283    .code32
     284
     285    popfl
     286    popal
     287
     288    // restore %eax
     289    movl    SAVED_EAX, %eax
     290
     291    ret
     292
     293//--------------------------------------------------------------
     294
    235295.globl idt_descriptor
    236296idt_descriptor:
    237297    .short  0x7ff               // IDT at 0x0, default real mode location
  • src/system/boot/platform/bios_ia32/keyboard.cpp

     
    5858extern "C" uint32
    5959check_for_boot_keys(void)
    6060{
    61     union key key;
     61    bios_regs regs;
    6262    uint32 options = 0;
    63 
    64     while ((key.ax = check_for_key()) != 0) {
    65         switch (key.code.ascii) {
    66             case ' ':
    67                 options |= BOOT_OPTION_MENU;
    68                 break;
    69             case 0x1b:  // escape
    70                 options |= BOOT_OPTION_DEBUG_OUTPUT;
    71                 break;
    72             case 0:
    73                 // evaluate BIOS scan codes
    74                 // ...
    75                 break;
    76         }
     63    uint32 keycode = 0;
     64    regs.eax = 0x0200;
     65    call_bios(0x16, &regs);
     66        // Read Keyboard flags. bit 0 LShift, bit 1 RShift
     67    if ((regs.eax & 0x03) != 0) {
     68        // LShift or RShift - option menu
     69        options |= BOOT_OPTION_MENU;
     70    } else {
     71        keycode = search_keyboard_buffer();
     72        if (keycode == 0x4200 || keycode == 0x8600 || keycode == 0x3920) {
     73            // F8 or F12 or Space - option menu
     74            options |= BOOT_OPTION_MENU;
     75        } else if (keycode == 0x011B) {
     76            // ESC - debug output
     77            options |= BOOT_OPTION_DEBUG_OUTPUT;
     78        }
    7779    }
    7880
    7981    dprintf("options = %ld\n", options);
  • src/system/boot/platform/bios_ia32/bios.h

     
    4141"C"
    4242#endif
    4343void call_bios(uint8 num, struct bios_regs *regs);
     44extern
     45#ifdef __cplusplus
     46"C"
     47#endif
     48uint32 search_keyboard_buffer();
    4449
    4550#endif  /* BIOS_H */
  • src/system/boot/platform/bios_ia32/start.c

     
    129129    mmu_init();
    130130    parse_multiboot_commandline(&args);
    131131
    132     // wait a bit to give the user the opportunity to press a key
    133     spin(750000);
    134 
    135132    // reading the keyboard doesn't seem to work in graphics mode
    136133    // (maybe a bochs problem)
    137134    sBootOptions = check_for_boot_keys();