Deleted Added
full compact
btxldr.S (125780) btxldr.S (128710)
1#
2# Copyright (c) 1998 Robert Nordier
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms are freely
6# permitted provided that the above copyright notice and this
7# paragraph and the following disclaimer are duplicated in all
8# such forms.
9#
10# This software is provided "AS IS" and without any express or
11# implied warranties, including, without limitation, the implied
12# warranties of merchantability and fitness for a particular
13# purpose.
14#
1/*
2 * Copyright (c) 1998 Robert Nordier
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are freely
6 * permitted provided that the above copyright notice and this
7 * paragraph and the following disclaimer are duplicated in all
8 * such forms.
9 *
10 * This software is provided "AS IS" and without any express or
11 * implied warranties, including, without limitation, the implied
12 * warranties of merchantability and fitness for a particular
13 * purpose.
14 *
15 * $FreeBSD: head/sys/boot/pc98/btx/btxldr/btxldr.S 128710 2004-04-28 10:15:31Z ru $
16 */
15
17
16# $FreeBSD: head/sys/boot/pc98/btx/btxldr/btxldr.S 125780 2004-02-13 15:39:59Z nyan $
18/*
19 * Prototype BTX loader program, written in a couple of hours. The
20 * real thing should probably be more flexible, and in C.
21 */
17
22
18#
19# Prototype BTX loader program, written in a couple of hours. The
20# real thing should probably be more flexible, and in C.
21#
22
23#
24# Memory locations.
25#
23/*
24 * Memory locations.
25 */
26 .set MEM_STUB,0x600 # Real mode stub
27 .set MEM_ESP,0x1000 # New stack pointer
28 .set MEM_TBL,0x5000 # BTX page tables
29 .set MEM_ENTRY,0x9010 # BTX entry point
30 .set MEM_DATA,start+0x1000 # Data segment
26 .set MEM_STUB,0x600 # Real mode stub
27 .set MEM_ESP,0x1000 # New stack pointer
28 .set MEM_TBL,0x5000 # BTX page tables
29 .set MEM_ENTRY,0x9010 # BTX entry point
30 .set MEM_DATA,start+0x1000 # Data segment
31#
32# Segment selectors.
33#
31/*
32 * Segment selectors.
33 */
34 .set SEL_SCODE,0x8 # 4GB code
35 .set SEL_SDATA,0x10 # 4GB data
36 .set SEL_RCODE,0x18 # 64K code
37 .set SEL_RDATA,0x20 # 64K data
34 .set SEL_SCODE,0x8 # 4GB code
35 .set SEL_SDATA,0x10 # 4GB data
36 .set SEL_RCODE,0x18 # 64K code
37 .set SEL_RDATA,0x20 # 64K data
38#
39# Paging constants.
40#
38/*
39 * Paging constants.
40 */
41 .set PAG_SIZ,0x1000 # Page size
42 .set PAG_ENT,0x4 # Page entry size
41 .set PAG_SIZ,0x1000 # Page size
42 .set PAG_ENT,0x4 # Page entry size
43#
44# Screen constants.
45#
43/*
44 * Screen constants.
45 */
46#ifdef PC98
47 .set SCR_MAT,0xe1 # Mode/attribute
48#else
49 .set SCR_MAT,0x7 # Mode/attribute
50#endif
51 .set SCR_COL,0x50 # Columns per row
52 .set SCR_ROW,0x19 # Rows per screen
46#ifdef PC98
47 .set SCR_MAT,0xe1 # Mode/attribute
48#else
49 .set SCR_MAT,0x7 # Mode/attribute
50#endif
51 .set SCR_COL,0x50 # Columns per row
52 .set SCR_ROW,0x19 # Rows per screen
53#
54# BIOS Data Area locations.
55#
53/*
54 * BIOS Data Area locations.
55 */
56#ifdef PC98
57 .set BDA_MEM,0xa1501 # Free memory
58 .set BDA_POS,0xa153e # Cursor position
59#else
60 .set BDA_MEM,0x413 # Free memory
61 .set BDA_SCR,0x449 # Video mode
62 .set BDA_POS,0x450 # Cursor position
63#endif
56#ifdef PC98
57 .set BDA_MEM,0xa1501 # Free memory
58 .set BDA_POS,0xa153e # Cursor position
59#else
60 .set BDA_MEM,0x413 # Free memory
61 .set BDA_SCR,0x449 # Video mode
62 .set BDA_POS,0x450 # Cursor position
63#endif
64#
65# Required by aout gas inadequacy.
66#
64/*
65 * Required by aout gas inadequacy.
66 */
67 .set SIZ_STUB,0x1a # Size of stub
67 .set SIZ_STUB,0x1a # Size of stub
68#
69# We expect to be loaded by boot2 at the origin defined in ./Makefile.
70#
68/*
69 * We expect to be loaded by boot2 at the origin defined in ./Makefile.
70 */
71 .globl start
71 .globl start
72#
73# BTX program loader for ELF clients.
74#
72/*
73 * BTX program loader for ELF clients.
74 */
75start: cld # String ops inc
76#ifdef PC98
77 cli
78gdcwait.1: inb $0x60,%al
79 testb $0x04,%al
80 jz gdcwait.1
81 movb $0xe0,%al
82 outb %al,$0x62

--- 24 unchanged lines hidden (view full) ---

107#endif
108 movl %eax,%ebp # Base of user stack
109#ifdef BTXLDR_VERBOSE
110 movl $m_mem,%esi # Display
111 call hexout # amount of
112 call putstr # base memory
113#endif
114 lgdt gdtdesc # Load new GDT
75start: cld # String ops inc
76#ifdef PC98
77 cli
78gdcwait.1: inb $0x60,%al
79 testb $0x04,%al
80 jz gdcwait.1
81 movb $0xe0,%al
82 outb %al,$0x62

--- 24 unchanged lines hidden (view full) ---

107#endif
108 movl %eax,%ebp # Base of user stack
109#ifdef BTXLDR_VERBOSE
110 movl $m_mem,%esi # Display
111 call hexout # amount of
112 call putstr # base memory
113#endif
114 lgdt gdtdesc # Load new GDT
115#
116# Relocate caller's arguments.
117#
115/*
116 * Relocate caller's arguments.
117 */
118#ifdef BTXLDR_VERBOSE
119 movl $m_esp,%esi # Display
120 movl %esp,%eax # caller
121 call hexout # stack
122 call putstr # pointer
123 movl $m_args,%esi # Format string
124 leal 0x4(%esp,1),%ebx # First argument
125 movl $0x6,%ecx # Count

--- 25 unchanged lines hidden (view full) ---

151 rep # Copy
152 movsb # them
153#ifdef BTXLDR_VERBOSE
154 movl $m_rel_args,%esi # Display
155 movl %ebp,%eax # argument
156 call hexout # relocation
157 call putstr # message
158#endif
118#ifdef BTXLDR_VERBOSE
119 movl $m_esp,%esi # Display
120 movl %esp,%eax # caller
121 call hexout # stack
122 call putstr # pointer
123 movl $m_args,%esi # Format string
124 leal 0x4(%esp,1),%ebx # First argument
125 movl $0x6,%ecx # Count

--- 25 unchanged lines hidden (view full) ---

151 rep # Copy
152 movsb # them
153#ifdef BTXLDR_VERBOSE
154 movl $m_rel_args,%esi # Display
155 movl %ebp,%eax # argument
156 call hexout # relocation
157 call putstr # message
158#endif
159#
160# Set up BTX kernel.
161#
159/*
160 * Set up BTX kernel.
161 */
162 movl $MEM_ESP,%esp # Set up new stack
163 movl $MEM_DATA,%ebx # Data segment
164 movl $m_vers,%esi # Display BTX
165 call putstr # version message
166 movb 0x5(%ebx),%al # Get major version
167 addb $'0',%al # Display
168 call putchr # it
169 movb $'.',%al # And a

--- 35 unchanged lines hidden (view full) ---

205#endif
206 addl $PAG_SIZ,%ebp # Display
207#ifdef BTXLDR_VERBOSE
208 movl $m_base,%esi # the
209 movl %ebp,%eax # user
210 call hexout # base
211 call putstr # address
212#endif
162 movl $MEM_ESP,%esp # Set up new stack
163 movl $MEM_DATA,%ebx # Data segment
164 movl $m_vers,%esi # Display BTX
165 call putstr # version message
166 movb 0x5(%ebx),%al # Get major version
167 addb $'0',%al # Display
168 call putchr # it
169 movb $'.',%al # And a

--- 35 unchanged lines hidden (view full) ---

205#endif
206 addl $PAG_SIZ,%ebp # Display
207#ifdef BTXLDR_VERBOSE
208 movl $m_base,%esi # the
209 movl %ebp,%eax # user
210 call hexout # base
211 call putstr # address
212#endif
213#
214# Set up ELF-format client program.
215#
213/*
214 * Set up ELF-format client program.
215 */
216 cmpl $0x464c457f,(%ebx) # ELF magic number?
217 je start.3 # Yes
218 movl $e_fmt,%esi # Display error
219 call putstr # message
220start.2: jmp start.2 # Hang
221start.3:
222#ifdef BTXLDR_VERBOSE
223 movl $m_elf,%esi # Display ELF

--- 60 unchanged lines hidden (view full) ---

284 movw %ax,%fs # segment
285 movw %ax,%gs # limits
286 movl %cr0,%eax # Switch to
287 decw %ax # real
288 movl %eax,%cr0 # mode
289 ljmp $0,$MEM_ENTRY # Jump to BTX entry point
290start.9:
291 .code32
216 cmpl $0x464c457f,(%ebx) # ELF magic number?
217 je start.3 # Yes
218 movl $e_fmt,%esi # Display error
219 call putstr # message
220start.2: jmp start.2 # Hang
221start.3:
222#ifdef BTXLDR_VERBOSE
223 movl $m_elf,%esi # Display ELF

--- 60 unchanged lines hidden (view full) ---

284 movw %ax,%fs # segment
285 movw %ax,%gs # limits
286 movl %cr0,%eax # Switch to
287 decw %ax # real
288 movl %eax,%cr0 # mode
289 ljmp $0,$MEM_ENTRY # Jump to BTX entry point
290start.9:
291 .code32
292#
293# Output message [ESI] followed by EAX in hex.
294#
292/*
293 * Output message [ESI] followed by EAX in hex.
294 */
295hexout: pushl %eax # Save
296 call putstr # Display message
297 popl %eax # Restore
298 pushl %esi # Save
299 pushl %edi # caller's
300 movl $buf,%edi # Buffer
301 pushl %edi # Save
302 call hex32 # To hex

--- 6 unchanged lines hidden (view full) ---

309 testb %al,%al # End of string?
310 jne hexout.2 # No
311 decl %esi # Undo
312hexout.2: decl %esi # Adjust for inc
313 call putstr # Display hex
314 popl %edi # Restore
315 popl %esi # caller's
316 ret # To caller
295hexout: pushl %eax # Save
296 call putstr # Display message
297 popl %eax # Restore
298 pushl %esi # Save
299 pushl %edi # caller's
300 movl $buf,%edi # Buffer
301 pushl %edi # Save
302 call hex32 # To hex

--- 6 unchanged lines hidden (view full) ---

309 testb %al,%al # End of string?
310 jne hexout.2 # No
311 decl %esi # Undo
312hexout.2: decl %esi # Adjust for inc
313 call putstr # Display hex
314 popl %edi # Restore
315 popl %esi # caller's
316 ret # To caller
317#
318# Output zero-terminated string [ESI] to the console.
319#
317/*
318 * Output zero-terminated string [ESI] to the console.
319 */
320putstr.0: call putchr # Output char
321putstr: lodsb # Load char
322 testb %al,%al # End of string?
323 jne putstr.0 # No
324 ret # To caller
320putstr.0: call putchr # Output char
321putstr: lodsb # Load char
322 testb %al,%al # End of string?
323 jne putstr.0 # No
324 ret # To caller
325#
326# Output character AL to the console.
327#
325/*
326 * Output character AL to the console.
327 */
328putchr: pusha # Save
329 xorl %ecx,%ecx # Zero for loops
330 movb $SCR_MAT,%ah # Mode/attribute
331 movl $BDA_POS,%ebx # BDA pointer
332 movw (%ebx),%dx # Cursor position
333#ifdef PC98
334 movl $0xa0000,%edi # Regen buffer (color)
335#else

--- 60 unchanged lines hidden (view full) ---

396 movb %dh,%al
397 outb %al,$0x60
398#else
399 movb $SCR_ROW-1,%dh # Bottom line
400putchr.4: movw %dx,(%ebx) # Update position
401#endif
402 popa # Restore
403 ret # To caller
328putchr: pusha # Save
329 xorl %ecx,%ecx # Zero for loops
330 movb $SCR_MAT,%ah # Mode/attribute
331 movl $BDA_POS,%ebx # BDA pointer
332 movw (%ebx),%dx # Cursor position
333#ifdef PC98
334 movl $0xa0000,%edi # Regen buffer (color)
335#else

--- 60 unchanged lines hidden (view full) ---

396 movb %dh,%al
397 outb %al,$0x60
398#else
399 movb $SCR_ROW-1,%dh # Bottom line
400putchr.4: movw %dx,(%ebx) # Update position
401#endif
402 popa # Restore
403 ret # To caller
404#
405# Convert EAX, AX, or AL to hex, saving the result to [EDI].
406#
404/*
405 * Convert EAX, AX, or AL to hex, saving the result to [EDI].
406 */
407hex32: pushl %eax # Save
408 shrl $0x10,%eax # Do upper
409 call hex16 # 16
410 popl %eax # Restore
411hex16: call hex16.1 # Do upper 8
412hex16.1: xchgb %ah,%al # Save/restore
413hex8: pushl %eax # Save
414 shrb $0x4,%al # Do upper

--- 4 unchanged lines hidden (view full) ---

419 sbbb $0x69,%al # to hex
420 das # digit
421 orb $0x20,%al # To lower case
422 stosb # Save char
423 ret # (Recursive)
424
425 .data
426 .p2align 4
407hex32: pushl %eax # Save
408 shrl $0x10,%eax # Do upper
409 call hex16 # 16
410 popl %eax # Restore
411hex16: call hex16.1 # Do upper 8
412hex16.1: xchgb %ah,%al # Save/restore
413hex8: pushl %eax # Save
414 shrb $0x4,%al # Do upper

--- 4 unchanged lines hidden (view full) ---

419 sbbb $0x69,%al # to hex
420 das # digit
421 orb $0x20,%al # To lower case
422 stosb # Save char
423 ret # (Recursive)
424
425 .data
426 .p2align 4
427#
428# Global descriptor table.
429#
427/*
428 * Global descriptor table.
429 */
430gdt: .word 0x0,0x0,0x0,0x0 # Null entry
431 .word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE
432 .word 0xffff,0x0,0x9200,0xcf # SEL_SDATA
433 .word 0xffff,0x0,0x9a00,0x0 # SEL_RCODE
434 .word 0xffff,0x0,0x9200,0x0 # SEL_RDATA
435gdt.1:
436gdtdesc: .word gdt.1-gdt-1 # Limit
437 .long gdt # Base
430gdt: .word 0x0,0x0,0x0,0x0 # Null entry
431 .word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE
432 .word 0xffff,0x0,0x9200,0xcf # SEL_SDATA
433 .word 0xffff,0x0,0x9a00,0x0 # SEL_RCODE
434 .word 0xffff,0x0,0x9200,0x0 # SEL_RDATA
435gdt.1:
436gdtdesc: .word gdt.1-gdt-1 # Limit
437 .long gdt # Base
438#
439# Messages.
440#
438/*
439 * Messages.
440 */
441m_logo: .asciz " \nBTX loader 1.00 "
442m_vers: .asciz "BTX version is \0\n"
443e_fmt: .asciz "Error: Client format not supported\n"
444#ifdef BTXLDR_VERBOSE
445m_mem: .asciz "Starting in protected mode (base mem=\0)\n"
446m_esp: .asciz "Arguments passed (esp=\0):\n"
447m_args: .asciz"<howto="
448 .asciz" bootdev="

--- 11 unchanged lines hidden (view full) ---

460 .asciz " filesz="
461 .asciz " memsz=\0\n"
462 .asciz "data segment: offset="
463 .asciz " vaddr="
464 .asciz " filesz="
465 .asciz " memsz=\0\n"
466m_done: .asciz "Loading complete\n"
467#endif
441m_logo: .asciz " \nBTX loader 1.00 "
442m_vers: .asciz "BTX version is \0\n"
443e_fmt: .asciz "Error: Client format not supported\n"
444#ifdef BTXLDR_VERBOSE
445m_mem: .asciz "Starting in protected mode (base mem=\0)\n"
446m_esp: .asciz "Arguments passed (esp=\0):\n"
447m_args: .asciz"<howto="
448 .asciz" bootdev="

--- 11 unchanged lines hidden (view full) ---

460 .asciz " filesz="
461 .asciz " memsz=\0\n"
462 .asciz "data segment: offset="
463 .asciz " vaddr="
464 .asciz " filesz="
465 .asciz " memsz=\0\n"
466m_done: .asciz "Loading complete\n"
467#endif
468#
469# Uninitialized data area.
470#
468/*
469 * Uninitialized data area.
470 */
471buf: # Scratch buffer
471buf: # Scratch buffer