From e35d4f46fd6677e9c1e29fa4a51e0649bea5e1b7 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 15 Mar 2021 09:17:15 -0700 Subject: . --- boot.subx | 17 +++++----- linux/survey_baremetal | Bin 53128 -> 53101 bytes linux/survey_baremetal.subx | 79 +++++++++++++++++++++++++++++++++++--------- 3 files changed, 71 insertions(+), 25 deletions(-) diff --git a/boot.subx b/boot.subx index bf30647e..482a1351 100644 --- a/boot.subx +++ b/boot.subx @@ -276,18 +276,17 @@ initialize_32bit_mode: 55 aa ## sector 2 onwards loaded by load_disk, not automatically on boot -== data -# offset 200 (address 0x7e00): -# null interrupt handler: +null-interrupt-handler: cf # iret # padding # 201: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -# 210: -# keyboard interrupt handler: +== data + +keyboard-interrupt-handler: # prologue fa # disable interrupts 60 # push all registers to stack @@ -557,18 +556,18 @@ idt_start: # https://wiki.osdev.org/index.php?title=Interrupts&oldid=25102#Default_PC_Interrupt_Vector_Assignment # entry 8: clock - 00 7e # target[0:16] = null interrupt handler [label] + null-interrupt-handler/imm16 # target[0:16] 08 00 # segment selector (gdt_code) 00 # unused 8e # 1/p 00/dpl 0 1110/type/32-bit-interrupt-gate - 00 00 # target[16:32] + 0/imm16 # target[16:32] -- null-interrupt-handler must be within address 0x10000 # entry 9: keyboard - 10 7e # target[0:16] = keyboard interrupt handler [label] + keyboard-interrupt-handler/imm16 # target[0:16] 08 00 # segment selector (gdt_code) 00 # unused 8e # 1/p 00/dpl 0 1110/type/32-bit-interrupt-gate - 00 00 # target[16:32] + 0/imm16 # target[16:32] -- keyboard-interrupt-handler must be within address 0x10000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 diff --git a/linux/survey_baremetal b/linux/survey_baremetal index 74ff0852..c9686c61 100755 Binary files a/linux/survey_baremetal and b/linux/survey_baremetal differ diff --git a/linux/survey_baremetal.subx b/linux/survey_baremetal.subx index a8a44ec4..41314e53 100644 --- a/linux/survey_baremetal.subx +++ b/linux/survey_baremetal.subx @@ -982,7 +982,9 @@ emit-output: # in: (addr stream byte), out: (addr buffered-file), labels: (addr # var datum: (addr slice) = next-token-from-slice(word-slice->start, word-slice->end, "/") # var address: (addr int) = get-slice(labels, datum) # if has-metadata?(word-slice, "imm8") - # abort + # emit(out, *address, 1) + # else if has-metadata?(word-slice, "imm16") + # emit(out, *address, 2) # else if has-metadata?(word-slice, "imm32") # emit(out, *address, 4) # else if has-metadata?(word-slice, "disp8") @@ -1418,7 +1420,7 @@ $emit-output:check-imm8: 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . if (eax != false) abort 3d/compare-eax-and 0/imm32/false - 74/jump-if-= $emit-output:check-imm32/disp8 + 74/jump-if-= $emit-output:check-imm16/disp8 $emit-output:emit-imm8: # emit-hex(out, *address, 1) # . . push args @@ -1431,6 +1433,65 @@ $emit-output:emit-imm8: 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # continue e9/jump $emit-output:word-loop/disp32 +$emit-output:check-imm16: + # if (!has-metadata?(word-slice, "imm16")) goto next check + # . eax = has-metadata?(edx, "imm16") + # . . push args + 68/push "imm16"/imm32 + 52/push-edx + # . . call + e8/call has-metadata?/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # . if (eax == false) goto next check + 3d/compare-eax-and 0/imm32/false + 74/jump-if-= $emit-output:check-imm32/disp8 +#? # dump *address {{{ +#? # . write(2/stderr, "*address: ") +#? # . . push args +#? 68/push "*address: "/imm32 +#? 68/push 2/imm32/stderr +#? # . . call +#? e8/call write/disp32 +#? # . . discard args +#? 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +#? # . write-int32-hex-buffered(Stderr, *address) +#? # . . push args +#? ff 6/subop/push 0/mod/indirect 6/rm32/esi . . . . . . # push *esi +#? 68/push Stderr/imm32 +#? # . . call +#? e8/call write-int32-hex-buffered/disp32 +#? # . . discard args +#? 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +#? # . flush(Stderr) +#? # . . push args +#? 68/push Stderr/imm32 +#? # . . call +#? e8/call flush/disp32 +#? # . . discard args +#? 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +#? # . write(2/stderr, "$\n") +#? # . . push args +#? 68/push "$\n"/imm32 +#? 68/push 2/imm32/stderr +#? # . . call +#? e8/call write/disp32 +#? # . . discard args +#? 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +#? # }}} +$emit-output:emit-imm16: + # emit-hex(out, *address, 2) + # . . push args + 68/push 2/imm32 + ff 6/subop/push 0/mod/indirect 6/rm32/esi . . . . . . # push *esi + ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) + # . . call + e8/call emit-hex/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp + # TODO: ensure that the higher 2 bytes are zero + # continue + e9/jump $emit-output:word-loop/disp32 $emit-output:check-imm32: # if (!has-metadata?(word-slice, "imm32")) goto next check # . eax = has-metadata?(edx, "imm32") @@ -1601,20 +1662,6 @@ $emit-output:end: 5d/pop-to-ebp c3/return -$emit-output:imm8-abort: - # . _write(2/stderr, error) - # . . push args - 68/push "emit-output: cannot refer to code labels with /imm8"/imm32 - 68/push 2/imm32/stderr - # . . call - e8/call _write/disp32 - # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # . syscall(exit, 1) - bb/copy-to-ebx 1/imm32 - e8/call syscall_exit/disp32 - # never gets here - $emit-output:abort: # print(stderr, "missing metadata in " word-slice) # . _write(2/stderr, "missing metadata in word ") -- cgit 1.4.1-2-gfad0