199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1998 Robert Nordier
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms are freely
199767f8919635c4928607450d9e0abb932109ceToomas Soome * permitted provided that the above copyright notice and this
199767f8919635c4928607450d9e0abb932109ceToomas Soome * paragraph and the following disclaimer are duplicated in all
199767f8919635c4928607450d9e0abb932109ceToomas Soome * such forms.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This software is provided "AS IS" and without any express or
199767f8919635c4928607450d9e0abb932109ceToomas Soome * implied warranties, including, without limitation, the implied
199767f8919635c4928607450d9e0abb932109ceToomas Soome * warranties of merchantability and fitness for a particular
199767f8919635c4928607450d9e0abb932109ceToomas Soome * purpose.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <bootargs.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Memory layout.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_BTX,0x1000 # Start of BTX memory
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_ESP0,0x1800 # Supervisor stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_BUF,0x1800 # Scratch buffer
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_ESPR,0x5e00 # Real mode stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_IDT,0x5e00 # IDT
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_TSS,0x5f98 # TSS
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_MAP,0x6000 # I/O bit map
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_TSS_END,0x7fff # End of TSS
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_ORG,0x9000 # BTX code
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set MEM_USR,0xa000 # Start of user memory
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Paging control.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set PAG_SIZ,0x1000 # Page size
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set PAG_CNT,0x1000 # Pages to map
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Fields in %eflags.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set PSL_RESERVED_DEFAULT,0x00000002
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set PSL_T,0x00000100 # Trap flag
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set PSL_I,0x00000200 # Interrupt enable flag
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set PSL_D,0x00000400 # String instruction direction
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set PSL_NT,0x00004000 # Nested task flag
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set PSL_VM,0x00020000 # Virtual 8086 mode flag
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set PSL_AC,0x00040000 # Alignment check flag
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Segment selectors.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_SCODE,0x8 # Supervisor code
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_SDATA,0x10 # Supervisor data
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_RCODE,0x18 # Real mode code
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_RDATA,0x20 # Real mode data
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_UCODE,0x28|3 # User code
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_UDATA,0x30|3 # User data
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_TSS,0x38 # TSS
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Task state segment fields.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set TSS_ESP0,0x4 # PL 0 ESP
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set TSS_SS0,0x8 # PL 0 SS
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set TSS_MAP,0x66 # I/O bit map base
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * System calls.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SYS_EXIT,0x0 # Exit
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SYS_EXEC,0x1 # Exec
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Fields in V86 interface structure.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set V86_CTL,0x0 # Control flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set V86_ADDR,0x4 # Int number/address
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set V86_ES,0x8 # V86 ES
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set V86_DS,0xc # V86 DS
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set V86_FS,0x10 # V86 FS
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set V86_GS,0x14 # V86 GS
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * V86 control flags.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set V86F_ADDR,0x10000 # Segment:offset address
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set V86F_CALLF,0x20000 # Emulate far call
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set V86F_FLAGS,0x40000 # Return flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Dump format control bytes.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set DMP_X16,0x1 # Word
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set DMP_X32,0x2 # Long
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set DMP_MEM,0x4 # Memory
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set DMP_EOL,0x8 # End of line
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Screen defaults and assumptions.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SCR_MAT,0x7 # Mode/attribute
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SCR_COL,0x50 # Columns per row
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SCR_ROW,0x19 # Rows per screen
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * BIOS Data Area locations.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set BDA_MEM,0x413 # Free memory
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set BDA_SCR,0x449 # Video mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set BDA_POS,0x450 # Cursor position
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set BDA_BOOT,0x472 # Boot howto flag
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Derivations, for brevity.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set _ESP0H,MEM_ESP0>>0x8 # Byte 1 of ESP0
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set _TSSIO,MEM_MAP-MEM_TSS # TSS I/O base
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set _TSSLM,MEM_TSS_END-MEM_TSS # TSS limit
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set _IDTLM,MEM_TSS-MEM_IDT-1 # IDT limit
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Code segment.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl start
199767f8919635c4928607450d9e0abb932109ceToomas Soome .code16
199767f8919635c4928607450d9e0abb932109ceToomas Soomestart: # Start of code
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * BTX header.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomebtx_hdr: .byte 0xeb # Machine ID
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0xe # Header size
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "BTX" # Magic
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x1 # Major version
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x2 # Minor version
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte BTX_FLAGS # Flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word PAG_CNT-MEM_ORG>>0xc # Paging control
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word break-start # Text size
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long 0x0 # Entry address
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Initialization routine.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeinit: cli # Disable interrupts
199767f8919635c4928607450d9e0abb932109ceToomas Soome xor %ax,%ax # Zero/segment
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %ax,%ss # Set up
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov $MEM_ESP0,%sp # stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %ax,%es # Address
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %ax,%ds # data
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl $0x2 # Clear
199767f8919635c4928607450d9e0abb932109ceToomas Soome popfl # flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Initialize memory.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov $MEM_IDT,%di # Memory to initialize
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov $(MEM_ORG-MEM_IDT)/2,%cx # Words to zero
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # Zero-fill
199767f8919635c4928607450d9e0abb932109ceToomas Soome stosw # memory
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Update real mode IDT for reflecting hardware interrupts.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov $intr20,%bx # Address first handler
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov $0x10,%cx # Number of handlers
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov $0x20*4,%di # First real mode IDT entry
199767f8919635c4928607450d9e0abb932109ceToomas Soomeinit.0: mov %bx,(%di) # Store IP
199767f8919635c4928607450d9e0abb932109ceToomas Soome inc %di # Address next
199767f8919635c4928607450d9e0abb932109ceToomas Soome inc %di # entry
199767f8919635c4928607450d9e0abb932109ceToomas Soome stosw # Store CS
199767f8919635c4928607450d9e0abb932109ceToomas Soome add $4,%bx # Next handler
199767f8919635c4928607450d9e0abb932109ceToomas Soome loop init.0 # Next IRQ
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Create IDT.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov $MEM_IDT,%di
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov $idtctl,%si # Control string
199767f8919635c4928607450d9e0abb932109ceToomas Soomeinit.1: lodsb # Get entry
199767f8919635c4928607450d9e0abb932109ceToomas Soome cbw # count
199767f8919635c4928607450d9e0abb932109ceToomas Soome xchg %ax,%cx # as word
199767f8919635c4928607450d9e0abb932109ceToomas Soome jcxz init.4 # If done
199767f8919635c4928607450d9e0abb932109ceToomas Soome lodsb # Get segment
199767f8919635c4928607450d9e0abb932109ceToomas Soome xchg %ax,%dx # P:DPL:type
199767f8919635c4928607450d9e0abb932109ceToomas Soome lodsw # Get control
199767f8919635c4928607450d9e0abb932109ceToomas Soome xchg %ax,%bx # set
199767f8919635c4928607450d9e0abb932109ceToomas Soome lodsw # Get handler offset
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov $SEL_SCODE,%dh # Segment selector
199767f8919635c4928607450d9e0abb932109ceToomas Soomeinit.2: shr %bx # Handle this int?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnc init.3 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %ax,(%di) # Set handler offset
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %dh,0x2(%di) # and selector
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %dl,0x5(%di) # Set P:DPL:type
199767f8919635c4928607450d9e0abb932109ceToomas Soome add $0x4,%ax # Next handler
199767f8919635c4928607450d9e0abb932109ceToomas Soomeinit.3: lea 0x8(%di),%di # Next entry
199767f8919635c4928607450d9e0abb932109ceToomas Soome loop init.2 # Till set done
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp init.1 # Continue
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Initialize TSS.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeinit.4: movb $_ESP0H,TSS_ESP0+1(%di) # Set ESP0
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SEL_SDATA,TSS_SS0(%di) # Set SS0
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $_TSSIO,TSS_MAP(%di) # Set I/O bit map base
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Bring up the system.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov $0x2820,%bx # Set protected mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome callw setpic # IRQ offsets
199767f8919635c4928607450d9e0abb932109ceToomas Soome lidt idtdesc # Set IDT
199767f8919635c4928607450d9e0abb932109ceToomas Soome lgdt gdtdesc # Set GDT
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %cr0,%eax # Switch to protected
199767f8919635c4928607450d9e0abb932109ceToomas Soome inc %ax # mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %eax,%cr0 #
199767f8919635c4928607450d9e0abb932109ceToomas Soome ljmp $SEL_SCODE,$init.8 # To 32-bit code
199767f8919635c4928607450d9e0abb932109ceToomas Soome .code32
199767f8919635c4928607450d9e0abb932109ceToomas Soomeinit.8: xorl %ecx,%ecx # Zero
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SEL_SDATA,%cl # To 32-bit
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %cx,%ss # stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Launch user task.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SEL_TSS,%cl # Set task
199767f8919635c4928607450d9e0abb932109ceToomas Soome ltr %cx # register
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $MEM_USR,%edx # User base address
199767f8919635c4928607450d9e0abb932109ceToomas Soome movzwl %ss:BDA_MEM,%eax # Get free memory
199767f8919635c4928607450d9e0abb932109ceToomas Soome shll $0xa,%eax # To bytes
199767f8919635c4928607450d9e0abb932109ceToomas Soome subl $ARGSPACE,%eax # Less arg space
199767f8919635c4928607450d9e0abb932109ceToomas Soome subl %edx,%eax # Less base
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SEL_UDATA,%cl # User data selector
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ecx # Set SS
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %eax # Set ESP
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x202 # Set flags (IF set)
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $SEL_UCODE # Set CS
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl btx_hdr+0xc # Set EIP
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ecx # Set GS
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ecx # Set FS
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ecx # Set DS
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ecx # Set ES
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %edx # Set EAX
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x7,%cl # Set remaining
199767f8919635c4928607450d9e0abb932109ceToomas Soomeinit.9: push $0x0 # general
199767f8919635c4928607450d9e0abb932109ceToomas Soome loop init.9 # registers
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTX_SERIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome call sio_init # setup the serial console
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome popa # and initialize
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %es # Initialize
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %ds # user
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %fs # segment
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %gs # registers
199767f8919635c4928607450d9e0abb932109ceToomas Soome iret # To user mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Exit routine.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeexit: cli # Disable interrupts
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $MEM_ESP0,%esp # Clear stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Turn off paging.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %cr0,%eax # Get CR0
199767f8919635c4928607450d9e0abb932109ceToomas Soome andl $~0x80000000,%eax # Disable
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax,%cr0 # paging
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorl %ecx,%ecx # Zero
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ecx,%cr3 # Flush TLB
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Restore the GDT in case we caught a kernel trap.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome lgdt %cs:gdtdesc # Set GDT
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * To 16 bits.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ljmpw $SEL_RCODE,$exit.1 # Reload CS
199767f8919635c4928607450d9e0abb932109ceToomas Soome .code16
199767f8919635c4928607450d9e0abb932109ceToomas Soomeexit.1: mov $SEL_RDATA,%cl # 16-bit selector
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %cx,%ss # Reload SS
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %cx,%ds # Load
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %cx,%es # remaining
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %cx,%fs # segment
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %cx,%gs # registers
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * To real-address mode.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome dec %ax # Switch to
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %eax,%cr0 # real mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome ljmp $0x0,$exit.2 # Reload CS
199767f8919635c4928607450d9e0abb932109ceToomas Soomeexit.2: xor %ax,%ax # Real mode segment
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %ax,%ss # Reload SS
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %ax,%ds # Address data
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov $0x7008,%bx # Set real mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome callw setpic # IRQ offsets
199767f8919635c4928607450d9e0abb932109ceToomas Soome lidt ivtdesc # Set IVT
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Reboot or await reset.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome sti # Enable interrupts
199767f8919635c4928607450d9e0abb932109ceToomas Soome testb $0x1,btx_hdr+0x7 # Reboot?
199767f8919635c4928607450d9e0abb932109ceToomas Soomeexit.3: jz exit.3 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw $0x1234, BDA_BOOT # Do a warm boot
199767f8919635c4928607450d9e0abb932109ceToomas Soome ljmp $0xf000,$0xfff0 # reboot the machine
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Set IRQ offsets by reprogramming 8259A PICs.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomesetpic: in $0x21,%al # Save master
199767f8919635c4928607450d9e0abb932109ceToomas Soome push %ax # IMR
199767f8919635c4928607450d9e0abb932109ceToomas Soome in $0xa1,%al # Save slave
199767f8919635c4928607450d9e0abb932109ceToomas Soome push %ax # IMR
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x11,%al # ICW1 to
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0x20 # master,
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0xa0 # slave
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb %bl,%al # ICW2 to
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0x21 # master
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb %bh,%al # ICW2 to
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0xa1 # slave
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x4,%al # ICW3 to
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0x21 # master
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x2,%al # ICW3 to
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0xa1 # slave
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x1,%al # ICW4 to
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0x21 # master,
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0xa1 # slave
199767f8919635c4928607450d9e0abb932109ceToomas Soome pop %ax # Restore slave
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0xa1 # IMR
199767f8919635c4928607450d9e0abb932109ceToomas Soome pop %ax # Restore master
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0x21 # IMR
199767f8919635c4928607450d9e0abb932109ceToomas Soome retw # To caller
199767f8919635c4928607450d9e0abb932109ceToomas Soome .code32
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Exception jump table.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintx00: push $0x0 # Int 0x0: #DE
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp ex_noc # Divide error
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x1 # Int 0x1: #DB
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp ex_noc # Debug
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x3 # Int 0x3: #BP
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp ex_noc # Breakpoint
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x4 # Int 0x4: #OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp ex_noc # Overflow
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x5 # Int 0x5: #BR
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp ex_noc # BOUND range exceeded
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x6 # Int 0x6: #UD
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp ex_noc # Invalid opcode
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x7 # Int 0x7: #NM
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp ex_noc # Device not available
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x8 # Int 0x8: #DF
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp except # Double fault
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xa # Int 0xa: #TS
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp except # Invalid TSS
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xb # Int 0xb: #NP
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp except # Segment not present
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xc # Int 0xc: #SS
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp except # Stack segment fault
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xd # Int 0xd: #GP
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp except # General protection
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xe # Int 0xe: #PF
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp except # Page fault
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintx10: push $0x10 # Int 0x10: #MF
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp ex_noc # Floating-point error
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Save a zero error code.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeex_noc: pushl (%esp,1) # Duplicate int no
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x0,0x4(%esp,1) # Fake error code
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Handle exception.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeexcept: cld # String ops inc
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ds # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %es # most
199767f8919635c4928607450d9e0abb932109ceToomas Soome pusha # registers
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %gs # Set GS
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %fs # Set FS
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ds # Set DS
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %es # Set ES
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpw $SEL_SCODE,0x44(%esp,1) # Supervisor mode?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jne except.1 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ss # Set SS
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp except.2 # Join common code
199767f8919635c4928607450d9e0abb932109ceToomas Soomeexcept.1: pushl 0x50(%esp,1) # Set SS
199767f8919635c4928607450d9e0abb932109ceToomas Soomeexcept.2: pushl 0x50(%esp,1) # Set ESP
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $SEL_SDATA # Set up
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %ds # to
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ds # address
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %es # data
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %esp,%ebx # Stack frame
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $dmpfmt,%esi # Dump format string
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $MEM_BUF,%edi # Buffer
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %edi # Dump to
199767f8919635c4928607450d9e0abb932109ceToomas Soome call dump # buffer
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %esi # and
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # display
199767f8919635c4928607450d9e0abb932109ceToomas Soome leal 0x18(%esp,1),%esp # Discard frame
199767f8919635c4928607450d9e0abb932109ceToomas Soome popa # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %es # registers
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %ds # saved
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpb $0x3,(%esp,1) # Breakpoint?
199767f8919635c4928607450d9e0abb932109ceToomas Soome je except.3 # Yes
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpb $0x1,(%esp,1) # Debug?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jne except.2a # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome testl $PSL_T,0x10(%esp,1) # Trap flag set?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz except.3 # Yes
199767f8919635c4928607450d9e0abb932109ceToomas Soomeexcept.2a: jmp exit # Exit
199767f8919635c4928607450d9e0abb932109ceToomas Soomeexcept.3: leal 0x8(%esp,1),%esp # Discard err, int no
199767f8919635c4928607450d9e0abb932109ceToomas Soome iret # From interrupt
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Reboot the machine by setting the reboot flag and exiting
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomereboot: orb $0x1,btx_hdr+0x7 # Set the reboot flag
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp exit # Terminate BTX and reboot
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Protected Mode Hardware interrupt jump table.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintx20: push $0x8 # Int 0x20: IRQ0
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0x8
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x9 # Int 0x21: IRQ1
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0x9
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xa # Int 0x22: IRQ2
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0xa
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xb # Int 0x23: IRQ3
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0xb
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xc # Int 0x24: IRQ4
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0xc
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xd # Int 0x25: IRQ5
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0xd
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xe # Int 0x26: IRQ6
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0xe
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xf # Int 0x27: IRQ7
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0xf
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x70 # Int 0x28: IRQ8
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0x70
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x71 # Int 0x29: IRQ9
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0x71
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x72 # Int 0x2a: IRQ10
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0x72
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x73 # Int 0x2b: IRQ11
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0x73
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x74 # Int 0x2c: IRQ12
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0x74
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x75 # Int 0x2d: IRQ13
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0x75
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x76 # Int 0x2e: IRQ14
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0x76
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x77 # Int 0x2f: IRQ15
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hw # V86 int 0x77
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Invoke real mode interrupt/function call from user mode with arguments.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintx31: pushl $-1 # Dummy int no for btx_v86
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Invoke real mode interrupt/function call from protected mode.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * We place a trampoline on the user stack that will return to rret_tramp
199767f8919635c4928607450d9e0abb932109ceToomas Soome * which will reenter protected mode and then finally return to the user
199767f8919635c4928607450d9e0abb932109ceToomas Soome * client.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Kernel frame %esi points to: Real mode stack frame at MEM_ESPR:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x00 user %ss -0x04 kernel %esp (with full frame)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x04 user %esp -0x08 btx_v86 pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x08 user %eflags -0x0c flags (only used if interrupt)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x0c user %cs -0x10 real mode CS:IP return trampoline
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x10 user %eip -0x12 real mode flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x14 int no -0x16 real mode CS:IP (target)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x18 %eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x1c %ecx
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x20 %edx
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x24 %ebx
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x28 %esp
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x2c %ebp
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x30 %esi
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x34 %edi
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x38 %gs
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x3c %fs
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x40 %ds
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x44 %es
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x48 zero %eax (hardware int only)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x4c zero %ecx (hardware int only)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x50 zero %edx (hardware int only)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x54 zero %ebx (hardware int only)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x58 zero %esp (hardware int only)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x5c zero %ebp (hardware int only)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x60 zero %esi (hardware int only)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x64 zero %edi (hardware int only)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x68 zero %gs (hardware int only)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x6c zero %fs (hardware int only)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x70 zero %ds (hardware int only)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x74 zero %es (hardware int only)
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint_hw: cld # String ops inc
199767f8919635c4928607450d9e0abb932109ceToomas Soome pusha # Save gp regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %gs # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %fs # seg
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ds # regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %es
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $SEL_SDATA # Set up
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %ds # to
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ds # address
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %es # data
199767f8919635c4928607450d9e0abb932109ceToomas Soome leal 0x44(%esp,1),%esi # Base of frame
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %esp,MEM_ESPR-0x04 # Save kernel stack pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl -0x14(%esi),%eax # Get Int no
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpl $-1,%eax # Hardware interrupt?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jne intusr.1 # Yes
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * v86 calls save the btx_v86 pointer on the real mode stack and read
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the address and flags from the btx_v86 structure. For interrupt
199767f8919635c4928607450d9e0abb932109ceToomas Soome * handler invocations (VM86 INTx requests), disable interrupts,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * tracing, and alignment checking while the handler runs.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $MEM_USR,%ebx # User base
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ebx,%edx # address
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl -0x4(%esi),%ebx # User ESP
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl (%ebx),%ebp # btx_v86 pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl %ebp,%edx # Flatten btx_v86 ptr
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %edx,MEM_ESPR-0x08 # Save btx_v86 ptr
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl V86_ADDR(%edx),%eax # Get int no/address
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl V86_CTL(%edx),%edx # Get control flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl -0x08(%esi),%ebx # Save user flags in %ebx
199767f8919635c4928607450d9e0abb932109ceToomas Soome testl $V86F_ADDR,%edx # Segment:offset?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz intusr.4 # Yes
199767f8919635c4928607450d9e0abb932109ceToomas Soome andl $~(PSL_I|PSL_T|PSL_AC),%ebx # Disable interrupts, tracing,
199767f8919635c4928607450d9e0abb932109ceToomas Soome # and alignment checking for
199767f8919635c4928607450d9e0abb932109ceToomas Soome # interrupt handler
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp intusr.3 # Skip hardware interrupt
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Hardware interrupts store a NULL btx_v86 pointer and use the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * address (interrupt number) from the stack with empty flags. Also,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * push a dummy frame of zeros onto the stack for all the general
199767f8919635c4928607450d9e0abb932109ceToomas Soome * purpose and segment registers and clear %eflags. This gives the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * hardware interrupt handler a clean slate.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintusr.1: xorl %edx,%edx # Control flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %edx,MEM_ESPR-0x08 # NULL btx_v86 ptr
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $12,%ecx # Frame is 12 dwords
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintusr.2: pushl $0x0 # Fill frame
199767f8919635c4928607450d9e0abb932109ceToomas Soome loop intusr.2 # with zeros
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $PSL_RESERVED_DEFAULT,%ebx # Set clean %eflags
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Look up real mode IDT entry for hardware interrupts and VM86 INTx
199767f8919635c4928607450d9e0abb932109ceToomas Soome * requests.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintusr.3: shll $0x2,%eax # Scale
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl (%eax),%eax # Load int vector
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp intusr.5 # Skip CALLF test
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Panic if V86F_CALLF isn't set with V86F_ADDR.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintusr.4: testl $V86F_CALLF,%edx # Far call?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz intusr.5 # Ok
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %edx,0x30(%esp,1) # Place VM86 flags in int no
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $badvm86,%esi # Display bad
199767f8919635c4928607450d9e0abb932109ceToomas Soome call putstr # VM86 call
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %es # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %ds # seg
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %fs # regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %gs
199767f8919635c4928607450d9e0abb932109ceToomas Soome popal # Restore gp regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp ex_noc # Panic
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * %eax now holds the segment:offset of the function.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * %ebx now holds the %eflags to pass to real mode.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * %edx now holds the V86F_* flags.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintusr.5: movw %bx,MEM_ESPR-0x12 # Pass user flags to real mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome # target
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If this is a v86 call, copy the seg regs out of the btx_v86 structure.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl MEM_ESPR-0x08,%ecx # Get btx_v86 ptr
199767f8919635c4928607450d9e0abb932109ceToomas Soome jecxz intusr.6 # Skip for hardware ints
199767f8919635c4928607450d9e0abb932109ceToomas Soome leal -0x44(%esi),%edi # %edi => kernel stack seg regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %esi # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome leal V86_ES(%ecx),%esi # %esi => btx_v86 seg regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $4,%ecx # Copy seg regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # from btx_v86
199767f8919635c4928607450d9e0abb932109ceToomas Soome movsl # to kernel stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %esi # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintusr.6: movl -0x08(%esi),%ebx # Copy user flags to real
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ebx,MEM_ESPR-0x0c # mode return trampoline
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $rret_tramp,%ebx # Set return trampoline
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ebx,MEM_ESPR-0x10 # CS:IP
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax,MEM_ESPR-0x16 # Real mode target CS:IP
199767f8919635c4928607450d9e0abb932109ceToomas Soome ljmpw $SEL_RCODE,$intusr.7 # Change to 16-bit segment
199767f8919635c4928607450d9e0abb932109ceToomas Soome .code16
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintusr.7: movl %cr0,%eax # Leave
199767f8919635c4928607450d9e0abb932109ceToomas Soome dec %al # protected
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax,%cr0 # mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome ljmpw $0x0,$intusr.8
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintusr.8: xorw %ax,%ax # Reset %ds
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax,%ds # and
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax,%ss # %ss
199767f8919635c4928607450d9e0abb932109ceToomas Soome lidt ivtdesc # Set IVT
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %es # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %ds # seg
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %fs # regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %gs
199767f8919635c4928607450d9e0abb932109ceToomas Soome popal # Restore gp regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw $MEM_ESPR-0x16,%sp # Switch to real mode stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome iret # Call target routine
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * For the return to real mode we setup a stack frame like this on the real
199767f8919635c4928607450d9e0abb932109ceToomas Soome * mode stack. Note that callf calls won't pop off the flags, but we just
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ignore that by repositioning %sp to be just above the btx_v86 pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome * so it is aligned. The stack is relative to MEM_ESPR.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x04 kernel %esp
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x08 btx_v86
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x0c %eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x10 %ecx
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x14 %edx
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x18 %ebx
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x1c %esp
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x20 %ebp
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x24 %esi
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x28 %edi
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x2c %gs
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x30 %fs
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x34 %ds
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x38 %es
199767f8919635c4928607450d9e0abb932109ceToomas Soome * -0x3c %eflags
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomerret_tramp: movw $MEM_ESPR-0x08,%sp # Reset stack pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushal # Save gp regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %gs # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %fs # seg
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ds # regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %es
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushfl # Save %eflags
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl $PSL_RESERVED_DEFAULT|PSL_D # Use clean %eflags with
199767f8919635c4928607450d9e0abb932109ceToomas Soome popfl # string ops dec
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorw %ax,%ax # Reset seg
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax,%ds # regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax,%es # (%ss is already 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome lidt idtdesc # Set IDT
199767f8919635c4928607450d9e0abb932109ceToomas Soome lgdt gdtdesc # Set GDT
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %cr0,%eax # Switch to protected
199767f8919635c4928607450d9e0abb932109ceToomas Soome inc %ax # mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %eax,%cr0 #
199767f8919635c4928607450d9e0abb932109ceToomas Soome ljmp $SEL_SCODE,$rret_tramp.1 # To 32-bit code
199767f8919635c4928607450d9e0abb932109ceToomas Soome .code32
199767f8919635c4928607450d9e0abb932109ceToomas Soomerret_tramp.1: xorl %ecx,%ecx # Zero
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SEL_SDATA,%cl # Setup
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %cx,%ss # 32-bit
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %cx,%ds # seg
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %cx,%es # regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl MEM_ESPR-0x04,%esp # Switch to kernel stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome leal 0x44(%esp,1),%esi # Base of frame
199767f8919635c4928607450d9e0abb932109ceToomas Soome andb $~0x2,tss_desc+0x5 # Clear TSS busy
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SEL_TSS,%cl # Set task
199767f8919635c4928607450d9e0abb932109ceToomas Soome ltr %cx # register
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Now we are back in protected mode. The kernel stack frame set up
199767f8919635c4928607450d9e0abb932109ceToomas Soome * before entering real mode is still intact. For hardware interrupts,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * leave the frame unchanged.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpl $0,MEM_ESPR-0x08 # Leave saved regs unchanged
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz rret_tramp.3 # for hardware ints
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * For V86 calls, copy the registers off of the real mode stack onto
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the kernel stack as we want their updated values. Also, initialize
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the segment registers on the kernel stack.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Note that the %esp in the kernel stack after this is garbage, but popa
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ignores it, so we don't have to fix it up.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome leal -0x18(%esi),%edi # Kernel stack GP regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %esi # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $MEM_ESPR-0x0c,%esi # Real mode stack GP regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $8,%ecx # Copy GP regs from
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # real mode stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome movsl # to kernel stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $SEL_UDATA,%eax # Selector for data seg regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $4,%ecx # Initialize %ds,
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # %es, %fs, and
199767f8919635c4928607450d9e0abb932109ceToomas Soome stosl # %gs
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * For V86 calls, copy the saved seg regs on the real mode stack back
199767f8919635c4928607450d9e0abb932109ceToomas Soome * over to the btx_v86 structure. Also, conditionally update the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * saved eflags on the kernel stack based on the flags from the user.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl MEM_ESPR-0x08,%ecx # Get btx_v86 ptr
199767f8919635c4928607450d9e0abb932109ceToomas Soome leal V86_GS(%ecx),%edi # %edi => btx_v86 seg regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome leal MEM_ESPR-0x2c,%esi # %esi => real mode seg regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome xchgl %ecx,%edx # Save btx_v86 ptr
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $4,%ecx # Copy seg regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # from real mode stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome movsl # to btx_v86
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %esi # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl V86_CTL(%edx),%edx # Read V86 control flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome testl $V86F_FLAGS,%edx # User wants flags?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz rret_tramp.3 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl MEM_ESPR-0x3c,%eax # Read real mode flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome andl $~(PSL_T|PSL_NT),%eax # Clear unsafe flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax,-0x08(%esi) # Update user flags (low 16)
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Return to the user task
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomerret_tramp.3: popl %es # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %ds # seg
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %fs # regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %gs
199767f8919635c4928607450d9e0abb932109ceToomas Soome popal # Restore gp regs
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl $4,%esp # Discard int no
199767f8919635c4928607450d9e0abb932109ceToomas Soome iret # Return to user mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * System Call.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintx30: cmpl $SYS_EXEC,%eax # Exec system call?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jne intx30.1 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ss # Set up
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %es # all
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %es # segment
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %ds # registers
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ds # for the
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %fs # program
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %fs # we're
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %gs # invoking
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $MEM_USR,%eax # User base address
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl 0xc(%esp,1),%eax # Change to user
199767f8919635c4928607450d9e0abb932109ceToomas Soome leal 0x4(%eax),%esp # stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %eax # Call
199767f8919635c4928607450d9e0abb932109ceToomas Soome call *%eax # program
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintx30.1: orb $0x1,%ss:btx_hdr+0x7 # Flag reboot
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp exit # Exit
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Dump structure [EBX] to [EDI], using format string [ESI].
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.0: stosb # Save char
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump: lodsb # Load char
199767f8919635c4928607450d9e0abb932109ceToomas Soome testb %al,%al # End of string?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz dump.10 # Yes
199767f8919635c4928607450d9e0abb932109ceToomas Soome testb $0x80,%al # Control?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz dump.0 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb %al,%ch # Save control
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $'=',%al # Append
199767f8919635c4928607450d9e0abb932109ceToomas Soome stosb # '='
199767f8919635c4928607450d9e0abb932109ceToomas Soome lodsb # Get offset
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %esi # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome movsbl %al,%esi # To
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl %ebx,%esi # pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome testb $DMP_X16,%ch # Dump word?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz dump.1 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome lodsw # Get and
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hex16 # dump it
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.1: testb $DMP_X32,%ch # Dump long?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz dump.2 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome lodsl # Get and
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hex32 # dump it
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.2: testb $DMP_MEM,%ch # Dump memory?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz dump.8 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %ds # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome testl $PSL_VM,0x50(%ebx) # V86 mode?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz dump.3 # Yes
199767f8919635c4928607450d9e0abb932109ceToomas Soome verr 0x4(%esi) # Readable selector?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz dump.3 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome ldsl (%esi),%esi # Load pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp dump.4 # Join common code
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.3: lodsl # Set offset
199767f8919635c4928607450d9e0abb932109ceToomas Soome xchgl %eax,%edx # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome lodsl # Get segment
199767f8919635c4928607450d9e0abb932109ceToomas Soome shll $0x4,%eax # * 0x10
199767f8919635c4928607450d9e0abb932109ceToomas Soome addl %edx,%eax # + offset
199767f8919635c4928607450d9e0abb932109ceToomas Soome xchgl %eax,%esi # Set pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.4: movb $2,%dl # Num lines
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.4a: movb $0x10,%cl # Bytes to dump
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.5: lodsb # Get byte and
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hex8 # dump it
199767f8919635c4928607450d9e0abb932109ceToomas Soome decb %cl # Keep count
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz dump.6a # If done
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $'-',%al # Separator
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpb $0x8,%cl # Half way?
199767f8919635c4928607450d9e0abb932109ceToomas Soome je dump.6 # Yes
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $' ',%al # Use space
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.6: stosb # Save separator
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp dump.5 # Continue
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.6a: decb %dl # Keep count
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz dump.7 # If done
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0xa,%al # Line feed
199767f8919635c4928607450d9e0abb932109ceToomas Soome stosb # Save one
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $7,%cl # Leading
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $' ',%al # spaces
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.6b: stosb # Dump
199767f8919635c4928607450d9e0abb932109ceToomas Soome decb %cl # spaces
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz dump.6b
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp dump.4a # Next line
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.7: popl %ds # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.8: popl %esi # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0xa,%al # Line feed
199767f8919635c4928607450d9e0abb932109ceToomas Soome testb $DMP_EOL,%ch # End of line?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz dump.9 # Yes
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $' ',%al # Use spaces
199767f8919635c4928607450d9e0abb932109ceToomas Soome stosb # Save one
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.9: jmp dump.0 # Continue
199767f8919635c4928607450d9e0abb932109ceToomas Soomedump.10: stosb # Terminate string
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret # To caller
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Convert EAX, AX, or AL to hex, saving the result to [EDI].
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomehex32: pushl %eax # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome shrl $0x10,%eax # Do upper
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hex16 # 16
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %eax # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soomehex16: call hex16.1 # Do upper 8
199767f8919635c4928607450d9e0abb932109ceToomas Soomehex16.1: xchgb %ah,%al # Save/restore
199767f8919635c4928607450d9e0abb932109ceToomas Soomehex8: pushl %eax # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome shrb $0x4,%al # Do upper
199767f8919635c4928607450d9e0abb932109ceToomas Soome call hex8.1 # 4
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %eax # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soomehex8.1: andb $0xf,%al # Get lower 4
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpb $0xa,%al # Convert
199767f8919635c4928607450d9e0abb932109ceToomas Soome sbbb $0x69,%al # to hex
199767f8919635c4928607450d9e0abb932109ceToomas Soome das # digit
199767f8919635c4928607450d9e0abb932109ceToomas Soome orb $0x20,%al # To lower case
199767f8919635c4928607450d9e0abb932109ceToomas Soome stosb # Save char
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret # (Recursive)
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Output zero-terminated string [ESI] to the console.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputstr.0: call putchr # Output char
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputstr: lodsb # Load char
199767f8919635c4928607450d9e0abb932109ceToomas Soome testb %al,%al # End of string?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz putstr.0 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret # To caller
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BTX_SERIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SIO_PRT,SIOPRT # Base port
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SIO_FMT,SIOFMT # 8N1
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SIO_DIV,(115200/SIOSPD) # 115200 / SPD
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * int sio_init(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomesio_init: movw $SIO_PRT+0x3,%dx # Data format reg
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SIO_FMT|0x80,%al # Set format
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,(%dx) # and DLAB
199767f8919635c4928607450d9e0abb932109ceToomas Soome pushl %edx # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome subb $0x3,%dl # Divisor latch reg
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw $SIO_DIV,%ax # Set
199767f8919635c4928607450d9e0abb932109ceToomas Soome outw %ax,(%dx) # BPS
199767f8919635c4928607450d9e0abb932109ceToomas Soome popl %edx # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SIO_FMT,%al # Clear
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,(%dx) # DLAB
199767f8919635c4928607450d9e0abb932109ceToomas Soome incl %edx # Modem control reg
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x3,%al # Set RTS,
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,(%dx) # DTR
199767f8919635c4928607450d9e0abb932109ceToomas Soome incl %edx # Line status reg
199767f8919635c4928607450d9e0abb932109ceToomas Soome call sio_getc.1 # Get character
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * int sio_flush(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomesio_flush: xorl %eax,%eax # Return value
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorl %ecx,%ecx # Timeout
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x80,%ch # counter
199767f8919635c4928607450d9e0abb932109ceToomas Soomesio_flush.1: call sio_ischar # Check for character
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz sio_flush.2 # Till none
199767f8919635c4928607450d9e0abb932109ceToomas Soome loop sio_flush.1 # or counter is zero
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $1, %al # Exhausted all tries
199767f8919635c4928607450d9e0abb932109ceToomas Soomesio_flush.2: ret # To caller
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * void sio_putc(int c)
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomesio_putc: movw $SIO_PRT+0x5,%dx # Line status reg
199767f8919635c4928607450d9e0abb932109ceToomas Soome xor %ecx,%ecx # Timeout
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x40,%ch # counter
199767f8919635c4928607450d9e0abb932109ceToomas Soomesio_putc.1: inb (%dx),%al # Transmitter
199767f8919635c4928607450d9e0abb932109ceToomas Soome testb $0x20,%al # buffer empty?
199767f8919635c4928607450d9e0abb932109ceToomas Soome loopz sio_putc.1 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz sio_putc.2 # If timeout
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb 0x4(%esp,1),%al # Get character
199767f8919635c4928607450d9e0abb932109ceToomas Soome subb $0x5,%dl # Transmitter hold reg
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,(%dx) # Write character
199767f8919635c4928607450d9e0abb932109ceToomas Soomesio_putc.2: ret $0x4 # To caller
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * int sio_getc(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomesio_getc: call sio_ischar # Character available?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz sio_getc # No
199767f8919635c4928607450d9e0abb932109ceToomas Soomesio_getc.1: subb $0x5,%dl # Receiver buffer reg
199767f8919635c4928607450d9e0abb932109ceToomas Soome inb (%dx),%al # Read character
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret # To caller
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * int sio_ischar(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomesio_ischar: movw $SIO_PRT+0x5,%dx # Line status register
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorl %eax,%eax # Zero
199767f8919635c4928607450d9e0abb932109ceToomas Soome inb (%dx),%al # Received data
199767f8919635c4928607450d9e0abb932109ceToomas Soome andb $0x1,%al # ready?
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret # To caller
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Output character AL to the serial console.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputchr: pusha # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpb $10, %al # is it a newline?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jne putchr.1 # no?, then leave
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $13 # output a carriage
199767f8919635c4928607450d9e0abb932109ceToomas Soome call sio_putc # return first
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $10, %al # restore %al
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputchr.1: pushl %eax # Push the character
199767f8919635c4928607450d9e0abb932109ceToomas Soome # onto the stack
199767f8919635c4928607450d9e0abb932109ceToomas Soome call sio_putc # Output the character
199767f8919635c4928607450d9e0abb932109ceToomas Soome popa # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret # To caller
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Output character AL to the console.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputchr: pusha # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorl %ecx,%ecx # Zero for loops
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SCR_MAT,%ah # Mode/attribute
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $BDA_POS,%ebx # BDA pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw (%ebx),%dx # Cursor position
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $0xb8000,%edi # Regen buffer (color)
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jne putchr.1 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorw %di,%di # Regen buffer (mono)
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputchr.1: cmpb $0xa,%al # New line?
199767f8919635c4928607450d9e0abb932109ceToomas Soome je putchr.2 # Yes
199767f8919635c4928607450d9e0abb932109ceToomas Soome xchgl %eax,%ecx # Save char
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SCR_COL,%al # Columns per row
199767f8919635c4928607450d9e0abb932109ceToomas Soome mulb %dh # * row position
199767f8919635c4928607450d9e0abb932109ceToomas Soome addb %dl,%al # + column
199767f8919635c4928607450d9e0abb932109ceToomas Soome adcb $0x0,%ah # position
199767f8919635c4928607450d9e0abb932109ceToomas Soome shll %eax # * 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome xchgl %eax,%ecx # Swap char, offset
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax,(%edi,%ecx,1) # Write attr:char
199767f8919635c4928607450d9e0abb932109ceToomas Soome incl %edx # Bump cursor
199767f8919635c4928607450d9e0abb932109ceToomas Soome cmpb $SCR_COL,%dl # Beyond row?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jb putchr.3 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputchr.2: xorb %dl,%dl # Zero column
199767f8919635c4928607450d9e0abb932109ceToomas Soome incb %dh # Bump row
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputchr.3: cmpb $SCR_ROW,%dh # Beyond screen?
199767f8919635c4928607450d9e0abb932109ceToomas Soome jb putchr.4 # No
199767f8919635c4928607450d9e0abb932109ceToomas Soome leal 2*SCR_COL(%edi),%esi # New top line
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # Scroll
199767f8919635c4928607450d9e0abb932109ceToomas Soome movsl # screen
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x20,%al # Space
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SCR_COL,%cl # Columns to clear
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep # Clear
199767f8919635c4928607450d9e0abb932109ceToomas Soome stosw # line
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SCR_ROW-1,%dh # Bottom line
199767f8919635c4928607450d9e0abb932109ceToomas Soomeputchr.4: movw %dx,(%ebx) # Update position
199767f8919635c4928607450d9e0abb932109ceToomas Soome popa # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret # To caller
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome .code16
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Real Mode Hardware interrupt jump table.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeintr20: push $0x8 # Int 0x20: IRQ0
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0x8
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x9 # Int 0x21: IRQ1
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0x9
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xa # Int 0x22: IRQ2
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0xa
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xb # Int 0x23: IRQ3
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0xb
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xc # Int 0x24: IRQ4
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0xc
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xd # Int 0x25: IRQ5
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0xd
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xe # Int 0x26: IRQ6
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0xe
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0xf # Int 0x27: IRQ7
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0xf
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x70 # Int 0x28: IRQ8
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0x70
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x71 # Int 0x29: IRQ9
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0x71
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x72 # Int 0x2a: IRQ10
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0x72
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x73 # Int 0x2b: IRQ11
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0x73
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x74 # Int 0x2c: IRQ12
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0x74
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x75 # Int 0x2d: IRQ13
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0x75
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x76 # Int 0x2e: IRQ14
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0x76
199767f8919635c4928607450d9e0abb932109ceToomas Soome push $0x77 # Int 0x2f: IRQ15
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp int_hwr # V86 int 0x77
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Reflect hardware interrupts in real mode.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint_hwr: push %ax # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome push %ds # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome push %bp # Save
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %sp,%bp # Address stack frame
199767f8919635c4928607450d9e0abb932109ceToomas Soome xchg %bx,6(%bp) # Swap BX, int no
199767f8919635c4928607450d9e0abb932109ceToomas Soome xor %ax,%ax # Set %ds:%bx to
199767f8919635c4928607450d9e0abb932109ceToomas Soome shl $2,%bx # point to
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov %ax,%ds # IDT entry
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov (%bx),%ax # Load IP
199767f8919635c4928607450d9e0abb932109ceToomas Soome mov 2(%bx),%bx # Load CS
199767f8919635c4928607450d9e0abb932109ceToomas Soome xchg %ax,4(%bp) # Swap saved %ax,%bx with
199767f8919635c4928607450d9e0abb932109ceToomas Soome xchg %bx,6(%bp) # CS:IP of handler
199767f8919635c4928607450d9e0abb932109ceToomas Soome pop %bp # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome pop %ds # Restore
199767f8919635c4928607450d9e0abb932109ceToomas Soome lret # Jump to handler
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome .p2align 4
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Global descriptor table.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomegdt: .word 0x0,0x0,0x0,0x0 # Null entry
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff,0x0,0x9200,0xcf # SEL_SDATA
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff,0x0,0x9a00,0x0 # SEL_RCODE
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff,0x0,0x9200,0x0 # SEL_RDATA
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff,MEM_USR,0xfa00,0xcf# SEL_UCODE
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff,MEM_USR,0xf200,0xcf# SEL_UDATA
199767f8919635c4928607450d9e0abb932109ceToomas Soometss_desc: .word _TSSLM,MEM_TSS,0x8900,0x0 # SEL_TSS
199767f8919635c4928607450d9e0abb932109ceToomas Soomegdt.1:
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Pseudo-descriptors.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomegdtdesc: .word gdt.1-gdt-1,gdt,0x0 # GDT
199767f8919635c4928607450d9e0abb932109ceToomas Soomeidtdesc: .word _IDTLM,MEM_IDT,0x0 # IDT
199767f8919635c4928607450d9e0abb932109ceToomas Soomeivtdesc: .word 0x400-0x0-1,0x0,0x0 # IVT
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IDT construction control string.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeidtctl: .byte 0x10, 0x8e # Int 0x0-0xf
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0x7dfb,intx00 # (exceptions)
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x10, 0x8e # Int 0x10
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0x1, intx10 # (exception)
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x10, 0x8e # Int 0x20-0x2f
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff,intx20 # (hardware)
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x1, 0xee # int 0x30
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0x1, intx30 # (system call)
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x2, 0xee # Int 0x31-0x32
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0x1, intx31 # (V86, null)
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x0 # End of string
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Dump format string.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomedmpfmt: .byte '\n' # "\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "int" # "int="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X32, 0x40 # "00000000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "err" # "err="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X32, 0x44 # "00000000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "efl" # "efl="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X32, 0x50 # "00000000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "eip" # "eip="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X32|DMP_EOL,0x48 # "00000000\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "eax" # "eax="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X32, 0x34 # "00000000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "ebx" # "ebx="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X32, 0x28 # "00000000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "ecx" # "ecx="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X32, 0x30 # "00000000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "edx" # "edx="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X32|DMP_EOL,0x2c # "00000000\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "esi" # "esi="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X32, 0x1c # "00000000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "edi" # "edi="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X32, 0x18 # "00000000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "ebp" # "ebp="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X32, 0x20 # "00000000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "esp" # "esp="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X32|DMP_EOL,0x0 # "00000000\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "cs" # "cs="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X16, 0x4c # "0000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "ds" # "ds="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X16, 0xc # "0000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "es" # "es="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X16, 0x8 # "0000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii " " # " "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "fs" # "fs="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X16, 0x10 # "0000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "gs" # "gs="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X16, 0x14 # "0000 "
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "ss" # "ss="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_X16|DMP_EOL,0x4 # "0000\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "cs:eip" # "cs:eip="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_MEM|DMP_EOL,0x48 # "00 00 ... 00 00\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome .ascii "ss:esp" # "ss:esp="
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x80|DMP_MEM|DMP_EOL,0x0 # "00 00 ... 00 00\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome .asciz "BTX halted\n" # End
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Bad VM86 call panic
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomebadvm86: .asciz "Invalid VM86 Request\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * End of BTX memory.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .p2align 4
199767f8919635c4928607450d9e0abb932109ceToomas Soomebreak: