[movitz-cvs] CVS movitz
ffjeld
ffjeld at common-lisp.net
Sat Feb 9 18:42:26 UTC 2008
Update of /project/movitz/cvsroot/movitz
In directory clnet:/tmp/cvs-serv21135
Modified Files:
bootblock.lisp
Log Message:
Use new assembler. Compile twice as fast.
--- /project/movitz/cvsroot/movitz/bootblock.lisp 2007/03/16 17:39:27 1.13
+++ /project/movitz/cvsroot/movitz/bootblock.lisp 2008/02/09 18:42:26 1.14
@@ -9,7 +9,7 @@
;;;; Created at: Mon Oct 9 20:47:19 2000
;;;; Distribution: See the accompanying file COPYING.
;;;;
-;;;; $Id: bootblock.lisp,v 1.13 2007/03/16 17:39:27 ffjeld Exp $
+;;;; $Id: bootblock.lisp,v 1.14 2008/02/09 18:42:26 ffjeld Exp $
;;;;
;;;;------------------------------------------------------------------
@@ -83,245 +83,239 @@
(let* ((first-sector (1+ skip-sectors))
(last-sector (+ first-sector (ceiling image-size +sector-size+)))
(read-buffer-segment (floor +read-buffer+ #x10)))
- (ia-x86:read-proglist
- `(
- (:jmp (:pc+ 0)) ; some BIOSes might check for this.
-
- ;;
- ;; We are running at address #x7c00.
- ;;
-
- (:xorw :ax :ax)
- (:movw :ax :ds)
- (:movw :ax :es)
-
- (:movw #x9000 :ax)
- (:movw :ax :ss)
- (:movw #xfffc :bp)
- (:leaw (:bp ,(- +stack-frame-size+)) :sp)
- (:movw 'welcome :si) ; Print welcome message)
- (:call 'print)
-
- ;;
- ;; Enable the A20 gate
- ;;
- (:call 'empty-8042)
- (:movb #xd1 :al)
- (:outb :al #x64)
-
- (:call 'empty-8042)
- (:movb #xdf :al)
- (:outb :al #x60)
- (:call 'empty-8042)
-
- ;; Poll the floppy's sectors per track
-
- (:movw 5 (:bp ,+sectors-per-track+))
- check-geometry
- (:incb (:bp ,+sectors-per-track+))
- (:jz 'read-error)
- (:movw (:bp ,+sectors-per-track+) :cx )
- (:movw #x0201 :ax)
- (:xorw :dx :dx)
- (:movw ,read-buffer-segment :bx)
- (:movw :bx :es)
- (:xorw :bx :bx)
- (:int #x13) ; Call BIOS routine
- (:testb :ah :ah)
- (:jz 'check-geometry)
- (:decb (:bp ,+sectors-per-track+))
-
- ;;
- ;; Read sectors into memory
- ;;
+ `((:jmp (:pc+ 0)) ; some BIOSes might check for this.
+ ;;
+ ;; We are running at address #x7c00.
+ ;;
+ (:xorw :ax :ax)
+ (:movw :ax :ds)
+ (:movw :ax :es)
+
+ (:movw #x9000 :ax)
+ (:movw :ax :ss)
+ (:movw #xfffc :bp)
+ (:leaw (:bp ,(- +stack-frame-size+)) :sp)
+ (:movw 'welcome :si) ; Print welcome message)
+ (:call 'print)
+
+ ;;
+ ;; Enable the A20 gate
+ ;;
+ (:call 'empty-8042)
+ (:movb #xd1 :al)
+ (:outb :al #x64)
+
+ (:call 'empty-8042)
+ (:movb #xdf :al)
+ (:outb :al #x60)
+ (:call 'empty-8042)
+
+ ;; Poll the floppy's sectors per track
+
+ (:movw 5 (:bp ,+sectors-per-track+))
+ check-geometry
+ (:incb (:bp ,+sectors-per-track+))
+ (:jz 'read-error)
+ (:movw (:bp ,+sectors-per-track+) :cx )
+ (:movw #x0201 :ax)
+ (:xorw :dx :dx)
+ (:movw ,read-buffer-segment :bx)
+ (:movw :bx :es)
+ (:xorw :bx :bx)
+ (:int #x13) ; Call BIOS routine
+ (:testb :ah :ah)
+ (:jz 'check-geometry)
+ (:decb (:bp ,+sectors-per-track+))
+
+ ;;
+ ;; Read sectors into memory
+ ;;
- (:movw ,first-sector (:bp ,+linear-sector+))
- (:movl ,load-address (:bp ,+destination+))
+ (:movw ,first-sector (:bp ,+linear-sector+))
+ (:movl ,load-address (:bp ,+destination+))
- read-loop
+ read-loop
- (:cmpw ,last-sector (:bp ,+linear-sector+))
- (:jg 'read-done)
+ (:cmpw ,last-sector (:bp ,+linear-sector+))
+ (:jg 'read-done)
- (:movw 'track-start-msg :si) ; Print '(' to screen for each track
- (:call 'print)
+ (:movw 'track-start-msg :si) ; Print '(' to screen for each track
+ (:call 'print)
- (:movw (:bp ,+linear-sector+) :ax)
- (:movb (:bp ,+sectors-per-track+) :cl)
- (:divb :cl :ax) ; al=quotient, ah=remainder of :ax/:cl
-
- (:movb :ah :cl) ; sector - 1
- (:movb :al :dh)
- (:andb 1 :dh) ; head
- (:movb :al :ch)
- (:shrb 1 :ch) ; track
- (:xorb :dl :dl) ; drive = 0
- (:movw (:bp ,+sectors-per-track+) :ax)
- (:subb :cl :al) ; number of sectors (rest of track)
- (:incb :cl)
- (:addw :ax (:bp ,+linear-sector+)) ; update read pointer
- (:movw (:bp ,+linear-sector+) :bx) ; subtract some if it's the last track.
- (:subw ,last-sector :bx)
- (:jc 'subtract-zero-sectors)
- (:subw :bx :ax)
- (:jz 'read-done)
- subtract-zero-sectors
- (:movb 2 :ah)
-
- (:movw ,read-buffer-segment :bx)
- (:movw :bx :es)
- (:xorw :bx :bx)
- (:int #x13) ; Call BIOS routine
-
- (:jc 'read-error)
- (:movzxb :al :ecx)
-
- ;;
- ;; Install GS as 4GB segment
- ;; http://www.faqs.org/faqs/assembly-language/x86/general/part2/
- ;;
- (:cli)
- (:lgdt ('gdt-addr)) ; load gdt
- (:movcr :cr0 :eax)
- (:orb 1 :al)
- (:movcr :eax :cr0)
- (:jmp (:pc+ 0))
- (:movw 16 :bx)
- (:movw :bx :gs)
- (:andb #xfe :al)
- (:movcr :eax :cr0)
- (:jmp (:pc+ 0))
- (:sti)
- ;; Completed install GS as 4GB segment.
-
- ;; Copy data to destination
- (:shll ,(+ 9 -2) :ecx) ; 512/4 = sector-size/word-size
- (:movl ,+read-buffer+ :ebx)
- (:movl (:bp ,+destination+) :esi)
- (:leal (:esi (:ecx 4)) :edx)
-
- (:movl :edx (:bp ,+destination+))
-
- copy-loop
- (:decl :ecx)
- ((:gs-override) :movl (:ebx (:ecx 4)) :edx)
- ((:gs-override) :movl :edx (:esi (:ecx 4)))
- (:jnz 'copy-loop)
-
- (:movw 'track-end-msg :si) ; Print ')' to screen after each track
- (:call 'print)
-
- (:jmp 'read-loop)
-
- read-done
-
- motor-loop ; Wait for floppy motor
- (:btw 8 (#x43e))
- (:jc 'motor-loop)
-
- (movw 'entering :si) ; Print welcome message
- (call 'print)
-
- ;; Read the cursor position into DH (row) and DL (column).
- (:movb 3 :ah)
- (:movb 0 :bh)
- (:int #x10)
-
- (:cli) ; Disable interrupts
- (:lgdt ('gdt-addr)) ; load gdt
-
- (:xorw :ax :ax)
- (:movw :ax :es) ; reset es
-
- ;;
- ;; Turn off the cursor
- ;;
+ (:movw (:bp ,+linear-sector+) :ax)
+ (:movb (:bp ,+sectors-per-track+) :cl)
+ (:divb :cl :ax) ; al=quotient, ah=remainder of :ax/:cl
+
+ (:movb :ah :cl) ; sector - 1
+ (:movb :al :dh)
+ (:andb 1 :dh) ; head
+ (:movb :al :ch)
+ (:shrb 1 :ch) ; track
+ (:xorb :dl :dl) ; drive = 0
+ (:movw (:bp ,+sectors-per-track+) :ax)
+ (:subb :cl :al) ; number of sectors (rest of track)
+ (:incb :cl)
+ (:addw :ax (:bp ,+linear-sector+)) ; update read pointer
+ (:movw (:bp ,+linear-sector+) :bx) ; subtract some if it's the last track.
+ (:subw ,last-sector :bx)
+ (:jc 'subtract-zero-sectors)
+ (:subw :bx :ax)
+ (:jz 'read-done)
+ subtract-zero-sectors
+ (:movb 2 :ah)
+
+ (:movw ,read-buffer-segment :bx)
+ (:movw :bx :es)
+ (:xorw :bx :bx)
+ (:int #x13) ; Call BIOS routine
+
+ (:jc 'read-error)
+ (:movzxb :al :ecx)
+
+ ;;
+ ;; Install GS as 4GB segment
+ ;; http://www.faqs.org/faqs/assembly-language/x86/general/part2/
+ ;;
+ (:cli)
+ (:lgdt ('gdt-addr)) ; load gdt
+ (:movcr :cr0 :eax)
+ (:orb 1 :al)
+ (:movcr :eax :cr0)
+ (:jmp (:pc+ 0))
+ (:movw 16 :bx)
+ (:movw :bx :gs)
+ (:andb #xfe :al)
+ (:movcr :eax :cr0)
+ (:jmp (:pc+ 0))
+ (:sti)
+ ;; Completed install GS as 4GB segment.
+
+ ;; Copy data to destination
+ (:shll ,(+ 9 -2) :ecx) ; 512/4 = sector-size/word-size
+ (:movl ,+read-buffer+ :ebx)
+ (:movl (:bp ,+destination+) :esi)
+ (:leal (:esi (:ecx 4)) :edx)
+
+ (:movl :edx (:bp ,+destination+))
+
+ copy-loop
+ (:decl :ecx)
+ ((:gs-override) :movl (:ebx (:ecx 4)) :edx)
+ ((:gs-override) :movl :edx (:esi (:ecx 4)))
+ (:jnz 'copy-loop)
+
+ (:movw 'track-end-msg :si) ; Print ')' to screen after each track
+ (:call 'print)
+
+ (:jmp 'read-loop)
+
+ read-done
+
+ motor-loop ; Wait for floppy motor
+ (:btw 8 (#x43e))
+ (:jc 'motor-loop)
+
+ (:movw 'entering :si) ; Print welcome message
+ (:call 'print)
+
+ ;; Read the cursor position into DH (row) and DL (column).
+ (:movb 3 :ah)
+ (:movb 0 :bh)
+ (:int #x10)
+
+ (:cli) ; Disable interrupts
+ (:lgdt ('gdt-addr)) ; load gdt
+
+ (:xorw :ax :ax)
+ (:movw :ax :es) ; reset es
+
+ ;;
+ ;; Turn off the cursor
+ ;;
;;; (movb #x01 :ah)
;;; (movw #x0100 :cx)
;;; (int #x10)
- ;;
- ;; Load machine status word. This will enable
- ;; protected mode. The subsequent instruction MUST
- ;; reload the code segment register with a selector for
- ;; the protected mode code segment descriptor (see
- ;; GDT specification).
- ;;
- (:movw 1 :ax)
- (:lmsw :ax) ; load word 0 of cr0
-
- ;;
- ;; Do a longjump to new-world. This will cause the CS to
- ;; be loaded with the correct descriptor, and the processor
- ;; will now run in 32 bit mode.
- ;;
-
- (:jmp 8 ('new-world))
-
- ;;
- ;; Display error message and hang
- ;;
- read-error
- (:movw 'error :si) ; Print error message
- (:call 'print)
- halt-cpu
- (:halt)
- (:jmp 'halt-cpu) ; Infinite loop
-
- ;;
- ;; Empty the 8042 Keyboard controller
- ;;
- empty-8042
- (:call 'delay)
- (:inb #x64 :al) ; 8042 status port
- (:testb 1 :al) ; if ( no information available )
- (:jz 'no-output) ; goto no_output
- (:call 'delay)
- (:inb #x60 :al) ; read it
- (:jmp 'empty-8042)
- no-output
- (:testb 2 :al) ; if ( input buffer is full )
- (:jnz 'empty-8042) ; goto empty_8042
- (:ret)
-
- delay
- (:xorw :cx :cx)
- delay-loop
- (:loop 'delay-loop)
- (:ret)
-
- print ,@(mkasm16-bios-print)
-
- ;; Data
- welcome (% format 8 "Loading Movitz ~D..~%
"
- ,(incf *bootblock-build*))
- entering (% format 8 "~%
Enter..")
- error (% format 8 "Failed!)")
- track-start-msg (% format 8 "(")
- track-end-msg (% format 8 ")")
- sector-msg (% format 8 "-")
+ ;;
+ ;; Load machine status word. This will enable
+ ;; protected mode. The subsequent instruction MUST
+ ;; reload the code segment register with a selector for
+ ;; the protected mode code segment descriptor (see
+ ;; GDT specification).
+ ;;
+ (:movw 1 :ax)
+ (:lmsw :ax) ; load word 0 of cr0
+
+ ;;
+ ;; Do a longjump to new-world. This will cause the CS to
+ ;; be loaded with the correct descriptor, and the processor
+ ;; will now run in 32 bit mode.
+ ;;
+
+ (:jmp 8 ('new-world))
+
+ ;;
+ ;; Display error message and hang
+ ;;
+ read-error
[234 lines skipped]
More information about the Movitz-cvs
mailing list