aboutsummaryrefslogtreecommitdiff
path: root/mubios/services/int14.c
blob: 86019b7043965c8d1667d5b031ff4a7b4a4c69d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 RCC-Project

 Copyright (C) 2026 Richard Qin

 This file is part of RCC-Project.
 */

#include "bios.h"
#include "io.h"
#include "regs.h"

#define COM1_BASE 0x03F8u
#define COM_DATA 0x00u
#define COM_LSR 0x05u
#define COM_LSR_THRE 0x20u
#define COM_LSR_IDLE 0x40u

static void
int14_putc (u8 value)
{
  while ((io_in8 ((u16)(COM1_BASE + COM_LSR)) & COM_LSR_THRE) == 0u)
    {
    }

  io_out8 ((u16)(COM1_BASE + COM_DATA), value);
}

void
int14_service (struct bios_regs *regs)
{
  u8 function;
  u8 status;

  function = (u8)(regs->eax >> 8);

  if (function == 0x00u)
    {
      serial_init ();
      regs->eax &= 0xFFFF0000u;
      return;
    }

  if (function == 0x01u)
    {
      int14_putc ((u8)regs->eax);
      status = (u8)(io_in8 ((u16)(COM1_BASE + COM_LSR))
                    | COM_LSR_THRE | COM_LSR_IDLE);
      regs->eax = (regs->eax & 0xFFFF00FFu) | ((u32)status << 8);
      return;
    }

  if (function == 0x03u)
    {
      status = io_in8 ((u16)(COM1_BASE + COM_LSR));
      regs->eax = (regs->eax & 0xFFFF00FFu) | ((u32)status << 8);
      return;
    }

  regs->eax = 0x0100u;
}